Fix other civs being able to upgrade Han CC to Court.
This ensures the `{civ}` and `{native}` tags are (properly) supported for upgrades and uses it for the Han CC. Reported on the forums (https://wildfiregames.com/forum/topic/82754-alpha-26-pre-releaserelease-candidate-build-testing/page/10/#comment-508908) by @Gurken Khan. Differential revision: https://code.wildfiregames.com/D4733 Comments by: @Stan, @wowgetoffyourcellphone This was SVN commit r27008.
This commit is contained in:
parent
2ccf42a244
commit
fd08ab051f
@ -56,24 +56,8 @@ Upgrade.prototype.Schema =
|
||||
|
||||
Upgrade.prototype.Init = function()
|
||||
{
|
||||
this.upgrading = false;
|
||||
this.completed = false;
|
||||
this.elapsedTime = 0;
|
||||
this.timer = undefined;
|
||||
this.expendedResources = {};
|
||||
|
||||
this.upgradeTemplates = {};
|
||||
|
||||
for (let choice in this.template)
|
||||
{
|
||||
let cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity);
|
||||
let name = this.template[choice].Entity;
|
||||
if (cmpIdentity)
|
||||
name = name.replace(/\{civ\}/g, cmpIdentity.GetCiv());
|
||||
if (this.upgradeTemplates.name)
|
||||
warn("Upgrade Component: entity " + this.entity + " has two upgrades to the same entity, only the last will be used.");
|
||||
this.upgradeTemplates[name] = choice;
|
||||
}
|
||||
};
|
||||
|
||||
// This will also deal with the "OnDestroy" case.
|
||||
@ -83,7 +67,32 @@ Upgrade.prototype.OnOwnershipChanged = function(msg)
|
||||
this.CancelUpgrade(msg.from);
|
||||
|
||||
if (msg.to != INVALID_PLAYER)
|
||||
{
|
||||
this.owner = msg.to;
|
||||
this.DetermineUpgrades();
|
||||
}
|
||||
};
|
||||
|
||||
Upgrade.prototype.DetermineUpgrades = function()
|
||||
{
|
||||
this.upgradeTemplates = {};
|
||||
|
||||
for (const choice in this.template)
|
||||
{
|
||||
const nativeCiv = Engine.QueryInterface(this.entity, IID_Identity).GetCiv();
|
||||
const playerCiv = QueryPlayerIDInterface(this.owner, IID_Identity).GetCiv();
|
||||
const name = this.template[choice].Entity.
|
||||
replace(/\{native\}/g, nativeCiv).
|
||||
replace(/\{civ\}/g, playerCiv);
|
||||
|
||||
if (!Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager).TemplateExists(name))
|
||||
continue;
|
||||
|
||||
if (this.upgradeTemplates[name])
|
||||
warn("Upgrade Component: entity " + this.entity + " has two upgrades to the same entity, only the last will be used.");
|
||||
|
||||
this.upgradeTemplates[name] = choice;
|
||||
}
|
||||
};
|
||||
|
||||
Upgrade.prototype.ChangeUpgradedEntityCount = function(amount)
|
||||
@ -128,22 +137,19 @@ Upgrade.prototype.GetUpgrades = function()
|
||||
{
|
||||
let ret = [];
|
||||
|
||||
let cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity);
|
||||
|
||||
for (let option in this.template)
|
||||
for (const option in this.upgradeTemplates)
|
||||
{
|
||||
let choice = this.template[option];
|
||||
let templateName = cmpIdentity ? choice.Entity.replace(/\{civ\}/g, cmpIdentity.GetCiv()) : choice.Entity;
|
||||
const choice = this.template[this.upgradeTemplates[option]];
|
||||
|
||||
let cost = {};
|
||||
if (choice.Cost)
|
||||
cost = this.GetResourceCosts(templateName);
|
||||
cost = this.GetResourceCosts(option);
|
||||
if (choice.Time)
|
||||
cost.time = this.GetUpgradeTime(templateName);
|
||||
cost.time = this.GetUpgradeTime(option);
|
||||
|
||||
let hasCost = choice.Cost || choice.Time;
|
||||
ret.push({
|
||||
"entity": templateName,
|
||||
"entity": option,
|
||||
"icon": choice.Icon || undefined,
|
||||
"cost": hasCost ? cost : undefined,
|
||||
"tooltip": choice.Tooltip || undefined,
|
||||
@ -161,7 +167,7 @@ Upgrade.prototype.CancelTimer = function()
|
||||
|
||||
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
|
||||
cmpTimer.CancelTimer(this.timer);
|
||||
this.timer = undefined;
|
||||
delete this.timer;
|
||||
};
|
||||
|
||||
Upgrade.prototype.IsUpgrading = function()
|
||||
@ -289,7 +295,7 @@ Upgrade.prototype.CancelUpgrade = function(owner)
|
||||
cmpVisual.SelectAnimation("idle", false, 1.0);
|
||||
}
|
||||
|
||||
this.upgrading = false;
|
||||
delete this.upgrading;
|
||||
this.CancelTimer();
|
||||
this.SetElapsedTime(0);
|
||||
};
|
||||
|
@ -82,7 +82,8 @@ AddMock(SYSTEM_ENTITY, IID_PlayerManager, {
|
||||
"GetPlayerByID": pID => 10 // Called in helpers/player.js::QueryPlayerIDInterface(), as part of Tests T2 and T5.
|
||||
});
|
||||
AddMock(SYSTEM_ENTITY, IID_TemplateManager, {
|
||||
"GetTemplate": () => template // Called in components/Upgrade.js::ChangeUpgradedEntityCount().
|
||||
"GetTemplate": () => template, // Called in components/Upgrade.js::ChangeUpgradedEntityCount().
|
||||
"TemplateExists": (templ) => true
|
||||
});
|
||||
AddMock(SYSTEM_ENTITY, IID_Timer, {
|
||||
"SetInterval": () => 1, // Called in components/Upgrade.js::Upgrade().
|
||||
@ -113,6 +114,9 @@ AddMock(10, IID_Player, {
|
||||
"GetPlayerID": () => playerID, // Called in helpers/Player.js::QueryOwnerInterface() (and several times below).
|
||||
"TrySubtractResources": () => true // Called in components/Upgrade.js::Upgrade().
|
||||
});
|
||||
AddMock(10, IID_Identity, {
|
||||
"GetCiv": () => civCode
|
||||
});
|
||||
|
||||
// Create an entity with an Upgrade component:
|
||||
AddMock(20, IID_Ownership, {
|
||||
@ -126,6 +130,7 @@ AddMock(20, IID_ProductionQueue, {
|
||||
});
|
||||
let cmpUpgrade = ConstructComponent(20, "Upgrade", template.Upgrade);
|
||||
cmpUpgrade.owner = playerID;
|
||||
cmpUpgrade.OnOwnershipChanged({ "to": playerID });
|
||||
|
||||
/**
|
||||
* Now to start the test proper
|
||||
|
@ -29,7 +29,7 @@
|
||||
</Trainer>
|
||||
<Upgrade>
|
||||
<ImperialCourt>
|
||||
<Entity>structures/han/civil_centre_court</Entity>
|
||||
<Entity>structures/{civ}/civil_centre_court</Entity>
|
||||
<Tooltip>This greatly increases the health, capture resistance, and garrison capacity of this specific Civic Center. Unlock training of Heroes here and reduce its research and batch training times by half.</Tooltip>
|
||||
<RequiredTechnology>phase_city</RequiredTechnology>
|
||||
<Cost>
|
||||
|
Loading…
Reference in New Issue
Block a user