This repository has been archived by the owner on Dec 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
Script additions #272
Open
andreus791
wants to merge
2
commits into
Kromster80:master
Choose a base branch
from
andreus791:script-additions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Script additions #272
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,12 +24,15 @@ TKMScriptStates = class(TKMScriptEntity) | |
|
||
function GameTime: Cardinal; | ||
|
||
function GetAllTeams: TIntegerArray; | ||
|
||
function GroupAt(aX, aY: Word): Integer; | ||
function GroupColumnCount(aGroupID: Integer): Integer; | ||
function GroupDead(aGroupID: Integer): Boolean; | ||
function GroupIdle(aGroupID: Integer): Boolean; | ||
function GroupMember(aGroupID, aMemberIndex: Integer): Integer; | ||
function GroupMemberCount(aGroupID: Integer): Integer; | ||
function GroupOrdersBlocked(aGroupID: Integer): Boolean; | ||
function GroupOwner(aGroupID: Integer): Integer; | ||
function GroupType(aGroupID: Integer): Integer; | ||
|
||
|
@@ -91,6 +94,7 @@ TKMScriptStates = class(TKMScriptEntity) | |
function PlayerGetAllGroups(aPlayer: Byte): TIntegerArray; | ||
function PlayerIsAI(aPlayer: Byte): Boolean; | ||
function PlayerName(aPlayer: Byte): AnsiString; | ||
function PlayerTeam(aPlayer: Byte): Integer; | ||
function PlayerVictorious(aPlayer: Byte): Boolean; | ||
function PlayerWareDistribution(aPlayer, aWareType, aHouseType: Byte): Byte; | ||
|
||
|
@@ -507,6 +511,31 @@ function TKMScriptStates.GameTime: Cardinal; | |
end; | ||
|
||
|
||
//* Version: 7000+ | ||
//* Returns an array with IDs of teams for all players | ||
//* Result: Array of team IDs | ||
function TKMScriptStates.GetAllTeams: TIntegerArray; | ||
var | ||
I, NetIndex: Integer; | ||
begin | ||
try | ||
SetLength(Result, 0); | ||
for I := 1 to gGame.Networking.NetPlayers.Count do | ||
begin | ||
NetIndex := gGame.Networking.NetPlayers.PlayerIndexToLocal(I); | ||
SetLength(Result, Length(Result) + 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to resize the array every loop (inefficient), just set the size once at the start. |
||
if NetIndex <> -1 then | ||
Result[Length(Result) - 1] := gGame.Networking.NetPlayers[NetIndex].Team | ||
else | ||
Result[Length(Result) - 1] := -1; | ||
end; | ||
except | ||
gScriptEvents.ExceptionOutsideScript := True; //Don't blame script for this exception | ||
raise; | ||
end; | ||
end; | ||
|
||
|
||
//* Version: 5057 | ||
//* Length of peacetime in ticks (multiplayer) | ||
//* Result: Ticks (~10 per second) | ||
|
@@ -1104,6 +1133,30 @@ function TKMScriptStates.PlayerName(aPlayer: Byte): AnsiString; | |
end; | ||
|
||
|
||
//* Version: 7000+ | ||
//* Get players team (usually for multiplayer) | ||
//* Result: Player team | ||
function TKMScriptStates.PlayerTeam(aPlayer: Byte): Integer; | ||
var | ||
NetIndex: Integer; | ||
begin | ||
try | ||
Result := -1; | ||
if InRange(aPlayer, 0, gHands.Count - 1) then | ||
begin | ||
NetIndex := gGame.Networking.NetPlayers.PlayerIndexToLocal(aPlayer); | ||
if NetIndex <> -1 then | ||
Result := gGame.Networking.NetPlayers[NetIndex].Team; | ||
end | ||
else | ||
LogParamWarning('States.PlayerTeam', [aPlayer]); | ||
except | ||
gScriptEvents.ExceptionOutsideScript := True; //Don't blame script for this exception | ||
raise; | ||
end; | ||
end; | ||
|
||
|
||
//* Version: 5057 | ||
//* Returns the ID of the house at the specified location or -1 if no house exists there | ||
//* Result: House ID | ||
|
@@ -2638,6 +2691,30 @@ function TKMScriptStates.GroupIdle(aGroupID: Integer): Boolean; | |
end; | ||
|
||
|
||
//* Version: 7000+ | ||
//* See whether orders for specified group are blocked | ||
//* Result: Orders block state | ||
function TKMScriptStates.GroupOrdersBlocked(aGroupID: Integer): Boolean; | ||
var | ||
G: TKMUnitGroup; | ||
begin | ||
try | ||
Result := False; | ||
if aGroupID > 0 then | ||
begin | ||
G := fIDCache.GetGroup(aGroupID); | ||
if G <> nil then | ||
Result := G.BlockOrders; | ||
end | ||
else | ||
LogParamWarning('States.GroupOrdersBlocked', [aGroupID]); | ||
except | ||
gScriptEvents.ExceptionOutsideScript := True; //Don't blame script for this exception | ||
raise; | ||
end; | ||
end; | ||
|
||
|
||
//* Version: 5057 | ||
//* Returns the owner of the specified group or -1 if Group ID invalid | ||
//* Result: Player ID | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear what this function returns. Is it a mapping (lookup table) from Hand Index to Team? (that would make the most sense for the script). In that case you should iterate over hands count not NetPlayers count (so the length of the returned array is always hands count).
Otherwise it's unclear how this function could be useful to the script, since the indexes of the array will not match up with player indexes that the script uses in other functions (e.g. the player/hand index in Actions.OverlayTextSet would not be the same as the index into the array returned by this function).