Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/maps/scripts/CaptureTheWonder.js
Trigger.prototype.IsCaptureTheWonderEntity = function(entity) | |||||
{ | |||||
return !!Engine.QueryInterface(entity, IID_CaptureTheWonder) | |||||
} | |||||
Trigger.prototype.CaptureTheWonderEntityRenamed = function(data) | |||||
{ | |||||
if (this.captureTheWonderMessages[data.entity] && this.IsCaptureTheWonderEntity(data.newentity)) | |||||
{ | |||||
// When an entity is renamed, we first create a new entity, | |||||
// which in case it is a wonder will receive a timer. | |||||
// However on a rename we want to use the timer from the old entity, | |||||
// so we need to remove the timer of the new entity. | |||||
this.CaptureTheWonderDeleteTimer(data.newentity); | |||||
this.captureTheWonderMessages[data.newentity] = this.captureTheWonderMessages[data.entity]; | |||||
delete this.captureTheWonderMessages[data.entity]; | |||||
} | |||||
}; | |||||
Trigger.prototype.CaptureTheWonderOwnershipChanged = function(data) | |||||
{ | |||||
if (!this.IsCaptureTheWonderEntity(data.entity)) | |||||
return; | |||||
this.CaptureTheWonderDeleteTimer(data.entity); | |||||
if (data.to > 0) | |||||
this.CaptureTheWonderStartTimer(data.entity, data.to); | |||||
}; | |||||
Trigger.prototype.CaptureTheWonderDiplomacyChanged = function(data) | |||||
{ | |||||
if (!Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager).GetAlliedVictory()) | |||||
return; | |||||
for (let ent in this.captureTheWonderMessages) | |||||
{ | |||||
if (this.captureTheWonderMessages[ent].playerID != data.player && this.captureTheWonderMessages[ent].playerID != data.otherPlayer) | |||||
continue; | |||||
let owner = this.captureTheWonderMessages[ent].playerID; | |||||
let otherPlayer = owner == data.player ? data.otherPlayer : data.player; | |||||
let newAllies = new Set(QueryPlayerIDInterface(owner).GetPlayersByDiplomacy("IsExclusiveMutualAlly")); | |||||
if (newAllies.has(otherPlayer) && !this.captureTheWonderMessages[ent].allies.has(otherPlayer) || | |||||
!newAllies.has(otherPlayer) && this.captureTheWonderMessages[ent].allies.has(otherPlayer)) | |||||
{ | |||||
this.CaptureTheWonderDeleteTimer(ent); | |||||
this.CaptureTheWonderStartTimer(ent, owner); | |||||
} | |||||
} | |||||
}; | |||||
/** | |||||
* Create new messages, and start timer to register defeat. | |||||
*/ | |||||
Trigger.prototype.CaptureTheWonderStartTimer = function(ent, player) | |||||
{ | |||||
let cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager); | |||||
let allies = cmpEndGameManager.GetAlliedVictory() ? | |||||
QueryPlayerIDInterface(player).GetPlayersByDiplomacy("IsExclusiveMutualAlly") : []; | |||||
let others = [-1]; | |||||
for (let playerID = 1; playerID < TriggerHelper.GetNumberOfPlayers(); ++playerID) | |||||
{ | |||||
let cmpPlayer = QueryPlayerIDInterface(playerID); | |||||
if (cmpPlayer.GetState() == "won") | |||||
return; | |||||
if (allies.indexOf(playerID) == -1 && playerID != player) | |||||
others.push(playerID); | |||||
} | |||||
let cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); | |||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | |||||
let wonderDuration = cmpEndGameManager.GetGameSettings().captureTheWonderDuration; | |||||
this.captureTheWonderMessages[ent] = { | |||||
"playerID": player, | |||||
"allies": new Set(allies), | |||||
"timer": cmpTimer.SetTimeout(SYSTEM_ENTITY, IID_Trigger, "CaptureTheWonderSetWinner", wonderDuration, player), | |||||
"messages": [ | |||||
cmpGuiInterface.AddTimeNotification( | |||||
{ | |||||
"message": allies.length ? | |||||
markForTranslation("%(_player_)s captured a Wonder and %(_player_)s and their allies will win in %(time)s.") : | |||||
markForTranslation("%(_player_)s captured a Wonder and will win in %(time)s."), | |||||
"players": others, | |||||
"parameters": { | |||||
"_player_": player | |||||
}, | |||||
"translateMessage": true, | |||||
"translateParameters": [] | |||||
}, | |||||
wonderDuration), | |||||
cmpGuiInterface.AddTimeNotification( | |||||
{ | |||||
"message": markForTranslation("%(_player_)s captured a Wonder and you will win in %(time)s."), | |||||
"players": allies, | |||||
"parameters": { | |||||
"_player_": player | |||||
}, | |||||
"translateMessage": true, | |||||
"translateParameters": [] | |||||
}, | |||||
wonderDuration), | |||||
cmpGuiInterface.AddTimeNotification( | |||||
{ | |||||
"message": allies.length ? | |||||
markForTranslation("You own a Wonder and you and your allies will win in %(time)s.") : | |||||
markForTranslation("You own a Wonder and will win in %(time)s."), | |||||
"players": [player], | |||||
"translateMessage": true | |||||
}, | |||||
wonderDuration) | |||||
] | |||||
}; | |||||
}; | |||||
Trigger.prototype.CaptureTheWonderDeleteTimer = function(ent) | |||||
{ | |||||
if (!this.captureTheWonderMessages[ent]) | |||||
return; | |||||
let cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); | |||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); | |||||
for (let message of this.captureTheWonderMessages[ent].messages) | |||||
cmpGuiInterface.DeleteTimeNotification(message); | |||||
cmpTimer.CancelTimer(this.captureTheWonderMessages[ent].timer); | |||||
delete this.captureTheWonderMessages[ent]; | |||||
}; | |||||
Trigger.prototype.CaptureTheWonderPlayerWon = function(data) | |||||
{ | |||||
for (let ent in this.captureTheWonderMessages) | |||||
this.CaptureTheWonderDeleteTimer(ent); | |||||
}; | |||||
Trigger.prototype.CaptureTheWonderPlayerDefeated = function(data) | |||||
{ | |||||
for (let ent in this.captureTheWonderMessages) | |||||
if (this.captureTheWonderMessages[ent].allies.has(data.playerId)) | |||||
{ | |||||
let owner = this.captureTheWonderMessages[ent].playerID; | |||||
this.CaptureTheWonderDeleteTimer(ent); | |||||
this.CaptureTheWonderStartTimer(ent, owner); | |||||
} | |||||
}; | |||||
Trigger.prototype.CaptureTheWonderSetWinner = function(playerID) | |||||
{ | |||||
let cmpEndGameManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager); | |||||
cmpEndGameManager.MarkPlayerAndAlliesAsWon( | |||||
playerID, | |||||
n => markForPluralTranslation( | |||||
"%(lastPlayer)s has won (capture the wonder victory).", | |||||
"%(players)s and %(lastPlayer)s have won (capture the wonder victory).", | |||||
n), | |||||
n => markForPluralTranslation( | |||||
"%(lastPlayer)s has been defeated (capture the wonder victory).", | |||||
"%(players)s and %(lastPlayer)s have been defeated (capture the wonder victory).", | |||||
n)); | |||||
}; | |||||
{ | |||||
let cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger); | |||||
cmpTrigger.RegisterTrigger("OnEntityRenamed", "CaptureTheWonderEntityRenamed", { "enabled": true }); | |||||
cmpTrigger.RegisterTrigger("OnOwnershipChanged", "CaptureTheWonderOwnershipChanged", { "enabled": true }); | |||||
cmpTrigger.RegisterTrigger("OnDiplomacyChanged", "CaptureTheWonderDiplomacyChanged", { "enabled": true }); | |||||
cmpTrigger.RegisterTrigger("OnPlayerWon", "CaptureTheWonderPlayerWon", { "enabled": true }); | |||||
cmpTrigger.RegisterTrigger("OnPlayerDefeated", "CaptureTheWonderPlayerDefeated", { "enabled": true }); | |||||
cmpTrigger.captureTheWonderMessages = {}; | |||||
} | |||||
{ | |||||
const wonders = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager) | |||||
Freagarach: Would it be possible to create the wonders here? (That way one doesn't need the extra sim… | |||||
Done Inline ActionsYes but this is not a good place because then the map maker can't specify anything on the rmgen / map editor for his "wonder". How do you distinguish a normal wonder from a "capture the wonder" wonder/entity otherwise? Also is not a big deal in terms of performance, just a one time instancing. nani: Yes but this is not a good place because then the map maker can't specify anything on the rmgen… | |||||
.GetGaiaAndNonGaiaEntities() | |||||
.filter(entity => Engine.QueryInterface(entity, IID_CaptureTheWonder) != undefined) | |||||
if(wonders.length == 0) | |||||
warn("Game mode is 'Capture the wonder' but there are no wonders in the map") | |||||
} |
Wildfire Games · Phabricator
Would it be possible to create the wonders here? (That way one doesn't need the extra sim component.)