Ticket #745: rallypoint_on_entities.diff
File rallypoint_on_entities.diff, 10.9 KB (added by , 12 years ago) |
---|
-
binaries/data/mods/public/gui/session/input.js
139 139 if (!target) 140 140 { 141 141 if (action == "set-rallypoint" && haveRallyPoints) 142 return {"possible": true };142 return {"possible": true, "command": "walk"}; 143 143 else if (action == "move") 144 144 return {"possible": true}; 145 145 else … … 163 163 // Check if any entities in the selection can gather the requested resource, 164 164 // can return to the dropsite, can build the foundation, or can attack the enemy 165 165 var simState = Engine.GuiInterfaceCall("GetSimulationState"); 166 167 // Look to see what type of command units going to the rally point should use 168 if (haveRallyPoints && action == "set-rallypoint"){ 169 // haveRallyPoints ensures all selected entities can have rally points. 170 // We assume that all entities are owned by the same player. 171 var entState = GetEntityState(selection[0]); 172 173 var playerState = simState.players[entState.player]; 174 var playerOwned = (targetState.player == entState.player); 175 var allyOwned = playerState.isAlly[targetState.player]; 176 var enemyOwned = playerState.isEnemy[targetState.player]; 177 var gaiaOwned = (targetState.player == 0); 178 179 // default to walking there 180 var data = {command: "walk"}; 181 if (targetState.garrisonHolder && playerOwned) 182 { 183 data.command = "garrison"; 184 data.target = target; 185 } 186 else if (targetState.resourceSupply && (playerOwned || gaiaOwned)) 187 { 188 var resourceType = targetState.resourceSupply.type.generic; 189 if (resourceType === "treasure") 190 { 191 resourceType = targetState.resourceSupply.type.specific; 192 } 193 data.command = "gather"; 194 data.resourceType = resourceType; 195 } 196 else if (targetState.foundation && entState.buildEntities) 197 { 198 data.command = "build"; 199 data.target = target; 200 } 201 else if (targetState.needsRepair && allyOwned) 202 { 203 data.command = "repair"; 204 data.target = target; 205 } 206 else if (targetState.hitpoints && enemyOwned){ 207 data.command = "attack"; 208 data.target = target; 209 } 210 211 return {"possible": true, "data": data, "position": targetState.position}; 212 } 166 213 167 214 for each (var entityID in selection) 168 215 { … … 312 359 return {"type": "build", "cursor": "action-repair", "target": target}; 313 360 else if (getActionInfo("attack", target).possible) 314 361 return {"type": "attack", "cursor": "action-attack", "target": target}; 315 else if( getActionInfo("set-rallypoint", target).possible)316 return {"type": "set-rallypoint" };362 else if((actionInfo = getActionInfo("set-rallypoint", target)).possible) 363 return {"type": "set-rallypoint", "data": actionInfo.data, "position": actionInfo.position}; 317 364 else if(getActionInfo("unset-rallypoint", target).possible) 318 365 return {"type": "unset-rallypoint"}; 319 366 else if (getActionInfo("move", target).possible) … … 932 979 return true; 933 980 934 981 case "set-rallypoint": 935 var target = Engine.GetTerrainAtPoint(ev.x, ev.y); 936 Engine.PostNetworkCommand({"type": "set-rallypoint", "entities": selection, "x": target.x, "z": target.z}); 982 var pos = undefined; 983 // if there is a position set in the action then use this so that when setting a 984 // rally point on an entity it is centered on that entity 985 if (action.position) 986 { 987 pos = action.position; 988 } 989 else 990 { 991 pos = Engine.GetTerrainAtPoint(ev.x, ev.y); 992 } 993 Engine.PostNetworkCommand({"type": "set-rallypoint", "entities": selection, "x": pos.x, "z": pos.z, "data": action.data}); 937 994 // Display rally point at the new coordinates, to avoid display lag 938 995 Engine.GuiInterfaceCall("DisplayRallyPoint", { 939 996 "entities": selection, 940 "x": target.x,941 "z": target.z997 "x": pos.x, 998 "z": pos.z 942 999 }); 943 1000 return true; 944 1001 -
binaries/data/mods/public/simulation/helpers/Commands.js
-
binaries/data/mods/public/simulation/components/TrainingQueue.js
function ProcessCommand(player, cmd) { @@ -94,6 +94,13 @@ cmpUnitAI.Gather(cmd.target, cmd.queued); }); break; + + case "gatherNearPosition": + var entities = FilterEntityList(cmd.entities, player, controlAllUnits); + GetFormationUnitAIs(entities).forEach(function(cmpUnitAI) { + cmpUnitAI.GatherNearPosition([cmd.x, cmd.z], cmd.resourceType, cmd.queued); + }); + break; case "returnresource": // Check dropsite is owned by player @@ -288,7 +295,10 @@ { var cmpRallyPoint = Engine.QueryInterface(ent, IID_RallyPoint); if (cmpRallyPoint) + { cmpRallyPoint.SetPosition(cmd.x, cmd.z); + cmpRallyPoint.SetData(cmd.data); + } } break;
286 286 var rallyPos = cmpRallyPoint.GetPosition(); 287 287 if (rallyPos) 288 288 { 289 ProcessCommand(cmpOwnership.GetOwner(), { 290 "type": "walk", 291 "entities": spawnedEnts, 292 "x": rallyPos.x, 293 "z": rallyPos.z, 294 "queued": false 295 }); 289 // Look and see if there is a command in the rally point data, otherwise just walk there. 290 var data = cmpRallyPoint.GetData(); 291 var command = undefined; 292 if (data && data.command){ 293 command = data.command; 294 }else{ 295 command = "walk"; 296 } 297 298 // If a target was set and the target no longer exists them just walk to the rally point. 299 if (data && data.target){ 300 if (! Engine.QueryInterface(data.target, IID_Position)){ 301 command = "walk"; 302 } 303 } 304 305 switch (command) 306 { 307 case "gather": 308 ProcessCommand(cmpOwnership.GetOwner(), { 309 "type": "gatherNearPosition", 310 "entities": spawnedEnts, 311 "x": rallyPos.x, 312 "z": rallyPos.z, 313 "resourceType": data.resourceType, 314 "queued": false 315 }); 316 break; 317 case "repair": 318 case "build": 319 ProcessCommand(cmpOwnership.GetOwner(), { 320 "type": "repair", 321 "entities": spawnedEnts, 322 "target": data.target, 323 "queued": false, 324 "autocontinue": true 325 }); 326 break; 327 case "garrison": 328 ProcessCommand(cmpOwnership.GetOwner(), { 329 "type": "garrison", 330 "entities": spawnedEnts, 331 "target": data.target, 332 "queued": false 333 }); 334 break; 335 case "attack": 336 ProcessCommand(cmpOwnership.GetOwner(), { 337 "type": "attack", 338 "entities": spawnedEnts, 339 "target": data.target, 340 "queued": false 341 }); 342 break; 343 default: 344 ProcessCommand(cmpOwnership.GetOwner(), { 345 "type": "walk", 346 "entities": spawnedEnts, 347 "x": rallyPos.x, 348 "z": rallyPos.z, 349 "queued": false 350 }); 351 } 296 352 } 297 353 } 298 354 -
binaries/data/mods/public/simulation/components/UnitAI.js
284 284 }, 285 285 286 286 "Order.Gather": function(msg) { 287 287 288 // If the target is still alive, we need to kill it first 288 289 if (this.MustKillGatherTarget(this.order.data.target) && this.CheckTargetVisible(this.order.data.target)) 289 290 { … … 315 316 this.SetNextState("INDIVIDUAL.GATHER.GATHERING"); 316 317 } 317 318 }, 319 320 "Order.GatherNearPosition": function(msg){ 321 // Move the unit to the position to gather from. 322 this.MoveToPoint(this.order.data.x, this.order.data.z); 323 this.SetNextState("INDIVIDUAL.GATHER.WALKING"); 324 }, 318 325 319 326 "Order.ReturnResource": function(msg) { 320 327 // Try to move to the dropsite … … 408 415 cmpFormation.CallMemberFunction("Gather", [msg.data.target, false]); 409 416 cmpFormation.Disband(); 410 417 }, 418 419 "Order.GatherNearPosition": function(msg){ 420 var cmpFormation = Engine.QueryInterface(this.entity, IID_Formation); 421 cmpFormation.CallMemberFunction("GatherNearPosition", [[msg.data.x, msg.data.z], msg.data.type, false]); 422 cmpFormation.Disband(); 423 }, 411 424 412 425 "Order.ReturnResource": function(msg) { 413 426 // TODO: see notes in Order.Attack … … 815 828 this.SetNextState("GATHERING"); 816 829 }, 817 830 }, 831 832 // Walking to a good place to gather resoruce near, ued by gatherNearPosition 833 "WALKING": { 834 "enter": function() { 835 this.SelectAnimation("move"); 836 }, 818 837 838 "MoveCompleted": function(msg) { 839 var resourceType = this.order.data.type; 840 841 // Try to find another nearby target of the same specific type 842 var nearby = this.FindNearbyResource(function (ent, type) { 843 if (type.generic === "treasure"){ 844 return (type.specific == resourceType); 845 } 846 return (type.generic == resourceType); 847 }); 848 849 // If there is a nearby resource start gathering 850 if (nearby) 851 { 852 this.Gather(nearby, false); 853 return; 854 } 855 856 // Couldn't find nearby resources, so give up 857 this.FinishOrder(); 858 859 }, 860 }, 861 819 862 "GATHERING": { 820 863 "enter": function() { 821 864 this.StartTimer(1000, 1000); … … 2179 2222 switch (order.type) 2180 2223 { 2181 2224 case "Walk": 2225 case "GatherNearPosition": 2182 2226 // Add the distance to the target point 2183 2227 var dx = order.data.x - pos.x; 2184 2228 var dz = order.data.z - pos.z; … … 2307 2351 this.AddOrder("Gather", { "target": target, "type": type, "lastPos": lastPos }, queued); 2308 2352 }; 2309 2353 2354 UnitAI.prototype.GatherNearPosition = function(position, type, queued){ 2355 this.AddOrder("GatherNearPosition", { "type": type, "x": position[0], "z": position[1] }, queued); 2356 } 2357 2310 2358 UnitAI.prototype.ReturnResource = function(target, queued) 2311 2359 { 2312 2360 if (!this.CanReturnResource(target, true)) -
binaries/data/mods/public/simulation/components/RallyPoint.js
16 16 } 17 17 }; 18 18 19 RallyPoint.prototype. Unset= function()19 RallyPoint.prototype.GetPosition = function() 20 20 { 21 this.pos = undefined;21 return this.pos; 22 22 }; 23 23 24 RallyPoint.prototype.GetPosition = function() 24 // Extra data for the rally point, should have a command property and then helpful data for that command 25 // See getActionInfo in gui/input.js 26 RallyPoint.prototype.SetData = function(data) 25 27 { 26 return this.pos;28 this.data = data; 27 29 }; 28 30 31 RallyPoint.prototype.GetData = function() 32 { 33 return this.data; 34 }; 35 36 RallyPoint.prototype.Unset = function() 37 { 38 this.pos = undefined; 39 this.data = undefined; 40 }; 41 42 29 43 Engine.RegisterComponentType(IID_RallyPoint, "RallyPoint", RallyPoint);