Merge lp:~widelands-dev/widelands/document_world into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 8447
Proposed branch: lp:~widelands-dev/widelands/document_world
Merge into: lp:widelands
Diff against target: 1172 lines (+670/-241)
12 files modified
data/world/critters/badger/init.lua (+49/-0)
data/world/immovables/bush1/init.lua (+141/-0)
data/world/init.lua (+195/-111)
data/world/resources/init.lua (+67/-8)
data/world/terrains/init.lua (+145/-58)
doc/sphinx/extract_rst.py (+10/-1)
doc/sphinx/source/lua_world.rst (+5/-1)
doc/sphinx/source/lua_world_defining.rst.org (+14/-0)
doc/sphinx/source/lua_world_other.rst.org (+9/-0)
doc/sphinx/source/lua_world_units.rst.org (+17/-0)
doc/sphinx/source/map_objects.rst (+1/-1)
src/scripting/lua_root.cc (+17/-61)
To merge this branch: bzr merge lp:~widelands-dev/widelands/document_world
Reviewer Review Type Date Requested Status
Widelands Developers Pending
Review via email: mp+329950@code.launchpad.net

Commit message

Started adding documentation for world entities.

Description of the change

More documentation. Immovable and critter programs as well as map generation are still missing here and will have to be done in a follow-up branch.

To post a comment you must log in.
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2624. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/270101584.
Appveyor build 2446. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_document_world-2446.

Revision history for this message
kaputtnik (franku) wrote :

Some proofreading. The part in new_editor_<element_type>_category{table} is quite complicated for me.

Did not read all.

Revision history for this message
kaputtnik (franku) wrote :

Proof reading done and added some more diff comments.

Especially in terrains the 'is' value and the 'valid_resource' value depend on each other. Don't know how to explain that though. https://bugs.launchpad.net/widelands/+bug/1505345/comments/1

Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks for your comments. For the is value, I have linked to the bug now - I think explaining that in detail is out of scope for the documentation, since it's a bug.

I have fiddled a bit with the editor category documentation, but I am not thrilled by the results either. I'd like to revisit that later in https://code.launchpad.net/~widelands-dev/widelands/dynamic_world_loading, since I'll be changing the API there. I think the new API will also be easier to explain. The "element" thing is a bit tricky ere - I can't just say "Map Object", because terrains are not map objects.

Revision history for this message
kaputtnik (franku) wrote :

Thanks :-)

For the Animals it should be clarified, that 'fish' is a resource, and does not belong to the critters, imho.

Regarding the editor category documentation:
From my understanding there are only three types available (at the moment) and adding a new element_type is not possible. So why not document similar to the workers? E.g.:

"This file also defines the editor categories for world elements like terrains or immovables so that they will be added to their respective editor tools (Place terrain, Place immovable etc.). The available categories are:

- new_editor_terrain_category{table}
- new_editor_immovable_category{table}
- new_editor_critter_category{table}

All categories have the same properties in the argument table:

(listing the table entries)
"

So we get rid of the abstract term "new_editor_<element_type>_category{table}".

Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks, that looks much better now :)

I also ripped out the duplicate documentation in lua_root and linked to the new documentation there.

Revision history for this message
kaputtnik (franku) wrote :

Could not resist to make a suggestion. Feel free to revert it.

Revision history for this message
GunChleoc (gunchleoc) wrote :

