Ticket #521: RallyPoints.diff
| File RallyPoints.diff, 7.8 KB (added by evans, 22 months ago) |
|---|
-
binaries/data/mods/public/gui/session_new/input.js
62 62 } 63 63 64 64 /** 65 * Checks if all the given entities are buildings. 66 * @param entities 67 */ 68 function areAllBuildings(entities) 69 { 70 for each (var ent in entities) 71 { 72 var entState = Engine.GuiInterfaceCall("GetEntityState", ent); 73 //If the entity does not have a RallyPoint defined, 74 if (!entState.isABuilding) 75 { 76 return false; 77 } 78 79 } 80 return true; 81 } 82 83 /** 65 84 * Determine the context-sensitive action that should be performed when the mouse is at (x,y) 66 85 */ 67 86 function determineAction(x, y) … … 86 105 87 106 // If there's no unit, just walk 88 107 if (!targets.length) 89 return {"type": "move"}; 90 108 { 109 //If all selected entities are buildings, 110 //set gather points, else make them walk 111 if (areAllBuildings(selection)) 112 { 113 return {"type": "set-rallypoint"}; 114 } 115 else 116 { 117 return {"type": "move"}; 118 } 119 } 91 120 // Look at the first targeted entity 92 121 // (TODO: maybe we eventually want to look at more, and be more context-sensitive? 93 122 // e.g. prefer to attack an enemy unit, even if some friendly units are closer to the mouse) … … 266 295 g_Selection.reset(); 267 296 g_Selection.addList(ents); 268 297 298 Engine.GuiInterfaceCall("DisplayRallyPoint", { 299 "entities": ents[0] 300 }); 301 269 302 // Create the selection groups 270 303 g_Selection.groups.createGroups(ents); 271 304 … … 463 496 case "gather": 464 497 Engine.PostNetworkCommand({"type": "gather", "entities": selection, "target": action.target, "queued": queued}); 465 498 return true; 466 499 case "set-rallypoint": 500 var target = Engine.GetTerrainAtPoint(ev.x, ev.y); 501 Engine.PostNetworkCommand({"type": "set-rallypoint", "entities": selection, "x": target.x, "z": target.z}); 502 //Display rally point passing just the coordinates 503 Engine.GuiInterfaceCall("SetRallyPoint", { 504 "x": target.x, 505 "z": target.z 506 }); 507 return true; 467 508 default: 468 509 throw new Error("Invalid action.type "+action.type); 469 510 } … … 497 538 if (!ents.length) 498 539 { 499 540 g_Selection.reset(); 500 501 541 inputState = INPUT_NORMAL; 542 //Clear Rally Points 543 Engine.GuiInterfaceCall("DisplayRallyPoint", { 544 "entities": undefined 545 }); 502 546 return true; 503 547 } 504 548 //Display Rally Point 549 Engine.GuiInterfaceCall("DisplayRallyPoint", { 550 "entities": [ents[0]] 551 }); 505 552 g_Selection.reset(); 506 553 g_Selection.addList([ents[0]]); 507 508 554 inputState = INPUT_NORMAL; 509 555 return true; 510 556 } -
binaries/data/mods/public/simulation/helpers/Commands.js
123 123 }); 124 124 125 125 break; 126 126 case "set-rallypoint": 127 for each (var ent in cmd.entities) 128 { 129 var cmpRallyPoint = Engine.QueryInterface(ent, IID_RallyPoint); 130 if (cmpRallyPoint) 131 cmpRallyPoint.SetPosition(cmd.x, cmd.z); 132 } 133 break; 127 134 default: 128 135 error("Ignoring unrecognised command type '" + cmd.type + "'"); 129 136 } -
binaries/data/mods/public/simulation/components/GuiInterface.js
11 11 GuiInterface.prototype.Init = function() 12 12 { 13 13 this.placementEntity = undefined; // = undefined or [templateName, entityID] 14 this.rallyPoints = undefined; 14 15 }; 15 16 16 17 GuiInterface.prototype.GetSimulationState = function(player) … … 124 125 ret.resourceGatherRates = cmpResourceGatherer.GetGatherRates(); 125 126 } 126 127 128 var cmpRallyPoint = Engine.QueryInterface(ent, IID_RallyPoint); 129 if(cmpRallyPoint) 130 { 131 ret.isABuilding = true; 132 if (cmpRallyPoint.GetPosition() != undefined) 133 { 134 ret.isRallyPointSet = true; 135 } 136 else 137 { 138 ret.isRallyPointSet = false; 139 } 140 } 127 141 return ret; 128 142 }; 129 143 … … 170 184 }; 171 185 172 186 /** 187 * Displays the rally point of a building 188 */ 189 GuiInterface.prototype.DisplayRallyPoint = function(player, cmd) 190 { 191 var positions; 192 if (this.rallyPoints) 193 { 194 //If there are rally points already displayed, destroy them 195 for each (var rallyPoint in this.rallyPoints) 196 { 197 Engine.DestroyEntity(rallyPoint); 198 } 199 } 200 if (cmd.entities) 201 { 202 //DisplayRallyPoints is called passing a list of entities for which 203 //Rally Points must be displayed 204 positions = new Array(); 205 for each (var ent in cmd.entities) 206 { 207 var cmpRallyPoint = Engine.QueryInterface(ent, IID_RallyPoint); 208 if (cmpRallyPoint && cmpRallyPoint.GetPosition()) 209 { 210 positions.push(cmpRallyPoint.GetPosition()); 211 } 212 } 213 } 214 else if (cmd.x && cmd.z) 215 { 216 //Sometimes DisplayRallyPoint() is called specifying just a coordinate. 217 positions = [{"x": cmd.x, "z": cmd.z}]; 218 } 219 if (positions) 220 { 221 this.rallyPoints = new Array(); 222 //Add Rally Point entitied for each building 223 for each (var pos in positions) 224 { 225 var rallyPoint = Engine.AddLocalEntity("actor|props/special/common/waypoint_flag.xml"); 226 var cmpPosition = Engine.QueryInterface(rallyPoint, IID_Position); 227 cmpPosition.JumpTo(pos.x, pos.z); 228 this.rallyPoints.push(rallyPoint); 229 } 230 } 231 232 } 233 234 /** 173 235 * Display the building placement preview. 174 236 * cmd.template is the name of the entity template, or "" to disable the preview. 175 237 * cmd.x, cmd.z, cmd.angle give the location. … … 248 310 } 249 311 }; 250 312 251 GuiInterface.prototype.SetRangeDebugOverlay = function(player, enabled)252 {253 var cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);254 cmpRangeManager.SetDebugOverlay(enabled);255 };256 257 313 // List the GuiInterface functions that can be safely called by GUI scripts. 258 314 // (GUI scripts are non-deterministic and untrusted, so these functions must be 259 315 // appropriately careful. They are called with a first argument "player", which is … … 268 324 "SetPathfinderDebugOverlay": 1, 269 325 "SetObstructionDebugOverlay": 1, 270 326 "SetMotionDebugOverlay": 1, 271 " SetRangeDebugOverlay": 1,327 "DisplayRallyPoint": 1 272 328 }; 273 329 274 330 GuiInterface.prototype.ScriptCall = function(player, name, args) -
binaries/data/mods/public/simulation/components/TrainingQueue.js
158 158 var cmpFootprint = Engine.QueryInterface(this.entity, IID_Footprint); 159 159 var cmpPosition = Engine.QueryInterface(this.entity, IID_Position); 160 160 var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); 161 161 var cmpRallyPoint = Engine.QueryInterface(this.entity, IID_RallyPoint); 162 162 163 for (var i = 0; i < count; ++i) 163 164 { 164 165 var ent = Engine.AddEntity(templateName); … … 181 182 cmpNewOwnership.SetOwner(cmpOwnership.GetOwner()); 182 183 183 184 // TODO: move to rally points 185 var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); 186 if (cmpUnitAI && cmpRallyPoint.GetPosition() != undefined) 187 cmpUnitAI.Walk(cmpRallyPoint.GetPosition().x, cmpRallyPoint.GetPosition().z, false); 184 188 } 185 189 }; 186 190 -
binaries/data/mods/public/simulation/templates/template_structure.xml
36 36 <Range>36</Range> 37 37 <RetainInFog>true</RetainInFog> 38 38 </Vision> 39 <RallyPoint> 40 </RallyPoint> 39 41 </Entity>
