Jump to content

Mod question: Make units lose health if a resource is beyond a given threshold


MirceaKitsune
 Share

Recommended Posts

I have a question related to modding. Was thinking of making a simple mod to change the basics of how some buildings and units behave, possibly add new units or upgrades and so on. Looking at existing examples I'm happy with how easy this seems to be done by simply modifying simulation/templates/*.xml. Yet there are a few wishes I had in mind which might require custom code which I'm not willing to get into yet unless the necessary script would be simple. Wanted to ask if there's a builtin way to do what I was thinking via defs alone.

Essentially I was pondering implementing a mechanic from Glest / Megaglest: Food as a resource is periodically consumed by living units. If food drops below a certain amount, organic units begin taking damage and slowly lose their health over time until they die. You'd thus have to keep producing food not just to create new soldiers, but also to keep existing ones from dying. It was a simple starvation mechanic which made things interesting and gave you something extra to look for.

I guess there would be two parts to this question: First, can you make it so that an unit periodically consumes resources during its existence, so that the more units you have the more this small drain adds up over time? And second, can you make a stat offset with the amount of a resource you have... in this case regeneration, but have it go negative if food is below a given threshold so it drains the health instead? Ideally damage is random and you can hear the damage sound (scream, crumble, etc).

I'm even thinking of going further and requiring stone to maintain buildings, having them lose health and eventually crumble if you're down to too little stone. Or catapults with metal, so you need to consume like 10 metal every minute to keep them in shape else they start breaking down. Could be a fun mechanic to experiment with, but only planning to bother if the engine already supports this as a capability... if not what would be the simplest script to add such a mechanic via new xml settings in units if it can be something basic?

Link to comment
Share on other sites

5 minutes ago, Langbart said:

@Silier's mod did that.

Ref: Survival [A23 only] (14/Jul/19)

image.jpeg.e20bd1c37c8b5eb2d1ce865e1dcbca76.jpeg

Should be useful, will look more closely tomorrow, thanks. Does it require custom scripting or is the "consuming" field a builtin setting? I also found something called resource trickle in the defaults which I presume is an interval based decrease, may come in handy to at least simulate food getting used over time.

Link to comment
Share on other sites

On 15/06/2022 at 3:57 AM, Freagarach said:

We have an Upkeep component, and you'll need to override one or two functions: https://code.wildfiregames.com/source/0ad/browse/ps/trunk/binaries/data/mods/public/simulation/components/Upkeep.js$73.

I didn't know this existed! You must have added it since after my hiatus :-p

@FreagarachIs it better for performance to have longer ticker intervals? Eg between 2 and 10 seconds instead of 1 second? Also How are fractions calculated? If I did .2 food per second, would it do 0 food or 1 every 5 seconds? Hope you don't mind all the questions.

You might be waiting for me to stop asking questions and actually make a contribution to the codebase or at least a mod but I am trying to understand things properly first :-p.

Edited by myou5e
Link to comment
Share on other sites

7 hours ago, myou5e said:

Is it better for performance to have longer ticker intervals? Eg between 2 and 10 seconds instead of 1 second? Also How are fractions calculated? If I did .2 food per second, would it do 0 food or 1 every 5 seconds? Hope you don't mind all the questions.

Less ticks means less execution time. There was a plan to make gathering a bit more efficient by doing more resource gathering at once.

It would be 0.2 per second if decimals are allowed. The GUI might not represent that well, though.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

For now I'm likely going to skip this feature as it makes my mod more complex than where I wanna go. If the engine adds support for this on units later, that would be an interesting feature to have and play with.

I also noticed something else: The game will break and print tons of errors if you add a negative value to resource trickle. This does feel like a bug to be fair and it would be nice to see it resolved. If anyone can't reproduce it let me know and I'll try it again and share what's happening.

Link to comment
Share on other sites

50 minutes ago, MirceaKitsune said:

For now I'm likely going to skip this feature as it makes my mod more complex than where I wanna go. If the engine adds support for this on units later, that would be an interesting feature to have and play with.

I also noticed something else: The game will break and print tons of errors if you add a negative value to resource trickle. This does feel like a bug to be fair and it would be nice to see it resolved. If anyone can't reproduce it let me know and I'll try it again and share what's happening.

 

I remember a similar error in a mod I created to play with some ideas, I believe this error is solved by editing some value in a file in the gui. But I forgot what it was, if I find it I'll come back here to tell you what it was.

Link to comment
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.

 Share

×
×
  • Create New...