Jump to content

Tips: Make your citizens consume food...


Recommended Posts

I am asking a question on here so I also need to provide a tip or two, for what they are worth... Experienced modders are no doubt already aware of this but for the people new to coding:

I am always aggrieved by units that cost food to "create", but then do not consume food whilst they are "alive". So, how to make your units consume food:

(1) Change the simulation/components/ResourceTrickle.js

Add a new schema element that provides "Negative Trickle" amounts...

ResourceTrickle.prototype.Schema =
        "<a:help>Controls the resource trickle ability of the unit.</a:help>" +
        "<element name='Rates' a:help='Positive Trickle Rates'>" +
                Resources.BuildSchema("nonNegativeDecimal") +
        "</element>" +
        "<element name='NegativeRates' a:help='Negative Trickle Rates'>" +
                Resources.BuildSchema("nonNegativeDecimal") +
        "</element>" +

        "<element name='Interval' a:help='Number of miliseconds must pass for the player to gain the next trickle.'>" +
                "<ref name='nonNegativeDecimal'/>" +
        "</element>";

(2) Update the function to take account of the "Negative Trickle":

ResourceTrickle.prototype.ComputeRates = function()
{
        this.rates = {};
        for (let resource in this.template.Rates)
                this.rates[resource] = ApplyValueModificationsToEntity("ResourceTrickle/Rates/"+resource, +this.template.Rates[resource], this.entity);

        for (let resource in this.template.NegativeRates)
                this.rates[resource] = ApplyValueModificationsToEntity("ResourceTrickle/NegativeRates/"+resource, -this.template.NegativeRates[resource], this.entity);

};

(3) Change the simulation/templates/template_unit.xml

Add the newly defined element to the Xml as appropriate. The unit is the default for "everyone" and so covers the whole population that needs to feed:

  <ResourceTrickle>
    <Rates/>
    <NegativeRates>
      <food>0.1</food>
    </NegativeRates>

    <Interval>4000</Interval>
  </ResourceTrickle>

(4) Start feeding your population before you run out of food...

Hope it's useful to somebody...

*NOTE: Obviously, the templates for template_structure.xml  must also be updated to included the new element (e.g. <NegativeRates/>). Under most circumstances you do not want it but I use it for my blacksmith so that he burns wood to keep the forge hot, etc. You can use it for anything that consume resources by default.

 

Edited by Grenefolc
There is always something to forget...
Link to post
Share on other sites
26 minutes ago, dmzerocold said:

And what if food amount reach 0 ?

I forgot to mention this earlier, but you need a check in ResourceTrickle.js before trickling if you don't want negative resource amounts.

Link to post
Share on other sites

Probably not, this discussion came up before and many casual rts gamers felt it would add too much micro and such. But I am working on a delenda est/balance-mod/age-of-0ad mega fork that will focus on the tastes of more hardcore rts gamers with supply lines, more combat support units such as engineers, etc

  • Like 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...