Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'remotes/trunk'
- Loading branch information
Showing
10 changed files
with
424 additions
and
266 deletions.
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
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
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
121 changes: 65 additions & 56 deletions
121
binaries/data/mods/public/simulation/helpers/RallyPointCommands.js
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,67 +1,76 @@ | |||
// Returns an command suitable for ProcessCommand() based on the rally point data. | // Returns an array of commands suitable for ProcessCommand() based on the rally point data. | ||
// This assumes that the rally point has a valid position. | // This assumes that the rally point has a valid position. | ||
function GetRallyPointCommand(cmpRallyPoint, spawnedEnts) | function GetRallyPointCommands(cmpRallyPoint, spawnedEnts) | ||
{ | { | ||
// Look and see if there is a command in the rally point data, otherwise just walk there. | |||
var data = cmpRallyPoint.GetData(); | var data = cmpRallyPoint.GetData(); | ||
var rallyPos = cmpRallyPoint.GetPosition(); | var rallyPos = cmpRallyPoint.GetPositions(); | ||
var command = undefined; | var ret = []; | ||
if (data && data.command) | for(var i = 0; i < rallyPos.length; ++i) | ||
{ | { | ||
command = data.command; | // Look and see if there is a command in the rally point data, otherwise just walk there. | ||
} | var command = undefined; | ||
else | if (data[i] && data[i].command) | ||
{ | { | ||
command = "walk"; | command = data[i].command; | ||
} | } | ||
|
else | ||
// If a target was set and the target no longer exists, or no longer | |||
// has a valid position, then just walk to the rally point. | |||
if (data && data.target) | |||
{ | |||
var cmpPosition = Engine.QueryInterface(data.target, IID_Position); | |||
if (!cmpPosition || !cmpPosition.IsInWorld()) | |||
{ | { | ||
command = "walk"; | command = "walk"; | ||
} | } | ||
} | |||
|
|
||
switch (command) | // If a target was set and the target no longer exists, or no longer | ||
{ | // has a valid position, then just walk to the rally point. | ||
case "gather": | if (data[i] && data[i].target) | ||
return { | { | ||
"type": "gather-near-position", | var cmpPosition = Engine.QueryInterface(data[i].target, IID_Position); | ||
"entities": spawnedEnts, | if (!cmpPosition || !cmpPosition.IsInWorld()) | ||
"x": rallyPos.x, | { | ||
"z": rallyPos.z, | command = "walk"; | ||
"resourceType": data.resourceType, | } | ||
"queued": false | } | ||
}; |
|
||
case "repair": | switch (command) | ||
case "build": | { | ||
return { | case "gather": | ||
"type": "repair", | ret.push( { | ||
"entities": spawnedEnts, | "type": "gather-near-position", | ||
"target": data.target, | "entities": spawnedEnts, | ||
"queued": false, | "x": rallyPos[i].x, | ||
"autocontinue": true | "z": rallyPos[i].z, | ||
}; | "resourceType": data[i].resourceType, | ||
case "garrison": | "queued": true | ||
return { | }); | ||
"type": "garrison", | break; | ||
"entities": spawnedEnts, | case "repair": | ||
"target": data.target, | case "build": | ||
"queued": false | ret.push( { | ||
}; | "type": "repair", | ||
default: | "entities": spawnedEnts, | ||
return { | "target": data[i].target, | ||
"type": "walk", | "queued": true, | ||
"entities": spawnedEnts, | "autocontinue": (i == rallyPos.length-1) | ||
"x": rallyPos.x, | }); | ||
"z": rallyPos.z, | break; | ||
"queued": false | case "garrison": | ||
}; | ret.push( { | ||
"type": "garrison", | |||
"entities": spawnedEnts, | |||
"target": data[i].target, | |||
"queued": true | |||
}); | |||
break; | |||
default: | |||
ret.push( { | |||
"type": "walk", | |||
"entities": spawnedEnts, | |||
"x": rallyPos[i].x, | |||
"z": rallyPos[i].z, | |||
"queued": true | |||
}); | |||
break; | |||
} | |||
} | } | ||
return ret; | |||
} | } | ||
|
|
||
Engine.RegisterGlobal("GetRallyPointCommand", GetRallyPointCommand); | Engine.RegisterGlobal("GetRallyPointCommands", GetRallyPointCommands); |
Oops, something went wrong.