Index: binaries/data/mods/public/simulation/components/Health.js
===================================================================
--- binaries/data/mods/public/simulation/components/Health.js
+++ binaries/data/mods/public/simulation/components/Health.js
@@ -293,9 +293,17 @@
// persistent corpse retaining the ResourceSupply element of the parent.
var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
var templateName = cmpTemplateManager.GetCurrentTemplateName(this.entity);
- var corpse;
+ let corpse;
if (leaveResources)
- corpse = Engine.AddEntity("resource|" + templateName);
+ {
+ let cmpResourceSupply = Engine.QueryInterface(this.entity, IID_ResourceSupply);
+ if (cmpResourceSupply)
+ {
+ corpse = Engine.AddEntity("resource|" + templateName);
+ let corpseResourceSupply = Engine.QueryInterface(corpse, IID_ResourceSupply);
+ corpseResourceSupply.SetAmount(cmpResourceSupply.GetCurrentAmount());
+ }
+ }
else
corpse = Engine.AddLocalEntity("corpse|" + templateName);
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,18 @@
"false" +
"25" +
"0.8" +
+ "" +
+ "" +
+ "true" +
+ "0.5" +
+ "500" +
+ "" +
+ "" +
+ "true" +
+ "0.5" +
+ "" +
+ "500" +
+ "" +
"" +
"" +
"" +
@@ -25,13 +37,84 @@
"" +
"" +
"" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
"";
+
ResourceSupply.prototype.Init = function()
{
// Current resource amount (non-negative)
- this.amount = this.GetMaxAmount();
+ this.amount = +this.template.Amount;
+ this.maxAmount = this.amount;
+
+ this.regenRate = 0;
+ this.decayRate = 0;
+ this.regenInterval = null;
+ this.regenerateTimer = null;
+ this.growsWhenAliveOnly = false;
+ this.decaysWhenDeadOnly = false;
+
+ if (this.template.Regeneration)
+ {
+ this.regenInterval = +this.template.Regeneration.RegenInterval;
+ if (this.template.Regeneration.Fattening)
+ {
+ this.growsWhenAliveOnly = this.template.Regeneration.Fattening.GrowsWhenAliveOnly == "true";
+ this.regenRate = +this.template.Regeneration.Fattening.Rate;
+ if (this.template.Regeneration.Fattening.MaxAmount && +this.template.Regeneration.Fattening.MaxAmount > this.amount && this.GetKillBeforeGather())
+ this.maxAmount = +this.template.Regeneration.Fattening.MaxAmount;
+ }
+ if (this.template.Regeneration.Decaying)
+ {
+ this.decaysWhenDeadOnly = this.template.Regeneration.Decaying.DecaysWhenDeadOnly == "true";
+ this.decayRate = +this.template.Regeneration.Decaying.Rate;
+ }
+
+ if (!this.GetKillBeforeGather())
+ this.regenerateTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer).SetInterval(this.entity, IID_ResourceSupply, "RegenerateSupply", this.regenInterval, this.regenInterval, undefined);
+ else if(this.template.Regeneration.Fattening && this.template.Regeneration.Fattening.MaxAmount && this.template.Regeneration.Fattening.MaxAmount > this.amount && this.GetKillBeforeGather())
+ this.regenerateTimer = 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 = [];
let numPlayers = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetNumPlayers()
@@ -56,7 +139,7 @@
ResourceSupply.prototype.GetMaxAmount = function()
{
- return +this.template.Amount;
+ return this.maxAmount;
};
ResourceSupply.prototype.GetCurrentAmount = function()
@@ -90,6 +173,11 @@
return null;
};
+ResourceSupply.prototype.SetAmount = function(newAmount)
+{
+ this.amount = Math.min(Math.max(newAmount), this.GetMaxAmount());
+}
+
ResourceSupply.prototype.TakeResources = function(rate)
{
// Before changing the amount, activate Fogging if necessary to hide changes
@@ -138,6 +226,9 @@
Engine.PostMessage(this.entity, MT_ResourceSupplyNumGatherersChanged, { "to": this.GetNumGatherers() });
}
+ if (this.regenerateTimer)
+ this.regenerateTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer).CancelTimer(this.regenerateTimer);
+
return true;
};
@@ -161,6 +252,43 @@
return;
}
}
+
+ if (!this.gatherers.every((player) => player.length) && !this.regenerateTimer && this.template.Regeneration)
+ this.regenerateTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer).SetInterval(this.entity, IID_ResourceSupply, "RegenerateSupply", this.regenInterval, this.regenInterval, undefined);
};
+ResourceSupply.prototype.RegenerateSupply = function()
+{
+ let old = this.GetCurrentAmount();
+ if(!this.growsWhenAliveOnly || this.decaysWhenDeadOnly)
+ {
+ let cmpVisual = Engine.QueryInterface(this.entity, IID_Visual);
+ let cmpHealth = Engine.QueryInterface(this.entity, IID_Health);
+ if(cmpHealth && this.growsWhenAliveOnly && cmpHealth.GetHitpoints() > 0 && cmpVisual.GetAnimationName() === "feeding")
+ this.amount += this.regenRate;
+
+ // Check whether the entity is dead by using the variant name, as the health is now the resource amount.
+ if (cmpVisual && this.decaysWhenDeadOnly && cmpVisual.GetAnimationName() === "death")
+ this.amount += this.decayRate;
+ }
+
+ if(!this.growsWhenAliveOnly)
+ {
+ this.amount += this.regenRate;
+ }
+
+ if(!this.decaysWhenDeadOnly)
+ {
+ this.amount += this.decayRate;
+ }
+
+ this.SetAmount(this.amount);
+
+ // Remove entities that have been exhausted
+ if (this.GetMaxAmount() === 0)
+ Engine.DestroyEntity(this.entity);
+
+ Engine.PostMessage(this.entity, MT_ResourceSupplyChanged, { "from": old, "to": this.GetMaxAmount() });
+};
+
Engine.RegisterComponentType(IID_ResourceSupply, "ResourceSupply", ResourceSupply);
Index: binaries/data/mods/public/simulation/templates/gaia/fauna_sheep.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/gaia/fauna_sheep.xml
+++ binaries/data/mods/public/simulation/templates/gaia/fauna_sheep.xml
@@ -12,6 +12,20 @@
pitch
+
+
+
+ true
+ 200
+ 1
+
+
+ true
+ -0.5
+
+ 1000
+
+
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,12 @@
100
food.meat
8
+
+
+ true
+ -0.5
+
+ 1000
+