Ticket #2160: Regicide_v0.4.patch
File Regicide_v0.4.patch, 9.1 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/globalscripts/utility.js
function clone(o) 14 14 return o; 15 15 for (let key in o) 16 16 r[key] = clone(o[key]); 17 17 return r; 18 18 } 19 20 /** 21 * "Inside-out" implementation of Fisher-Yates shuffle 22 */ 23 function shuffleArray(source) 24 { 25 if (!source.length) 26 return []; 27 28 let result = [source[0]]; 29 for (let i = 1; i < source.length; ++i) 30 { 31 let j = Math.floor(Math.random() * i); 32 result[i] = result[j]; 33 result[j] = source[i]; 34 } 35 return result; 36 } -
binaries/data/mods/public/maps/random/rmgen/library.js
const MAX_MAP_SIZE = 512; 9 9 const MAP_BORDER_WIDTH = 3; 10 10 const FALLBACK_CIV = "athen"; 11 11 /** 12 12 * Constants needed for heightmap_manipulation.js 13 13 */ 14 const MAX_HEIGHT_RANGE = 0xFFFF / HEIGHT_UNITS_PER_METRE // Engine limit, Roughly 700 meters14 const MAX_HEIGHT_RANGE = 0xFFFF / HEIGHT_UNITS_PER_METRE; // Engine limit, Roughly 700 meters 15 15 const MIN_HEIGHT = - SEA_LEVEL; 16 16 const MAX_HEIGHT = MAX_HEIGHT_RANGE - SEA_LEVEL; 17 17 // Default angle for buildings 18 18 const BUILDING_ORIENTATION = - PI / 4; 19 19 … … function min(a, b) 90 90 { 91 91 return a < b ? a : b; 92 92 } 93 93 94 94 /** 95 * "Inside-out" implementation of Fisher-Yates shuffle96 */97 function shuffleArray(source)98 {99 if (!source.length)100 return [];101 102 let result = [source[0]];103 for (let i = 1; i < source.length; ++i)104 {105 let j = randInt(0, i);106 result[i] = result[j];107 result[j] = source[i];108 }109 return result;110 }111 112 /**113 95 * Retries the given function with those arguments as often as specified. 114 96 */ 115 97 function retryPlacing(placeFunc, placeArgs, retryFactor, amount, getResult) 116 98 { 117 99 let maxFail = amount * retryFactor; -
binaries/data/mods/public/maps/scripts/Regicide.js
1 Trigger.prototype.CheckRegicideDefeat = function(data) 2 { 3 if (data.entity == this.heroes[data.from]) 4 TriggerHelper.DefeatPlayer(data.from); 5 }; 6 7 Trigger.prototype.InitRegicideGame = function(msg) 8 { 9 let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); 10 11 // Get unique list of chosen civs 12 let civs = []; 13 let playersCivs = []; 14 for (let playerID = 1; playerID < TriggerHelper.GetNumberOfPlayers(); ++playerID) 15 { 16 let civ = QueryPlayerIDInterface(playerID).GetCiv(); 17 playersCivs[playerID] = civ; 18 19 if (civs.indexOf(civ) == -1) 20 civs.push(civ); 21 } 22 23 // Get all hero templates of these civs 24 let heroTemplates = {}; 25 for (let templateName of cmpTemplateManager.FindAllTemplates(false)) 26 { 27 if (templateName.substring(0,6) != "units/") 28 continue; 29 30 let identity = cmpTemplateManager.GetTemplate(templateName).Identity; 31 let classes = GetIdentityClasses(identity); 32 33 if (classes.indexOf("Hero") == -1) 34 continue; 35 36 if (!heroTemplates[identity.Civ]) 37 heroTemplates[identity.Civ] = []; 38 39 if (heroTemplates[identity.Civ].indexOf(templateName) == -1) 40 heroTemplates[identity.Civ].push({ 41 "templateName": templateName, 42 "classes": classes 43 }); 44 } 45 46 // Sort spawn points by preference 47 let getPreference = entity => { 48 let cmpIdentity = Engine.QueryInterface(entity, IID_Identity); 49 let classes = cmpIdentity.GetClassesList(); 50 51 if (classes.indexOf("CivilCentre") != -1) 52 return 3; 53 54 if (classes.indexOf("Structure") != -1) 55 return 2; 56 57 if (classes.indexOf("Ship") != -1) 58 return 1; 59 60 return 0; 61 }; 62 63 let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 64 for (let playerID = 1; playerID < TriggerHelper.GetNumberOfPlayers(); ++playerID) 65 { 66 let spawnPoints = cmpRangeManager.GetEntitiesByPlayer(playerID).sort((entity1, entity2) => 67 getPreference(entity2) - getPreference(entity1)); 68 69 this.heroes[playerID] = this.SpawnHero(playerID, heroTemplates[playersCivs[playerID]], spawnPoints); 70 } 71 }; 72 73 /** 74 * Spawn a random hero at one of the given locations (which are checked in order). 75 * Garrison it if the location is a ship. 76 * 77 * @param spawnPoints - entity IDs at which to spawn 78 */ 79 Trigger.prototype.SpawnHero = function(playerID, heroTemplates, spawnPoints) 80 { 81 for (let heroTemplate of shuffleArray(heroTemplates)) 82 for (let spawnPoint of spawnPoints) 83 { 84 let cmpPosition = Engine.QueryInterface(spawnPoint, IID_Position); 85 if (!cmpPosition || !cmpPosition.IsInWorld()) 86 continue; 87 88 let isShip = TriggerHelper.EntityHasClass(spawnPoint, "Ship"); 89 if (isShip) 90 { 91 let cmpGarrisonHolder = Engine.QueryInterface(spawnPoint, IID_GarrisonHolder); 92 if (cmpGarrisonHolder.IsFull() || 93 !MatchesClassList(heroTemplate.classes, cmpGarrisonHolder.GetAllowedClasses())) 94 continue; 95 } 96 97 let hero = TriggerHelper.SpawnUnits(spawnPoint, heroTemplate.templateName, 1, playerID); 98 if (!hero.length) 99 continue; 100 101 hero = hero[0]; 102 103 if (isShip) 104 { 105 let cmpUnitAI = Engine.QueryInterface(hero, IID_UnitAI); 106 cmpUnitAI.Garrison(spawnPoint); 107 } 108 109 return hero; 110 } 111 112 error("Couldn't spawn hero for player " + playerID); 113 return undefined; 114 }; 115 116 let cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger); 117 cmpTrigger.heroes = []; // TODO: what if gaia gets a hero? 118 cmpTrigger.DoAfterDelay(0, "InitRegicideGame", {}); 119 120 cmpTrigger.RegisterTrigger("OnOwnershipChanged", "CheckRegicideDefeat", { "enabled": true }); -
binaries/data/mods/public/maps/scripts/TriggerHelper.js
TriggerHelper.GetOwner = function(ent) 20 20 21 21 return -1; 22 22 }; 23 23 24 24 /** 25 * Can be used to "force" a building to spawn a group of entities.26 * Only works for buildings that can already train units.25 * Can be used to "force" a building/unit to spawn a group of entities. 26 * A default position is returned if no valid position is found. 27 27 * @param source Entity id of the point where they will be spawned from 28 28 * @param template Name of the template 29 29 * @param count Number of units to spawn 30 30 * @param owner Player id of the owner of the new units. By default, the owner 31 31 * of the source entity. -
binaries/data/mods/public/simulation/data/settings/victory_conditions/regicide.json
1 { 2 "TranslatedKeys": ["Title", "Description"], 3 "Data": 4 { 5 "Title": "Regicide", 6 "Description": "Keep your Hero alive to win", 7 "Scripts": 8 [ 9 "scripts/TriggerHelper.js", 10 "scripts/ConquestCommon.js", 11 "scripts/Conquest.js", 12 "scripts/Regicide.js" 13 ] 14 } 15 } -
binaries/data/mods/public/simulation/templates/units/maur_ship_trireme.xml
6 6 <Footprint> 7 7 <Square width="17.0" depth="45.0"/> 8 8 <Height>8.0</Height> 9 9 </Footprint> 10 10 <GarrisonHolder> 11 <Max> 40</Max>11 <Max>15</Max> 12 12 </GarrisonHolder> 13 13 <Health> 14 14 <Max op="add">200</Max> 15 15 </Health> 16 16 <Identity> -
source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp
1 /* Copyright (C) 201 5Wildfire Games.1 /* Copyright (C) 2016 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify 5 5 * it under the terms of the GNU General Public License as published by 6 6 * the Free Software Foundation, either version 2 of the License, or … … void MapSettingsControl::CreateWidgets() 146 146 gameTypes.Add(_T("conquest")); 147 147 gameTypes.Add(_T("conquest_structures")); 148 148 gameTypes.Add(_T("conquest_units")); 149 149 gameTypes.Add(_T("wonder")); 150 150 gameTypes.Add(_T("endless")); 151 gameTypes.Add(_T("regicide")); 151 152 152 153 wxFlexGridSizer* gridSizer = new wxFlexGridSizer(2, 5, 5); 153 154 gridSizer->AddGrowableCol(1); 154 155 // TODO: have preview selector tool? 155 156 gridSizer->Add(new wxStaticText(this, wxID_ANY, _("Preview")), wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT));