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

Proposed by kaputtnik
Status: Merged
Merged at revision: 8583
Proposed branch: lp:~widelands-dev/widelands/fix_infrastructure_return_values
Merge into: lp:widelands
Diff against target: 75 lines (+15/-6)
1 file modified
data/scripting/infrastructure.lua (+15/-6)
To merge this branch: bzr merge lp:~widelands-dev/widelands/fix_infrastructure_return_values
Reviewer Review Type Date Requested Status
Klaus Halfmann Approve
GunChleoc Approve
kaputtnik (community) Needs Resubmitting
Review via email: mp+337364@code.launchpad.net

Description of the change

While working on a fix of bug 1639514 i found that there was a return value for place_building_in_region() is documented, but it does not return anything.

https://wl.widelands.org/docs/wl/autogen_auxiliary_infrastructure/#place_building_in_region

The problem was that place_building_in_region() calls prefilled_buildings() which does not return the building created whereas this value is returned by place_buildings()

Relevant code of place_building_in_region():
https://bazaar.launchpad.net/~widelands-dev/widelands/trunk/view/head:/data/scripting/infrastructure.lua#L154

prefilled_buildings() get the building of place_buildings(), but do not return it:
https://bazaar.launchpad.net/~widelands-dev/widelands/trunk/view/head:/data/scripting/infrastructure.lua#L99

This branch provides a small change, so that both functions returns the placed building. Also some small corrections related to RST.

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

Ups, that will not work...

review: Needs Fixing
Revision history for this message
kaputtnik (franku) wrote :

That should work now.

review: Needs Resubmitting
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 3154. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/339079461.
Appveyor build 2961. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_fix_infrastructure_return_values-2961.

Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

kaputtnik whats the problem then?
Is it worth, me taking a look?

Revision history for this message
kaputtnik (franku) wrote :

There was no real problem, but wrong documentation. Nevertheless this change will make it possible to work with the returned building, e.g. using building.flag for creating roads or query building.descr.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Code LGTM, not tested.

review: Approve
Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

OK I testplayed this for a while,
but I assume nobody activly usee this code.
So there is nothing to find?

kaputtnik: Ith er any way to actually test this, or perhpas a regression test?
If not this can go in.

review: Approve (compile, testplay)
Revision history for this message
kaputtnik (franku) wrote :

Klaus, this code is only used in scenarios or campaigns.

I grep'd through the data directory and currently all campaigns which use prefilled_buildings() or place_building_in_region() didn't use any return values. I would have been surprised if they do :-D

The branch linked in bug 1639514 uses the return value from prefilled_buildings():

https://bazaar.launchpad.net/~widelands-dev/widelands/bug-1639514_fix_yellow_player/view/head:/data/campaigns/bar02.wmf/scripting/starting_conditions.lua#L97

For testing one has to write a scenario map. I could do so if it is wanted :-)

Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

SO actually you next branch will use and then test it.

@bunnybot merge

review: Approve
Revision history for this message
GunChleoc (gunchleoc) wrote :

I started all the campaign and tutorial scenarios without problems, so it's OK.

Thanks for fixing :)

BTW we forgot to set a commit message ;)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'data/scripting/infrastructure.lua'
--- data/scripting/infrastructure.lua 2017-06-08 12:37:10 +0000
+++ data/scripting/infrastructure.lua 2018-02-08 16:11:51 +0000
@@ -32,6 +32,7 @@
32-- :arg create_carriers: If this is :const:`true` carriers are created for32-- :arg create_carriers: If this is :const:`true` carriers are created for
33-- the roads. Otherwise no carriers will be created.33-- the roads. Otherwise no carriers will be created.
34-- :type create_carriers: :class:`boolean`34-- :type create_carriers: :class:`boolean`
35
35function connected_road(p, start, cmd, g_create_carriers)36function connected_road(p, start, cmd, g_create_carriers)
36 create_carriers = true37 create_carriers = true
37 if g_create_carriers ~= nil then38 if g_create_carriers ~= nil then
@@ -96,7 +97,11 @@
96-- :meth:`wl.map.Warehouse.set_workers`. Note that ProductionSites97-- :meth:`wl.map.Warehouse.set_workers`. Note that ProductionSites
97-- are filled with workers by default.98-- are filled with workers by default.
98-- :type b1_descr: :class:`array`99-- :type b1_descr: :class:`array`
100--
101-- :returns: A table of created buildings
102
99function prefilled_buildings(p, ...)103function prefilled_buildings(p, ...)
104 local b_table = {}
100 for idx,bdescr in ipairs({...}) do105 for idx,bdescr in ipairs({...}) do
101 local b = p:place_building(bdescr[1], wl.Game().map:get_field(bdescr[2],bdescr[3]), false, true)106 local b = p:place_building(bdescr[1], wl.Game().map:get_field(bdescr[2],bdescr[3]), false, true)
102 -- Fill with workers107 -- Fill with workers
@@ -115,7 +120,10 @@
115 -- Fill with wares if this is requested120 -- Fill with wares if this is requested
116 if bdescr.wares then b:set_wares(bdescr.wares) end121 if bdescr.wares then b:set_wares(bdescr.wares) end
117 if bdescr.inputs then b:set_inputs(bdescr.inputs) end122 if bdescr.inputs then b:set_inputs(bdescr.inputs) end
123
124 table.insert(b_table, b)
118 end125 end
126 return b_table
119end127end
120128
121-- RST129-- RST
@@ -132,12 +140,12 @@
132-- :type building: :class:`string`140-- :type building: :class:`string`
133-- :arg region: The fields which are tested for suitability.141-- :arg region: The fields which are tested for suitability.
134-- :type region: :class:`array`142-- :type region: :class:`array`
135-- :arg opts: a table with prefill information (wares, soldiers, workers,143-- :arg opts: A table with prefill information (wares, soldiers, workers,
136-- see :func:`prefilled_buildings`) and the following options:144-- see :func:`prefilled_buildings`)
137--
138-- :type opts: :class:`table`145-- :type opts: :class:`table`
139--146--
140-- :returns: the building created147-- :returns: The building created
148
141function place_building_in_region(plr, building, fields, gargs)149function place_building_in_region(plr, building, fields, gargs)
142 local idx150 local idx
143 local f151 local f
@@ -151,7 +159,7 @@
151 args[1] = building159 args[1] = building
152 args[2] = f.x160 args[2] = f.x
153 args[3] = f.y161 args[3] = f.y
154 return prefilled_buildings(plr, args)162 return prefilled_buildings(plr, args)[1]
155 end163 end
156 table.remove(fields, idx)164 table.remove(fields, idx)
157 end165 end
@@ -167,12 +175,13 @@
167-- RST175-- RST
168-- .. function:: is_building(immovable)176-- .. function:: is_building(immovable)
169--177--
170-- Checks whether an immpvable is a finished building, i.e. not178-- Checks whether an immovable is a finished building, i.e. not
171-- a construction site.179-- a construction site.
172--180--
173-- :arg immovable: The immovable to test181-- :arg immovable: The immovable to test
174--182--
175-- :returns: true if the immovable is a building183-- :returns: true if the immovable is a building
184
176function is_building(immovable)185function is_building(immovable)
177 return immovable.descr.type_name == "productionsite" or186 return immovable.descr.type_name == "productionsite" or
178 immovable.descr.type_name == "warehouse" or187 immovable.descr.type_name == "warehouse" or

Subscribers

People subscribed via source and target branches

to status/vote changes: