Adding Upkeep or Maintenance

I’m currently working on a rebalance data mod, and one of the things I’m dying to add is some sort of ongoing food cost for units you have already created.

I’ve tried doing it using a negative multiplier for the feitoria ability, without success. I’ve also tried to use some sort of auto self plunder/raid or a variation of the make ability used by farms. But I couldn’t get it to work.

Essentially what I need is for a player’s food storage to slowly tick down based on their population. I’m open to suggestions on how to make this. Similar to how it works in the game Cossacks.

At this point I’m desperate enough that I’ve thought of using a negative food storage value in an invisible unit that gets spawned as an annex by villagers and just continuously dies and spawns itself upon death or some variation of the concept. There has to be a more elegant solution… To be honest, all my problems would be solved if the Feitoria ability could subtract values from a player’s resource when the multiplier is negative.

xs scripting is what you need and you’d probably need to incorporate that into the RMS, that way it’ll still work on random map, but just the ones with the RMS that has this xs script.

as to how to write it not sure.

if you want only datamod without xs-scripting, then use the old sicilian’s UT that loops itself and check how many military units on field every 10 seconds till end of game. that would have to mean the feature would need to work with negative value and output negative resource. we know it gives positive resources as the old UT was 20gold per military unit on field.

if it works with negative value, what you wanted is doable.

1 Like

Really appreciate the help!

So, regarding the sicilian UT, it doesn’t seem to solve my problem because I already had a way to calculate the appropriate amount of food using civilization resources and effects. The main issue was the inability to keep executing the effect periodically. So for instance I could have an effect that sets an unused civ resource to be the total population value (11) times a constant I’d set to a reasonable value like 0.05 or similar depending on update frequency. Then just modify the current food amount by that variable.

My problem is specifically with having to run the effect periodically, based on what the wiki and a video by Spirit of the Law the Scutage effect ran only once and probably made use of the military population civ resource. I couldn’t find it in the DE data either…

But the XS Scripting works for my needs, in fact it has a high update frequency setting for periodic events, it’s just an amazing tool. And since my data mod is supposed to be used in conjunction with a custom RMS it suits my purposes perfectly. It’d have been cool to have kept it contained to a data mod though!

So, thanks again for showing me the tool I needed. :slight_smile:

Interesting idea for a mercenary unit that cost gold while on the field.


Just sharing my basic loop here in case anyone ever stumbles on this thread looking for the same thing.

// Here, you are creating a function that is called ‘main’.
void main() {
xsEffectAmount(cModResource, cAttributeFood, cAttributeAdd, 50, -1);

//Pop Food Consumption Logic

//Constant divider is frequency times 20
float div = 1200; // 60 * 20

//Get Player Food Amount
float RecalculateFood(int playerID = 1) {
float pfood = xsPlayerAttribute(playerID, 0);
float ppop = xsPlayerAttribute(playerID, 11);
pfood = pfood - ( ppop / div );
return (pfood);

// Loop for consumption
float rfood = 0;
rule chatTheValueOfA
group chatGroup
for(p = 1; < xsGetNumPlayers()) {
rfood = RecalculateFood(p);
xsSetPlayerAttribute(p, 0, rfood);

I was thinking about the same thing!

Though I was thinking of a more generic loop where you pay a tiny amount of gold per each each military unit as upkeep. Though I’d be reluctant to add that because you can just go full trash and ignore your negative gold. And I’m not feeling like coding rebelion mechanics. lol

1 Like

But it adds a strategic depth to your unit selection.You can go for gold using powerful units or low quality/levy trash units.

Im interested to hear your idea on how to implement a rebellion.I would imagine a rebellion where a portion of the units turns hostile gaia and start attacking you when payment runs out.

Either that or just making it so that you cannot train new units of any type when your gold is on the negatives, or perhaps they just cost double… That’d be much easier to implement. A proper units turn hostile system would be hard to implement properly, because it might just be frustrating or ineffective or just look very glitchy. The key thing with a gold upkeep for gameplay is:
-You are adding a requirement for every player to want to have some gold income and limits army size vs economy size and increases the value of gold mines or trade.
-You do not want to allow someone to cheese it by letting the gold slide into negative infinity while building only post imperial trash.

Though if you ever play the mod I’m making, provisionally called Epic Matches 2, you would see that in a true competitive game you’d hardly ever make to Imperial or mine out the map… At least not on a 1x1. On that note, I’m very very much looking for players to test it, interested?

1 Like

im really bad at programming so xs is outside my expertise. @PsychoticSock1 would know way more on this topic.

as for the loop with just datamod, have a type 80 unit that spawn from TC, that is invisible with no hitbox and high regen so it is unkillable. the spawn method is similar to incas’s sheep, or guarjaras’ bush, or chinese/mayan extra vills.

then another unit that spawns from this type 80 which triggers the tech/effect of the sicilian’s calculation, and it’s dead unit is also itself, with the death animation set to say 3 seconds (calculating every 3 seconds ingame) thus looping itself.

if the negative value thing work with negative resource output, then it’ll work. xs is definitely cleaner for sure.

to answer the frequency and non-integer value those require testing. frequency can be set low but with low-ingame fps it affects everything, game is old and when lag a lot of things break just how it is. probablyb est to set that 1 second interval.

We think very alike, I thought about something like that. I even started trying to implement it using ####### but it didn’t really work because it create 10 other glitches I’d have to solve including a crash when it dies. Also I’m still pretty sure that the sicilian ability just uses the military population civ resource and doesn’t actually cycle through units. So I’d have to make every unit, or at least every house/TC/castle, spawn it to keep count.

I’ll say it though, I’m so very pleased with xs that I don’t think I will bother, especially since now it left me wondering about all the different things I could do with it… It’s so powerful, I’m very happy the devs added it with Lord of the West.

As for the negative value and fractional values, it’s important to note that most variables in the game, including the basic resources, are all floating numbers. The UI rounds them up, but actually it’s a fractional float value. You can observe that first hand if you trade with a really close market as it will round the gold value to 0, but actually your gold will still go up over multiple trips. The truth is that it’s going up by a fraction and eventually it just gets rounded up on the UI, on the back end the value is different.

As you probably know, floating numbers are signed, or at least those in AOE2 are. They can be set to any value and the effects allow you to edit them by fractional values. In my test with xs it worked flawlessly, the food counter drops smoothly with the code running 60 times a second, it is very satisfying to watch…

You can give it a try:

Edit: apparently the world a n n e # # # is censured. I have no idea why. It’s a thing in genie, Annex Units. lol