How to mod the game to include unit limits?

Contribute, display and discuss rulesets and modpacks for use in Freeciv here.
Sanguivorant
Posts: 11
Joined: Mon Apr 25, 2022 12:54 am

How to mod the game to include unit limits?

Post by Sanguivorant »

In my opinion, the biggest problem that the AI has is that it just never knows when to stop building units. Not only that but they will mass produce the units that have the largest defence strength. Because of this, most games that are played with the AI often end up like this:
-Initial peace where the civ progresses in science
-War breaks out and each AI develops a defensive posture
-The AI mass produces phalanxes and stalls in production or science due to insane unit upkeep costs.
-A total of 300 phalanxes on the battlefield and literally no other unit being made
-400 freights and caravans in the game not doing anything but moving around, and lagging the game
-frontlines devolve into stalemates and city conquest becomes impossible; national borders don't change for years
-The AI with the most number of cities wins, since they can best weather the crippling unit upkeep costs.

Most of the games I play don't have map sizes that exceed 100x80, and don't exceed ten players. If I could create a rule to limit the number of units of a specific unit type that an AI can build, I would force the AI to build more than just phalanxes and it would be better overall. But how do I do this?
cazfi
Elite
Posts: 3111
Joined: Tue Jan 29, 2013 6:54 pm

Re: How to mod the game to include unit limits?

Post by cazfi »

There's several causes to that AI behavior, but one thing that explain some of it: https://osdn.net/projects/freeciv/ticket/45592 - it builds defenders for martial law effect, but then lets them to leave the city, and needs to build new ones... ad infinitum.
Add to that https://osdn.net/projects/freeciv/ticket/45595 causing it to want martial law units too much to begin with.

Don't know if I can get anything done for those before 3.0.5 (quite overwhelmed with other issues), but hopefully get something done to 3.0.6.

As for having limited number of certain unit type. No, there currently isn't an easy way to do that, but it might be relatively easy to add, based on existing unique unit concept (which is essentially such a limit with a value of 1), to a future version.
cazfi
Elite
Posts: 3111
Joined: Tue Jan 29, 2013 6:54 pm

Re: How to mod the game to include unit limits?

Post by cazfi »

cazfi wrote: Tue Oct 25, 2022 3:55 amAdd to that https://osdn.net/projects/freeciv/ticket/45595 causing it to want martial law units too much to begin with.
For that one I have a patch in testing. It has passed some smoke tests (set of all-AI autogames went through without server crashing). Any volunteers to test it in their game, to see that it has no surprise side-effects?

Such side-effects are often problem in fixing our AI bugs - some seemingly unrelated other part breaks when fixed part gives different results from what it used to.
cazfi
Elite
Posts: 3111
Joined: Tue Jan 29, 2013 6:54 pm

Re: How to mod the game to include unit limits?

Post by cazfi »

