Index: binaries/data/mods/public/globalscripts/Resources.js
===================================================================
--- binaries/data/mods/public/globalscripts/Resources.js
+++ binaries/data/mods/public/globalscripts/Resources.js
@@ -18,13 +18,6 @@
if (data.code != data.code.toLowerCase())
warn("Resource codes should use lower case: " + data.code);
- // Treasures are supported for every specified resource
- if (data.code == "treasure")
- {
- error("Encountered resource with reserved keyword: " + data.code);
- continue;
- }
-
this.resourceData.push(data);
this.resourceDataObj[data.code] = data;
this.resourceCodes.push(data.code);
Index: binaries/data/mods/public/globalscripts/Templates.js
===================================================================
--- binaries/data/mods/public/globalscripts/Templates.js
+++ binaries/data/mods/public/globalscripts/Templates.js
@@ -476,6 +476,16 @@
"GainMultiplier": getEntityValue("Trader/GainMultiplier")
};
+ if (template.Treasure)
+ {
+ ret.treasure = {
+ "collectTime": getEntityValue("Treasure/CollectTime"),
+ "reward": {}
+ };
+ for (let resource in template.Treasure.Resources)
+ ret.treasure.reward[resource] = getEntityValue("Treasure/Resources/" + resource);
+ }
+
if (template.WallSet)
{
ret.wallSet = {
Index: binaries/data/mods/public/gui/common/tooltips.js
===================================================================
--- binaries/data/mods/public/gui/common/tooltips.js
+++ binaries/data/mods/public/gui/common/tooltips.js
@@ -746,7 +746,7 @@
return "";
let supply = template.supply;
- let type = supply.type[0] == "treasure" ? supply.type[1] : supply.type[0];
+ let type = supply.type[0];
// Translation: Label in tooltip showing the resource type and quantity of a given resource supply.
return sprintf(translate("%(label)s %(component)s %(amount)s"), {
@@ -757,6 +757,37 @@
});
}
+/**
+ * Returns the resources this entity gives as a reward.
+ */
+function getTreasureTooltip(template)
+{
+ if (!template.treasure)
+ return "";
+
+ let resources = {};
+ for (let resource of g_ResourceData.GetResources())
+ {
+ let type = resource.code;
+ if (template.treasure.reward[type])
+ resources[type] = template.treasure.reward[type];
+ }
+
+ if (!Object.keys(resources).length)
+ return "";
+
+ return sprintf(translate("%(label)s %(details)s"), {
+ "label": headerFont(translate("Collection Reward:")),
+ "details":
+ Object.keys(resources).map(
+ type => sprintf(translate("%(resourceIcon)s %(reward)s"), {
+ "resourceIcon": resourceIcon(type),
+ "reward": resources[type]
+ })
+ ).join(" ")
+ });
+}
+
function getResourceTrickleTooltip(template)
{
if (!template.resourceTrickle)
Index: binaries/data/mods/public/gui/session/selection_details.js
===================================================================
--- binaries/data/mods/public/gui/session/selection_details.js
+++ binaries/data/mods/public/gui/session/selection_details.js
@@ -12,10 +12,7 @@
function getResourceTypeDisplayName(resourceType)
{
- return resourceNameFirstWord(
- resourceType.generic == "treasure" ?
- resourceType.specific :
- resourceType.generic);
+ return resourceNameFirstWord(resourceType.generic);
}
// Updates the health bar of garrisoned units
@@ -347,6 +344,7 @@
getVisibleEntityClassesFormatted,
getAurasTooltip,
getEntityTooltip,
+ getTreasureTooltip,
showTemplateViewerOnRightClickTooltip
].map(func => func(template)));
Index: binaries/data/mods/public/gui/session/unit_actions.js
===================================================================
--- binaries/data/mods/public/gui/session/unit_actions.js
+++ binaries/data/mods/public/gui/session/unit_actions.js
@@ -803,6 +803,49 @@
"specificness": 40,
},
+ "collect-treasure":
+ {
+ "execute": function(target, action, selection, queued)
+ {
+ Engine.PostNetworkCommand({
+ "type": "collect-treasure",
+ "entities": selection,
+ "target": action.target,
+ "queued": queued,
+ "formation": g_AutoFormation.getNull()
+ });
+
+ Engine.GuiInterfaceCall("PlaySound", {
+ "name": "order_collect_treasure",
+ "entity": action.firstAbleEntity
+ });
+
+ return true;
+ },
+ "getActionInfo": function(entState, targetState)
+ {
+ if (!entState.treasureCollecter ||
+ !targetState || !targetState.treasure)
+ return false;
+
+ return {
+ "possible": true,
+ "cursor": "action-collect-treasure"
+ };
+ },
+ "actionCheck": function(target, selection)
+ {
+ let actionInfo = getActionInfo("collect-treasure", target, selection);
+ return actionInfo.possible && {
+ "type": "collect-treasure",
+ "cursor": actionInfo.cursor,
+ "target": target,
+ "firstAbleEntity": actionInfo.entity
+ };
+ },
+ "specificness": 1,
+ },
+
"remove-guard":
{
"execute": function(target, action, selection, queued)
@@ -932,10 +975,7 @@
else if (targetState && targetState.resourceSupply)
{
let resourceType = targetState.resourceSupply.type;
- if (resourceType.generic == "treasure")
- cursor = "action-gather-" + resourceType.generic;
- else
- cursor = "action-gather-" + resourceType.specific;
+ cursor = "action-gather-" + resourceType.specific;
data.command = "gather-near-position";
data.resourceType = resourceType;
Index: binaries/data/mods/public/simulation/components/GuiInterface.js
===================================================================
--- binaries/data/mods/public/simulation/components/GuiInterface.js
+++ binaries/data/mods/public/simulation/components/GuiInterface.js
@@ -540,6 +540,17 @@
"rates": cmpResourceTrickle.GetRates()
};
+ let cmpTreasure = Engine.QueryInterface(ent, IID_Treasure);
+ if (cmpTreasure)
+ ret.treasure = {
+ "collectTime": cmpTreasure.Time(),
+ "reward": cmpTreasure.Reward()
+ };
+
+ let cmpTreasureCollecter = Engine.QueryInterface(ent, IID_TreasureCollecter);
+ if (cmpTreasureCollecter)
+ ret.treasureCollecter = true;
+
let cmpUnitMotion = Engine.QueryInterface(ent, IID_UnitMotion);
if (cmpUnitMotion)
ret.speed = {
Index: binaries/data/mods/public/simulation/components/ResourceGatherer.js
===================================================================
--- binaries/data/mods/public/simulation/components/ResourceGatherer.js
+++ binaries/data/mods/public/simulation/components/ResourceGatherer.js
@@ -25,7 +25,7 @@
"" +
"" +
"" +
- Resources.BuildSchema("positiveDecimal", ["treasure"], true) +
+ Resources.BuildSchema("positiveDecimal", [], true) +
"" +
"" +
Resources.BuildSchema("positiveDecimal") +
@@ -113,7 +113,7 @@
{
let type = r.split(".");
- if (type[0] != "treasure" && type.length > 1 && !Resources.GetResource(type[0]).subtypes[type[1]])
+ if (!Resources.GetResource(type[0]).subtypes[type[1]])
{
error("Resource subtype not found: " + type[0] + "." + type[1]);
continue;
@@ -155,35 +155,6 @@
};
/**
- * Try to gather treasure
- * @return 'true' if treasure is successfully gathered, otherwise 'false'
- */
-ResourceGatherer.prototype.TryInstantGather = function(target)
-{
- let cmpResourceSupply = Engine.QueryInterface(target, IID_ResourceSupply);
- let type = cmpResourceSupply.GetType();
-
- if (type.generic != "treasure")
- return false;
-
- let status = cmpResourceSupply.TakeResources(cmpResourceSupply.GetCurrentAmount());
-
- let cmpPlayer = QueryOwnerInterface(this.entity, IID_Player);
- if (cmpPlayer)
- cmpPlayer.AddResource(type.specific, status.amount);
-
- let cmpStatisticsTracker = QueryOwnerInterface(this.entity, IID_StatisticsTracker);
- if (cmpStatisticsTracker)
- cmpStatisticsTracker.IncreaseTreasuresCollectedCounter();
-
- let cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
- if (cmpTrigger && cmpPlayer)
- cmpTrigger.CallEvent("TreasureCollected", { "player": cmpPlayer.GetPlayerID(), "type": type.specific, "amount": status.amount });
-
- return true;
-};
-
-/**
* Gather from the target entity. This should only be called after a successful range check,
* and if the target has a compatible ResourceSupply.
* Call interval will be determined by gather rate, so always gather 1 amount when called.
Index: binaries/data/mods/public/simulation/components/ResourceSupply.js
===================================================================
--- binaries/data/mods/public/simulation/components/ResourceSupply.js
+++ binaries/data/mods/public/simulation/components/ResourceSupply.js
@@ -16,7 +16,7 @@
"Infinity" +
"" +
"" +
- Resources.BuildChoicesSchema(true, true) +
+ Resources.BuildChoicesSchema(true) +
"" +
"" +
"" +
Index: binaries/data/mods/public/simulation/components/Treasure.js
===================================================================
--- /dev/null
+++ binaries/data/mods/public/simulation/components/Treasure.js
@@ -0,0 +1,89 @@
+function Treasure() {}
+
+Treasure.prototype.Schema =
+ "Provides a bonus when taken. E.g. a supply of resources." +
+ "" +
+ "" +
+ "1000" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ Resources.BuildSchema("positiveDecimal") +
+ "" +
+ "";
+
+Treasure.prototype.Init = function()
+{
+ this.CalculateReward();
+};
+
+Treasure.prototype.CalculateReward = function()
+{
+ for (let resource in this.template.Resources)
+ {
+ let amount = ApplyValueModificationsToEntity("Treasure/Resources/" + resource, this.template.Resources[resource], this.entity);
+ if (amount)
+ {
+ if (!this.resources)
+ this.resources = {};
+ this.resources[resource] = amount;
+ }
+ }
+};
+
+/**
+ * ToDo: generalise.
+ * @return {Object} - The rewards given by this treasure.
+ */
+Treasure.prototype.Reward = function()
+{
+ return this.resources || {};
+};
+
+/**
+ * @return {number} - The time in miliseconds it takes to collect this treasure.
+ */
+Treasure.prototype.Time = function()
+{
+ return +this.template.CollectTime;
+};
+
+/**
+ * @param {number} entity - The entity taking us.
+ * @return {boolean} - Whether we are succesfully taken.
+ */
+Treasure.prototype.Collect = function(entity)
+{
+ if (!Engine.QueryInterface(entity, IID_TreasureCollecter))
+ return false;
+
+ let cmpFogging = Engine.QueryInterface(this.entity, IID_Fogging);
+ if (cmpFogging)
+ cmpFogging.Activate();
+
+ let cmpStatisticsTracker = QueryOwnerInterface(this.entity, IID_StatisticsTracker);
+ if (cmpStatisticsTracker)
+ cmpStatisticsTracker.IncreaseTreasuresCollectedCounter();
+
+ let cmpPlayer = QueryOwnerInterface(entity);
+ let cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
+ if (cmpPlayer)
+ {
+ if (this.resources)
+ cmpPlayer.AddResources(this.resources);
+
+ cmpTrigger.CallEvent("TreasureCollected", {
+ "player": cmpPlayer.GetPlayerID(),
+ "treasure": this.entity
+ });
+ }
+
+ Engine.DestroyEntity(this.entity);
+ return true;
+};
+
+Engine.RegisterComponentType(IID_Treasure, "Treasure", Treasure);
Index: binaries/data/mods/public/simulation/components/TreasureCollecter.js
===================================================================
--- /dev/null
+++ binaries/data/mods/public/simulation/components/TreasureCollecter.js
@@ -0,0 +1,110 @@
+function TreasureCollecter() {}
+
+TreasureCollecter.prototype.Schema =
+ "Defines the treasure collecting abilities." +
+ "" +
+ "2.0" +
+ "" +
+ "" +
+ "" +
+ "";
+
+TreasureCollecter.prototype.Init = function()
+{
+};
+
+/**
+ * @return {Object} - Range at which this entity can claim a treasure.
+ */
+TreasureCollecter.prototype.GetRange = function()
+{
+ // Maybe this should depend on the unit or target or something?
+ return { "max": +this.template.MaxDistance, "min": 0 };
+};
+
+/**
+ * @param {number} target - The target to collect.
+ * @param {Object} callback - Optionally an object with the functions to call on specific events.
+ * Must at least have the IID of the component to call.
+ *
+ * @return {boolean} - Whether we started collecting.
+ */
+TreasureCollecter.prototype.StartCollecting = function(target, callback)
+{
+ if (this.target)
+ this.StopCollecting();
+
+ let cmpTreasure = Engine.QueryInterface(target, IID_Treasure);
+ if (!cmpTreasure)
+ return false;
+
+ // ToDo: Implement rate modifiers.
+ let time = cmpTreasure.Time() * 1;
+
+ this.target = target;
+ this.callback = callback;
+
+ let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
+ this.timer = cmpTimer.SetTimeout(this.entity, IID_TreasureCollecter, "CollectTreasure", time, null);
+
+ return true;
+};
+
+/**
+ * @param {String} reason - The reason why we stopped collecting. Currently implemented are:
+ * "outOfRange" and "targetInvalidated".
+ */
+TreasureCollecter.prototype.StopCollecting = function(reason)
+{
+ if (this.timer)
+ {
+ let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
+ cmpTimer.CancelTimer(this.timer);
+ delete this.timer;
+ }
+ if (this.target)
+ delete this.target;
+
+ if (reason && this.callback && this.callback[reason])
+ {
+ let component = Engine.QueryInterface(this.entity, this.callback.iid);
+ if (component)
+ component[this.callback[reason]].apply(component);
+ }
+ delete this.callback;
+};
+
+/**
+ * @params - Data and lateness are unused.
+ */
+TreasureCollecter.prototype.CollectTreasure = function(data, lateness)
+{
+ let cmpTreasure = Engine.QueryInterface(this.target, IID_Treasure);
+ if (!cmpTreasure)
+ {
+ this.StopCollecting("targetInvalidated");
+ return;
+ }
+
+ if (!this.IsTargetInRange(this.target))
+ {
+ this.StopCollecting("outOfRange");
+ return;
+ }
+
+ cmpTreasure.Collect(this.entity);
+ this.StopCollecting("targetInvalidated");
+};
+
+/**
+ * @param {number} - The entity ID of the target to check.
+ * @return {boolean} - Whether this entity is in range of its target.
+ */
+TreasureCollecter.prototype.IsTargetInRange = function(target)
+{
+ let range = this.GetRange();
+ let cmpObstructionManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_ObstructionManager);
+ return cmpObstructionManager.IsInTargetRange(this.entity, target, range.min, range.max, false);
+};
+
+Engine.RegisterComponentType(IID_TreasureCollecter, "TreasureCollecter", TreasureCollecter);
Index: binaries/data/mods/public/simulation/components/UnitAI.js
===================================================================
--- binaries/data/mods/public/simulation/components/UnitAI.js
+++ binaries/data/mods/public/simulation/components/UnitAI.js
@@ -275,7 +275,6 @@
this.SetNextState("FORMATIONMEMBER.IDLE");
else
this.SetNextState("INDIVIDUAL.IDLE");
-
},
"Order.Walk": function(msg) {
@@ -680,6 +679,13 @@
this.FinishOrder();
},
+ "Order.CollectTreasure": function(msg) {
+ if (!Engine.QueryInterface(this.entity, IID_TreasureCollecter))
+ return { "discardOrder": true };
+
+ this.SetNextState("COLLECTTREASURE");
+ },
+
// States for the special entity representing a group of units moving in formation:
"FORMATIONCONTROLLER": {
@@ -2523,10 +2529,6 @@
let cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer);
- // Try to gather treasure
- if (cmpResourceGatherer.TryInstantGather(this.gatheringTarget))
- return;
-
// If we've already got some resources but they're the wrong type,
// drop them first to ensure we're only ever carrying one type
if (cmpResourceGatherer.IsCarryingAnythingExcept(resourceType.generic))
@@ -2842,6 +2844,84 @@
},
},
+ "COLLECTTREASURE": {
+ "enter": function() {
+ let cmpTreasureCollecter = Engine.QueryInterface(this.entity, IID_TreasureCollecter);
+ if (!cmpTreasureCollecter)
+ {
+ this.FinishOrder();
+ return true;
+ }
+ if (this.CheckTargetRange(this.order.data.target, IID_TreasureCollecter))
+ this.SetNextState("COLLECTING");
+ else
+ this.SetNextState("APPROACHING");
+ return true;
+ },
+
+ "leave": function() {
+ },
+
+ "APPROACHING": {
+ "enter": function() {
+ if (!this.MoveToTargetRange(this.order.data.target, IID_TreasureCollecter))
+ {
+ this.FinishOrder();
+ return true;
+ }
+ return false;
+ },
+
+ "leave": function() {
+ this.StopMoving();
+ },
+
+ "MovementUpdate": function(msg) {
+ if ((msg.likelyFailure || msg.likelySuccess) &&
+ this.CheckTargetRange(this.order.data.target, IID_TreasureCollecter))
+ this.SetNextState("COLLECTING");
+ },
+ },
+
+ "COLLECTING": { // ToDo: Autocontinue.
+ "enter": function() {
+ if (!this.CheckTargetRange(this.order.data.target, IID_TreasureCollecter))
+ {
+ this.OutOfRange();
+ return true;
+ }
+ let callback = {
+ "iid": IID_UnitAI,
+ "outOfRange": "OutOfRange",
+ "targetInvalidated": "TargetInvalidated"
+ };
+ let cmpTreasureCollecter = Engine.QueryInterface(this.entity, IID_TreasureCollecter);
+ if (!cmpTreasureCollecter.StartCollecting(this.order.data.target, callback))
+ {
+ this.TargetInvalidated();
+ return true;
+ }
+ this.FaceTowardsTarget(this.order.data.target);
+ this.SelectAnimation("collecting_treasure");
+ },
+
+ "leave": function() {
+ let cmpTreasureCollecter = Engine.QueryInterface(this.entity, IID_TreasureCollecter);
+ if (cmpTreasureCollecter)
+ cmpTreasureCollecter.StopCollecting();
+ this.ResetAnimation();
+ },
+
+ "OutOfRange": function(msg) {
+ this.SetNextState("APPROACHING");
+ },
+
+ "TargetInvalidated": function(msg) {
+ this.FinishOrder();
+ },
+ },
+ },
+
"TRADE": {
"Attacked": function(msg) {
// Ignore attack
@@ -4322,6 +4402,16 @@
this.UnitFsm.ProcessMessage(this, {"type": "PackFinished", "packed": msg.packed});
};
+UnitAI.prototype.OutOfRange = function(msg)
+{
+ this.UnitFsm.ProcessMessage(this, { "type": "OutOfRange", "data": msg });
+};
+
+UnitAI.prototype.TargetInvalidated = function(msg)
+{
+ this.UnitFsm.ProcessMessage(this, { "type": "TargetInvalidated", "data": msg });
+};
+
//// Helper functions to be called by the FSM ////
UnitAI.prototype.GetWalkSpeed = function()
@@ -5659,6 +5749,14 @@
this.AddOrder("ReturnResource", { "target": target, "force": true }, queued);
};
+/**
+ * Adds order to collect a treasure to queue, forced by the player.
+ */
+UnitAI.prototype.CollectTreasure = function(target, queued)
+{
+ this.AddOrder("CollectTreasure", { "target": target, "force": true }, queued);
+};
+
UnitAI.prototype.CancelSetupTradeRoute = function(target)
{
let cmpTrader = Engine.QueryInterface(this.entity, IID_Trader);
Index: binaries/data/mods/public/simulation/components/interfaces/Treasure.js
===================================================================
--- /dev/null
+++ binaries/data/mods/public/simulation/components/interfaces/Treasure.js
@@ -0,0 +1 @@
+Engine.RegisterInterface("Treasure");
Index: binaries/data/mods/public/simulation/components/interfaces/TreasureCollecter.js
===================================================================
--- /dev/null
+++ binaries/data/mods/public/simulation/components/interfaces/TreasureCollecter.js
@@ -0,0 +1 @@
+Engine.RegisterInterface("TreasureCollecter");
Index: binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js
===================================================================
--- binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js
+++ binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js
@@ -32,6 +32,7 @@
Engine.LoadComponentScript("interfaces/Trader.js");
Engine.LoadComponentScript("interfaces/TurretHolder.js");
Engine.LoadComponentScript("interfaces/Timer.js");
+Engine.LoadComponentScript("interfaces/Treasure.js");
Engine.LoadComponentScript("interfaces/StatisticsTracker.js");
Engine.LoadComponentScript("interfaces/StatusEffectsReceiver.js");
Engine.LoadComponentScript("interfaces/UnitAI.js");
Index: binaries/data/mods/public/simulation/components/tests/test_Treasure.js
===================================================================
--- /dev/null
+++ binaries/data/mods/public/simulation/components/tests/test_Treasure.js
@@ -0,0 +1,53 @@
+Resources = {
+ "BuildSchema": () => {
+ let schema = "";
+ for (let res of ["food", "metal"])
+ {
+ for (let subtype in ["meat", "grain"])
+ schema += "" + res + "." + subtype + "";
+ schema += " treasure." + res + "";
+ }
+ return "" + schema + "";
+ }
+};
+
+Engine.LoadHelperScript("Player.js");
+Engine.LoadComponentScript("interfaces/StatisticsTracker.js");
+Engine.LoadComponentScript("interfaces/Treasure.js");
+Engine.LoadComponentScript("interfaces/TreasureCollecter.js");
+Engine.LoadComponentScript("interfaces/Trigger.js");
+Engine.LoadComponentScript("Treasure.js");
+Engine.LoadComponentScript("Trigger.js");
+
+Engine.RegisterGlobal("ApplyValueModificationsToEntity", (prop, oVal, ent) => oVal);
+ConstructComponent(SYSTEM_ENTITY, "Trigger", {});
+
+const entity = 11;
+let treasurer = 12;
+let treasurerOwner = 1;
+
+let cmpTreasure = ConstructComponent(entity, "Treasure", {
+ "CollectTime": "1000",
+ "Resources": {
+ "Food": "10"
+ }
+});
+
+TS_ASSERT(!cmpTreasure.Collect(treasurer));
+AddMock(treasurer, IID_TreasureCollecter, {});
+
+AddMock(treasurer, IID_Ownership, {
+ "GetOwner": () => treasurerOwner
+});
+
+AddMock(SYSTEM_ENTITY, IID_PlayerManager, {
+ "GetPlayerByID": (id) => treasurerOwner
+});
+
+let cmpPlayer = AddMock(treasurerOwner, IID_Player, {
+ "AddResources": (type, amount) => {},
+ "GetPlayerID": () => treasurerOwner
+});
+let spy = new Spy(cmpPlayer, "AddResources");
+TS_ASSERT(cmpTreasure.Collect(treasurer));
+TS_ASSERT_EQUALS(spy._called, 1);
Index: binaries/data/mods/public/simulation/components/tests/test_TreasureCollecter.js
===================================================================
--- /dev/null
+++ binaries/data/mods/public/simulation/components/tests/test_TreasureCollecter.js
@@ -0,0 +1,46 @@
+Engine.LoadHelperScript("Player.js");
+Engine.LoadComponentScript("interfaces/Timer.js");
+Engine.LoadComponentScript("interfaces/Treasure.js");
+Engine.LoadComponentScript("interfaces/TreasureCollecter.js");
+Engine.LoadComponentScript("interfaces/UnitAI.js");
+Engine.LoadComponentScript("Timer.js");
+Engine.LoadComponentScript("TreasureCollecter.js");
+
+AddMock(SYSTEM_ENTITY, IID_ObstructionManager, {
+ "IsInTargetRange": () => true
+});
+
+const entity = 11;
+let treasure = 12;
+let cmpTimer = ConstructComponent(SYSTEM_ENTITY, "Timer", {});
+
+let cmpTreasurer = ConstructComponent(entity, "TreasureCollecter", {
+ "MaxDistance": "2.0"
+});
+
+TS_ASSERT(!cmpTreasurer.StartCollecting(treasure));
+
+let cmpTreasure = AddMock(treasure, IID_Treasure, {
+ "Collect": (ent) => {},
+ "Time": () => 1000
+});
+let spyTreasure = new Spy(cmpTreasure, "Collect");
+TS_ASSERT(cmpTreasurer.StartCollecting(treasure));
+cmpTimer.OnUpdate({ "turnLength": 1 });
+TS_ASSERT_EQUALS(spyTreasure._called, 1);
+
+// Test that starting to collect twice merely collects once.
+spyTreasure._called = 0;
+TS_ASSERT(cmpTreasurer.StartCollecting(treasure));
+TS_ASSERT(cmpTreasurer.StartCollecting(treasure));
+cmpTimer.OnUpdate({ "turnLength": 1 });
+TS_ASSERT_EQUALS(spyTreasure._called, 1);
+
+// Test callback is called.
+let cmpUnitAI = AddMock(entity, IID_UnitAI, {
+ "findnewtarget": () => {}
+});
+let spyUnitAI = new Spy(cmpUnitAI, "findnewtarget");
+TS_ASSERT(cmpTreasurer.StartCollecting(treasure, { "iid": IID_UnitAI, "targetInvalidated": "findnewtarget" }));
+cmpTimer.OnUpdate({ "turnLength": 1 });
+TS_ASSERT_EQUALS(spyUnitAI._called, 1);
Index: binaries/data/mods/public/simulation/helpers/Commands.js
===================================================================
--- binaries/data/mods/public/simulation/helpers/Commands.js
+++ binaries/data/mods/public/simulation/helpers/Commands.js
@@ -72,6 +72,13 @@
Cheat(cmd);
},
+ "collect-treasure": function(player, cmd, data)
+ {
+ GetFormationUnitAIs(data.entities, player, cmd, data.formation).forEach(cmpUnitAI => {
+ cmpUnitAI.CollectTreasure(cmd.target, cmd.queued);
+ });
+ },
+
"diplomacy": function(player, cmd, data)
{
let cmpCeasefireManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_CeasefireManager);
Index: binaries/data/mods/public/simulation/helpers/Resources.js
===================================================================
--- binaries/data/mods/public/simulation/helpers/Resources.js
+++ binaries/data/mods/public/simulation/helpers/Resources.js
@@ -4,7 +4,7 @@
* To prevent validation errors, disabled resources are included in the schema.
*
* @param datatype - The datatype of the element
- * @param additional - Array of additional data elements. Time, xp, treasure, etc.
+ * @param additional - Array of additional data elements. Time, xp, etc.
* @param subtypes - If true, resource subtypes will be included as well.
* @return RelaxNG schema string
*/
@@ -47,15 +47,6 @@
"" +
"";
- if (additional.indexOf("treasure") !== -1)
- for (let res of resCodes)
- schema +=
- "" +
- "" +
- datatype +
- "" +
- "";
-
return "" + schema + "";
};
@@ -63,29 +54,22 @@
* Builds the value choices for a RelaxNG `` object, based on currently valid resources.
*
* @oaram subtypes - If set to true, the choices returned will be resource subtypes, rather than main types
- * @param treasure - If set to true, the pseudo resource 'treasure' (or its subtypes) will be included
* @return String of RelaxNG Schema `` values.
*/
-Resources.prototype.BuildChoicesSchema = function(subtypes = false, treasure = false)
+Resources.prototype.BuildChoicesSchema = function(subtypes = false)
{
let schema = "";
if (!subtypes)
{
let resCodes = this.resourceData.map(resource => resource.code);
- if (treasure)
- resCodes.push("treasure");
for (let res of resCodes)
schema += "" + res + "";
}
else
for (let res of this.resourceData)
- {
for (let subtype in res.subtypes)
schema += "" + res.code + "." + subtype + "";
- if (treasure)
- schema += "" + "treasure." + res.code + "";
- }
return "" + schema + "";
};
Index: binaries/data/mods/public/simulation/helpers/Setup.js
===================================================================
--- binaries/data/mods/public/simulation/helpers/Setup.js
+++ binaries/data/mods/public/simulation/helpers/Setup.js
@@ -23,12 +23,8 @@
}
if (settings.DisableTreasures)
- for (let ent of Engine.GetEntitiesWithInterface(IID_ResourceSupply))
- {
- let cmpResourceSupply = Engine.QueryInterface(ent, IID_ResourceSupply);
- if (cmpResourceSupply.GetType().generic == "treasure")
- Engine.DestroyEntity(ent);
- }
+ for (let ent of Engine.GetEntitiesWithInterface(IID_Treasure))
+ Engine.DestroyEntity(ent);
let cmpRangeManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
if (cmpRangeManager)
Index: binaries/data/mods/public/simulation/templates/gaia/treasure/food_barrel.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/treasure/food_barrel.xml
+++ binaries/data/mods/public/simulation/templates/gaia/treasure/food_barrel.xml
@@ -8,10 +8,6 @@
Food Treasure
gaia/special_treasure_food.png
-
- 100
- treasure.food
-
@@ -20,6 +16,11 @@
+
+
+ 100
+
+
props/special/eyecandy/barrel_a.xml
Index: binaries/data/mods/public/simulation/templates/gaia/treasure/food_barrels_buried.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/treasure/food_barrels_buried.xml
+++ binaries/data/mods/public/simulation/templates/gaia/treasure/food_barrels_buried.xml
@@ -15,10 +15,11 @@
false
0.0
-
- 200
- treasure.food
-
+
+
+ 200
+
+
props/special/eyecandy/barrels_buried.xml
Index: binaries/data/mods/public/simulation/templates/gaia/treasure/food_bin.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/treasure/food_bin.xml
+++ binaries/data/mods/public/simulation/templates/gaia/treasure/food_bin.xml
@@ -11,10 +11,11 @@
-
- 300
- treasure.food
-
+
+
+ 300
+
+
props/special/eyecandy/produce_bin_a.xml
Index: binaries/data/mods/public/simulation/templates/gaia/treasure/food_crate.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/treasure/food_crate.xml
+++ binaries/data/mods/public/simulation/templates/gaia/treasure/food_crate.xml
@@ -11,10 +11,11 @@
-
- 200
- treasure.food
-
+
+
+ 200
+
+
props/special/eyecandy/crate_a.xml
Index: binaries/data/mods/public/simulation/templates/gaia/treasure/food_jars.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/treasure/food_jars.xml
+++ binaries/data/mods/public/simulation/templates/gaia/treasure/food_jars.xml
@@ -11,10 +11,11 @@
-
- 300
- treasure.food
-
+
+
+ 300
+
+
props/special/eyecandy/amphorae.xml
Index: binaries/data/mods/public/simulation/templates/gaia/treasure/food_persian_big.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/treasure/food_persian_big.xml
+++ binaries/data/mods/public/simulation/templates/gaia/treasure/food_persian_big.xml
@@ -11,10 +11,11 @@
-
- 600
- treasure.food
-
+
+
+ 600
+
+
props/special/eyecandy/treasure_persian_food_big.xml
Index: binaries/data/mods/public/simulation/templates/gaia/treasure/food_persian_small.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/treasure/food_persian_small.xml
+++ binaries/data/mods/public/simulation/templates/gaia/treasure/food_persian_small.xml
@@ -11,10 +11,11 @@
-
- 400
- treasure.food
-
+
+
+ 400
+
+
props/special/eyecandy/treasure_persian_food_small.xml
Index: binaries/data/mods/public/simulation/templates/gaia/treasure/golden_fleece.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/treasure/golden_fleece.xml
+++ binaries/data/mods/public/simulation/templates/gaia/treasure/golden_fleece.xml
@@ -7,10 +7,11 @@
Golden Fleece
-
- 1000
- treasure.metal
-
+
+
+ 1000
+
+
special/golden_fleece.xml
Index: binaries/data/mods/public/simulation/templates/gaia/treasure/metal.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/treasure/metal.xml
+++ binaries/data/mods/public/simulation/templates/gaia/treasure/metal.xml
@@ -7,15 +7,16 @@
Secret Box
-
- 300
- treasure.metal
-
+
+
+ 300
+
+
props/special/eyecandy/barrel_a.xml
Index: binaries/data/mods/public/simulation/templates/gaia/treasure/metal_persian_big.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/treasure/metal_persian_big.xml
+++ binaries/data/mods/public/simulation/templates/gaia/treasure/metal_persian_big.xml
@@ -10,15 +10,16 @@
-
- 500
- treasure.metal
-
+
+
+ 500
+
+
props/special/eyecandy/treasure_persian_metal_big.xml
Index: binaries/data/mods/public/simulation/templates/gaia/treasure/metal_persian_small.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/treasure/metal_persian_small.xml
+++ binaries/data/mods/public/simulation/templates/gaia/treasure/metal_persian_small.xml
@@ -10,15 +10,16 @@
-
- 300
- treasure.metal
-
+
+
+ 300
+
+
props/special/eyecandy/treasure_persian_metal_small.xml
Index: binaries/data/mods/public/simulation/templates/gaia/treasure/pegasus.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/treasure/pegasus.xml
+++ binaries/data/mods/public/simulation/templates/gaia/treasure/pegasus.xml
@@ -7,10 +7,11 @@
Pegasus
-
- 1000
- treasure.metal
-
+
+
+ 1000
+
+
special/pegasus.xml
Index: binaries/data/mods/public/simulation/templates/gaia/treasure/shipwreck.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/treasure/shipwreck.xml
+++ binaries/data/mods/public/simulation/templates/gaia/treasure/shipwreck.xml
@@ -14,10 +14,11 @@
true
0.0
-
- 500
- treasure.wood
-
+
+
+ 500
+
+
props/special/eyecandy/shipwreck_ram_side.xml
Index: binaries/data/mods/public/simulation/templates/gaia/treasure/shipwreck_debris.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/treasure/shipwreck_debris.xml
+++ binaries/data/mods/public/simulation/templates/gaia/treasure/shipwreck_debris.xml
@@ -17,10 +17,11 @@
true
0.0
-
- 200
- treasure.food
-
+
+
+ 200
+
+
props/special/eyecandy/barrels_floating.xml
Index: binaries/data/mods/public/simulation/templates/gaia/treasure/shipwreck_ram_bow.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/treasure/shipwreck_ram_bow.xml
+++ binaries/data/mods/public/simulation/templates/gaia/treasure/shipwreck_ram_bow.xml
@@ -14,10 +14,11 @@
true
0.0
-
- 550
- treasure.wood
-
+
+
+ 550
+
+
props/special/eyecandy/shipwreck_ram_bow.xml
Index: binaries/data/mods/public/simulation/templates/gaia/treasure/shipwreck_sail_boat.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/treasure/shipwreck_sail_boat.xml
+++ binaries/data/mods/public/simulation/templates/gaia/treasure/shipwreck_sail_boat.xml
@@ -14,10 +14,11 @@
true
0.0
-
- 400
- treasure.wood
-
+
+
+ 400
+
+
props/special/eyecandy/shipwreck_sail_boat.xml
Index: binaries/data/mods/public/simulation/templates/gaia/treasure/shipwreck_sail_boat_cut.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/treasure/shipwreck_sail_boat_cut.xml
+++ binaries/data/mods/public/simulation/templates/gaia/treasure/shipwreck_sail_boat_cut.xml
@@ -14,10 +14,11 @@
true
0.0
-
- 450
- treasure.wood
-
+
+
+ 450
+
+
props/special/eyecandy/shipwreck_sail_boat_cut.xml
Index: binaries/data/mods/public/simulation/templates/gaia/treasure/standing_stone.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/treasure/standing_stone.xml
+++ binaries/data/mods/public/simulation/templates/gaia/treasure/standing_stone.xml
@@ -10,15 +10,16 @@
-
- 300
- treasure.stone
-
+
+
+ 300
+
+
props/special/eyecandy/standing_stones.xml
Index: binaries/data/mods/public/simulation/templates/gaia/treasure/stone.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/treasure/stone.xml
+++ binaries/data/mods/public/simulation/templates/gaia/treasure/stone.xml
@@ -10,15 +10,16 @@
-
- 300
- treasure.stone
-
+
+
+ 300
+
+
props/special/eyecandy/stone_pile.xml
Index: binaries/data/mods/public/simulation/templates/gaia/treasure/wood.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/treasure/wood.xml
+++ binaries/data/mods/public/simulation/templates/gaia/treasure/wood.xml
@@ -10,15 +10,16 @@
-
- 300
- treasure.wood
-
+
+
+ 300
+
+
props/special/eyecandy/wood_pile.xml
Index: binaries/data/mods/public/simulation/templates/template_gaia_treasure.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_gaia_treasure.xml
+++ binaries/data/mods/public/simulation/templates/template_gaia_treasure.xml
@@ -16,11 +16,6 @@
-
- false
- 300
- 1
-
@@ -36,4 +31,7 @@
3.75
+
+ 1000
+
Index: binaries/data/mods/public/simulation/templates/template_unit.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit.xml
+++ binaries/data/mods/public/simulation/templates/template_unit.xml
@@ -83,19 +83,6 @@
-
- 2.0
- 1.0
-
- 1
-
-
- 10
- 10
- 10
- 10
-
-
@@ -118,6 +105,9 @@
5.0
+
+ 2
+
aggressive
12.0
Index: binaries/data/mods/public/simulation/templates/template_unit_catafalque.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_catafalque.xml
+++ binaries/data/mods/public/simulation/templates/template_unit_catafalque.xml
@@ -28,7 +28,6 @@
pitch-roll
-
Index: binaries/data/mods/public/simulation/templates/template_unit_cavalry.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_cavalry.xml
+++ binaries/data/mods/public/simulation/templates/template_unit_cavalry.xml
@@ -65,9 +65,6 @@
20
- 20
- 20
- 20
Index: binaries/data/mods/public/simulation/templates/template_unit_dog.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_dog.xml
+++ binaries/data/mods/public/simulation/templates/template_unit_dog.xml
@@ -47,7 +47,6 @@
-
Index: binaries/data/mods/public/simulation/templates/template_unit_fauna.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_fauna.xml
+++ binaries/data/mods/public/simulation/templates/template_unit_fauna.xml
@@ -21,7 +21,6 @@
4
-
Index: binaries/data/mods/public/simulation/templates/template_unit_infantry.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_infantry.xml
+++ binaries/data/mods/public/simulation/templates/template_unit_infantry.xml
@@ -97,6 +97,12 @@
2
0.5
+
+ 10
+ 10
+ 10
+ 10
+
Index: binaries/data/mods/public/simulation/templates/template_unit_ship_bireme.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_ship_bireme.xml
+++ binaries/data/mods/public/simulation/templates/template_unit_ship_bireme.xml
@@ -55,13 +55,13 @@
25
15
-
attack/impact/arrow_impact.xml
attack/weapon/bow_attack.xml
+
1.55
Index: binaries/data/mods/public/simulation/templates/template_unit_ship_fire.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_ship_fire.xml
+++ binaries/data/mods/public/simulation/templates/template_unit_ship_fire.xml
@@ -47,7 +47,6 @@
-
ship-small
1.6
Index: binaries/data/mods/public/simulation/templates/template_unit_ship_fishing.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_ship_fishing.xml
+++ binaries/data/mods/public/simulation/templates/template_unit_ship_fishing.xml
@@ -47,10 +47,11 @@
+
+ 1.0
6.0
1.8
-
40
@@ -75,6 +76,7 @@
0.333
5.0
+
passive
false
Index: binaries/data/mods/public/simulation/templates/template_unit_ship_quinquereme.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_ship_quinquereme.xml
+++ binaries/data/mods/public/simulation/templates/template_unit_ship_quinquereme.xml
@@ -69,12 +69,12 @@
2
-
attack/siege/ballist_attack.xml
+
1.8
Index: binaries/data/mods/public/simulation/templates/template_unit_ship_trireme.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_ship_trireme.xml
+++ binaries/data/mods/public/simulation/templates/template_unit_ship_trireme.xml
@@ -58,13 +58,13 @@
2
-
attack/impact/arrow_impact.xml
attack/weapon/bow_attack.xml
+
1.8
Index: binaries/data/mods/public/simulation/templates/template_unit_support_female_citizen.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_support_female_citizen.xml
+++ binaries/data/mods/public/simulation/templates/template_unit_support_female_citizen.xml
@@ -78,6 +78,12 @@
2
0.35
+
+ 10
+ 10
+ 10
+ 10
+
Index: binaries/data/mods/public/simulation/templates/template_unit_support_slave.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_support_slave.xml
+++ binaries/data/mods/public/simulation/templates/template_unit_support_slave.xml
@@ -61,9 +61,15 @@
1.0
5
1.0
-
+
+ 10
+ 10
+ 10
+ 10
+
+
resource/construction/con_wood.xml