Latest Posts

Topic: field.height setting (in editor) misbehaves

Tibor

Topic Opener
Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2014-01-08, 22:55

Hi

I am working on a lua script to create a random landscape and I have this code

f.height=newheight
print (" new value test: "..f.height)

so basically I set new height and immediatelly test if the new value is set as it should be. But it is not. My lua script prints to console this debug text:

iter: 2, pixel :53x51 New height 60 #setting height to 60
new value test: 20 #but field.height return this
iter: 3, pixel :58x55 New height 43
new value test: 18
iter: 4, pixel :44x53 New height 60
new value test: 20
iter: 5, pixel :37x46 New height 60
new value test: 20
iter: 6, pixel :12x40 New height 60
new value test: 20


old value is usually 0. So what is wrong? Why the 'new value' is always much lower then expected?

A side question - when in map editor, is there a simple way how to get an height (elevation) of single field? Like with mouse and so on...

Thanks for help!


Top Quote
wl-zocker

Joined: 2011-12-30, 16:37
Posts: 495
Ranking
Tribe Member
Location: Germany
Posted at: 2014-01-08, 23:18

Not sure if that is the reason, but have a look at https://wl.widelands.org/docs/wl/autogen_wl_map/#field (height vs. raw_height). The map is recalculated after setting the height.

And I think the default value is 10, but I am not sure.


"Only few people know how much one has to know in order to know how little one knows." - Werner Heisenberg

Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2014-01-08, 23:24

Hi,

the first step in my script is iterate over all fields and set height to 0. But I did not check if it is working properly... So this is why I said that old value is usually 0

But to the topic: I understand difference between height and raw_height. "height" should trigger recalculation of all affected fields. Visually (when looking on map) it does this, but the height the central pixel is not set as ordered.


Top Quote
SirVer

Joined: 2009-02-19, 14:18
Posts: 1445
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2014-01-09, 08:22

.height has to adhere to the constraints of the map, i.e. neighbouring fields are not allowed to be too different in height - otherwise the game looks funky and broken. If you want to randomize more than one height you should use .raw_height and then call https://wl.widelands.org/docs/wl/autogen_wl_map/#wl.map.Map.recalculate. If you fail to do this the outcome is undefined. recalculate() will reestablish the invariants that are required by the Widelands map. The height values of fields that are too different might change again for this.

height is a value between 0 and 63 (I think), 10 is the 'sea level'. And you are correct that setting .height to a value that is too different to it's current value might not set it to the value you expect it to - because the renormalization of neighbouring fields has no understanding which one is the 'correct' one and moves all of them a bit.


Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2014-01-09, 21:09

Well, .recalculate() somehow doesnt work properly, but I am not willing now investigate it more now. I came with a workaround - repeat field.height=x in loop until the target height is achieved!


Top Quote
SirVer

Joined: 2009-02-19, 14:18
Posts: 1445
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2014-01-10, 07:00

Well, .recalculate() does work - in the way I described. You are probably setting the heights of neighboring fields too differently. Setting field.height in a loop will also not do the right think: while the field you are currently looking at will get the correct heigh, as soon as you change a field in its neighborhood dramatically, its height will change again.

Oh, I forget in my last post. In the editor there is the Info tool (hotkey i) that will give you the height of individual fields.


Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2014-01-10, 22:03

Well, I can live with what is available now, but in theory something like .forced_height might be useful. But for a handfull of peoples who would ever use it it is not worth the effort face-smile.png

And thanks for "i" option - very very very useful!!!


Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2014-01-11, 22:15

SirVer,

How to get rid of "i" mode? It keeps generating new popup windows with any impulse from me...


Top Quote
SirVer

Joined: 2009-02-19, 14:18
Posts: 1445
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2014-01-12, 06:41

The ghosts you called for .... face-smile.png

No, seriously, I do not understand the question. Does it open new windows even when you move the mouse and not click on anything? It is just a regular tool, so if you select another one (i.e. setting height of fields) it goes away - you have to manually close the windows it created though.

the "i" tool is basically a debugging aid and not very polished


Top Quote
Tibor

Topic Opener
Joined: 2009-03-23, 22:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2014-01-12, 20:43

I noticed that SOMETIMES when I want to get rid of "i" popup window and clicking on it with right mouse, it seems there are many - like 10 or more popup windows that I has to get rid of before there is no window. So it seems there is some event that is triggering new "i" windows. All are stacked on the same place so you can not see how many they are.

But in general I dont use this much so no big issue for me...


Top Quote