Latest Posts

Topic: Improvement of lua-code for productionsites

Joined: 2017-02-08, 21:06
Posts: 288
Tribe Member
Location: Eisenach, Germany
Posted at: 2021-07-06, 18:40

I am currently working on the following problem. I have a smithy that can produce around 20 different products.

Originally the code looked like that I skipped the production of a certain ware when it is no longer needed by the economy. However, this means that the smithie will eventually run out of work and will not produce anything when all tools and weapons are full.

            "return=skipped unless economy needs ax_broad",

Now I've switched to a different system. All weapons will continue to be produced, regardless of whether they are needed or not, so that the smithy continues to have a productivity of more than 0%. I only check the consumed input.

            "return=skipped when economy needs planks",
            "return=skipped when economy needs coal",
            "return=skipped when economy needs iron",

This leads to a new problem that weapons are produced very unevenly. The consequences for the trainingsites are that certain weapons are in abundance and others are lacking.

Now, before each work program, I have set a series of skip commands that skip production if another weapon is missing. However, this has now in turn led to a deadlock in the smithy If more than 1 weapon is required, the skip prevents production for weapon 1 because weapon 2 is missing and for weapon 2 production is prevented because weapon 1 is missing..

Example - old code:

            "return=skipped when economy needs helmet_mask",
            "return=skipped when economy needs spear_advanced",
            "return=skipped when economy needs armor_chain",
            "return=skipped when economy needs shield_steel",
            "return=skipped when economy needs armor_gilded",
            "return=skipped when economy needs tabard_golden",
            "return=skipped when economy needs shield_advanced",
            "return=skipped when economy needs sword_broad",

I would therefore suggest implementing a code in the game that basically states that the production of a ware in a productionsite is only started when it is needed by the economy or when all ware that can be produced by the building are not needed by the economy.

new proposal (only analogously, not literally)

            "return=skipped when economy needs another ware buildable by this productionsite and not economy needs this ware
Edited: 2021-07-06, 19:46

My widelands project:

Top Quote
Joined: 2014-12-11, 23:16
Posts: 1958
One Elder of Players
Location: Bavaria
Posted at: 2021-07-06, 21:29

1. from a game mechanics point of view producing things that are not needed is a waste of inputs, if the inputs could be used for something more useful. Therefore the economy settings exist for all wares that use wares that can be used for different purposes.
2. the solution you want to implement is possible already I believe. Did you try to have a line like this:

        "return=skipped unless not economy needs a or not economy needs b or not economy needs ......... or economy needs z "
Edited: 2021-07-06, 21:30

Top Quote