Latest Posts

Topic: Editor Extensions

Gilb
Avatar
Topic Opener
Joined: 2020-12-01, 11:20
Posts: 13
Ranking
Pry about Widelands
Posted at: 2020-12-27, 21:28

So i ran into some problems here. One i could fix myself, the other one unfortunately not.

1) f.resource='coal' produces and error, then i tried with "gold_ore" and others ... but i guess those are the scripting names for the wares when they are out of the ground right? After some thought i realised i dont need to name it, i just need to copy it.
2) wl.Editor().map:place_immovable doesnt work for me whatever i try to put in as arguments.

Here my solution so far for copying a 64x64 map to the east. Everything before the If statement works fine.

players = 2

for x = 0, 63 do
for y = 0, 63 do

copy=wl.Editor().map:get_field(x, y)

for a = 0, players-1 do

paste=wl.Editor().map:get_field(x+64, y)

paste.terr=(copy.terr)
paste.terd=(copy.terd)
paste.height=(copy.height)
paste.resource=(copy.resource)
paste.resource_amount=(copy.resource_amount)

if copy.immovable ~= nil then
wl.Editor().map:place_immovable(copy.immovable, paste)
end

end

end
end


I tried hard to figure that out myself with the documentation here, but i didnt find many examples to help me in this case :( i found the scripting names for the tribe stuff, but none of the map stuff.
Would the the place_immovable line also copy animals and trees and such (i'd like that)? I would really appreciate it if someone could lend me a hand.
Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 18:07
Posts: 1929
OS: Debian Testing
Version: Latest master
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2020-12-27, 22:01

Did you try wl.Editor().map:place_immovable(copy.immovable.descr.name, paste)

Edit: Trees are also immovables. Animals can be accessed via copy.bobs which is an array of all critters on the field

Edited: 2020-12-27, 22:02

Top Quote
Gilb
Avatar
Topic Opener
Joined: 2020-12-01, 11:20
Posts: 13
Ranking
Pry about Widelands
Posted at: 2020-12-28, 12:47

Nice, immovable.descr.name is what i was looking for. That works for the first immobable it encounters. It makes a copy and then produces an error because that "node is no longer free". I dont understand why it is trying to copy the immovable more than once to the same field. IF statements are no loops or am i wrong? I put that into the IF statement btw because otherwise it is trying to index a nil value when it tries to copy an immovable that is not there.

Thanks for the bobs help, but unfortunately i didnt find any function in the wl.map index that allows me to place bobs. It is read only.


Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 18:07
Posts: 1929
OS: Debian Testing
Version: Latest master
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2020-12-28, 14:21

You are pasting over the same field multiple times:

for a = 0, players-1 do
paste=wl.Editor().map:get_field(x+64, y) 

should probably be something like

for a = 1, players do
paste=wl.Editor().map:get_field(x + (64 * a), y) 

Further, if a field already contains an immovable it needs to be removed with

if paste.immovable then paste.immovable:remove() end

as each field can hold at most 1 immovable.


Placing bobs via Lua is unfortunately not supported yet face-sad.png


Edit: Btw, resources are called resource_gold, resource_coal etc

Edited: 2020-12-28, 14:23

Top Quote
Gilb
Avatar
Topic Opener
Joined: 2020-12-01, 11:20
Posts: 13
Ranking
Pry about Widelands
Posted at: 2020-12-28, 14:31

(x + (64 * a)
Haha, seems like you know what i have in mind :D i just kept it simple until now until i can copy a 64x64 map one time to the east.
Alright so i didnt see that i messed up that loop and it already runs more than once. Awesome, much appreciated.

No problem with the bobs and starting positions, those things are added fast by hand.
Editing terrain takes so much time by hand so i really wanted a script like this.
I will upload some "singleplayer" maps with a description on how to extend them for x players.


Top Quote
Gilb
Avatar
Topic Opener
Joined: 2020-12-01, 11:20
Posts: 13
Ranking
Pry about Widelands
Posted at: 2021-01-07, 17:38

Terrain "ashes1" exists in map, not in world! :<
Das passiert wenn ich die dev editor map versuche im letzten release build zu öffnen. Ich habe aber überhaupt kein Ödland in der Map.
Hab dann mal das hier gebastelt:

for x = 0, 127 do
for y = 0, 63 do

copy=wl.Editor().map:get_field(x, y)

if copy.terr == ashes1 then
copy.terr = desert1
end
if copy.terd == ashes1 then
copy.terd = desert1
end

Das Script läuft zumindest ohne Error, macht allerdings auch nichts :/


Top Quote
Nordfriese
Avatar
Joined: 2017-01-17, 18:07
Posts: 1929
OS: Debian Testing
Version: Latest master
Ranking
One Elder of Players
Location: 0x55555d3a34c0
Posted at: 2021-01-07, 18:10

Terrain "ashes1" exists in map, not in world!

Dieser Geländetyp wurde vor einiger Zeit umbenannt. In build21 heißt er "ashes", in der aktuellen Entwicklungsversion "ashes1". Aus Effizienzgründen werden die Name aller Geländetypen in der Datei abgelegt – auch die, die gar nicht verwendet wurden. Modernere Karten sind daher nicht mit build21 kompatibel.

Was du machen könntest, wäre die Datei <meine_karte.wmf>/binary/terrain mit einem Hex-Editor zu öffnen und den Text "ashes1" suchen und manuell gegen "ashes" austauschen. dann müsste es (wahrscheinlich) mit build21 klappen…

Edited: 2021-01-07, 18:11

Top Quote
teppo

Joined: 2012-01-30, 09:42
Posts: 423
Ranking
Tribe Member
Posted at: 2021-01-09, 14:37

I have a version which makes symmetric maps ("an empire strikes back" and "fellowships" are made with it). The code is unpolished (=type symmetry is currently hard coded, a bit of code morphing and recompilation needed to use).

If that would be of larger interest, I could attempt polish it and push to repo. That is done using C++ level, not in lua.


Top Quote
Gilb
Avatar
Topic Opener
Joined: 2020-12-01, 11:20
Posts: 13
Ranking
Pry about Widelands
Posted at: 2021-01-11, 22:20

Yeah man, i would greatly appreciate it if the editor would get a function similar to what i am doing with lua face-smile.png


Top Quote