Ticket #2160: regicide_garrison_option_v2.patch
File regicide_garrison_option_v2.patch, 15.7 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/gamesetup/gamesetup.js
498 498 "ExploreMap": "exploreMap", 499 499 "DisableTreasures": "disableTreasures", 500 500 "LockTeams": "lockTeams", 501 "LastManStanding" : "lastManStanding", 501 "LastManStanding": "lastManStanding", 502 "RegicideGarrison": "regicideGarrison", 502 503 "CheatsEnabled": "enableCheats" 503 504 }; 504 505 … … 1183 1184 { 1184 1185 delete g_GameAttributes.settings.WonderDuration; 1185 1186 delete g_GameAttributes.settings.LastManStanding; 1187 delete g_GameAttributes.settings.RegicideGarrison; 1186 1188 } 1187 1189 1188 1190 if (mapSettings.PlayerData) … … 1380 1382 setGUIBoolean("revealMap", "revealMapText", !!mapSettings.RevealMap); 1381 1383 setGUIBoolean("lockTeams", "lockTeamsText", !!mapSettings.LockTeams); 1382 1384 setGUIBoolean("lastManStanding", "lastManStandingText", !!mapSettings.LastManStanding); 1385 setGUIBoolean("regicideGarrison", "regicideGarrisonText", !!mapSettings.RegicideGarrison); 1383 1386 setGUIBoolean("enableRating", "enableRatingText", !!mapSettings.RatingEnabled); 1384 1387 1385 1388 Engine.GetGUIObjectByName("optionWonderDuration").hidden = … … 1386 1389 g_GameAttributes.settings.GameType && 1387 1390 g_GameAttributes.settings.GameType != "wonder"; 1388 1391 Engine.GetGUIObjectByName("optionLastManStanding").hidden = mapSettings.LockTeams; 1392 Engine.GetGUIObjectByName("optionRegicideGarrison").hidden = 1393 g_GameAttributes.settings.GameType && 1394 g_GameAttributes.settings.GameType != "regicide"; 1389 1395 1390 1396 Engine.GetGUIObjectByName("cheatWarningText").hidden = !g_IsNetworked || !mapSettings.CheatsEnabled; 1391 1397 … … 1403 1409 1404 1410 for (let ctrl of ["victoryCondition", "wonderDuration", "populationCap", 1405 1411 "startingResources", "ceasefire", "revealMap", 1406 "exploreMap", "disableTreasures", "lockTeams", "lastManStanding"]) 1412 "exploreMap", "disableTreasures", "lockTeams", 1413 "lastManStanding", "regicideGarrison"]) 1407 1414 hideControl(ctrl, ctrl + "Text", notScenario); 1408 1415 1409 1416 Engine.GetGUIObjectByName("civResetButton").hidden = !notScenario; -
binaries/data/mods/public/gui/gamesetup/gamesetup.xml
335 335 </object> 336 336 </object> 337 337 338 <object name="option PopulationCap" size="14 98 94% 126">338 <object name="optionRegicideGarrison" size="14 98 94% 126"> 339 339 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 340 <translatableAttribute id="caption">Hero Garrison:</translatableAttribute> 341 </object> 342 <object name="regicideGarrisonText" size="40% 0 100% 28" type="text" style="ModernLeftLabelText"/> 343 <object name="regicideGarrison" size="40%+10 5 40%+30 100%-5" type="checkbox" style="ModernTickBox" hidden="true" tooltip_style="onscreenToolTip"> 344 <translatableAttribute id="tooltip">Toggle whether heroes can be garrisoned.</translatableAttribute> 345 </object> 346 </object> 347 348 <object name="optionPopulationCap" size="14 128 94% 156"> 349 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 340 350 <translatableAttribute id="caption">Population Cap:</translatableAttribute> 341 351 </object> 342 352 <object name="populationCapText" size="40% 0 100% 100%" type="text" style="ModernLeftLabelText"/> … … 345 355 </object> 346 356 </object> 347 357 348 <object name="optionStartingResources" size="14 1 28 94% 156">358 <object name="optionStartingResources" size="14 158 94% 186"> 349 359 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 350 360 <translatableAttribute id="caption">Starting Resources:</translatableAttribute> 351 361 </object> … … 355 365 </object> 356 366 </object> 357 367 358 <object name="optionCeasefire" size="14 1 58 94% 186">368 <object name="optionCeasefire" size="14 188 94% 216"> 359 369 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 360 370 <translatableAttribute id="caption">Ceasefire:</translatableAttribute> 361 371 </object> … … 440 450 name="hideMoreOptions" 441 451 type="button" 442 452 style="StoneButton" 443 size="50%-70 4 28 50%+70 456"453 size="50%-70 458 50%+70 486" 444 454 tooltip_style="onscreenToolTip" 445 455 hotkey="cancel" 446 456 > -
binaries/data/mods/public/maps/scripts/Regicide.js
6 6 7 7 Trigger.prototype.InitRegicideGame = function(msg) 8 8 { 9 let cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager); 10 this.regicideGarrison = cmpEndGameManager.GetGameTypeSettings().regicideGarrison; 11 9 12 let playersCivs = []; 10 13 for (let playerID = 1; playerID < TriggerHelper.GetNumberOfPlayers(); ++playerID) 11 14 playersCivs[playerID] = QueryPlayerIDInterface(playerID).GetCiv(); … … 89 92 90 93 hero = hero[0]; 91 94 95 if (!this.regicideGarrison && !isShip) 96 QueryPlayerIDInterface(playerID).AddDisabledGarrisonClass("Hero"); 97 92 98 if (isShip) 93 99 { 94 100 let cmpUnitAI = Engine.QueryInterface(hero, IID_UnitAI); … … 102 108 return undefined; 103 109 }; 104 110 111 Trigger.prototype.CheckRegicideHeroGarrison = function(data) 112 { 113 if (!data.removed.length) 114 return; 115 116 if (this.regicideHeroes.indexOf(data.removed[0]) == -1 || this.regicideGarrison) 117 return; 118 119 QueryOwnerInterface(data.removed[0]).AddDisabledGarrisonClass("Hero"); 120 }; 121 105 122 let cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger); 106 123 cmpTrigger.regicideHeroes = []; 124 cmpTrigger.regicideGarrison = false; 107 125 cmpTrigger.DoAfterDelay(0, "InitRegicideGame", {}); 108 126 cmpTrigger.RegisterTrigger("OnOwnershipChanged", "CheckRegicideDefeat", { "enabled": true }); 127 cmpTrigger.RegisterTrigger("OnGarrisonedUnitsChanged", "CheckRegicideHeroGarrison", { "enabled": true }); -
binaries/data/mods/public/simulation/components/GarrisonHolder.js
111 111 112 112 /** 113 113 * Returns an array of unit classes which can be garrisoned inside this 114 * particualar entity. Obtained from the entity's template114 * particualar entity. 115 115 */ 116 116 GarrisonHolder.prototype.GetAllowedClasses = function() 117 117 { 118 return this.template.List._string; 118 let allowedClasses = this.template.List._string.split(/\s+/); 119 let disabledClasses = QueryOwnerInterface(this.entity).GetDisabledGarrisonClasses(); 120 let classes = []; 121 122 for (let className of allowedClasses) 123 { 124 for (let disabled of disabledClasses) 125 className += "+!" + disabled; 126 classes.push(className); 127 } 128 129 return classes; 119 130 }; 120 131 121 132 /** … … 200 211 if (!cmpIdentity) 201 212 return false; 202 213 var entityClasses = cmpIdentity.GetClassesList(); 214 let cmpPlayer = QueryOwnerInterface(entity); 215 if (cmpPlayer && entityClasses.some(className => cmpPlayer.GetDisabledGarrisonClasses().indexOf(className) != -1)) 216 return false; 217 203 218 return MatchesClassList(entityClasses, this.template.List._string); 204 219 }; 205 220 -
binaries/data/mods/public/simulation/components/interfaces/Trigger.js
11 11 * sent from Player component. 12 12 */ 13 13 Engine.RegisterMessageType("DisabledTechnologiesChanged"); 14 15 /** 16 * Message of the form {} 17 * sent from Player component. 18 */ 19 Engine.RegisterMessageType("DisabledGarrisonClassesChanged"); -
binaries/data/mods/public/simulation/components/Player.js
53 53 this.disabledTemplates = {}; 54 54 this.disabledTechnologies = {}; 55 55 this.startingTechnologies = []; 56 this.disabledGarrisonClasses = []; 56 57 }; 57 58 58 59 Player.prototype.SetPlayerID = function(id) … … 853 854 this.startingTechnologies = techs; 854 855 }; 855 856 857 Player.prototype.AddDisabledGarrisonClass = function(className) 858 { 859 if (this.disabledGarrisonClasses.indexOf(className) != -1) 860 return; 861 this.disabledGarrisonClasses.push(className); 862 Engine.BroadcastMessage(MT_DisabledGarrisonClassesChanged, {}); 863 }; 864 865 Player.prototype.RemoveDisabledGarrisonClass = function(className) 866 { 867 this.disabledGarrisonClasses.splice(this.disabledGarrisonClasses.indexOf(className), 1); 868 Engine.BroadcastMessage(MT_DisabledGarrisonClassesChanged, {}); 869 }; 870 871 Player.prototype.SetDisabledGarrisonClasses = function(classes) 872 { 873 this.disabledGarrisonClasses = classes; 874 Engine.BroadcastMessage(MT_DisabledGarrisonClassesChanged, {}); 875 }; 876 877 Player.prototype.GetDisabledGarrisonClasses = function() 878 { 879 return this.disabledGarrisonClasses; 880 }; 881 856 882 Engine.RegisterComponentType(IID_Player, "Player", Player); -
binaries/data/mods/public/simulation/components/tests/test_GarrisonHolder.js
1 Engine.LoadHelperScript("Player.js"); 2 Engine.LoadHelperScript("ValueModification.js"); 3 Engine.LoadComponentScript("interfaces/GarrisonHolder.js"); 4 Engine.LoadComponentScript("interfaces/Health.js"); 5 Engine.LoadComponentScript("interfaces/Trigger.js"); 6 Engine.LoadComponentScript("interfaces/Player.js"); 7 Engine.LoadComponentScript("GarrisonHolder.js"); 8 Engine.LoadComponentScript("Identity.js"); 9 Engine.LoadComponentScript("Player.js"); 10 Engine.LoadComponentScript("PlayerManager.js"); 11 12 let garrisonEnt = 15; 13 let unitEnt = 33; 14 let entHP = 1000; 15 let playerEnt = 1; 16 17 AddMock(SYSTEM_ENTITY, IID_PlayerManager, { 18 "GetPlayerByID": (id) => playerEnt, 19 }); 20 21 AddMock(garrisonEnt, IID_Health, { 22 "GetHitpoints": () => entHP, 23 "Decrease": hp => { 24 entHP = Math.max(entHP - hp, 0); 25 }, 26 }); 27 28 AddMock(playerEnt, IID_Player, { 29 "IsAlly": (id) => id == 1, 30 "IsEnemy": (id) => id != 1, 31 "GetPlayerID": () => 1, 32 "GetDisabledGarrisonClasses": () => [], 33 "QueryOwnerInterface": (unitEnt) => playerEnt, 34 }); 35 36 AddMock(unitEnt, IID_Identity, { 37 "GetClassesList": () => ["Hero", "Infantry"], 38 "GetVisibleClassesList": () => ["Hero", "Infantry"], 39 "HasClass": () => true, 40 }); 41 42 AddMock(garrisonEnt, IID_Ownership, { 43 "GetOwner": () => playerEnt, 44 }); 45 46 AddMock(playerEnt, IID_Ownership, { 47 "GetOwner": () => playerEnt, 48 }); 49 50 let cmpGarrisonHolder = ConstructComponent(garrisonEnt, "GarrisonHolder", { 51 "LoadingRange": "2.0", 52 "Max": "20", 53 "List": { "_string": "Support Infantry Cavalry"}, 54 "entity": garrisonEnt, 55 }); 56 57 let cmpPlayer = ConstructComponent(playerEnt, "Player") 58 59 TS_ASSERT_EQUALS(cmpGarrisonHolder.GetGarrisonedEntitiesCount(), 0); 60 TS_ASSERT_EQUALS(cmpGarrisonHolder.entities.length, 0); 61 TS_ASSERT_EQUALS(cmpGarrisonHolder.visibleGarrisonPoints.length, 0); 62 TS_ASSERT_EQUALS(+cmpGarrisonHolder.template.Max, 20); 63 TS_ASSERT_EQUALS(cmpGarrisonHolder.GetLoadingRange().max, 2.0); 64 TS_ASSERT_EQUALS(cmpGarrisonHolder.IsGarrisoningAllowed(), true); 65 TS_ASSERT_EQUALS(cmpGarrisonHolder.AllowedToGarrison(unitEnt), true); 66 TS_ASSERT_EQUALS(cmpGarrisonHolder.GetAllowedClasses().length, 3); 67 68 cmpPlayer.AddDisabledGarrisonClass("Hero"); 69 TS_ASSERT(cmpGarrisonHolder.GetAllowedClasses(unitEnt)[0].indexOf("!Hero") != 1); -
binaries/data/mods/public/simulation/components/tests/test_Player.js
Property changes on: binaries/data/mods/public/simulation/components/tests/test_GarrisonHolder.js ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property
1 1 Engine.LoadHelperScript("ValueModification.js"); 2 Engine.LoadComponentScript("interfaces/EndGameManager.js") 3 Engine.LoadComponentScript("interfaces/TechnologyManager.js") 4 Engine.LoadComponentScript("interfaces/Timer.js") 5 Engine.LoadComponentScript("EndGameManager.js") 2 Engine.LoadComponentScript("interfaces/EndGameManager.js"); 3 Engine.LoadComponentScript("interfaces/TechnologyManager.js"); 4 Engine.LoadComponentScript("interfaces/Timer.js"); 5 Engine.LoadComponentScript("interfaces/Trigger.js"); 6 Engine.LoadComponentScript("interfaces/Player.js"); 7 Engine.LoadComponentScript("EndGameManager.js"); 6 8 Engine.LoadComponentScript("Player.js"); 7 Engine.LoadComponentScript("Timer.js") 9 Engine.LoadComponentScript("Timer.js"); 8 10 9 11 ConstructComponent(SYSTEM_ENTITY, "EndGameManager"); 10 12 ConstructComponent(SYSTEM_ENTITY, "Timer"); 11 13 12 var cmpPlayer = ConstructComponent(10, "Player"); 14 let playerEntity = 1; 15 let cmpPlayer = ConstructComponent(playerEntity, "Player"); 13 16 14 17 TS_ASSERT_EQUALS(cmpPlayer.GetPopulationCount(), 0); 15 18 TS_ASSERT_EQUALS(cmpPlayer.GetPopulationLimit(), 0); 19 TS_ASSERT_EQUALS(cmpPlayer.GetDisabledGarrisonClasses().length, 0); 20 21 cmpPlayer.AddDisabledGarrisonClass("Champion"); 22 TS_ASSERT_EQUALS(cmpPlayer.GetDisabledGarrisonClasses().length, 1); 23 TS_ASSERT_EQUALS(cmpPlayer.GetDisabledGarrisonClasses()[0], "Champion"); 24 25 cmpPlayer.AddDisabledGarrisonClass("Hero"); 26 TS_ASSERT_EQUALS(cmpPlayer.GetDisabledGarrisonClasses().length, 2); 27 TS_ASSERT_EQUALS(cmpPlayer.GetDisabledGarrisonClasses()[1], "Hero"); 28 29 cmpPlayer.RemoveDisabledGarrisonClass("Champion"); 30 TS_ASSERT_EQUALS(cmpPlayer.GetDisabledGarrisonClasses().length, 1); 31 TS_ASSERT_EQUALS(cmpPlayer.GetDisabledGarrisonClasses()[0], "Hero"); 32 TS_ASSERT_EQUALS(cmpPlayer.GetDisabledGarrisonClasses().length, 1); 33 34 cmpPlayer.SetDisabledGarrisonClasses(["Champion", "Elephant"]); 35 TS_ASSERT_EQUALS(cmpPlayer.GetDisabledGarrisonClasses().indexOf("Hero"), -1); 36 TS_ASSERT_EQUALS(cmpPlayer.GetDisabledGarrisonClasses().length, 2); 37 TS_ASSERT_EQUALS(cmpPlayer.GetDisabledGarrisonClasses()[1], "Elephant"); -
binaries/data/mods/public/simulation/components/Trigger.js
11 11 "CinemaPathEnded", 12 12 "CinemaQueueEnded", 13 13 "ConstructionStarted", 14 "GarrisonedUnitsChanged", 14 15 "Interval", 15 16 "OwnershipChanged", 16 17 "PlayerCommand", … … 265 266 this.CallEvent("PlayerWon", msg); 266 267 }; 267 268 269 Trigger.prototype.OnGlobalGarrisonedUnitsChanged = function(msg) 270 { 271 this.CallEvent("GarrisonedUnitsChanged", msg); 272 }; 273 268 274 /** 269 275 * Execute a function after a certain delay. 270 276 * -
binaries/data/mods/public/simulation/helpers/Setup.js
47 47 let gameTypeSettings = {}; 48 48 if (settings.WonderDuration) 49 49 gameTypeSettings.wonderDuration = settings.WonderDuration * 60 * 1000; 50 if (settings.GameType == "regicide") 51 gameTypeSettings.regicideGarrison = settings.RegicideGarrison; 50 52 if (settings.GameType) 51 53 cmpEndGameManager.SetGameType(settings.GameType, gameTypeSettings); 52 54