Index: binaries/data/mods/public/globalscripts/Templates.js
===================================================================
--- binaries/data/mods/public/globalscripts/Templates.js
+++ binaries/data/mods/public/globalscripts/Templates.js
@@ -417,16 +417,16 @@
if (template.Upgrade)
{
ret.upgrades = [];
- for (let upgradeName in template.Upgrade)
+ for (let upgradeName in template.Upgrade.Upgrades)
{
- let upgrade = template.Upgrade[upgradeName];
+ let upgrade = template.Upgrade.Upgrades[upgradeName];
let cost = {};
if (upgrade.Cost)
for (let res in upgrade.Cost)
- cost[res] = getEntityValue("Upgrade/" + upgradeName + "/Cost/" + res, "Upgrade/Cost/" + res);
+ cost[res] = getEntityValue("Upgrade/Upgrades/" + upgradeName + "/Cost/" + res, "Upgrade/Cost/" + res);
if (upgrade.Time)
- cost.time = getEntityValue("Upgrade/" + upgradeName + "/Time", "Upgrade/Time");
+ cost.time = getEntityValue("Upgrade/Upgrades/" + upgradeName + "/Time", "Upgrade/Time");
ret.upgrades.push({
"entity": upgrade.Entity,
Index: binaries/data/mods/public/simulation/components/Upgrade.js
===================================================================
--- binaries/data/mods/public/simulation/components/Upgrade.js
+++ binaries/data/mods/public/simulation/components/Upgrade.js
@@ -3,56 +3,63 @@
const UPGRADING_PROGRESS_INTERVAL = 250;
Upgrade.prototype.Schema =
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
"" +
"" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ Resources.BuildSchema("nonNegativeInteger") +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
"" +
- Resources.BuildSchema("nonNegativeInteger") +
+ "" +
+ "" +
"" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
- "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
"" +
- "";
+ "";
Upgrade.prototype.Init = function()
{
@@ -64,16 +71,18 @@
this.upgradeTemplates = {};
- for (let choice in this.template)
+ for (let choice in this.template.Upgrades)
{
let cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity);
- let name = this.template[choice].Entity;
+ let name = this.template.Upgrades[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.autoUpgrade = "AutoUpgrade" in this.template;
};
// This will also deal with the "OnDestroy" case.
@@ -82,8 +91,11 @@
if (!this.completed)
this.CancelUpgrade(msg.from);
- if (msg.to != INVALID_PLAYER)
- this.owner = msg.to;
+ if (msg.to == INVALID_PLAYER)
+ return;
+
+ this.owner = msg.to;
+ this.CheckAutoUpgrade();
};
Upgrade.prototype.ChangeUpgradedEntityCount = function(amount)
@@ -129,9 +141,9 @@
let cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity);
- for (let option in this.template)
+ for (let option in this.template.Upgrades)
{
- let choice = this.template[option];
+ let choice = this.template.Upgrades[option];
let templateName = cmpIdentity ? choice.Entity.replace(/\{civ\}/g, cmpIdentity.GetCiv()) : choice.Entity;
let cost = {};
@@ -179,23 +191,23 @@
return undefined;
// is undefined by default so use X in Y
- return "CheckPlacementRestrictions" in this.template[this.upgradeTemplates[template]];
+ return "CheckPlacementRestrictions" in this.template.Upgrades[this.upgradeTemplates[template]];
};
Upgrade.prototype.GetRequiredTechnology = function(templateArg)
{
let choice = this.upgradeTemplates[templateArg] || templateArg;
- if (this.template[choice].RequiredTechnology)
- return this.template[choice].RequiredTechnology;
+ if (this.template.Upgrades[choice].RequiredTechnology)
+ return this.template.Upgrades[choice].RequiredTechnology;
- if (!("RequiredTechnology" in this.template[choice]))
+ if (!("RequiredTechnology" in this.template.Upgrades[choice]))
return undefined;
let cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
let cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity);
- let entType = this.template[choice].Entity;
+ let entType = this.template.Upgrades[choice].Entity;
if (cmpIdentity)
entType = entType.replace(/\{civ\}/g, cmpIdentity.GetCiv());
@@ -212,12 +224,12 @@
return clone(this.expendedResources);
let choice = this.upgradeTemplates[template];
- if (!this.template[choice].Cost)
+ if (!this.template.Upgrades[choice].Cost)
return {};
let costs = {};
- for (let r in this.template[choice].Cost)
- costs[r] = ApplyValueModificationsToEntity("Upgrade/Cost/"+r, +this.template[choice].Cost[r], this.entity);
+ for (let r in this.template.Upgrades[choice].Cost)
+ costs[r] = ApplyValueModificationsToEntity("Upgrade/Cost/"+r, +this.template.Upgrades[choice].Cost[r], this.entity);
return costs;
};
@@ -267,7 +279,7 @@
// Do not update visual actor if the animation didn't change.
let choice = this.upgradeTemplates[this.upgrading];
- if (choice && this.template[choice].Variant)
+ if (choice && this.template.Upgrades[choice].Variant)
{
let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual);
if (cmpVisual)
@@ -287,10 +299,10 @@
if (!choice)
return undefined;
- if (!this.template[choice].Time)
+ if (!this.template.Upgrades[choice].Time)
return 0;
- return ApplyValueModificationsToEntity("Upgrade/Time", +this.template[choice].Time, this.entity);
+ return ApplyValueModificationsToEntity("Upgrade/Time", +this.template.Upgrades[choice].Time, this.entity);
};
Upgrade.prototype.GetElapsedTime = function()
@@ -315,14 +327,14 @@
{
let choice = this.upgradeTemplates[this.upgrading];
- if (!choice || !this.template[choice].Variant)
+ if (!choice || !this.template.Upgrades[choice].Variant)
return;
let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual);
if (!cmpVisual)
return;
- cmpVisual.SelectAnimation(this.template[choice].Variant, false, 1.0);
+ cmpVisual.SelectAnimation(this.template.Upgrades[choice].Variant, false, 1.0);
};
Upgrade.prototype.UpgradeProgress = function(data, lateness)
@@ -345,4 +357,13 @@
PlaySound("upgraded", newEntity);
};
+/**
+ * Checks for autoupgrade. And upgrades if applicable.
+ */
+Upgrade.prototype.CheckAutoUpgrade = function()
+{
+ if (this.autoUpgrade)
+ this.Upgrade(pickRandom(Object.keys(this.upgradeTemplates)));
+};
+
Engine.RegisterComponentType(IID_Upgrade, "Upgrade", Upgrade);
Index: binaries/data/mods/public/simulation/components/tests/test_UpgradeModification.js
===================================================================
--- binaries/data/mods/public/simulation/components/tests/test_UpgradeModification.js
+++ binaries/data/mods/public/simulation/components/tests/test_UpgradeModification.js
@@ -37,10 +37,12 @@
"VisibleClasses": { '@datatype': "tokens", "_string": "" }
},
"Upgrade": {
- "Tower": {
- "Cost": { "stone": "100", "wood": "50" },
- "Entity": "structures/{civ}_defense_tower",
- "Time": "100"
+ "Upgrades": {
+ "Tower": {
+ "Cost": { "stone": "100", "wood": "50" },
+ "Entity": "structures/{civ}_defense_tower",
+ "Time": "100"
+ }
}
}
};
@@ -159,3 +161,22 @@
// T7: ...but with the upgrade cancelled, it now uses the modified value.
cmpUpgrade.CancelUpgrade(playerID);
TS_ASSERT_UNEVAL_EQUALS(cmpUpgrade.GetUpgrades()[0].cost, { "stone": 160, "wood": 25, "time": 90 });
+
+// Test automatic upgrading.
+template["Upgrade"] = {
+ "Upgrades": {
+ "Tower": {
+ "Cost": { "stone": "100", "wood": "50" },
+ "Entity": "structures/{civ}_defense_tower",
+ "Time": "100"
+ }
+ },
+ "AutoUpgrade": undefined
+};
+cmpUpgrade = ConstructComponent(20, "Upgrade", template.Upgrade);
+cmpUpgrade.OnOwnershipChanged({ "from": INVALID_PLAYER, "to": playerID });
+TS_ASSERT(cmpUpgrade.IsUpgrading());
+
+// Stop upgrading when dying.
+cmpUpgrade.OnOwnershipChanged({ "from": playerID, "to": INVALID_PLAYER });
+TS_ASSERT(!cmpUpgrade.IsUpgrading());
Index: binaries/data/mods/public/simulation/templates/structures/athen_defense_tower.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/structures/athen_defense_tower.xml
+++ binaries/data/mods/public/simulation/templates/structures/athen_defense_tower.xml
@@ -18,27 +18,29 @@
structures/hellenes/scout_tower.xml
-
- structures/{civ}_tower_artillery
- Reinforce with stone block, and install small stone throwers to upgrade this defense tower into a slow, area of effect, and siege resistant artillery tower.
- phase_city
-
- 150
- 100
-
-
- upgrading
-
-
- structures/{civ}_tower_bolt
- Reinforce with stone block, and install scorpions to upgrade this defense tower into a prompt, long range, and accurate bolt tower.
- phase_city
-
- 100
- 100
-
-
- upgrading
-
+
+
+ structures/{civ}_tower_artillery
+ Reinforce with stone block, and install small stone throwers to upgrade this defense tower into a slow, area of effect, and siege resistant artillery tower.
+ phase_city
+
+ 150
+ 100
+
+
+ upgrading
+
+
+ structures/{civ}_tower_bolt
+ Reinforce with stone block, and install scorpions to upgrade this defense tower into a prompt, long range, and accurate bolt tower.
+ phase_city
+
+ 100
+ 100
+
+
+ upgrading
+
+
Index: binaries/data/mods/public/simulation/templates/structures/cart_defense_tower.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/structures/cart_defense_tower.xml
+++ binaries/data/mods/public/simulation/templates/structures/cart_defense_tower.xml
@@ -19,27 +19,29 @@
structures/carthaginians/scout_tower.xml
-
- structures/{civ}_tower_artillery
- Reinforce with stone block, and install small stone throwers to upgrade this defense tower into a slow, area of effect, and siege resistant artillery tower.
- phase_city
-
- 150
- 100
-
-
- upgrading
-
-
- structures/{civ}_tower_bolt
- Reinforce with stone block, and install scorpions to upgrade this defense tower into a prompt, long range, and accurate bolt tower.
- phase_city
-
- 100
- 100
-
-
- upgrading
-
+
+
+ structures/{civ}_tower_artillery
+ Reinforce with stone block, and install small stone throwers to upgrade this defense tower into a slow, area of effect, and siege resistant artillery tower.
+ phase_city
+
+ 150
+ 100
+
+
+ upgrading
+
+
+ structures/{civ}_tower_bolt
+ Reinforce with stone block, and install scorpions to upgrade this defense tower into a prompt, long range, and accurate bolt tower.
+ phase_city
+
+ 100
+ 100
+
+
+ upgrading
+
+
Index: binaries/data/mods/public/simulation/templates/structures/cart_s_wall_long.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/structures/cart_s_wall_long.xml
+++ binaries/data/mods/public/simulation/templates/structures/cart_s_wall_long.xml
@@ -7,14 +7,16 @@
Stone Wall
-
- structures/cart_s_wall_gate
-
- 0
- 20
-
-
-
+
+
+ structures/cart_s_wall_gate
+
+ 0
+ 20
+
+
+
+
structures/carthaginians/short_wall_long.xml
Index: binaries/data/mods/public/simulation/templates/structures/iber_sentry_tower.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/structures/iber_sentry_tower.xml
+++ binaries/data/mods/public/simulation/templates/structures/iber_sentry_tower.xml
@@ -4,12 +4,14 @@
iber
-
-
- 250
-
-
-
+
+
+
+ 250
+
+
+
+
structures/iberians/wooden_tower.xml
Index: binaries/data/mods/public/simulation/templates/structures/mace_defense_tower.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/structures/mace_defense_tower.xml
+++ binaries/data/mods/public/simulation/templates/structures/mace_defense_tower.xml
@@ -15,28 +15,30 @@
22.0
-
- structures/{civ}_tower_artillery
- Reinforce with stone block, and install small stone throwers to upgrade this defense tower into a slow, area of effect, and siege resistant artillery tower.
- phase_city
-
- 150
- 100
-
-
- upgrading
-
-
- structures/{civ}_tower_bolt
- Reinforce with stone block, and install scorpions to upgrade this defense tower into a prompt, long range, and accurate bolt tower.
- phase_city
-
- 100
- 100
-
-
- upgrading
-
+
+
+ structures/{civ}_tower_artillery
+ Reinforce with stone block, and install small stone throwers to upgrade this defense tower into a slow, area of effect, and siege resistant artillery tower.
+ phase_city
+
+ 150
+ 100
+
+
+ upgrading
+
+
+ structures/{civ}_tower_bolt
+ Reinforce with stone block, and install scorpions to upgrade this defense tower into a prompt, long range, and accurate bolt tower.
+ phase_city
+
+ 100
+ 100
+
+
+ upgrading
+
+
structures/hellenes/scout_tower.xml
Index: binaries/data/mods/public/simulation/templates/structures/maur_defense_tower.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/structures/maur_defense_tower.xml
+++ binaries/data/mods/public/simulation/templates/structures/maur_defense_tower.xml
@@ -8,16 +8,18 @@
19.0
-
- structures/{civ}_tower_double
- Reinforce with stone block, and add a second rampart for up to 16 archers to stand upon. Infantry Archer exclusive tower. Devastating against melee troops, weak to siege and massed ranged units
- phase_city
-
- 150
- 70
-
-
-
+
+
+ structures/{civ}_tower_double
+ Reinforce with stone block, and add a second rampart for up to 16 archers to stand upon. Infantry Archer exclusive tower. Devastating against melee troops, weak to siege and massed ranged units
+ phase_city
+
+ 150
+ 70
+
+
+
+
structures/mauryas/scout_tower.xml
Index: binaries/data/mods/public/simulation/templates/structures/maur_wall_long.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/structures/maur_wall_long.xml
+++ binaries/data/mods/public/simulation/templates/structures/maur_wall_long.xml
@@ -42,12 +42,14 @@
-
-
- 60
- 0
-
-
+
+
+
+ 60
+ 0
+
+
+
structures/mauryas/wall_long.xml
Index: binaries/data/mods/public/simulation/templates/structures/palisades_long.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/structures/palisades_long.xml
+++ binaries/data/mods/public/simulation/templates/structures/palisades_long.xml
@@ -27,15 +27,17 @@
9.0
-
- structures/palisades_gate
-
- 20
-
-
- This will allow you to let units circulate through your fortifications.
- upgrading
-
+
+
+ structures/palisades_gate
+
+ 20
+
+
+ This will allow you to let units circulate through your fortifications.
+ upgrading
+
+
props/special/palisade_rocks_long.xml
Index: binaries/data/mods/public/simulation/templates/structures/ptol_defense_tower.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/structures/ptol_defense_tower.xml
+++ binaries/data/mods/public/simulation/templates/structures/ptol_defense_tower.xml
@@ -18,27 +18,29 @@
structures/ptolemies/defense_tower.xml
-
- structures/{civ}_tower_artillery
- Reinforce with stone block, and install small stone throwers to upgrade this defense tower into a slow, area of effect, and siege resistant artillery tower.
- phase_city
-
- 150
- 100
-
-
- upgrading
-
-
- structures/{civ}_tower_bolt
- Reinforce with stone block, and install scorpions to upgrade this defense tower into a prompt, long range, and accurate bolt tower.
- phase_city
-
- 100
- 100
-
-
- upgrading
-
+
+
+ structures/{civ}_tower_artillery
+ Reinforce with stone block, and install small stone throwers to upgrade this defense tower into a slow, area of effect, and siege resistant artillery tower.
+ phase_city
+
+ 150
+ 100
+
+
+ upgrading
+
+
+ structures/{civ}_tower_bolt
+ Reinforce with stone block, and install scorpions to upgrade this defense tower into a prompt, long range, and accurate bolt tower.
+ phase_city
+
+ 100
+ 100
+
+
+ upgrading
+
+
Index: binaries/data/mods/public/simulation/templates/structures/rome_defense_tower.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/structures/rome_defense_tower.xml
+++ binaries/data/mods/public/simulation/templates/structures/rome_defense_tower.xml
@@ -18,27 +18,29 @@
structures/romans/scout_tower.xml
-
- structures/{civ}_tower_artillery
- Reinforce with stone block, and install small stone throwers to upgrade this defense tower into a slow, area of effect, and siege resistant artillery tower.
- phase_city
-
- 150
- 100
-
-
- upgrading
-
-
- structures/{civ}_tower_bolt
- Reinforce with stone block, and install scorpions to upgrade this defense tower into a prompt, long range, and accurate bolt tower.
- phase_city
-
- 100
- 100
-
-
- upgrading
-
+
+
+ structures/{civ}_tower_artillery
+ Reinforce with stone block, and install small stone throwers to upgrade this defense tower into a slow, area of effect, and siege resistant artillery tower.
+ phase_city
+
+ 150
+ 100
+
+
+ upgrading
+
+
+ structures/{civ}_tower_bolt
+ Reinforce with stone block, and install scorpions to upgrade this defense tower into a prompt, long range, and accurate bolt tower.
+ phase_city
+
+ 100
+ 100
+
+
+ upgrading
+
+
Index: binaries/data/mods/public/simulation/templates/structures/rome_siege_wall_long.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/structures/rome_siege_wall_long.xml
+++ binaries/data/mods/public/simulation/templates/structures/rome_siege_wall_long.xml
@@ -73,14 +73,16 @@
-
- structures/rome_siege_wall_gate
-
- 80
- 0
-
- upgrading
-
+
+
+ structures/rome_siege_wall_gate
+
+ 80
+ 0
+
+ upgrading
+
+
structures/romans/siege_wall_long.xml
Index: binaries/data/mods/public/simulation/templates/structures/sele_defense_tower.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/structures/sele_defense_tower.xml
+++ binaries/data/mods/public/simulation/templates/structures/sele_defense_tower.xml
@@ -18,16 +18,18 @@
structures/seleucids/scout_tower.xml
-
- structures/{civ}_tower_artillery
- Reinforce with stone block, and install small torsion engines to upgrade this defense tower into an artillery tower.
- phase_city
-
- 150
- 100
-
-
- upgrading
-
+
+
+ structures/{civ}_tower_artillery
+ Reinforce with stone block, and install small torsion engines to upgrade this defense tower into an artillery tower.
+ phase_city
+
+ 150
+ 100
+
+
+ upgrading
+
+
Index: binaries/data/mods/public/simulation/templates/structures/spart_defense_tower.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/structures/spart_defense_tower.xml
+++ binaries/data/mods/public/simulation/templates/structures/spart_defense_tower.xml
@@ -18,16 +18,18 @@
structures/spartans/defense_tower.xml
-
- structures/{civ}_tower_bolt
- Reinforce with stone block, and install small oxybeles to upgrade this defense tower into a prompt, long range, and accurate bolt tower.
- phase_city
-
- 100
- 100
-
-
- upgrading
-
+
+
+ structures/{civ}_tower_bolt
+ Reinforce with stone block, and install small oxybeles to upgrade this defense tower into a prompt, long range, and accurate bolt tower.
+ phase_city
+
+ 100
+ 100
+
+
+ upgrading
+
+
Index: binaries/data/mods/public/simulation/templates/template_structure_defensive_tower_sentry.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_structure_defensive_tower_sentry.xml
+++ binaries/data/mods/public/simulation/templates/template_structure_defensive_tower_sentry.xml
@@ -55,16 +55,19 @@
30000
-
- structures/{civ}_defense_tower
- Reinforce with stone and upgrade to a defense tower.
- phase_town
-
- 50
- 100
-
- upgrading
-
-
+
+
+ structures/{civ}_defense_tower
+ Reinforce with stone and upgrade to a defense tower.
+ phase_town
+
+ 50
+ 100
+
+ upgrading
+
+
+
+
Index: binaries/data/mods/public/simulation/templates/template_structure_defensive_wall_long.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_structure_defensive_wall_long.xml
+++ binaries/data/mods/public/simulation/templates/template_structure_defensive_wall_long.xml
@@ -47,15 +47,17 @@
-
- structures/{civ}_wall_gate
- This will allow you to let units circulate through your fortifications.
-
- 60
-
-
- upgrading
-
+
+
+ structures/{civ}_wall_gate
+ This will allow you to let units circulate through your fortifications.
+
+ 60
+
+
+ upgrading
+
+
structures/fndn_9x3_wall.xml