Currently Online

Latest Posts

Topic: Lua production/consumption variables.

Lokimaros
Avatar
Topic Opener
Joined: 2016-10-21, 17:51
Posts: 49
Ranking
Pry about Widelands
Location: Leiden, the Netherlands
Posted at: 2016-12-31, 17:55

Hi, I'm thinking of wetting my feet in lua with an economic advisor script for myself. For this I would like to know actual production since last check for all products and actual consumption. Separately, I know I can get net gain or loss by checking the warehouse contents, even if that doesn't include products in transit. So, the question is: is there a way to find out how many trees/rocks/wheat/flour/etcetera there have been produced since the previous check and how many were used for building or in buildings? Or is there a hook or something that gets checked whenever anything is produced or consumed?

Edited: 2016-12-31, 18:06

Top Quote
SirVer

Joined: 2009-02-19, 15:18
Posts: 1445
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2017-01-02, 16:39

So, the question is: is there a way to find out how many trees/rocks/wheat/flour/etcetera there have been produced since the previous check and how many were used for building or in buildings?

You can check the total stock of a player using Lua: see here and also get_wares. That is about as much granularity as is currently exposed for Lua.

Or is there a hook or something that gets checked whenever anything is produced or consumed?

unfortunately not. We have a functionality for lua hooks (grep for get_hook in src), but right now it is only used for custom statistics in some win conditions.


Top Quote
Lokimaros
Avatar
Topic Opener
Joined: 2016-10-21, 17:51
Posts: 49
Ranking
Pry about Widelands
Location: Leiden, the Netherlands
Posted at: 2017-01-02, 19:30

Pity, a way to do it would be to create two virtual warehouses and add one in the creation warehouse every time something gets created, and add one in the other every time something gets taken out.

Then I could compare those virtual warehouses in intervals and calculate creation and usage times in practice. Like this, I can only track the difference, which is better than nothing, but not what I was hoping for.


Top Quote
Tibor

Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2017-01-02, 20:15

Theoretically each productionsite can have counter of produced goods, and there would be some method (f.e. LUA interface) to get the number.


Top Quote
Lokimaros
Avatar
Topic Opener
Joined: 2016-10-21, 17:51
Posts: 49
Ranking
Pry about Widelands
Location: Leiden, the Netherlands
Posted at: 2017-01-03, 14:07

And from that usage could be calculated with: total_prod - previous_total + previous_warehouse - current_warehouse.

That would do me fine.


Top Quote
Tibor

Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2017-01-03, 19:56

Hey, I just found we already have the information: current_produced_statistics_, that is vector of counts of produces goods. So we only need and LUA interface that would fetch the count from there...


Top Quote
SirVer

Joined: 2009-02-19, 15:18
Posts: 1445
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2017-01-03, 21:59

Tibor wrote:

Hey, I just found we already have the information: current_produced_statistics_, that is vector of counts of produces goods. So we only need and LUA interface that would fetch the count from there...

Yes, this is the data used in the Ware menus - which contains exactly the data OP wants to access. Tab 1 is number of wares produced, Tab 2 is consumed and Tab 3 is (produced minus consumed), i.e. what OP would like to have in Lua. It is economy wide though, not per building.


Top Quote
Tibor

Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2017-01-03, 22:53

My feeling is that overall production per player would be enough..


Top Quote
Lokimaros
Avatar
Topic Opener
Joined: 2016-10-21, 17:51
Posts: 49
Ranking
Pry about Widelands
Location: Leiden, the Netherlands
Posted at: 2017-01-04, 02:19

Tibor wrote:

My feeling is that overall production per player would be enough..

It would be for my economic advisor script, though I can see use for per building to help find out whether a building is perhaps badly placed. But I don't need my script to tell me that, I just want it to thwack me in the head about the shortcomings in my economy in order of urgency.

And if it finds no fault, it should play a soundfile of a purring kitten.


Top Quote
Tibor

Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2017-01-04, 23:59

SirVer wrote:

Tibor wrote:

Hey, I just found we already have the information: current_produced_statistics_, that is vector of counts of produces goods. So we only need and LUA interface that would fetch the count from there...

Yes, this is the data used in the Ware menus - which contains exactly the data OP wants to access. Tab 1 is number of wares produced, Tab 2 is consumed and Tab 3 is (produced minus consumed), i.e. what OP would like to have in Lua. It is economy wide though, not per building.

I spend 2 hours today just to debug why the hell current_produced_statistics_ contains always 0 or 1 (never grow higher in spite of the production running). Than I found that there is another vector ware_productions_, where content of the first one is pushed regularly.

So now I believe I will be able to finish the LUA method and provide it for review...


Top Quote