widelands / widelands

Widelands is a free, open source real-time strategy game with singleplayer campaigns and a multiplayer mode. The game was inspired by Settlers II™ (© Bluebyte) but has significantly more variety and depth to it.
https://www.widelands.org/
GNU General Public License v2.0
2.01k stars 158 forks source link

Delete all related ware/worker requests when a building gets deleted #3962

Open gunchleoc opened 4 years ago

gunchleoc commented 4 years ago

Tools/workers are sometimes produced for a building that's no longer there.

Discussion: https://www.widelands.org/forum/topic/4880/

To reproduce: https://www.widelands.org/forum/topic/4880/?page=2#post-33731

WIP Branch: https://github.com/gunchleoc/widelands/tree/check-immovable-for-worker-requests

The target for the tool production in the Metal Workshop/Toolsmithy is the warehouse, so the check needs to be done at the warehouse level and the request delete triggered from there.

frankystone commented 3 years ago

Is it possible to show the requests, or the tool a toolsmithy will create the next time in the toolsmithies window?

If this is possible, would it be also possible to dismiss the request, or the next creation of a tool?

This way a player get knowledge of the production programs and has more control of those programs.

Noordfrees commented 3 years ago

Sadly no because there is no game-logical connection between the tool request and the toolsmithy. What the smithy does is to check whether its economy needs ware X, and if so start the production of tool X.

Why the economy needs or doesn't need a ware is known only to the economy itself and depends on the target settings, or (only if a ware's target setting is 0) any open requests.

These in turn are attached to the warehouse that opened a tool request and are not connected in any way to the building that originally requested the worker for whom the tool is intended. A lot of non-trivial backlinking will need to be implemented to address this issue…

frankystone commented 3 years ago

What the smithy does is to check whether its economy needs ware X, and if so start the production of tool X.

Ah, this done on demand. I thought a smithy might have a list of tools to produce. Say an economy requests 2 hammers and 3 scythes so the list might be {hammer, scythe, hammer, scythe, scythe} and represents the order of creation.

But if a smithy produce tools on demand, the order which tool to produce next is only made by the order of production programs? So production program produce hammer looks if this is needed by the economy and produces it or not and switch to the next program?

Why the economy needs or doesn't need a ware is known only to the economy itself and depends on the target settings, or (only if a ware's target setting is 0) any open requests.

This why is not relevant for a player, imho. The player doesn't need to know why an economy needs a ware, he may knows it anyway. Regarding to the initial problem and possibly to this one a player needs to have control which tool will be created next.

Or do i still not understand this requests?

Noordfrees commented 3 years ago

Correct. The order of tools is controlled by the smithy's init.lua:

      main = {
         -- TRANSLATORS: Completed/Skipped/Did not start working because ...
         descname = _"working",
         actions = {
            "call=produce_fire_tongs",
            "call=produce_hunting_bow",
            "call=produce_pick",
            "call=produce_hammer",
            "call=produce_saw",
            "call=produce_shovel",
            "call=produce_scythe",
            "call=produce_bread_paddle",
            "call=produce_hook_pole",
            "call=produce_buckets",
            "call=produce_milking_tongs",
            "call=produce_fishing_net",
         }
      },
      produce_bread_paddle = {
         -- TRANSLATORS: Completed/Skipped/Did not start making a bread paddle because ...
         descname = _"making a bread paddle",
         actions = {
            "return=skipped unless economy needs bread_paddle",
            "consume=iron log",
            "sleep=duration:32s",
            "playsound=sound/smiths/toolsmith priority:50% allow_multiple",
            "animate=working duration:35s",
            "produce=bread_paddle"
         }
      },
      ...

It checks if the first tool (fire tongs) in the list is needed and the raw materials are available. If so, produce the tool. Then move on to the next tool (hunting bow), again produce if needed and possible, then the next (pick) and so on. Skipping wares that are not needed is very fast.

If you want/need fine-grained control, the best solution is always to build only 1 building at a time and don't start construction of the next one before the last one has been occupied.

What I meant by "why" is: Why does the economy need a hammer? Because warehouse X requires one. Why does X need a hammer? Because the economy needs a builder. Why does it want one? Because constructionsite Y needs one. This may be not important to the player but these connections need to be represented in the game logic before this bug can reasonably be fixed. When such things are handled automatically there will also be no need to add any further controls to allow the player to interfere, IMHO.

frankystone commented 3 years ago

Just get again in a situation while playing discovery starting condition where i was wondering which tool the toolsmithy will made.

I built one building after the other until i noticed the sawmill misses a worker. So i built a toolsmithy but the toolsmith didn't produce a saw... it took me some time to find out why: He produces a fishing_rod because in my economy settings i have set it to one and producing a fishing_rod comes before producing a saw in the toolsmithies production program list.

Now i am asking myself if players do know all this... and since the economy profile "standard" is enabled by default the toolsmith will try to create all the wares from this economy profile.

I want to suggest to have a new economy profile called "None" or so, which sets all wares and workers to 0. This economy profile should then be enabled for starting conditions where one starts with minimum wares. This would help new players and experienced players can make an own economy profile or adjust the "None"-profile to his needs.

frankystone commented 3 years ago

Get this problem again with starting condition discovery:

Build a port from one of the three ships. After finishing the port i started to build a woodcutters house. Unfortunately at this moment there were no lumberjack in the port. Then i have cancelled the expedition of the remaining ships and a lumberjack arrives at the port and the woodcutters house got a lumberjack. After building a toolsmith the toolsmithy produces a felling ax at first ]:-(

It is just no fun... there are too many snares a player can get into. Just because a player doesn't know the secrets how ware requests are handled by the game.

knarrff commented 9 months ago

I built one building after the other until i noticed the sawmill misses a worker. So i built a toolsmithy but the toolsmith didn't produce a saw... it took me some time to find out why: He produces a fishing_rod because in my economy settings i have set it to one and producing a fishing_rod comes before producing a saw in the toolsmithies production program list.

As a player, I would have expected that tools that are needed for currently missing workers would have priority over tools that are needed only to fulfill some economy plan. I had to learn the hard way, that setting the plan to 0 is the only way to get some control over what is produced. I am fine with the player not having direct control over what is built next (as in: a button or something like that in the toolsmith), but there are things that obviously have a higher priority and should get that by the game, and things that are out of date, like described in this bug, which the game should just handle as such.