Latest Posts

Topic: Is it possible to place buildings?

Jenia
Avatar
Topic Opener
Joined: 2013-07-20, 20:25
Posts: 8
Ranking
Pry about Widelands
Posted at: 2013-07-30, 00:17

Say I want all players to start with a building other than their headquarters, for example one basic military building in a specific location. I have not found a way in the editor to do that - is it impossible?


Top Quote
wl-zocker

Joined: 2011-12-30, 17:37
Posts: 492
Ranking
Tribe Member
Location: Germany
Posted at: 2013-07-30, 10:23

It cannot be done in the editor, but via scripting. If you want to try this, have a look at the campaign maps (directory where you installed Widelands/campaigns/<choose any>/scripting). In the file init.lua or starting_conditions.lua (can be opened by any text editor), there are examples how that can be done. But I do not know how you can handle the different starting conditions (Guess: Use init.lua and play the map as scenario - see the map "Plateau"). I have not tried it out, but with some trial-and-error method that could work. I think if you make an interesting map it is better to have different starting conditions and not only the normal ones.


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

Top Quote
SirVer

Joined: 2009-02-19, 15:18
Posts: 1440
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2013-08-01, 04:51

There are plans to add some support for placing player infrastructure in the editor - it is not easy to add though and I did not make much progress when I started working on it. So do not hold your breath for it to happen. wl-zocker is correct, the only way is the one he is proposing. It is not as hard as it sounds though, just have a look at the docs https://wl.widelands.org/docs/wl/lua_index/ (especially the tutorial: https://wl.widelands.org/docs/wl/tutorial/) and try it out. We are here to help you out with any problem you might encounter.


Top Quote
Jenia
Avatar
Topic Opener
Joined: 2013-07-20, 20:25
Posts: 8
Ranking
Pry about Widelands
Posted at: 2013-08-01, 11:39

Thanks a lot for the link, SirVer!

I tried looking for a tutorial myself, but the link on this page was broken ("you went astray somewhere" page), so I thought the tutorial simply hasn't been put on the site for whatever reason. Since it's editable, I just fixed it myself...

And as a student of program engineering, I'd think something has gone horribly wrong if I found scripting a building's placement to be hard :(


Top Quote
SirVer

Joined: 2009-02-19, 15:18
Posts: 1440
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2013-08-01, 15:11

I tried looking for a tutorial myself, but the link on [url="https://wl.widelands.org/wiki/Creating%20Game%20Content/"] this page [/url] was broken ("you went astray somewhere" page), so I thought the tutorial simply hasn't been put on the site for whatever reason. Since it's editable, I just fixed it myself...

Thanks for fixing!

And as a student of program engineering, I'd think something has gone horribly wrong if I found scripting a building's placement to be hard face-sad.png

Aah, well, you know. The one's easy is the other's hard and usually directly vice versa. As an open source project we often decided to use the more flexible approach which would often mean the less user friendly one. I am interested what you think about the ease of use of the scenario development. If you find something needs rewording, the tutorial is also editable, but only directly in the source: http://bazaar.launchpad.net/~widelands-dev/widelands/trunk/files/head:/doc/sphinx/source/.


Top Quote
Jenia
Avatar
Topic Opener
Joined: 2013-07-20, 20:25
Posts: 8
Ranking
Pry about Widelands
Posted at: 2013-08-09, 01:21

While I will admit to not exploring the tutorial very thoroughly (due to lack of free time), I seem to be failing to script up buildings.
I tried copying the following code from the atlantean campaign:

   -- Place some buildings
   prefilled_buildings(p1,
      {"high_tower", first_tower_field.x, first_tower_field.y,
         soldiers = { [{0,0,0,0}] = 1 }
      },
      {"high_tower", second_tower_field.x, second_tower_field.y,
         soldiers = { [{0,0,0,0}] = 1 }
      }


I replaced the x/y entries with x/y coordinates and the "high tower" with "shipyard", as well as adding p2,p3,p4 entries (instead of just p1) but widelands throws an error at me when trying to load the map as scenario. Normally I'd just leave it for when I have time to browse the tutorial and code at my leisure, but map contest deadline is coming up. Hints, please?
Top Quote
SirVer

Joined: 2009-02-19, 15:18
Posts: 1440
Ranking
One Elder of Players
Location: Germany - Munich
Posted at: 2013-08-09, 05:12

You are missing the use directive to include the auxilary script - most likely.

See https://wl.widelands.org/docs/wl/reference/, especially https://wl.widelands.org/docs/wl/autogen_aux_infrastructure/#prefilled_buildings. You need something like

use("aux", "infrastructure")

for this.


Top Quote
Nasenbaer
Avatar
Joined: 2009-02-21, 18:17
Posts: 826
Ranking
One Elder of Players
Location: Germany
Posted at: 2013-08-09, 12:21

Just to ensure, as you did not mention the part with "soldiers = { [{0,0,0,0}] = 1 }" - you hopefully removed or altered that part.

If your problems persist, you might want to upload the script somewhere (e.g. pastebin.com), we will try to find the bugger than as soon as possible face-smile.png


Top Quote
Jenia
Avatar
Topic Opener
Joined: 2013-07-20, 20:25
Posts: 8
Ranking
Pry about Widelands
Posted at: 2013-08-09, 18:22

Thanks for the quick help! I managed to get it to work, but I do not think I can get the scenario portion working as I want it to by the deadline, so as far the contest is concerned, I'll drop it for now. I'll know how to do what I want next time, though...


Top Quote
stdh
Avatar
Joined: 2013-08-04, 22:05
Posts: 41
Ranking
Pry about Widelands
Posted at: 2013-08-09, 19:05

Hi Jenia, I have recently learned Lua and Widelands scripting, and I also have some free time before the deadline. If you want I can help you with what you'd like to code, or just do it for you. If you have good ideas and it's not too big, it would be a shame not to have a nice scenario in the contest. Same offer for other people who need a bit of help...


Top Quote