Ticket #1044: autogarrison-3.diff
File autogarrison-3.diff, 8.6 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/gui/session/input.js
295 295 } 296 296 } 297 297 298 // Don't allow the rally point to be set on any of the currently selected entities 298 // Don't allow the rally point to be set on any of the currently selected entities (used for unset) 299 // except if the target is a productionQueue and the autorallypoint hotkey is pressed 299 300 for (var i = 0; i < selection.length; i++) 301 { 300 302 if (target === selection[i]) 303 { 304 if (Engine.HotkeyIsPressed("session.autorallypoint") && targetState.production && targetState.production.entities.length) 305 break; 301 306 return {"possible": false}; 307 } 308 } 302 309 303 310 return {"possible": true, "data": data, "position": targetState.position, "cursor": cursor, "tooltip": tooltip}; 304 311 } … … 1788 1795 if (entity) 1789 1796 { 1790 1797 var entState = GetEntityState(entity); 1791 var template = GetTemplateData(entState.template);1792 var unitName = getEntityName(template);1793 1798 1794 1799 var playerID = Engine.GetPlayerID(); 1795 1800 var simState = GetSimState(); -
binaries/data/mods/public/simulation/components/ProductionQueue.js
442 442 }; 443 443 444 444 /* 445 * This function creates the entities and places them in world if possible. 446 * returns the number of successfully spawned entities. 445 * This function creates the entities and places them in world if possible 446 * and returns the number of successfully created entities. 447 * (some of these entities may be garrisoned directly if autogarrison, the others are spawned). 447 448 */ 448 449 ProductionQueue.prototype.SpawnUnits = function(templateName, count, metadata) 449 450 { … … 452 453 var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership); 453 454 var cmpRallyPoint = Engine.QueryInterface(this.entity, IID_RallyPoint); 454 455 456 var createdEnts = []; 455 457 var spawnedEnts = []; 456 458 457 459 if (this.entityCache.length == 0) … … 476 478 } 477 479 } 478 480 481 var cmpAutoGarrison = undefined; 482 if (cmpRallyPoint) 483 { 484 var data = cmpRallyPoint.GetData()[0]; 485 if (data && data.target == this.entity && data.command == "garrison") 486 cmpAutoGarrison = Engine.QueryInterface(this.entity, IID_GarrisonHolder); 487 } 488 479 489 for (var i = 0; i < count; ++i) 480 490 { 481 491 var ent = this.entityCache[0]; 482 var pos = cmpFootprint.PickSpawnPoint(ent); 483 if (pos.y < 0) 492 var cmpNewOwnership = Engine.QueryInterface(ent, IID_Ownership); 493 cmpNewOwnership.SetOwner(cmpOwnership.GetOwner()); 494 495 if (cmpAutoGarrison && cmpAutoGarrison.PerformGarrison(ent)) 484 496 { 485 // Fail: there wasn't any space to spawn the unit486 break;497 var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); 498 cmpUnitAI.Autogarrison(); 487 499 } 488 500 else 489 501 { 490 // Successfully spawned 491 var cmpNewPosition = Engine.QueryInterface(ent, IID_Position); 492 cmpNewPosition.JumpTo(pos.x, pos.z); 493 // TODO: what direction should they face in? 502 var pos = cmpFootprint.PickSpawnPoint(ent); 503 if (pos.y < 0) 504 { 505 // Fail: there wasn't any space to spawn the unit 506 break; 507 } 508 else 509 { 510 // Successfully spawned 511 var cmpNewPosition = Engine.QueryInterface(ent, IID_Position); 512 cmpNewPosition.JumpTo(pos.x, pos.z); 513 // TODO: what direction should they face in? 514 spawnedEnts.push(ent); 515 } 516 } 494 517 495 var cmpNewOwnership = Engine.QueryInterface(ent, IID_Ownership); 496 cmpNewOwnership.SetOwner(cmpOwnership.GetOwner()); 497 498 var cmpPlayerStatisticsTracker = QueryOwnerInterface(this.entity, IID_StatisticsTracker); 499 cmpPlayerStatisticsTracker.IncreaseTrainedUnitsCounter(); 518 var cmpPlayerStatisticsTracker = QueryOwnerInterface(this.entity, IID_StatisticsTracker); 519 cmpPlayerStatisticsTracker.IncreaseTrainedUnitsCounter(); 500 520 501 502 if (spawnedEnts.length == 0)503 521 // Play a sound, but only for the first in the batch (to avoid nasty phasing effects) 522 if (createdEnts.length == 0) 523 PlaySound("trained", ent); 504 524 505 this.entityCache.shift(); 506 spawnedEnts.push(ent); 507 } 525 this.entityCache.shift(); 526 createdEnts.push(ent); 508 527 } 509 528 510 529 if (spawnedEnts.length > 0) … … 518 537 { 519 538 var commands = GetRallyPointCommands(cmpRallyPoint, spawnedEnts); 520 539 for each(var com in commands) 521 {522 540 ProcessCommand(cmpOwnership.GetOwner(), com); 523 }524 541 } 525 542 } 543 } 526 544 545 if (createdEnts.length > 0) 546 { 527 547 Engine.PostMessage(this.entity, MT_TrainingFinished, { 528 "entities": spawnedEnts,548 "entities": createdEnts, 529 549 "owner": cmpOwnership.GetOwner(), 530 550 "metadata": metadata, 531 551 }); 532 552 } 533 553 534 return spawnedEnts.length;554 return createdEnts.length; 535 555 }; 536 556 537 557 /* -
binaries/data/mods/public/simulation/components/UnitAI.js
620 620 } 621 621 }, 622 622 623 "Order.Autogarrison": function(msg) { 624 this.SetNextState("INDIVIDUAL.AUTOGARRISON"); 625 }, 626 623 627 "Order.Cheering": function(msg) { 624 628 this.SetNextState("INDIVIDUAL.CHEERING"); 625 629 }, … … 2331 2335 }, 2332 2336 }, 2333 2337 2338 "AUTOGARRISON": { 2339 "enter": function() { 2340 this.isGarrisoned = true; 2341 return false; 2342 }, 2343 2344 "Order.Ungarrison": function() { 2345 if (this.FinishOrder()) 2346 return; 2347 }, 2348 2349 "leave": function() { 2350 this.isGarrisoned = false; 2351 } 2352 }, 2353 2334 2354 "CHEERING": { 2335 2355 "enter": function() { 2336 2356 // Unit is invulnerable while cheering … … 3980 4000 }; 3981 4001 3982 4002 /** 4003 * Adds autogarrison order to the queue (only used by ProductionQueue for auto-garrisoning) 4004 */ 4005 UnitAI.prototype.Autogarrison = function() 4006 { 4007 this.AddOrder("Autogarrison", null, false); 4008 }; 4009 4010 /** 3983 4011 * Adds gather order to the queue, forced by the player 3984 4012 * until the target is reached 3985 4013 */ -
binaries/data/mods/public/simulation/components/GarrisonHolder.js
157 157 */ 158 158 GarrisonHolder.prototype.Garrison = function(entity) 159 159 { 160 var cmpPosition = Engine.QueryInterface(entity, IID_Position); 161 if (!cmpPosition) 162 return false; 163 164 if (!this.PerformGarrison(entity)) 165 return false; 166 167 cmpPosition.MoveOutOfWorld(); 168 return true; 169 }; 170 171 GarrisonHolder.prototype.PerformGarrison = function(entity) 172 { 160 173 if (!this.HasEnoughHealth()) 161 174 return false; 162 175 … … 167 180 if (this.entities.length >= this.GetCapacity()) 168 181 return false; 169 182 170 var cmpPosition = Engine.QueryInterface(entity, IID_Position);171 if (!cmpPosition)172 return false;173 174 183 if (!this.timer && this.GetHealRate() > 0) 175 184 { 176 185 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); … … 179 188 180 189 // Actual garrisoning happens here 181 190 this.entities.push(entity); 182 cmpPosition.MoveOutOfWorld();183 191 this.UpdateGarrisonFlag(); 184 192 var cmpProductionQueue = Engine.QueryInterface(entity, IID_ProductionQueue); 185 193 if (cmpProductionQueue) … … 260 268 if (rallyPos) 261 269 { 262 270 var commands = GetRallyPointCommands(cmpRallyPoint, entities); 271 // ignore the rally point if it is autogarrison 272 if (commands[0].type == "garrison" && commands[0].target == this.entity) 273 return; 263 274 for each (var com in commands) 264 275 { 265 276 ProcessCommand(cmpOwnership.GetOwner(), com); -
binaries/data/config/default.cfg
276 276 hotkey.session.massbarter = Shift ; Modifier to barter bunch of resources 277 277 hotkey.session.masstribute = Shift ; Modifier to tribute bunch of resources 278 278 hotkey.session.unloadtype = Shift ; Modifier to unload all units of type 279 hotkey.session.autorallypoint = Ctrl ; Modifier to set the rally point of one building on itself 279 280 hotkey.session.deselectgroup = Ctrl ; Modifier to deselect units when clicking group icon, instead of selecting 280 281 hotkey.session.rotate.cw = RightBracket ; Rotate building placement preview clockwise 281 282 hotkey.session.rotate.ccw = LeftBracket ; Rotate building placement preview anticlockwise