Changeset View
Standalone View
binaries/data/mods/public/maps/scripts/Regicide.js
Trigger.prototype.CheckRegicideDefeat = function(data) | Trigger.prototype.CheckRegicideDefeat = function(data) | ||||
{ | { | ||||
if (data.entity == this.regicideHeroes[data.from]) | if (data.entity == this.regicideHeroes[data.from]) | ||||
TriggerHelper.DefeatPlayer(data.from); | TriggerHelper.DefeatPlayer(data.from); | ||||
}; | }; | ||||
Trigger.prototype.InitRegicideGame = function(msg) | Trigger.prototype.InitRegicideGame = function(msg) | ||||
{ | { | ||||
let cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager); | |||||
this.regicideGarrison = cmpEndGameManager.GetGameTypeSettings().regicideGarrison; | |||||
elexis: can be a local variable | |||||
let playersCivs = []; | let playersCivs = []; | ||||
for (let playerID = 1; playerID < TriggerHelper.GetNumberOfPlayers(); ++playerID) | for (let playerID = 1; playerID < TriggerHelper.GetNumberOfPlayers(); ++playerID) | ||||
playersCivs[playerID] = QueryPlayerIDInterface(playerID).GetCiv(); | playersCivs[playerID] = QueryPlayerIDInterface(playerID).GetCiv(); | ||||
// Get all hero templates of these civs | // Get all hero templates of these civs | ||||
let heroTemplates = {}; | let heroTemplates = {}; | ||||
let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); | let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); | ||||
for (let templateName of cmpTemplateManager.FindAllTemplates(false)) | for (let templateName of cmpTemplateManager.FindAllTemplates(false)) | ||||
{ | { | ||||
if (templateName.substring(0,6) != "units/") | if (templateName.substring(0,6) != "units/") | ||||
continue; | continue; | ||||
let identity = cmpTemplateManager.GetTemplate(templateName).Identity; | let identity = cmpTemplateManager.GetTemplate(templateName).Identity; | ||||
let classes = GetIdentityClasses(identity); | let classes = GetIdentityClasses(identity); | ||||
if (classes.indexOf("Hero") == -1 || | if (classes.indexOf("Hero") == -1 || | ||||
playersCivs.every(civ => civ != identity.Civ)) | playersCivs.every(civ => civ != identity.Civ)) | ||||
continue; | continue; | ||||
if (!heroTemplates[identity.Civ]) | if (!heroTemplates[identity.Civ]) | ||||
heroTemplates[identity.Civ] = []; | heroTemplates[identity.Civ] = []; | ||||
if (heroTemplates[identity.Civ].indexOf(templateName) == -1) | if (heroTemplates[identity.Civ].indexOf(templateName) == -1) | ||||
heroTemplates[identity.Civ].push({ | heroTemplates[identity.Civ].push({ | ||||
"templateName": templateName, | "templateName": this.regicideGarrison ? templateName : "ungarrisonable|" + templateName, | ||||
Done Inline Actions"regicide_garrison|" sounds descriptive enough, or do you expect there to be so many options? In that case "ungarrisonable|" would be better. leper: "regicide_garrison|" sounds descriptive enough, or do you expect there to be so many options? | |||||
"classes": classes | "classes": classes | ||||
}); | }); | ||||
} | } | ||||
// Sort available spawn points by preference | // Sort available spawn points by preference | ||||
let spawnPreferences = ["CivilCentre", "Structure", "Ship"]; | let spawnPreferences = ["CivilCentre", "Structure", "Ship"]; | ||||
let getSpawnPreference = entity => { | let getSpawnPreference = entity => { | ||||
Show All 11 Lines | Trigger.prototype.InitRegicideGame = function(msg) | ||||
// Attempt to spawn one hero per player | // Attempt to spawn one hero per player | ||||
let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); | ||||
for (let playerID = 1; playerID < TriggerHelper.GetNumberOfPlayers(); ++playerID) | for (let playerID = 1; playerID < TriggerHelper.GetNumberOfPlayers(); ++playerID) | ||||
{ | { | ||||
let spawnPoints = cmpRangeManager.GetEntitiesByPlayer(playerID).sort((entity1, entity2) => | let spawnPoints = cmpRangeManager.GetEntitiesByPlayer(playerID).sort((entity1, entity2) => | ||||
getSpawnPreference(entity2) - getSpawnPreference(entity1)); | getSpawnPreference(entity2) - getSpawnPreference(entity1)); | ||||
// Spawn the hero on land as close as possible | |||||
if (!this.regicideGarrison && TriggerHelper.EntityHasClass(spawnPoints[0], "Ship")) | |||||
{ | |||||
let shipPosition = Engine.QueryInterface(spawnPoints[0], IID_Position).GetPosition2D(); | |||||
let distanceToShip = entity => | |||||
Engine.QueryInterface(entity, IID_Position).GetPosition2D().distanceTo(shipPosition); | |||||
spawnPoints = TriggerHelper.GetLandSpawnPoints().sort((entity1, entity2) => | |||||
distanceToShip(entity1) - distanceToShip(entity2)); | |||||
} | |||||
Not Done Inline ActionsI guess you want cmpTerritoryManager.GetOwner(pos.x, pos.z) fatherbushido: I guess you want `cmpTerritoryManager.GetOwner(pos.x, pos.z)`
0 means neutral territory if I m… | |||||
Not Done Inline ActionsOkay, will fix the GetOwner call (I seem to recall that function not working with a 3D vector, but I must have been doing something wrong). Sandarac: Okay, will fix the `GetOwner` call (I seem to recall that function not working with a 3D vector… | |||||
Not Done Inline Actions(Same as relics - what if all territory is owned) elexis: (Same as relics - what if all territory is owned) | |||||
Not Done Inline ActionsOkay. Sandarac: Okay. | |||||
this.regicideHeroes[playerID] = this.SpawnRegicideHero(playerID, heroTemplates[playersCivs[playerID]], spawnPoints); | this.regicideHeroes[playerID] = this.SpawnRegicideHero(playerID, heroTemplates[playersCivs[playerID]], spawnPoints); | ||||
} | } | ||||
Not Done Inline Actionsok fatherbushido: ok
you can also use horizDistanceTo with the 3D pos wich will avoid you to create another… | |||||
Not Done Inline ActionsOkay, will add some checks. Sandarac: Okay, will add some checks. | |||||
Not Done Inline ActionsI don't know, it's a question :) fatherbushido: I don't know, it's a question :) | |||||
Not Done Inline ActionsLets just imagine there is a better map than sicilia nomad demonstrating naval nomad. One where you actually had a choice which island you would settle on. (Would be fun on most naval maps we have actually). elexis: Lets just imagine there is a better map than sicilia nomad demonstrating naval nomad. One where… | |||||
Not Done Inline ActionsBut that would involve doing the exact opposite of what this gamesetup option is supposed to do, and that is simply the strongest argument against doing that. Your hero (maybe heroes at some point) is supposed to be vulnerable (read: not garrisoned (hence "Exposed" heroes)). Not only that, but in order to allow heroes to start garrisoned when garrisoning is disabled would likely involve all sorts of hackery somewhere, and so I think it just isn't a good idea - especially at this point when we only have this one Skirmish map where units start on ships. Maybe at some point if other people propose new maps where units start garrisoned (and that's a big if), and they are accepted and included in the game, and then if it is deemed really important to have heroes start on ships (when they logically shouldn't be able to if one reads what this option actually toggles), then I guess it could be done in a new diff. Sandarac: But that would involve doing the exact opposite of what this gamesetup option is supposed to do… | |||||
}; | }; | ||||
Not Done Inline Actions(Why do we get the 3D position, never use the third coordinate and then convert it to 2D? horizDistanceToSquared works too (bit faster than horizDistanceTo and comparing the square one works just as well).) elexis: (Why do we get the 3D position, never use the third coordinate and then convert it to 2D? | |||||
Not Done Inline ActionsOkay. Sandarac: Okay. | |||||
/** | /** | ||||
* Spawn a random hero at one of the given locations (which are checked in order). | * Spawn a random hero at one of the given locations (which are checked in order). | ||||
* Garrison it if the location is a ship. | * Garrison it if the location is a ship. | ||||
* | * | ||||
* @param spawnPoints - entity IDs at which to spawn | * @param spawnPoints - entity IDs at which to spawn | ||||
*/ | */ | ||||
Trigger.prototype.SpawnRegicideHero = function(playerID, heroTemplates, spawnPoints) | Trigger.prototype.SpawnRegicideHero = function(playerID, heroTemplates, spawnPoints) | ||||
Show All 32 Lines | Trigger.prototype.SpawnRegicideHero = function(playerID, heroTemplates, spawnPoints) | ||||
error("Couldn't spawn hero for player " + playerID); | error("Couldn't spawn hero for player " + playerID); | ||||
return undefined; | return undefined; | ||||
}; | }; | ||||
{ | { | ||||
let cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger); | let cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger); | ||||
cmpTrigger.regicideHeroes = []; | cmpTrigger.regicideHeroes = []; | ||||
cmpTrigger.regicideGarrison = false; | |||||
cmpTrigger.DoAfterDelay(0, "InitRegicideGame", {}); | cmpTrigger.DoAfterDelay(0, "InitRegicideGame", {}); | ||||
cmpTrigger.RegisterTrigger("OnOwnershipChanged", "CheckRegicideDefeat", { "enabled": true }); | cmpTrigger.RegisterTrigger("OnOwnershipChanged", "CheckRegicideDefeat", { "enabled": true }); | ||||
} | } |
can be a local variable