Merge lp:~widelands-dev/widelands/feature-test-supply-crash into lp:widelands
- feature-test-supply-crash
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 8240 | ||||
Proposed branch: | lp:~widelands-dev/widelands/feature-test-supply-crash | ||||
Merge into: | lp:widelands | ||||
Diff against target: |
499 lines (+447/-1) 4 files modified
src/scripting/lua_map.cc (+230/-1) src/scripting/lua_map.h (+2/-0) test/maps/lua_testsuite.wmf/scripting/warehouse.lua (+148/-0) test/maps/ship_transportation.wmf/scripting/test_create_request_while_worker_with_ware_is_in_transit.lua (+67/-0) |
||||
To merge this branch: | bzr merge lp:~widelands-dev/widelands/feature-test-supply-crash | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
GunChleoc | Approve | ||
Review via email: mp+312422@code.launchpad.net |
Commit message
Description of the change
- Adds Lua-methods to set the ware and worker policies of warehouses (e.g. "remove from here").
- Creates a regression test for the linked bug which crashes the game when only this branch is used. See also the other branch for a fix of the bug:
https:/
bunnybot (widelandsofficial) wrote : | # |
GunChleoc (gunchleoc) wrote : | # |
Can you put the RST comments directly above each method? This will make the code easier to read and avoid accidentally documenting this twice in the future.
I have also added come nits and ideas.
bunnybot (widelandsofficial) wrote : | # |
Bunnybot encountered an error while working on this merge proposal:
HTTP Error 500: Internal Server Error
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 1699. State: failed. Details: https:/
Appveyor build 1539. State: success. Details: https:/
bunnybot (widelandsofficial) wrote : | # |
Bunnybot encountered an error while working on this merge proposal:
('The read operation timed out',)
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 1699. State: failed. Details: https:/
Appveyor build 1539. State: success. Details: https:/
bunnybot (widelandsofficial) wrote : | # |
Bunnybot encountered an error while working on this merge proposal:
HTTP Error 500: Internal Server Error
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 1699. State: failed. Details: https:/
Appveyor build 1539. State: success. Details: https:/
bunnybot (widelandsofficial) wrote : | # |
Bunnybot encountered an error while working on this merge proposal:
('The read operation timed out',)
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 1699. State: failed. Details: https:/
Appveyor build 1539. State: success. Details: https:/
Notabilis (notabilis27) wrote : | # |
The suggestions from the review has been dealt with.
The Travis-tests are failing on purpose since the created regression test shows a bug in trunk at creation time of this branch. When merging trunk locally the tests run fine. If there are no further objections regarding this branch trunk can be merged into it which will make this branch ready for merge.
GunChleoc (gunchleoc) wrote : | # |
Added some tiny nits - feel free to merge any time once you have addressed them :)
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 1807. State: passed. Details: https:/
Appveyor build 1645. State: success. Details: https:/
bunnybot (widelandsofficial) wrote : | # |
Bunnybot encountered an error while working on this merge proposal:
HTTP Error 500: Internal Server Error
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 1807. State: passed. Details: https:/
Appveyor build 1645. State: success. Details: https:/
GunChleoc (gunchleoc) wrote : | # |
@bunnybot merge
Preview Diff
1 | === modified file 'src/scripting/lua_map.cc' |
2 | --- src/scripting/lua_map.cc 2016-12-14 22:11:52 +0000 |
3 | +++ src/scripting/lua_map.cc 2017-01-06 15:58:31 +0000 |
4 | @@ -3871,6 +3871,7 @@ |
5 | |
6 | Every Headquarter or Warehouse on the Map is of this type. |
7 | */ |
8 | + |
9 | const char LuaWarehouse::className[] = "Warehouse"; |
10 | const MethodType<LuaWarehouse> LuaWarehouse::Methods[] = { |
11 | METHOD(LuaWarehouse, set_wares), |
12 | @@ -3879,6 +3880,8 @@ |
13 | METHOD(LuaWarehouse, get_workers), |
14 | METHOD(LuaWarehouse, set_soldiers), |
15 | METHOD(LuaWarehouse, get_soldiers), |
16 | + METHOD(LuaWarehouse, set_warehouse_policies), |
17 | + METHOD(LuaWarehouse, get_warehouse_policies), |
18 | METHOD(LuaWarehouse, start_expedition), |
19 | METHOD(LuaWarehouse, cancel_expedition), |
20 | {nullptr, nullptr}, |
21 | @@ -3974,7 +3977,233 @@ |
22 | WH_GET(ware, Ware) |
23 | // documented in parent class |
24 | WH_GET(worker, Worker) |
25 | -#undef GET |
26 | +#undef WH_GET |
27 | + |
28 | +// Transforms the given warehouse policy to a string which is used by the lua code |
29 | +inline void wh_policy_to_string(lua_State* L, Warehouse::StockPolicy p) { |
30 | + switch (p) { |
31 | + case Warehouse::StockPolicy::kNormal: |
32 | + lua_pushstring(L, "normal"); |
33 | + break; |
34 | + case Warehouse::StockPolicy::kPrefer: |
35 | + lua_pushstring(L, "prefer"); |
36 | + break; |
37 | + case Warehouse::StockPolicy::kDontStock: |
38 | + lua_pushstring(L, "dontstock"); |
39 | + break; |
40 | + case Warehouse::StockPolicy::kRemove: |
41 | + lua_pushstring(L, "remove"); |
42 | + break; |
43 | + } |
44 | +} |
45 | + |
46 | +// Transforms the given string from the lua code to a warehouse policy |
47 | +inline Warehouse::StockPolicy string_to_wh_policy(lua_State* L, uint32_t index) { |
48 | + std::string str = luaL_checkstring(L, index); |
49 | + if (str == "normal") |
50 | + return Warehouse::StockPolicy::kNormal; |
51 | + else if (str == "prefer") |
52 | + return Warehouse::StockPolicy::kPrefer; |
53 | + else if (str == "dontstock") |
54 | + return Warehouse::StockPolicy::kDontStock; |
55 | + else if (str == "remove") |
56 | + return Warehouse::StockPolicy::kRemove; |
57 | + else |
58 | + report_error(L, "<%s> is no valid warehouse policy!", str.c_str()); |
59 | +} |
60 | + |
61 | +bool do_set_ware_policy(Warehouse* wh, const DescriptionIndex idx, const Warehouse::StockPolicy p) { |
62 | + wh->set_ware_policy(idx, p); |
63 | + return true; |
64 | +} |
65 | + |
66 | +/** |
67 | + * Sets the given policy for the given ware in the given warehouse and return true. |
68 | + * If the no ware with the given name exists for the tribe of the warehouse, return false. |
69 | + */ |
70 | +bool do_set_ware_policy(Warehouse* wh, const std::string& name, const Warehouse::StockPolicy p) { |
71 | + const TribeDescr& tribe = wh->owner().tribe(); |
72 | + DescriptionIndex idx = tribe.ware_index(name); |
73 | + if (!tribe.has_ware(idx)) { |
74 | + return false; |
75 | + } |
76 | + return do_set_ware_policy(wh, idx, p); |
77 | +} |
78 | + |
79 | +bool do_set_worker_policy(Warehouse* wh, |
80 | + const DescriptionIndex idx, |
81 | + const Warehouse::StockPolicy p) { |
82 | + const TribeDescr& tribe = wh->owner().tribe(); |
83 | + // If the worker does not cost anything, ignore it |
84 | + // Otherwise, an unlimited stream of carriers might leave the warehouse |
85 | + if (tribe.get_worker_descr(idx)->is_buildable() && |
86 | + tribe.get_worker_descr(idx)->buildcost().empty()) { |
87 | + return true; |
88 | + } |
89 | + wh->set_worker_policy(idx, p); |
90 | + return true; |
91 | +} |
92 | + |
93 | +/** |
94 | + * Sets the given policy for the given worker in the given warehouse and returns true. |
95 | + * Also returns true if the given worker does not cost anything but in this case does not set its policy. |
96 | + * If no worker with the given name exists for the tribe of the warehouse, return false. |
97 | + */ |
98 | +bool do_set_worker_policy(Warehouse* wh, const std::string& name, const Warehouse::StockPolicy p) { |
99 | + const TribeDescr& tribe = wh->owner().tribe(); |
100 | + DescriptionIndex idx = tribe.worker_index(name); |
101 | + if (!tribe.has_worker(idx)) { |
102 | + return false; |
103 | + } |
104 | + return do_set_worker_policy(wh, idx, p); |
105 | +} |
106 | + |
107 | +/* RST |
108 | + .. method:: set_warehouse_policies(which, policy) |
109 | + |
110 | + Sets the policies how the warehouse should handle the given wares and workers. |
111 | + |
112 | + Usage example: |
113 | + .. code-block:: lua |
114 | + |
115 | + wh:set_warehouse_policies("coal", "prefer") |
116 | + |
117 | + :arg which: behaves like for :meth:`HasWares.get_wares`. |
118 | + |
119 | + :arg policy: the policy to apply for all the wares and workers given in `which`. |
120 | + :type policy: a string out of "normal", "prefer", "dontstock", "remove". |
121 | +*/ |
122 | +int LuaWarehouse::set_warehouse_policies(lua_State* L) { |
123 | + int32_t nargs = lua_gettop(L); |
124 | + if (nargs != 3) |
125 | + report_error(L, "Wrong number of arguments to set_warehouse_policies!"); |
126 | + |
127 | + Warehouse* wh = get(L, get_egbase(L)); |
128 | + Warehouse::StockPolicy p = string_to_wh_policy(L, -1); |
129 | + lua_pop(L, 1); |
130 | + const TribeDescr& tribe = wh->owner().tribe(); |
131 | + |
132 | + // takes either "all", a name or an array of names |
133 | + if (lua_isstring(L, 2)) { |
134 | + const std::string& what = luaL_checkstring(L, -1); |
135 | + if (what == "all") { |
136 | + for (const DescriptionIndex& i : tribe.wares()) { |
137 | + do_set_ware_policy(wh, i, p); |
138 | + } |
139 | + for (const DescriptionIndex& i : tribe.workers()) { |
140 | + do_set_worker_policy(wh, i, p); |
141 | + } |
142 | + } else { |
143 | + // Only one item requested |
144 | + if (!do_set_ware_policy(wh, what, p) && !do_set_worker_policy(wh, what, p)) { |
145 | + // Unknown whatever, abort |
146 | + report_error(L, "Unknown name: <%s>", what.c_str()); |
147 | + } |
148 | + } |
149 | + } else { |
150 | + // array of names |
151 | + luaL_checktype(L, 2, LUA_TTABLE); |
152 | + lua_pushnil(L); |
153 | + while (lua_next(L, 2) != 0) { |
154 | + const std::string& what = luaL_checkstring(L, -1); |
155 | + if (!do_set_ware_policy(wh, what, p) && !do_set_worker_policy(wh, what, p)) { |
156 | + // Note that this will change the policy for entries earlier in the list |
157 | + // but when the user provides broken data its his own fault |
158 | + report_error(L, "Unknown name: <%s>", what.c_str()); |
159 | + } |
160 | + lua_pop(L, 1); |
161 | + } |
162 | + } |
163 | + |
164 | + return 0; |
165 | +} |
166 | + |
167 | +// Gets the warehouse policy by ware/worker-name or id |
168 | +#define WH_GET_POLICY(type) \ |
169 | + void do_get_##type##_policy(lua_State* L, Warehouse* wh, const DescriptionIndex idx) { \ |
170 | + wh_policy_to_string(L, wh->get_##type##_policy(idx)); \ |
171 | + } \ |
172 | + \ |
173 | + bool do_get_##type##_policy(lua_State* L, Warehouse* wh, const std::string& name) { \ |
174 | + const TribeDescr& tribe = wh->owner().tribe(); \ |
175 | + DescriptionIndex idx = tribe.type##_index(name); \ |
176 | + if (!tribe.has_##type(idx)) { \ |
177 | + return false; \ |
178 | + } \ |
179 | + do_get_##type##_policy(L, wh, idx); \ |
180 | + return true; \ |
181 | + } |
182 | + |
183 | +WH_GET_POLICY(ware) |
184 | +WH_GET_POLICY(worker) |
185 | +#undef WH_GET_POLICY |
186 | + |
187 | +/* RST |
188 | + .. method:: get_warehouse_policies(which) |
189 | + |
190 | + Gets the policies how the warehouse should handle the given wares and workers. |
191 | + The method to handle is one of the strings "normal", "prefer", "dontstock", "remove". |
192 | + |
193 | + Usage example: |
194 | + .. code-block:: lua |
195 | + |
196 | + wh:get_warehouse_policies({"ax", "coal"}) |
197 | + -- Returns a table like {ax="normal", coal="prefer"} |
198 | + |
199 | + :arg which: behaves like for :meth:`HasWares.get_wares`. |
200 | + |
201 | + :returns: :class:`string` or :class:`table` |
202 | +*/ |
203 | +int LuaWarehouse::get_warehouse_policies(lua_State* L) { |
204 | + int32_t nargs = lua_gettop(L); |
205 | + if (nargs != 2) |
206 | + report_error(L, "Wrong number of arguments to get_warehouse_policies!"); |
207 | + Warehouse* wh = get(L, get_egbase(L)); |
208 | + const TribeDescr& tribe = wh->owner().tribe(); |
209 | + // takes either "all", a single name or an array of names |
210 | + if (lua_isstring(L, 2)) { |
211 | + std::string what = luaL_checkstring(L, -1); |
212 | + if (what == "all") { |
213 | + lua_newtable(L); |
214 | + for (const DescriptionIndex& i : tribe.wares()) { |
215 | + std::string name = tribe.get_ware_descr(i)->name(); |
216 | + lua_pushstring(L, name.c_str()); |
217 | + do_get_ware_policy(L, wh, i); |
218 | + lua_rawset(L, -3); |
219 | + } |
220 | + for (const DescriptionIndex& i : tribe.workers()) { |
221 | + std::string name = tribe.get_worker_descr(i)->name(); |
222 | + lua_pushstring(L, name.c_str()); |
223 | + do_get_worker_policy(L, wh, i); |
224 | + lua_rawset(L, -3); |
225 | + } |
226 | + } else { |
227 | + // Only one item requested |
228 | + if (!do_get_ware_policy(L, wh, what) && !do_get_worker_policy(L, wh, what)) { |
229 | + // Unknown whatever, abort |
230 | + report_error(L, "Unknown name: <%s>", what.c_str()); |
231 | + } |
232 | + } |
233 | + } else { |
234 | + // array of names |
235 | + luaL_checktype(L, 2, LUA_TTABLE); |
236 | + lua_newtable(L); |
237 | + lua_pushnil(L); |
238 | + while (lua_next(L, 2) != 0) { |
239 | + // Stack is: ... input_table new_table nil input_key input_value |
240 | + // input_value is the name of the ware or worker and will be added into the new table |
241 | + // input_key is an index and is dropped by the next call of lua_next() |
242 | + const std::string& what = luaL_checkstring(L, -1); |
243 | + if (!do_get_ware_policy(L, wh, what) && !do_get_worker_policy(L, wh, what)) { |
244 | + // Note that this will change the policy for entries earlier in the list |
245 | + // but when the user provides broken data its his own fault |
246 | + report_error(L, "Unknown name: <%s>", what.c_str()); |
247 | + } |
248 | + lua_rawset(L, -4); |
249 | + } |
250 | + } |
251 | + return 1; |
252 | +} |
253 | |
254 | // documented in parent class |
255 | int LuaWarehouse::get_soldiers(lua_State* L) { |
256 | |
257 | === modified file 'src/scripting/lua_map.h' |
258 | --- src/scripting/lua_map.h 2016-08-04 15:49:05 +0000 |
259 | +++ src/scripting/lua_map.h 2017-01-06 15:58:31 +0000 |
260 | @@ -1006,6 +1006,8 @@ |
261 | int get_workers(lua_State*); |
262 | int set_wares(lua_State*); |
263 | int set_workers(lua_State*); |
264 | + int get_warehouse_policies(lua_State*); |
265 | + int set_warehouse_policies(lua_State*); |
266 | int set_soldiers(lua_State*); |
267 | int get_soldiers(lua_State*); |
268 | int start_expedition(lua_State*); |
269 | |
270 | === modified file 'test/maps/lua_testsuite.wmf/scripting/warehouse.lua' |
271 | --- test/maps/lua_testsuite.wmf/scripting/warehouse.lua 2016-02-17 22:13:21 +0000 |
272 | +++ test/maps/lua_testsuite.wmf/scripting/warehouse.lua 2017-01-06 15:58:31 +0000 |
273 | @@ -125,6 +125,154 @@ |
274 | assert_equal(20, k.barbarians_lumberjack) |
275 | end |
276 | |
277 | +-- ======== |
278 | +-- Policies |
279 | +-- ======== |
280 | +function warehouse_tests:test_get_ware_policy() |
281 | + assert_equal(self.w:get_warehouse_policies("log"), "normal") |
282 | + k = self.w:get_warehouse_policies{"log", "granite"} |
283 | + assert_equal("normal", k.log) |
284 | + assert_equal("normal", k.granite) |
285 | + assert_equal(nil, k.coal) |
286 | + k = self.w:get_warehouse_policies("all") |
287 | + assert_equal("normal", k.log) |
288 | + assert_equal("normal", k.granite) |
289 | + assert_equal("normal", k.coal) |
290 | + assert_equal("normal", k.barbarians_lumberjack) |
291 | +end |
292 | + |
293 | +function warehouse_tests:test_get_worker_policy() |
294 | + assert_equal(self.w:get_warehouse_policies("barbarians_builder"), "normal") |
295 | + k = self.w:get_warehouse_policies{"barbarians_builder", "barbarians_lumberjack"} |
296 | + assert_equal("normal", k.barbarians_builder) |
297 | + assert_equal("normal", k.barbarians_lumberjack) |
298 | + assert_equal(nil, k.coal) |
299 | + k = self.w:get_warehouse_policies("all") |
300 | + assert_equal("normal", k.barbarians_builder) |
301 | + assert_equal("normal", k.barbarians_lumberjack) |
302 | + assert_equal("normal", k.coal) |
303 | +end |
304 | + |
305 | +function warehouse_tests:test_get_non_existing_policy() |
306 | + assert_error("ware policy for non existing ware", function() |
307 | + self.w:get_warehouse_policies("plastic") |
308 | + end) |
309 | + assert_error("worker policy for non existing worker", function() |
310 | + self.w:get_warehouse_policies("tree_climber") |
311 | + end) |
312 | +end |
313 | + |
314 | +function warehouse_tests:test_set_ware_policy() |
315 | + -- Make sure it is the normal policy until now |
316 | + assert_equal(self.w:get_warehouse_policies("log"), "normal") |
317 | + assert_equal(self.w:get_warehouse_policies("granite"), "normal") |
318 | + -- Set new policy for wares |
319 | + self.w:set_warehouse_policies("log", "prefer") |
320 | + assert_equal(self.w:get_warehouse_policies("log"), "prefer") |
321 | + assert_equal(self.w:get_warehouse_policies("granite"), "normal") |
322 | + self.w:set_warehouse_policies("log", "dontstock") |
323 | + assert_equal(self.w:get_warehouse_policies("log"), "dontstock") |
324 | + assert_equal(self.w:get_warehouse_policies("granite"), "normal") |
325 | + self.w:set_warehouse_policies("log", "remove") |
326 | + assert_equal(self.w:get_warehouse_policies("log"), "remove") |
327 | + assert_equal(self.w:get_warehouse_policies("granite"), "normal") |
328 | + self.w:set_warehouse_policies("granite", "dontstock") |
329 | + assert_equal(self.w:get_warehouse_policies("log"), "remove") |
330 | + assert_equal(self.w:get_warehouse_policies("granite"), "dontstock") |
331 | + self.w:set_warehouse_policies({"log", "granite"}, "prefer") |
332 | + assert_equal(self.w:get_warehouse_policies("log"), "prefer") |
333 | + assert_equal(self.w:get_warehouse_policies("granite"), "prefer") |
334 | + self.w:set_warehouse_policies("log", "normal") |
335 | + self.w:set_warehouse_policies("granite", "normal") |
336 | + assert_equal(self.w:get_warehouse_policies("log"), "normal") |
337 | + assert_equal(self.w:get_warehouse_policies("granite"), "normal") |
338 | + self.w:set_warehouse_policies("all", "prefer") |
339 | + assert_equal(self.w:get_warehouse_policies("log"), "prefer") |
340 | + assert_equal(self.w:get_warehouse_policies("granite"), "prefer") |
341 | + assert_equal(self.w:get_warehouse_policies("meat"), "prefer") |
342 | + assert_equal(self.w:get_warehouse_policies("coal"), "prefer") |
343 | +end |
344 | + |
345 | +function warehouse_tests:test_set_worker_policy() |
346 | + -- Make sure it is the normal policy until now |
347 | + assert_equal(self.w:get_warehouse_policies("barbarians_builder"), "normal") |
348 | + assert_equal(self.w:get_warehouse_policies("barbarians_lumberjack"), "normal") |
349 | + -- Set new policy for workers |
350 | + self.w:set_warehouse_policies("barbarians_builder", "prefer") |
351 | + assert_equal(self.w:get_warehouse_policies("barbarians_builder"), "prefer") |
352 | + assert_equal(self.w:get_warehouse_policies("barbarians_lumberjack"), "normal") |
353 | + self.w:set_warehouse_policies("barbarians_builder", "dontstock") |
354 | + assert_equal(self.w:get_warehouse_policies("barbarians_builder"), "dontstock") |
355 | + assert_equal(self.w:get_warehouse_policies("barbarians_lumberjack"), "normal") |
356 | + self.w:set_warehouse_policies({"barbarians_builder"}, "remove") |
357 | + assert_equal(self.w:get_warehouse_policies("barbarians_builder"), "remove") |
358 | + assert_equal(self.w:get_warehouse_policies("barbarians_lumberjack"), "normal") |
359 | + self.w:set_warehouse_policies("barbarians_lumberjack", "dontstock") |
360 | + assert_equal(self.w:get_warehouse_policies("barbarians_builder"), "remove") |
361 | + assert_equal(self.w:get_warehouse_policies("barbarians_lumberjack"), "dontstock") |
362 | + self.w:set_warehouse_policies({"barbarians_lumberjack", "barbarians_builder"}, "prefer") |
363 | + assert_equal(self.w:get_warehouse_policies("barbarians_builder"), "prefer") |
364 | + assert_equal(self.w:get_warehouse_policies("barbarians_lumberjack"), "prefer") |
365 | + self.w:set_warehouse_policies("barbarians_builder", "normal") |
366 | + self.w:set_warehouse_policies("barbarians_lumberjack", "normal") |
367 | + assert_equal(self.w:get_warehouse_policies("barbarians_builder"), "normal") |
368 | + assert_equal(self.w:get_warehouse_policies("barbarians_lumberjack"), "normal") |
369 | + self.w:set_warehouse_policies("all", "prefer") |
370 | + assert_equal(self.w:get_warehouse_policies("barbarians_builder"), "prefer") |
371 | + assert_equal(self.w:get_warehouse_policies("barbarians_lumberjack"), "prefer") |
372 | + assert_equal(self.w:get_warehouse_policies("barbarians_gardener"), "prefer") |
373 | +end |
374 | + |
375 | +function warehouse_tests:test_set_ware_and_worker_policy() |
376 | + -- Make sure it is the normal policy until now |
377 | + local ret = self.w:get_warehouse_policies({"log", "barbarians_builder", "barbarians_lumberjack"}) |
378 | + assert_equal("normal", ret.barbarians_builder) |
379 | + assert_equal("normal", ret.barbarians_lumberjack) |
380 | + assert_equal("normal", ret.log) |
381 | + assert_equal(nil, ret.granite) |
382 | + |
383 | + -- Set new policy for workers |
384 | + self.w:set_warehouse_policies({"log", "barbarians_builder"}, "remove") |
385 | + local ret = self.w:get_warehouse_policies({"log", "barbarians_builder", "barbarians_lumberjack"}) |
386 | + assert_equal("remove", ret.barbarians_builder) |
387 | + assert_equal("normal", ret.barbarians_lumberjack) |
388 | + assert_equal("remove", ret.log) |
389 | + |
390 | + self.w:set_warehouse_policies({"barbarians_builder"}, "prefer") |
391 | + local ret = self.w:get_warehouse_policies({"log", "barbarians_builder", "barbarians_lumberjack"}) |
392 | + assert_equal("prefer", ret.barbarians_builder) |
393 | + assert_equal("normal", ret.barbarians_lumberjack) |
394 | + assert_equal("remove", ret.log) |
395 | + |
396 | + self.w:set_warehouse_policies("log", "normal") |
397 | + ret = self.w:get_warehouse_policies({"log", "barbarians_builder", "barbarians_lumberjack"}) |
398 | + assert_equal("prefer", ret.barbarians_builder) |
399 | + assert_equal("normal", ret.barbarians_lumberjack) |
400 | + assert_equal("normal", ret.log) |
401 | + assert_equal(nil, ret.granite) |
402 | + |
403 | + ret = self.w:get_warehouse_policies("all") |
404 | + assert_equal("prefer", ret.barbarians_builder) |
405 | + assert_equal("normal", ret.barbarians_lumberjack) |
406 | + assert_equal("normal", ret.log) |
407 | + assert_equal("normal", ret.granite) |
408 | +end |
409 | + |
410 | + |
411 | +function warehouse_tests:test_set_non_existing_policy() |
412 | + assert_error("ware policy for non existing ware", function() |
413 | + self.w:set_warehouse_policies("plastic", "prefer") |
414 | + end) |
415 | + assert_error("invalid policy for ware", function() |
416 | + self.w:set_warehouse_policies("log", "burn") |
417 | + end) |
418 | + assert_error("worker policy for non existing worker", function() |
419 | + self.w:set_warehouse_policies("tree_climber", "prefer") |
420 | + end) |
421 | + assert_error("invalid policy for worker", function() |
422 | + self.w:set_warehouse_policies("barbarians_builder", "burn") |
423 | + end) |
424 | +end |
425 | |
426 | -- ========= |
427 | -- Soldiers |
428 | |
429 | === added file 'test/maps/ship_transportation.wmf/scripting/test_create_request_while_worker_with_ware_is_in_transit.lua' |
430 | --- test/maps/ship_transportation.wmf/scripting/test_create_request_while_worker_with_ware_is_in_transit.lua 1970-01-01 00:00:00 +0000 |
431 | +++ test/maps/ship_transportation.wmf/scripting/test_create_request_while_worker_with_ware_is_in_transit.lua 2017-01-06 15:58:31 +0000 |
432 | @@ -0,0 +1,67 @@ |
433 | +run(function() |
434 | + sleep(100) |
435 | + |
436 | + game.desired_speed = 50 * 1000 |
437 | + |
438 | + create_southern_port() |
439 | + create_northern_port() |
440 | + |
441 | + -- create a ready-to-work lumberjack connected to the northern port |
442 | + local lumberjack_hut = p1:place_building("barbarians_lumberjacks_hut", map:get_field(18, 4), false, true) |
443 | + if lumberjack_hut.valid_workers then lumberjack_hut:set_workers(lumberjack_hut.valid_workers) end |
444 | + connected_road(p1, map:get_field(18,5).immovable, "l,l|tl,tr|", true) |
445 | + |
446 | + -- a long street to capture the woodcutter when his house is burned |
447 | + connected_road(p1, map:get_field(18,5).immovable, "r,r|r,r|r,tr|tr,tl|l,l|l,l|l,l|", true) |
448 | + |
449 | + -- plant a tree inside the street to the right of the lumberjack hut |
450 | + |
451 | + assert_equal(nil, map:get_field(23,3).immovable) |
452 | + map:place_immovable("oak_summer_old", map:get_field(23,3), "world") |
453 | + assert_not_equal(nil, map:get_field(23,3).immovable) |
454 | + |
455 | + -- set logs and woodcutters to "remove from here" in the port |
456 | + np = northern_port() |
457 | + np:set_warehouse_policies({"log", "barbarians_lumberjack"}, "remove") |
458 | + |
459 | + -- aaand action! |
460 | + |
461 | + -- sleep until the tree has been felled |
462 | + while (map:get_field(23,3).immovable.descr:has_attribute("tree")) do |
463 | + sleep(100) |
464 | + end |
465 | + -- some more sleep since "removal of tree" and "worker has log" are not at the same time |
466 | + sleep(1000) |
467 | + -- now the worker should have the tree |
468 | + |
469 | + |
470 | + lumberjack_hut:destroy() |
471 | + -- worker will find street and enter port, can't stay there, enters ship |
472 | + while not (ship:get_workers() == 1) do |
473 | + sleep(100) |
474 | + end |
475 | + assert_equal(1, ship:get_workers()) |
476 | + -- no wares since the worker is still carrying the log |
477 | + assert_equal(0, ship:get_wares()) |
478 | + |
479 | + -- start to build a lumberjack on the second port while the required log is still in transit |
480 | + local cons = p1:place_building("barbarians_lumberjacks_hut", map:get_field(17, 17), true, true) |
481 | + connected_road(p1, map:get_field(18,18).immovable, "l,tl|", true) |
482 | + |
483 | + -- give the log time to reach the building site |
484 | + while not (ship:get_workers() == 0) do |
485 | + sleep(100) |
486 | + end |
487 | + sleep(3000) |
488 | + |
489 | + cons:destroy() |
490 | + |
491 | + sleep(6000) |
492 | + -- check if both lumberjack and log come to rest in the port |
493 | + -- if it is possible to check for the log in the building site that would be an alternative |
494 | + assert_equal(1, southern_port():get_wares("log")) |
495 | + assert_equal(1, southern_port():get_workers("barbarians_lumberjack")) |
496 | + |
497 | + print("# All Tests passed.") |
498 | + wl.ui.MapView():close() |
499 | +end) |
Continuous integration builds have changed state:
Travis build 1699. State: failed. Details: https:/ /travis- ci.org/ widelands/ widelands/ builds/ 181039459. /ci.appveyor. com/project/ widelands- dev/widelands/ build/_ widelands_ dev_widelands_ feature_ test_supply_ crash-1539.
Appveyor build 1539. State: success. Details: https:/