Polls

Default Game Speed

Log in to vote!

Latest Posts

Topic: Fixing "Calculation Needed"

JJG
Avatar
Joined: 2017-07-30, 03:48
Posts: 5
Ranking
Just found this site
Posted at: 2019-11-21, 05:15

Continued from Forums » Player Forums » Technical Help » Appveyor broken my post from Nov 2019

hessenfarmer: " ...building yourself is only necessary to test own changes to the code."

Yes, thanks, that was my intent; to understand the code, with these ideas in mind;

I'm trying to understand the source code for some grandiose ideas:
- Is there a way to instrument the code to get a stream of events? like Timestamp:buildingtype:x:y:inventory increased, or inventory consumed, or produced product, or etc.

I'd appreciate any pointers to any wiki, forum, README, etc that discusses how to understand the code.

My simplest idea is to fix "Calculation needed" help texts.

I tracked down "Calculation needed" as output of return no_performance_text_yet() in various productionsite/*/*/helptext.lua

It looks like the actual times are in the init.lua (see below) It looks like the time is a comment 57 + 3.6, based on sleep+animate+sleep times in milliseconds.

Where does the +3.6 come from?

I know enough perl to scrape out all the production times and update the helptexts with the production times. Maybe even to make a general purpose perl script to do the updating for new files as well. The problem that the real info is in the init.lua file, but the helptext can't access it, so it is just copied/hardcoded into the helptext.lua . The helptext CAN access the inputs, outputs, buildingcost, dismantle, enhancement, but not the production time. So this type of auto-update script would be just a band-aid.

eg widelands/data/tribes/buildings/productionsites/barbarians/ax_workshop/init.lua and helptext.lua
function building_helptext_performance()
   -- TRANSLATORS: Performance helptext for a building
   return pgettext("barbarians_building", "If all needed wares are delivered in time, this building can produce each type of ax in about %s on average."):bformat(ngettext("%d second", "%d seconds", **57**):bformat(57)) .. " " .. pgettext("barbarians_building", "All three weapons take the same time for making, but the required raw materials vary.")

 produce_ax_sharp = {    -- TRANSLATORS: Completed/Skipped/Did not start forging a sharp ax because ...
         descname = _"forging a sharp ax",
         actions = {
            -- time total: 57 + 3.6
            "return=skipped unless economy needs ax_sharp",
            "consume=coal iron:2",
            "sleep=26000",
            "playsound=sound/smiths/smith 192",
            "animate=working 22000",
            "playsound=sound/smiths/sharpening 120",
            "sleep=9000",
            "produce=ax_sharp"
         }
      },

Top Quote
WorldSavior
Avatar
Joined: 2016-10-15, 04:10
Posts: 1292
Ranking
One Elder of Players
Location: GER
Posted at: 2019-11-21, 07:49

JJG wrote:

Where does the +3.6 come from?

It seems like a worker needs 3.6 seconds to go to the flag, drop the ware there and go back into the building (on flat terrain). I'm not sure if it's the exact value, it might be also something like 3.75 seconds. And if the terrain is not flat, the duration might be even longer, but just slightly.


“It's a threat to our planet to believe that someone else will save it.” - Robert Swan

Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 807
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2019-11-21, 08:54

WorldSavior wrote:

JJG wrote:

Where does the +3.6 come from?

It seems like a worker needs 3.6 seconds to go to the flag, drop the ware there and go back into the building (on flat terrain). I'm not sure if it's the exact value, it might be also something like 3.75 seconds. And if the terrain is not flat, the duration might be even longer, but just slightly.

I believe the terrain is always flat as I think to remember that this flattness is prerequisite for showing the build Icon on the map.


Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 18:07
Posts: 504
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2019-11-21, 10:41

The worker´s speed is exactly 1800 ms per field. Faster/slower on slopes. I believe the terrain before a building doesn´t have to be completely flat but a small slope (~2 units) is tolerated.


Top Quote
WorldSavior
Avatar
Joined: 2016-10-15, 04:10
Posts: 1292
Ranking
One Elder of Players
Location: GER
Posted at: 2019-11-21, 17:19

Nordfriese wrote:

The worker´s speed is exactly 1800 ms per field.

Okay. Fun fact: It seems like any object in Widelands moves exactly that fast (on even terrain). But I think that this is no problem.

I believe the terrain before a building doesn´t have to be completely flat but a small slope (~2 units) is tolerated.

That's highly possible. For mines, an even higher slope might be tolerated.


“It's a threat to our planet to believe that someone else will save it.” - Robert Swan

Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 18:07
Posts: 504
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2019-11-21, 17:33

Okay. Fun fact: It seems like any object in Widelands moves exactly that fast (on even terrain).

Correct

I believe the terrain before a building doesn´t have to be completely flat but a small slope (~2 units) is tolerated.

That's highly possible. For mines, an even higher slope might be tolerated.

Mines have the same slope restrictions as small buildings. Small buildings allow steeper slopes around them than medium and big buildings.

JJG wrote:

I'm trying to understand the source code for some grandiose ideas:
- Is there a way to instrument the code to get a stream of events? like Timestamp:buildingtype:x:y:inventory increased, or inventory consumed, or produced product, or etc.

You could add a lot of log("%lu:%s%d:%d:…", game.gametime(), name().c_str(), get_position().x, …) in all relevant places (in productionsite_program.cc)

I'd appreciate any pointers to any wiki, forum, README, etc that discusses how to understand the code.

I´m afraid there isn´t really one (or if there is, it´s likely outdated) face-sad.png

The problem that the real info is in the init.lua file, but the helptext can't access it, so it is just copied/hardcoded into the helptext.lua . The helptext CAN access the inputs, outputs, buildingcost, dismantle, enhancement, but not the production time.

Unfortunately one can write really complex productionsite programs, with additional sleep times depending on whether certain additional wares are present/missing, and (silly but allowed) skip commands depending on economy demand or worker experience…
In general, I think a program can´t really be broken down to one value.

Edited: 2019-11-21, 17:36

Top Quote
JJG
Avatar
Joined: 2017-07-30, 03:48
Posts: 5
Ranking
Just found this site
Posted at: 2019-11-22, 07:42

Thanks for all the comments.
Regarding moving 1800ms per field, what is 'field'; one path segment?
So 3.6s comes from 1.8s walking in + 1.8s walking out.

In Settlers, I believe, you could build warehouses with an entrance slope of yellow instead of green, or the entrance speed was same as last road speed, so a yellow incoming road would have slower entrance as well. I don't seem to be able to test this for Widelands warehouse because entrance is always green, and only connecting roads are green and yellow, (no red). Maybe mines would work better. Has anyone seen this slowdown of entrance walk?

From the top post, I'm guessing that sleep and animate take arguments in mS.
Does Playsound also take time? ~200 mS seems like a short time for sound.

            "sleep=26000",
            "playsound=sound/smiths/smith 192",
            "animate=working 22000",

I found that the barbarian bakery init.lua uses 3 wheat + 3 water, and makes the first loaf in 40s and second loaf in 20s, for an average of 30s/loaf.
How does skip work? Does it take the same amount of time as production?

Thanks for pointer to syntax and location for logging.
I can't find productionsite_program.cc
But in src/logic/map_objects/tribes/ there is a production_program.cc and a productionsite.cc
It looks like there is skip data comparisons for "needs" and "has" I can look at in more detail.


Top Quote
stonerl
Avatar
Joined: 2018-07-30, 00:03
Posts: 240
Ranking
Widelands-Forum-Junkie
Location: Earth
Posted at: 2019-11-22, 08:34

Regarding moving 1800ms per field, what is 'field'; one path segment?

Have a look in the Documentation. Simply speaking, it is the distance between two nodes (flags, if you will).

Edited: 2019-11-22, 08:37

Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 807
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2019-11-22, 10:54

stonerl wrote:

Regarding moving 1800ms per field, what is 'field'; one path segment?

Have a look in the Documentation. Simply speaking, it is the distance between two nodes (flags, if you will).

Not quite exactly one field is the distance between 2 nodes. Flags however are separated at least 2 nodes.


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 807
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2019-11-22, 11:04

JJG wrote:

Thanks for all the comments.
Regarding moving 1800ms per field, what is 'field'; one path segment?
So 3.6s comes from 1.8s walking in + 1.8s walking out.

yes but in different order. as the the buildings can't store any produced wares they need to be carried out to the building flag, which is only one node away, to be stored on the flag until it gets transported. I believe if theres is a slope from building to flag the effects of slowing down uphill and accelerate downhil should average so it should be 3.6s all the time.

In Settlers, I believe, you could build warehouses with an entrance slope of yellow instead of green, or the entrance speed was same as last road speed, so a yellow incoming road would have slower entrance as well. I don't seem to be able to test this for Widelands warehouse because entrance is always green, and only connecting roads are green and yellow, (no red). Maybe mines would work better. Has anyone seen this slowdown of entrance walk?

From the top post, I'm guessing that sleep and animate take arguments in mS.
Does Playsound also take time? ~200 mS seems like a short time for sound. ~~~~ "sleep=26000", "playsound=sound/smiths/smith 192", "animate=working 22000", ~~~~

sound plays in parallel to the other commands as long as the sound file takes (duration of sound recorded). 192 is only a priority of the sound in relation to other sounds to be played in the same field of view on the map.

I found that the barbarian bakery init.lua uses 3 wheat + 3 water, and makes the first loaf in 40s and second loaf in 20s, for an average of 30s/loaf.
How does skip work? Does it take the same amount of time as production?

no skipping takes 10 seconds I believe but you need to look into the c++ code to confirm this.

Thanks for pointer to syntax and location for logging.
I can't find productionsite_program.cc
But in src/logic/map_objects/tribes/ there is a production_program.cc and a productionsite.cc

thats where the stuff is done.

It looks like there is skip data comparisons for "needs" and "has" I can look at in more detail.

yes skipping is always done conditional either for economy reason (the ware is not needed) or production reason the inputs to produce the ware are not available. This reasons are normally defined in the lua code. Personally I believe we could and should only calculate performance in the good case (all inputs available and wares are needed). As this is where performance matters.


Top Quote