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
@@ -8,6 +8,10 @@
"false" +
"25" +
"0.8" +
+ "" +
+ "0.5" +
+ "500" +
+ "/Regeneration>" +
"" +
"" +
"" +
@@ -25,12 +29,37 @@
"" +
"" +
"" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
"";
ResourceSupply.prototype.Init = function()
{
// Current resource amount (non-negative)
this.amount = this.GetMaxAmount();
+
+ this.regenRate = null;
+ this.regenInterval = null;
+ this.regenerate = null; // timer
+
+ if ("Regeneration" in this.template)
+ {
+ this.regenRate = +this.template.Regeneration.RegenRate;
+ this.regenInterval = +this.template.Regeneration.RegenInterval;
+
+ if (!this.GetKillBeforeGather())
+ this.regenerate = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer).SetInterval(this.entity, IID_ResourceSupply, "RegenerateSupply", this.regenInterval, this.regenInterval, undefined);
+ }
// List of IDs for each player
this.gatherers = [];
@@ -138,6 +167,9 @@
Engine.PostMessage(this.entity, MT_ResourceSupplyNumGatherersChanged, { "to": this.GetNumGatherers() });
}
+ if (this.regenerate)
+ this.regenerate = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer).CancelTimer(this.regenerate);
+
return true;
};
@@ -161,6 +193,20 @@
return;
}
}
+
+ if (!this.gatherers.every((player) => player.length))
+ this.regenerate = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer).SetInterval(this.entity, IID_ResourceSupply, "RegenerateSupply", this.regenInterval, this.regenInterval, undefined);
+};
+
+ResourceSupply.prototype.RegenerateSupply = function()
+{
+ let current = this.amount;
+ this.amount = Math.max(0, current + this.regenRate);
+
+ if (this.amount == 0)
+ Engine.DestroyEntity(this.entity);
+
+ Engine.PostMessage(this.entity, MT_ResourceSupplyChanged, { "from": current, "to": this.amount });
};
Engine.RegisterComponentType(IID_ResourceSupply, "ResourceSupply", ResourceSupply);
Index: binaries/data/mods/public/simulation/templates/template_unit_fauna_hunt.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit_fauna_hunt.xml
+++ binaries/data/mods/public/simulation/templates/template_unit_fauna_hunt.xml
@@ -12,5 +12,9 @@
100
food.meat
8
+
+ -0.25
+ 1000
+