Well, one problem is that in an freeciv-3.0 autogame, which I had an observer client following, an AI city produced so much history (culture value) that it overflow in the network protocol (wouldn't happen in freeciv-3.1).
Ignatus
Elite
Posts: 644
Joined: Mon Nov 06, 2017 12:05 pm
Location: St.Petersburg, Russia
Contact:

Re: How to mod the game to include unit limits?

Post by Ignatus »

I think, the limitation should be in a form "X units per city" (like CivII Caravan, but for it specifically we'd better use unique goods system) or "Y cities per unit" (like CivIII Army). And for just AI doing sane things, I think, before processing cities loop there should be some general accounting of the present unit forces, and then "want" for types that already have no where to apply themselves should be significantly reduced. (But while the accounting is more or less doable, finding where the necessary building "want" sits in the AI code needs lots of patience...)
cazfi
Elite
Posts: 3111
Joined: Tue Jan 29, 2013 6:54 pm

Re: How to mod the game to include unit limits?

Post by cazfi »

Ignatus wrote: Sun Oct 30, 2022 9:58 pmbefore processing cities loop there should be some general accounting of the present unit forces, and then "want" for types that already have no where to apply themselves should be significantly reduced.
That's what it does with workers (at least). Defenders are different in that we still want to produce them in the city under attack, even if there are free ones on the other side of the world.
Ignatus
Elite
Posts: 644
Joined: Mon Nov 06, 2017 12:05 pm
Location: St.Petersburg, Russia
Contact:

Re: How to mod the game to include unit limits?

Post by Ignatus »

cazfi wrote: Sun Oct 30, 2022 10:14 pm
Ignatus wrote: Sun Oct 30, 2022 9:58 pmbefore processing cities loop there should be some general accounting of the present unit forces, and then "want" for types that already have no where to apply themselves should be significantly reduced.
That's what it does with workers (at least). Defenders are different in that we still want to produce them in the city under attack, even if there are free ones on the other side of the world.
Right, but AI should resort to overproducing defenders in really emergent cases. (Like, in the cases when it is necessary to buy one. When a horseman is in one or two steps from your empty city, it's too late to build there a phalanx in 12 turns.) And, well, we return to the question of how do all these forses get to where they are present from where they are needed.
cazfi
Elite
Posts: 3111
Joined: Tue Jan 29, 2013 6:54 pm

Re: How to mod the game to include unit limits?

Post by cazfi »

Ignatus wrote: Sun Oct 30, 2022 11:33 pmRight, but AI should resort to overproducing defenders in really emergent cases. (Like, in the cases when it is necessary to buy one. When a horseman is in one or two steps from your empty city, it's too late to build there a phalanx in 12 turns.) And, well, we return to the question of how do all these forses get to where they are present from where they are needed.
True. Just when discussing current design vs better future designs, one needs to be careful not to see current buggy implementation same as current design. It would already be an improvement to get current code to work as it's meant to.
As for making bigger redesigns, it would likely make sense to start from scratch as a new AI module (that's the reason I implemented to AI modules/types support ... in freeciv-2.4) Unfortunately I myself struggle to find time to get even modest (as it still relies on default AI as a dependency module) Tex rearrangements done so it would usable in freeciv-3.1.
Sanguivorant
Posts: 11
Joined: Mon Apr 25, 2022 12:54 am

Re: How to mod the game to include unit limits?

Post by Sanguivorant »

cazfi wrote: Sun Oct 30, 2022 3:41 am
cazfi wrote: Tue Oct 25, 2022 3:55 amAdd to that https://osdn.net/projects/freeciv/ticket/45595 causing it to want martial law units too much to begin with.
For that one I have a patch in testing. It has passed some smoke tests (set of all-AI autogames went through without server crashing). Any volunteers to test it in their game, to see that it has no surprise side-effects?

Such side-effects are often problem in fixing our AI bugs - some seemingly unrelated other part breaks when fixed part gives different results from what it used to.
I would be willing to test it honestly. At this rate I might even remove high-defence units to see if it would change AI behaviour.

Edit: Actually I found an easier way to fix this without changing the AI.

In the Ruleset, the units that are defined as "DefendGood" seem to be overprioritized by the AI. I did some playing around and found that I can add that tag to any unit that I want the AI to build more of, and they will build it. I can also change what it prioritizes by modifying the units hitpoints. I removed the DefendGood from phalanx.

So early game, nations will build a mix between horsemen and archers now. Classical era they will build legions primarily. Medieval era they will build knights, then in the later ages they will prioritize cavalry like units.

The only unfortunate part is that the AI is only good at spamming one type of unit, so you'll never see a balanced military with siege, cavalry and foot soldiers. But having it build aggressive military units its more likely to go out and attack instead of maintain a defensive military posture. It also helps when I lower the city walls bonus.
cazfi
Elite
Posts: 3111
Joined: Tue Jan 29, 2013 6:54 pm

Re: How to mod the game to include unit limits?

Post by cazfi »

Sanguivorant wrote: Mon Oct 31, 2022 11:42 am
cazfi wrote: Sun Oct 30, 2022 3:41 am
cazfi wrote: Tue Oct 25, 2022 3:55 amAdd to that https://osdn.net/projects/freeciv/ticket/45595 causing it to want martial law units too much to begin with.
For that one I have a patch in testing.
I would be willing to test it honestly.
If you can build freeciv yourself, the patch is attached to that ticket.

Otherwise, what Operating System are you using?
Post Reply