LGTM, thanks :)

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/world/critters/badger/init.lua'
2--- data/world/critters/badger/init.lua 2017-02-12 09:10:57 +0000
3+++ data/world/critters/badger/init.lua 2017-09-03 10:57:20 +0000
4@@ -1,3 +1,14 @@
5+-- RST
6+-- .. _lua_world_critters:
7+--
8+-- Critters (Animals)
9+-- ------------------
10+--
11+-- Critters are entities owned by the world that will move around the map at random, usually animals. On how to add fish to the map, see :ref:`lua_world_resources`.
12+--
13+-- Critters are defined in
14+-- ``data/world/critters/<critter_name>/init.lua``.
15+
16 dirname = path.dirname(__file__)
17
18 animations = {
19@@ -10,6 +21,44 @@
20
21 add_walking_animations(animations, "walk", dirname, "walk", {13, 15}, 20)
22
23+-- RST
24+-- .. function:: new_critter_type{table}
25+--
26+-- This function adds the definition of a critter to the engine.
27+--
28+-- :arg table: This table contains all the data that the game engine will add to this critter. It contains the following entries:
29+--
30+-- **name**
31+-- *Mandatory*. A string containing the internal name of this critter, e.g.::
32+--
33+-- name = "badger",
34+--
35+-- **descname**
36+-- *Mandatory*. The translatable display name, e.g.::
37+--
38+-- descname = _"Badger",
39+--
40+-- **editor_category**
41+-- *Mandatory*. The category that is used in the editor tools for placing a critter of this type on the map, e.g.::
42+--
43+-- editor_category = "critters_carnivores",
44+--
45+-- **attributes**
46+-- *Mandatory*. Attributes can be used by other programs to identify a class of critters, e.g.::
47+--
48+-- attributes = { "eatable" }, -- This animal can be hunted
49+--
50+-- **programs**
51+-- *Mandatory*. Every critter has an automatic default program, which is to move around the map at random. Additional programs can be defined that other map objects can then call in their programs, e.g.::
52+--
53+-- programs = {
54+-- remove = { "remove" }, -- A hunter will call this after catching this animal
55+-- },
56+--
57+-- **animations**
58+-- *Mandatory*. A table containing all animations for this critter. Every critter
59+-- needs to have an ``idle`` and a directional ``walk`` animation.
60+-- See :doc:`animations` for a detailed description of the animation format.
61 world:new_critter_type{
62 name = "badger",
63 descname = _ "Badger",
64
65=== modified file 'data/world/immovables/bush1/init.lua'
66--- data/world/immovables/bush1/init.lua 2015-11-03 18:18:27 +0000
67+++ data/world/immovables/bush1/init.lua 2017-09-03 10:57:20 +0000
68@@ -1,5 +1,103 @@
69+-- RST
70+-- .. _lua_world_immovables:
71+--
72+-- Immovables
73+-- ----------
74+--
75+-- Immovables are entities owned by the world that are placed in a fixed position
76+-- on the map. They include trees, rocks, artifacts, and eye candy.
77+--
78+-- Immovables are defined in
79+-- ``data/world/immovables/<immovable_name>/init.lua``.
80+-- Some immovables are grouped into subdirectories, e.g. trees and rocks.
81+-- There are also some specialized immovables:
82+--
83+-- * `Artifacts`_
84+-- * `Rocks`_
85+-- * `Trees`_
86+
87 dirname = path.dirname(__file__)
88
89+-- RST
90+-- .. function:: new_immovable_type{table}
91+--
92+-- This function adds the definition of an immovable to the engine.
93+--
94+-- :arg table: This table contains all the data that the game engine will add
95+-- to this immovable. It contains the following entries:
96+--
97+-- **name**
98+-- *Mandatory*. A string containing the internal name of this immovable, e.g.::
99+--
100+-- name = "alder_summer_old",
101+--
102+-- **descname**
103+-- *Mandatory*. The translatable display name, e.g.::
104+--
105+-- descname = _"Alder (Old)",
106+--
107+-- **species**
108+-- *Mandatory for trees*. `Trees`_ have 4 variants (sapling, pole, mature, and old),
109+-- so we will want a simplified translatable display name for the editor help, e.g.::
110+--
111+-- species = _"Alder",
112+--
113+-- **editor_category**
114+-- *Mandatory*. The category that is used in the editor tools for placing an
115+-- immovable of this type on the map, e.g.::
116+--
117+-- editor_category = "trees_deciduous",
118+--
119+-- **size**
120+-- *Optional*. The size of the immovable. Defaults to ``none`` -
121+-- note that immovables with size ``none`` will be removed when
122+-- their space is needed for a road. Possible values
123+-- are ``none``, ``small``, ``medium``, and ``big``, e.g.::
124+--
125+-- size = "small",
126+--
127+-- **attributes**
128+-- *Optional*. Attributes can be used by other programs to identify a class
129+-- of immovables, e.g.::
130+--
131+-- attributes = { "tree" }, -- This is a tree, so it can be felled
132+--
133+-- **programs**
134+-- *Mandatory*. Every immovable has an automatic default program,
135+-- which will simply play the ``idle`` animation. Leave the table empty if
136+-- this is all you need. You can also overwrite this default ``program``,
137+-- like this::
138+--
139+-- program = {
140+-- "animate=idle 50000",
141+-- "remove=18",
142+-- "grow=alder_summer_old",
143+-- },
144+--
145+-- **terrain_affinity**
146+-- *Mandatory for trees*. If your immovable is a tree (c.f. `Trees`_), you will need to specify its
147+-- terrain affinity, which will determine its chances to survive on different
148+-- terrains. Terrain affinity is a table and looks like this::
149+--
150+-- terrain_affinity = {
151+-- -- Temperature is in arbitrary units.
152+-- preferred_temperature = 125,
153+--
154+-- -- In percent (1 being very wet).
155+-- preferred_humidity = 0.65,
156+--
157+-- -- In percent (1 being very fertile).
158+-- preferred_fertility = 0.6,
159+--
160+-- -- A value in [0, 1] that defines how well this immovable can deal with non-ideal terrain.
161+-- -- A lower value means that it is less picky, i.e. it can deal better with it.
162+-- pickiness = 0.6,
163+-- }
164+--
165+-- **animations**
166+-- *Mandatory*. A table containing all animations for this immovable.
167+-- Every immovable needs to have at least an ``idle`` animation.
168+-- See :doc:`animations` for a detailed description of the animation format.
169 world:new_immovable_type{
170 name = "bush1",
171 descname = _ "Bush",
172@@ -14,3 +112,46 @@
173 },
174 }
175 }
176+
177+-- RST
178+--
179+-- Artifacts
180+-- ^^^^^^^^^
181+-- Artifacts are immovables that players can hunt for when using the "Artifacts" win condition.
182+-- They need to define the ``artifact`` attribute in order for the win condition to find them,
183+-- and should be placed in the editor_category "artifacts".
184+--
185+-- Rocks
186+-- ^^^^^
187+-- Rocks are a special type of immovable that can be quarried by a stonecutter.
188+-- They need to define the ``rocks`` attribute in order for the stonecutter to find them,
189+-- and should be placed in the editor_category "rocks".
190+-- Rocks will shrink over time and disappear eventually while being quarried.
191+-- This shrinking is implemented via their ``shrink`` program, which will be triggered
192+-- by the stonecutter. Rocks usually come in series of 6 immovables:
193+--
194+-- * **<rock_name>6 - <rock_name>2**: These rocks will transform into the next smaller rock by calling ``transform``
195+-- in their ``shrink`` program.
196+--
197+-- * **<rock_name>1**: This is the smallest rock, so it needs to call ``remove`` in its ``shrink``
198+-- program in order to disappear from the map.
199+--
200+-- Trees
201+-- ^^^^^
202+--
203+-- Trees are a special type of immovable, and should be placed in the editor_category
204+-- "trees_coniferous", "trees_deciduous", "trees_palm", or "trees_wasteland".
205+-- Because they will grow with time, this growth is represented by transforming one
206+-- tree into the next through the ``grow`` command in their program.
207+-- They also all need to define a species name and their terrain affinity (see above).
208+-- Trees will grow in 4 stages:
209+--
210+-- * **Sapling**: A sapling will be seeded by another tree or planted by a forester.
211+-- All saplings have the attribute ``"tree_sapling"``.
212+-- * **Pole**: A young, slender tree that is not able to seed other trees yet.
213+-- A pole has no special attributes.
214+-- * **Mature**: A visually grown tree but without any special attributes, just like the pole.
215+-- * **Old**: Old trees can be felled, which is defined by the attribute ``tree``.
216+-- They will also die off and seed a new tree via the ``transform`` and ``seed``
217+-- commands in their program. They also need to specify a ``fall`` program,
218+-- which will be triggered when a lumberjack fells them.
219
220=== modified file 'data/world/init.lua'
221--- data/world/init.lua 2017-02-12 09:10:57 +0000
222+++ data/world/init.lua 2017-09-03 10:57:20 +0000
223@@ -1,3 +1,15 @@
224+-- RST
225+-- init.lua
226+-- --------
227+--
228+-- World initialization.
229+-- All world entities are loaded via this file.
230+--
231+-- This file also defines the editor categories for world elements like terrains or
232+-- immovables so that they will be added to their respective editor tools (Place Terrain,
233+-- Place Immovable etc.). There are three categories available,
234+-- each with their own function:
235+
236 world = wl.World()
237
238 set_textdomain("world")
239@@ -11,126 +23,61 @@
240 end)
241
242 print_loading_message("┃ Terrains", function()
243+
244+-- RST
245+-- .. function:: new_editor_terrain_category{table}
246+--
247+-- This function adds the definition for a category in the "Terrains" tool.
248+-- Only terrains can be in this editor category. The parameter `table` is described below.
249+
250+ world:new_editor_terrain_category{
251+ name = "summer",
252+ descname = _ "Summer",
253+ picture = "world/pics/editor_terrain_category_green.png",
254+ items_per_row = 6,
255+ }
256+ world:new_editor_terrain_category{
257+ name = "wasteland",
258+ descname = _ "Wasteland",
259+ picture = "world/pics/editor_terrain_category_wasteland.png",
260+ items_per_row = 6,
261+ }
262+ world:new_editor_terrain_category{
263+ name = "winter",
264+ descname = _ "Winter",
265+ picture = "world/pics/editor_terrain_category_winter.png",
266+ items_per_row = 6,
267+ }
268+ world:new_editor_terrain_category{
269+ name = "desert",
270+ descname = _ "Desert",
271+ picture = "world/pics/editor_terrain_category_desert.png",
272+ items_per_row = 6,
273+ }
274+
275 include "world/terrains/init.lua"
276 end)
277
278- world:new_editor_immovable_category{
279- name = "miscellaneous",
280- descname = _ "Miscellaneous",
281- picture = "world/immovables/ruin5/idle.png",
282- items_per_row = 6,
283- }
284-
285- world:new_editor_immovable_category{
286- name = "artifacts",
287- descname = _ "Artifacts" .. "<br>" .. _ "These immovables are used by the win condition “Artifacts”.",
288- picture = "world/immovables/manmade/artifacts/artifact00/idle.png",
289- items_per_row = 6,
290- }
291-
292- world:new_editor_immovable_category{
293- name = "plants",
294- descname = _ "Plants",
295- picture = "world/immovables/cactus3/idle.png",
296- items_per_row = 8,
297- }
298-
299- world:new_editor_immovable_category{
300- name = "standing_stones",
301- descname = _ "Standing Stones",
302- picture = "world/immovables/standing_stones/standing_stone4_desert/idle.png",
303- items_per_row = 4,
304- }
305-
306- world:new_editor_immovable_category{
307- name = "rocks",
308- descname = _ "Rocks",
309- picture = "world/immovables/rocks/greenland_rocks6/idle.png",
310- items_per_row = 6,
311- }
312-
313- world:new_editor_immovable_category{
314- name = "trees_dead",
315- descname = _ "Dead Trees",
316- picture = "world/immovables/trees/deadtree2/idle.png",
317- items_per_row = 8,
318- }
319-
320- world:new_editor_immovable_category{
321- name = "trees_coniferous",
322- descname = _ "Coniferous Trees",
323- picture = "world/immovables/trees/spruce/old/idle_0.png",
324- items_per_row = 8,
325- }
326-
327- world:new_editor_immovable_category{
328- name = "trees_deciduous",
329- descname = _ "Deciduous Trees",
330- picture = "world/immovables/trees/alder/old/idle_0.png",
331- items_per_row = 8,
332- }
333-
334- world:new_editor_immovable_category{
335- name = "trees_palm",
336- descname = _ "Palm Trees",
337- picture = "world/immovables/trees/palm_borassus/old/idle_0.png",
338- items_per_row = 8,
339- }
340-
341- world:new_editor_immovable_category{
342- name = "trees_wasteland",
343- descname = _ "Wasteland Trees",
344- picture = "world/immovables/trees/umbrella_red/old/idle_0.png",
345- items_per_row = 8,
346- }
347-
348- world:new_editor_critter_category {
349- name = "critters_herbivores",
350- -- TRANSLATORS: A category in the editor for placing animals on the map.
351- descname = _ "Herbivores",
352- picture = "world/critters/sheep/idle_00.png",
353- items_per_row = 10,
354- }
355-
356- world:new_editor_critter_category {
357- name = "critters_carnivores",
358- -- TRANSLATORS: A category in the editor for placing animals on the map.
359- descname = _ "Carnivores",
360- picture = "world/critters/fox/idle_00.png",
361- items_per_row = 10,
362- }
363-
364- world:new_editor_critter_category {
365- name = "critters_aquatic",
366- -- TRANSLATORS: A category in the editor for placing animals on the map.
367- descname = _ "Aquatic",
368- picture = "world/critters/duck/idle_00.png",
369- items_per_row = 10,
370- }
371-
372 print_loading_message("┃ Immovables", function()
373- include "world/immovables/grass1/init.lua"
374- include "world/immovables/grass2/init.lua"
375- include "world/immovables/grass3/init.lua"
376- include "world/immovables/bush1/init.lua"
377- include "world/immovables/bush2/init.lua"
378- include "world/immovables/bush3/init.lua"
379- include "world/immovables/bush4/init.lua"
380- include "world/immovables/bush5/init.lua"
381- include "world/immovables/cactus1/init.lua"
382- include "world/immovables/cactus3/init.lua"
383- include "world/immovables/cactus4/init.lua"
384- include "world/immovables/cactus2/init.lua"
385+-- RST
386+-- .. function:: new_editor_immovable_category{table}
387+--
388+-- This function adds the definition for a category in the "Immovables" tool.
389+-- Only immovables can be in this editor category. The parameter `table` is described below.
390+
391+ world:new_editor_immovable_category{
392+ name = "miscellaneous",
393+ descname = _ "Miscellaneous",
394+ picture = "world/immovables/ruin5/idle.png",
395+ items_per_row = 6,
396+ }
397+
398 include "world/immovables/pebble1/init.lua"
399 include "world/immovables/pebble2/init.lua"
400 include "world/immovables/pebble3/init.lua"
401 include "world/immovables/pebble4/init.lua"
402 include "world/immovables/pebble5/init.lua"
403 include "world/immovables/pebble6/init.lua"
404- include "world/immovables/manmade/artifacts/artifact00/init.lua"
405- include "world/immovables/manmade/artifacts/artifact01/init.lua"
406- include "world/immovables/manmade/artifacts/artifact02/init.lua"
407- include "world/immovables/manmade/artifacts/artifact03/init.lua"
408 include "world/immovables/mushroom1/init.lua"
409 include "world/immovables/mushroom2/init.lua"
410 include "world/immovables/manmade/snowman/init.lua"
411@@ -152,8 +99,48 @@
412 include "world/immovables/skeleton2/init.lua"
413 include "world/immovables/skeleton4/init.lua"
414
415+ -- Artifacts
416+ world:new_editor_immovable_category{
417+ name = "artifacts",
418+ descname = _ "Artifacts" .. "<br>" .. _ "These immovables are used by the win condition “Artifacts”.",
419+ picture = "world/immovables/manmade/artifacts/artifact00/idle.png",
420+ items_per_row = 6,
421+ }
422+
423+ include "world/immovables/manmade/artifacts/artifact00/init.lua"
424+ include "world/immovables/manmade/artifacts/artifact01/init.lua"
425+ include "world/immovables/manmade/artifacts/artifact02/init.lua"
426+ include "world/immovables/manmade/artifacts/artifact03/init.lua"
427+
428+ -- Plants
429+ world:new_editor_immovable_category{
430+ name = "plants",
431+ descname = _ "Plants",
432+ picture = "world/immovables/cactus3/idle.png",
433+ items_per_row = 8,
434+ }
435+
436+ include "world/immovables/grass1/init.lua"
437+ include "world/immovables/grass2/init.lua"
438+ include "world/immovables/grass3/init.lua"
439+ include "world/immovables/bush1/init.lua"
440+ include "world/immovables/bush2/init.lua"
441+ include "world/immovables/bush3/init.lua"
442+ include "world/immovables/bush4/init.lua"
443+ include "world/immovables/bush5/init.lua"
444+ include "world/immovables/cactus1/init.lua"
445+ include "world/immovables/cactus3/init.lua"
446+ include "world/immovables/cactus4/init.lua"
447+ include "world/immovables/cactus2/init.lua"
448
449 -- Standing Stones
450+ world:new_editor_immovable_category{
451+ name = "standing_stones",
452+ descname = _ "Standing Stones",
453+ picture = "world/immovables/standing_stones/standing_stone4_desert/idle.png",
454+ items_per_row = 4,
455+ }
456+
457 include "world/immovables/standing_stones/standing_stone1_desert/init.lua"
458 include "world/immovables/standing_stones/standing_stone1_summer/init.lua"
459 include "world/immovables/standing_stones/standing_stone1_wasteland/init.lua"
460@@ -178,6 +165,13 @@
461 include "world/immovables/standing_stones/standing_stone7/init.lua"
462
463 -- Rocks
464+ world:new_editor_immovable_category{
465+ name = "rocks",
466+ descname = _ "Rocks",
467+ picture = "world/immovables/rocks/greenland_rocks6/idle.png",
468+ items_per_row = 6,
469+ }
470+
471 include "world/immovables/rocks/blackland_rocks1/init.lua"
472 include "world/immovables/rocks/blackland_rocks2/init.lua"
473 include "world/immovables/rocks/blackland_rocks3/init.lua"
474@@ -204,6 +198,41 @@
475 include "world/immovables/rocks/winterland_rocks6/init.lua"
476
477 -- Trees
478+ world:new_editor_immovable_category{
479+ name = "trees_dead",
480+ descname = _ "Dead Trees",
481+ picture = "world/immovables/trees/deadtree2/idle.png",
482+ items_per_row = 8,
483+ }
484+
485+ world:new_editor_immovable_category{
486+ name = "trees_coniferous",
487+ descname = _ "Coniferous Trees",
488+ picture = "world/immovables/trees/spruce/old/idle_0.png",
489+ items_per_row = 8,
490+ }
491+
492+ world:new_editor_immovable_category{
493+ name = "trees_deciduous",
494+ descname = _ "Deciduous Trees",
495+ picture = "world/immovables/trees/alder/old/idle_0.png",
496+ items_per_row = 8,
497+ }
498+
499+ world:new_editor_immovable_category{
500+ name = "trees_palm",
501+ descname = _ "Palm Trees",
502+ picture = "world/immovables/trees/palm_borassus/old/idle_0.png",
503+ items_per_row = 8,
504+ }
505+
506+ world:new_editor_immovable_category{
507+ name = "trees_wasteland",
508+ descname = _ "Wasteland Trees",
509+ picture = "world/immovables/trees/umbrella_red/old/idle_0.png",
510+ items_per_row = 8,
511+ }
512+
513 include "world/immovables/trees/alder/init.lua"
514 include "world/immovables/trees/aspen/init.lua"
515 include "world/immovables/trees/beech/init.lua"
516@@ -236,7 +265,21 @@
517 end)
518
519 print_loading_message("┃ Critters", function()
520- -- Herbivores
521+
522+-- RST
523+-- .. function:: new_editor_critter_category{table}
524+--
525+-- This function adds the definition for a category in the "Animals" tool.
526+-- Only critters can be in this editor category.
527+
528+ world:new_editor_critter_category {
529+ name = "critters_herbivores",
530+ -- TRANSLATORS: A category in the editor for placing animals on the map.
531+ descname = _ "Herbivores",
532+ picture = "world/critters/sheep/idle_00.png",
533+ items_per_row = 10,
534+ }
535+
536 include "world/critters/bunny/init.lua"
537 include "world/critters/sheep/init.lua"
538 include "world/critters/wisent/init.lua"
539@@ -248,6 +291,14 @@
540 include "world/critters/elk/init.lua"
541
542 -- Carnivores
543+ world:new_editor_critter_category {
544+ name = "critters_carnivores",
545+ -- TRANSLATORS: A category in the editor for placing animals on the map.
546+ descname = _ "Carnivores",
547+ picture = "world/critters/fox/idle_00.png",
548+ items_per_row = 10,
549+ }
550+
551 include "world/critters/marten/init.lua"
552 include "world/critters/badger/init.lua"
553 include "world/critters/lynx/init.lua"
554@@ -256,6 +307,39 @@
555 include "world/critters/brownbear/init.lua"
556
557 -- Aquatic animals
558+ world:new_editor_critter_category {
559+ name = "critters_aquatic",
560+ -- TRANSLATORS: A category in the editor for placing animals on the map.
561+ descname = _ "Aquatic",
562+ picture = "world/critters/duck/idle_00.png",
563+ items_per_row = 10,
564+ }
565+
566 include "world/critters/duck/init.lua"
567 end)
568 end)
569+
570+-- RST
571+-- :arg table: This table contains all the data that the game engine will
572+-- add to these editor categories.
573+--
574+-- **name**
575+-- *Mandatory*. A string containing the internal name of this editor category
576+-- for reference, e.g.::
577+--
578+-- name = "summer",
579+--
580+-- **descname**
581+-- *Mandatory*. The translatable display name, e.g.::
582+--
583+-- descname = _"Summer",
584+--
585+-- **picture**
586+-- *Mandatory*. An image to represent this category in the editor tool's tab, e.g.::
587+--
588+-- picture = "world/pics/editor_terrain_category_green.png",
589+--
590+-- **items_per_row**
591+-- *Mandatory*. How many items will be displayed in each row by the tool, e.g.::
592+--
593+-- items_per_row = 6,
594
595=== modified file 'data/world/resources/init.lua'
596--- data/world/resources/init.lua 2016-01-25 18:16:48 +0000
597+++ data/world/resources/init.lua 2017-09-03 10:57:20 +0000
598@@ -1,19 +1,78 @@
599+-- RST
600+-- .. _lua_world_resources:
601+--
602+-- Resources
603+-- ---------
604+--
605+-- Resources are mineable map resources.
606+-- All resources are defined in ``data/world/resources/init.lua``.
607+--
608+-- * **Fish** can be placed in water terrain only and be fished by a fisher.
609+-- * **Water** can be placed on any non-mountain terrain and be pulled up by a well.
610+-- * **Stones**, **Coal**, **Iron** and **Gold** are placed on mountain terrain
611+-- and can be dug up by mines.
612+--
613+-- Which resource can be placed where on the map is defined in each terrain's
614+-- ``valid_resources`` table.
615+--
616+-- The resource names are currently hard-coded in the ``geologist`` worker program
617+-- (`bug #1713706 <https://bugs.launchpad.net/widelands/+bug/1713706>`_), so we can't add any detectable resources at the moment.
618+
619 pics_dir = path.dirname(__file__) .. "pics/"
620
621+-- RST
622+-- .. function:: new_resource_type{table}
623+--
624+-- This function adds the definition of a resource to the engine.
625+--
626+-- :arg table: This table contains all the data that the game engine will add
627+-- to this resource. It contains the following entries:
628+--
629+-- **name**
630+-- *Mandatory*. A string containing the internal name of this resource, e.g.::
631+--
632+-- name = "coal",
633+--
634+-- **descname**
635+-- *Mandatory*. The translatable display name, e.g.::
636+--
637+-- descname = _"Coal",
638+--
639+-- **max_amount**
640+-- *Mandatory*. The maximum possible amount of this map resource that can
641+-- be placed on a map tile, e.g.::
642+--
643+-- max_amount = 20,
644+--
645+-- **detectable**
646+-- *Mandatory*. Set this to ``true`` if a geologist can find it (water or
647+-- mountain resources), and to ``false`` otherwise (fish), e.g.::
648+--
649+-- detectable = true,
650+--
651+-- **representative_image**
652+-- *Mandatory*. Path to an image file that will represent the resource in menus
653+-- etc., e.g.::
654+--
655+-- representative_image = pics_dir .. "coal4.png",
656+--
657+-- **editor_pictures**
658+-- *Mandatory*. A table of pictures that will indicate the resource amount
659+-- on the map, for use in the editor, e.g.::
660+--
661+-- editor_pictures = {
662+-- [5] = pics_dir .. "coal1.png", -- Use this image for amount 0-5;
663+-- [10] = pics_dir .. "coal2.png", -- Use this image for amount 6-10;
664+-- [15] = pics_dir .. "coal3.png", -- Use this image for amount 11-15;
665+-- [1000] = pics_dir .. "coal4.png", -- Use this image for amount > 15;
666+-- }
667+--
668 world:new_resource_type{
669- -- Internal name, must be unique
670 name = "coal",
671- -- The name that will be used in UI and translated.
672 descname = _ "Coal",
673- -- Maximum possible amount
674 max_amount = 20,
675- -- A geologist can find it, otherwise false (see Fish)
676 detectable = true,
677- -- This represents the resource in menus etc.
678 representative_image = pics_dir .. "coal4.png",
679- -- Picture that is used to indicate the amount of resource on the map
680- -- [5] means amount 0 to 5; next line means amount 6 to 10 and so on
681- -- The picture with highest number is additionally used in ui
682 editor_pictures = {
683 [5] = pics_dir .. "coal1.png",
684 [10] = pics_dir .. "coal2.png",
685
686=== modified file 'data/world/terrains/init.lua'
687--- data/world/terrains/init.lua 2017-01-17 08:54:46 +0000
688+++ data/world/terrains/init.lua 2017-09-03 10:57:20 +0000
689@@ -1,86 +1,173 @@
690--- Categories for the editor.
691-world:new_editor_terrain_category{
692- name = "summer",
693- descname = _ "Summer",
694- picture = "world/pics/editor_terrain_category_green.png",
695- items_per_row = 6,
696-}
697-world:new_editor_terrain_category{
698- name = "wasteland",
699- descname = _ "Wasteland",
700- picture = "world/pics/editor_terrain_category_wasteland.png",
701- items_per_row = 6,
702-}
703-world:new_editor_terrain_category{
704- name = "winter",
705- descname = _ "Winter",
706- picture = "world/pics/editor_terrain_category_winter.png",
707- items_per_row = 6,
708-}
709-world:new_editor_terrain_category{
710- name = "desert",
711- descname = _ "Desert",
712- picture = "world/pics/editor_terrain_category_desert.png",
713- items_per_row = 6,
714-}
715+-- RST
716+-- .. _lua_world_terrains:
717+--
718+-- Terrains
719+-- --------
720+--
721+-- Terrains define the basic look of the map, and all terrains are defined in ``data/world/terrains/init.lua``.
722+--
723+-- .. code-block:: none
724+--
725+-- *-------*
726+-- / \ / \
727+-- / \ / \
728+-- / \ / \
729+-- *-------*-------*
730+-- \ / \ /
731+-- \ / \ /
732+-- \ / \ /
733+-- *-------*
734+--
735+-- Terrain tiles have a triangular shape, and 6 of them will be combined to form a hexagon. Each vertex between the terrains (* in the figure) will form a node that is influenced by the 6 terrains surrounding it, and where other map entities can be placed. You can find more information on the terrains' shape and on how to create textures on the `wiki <https://wl.widelands.org/wiki/HelpTerrains/>`_.
736+--
737+-- Each terrain tile will also influence some properties for the map entities that are placed on its 3 vertices, like:
738+--
739+-- * Which resources can go on a map node.
740+-- * How well which type of tree will grow on a map node.
741+-- * Which map objects can be built on the nodes or move through them.
742+
743+pics_dir = path.dirname(__file__) .. "pics/"
744+
745+-- RST
746+-- .. function:: new_terrain_type{table}
747+--
748+-- This function adds the definition of a terrain to the engine.
749+--
750+-- :arg table: This table contains all the data that the game engine will add
751+-- to this terrain. It contains the following entries:
752+--
753+-- **name**
754+-- *Mandatory*. A string containing the internal name of this terrain, e.g.::
755+--
756+-- name = "summer_meadow1",
757+--
758+-- **descname**
759+-- *Mandatory*. The translatable display name, e.g.::
760+--
761+-- descname = _"Meadow 1",
762+--
763+-- **editor_category**
764+-- *Mandatory*. The category that is used in the editor tools for placing a
765+-- terrain of this type on the map, e.g.::
766+--
767+-- editor_category = "summer",
768+--
769+-- **is**
770+-- *Mandatory*. The type of this terrain, which determines if the nodes
771+-- surrounding the terrain will be walkable or navigable, if mines or buildings
772+-- can be built on them, if flags can be built on them, and so on.
773+-- The following properties are available:
774+--
775+-- * ``arable``: Allows building of normal buildings and roads.
776+-- * ``mineable``: Allows building of mines and roads.
777+-- * ``walkable``: Allows building of flags and roads only.
778+-- * ``water``: Nothing can be built here, but ships and aquatic animals can pass.
779+-- * ``unreachable``: Nothing can be built here, and nothing can walk on it,
780+-- and nothing will grow.
781+-- * ``unwalkable``: Nothing can be built here, and nothing can walk on it.
782+--
783+-- Example::
784+--
785+-- is = "arable",
786+--
787+-- *Note: There is currently some interdependency between ``is`` and
788+-- ``valid_resources``, so not all combinations are possible. See*
789+-- `Bug 1505345 <https://bugs.launchpad.net/widelands/+bug/1505345>`_
790+-- *for more information.*
791+--
792+-- **tooltips**
793+-- *Optional*. Additional custom tooltip entries, e.g.::
794+--
795+-- tooltips = {
796+-- -- TRANSLATORS: This is an entry in a terrain tooltip. Try to use 1 word if possible.
797+-- _"likes trees",
798+-- },
799+--
800+-- **valid_resources**
801+-- *Mandatory*. The list of mineable resources that can be found on this terrain.
802+-- Leave this empty (``{}``) if you want no resources on this terrain. Example::
803+--
804+-- valid_resources = {"water"},
805+--
806+-- *Note: There is currently some interdependency between ``is`` and
807+-- ``valid_resources``, so not all combinations are possible. See*
808+-- `Bug #1505345 <https://bugs.launchpad.net/widelands/+bug/1505345/>`_
809+-- *for more information.*
810+--
811+-- **default_resource**
812+-- *Mandatory*. A resource type that can always be found on this terrain when
813+-- a new game is started, unless the map maker places some resources there via
814+-- the editor. Use the empty string
815+-- (``""``) if you want no default resource. Example::
816+--
817+-- default_resource = "water",
818+--
819+-- **default_resource_amount**
820+-- *Mandatory*. The amount of the above default resource that will
821+-- automatically be placed on this terrain, e.g.::
822+--
823+-- default_resource_amount = 10,
824+--
825+-- **textures**
826+-- *Mandatory*. The images used for this terrain. Examples::
827+--
828+-- textures = { pics_dir .. "summer/meadow1_00.png" }, - A static terrain
829+-- textures = path.list_files(pics_dir .. "summer/lava/lava_??.png"), -- An animated terrain
830+--
831+-- **dither_layer**
832+-- *Mandatory*. Terrains will be blended slightly over each other in order
833+-- to hide the harsh edges of the triangles. This describes the
834+-- `z layer <https://en.wikipedia.org/wiki/Z-order>`_ of a terrain when
835+-- rendered next to another terrain. Terrains with a higher value will be
836+-- dithered on top of terrains with a lower value. Example::
837+--
838+-- dither_layer = 340,
839+--
840+-- **temperature**
841+-- *Mandatory*. A terrain affinity constant. These are used to model how well
842+-- trees will grow on this terrain. Temperature is in arbitrary units. Example::
843+--
844+-- temperature = 100,
845+--
846+-- **humidity**
847+-- *Mandatory*. A terrain affinity constant. These are used to model how well
848+-- trees will grow on this terrain. Humidity is in percent (1 being very wet).
849+-- Example::
850+--
851+-- humidity = 0.6,
852+--
853+-- **fertility**
854+-- *Mandatory*. A terrain affinity constant. These are used to model how well
855+-- trees will grow on this terrain. Fertility is in percent (1 being very
856+-- fertile). Example::
857+--
858+-- fertility = 0.7,
859+--
860
861 ------------------------
862 -- Former greenland --
863 ------------------------
864
865-pics_dir = path.dirname(__file__) .. "pics/"
866 world:new_terrain_type{
867- -- The internal name of this terrain.
868 name = "summer_meadow1",
869-
870- -- The name that will be used in UI and translated.
871 descname = _ "Meadow 1",
872-
873- -- The category for sorting this into menus in the editor.
874 editor_category = "summer",
875-
876- -- Type of terrain. Describes if the terrain is walkable, swimmable, if
877- -- mines or buildings can be build on it, if flags can be build on it and so
878- -- on.
879- --
880- -- The following properties are available:
881- -- "arable": Allows building of normal buildings and roads
882- -- "mineable": Allows building of mines and roads
883- -- "walkable": Allows building of roads only.
884- -- "water": Nothing can be built here, but ships and aquatic animals can pass
885- -- "unreachable": Nothing can be built here, and nothing can walk on it, and nothing will grow.
886- -- "unwalkable": Nothing can be built here, and nothing can walk on it
887 is = "arable",
888-
889- -- You can add custom additional tooltip entries here.
890 tooltips = {
891 -- TRANSLATORS: This is an entry in a terrain tooltip. Try to use 1 word if possible.
892 _"likes trees",
893 },
894
895- -- The list resources that can be found in this terrain.
896 valid_resources = {"water"},
897-
898- -- The resources that is always in this terrain (if not overwritten by the
899- -- map maker through the editor) and the amount.
900 default_resource = "water",
901 default_resource_amount = 10,
902
903- -- The images used for this terrain.
904 textures = { pics_dir .. "summer/meadow1_00.png" },
905
906- -- This describes the z layer of the terrain when rendered next to another
907- -- one and blending slightly over it to hide the triangles.
908 dither_layer = 340,
909
910- -- Terrain affinity constants. This is used to model how well plants grow on this terrain.
911- -- Temperature is in arbitrary units.
912 temperature = 100,
913-
914- -- Humidity is in percent (1 being very wet).
915 humidity = 0.6,
916-
917- -- Fertility is in percent (1 being very fertile).
918 fertility = 0.7,
919 }
920
921
922=== modified file 'doc/sphinx/extract_rst.py'
923--- doc/sphinx/extract_rst.py 2017-08-30 11:58:41 +0000
924+++ doc/sphinx/extract_rst.py 2017-09-03 10:57:20 +0000
925@@ -31,7 +31,7 @@
926 lua_dirs = (
927 ('data/scripting', '', 'auxiliary'),
928 ('data/scripting/win_conditions', '', 'auxiliary'),
929- ('data/scripting/editor', '', 'lua_world'),
930+ ('data/scripting/editor', '', 'lua_world_other'),
931 ('data/tribes', '', 'lua_tribes_defining'),
932 ('data/tribes/scripting', '', 'lua_tribes_other'),
933 ('data/tribes/scripting/mapobject_info', '', 'lua_tribes_other'),
934@@ -60,6 +60,15 @@
935 'carriers', 'lua_tribes_workers'),
936 ('data/tribes/workers/atlanteans/soldier',
937 'soldiers', 'lua_tribes_workers'),
938+ ('data/world', '', 'lua_world_defining'),
939+ ('data/world/critters/badger',
940+ 'critters', 'lua_world_units'),
941+ ('data/world/immovables/bush1',
942+ 'immovables', 'lua_world_units'),
943+ ('data/world/resources',
944+ 'resources', 'lua_world_units'),
945+ ('data/world/terrains',
946+ 'terrains', 'lua_world_units'),
947 )
948
949
950
951=== renamed file 'doc/sphinx/source/lua_world.rst.org' => 'doc/sphinx/source/lua_world.rst'
952--- doc/sphinx/source/lua_world.rst.org 2016-08-29 14:02:55 +0000
953+++ doc/sphinx/source/lua_world.rst 2017-09-03 10:57:20 +0000
954@@ -1,3 +1,5 @@
955+.. _toc_lua_world:
956+
957 Scripts for World
958 =================
959
960@@ -19,4 +21,6 @@
961 .. toctree::
962 :maxdepth: 3
963
964-REPLACE_ME
965+ autogen_toc_lua_world_defining
966+ autogen_toc_lua_world_units
967+ autogen_toc_lua_world_other
968
969=== added file 'doc/sphinx/source/lua_world_defining.rst.org'
970--- doc/sphinx/source/lua_world_defining.rst.org 1970-01-01 00:00:00 +0000
971+++ doc/sphinx/source/lua_world_defining.rst.org 2017-09-03 10:57:20 +0000
972@@ -0,0 +1,14 @@
973+Defining the World
974+==================
975+
976+The world is bootstrapped with the following scripts:
977+
978+* ``data/world/init.lua``: This file loads all the scripts that define the
979+ world. So, if you add a new unit to the world, it needs to be
980+ listed in this file.
981+* ``data/world/map_generation.lua``: This file is used by the random map generator.
982+
983+.. toctree::
984+ :maxdepth: 3
985+
986+REPLACE_ME
987
988=== added file 'doc/sphinx/source/lua_world_other.rst.org'
989--- doc/sphinx/source/lua_world_other.rst.org 1970-01-01 00:00:00 +0000
990+++ doc/sphinx/source/lua_world_other.rst.org 2017-09-03 10:57:20 +0000
991@@ -0,0 +1,9 @@
992+Other Scripts
993+=============
994+
995+The help files for the editor that describe the world entities are located in ``data/scripting/editor``.
996+
997+.. toctree::
998+ :maxdepth: 3
999+
1000+REPLACE_ME
1001
1002=== added file 'doc/sphinx/source/lua_world_units.rst.org'
1003--- doc/sphinx/source/lua_world_units.rst.org 1970-01-01 00:00:00 +0000
1004+++ doc/sphinx/source/lua_world_units.rst.org 2017-09-03 10:57:20 +0000
1005@@ -0,0 +1,17 @@
1006+Defining Units
1007+==============
1008+
1009+A world can have the following types of units:
1010+
1011+* **Critters**: Animals that will move around the map at random
1012+* **Immovables**: Trees, rocks, artifacts and eye candy
1013+* **Resources**: Mineable map resources like fish, water, coal, ...
1014+* **Terrains**: The base of the landscape. Meadows, mountains, water...
1015+
1016+The definitions for the world's units are located in the subdirectories of
1017+``data/world``. Each unit needs to have an ``init.lua`` file, which will load the unit to be used in the game.
1018+
1019+.. toctree::
1020+ :maxdepth: 3
1021+
1022+REPLACE_ME
1023
1024=== modified file 'doc/sphinx/source/map_objects.rst'
1025--- doc/sphinx/source/map_objects.rst 2017-08-28 15:17:11 +0000
1026+++ doc/sphinx/source/map_objects.rst 2017-09-03 10:57:20 +0000
1027@@ -5,6 +5,6 @@
1028 :maxdepth: 3
1029
1030 animations
1031- autogen_toc_lua_world
1032+ lua_world
1033 lua_tribes
1034 map_object_programs
1035
1036=== modified file 'src/scripting/lua_root.cc'
1037--- src/scripting/lua_root.cc 2017-01-25 18:55:59 +0000
1038+++ src/scripting/lua_root.cc 2017-09-03 10:57:20 +0000
1039@@ -294,8 +294,9 @@
1040
1041 .. class:: World
1042
1043- This offers access to the objects in a the widelands world and allows to add
1044- new objects.
1045+ This offers access to the objects in the Widelands world and allows to add new objects.
1046+ On how to build the world and adding new objects to it, see
1047+ :ref:`toc_lua_world`.
1048 */
1049
1050 const char LuaWorld::className[] = "World";
1051@@ -376,15 +377,8 @@
1052 return 1;
1053 }
1054
1055-/* RST
1056- .. method:: new_resource_type(table)
1057-
1058- Adds a new resource type that can be in the different maps. Takes a
1059- single argument, a table with the descriptions for the resource type. See the
1060- files in data/world/ for usage examples.
1061-
1062- :returns: :const:`nil`
1063-*/
1064+// Documented in data/world/resources/init.lua.
1065+// See also the World and Tribes section in the Widelands Scripting Reference on the website.
1066 int LuaWorld::new_resource_type(lua_State* L) {
1067 if (lua_gettop(L) != 2) {
1068 report_error(L, "Takes only one argument.");
1069@@ -400,15 +394,8 @@
1070 return 0;
1071 }
1072
1073-/* RST
1074- .. method:: new_terrain_type(table)
1075-
1076- Adds a new terrain type that can be used in maps. Takes a single
1077- argument, a table with the descriptions for the terrain type. See the files in data/world/
1078- for usage examples.
1079-
1080- :returns: :const:`nil`
1081-*/
1082+// Documented in data/world/terrains/init.lua.
1083+// See also the World and Tribes section in the Widelands Scripting Reference on the website.
1084 int LuaWorld::new_terrain_type(lua_State* L) {
1085 if (lua_gettop(L) != 2) {
1086 report_error(L, "Takes only one argument.");
1087@@ -423,15 +410,8 @@
1088 return 0;
1089 }
1090
1091-/* RST
1092- .. method:: new_critter_type(table)
1093-
1094- Adds a new critter type that can be used in maps. Takes a single
1095- argument, a table with the description. See the files in data/world/ for usage
1096- examples.
1097-
1098- :returns: :const:`nil`
1099-*/
1100+// Documented in data/world/critters/badger/init.lua.
1101+// See also the World and Tribes section in the Widelands Scripting Reference on the website.
1102 int LuaWorld::new_critter_type(lua_State* L) {
1103 if (lua_gettop(L) != 2) {
1104 report_error(L, "Takes only one argument.");
1105@@ -445,15 +425,8 @@
1106 return 0;
1107 }
1108
1109-/* RST
1110- .. method:: new_immovable_type(table)
1111-
1112- Adds a new immovable type that can be used in maps. Takes a single
1113- argument, a table with the description. See the files in data/world/ for usage
1114- examples.
1115-
1116- :returns: :const:`nil`
1117-*/
1118+// Documented in data/world/immovables/bush1/init.lua.
1119+// See also the World and Tribes section in the Widelands Scripting Reference on the website.
1120 int LuaWorld::new_immovable_type(lua_State* L) {
1121 if (lua_gettop(L) != 2) {
1122 report_error(L, "Takes only one argument.");
1123@@ -467,15 +440,8 @@
1124 return 0;
1125 }
1126
1127-/* RST
1128- .. method:: new_editor_terrain_category(table)
1129-
1130- Adds a new editor category that can be used to classify objects in the
1131- world. This will be used to sort them into sub menus in the editor. See
1132- usage examples in data/world/.
1133-
1134- :returns: :const:`nil`
1135-*/
1136+// Documented in data/world/init.lua.
1137+// See also the World and Tribes section in the Widelands Scripting Reference on the website.
1138 int LuaWorld::new_editor_terrain_category(lua_State* L) {
1139 if (lua_gettop(L) != 2) {
1140 report_error(L, "Takes only one argument.");
1141@@ -489,13 +455,8 @@
1142 return 0;
1143 }
1144
1145-/* RST
1146- .. method:: new_editor_critter_category(table)
1147-
1148- Like :func:`new_editor_terrain_category`, but for immovables.
1149-
1150- :returns: :const:`nil`
1151-*/
1152+// Documented in data/world/init.lua.
1153+// See also the World and Tribes section in the Widelands Scripting Reference on the website.
1154 int LuaWorld::new_editor_critter_category(lua_State* L) {
1155 if (lua_gettop(L) != 2) {
1156 report_error(L, "Takes only one argument.");
1157@@ -509,13 +470,8 @@
1158 return 0;
1159 }
1160
1161-/* RST
1162- .. method:: new_editor_immovable_category(table)
1163-
1164- Like :func:`new_editor_terrain_category`, but for immovables.
1165-
1166- :returns: :const:`nil`
1167-*/
1168+// Documented in data/world/init.lua.
1169+// See also the World and Tribes section in the Widelands Scripting Reference on the website.
1170 int LuaWorld::new_editor_immovable_category(lua_State* L) {
1171 if (lua_gettop(L) != 2) {
1172 report_error(L, "Takes only one argument.");

Subscribers

People subscribed via source and target branches

to status/vote changes: