Ticket #1432: one_hero_2012_05_24.diff
File one_hero_2012_05_24.diff, 12.2 KB (added by , 12 years ago) |
---|
-
binaries/data/mods/public/gui/session/unit_commands.js
129 129 } 130 130 131 131 // Sets up "unit panels" - the panels with rows of icons (Helper function for updateUnitDisplay) 132 function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)132 function setupUnitPanel(guiName, usedPanels, unitEntState, playerState, items, callback) 133 133 { 134 134 usedPanels[guiName] = 1; 135 135 var numberOfItems = items.length; … … 253 253 tooltip += "\n" + getEntitySpeed(template); 254 254 255 255 tooltip += "\n\n[font=\"serif-bold-13\"]Shift-click[/font][font=\"serif-13\"] to train " + trainNum + ".[/font]"; 256 257 256 break; 258 257 259 258 case CONSTRUCTION: … … 338 337 icon.sprite = "stretched:session/icons/single/" + item.icon; 339 338 340 339 } 340 else if (guiName == "Training") 341 { 342 if (template.icon) 343 { 344 icon.sprite = "stretched:session/portraits/" + template.icon; 345 } 346 } 341 347 else if (template.icon) 342 348 { 343 349 icon.sprite = "stretched:session/portraits/" + template.icon; … … 390 396 } 391 397 392 398 // Sets up "unit barter panel" - special case for setupUnitPanel 393 function setupUnitBarterPanel(unitEntState )399 function setupUnitBarterPanel(unitEntState, playerState) 394 400 { 395 401 // Amount of player's resource to exchange 396 402 var amountToSell = BARTER_RESOURCE_AMOUNT_TO_SELL; … … 460 466 var player = Engine.GetPlayerID(); 461 467 if (entState.player == player || g_DevSettings.controlAll) 462 468 { 469 // Get player state to check some constraints 470 // e.g. presence of a hero or build limits 471 var simState = Engine.GuiInterfaceCall("GetSimulationState"); 472 var playerState = simState.players[player]; 473 463 474 if (entState.attack) // TODO - this should be based on some AI properties 464 475 { 465 476 //usedPanels["Stance"] = 1; … … 472 483 } 473 484 474 485 if (selection.length > 1) 475 setupUnitPanel("Selection", usedPanels, entState, g_Selection.groups.getTemplateNames(),486 setupUnitPanel("Selection", usedPanels, entState, playerState, g_Selection.groups.getTemplateNames(), 476 487 function (entType) { changePrimarySelectionGroup(entType); } ); 477 488 478 489 var commands = getEntityCommandsList(entState); 479 490 if (commands.length) 480 setupUnitPanel("Command", usedPanels, entState, commands,491 setupUnitPanel("Command", usedPanels, entState, playerState, commands, 481 492 function (item) { performCommand(entState.id, item.name); } ); 482 493 483 494 if (entState.garrisonHolder) 484 495 { 485 496 var groups = new EntityGroups(); 486 497 groups.add(entState.garrisonHolder.entities); 487 setupUnitPanel("Garrison", usedPanels, entState, groups.getTemplateNames(),498 setupUnitPanel("Garrison", usedPanels, entState, playerState, groups.getTemplateNames(), 488 499 function (item) { unload(entState.id, groups.getEntsByName(item)[0]); } ); 489 500 } 490 501 491 502 var formations = getEntityFormationsList(entState); 492 503 if (isUnit(entState) && !isAnimal(entState) && !entState.garrisonHolder && formations.length) 493 504 { 494 setupUnitPanel("Formation", usedPanels, entState, formations,505 setupUnitPanel("Formation", usedPanels, entState, playerState, formations, 495 506 function (item) { performFormation(entState.id, item); } ); 496 507 } 497 508 … … 500 511 var stances = ["violent", "aggressive", "passive", "defensive", "stand"]; 501 512 if (isUnit(entState) && !isAnimal(entState) && !entState.garrisonHolder && stances.length) 502 513 { 503 setupUnitPanel("Stance", usedPanels, entState, stances,514 setupUnitPanel("Stance", usedPanels, entState, playerState, stances, 504 515 function (item) { performStance(entState.id, item); } ); 505 516 } 506 517 … … 508 519 if (entState.barterMarket) 509 520 { 510 521 usedPanels["Barter"] = 1; 511 setupUnitBarterPanel(entState );522 setupUnitBarterPanel(entState, playerState); 512 523 } 513 524 514 525 if (entState.buildEntities && entState.buildEntities.length) 515 526 { 516 setupUnitPanel("Construction", usedPanels, entState, entState.buildEntities, startBuildingPlacement);527 setupUnitPanel("Construction", usedPanels, entState, playerState, entState.buildEntities, startBuildingPlacement); 517 528 // isInvisible = false; 518 529 } 519 530 520 531 if (entState.training && entState.training.entities.length) 521 532 { 522 setupUnitPanel("Training", usedPanels, entState, entState.training.entities,533 setupUnitPanel("Training", usedPanels, entState, playerState, entState.training.entities, 523 534 function (trainEntType) { addToTrainingQueue(entState.id, trainEntType); } ); 524 535 // isInvisible = false; 525 536 } 526 537 527 538 if (entState.training && entState.training.queue.length) 528 setupUnitPanel("Queue", usedPanels, entState, entState.training.queue,539 setupUnitPanel("Queue", usedPanels, entState, playerState, entState.training.queue, 529 540 function (item) { removeFromTrainingQueue(entState.id, item.id); } ); 530 541 531 542 // supplementalDetailsPanel.hidden = false; -
binaries/data/mods/public/simulation/components/Player.js
24 24 this.state = "active"; // game state - one of "active", "defeated", "won" 25 25 this.diplomacy = []; // array of diplomatic stances for this player with respect to other players (including gaia and self) 26 26 this.conquestCriticalEntitiesCount = 0; // number of owned units with ConquestCritical class 27 this.heroesCount = 0; // number of owned units with Hero class 27 28 this.phase = "village"; 28 29 this.startCam = undefined; 29 30 this.controlAllUnits = false; … … 328 329 Player.prototype.OnGlobalOwnershipChanged = function(msg) 329 330 { 330 331 var isConquestCritical = false; 331 332 var isHero = false; 332 333 // Load class list only if we're going to need it 333 334 if (msg.from == this.playerID || msg.to == this.playerID) 334 335 { 335 336 var cmpIdentity = Engine.QueryInterface(msg.entity, IID_Identity); 336 337 if (cmpIdentity) 337 338 { 338 var classes = cmpIdentity.GetClassesList();339 is ConquestCritical = classes.indexOf("ConquestCritical") != -1;339 isConquestCritical = cmpIdentity.HasClass("ConquestCritical"); 340 isHero = cmpIdentity.HasClass("Hero"); 340 341 } 341 342 } 342 343 343 if (msg.from == this.playerID) 344 344 { 345 345 if (isConquestCritical) 346 this.conquestCriticalEntitiesCount--; 347 346 this.conquestCriticalEntitiesCount--; 347 if (isHero) 348 this.heroesCount--; 348 349 var cost = Engine.QueryInterface(msg.entity, IID_Cost); 349 350 if (cost) 350 351 { … … 352 353 this.popBonuses -= cost.GetPopBonus(); 353 354 } 354 355 } 355 356 356 if (msg.to == this.playerID) 357 357 { 358 358 if (isConquestCritical) 359 359 this.conquestCriticalEntitiesCount++; 360 360 if (isHero) 361 this.heroesCount++; 361 362 var cost = Engine.QueryInterface(msg.entity, IID_Cost); 362 363 if (cost) 363 364 { … … 382 383 } 383 384 }; 384 385 386 Player.prototype.IncreaseHeroesCount = function() 387 { 388 this.heroesCount++; 389 } 390 391 Player.prototype.DecreaseHeroesCount = function() 392 { 393 this.heroesCount--; 394 } 395 396 Player.prototype.HasHero = function() 397 { 398 return this.heroesCount != 0; 399 } 400 385 401 Engine.RegisterComponentType(IID_Player, "Player", Player); -
binaries/data/mods/public/simulation/components/GuiInterface.js
70 70 "state": cmpPlayer.GetState(), 71 71 "team": cmpPlayer.GetTeam(), 72 72 "phase": cmpPlayer.GetPhase(), 73 "hasHero": cmpPlayer.HasHero(), 73 74 "isAlly": allies, 74 75 "isEnemy": enemies, 75 76 "buildLimits": cmpPlayerBuildLimits.GetLimits(), -
binaries/data/mods/public/simulation/components/TrainingQueue.js
90 90 if (!cmpPlayer.TrySubtractResources(totalCosts)) 91 91 return; 92 92 93 // If we train a hero, state this in player compoment 94 var isHero = TemplateHasIdentityClass(template, "Hero"); 95 if (isHero) 96 cmpPlayer.IncreaseHeroesCount(); 97 93 98 this.queue.push({ 94 99 "id": this.nextID++, 95 100 "player": cmpPlayer.GetPlayerID(), … … 102 107 "timeTotal": time*1000, 103 108 "timeRemaining": time*1000, 104 109 }); 110 105 111 Engine.PostMessage(this.entity, MT_TrainingQueueChanged, { }); 106 112 107 113 // If this is the first item in the queue, start the timer … … 142 148 143 149 var cmpPlayer = QueryPlayerIDInterface(item.player, IID_Player); 144 150 151 // If we trained a hero, state this in player compoment 152 var cmpTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); 153 var template = cmpTempMan.GetTemplate(item.template); 154 var isHero = TemplateHasIdentityClass(template, "Hero"); 155 if (isHero) 156 cmpPlayer.DecreaseHeroesCount(); 157 145 158 // Refund the resource cost for this batch 146 159 var totalCosts = {}; 147 160 for each (var r in ["food", "wood", "stone", "metal"]) … … 243 256 // so only create them once and use as needed 244 257 for (var i = 0; i < count; ++i) 245 258 { 246 this.entityCache.push(Engine.AddEntity(templateName)); 259 var ent = Engine.AddEntity(templateName); 260 this.entityCache.push(ent); 261 // If we create a hero entity - decrease heroes count, since it will be 262 // increased by Player.OnGlobalOwnershipChanged function, 263 // i.e. we replace 'trained' hero to a 'alive' one 264 var cmpIdentity = Engine.QueryInterface(ent, IID_Identity); 265 var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player); 266 var isHero = cmpIdentity.HasClass('Hero'); 267 if (isHero) 268 cmpPlayer.DecreaseHeroesCount(); 247 269 } 248 270 } 249 271 -
binaries/data/mods/public/simulation/helpers/Templates.js
1 /** 2 * Check whether template.Identity.Classes contains specified class 3 */ 4 function TemplateHasIdentityClass(template, className) 5 { 6 var hasClass = template.Identity && template.Identity.Classes && "_string" in template.Identity.Classes && template.Identity.Classes._string.indexOf(className) != -1; 7 return hasClass; 8 } 9 10 Engine.RegisterGlobal("TemplateHasIdentityClass", TemplateHasIdentityClass); 11 -
binaries/data/mods/public/simulation/helpers/Commands.js
119 119 120 120 case "train": 121 121 // Verify that the building can be controlled by the player 122 if ( CanControlUnit(cmd.entity, player, controlAllUnits))122 if (!CanControlUnit(cmd.entity, player, controlAllUnits)) 123 123 { 124 var queue = Engine.QueryInterface(cmd.entity, IID_TrainingQueue); 125 if (queue) 126 queue.AddBatch(cmd.template, +cmd.count, cmd.metadata); 124 if (g_DebugCommands) 125 { 126 warn("Invalid command: training building cannot be controlled by player "+player+": "+uneval(cmd)); 127 } 128 break; 127 129 } 128 else if (g_DebugCommands) 130 // Check hero restrictions 131 var cmpTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); 132 var template = cmpTempMan.GetTemplate(cmd.template); 133 var isHero = TemplateHasIdentityClass(template, "Hero"); 134 if (isHero) 129 135 { 130 warn("Invalid command: training building cannot be controlled by player "+player+": "+uneval(cmd)); 136 var cmpPlayer = QueryOwnerInterface(cmd.entity, IID_Player); 137 if (+cmd.count > 1) 138 { 139 if (g_DebugCommands) 140 { 141 warn("Invalid command: batch training isn't allowed for heroes: "+uneval(cmd)); 142 } 143 break; 144 } 145 if (cmpPlayer.HasHero()) 146 { 147 if (g_DebugCommands) 148 { 149 warn("Invalid command: can't train hero because player already has one: "+uneval(cmd)); 150 } 151 break; 152 } 131 153 } 154 155 var queue = Engine.QueryInterface(cmd.entity, IID_TrainingQueue); 156 if (queue) 157 queue.AddBatch(cmd.template, +cmd.count, cmd.metadata); 132 158 break; 133 159 134 160 case "stop-train":