Ticket #745: rallypoint_on_entities2011_12_5.diff
File rallypoint_on_entities2011_12_5.diff, 10.8 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 var cursor = ""; 180 181 // default to walking there 182 var data = {command: "walk"}; 183 if (targetState.garrisonHolder && playerOwned) 184 { 185 data.command = "garrison"; 186 data.target = target; 187 cursor = "action-garrison"; 188 } 189 else if (targetState.resourceSupply && (playerOwned || gaiaOwned)) 190 { 191 var resourceType = targetState.resourceSupply.type.generic; 192 if (resourceType === "treasure") 193 { 194 resourceType = targetState.resourceSupply.type.specific; 195 cursor = "action-gather-" + targetState.resourceSupply.type.generic; 196 } 197 else 198 { 199 cursor = "action-gather-" + targetState.resourceSupply.type.specific; 200 } 201 data.command = "gather"; 202 data.resourceType = resourceType; 203 } 204 else if (targetState.foundation && entState.buildEntities) 205 { 206 data.command = "build"; 207 data.target = target; 208 cursor = "action-build"; 209 } 210 else if (targetState.needsRepair && allyOwned) 211 { 212 data.command = "repair"; 213 data.target = target; 214 cursor = "action-repair"; 215 } 216 217 return {"possible": true, "data": data, "position": targetState.position, "cursor": cursor}; 218 } 166 219 167 220 for each (var entityID in selection) 168 221 { … … 312 365 return {"type": "build", "cursor": "action-repair", "target": target}; 313 366 else if (getActionInfo("attack", target).possible) 314 367 return {"type": "attack", "cursor": "action-attack", "target": target}; 315 else if( getActionInfo("set-rallypoint", target).possible)316 return {"type": "set-rallypoint" };368 else if((actionInfo = getActionInfo("set-rallypoint", target)).possible) 369 return {"type": "set-rallypoint", "cursor": actionInfo.cursor, "data": actionInfo.data, "position": actionInfo.position}; 317 370 else if(getActionInfo("unset-rallypoint", target).possible) 318 371 return {"type": "unset-rallypoint"}; 319 372 else if (getActionInfo("move", target).possible) 320 373 return {"type": "move"}; 321 374 } … … 932 985 return true; 933 986 934 987 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}); 988 var pos = undefined; 989 // if there is a position set in the action then use this so that when setting a 990 // rally point on an entity it is centered on that entity 991 if (action.position) 992 { 993 pos = action.position; 994 } 995 else 996 { 997 pos = Engine.GetTerrainAtPoint(ev.x, ev.y); 998 } 999 Engine.PostNetworkCommand({"type": "set-rallypoint", "entities": selection, "x": pos.x, "z": pos.z, "data": action.data}); 937 1000 // Display rally point at the new coordinates, to avoid display lag 938 1001 Engine.GuiInterfaceCall("DisplayRallyPoint", { 939 1002 "entities": selection, 940 "x": target.x,941 "z": target.z1003 "x": pos.x, 1004 "z": pos.z 942 1005 }); 943 1006 return true; 944 1007 -
binaries/data/mods/public/simulation/helpers/Commands.js
94 94 cmpUnitAI.Gather(cmd.target, cmd.queued); 95 95 }); 96 96 break; 97 98 case "gatherNearPosition": 99 var entities = FilterEntityList(cmd.entities, player, controlAllUnits); 100 GetFormationUnitAIs(entities).forEach(function(cmpUnitAI) { 101 cmpUnitAI.GatherNearPosition([cmd.x, cmd.z], cmd.resourceType, cmd.queued); 102 }); 103 break; 97 104 98 105 case "returnresource": 99 106 // Check dropsite is owned by player … … 288 295 { 289 296 var cmpRallyPoint = Engine.QueryInterface(ent, IID_RallyPoint); 290 297 if (cmpRallyPoint) 298 { 291 299 cmpRallyPoint.SetPosition(cmd.x, cmd.z); 300 cmpRallyPoint.SetData(cmd.data); 301 } 292 302 } 293 303 break; 294 304 -
binaries/data/mods/public/simulation/components/TrainingQueue.js
280 280 281 281 if (spawnedEnts.length > 0) 282 282 { 283 // If a rally point is set, walk towards it (in formation) 283 // If a rally point is set, walk towards it (in formation) using a suitable command based on where the 284 // rally point is placed. 284 285 if (cmpRallyPoint) 285 286 { 286 287 var rallyPos = cmpRallyPoint.GetPosition(); 287 288 if (rallyPos) 288 289 { 289 ProcessCommand(cmpOwnership.GetOwner(), { 290 "type": "walk", 291 "entities": spawnedEnts, 292 "x": rallyPos.x, 293 "z": rallyPos.z, 294 "queued": false 295 }); 290 ProcessCommand(cmpOwnership.GetOwner(), getRallyPointCommand(cmpRallyPoint, spawnedEnts)); 296 291 } 297 292 } 298 293 -
binaries/data/mods/public/simulation/components/GarrisonHolder.js
191 191 var rallyPos = cmpRallyPoint.GetPosition(); 192 192 if (rallyPos) 193 193 { 194 ProcessCommand(cmpOwnership.GetOwner(), { 195 "type": "walk", 196 "entities": entities, 197 "x": rallyPos.x, 198 "z": rallyPos.z, 199 "queued": false 200 }); 194 ProcessCommand(cmpOwnership.GetOwner(), getRallyPointCommand(cmpRallyPoint, entities)); 201 195 } 202 196 } 203 197 }; -
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 // Returns the data associated with this rally point. Uses the data structure: 32 // {"type": "walk/gather/garrison/...", "target": targetEntityId, "resourceType": "wood/food/metal/stone"} 33 // where target and resourceType are optional, also target may be an invalid entity, check for existance. 34 RallyPoint.prototype.GetData = function() 35 { 36 return this.data; 37 }; 38 39 RallyPoint.prototype.Unset = function() 40 { 41 this.pos = undefined; 42 this.data = undefined; 43 }; 44 45 29 46 Engine.RegisterComponentType(IID_RallyPoint, "RallyPoint", RallyPoint);