Merge lp:~widelands-dev/widelands/bug-1551578-place_building-crash into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 7861
Proposed branch: lp:~widelands-dev/widelands/bug-1551578-place_building-crash
Merge into: lp:widelands
Diff against target: 193 lines (+39/-64)
5 files modified
data/scripting/infrastructure.lua (+6/-5)
data/tribes/scripting/starting_conditions/atlanteans/fortified_village.lua (+10/-19)
data/tribes/scripting/starting_conditions/barbarians/fortified_village.lua (+13/-22)
data/tribes/scripting/starting_conditions/empire/fortified_village.lua (+9/-18)
utils/buildcat.py (+1/-0)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1551578-place_building-crash
Reviewer Review Type Date Requested Status
TiborB Approve
Review via email: mp+287660@code.launchpad.net

Commit message

Fixed crash with playing buildings in Fortified Village when there isn't enough space by redesigning the error message. This also unmasked some other error messages, which showed some outdated building names in Barbarians Fortified Village.

Description of the change

Fixed crash with playing buildings in Fortified Village when there isn't enough space by redesigning the error message. This also unmasked some other error messages, which showed some outdated building names in Barbarians Fortified Village.

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

Nice

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

Continuous integration builds have changed state:

Travis build 789. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/112898878.
Appveyor build 635. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1551578_place_building_crash-635.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks for the review :)

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/scripting/infrastructure.lua'
2--- data/scripting/infrastructure.lua 2015-11-24 18:19:22 +0000
3+++ data/scripting/infrastructure.lua 2016-03-01 16:19:34 +0000
4@@ -90,9 +90,8 @@
5 -- are filled with workers by default.
6 -- :type b1_descr: :class:`array`
7 function prefilled_buildings(p, ...)
8- -- TODO(GunChleoc) this should produce an error message if a building/ware/worker doesn't exist.
9 for idx,bdescr in ipairs({...}) do
10- b = p:place_building(bdescr[1], wl.Game().map:get_field(bdescr[2],bdescr[3]), false, true)
11+ local b = p:place_building(bdescr[1], wl.Game().map:get_field(bdescr[2],bdescr[3]), false, true)
12 -- Fill with workers
13 if b.valid_workers then b:set_workers(b.valid_workers) end
14 if bdescr.workers then b:set_workers(bdescr.workers) end
15@@ -153,9 +152,11 @@
16 end
17 table.remove(fields, idx)
18 end
19- error(string.format(
20- "Could not find a suitable position for building '%s' for player %i",
21- building, plr.number)
22+ plr:send_message(
23+ -- TRANSLATORS: Short for "Not enough space"
24+ _"No Space",
25+ rt(p(_([[Some of your starting buildings didn’t have enough room and weren’t built. You are at a disadvantage with this; consider restarting this map with a fair starting condition.]]))),
26+ {popup=true, heading=_"Not enough space"}
27 )
28 end
29
30
31=== modified file 'data/tribes/scripting/starting_conditions/atlanteans/fortified_village.lua'
32--- data/tribes/scripting/starting_conditions/atlanteans/fortified_village.lua 2016-01-28 05:24:34 +0000
33+++ data/tribes/scripting/starting_conditions/atlanteans/fortified_village.lua 2016-03-01 16:19:34 +0000
34@@ -10,17 +10,16 @@
35 descname = _ "Fortified Village",
36 func = function(plr, shared_in_start)
37
38- local sf = wl.Game().map.player_slots[plr.number].starting_field
39- if shared_in_start then
40- sf = shared_in_start
41- else
42- plr:allow_workers("all")
43- end
44-
45- local h = plr:place_building("atlanteans_castle", sf, false, true)
46- h:set_soldiers{[{0,0,0,0}] = 12}
47-
48- if not pcall(function()
49+ local sf = wl.Game().map.player_slots[plr.number].starting_field
50+ if shared_in_start then
51+ sf = shared_in_start
52+ else
53+ plr:allow_workers("all")
54+ end
55+
56+ local h = plr:place_building("atlanteans_castle", sf, false, true)
57+ h:set_soldiers{[{0,0,0,0}] = 12}
58+
59 place_building_in_region(plr, "atlanteans_warehouse", sf:region(7), {
60 wares = {
61 diamond = 7,
62@@ -97,13 +96,5 @@
63 place_building_in_region(plr, "atlanteans_sawmill", sf:region(11), {
64 wares = { log = 1 }
65 })
66- end) then
67- plr:send_message(
68- -- TRANSLATORS: Short for "Not enough space"
69- _"No Space",
70- rt(p(_([[Some of your starting buildings didn’t have enough room and weren’t built. You are at a disadvantage with this; consider restarting this map with a fair starting condition.]]))),
71- {popup=true, heading=_"Not enough space"}
72- )
73 end
74-end
75 }
76
77=== modified file 'data/tribes/scripting/starting_conditions/barbarians/fortified_village.lua'
78--- data/tribes/scripting/starting_conditions/barbarians/fortified_village.lua 2016-01-28 05:24:34 +0000
79+++ data/tribes/scripting/starting_conditions/barbarians/fortified_village.lua 2016-03-01 16:19:34 +0000
80@@ -10,18 +10,17 @@
81 descname = _ "Fortified Village",
82 func = function(plr, shared_in_start)
83
84- local sf = wl.Game().map.player_slots[plr.number].starting_field
85-
86- if shared_in_start then
87- sf = shared_in_start
88- else
89- plr:allow_workers("all")
90- end
91-
92- local h = plr:place_building("barbarians_citadel", sf, false, true)
93- h:set_soldiers{[{0,0,0,0}] = 12}
94-
95- if not pcall(function()
96+ local sf = wl.Game().map.player_slots[plr.number].starting_field
97+
98+ if shared_in_start then
99+ sf = shared_in_start
100+ else
101+ plr:allow_workers("all")
102+ end
103+
104+ local h = plr:place_building("barbarians_citadel", sf, false, true)
105+ h:set_soldiers{[{0,0,0,0}] = 12}
106+
107 place_building_in_region(plr, "barbarians_warehouse", sf:region(7), {
108 wares = {
109 ax = 5,
110@@ -78,25 +77,17 @@
111 place_building_in_region(plr, "barbarians_helmsmithy", sf:region(12), {
112 wares = { iron = 4, gold = 4 }
113 })
114- place_building_in_region(plr, "barbarians_metalworks", sf:region(12), {
115+ place_building_in_region(plr, "barbarians_metal_workshop", sf:region(12), {
116 wares = { iron = 8 },
117 })
118 place_building_in_region(plr, "barbarians_ax_workshop", sf:region(12), {
119 wares = { coal = 8 },
120 })
121- place_building_in_region(plr, "barbarians_hardener", sf:region(12), {
122+ place_building_in_region(plr, "barbarians_wood_hardener", sf:region(12), {
123 wares = { log = 1 },
124 })
125 place_building_in_region(plr, "barbarians_lime_kiln", sf:region(12), {
126 wares = { granite = 6, coal = 3 },
127 })
128- end) then
129- plr:send_message(
130- -- TRANSLATORS: Short for "Not enough space"
131- _"No Space",
132- rt(p(_([[Some of your starting buildings didn’t have enough room and weren’t built. You are at a disadvantage with this; consider restarting this map with a fair starting condition.]]))),
133- {popup=true, heading=_"Not enough space"}
134- )
135 end
136-end,
137 }
138
139=== modified file 'data/tribes/scripting/starting_conditions/empire/fortified_village.lua'
140--- data/tribes/scripting/starting_conditions/empire/fortified_village.lua 2016-01-28 05:24:34 +0000
141+++ data/tribes/scripting/starting_conditions/empire/fortified_village.lua 2016-03-01 16:19:34 +0000
142@@ -12,16 +12,15 @@
143
144 local sf = wl.Game().map.player_slots[plr.number].starting_field
145
146- if shared_in_start then
147- sf = shared_in_start
148- else
149- plr:allow_workers("all")
150- end
151-
152- local h = plr:place_building("empire_castle", sf, false, true)
153- h:set_soldiers{[{0,0,0,0}] = 12}
154-
155- if not pcall(function()
156+ if shared_in_start then
157+ sf = shared_in_start
158+ else
159+ plr:allow_workers("all")
160+ end
161+
162+ local h = plr:place_building("empire_castle", sf, false, true)
163+ h:set_soldiers{[{0,0,0,0}] = 12}
164+
165 place_building_in_region(plr, "empire_warehouse", sf:region(7), {
166 wares = {
167 armor_helmet = 2,
168@@ -115,13 +114,5 @@
169 })
170
171 place_building_in_region(plr, "empire_stonemasons_house", sf:region(11))
172- end) then
173- plr:send_message(
174- -- TRANSLATORS: Short for "Not enough space"
175- _"No Space",
176- rt(p(_([[Some of your starting buildings didn’t have enough room and weren’t built. You are at a disadvantage with this; consider restarting this map with a fair starting condition.]]))),
177- {popup=true, heading=_"Not enough space"}
178- )
179 end
180-end
181 }
182
183=== modified file 'utils/buildcat.py'
184--- utils/buildcat.py 2016-03-01 09:26:35 +0000
185+++ utils/buildcat.py 2016-03-01 16:19:34 +0000
186@@ -50,6 +50,7 @@
187 "../../src/*/*/*/*.h",
188 "../../src/*/*/*/*/*.h",
189 "../../src/*/*/*/*/*/*.h",
190+ "../../data/scripting/*.lua",
191 "../../data/scripting/editor/*.lua",
192 "../../data/scripting/widelands/*.lua",
193 ] ),

Subscribers

People subscribed via source and target branches

to status/vote changes: