Merge lp:~widelands-dev/widelands/bug-1678598-expedition-no-eco-crash into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 8343
Proposed branch: lp:~widelands-dev/widelands/bug-1678598-expedition-no-eco-crash
Merge into: lp:widelands
Diff against target: 839 lines (+120/-52)
42 files modified
src/ai/defaultai_seafaring.cc (+10/-0)
src/economy/flag.cc (+2/-1)
src/economy/flag.h (+1/-1)
src/economy/fleet.cc (+10/-3)
src/economy/fleet.h (+2/-1)
src/economy/portdock.cc (+2/-1)
src/economy/portdock.h (+1/-1)
src/economy/road.cc (+2/-1)
src/economy/road.h (+1/-1)
src/economy/ware_instance.cc (+2/-2)
src/economy/ware_instance.h (+1/-1)
src/logic/map_objects/bob.cc (+2/-1)
src/logic/map_objects/bob.h (+1/-1)
src/logic/map_objects/immovable.cc (+4/-3)
src/logic/map_objects/immovable.h (+2/-2)
src/logic/map_objects/map_object.cc (+2/-1)
src/logic/map_objects/map_object.h (+1/-1)
src/logic/map_objects/tribes/battle.cc (+2/-1)
src/logic/map_objects/tribes/battle.h (+1/-1)
src/logic/map_objects/tribes/building.cc (+2/-1)
src/logic/map_objects/tribes/building.h (+1/-1)
src/logic/map_objects/tribes/constructionsite.cc (+2/-1)
src/logic/map_objects/tribes/constructionsite.h (+1/-1)
src/logic/map_objects/tribes/dismantlesite.cc (+2/-1)
src/logic/map_objects/tribes/dismantlesite.h (+1/-1)
src/logic/map_objects/tribes/militarysite.cc (+2/-1)
src/logic/map_objects/tribes/militarysite.h (+1/-1)
src/logic/map_objects/tribes/partially_finished_building.cc (+2/-1)
src/logic/map_objects/tribes/partially_finished_building.h (+1/-1)
src/logic/map_objects/tribes/productionsite.cc (+2/-1)
src/logic/map_objects/tribes/productionsite.h (+1/-1)
src/logic/map_objects/tribes/ship.cc (+23/-4)
src/logic/map_objects/tribes/ship.h (+3/-3)
src/logic/map_objects/tribes/soldier.cc (+2/-2)
src/logic/map_objects/tribes/soldier.h (+1/-1)
src/logic/map_objects/tribes/trainingsite.cc (+2/-1)
src/logic/map_objects/tribes/trainingsite.h (+1/-1)
src/logic/map_objects/tribes/warehouse.cc (+2/-1)
src/logic/map_objects/tribes/warehouse.h (+1/-1)
src/logic/map_objects/tribes/worker.cc (+2/-1)
src/logic/map_objects/tribes/worker.h (+1/-1)
src/wui/shipwindow.cc (+15/-0)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1678598-expedition-no-eco-crash
Reviewer Review Type Date Requested Status
Klaus Halfmann code revie, compile, test Approve
Review via email: mp+323004@code.launchpad.net

Commit message

Only cancel expedition if there is a reachable portdock.
- Reset the expedition state to "Waiting" if no portdock could be found
- Show a warning message to owner
- AI will continue exploring

- Added a boolean success semantics to MapObject::init() to achieve this.

To post a comment you must log in.
Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

1st Code Review

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

Original Nile crash now shows:

5: Azurea Sea at 101x100: END OF EXPEDITION without port, continue exploring
  5: last command for ship Azurea Sea at 102x102 was 41518 seconds ago, something wrong here?...
5: Azurea Sea at 102x102: explore uphold, visited first time
5: Azurea Sea: continue island circumvention, dir=1

and the game doe not crash .... ok.

Tried the game attached to 1678598 in trunk -> crashes when canceling the expedition
without harbours, expected.

Tried the same in this brach, got the expected message.

-> Fine for me

will try to finish that nile szenario now, using that branch.

review: Approve (code revie, compile, test)
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2114. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/224895585.
Appveyor build 1949. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1678598_expedition_no_eco_crash-1949.

Revision history for this message
GunChleoc (gunchleoc) wrote :

You can ignore the something wrong here? bit. I am only resetting the expedition status, not giving any new commands to the Ai ship. So, the ship will be waiting until the AI issues the next round of commands.

Revision history for this message
GunChleoc (gunchleoc) wrote :

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ai/defaultai_seafaring.cc'
2--- src/ai/defaultai_seafaring.cc 2017-01-28 14:53:28 +0000
3+++ src/ai/defaultai_seafaring.cc 2017-04-23 12:22:45 +0000
4@@ -19,6 +19,8 @@
5
6 #include "ai/defaultai.h"
7
8+#include "economy/fleet.h"
9+
10 using namespace Widelands;
11
12 // this scores spot for potential colony
13@@ -358,6 +360,14 @@
14 log("%d: %s at %3dx%3d: END OF EXPEDITION due to time-out\n", pn,
15 so.ship->get_shipname().c_str(), so.ship->get_position().x, so.ship->get_position().y);
16
17+ // In case there is no port left to get back to, continue exploring
18+ if (!so.ship->get_fleet() || !so.ship->get_fleet()->has_ports()) {
19+ log("%d: %s at %3dx%3d: END OF EXPEDITION without port, continue exploring\n", pn,
20+ so.ship->get_shipname().c_str(), so.ship->get_position().x, so.ship->get_position().y);
21+ persistent_data->expedition_start_time = gametime;
22+ return;
23+ }
24+
25 // For known and running expedition
26 } else {
27 // set persistent_data->colony_scan_area based on elapsed expedition time
28
29=== modified file 'src/economy/flag.cc'
30--- src/economy/flag.cc 2017-01-25 18:55:59 +0000
31+++ src/economy/flag.cc 2017-04-23 12:22:45 +0000
32@@ -652,12 +652,13 @@
33 always_call_for_flag_ = nullptr;
34 }
35
36-void Flag::init(EditorGameBase& egbase) {
37+bool Flag::init(EditorGameBase& egbase) {
38 PlayerImmovable::init(egbase);
39
40 set_position(egbase, position_);
41
42 animstart_ = egbase.get_gametime();
43+ return true;
44 }
45
46 /**
47
48=== modified file 'src/economy/flag.h'
49--- src/economy/flag.h 2017-01-25 18:55:59 +0000
50+++ src/economy/flag.h 2017-04-23 12:22:45 +0000
51@@ -142,7 +142,7 @@
52 void log_general_info(const EditorGameBase&) override;
53
54 protected:
55- void init(EditorGameBase&) override;
56+ bool init(EditorGameBase&) override;
57 void cleanup(EditorGameBase&) override;
58
59 void draw(uint32_t gametime,
60
61=== modified file 'src/economy/fleet.cc'
62--- src/economy/fleet.cc 2017-01-25 18:55:59 +0000
63+++ src/economy/fleet.cc 2017-04-23 12:22:45 +0000
64@@ -93,19 +93,22 @@
65 * Initialize the fleet, including a search through the map
66 * to rejoin with the next other fleet we can find.
67 */
68-void Fleet::init(EditorGameBase& egbase) {
69+bool Fleet::init(EditorGameBase& egbase) {
70 MapObject::init(egbase);
71
72 if (ships_.empty() && ports_.empty()) {
73 molog("Empty fleet initialized; disband immediately\n");
74 remove(egbase);
75- return;
76+ return false;
77 }
78
79 find_other_fleet(egbase);
80
81- if (active())
82+ if (active()) {
83 update(egbase);
84+ return true;
85+ }
86+ return false;
87 }
88
89 struct StepEvalFindFleet {
90@@ -564,6 +567,10 @@
91 }
92 }
93
94+bool Fleet::has_ports() {
95+ return !ports_.empty();
96+}
97+
98 /**
99 * Search among the docks of the fleet for the one that has the given flag as its base.
100 *
101
102=== modified file 'src/economy/fleet.h'
103--- src/economy/fleet.h 2017-01-25 18:55:59 +0000
104+++ src/economy/fleet.h 2017-04-23 12:22:45 +0000
105@@ -91,7 +91,7 @@
106
107 bool active() const;
108
109- void init(EditorGameBase&) override;
110+ bool init(EditorGameBase&) override;
111 void cleanup(EditorGameBase&) override;
112 void update(EditorGameBase&);
113
114@@ -99,6 +99,7 @@
115 void remove_ship(EditorGameBase& egbase, Ship* ship);
116 void add_port(EditorGameBase& egbase, PortDock* port);
117 void remove_port(EditorGameBase& egbase, PortDock* port);
118+ bool has_ports();
119
120 void log_general_info(const EditorGameBase&) override;
121
122
123=== modified file 'src/economy/portdock.cc'
124--- src/economy/portdock.cc 2017-02-22 20:23:49 +0000
125+++ src/economy/portdock.cc 2017-04-23 12:22:45 +0000
126@@ -144,7 +144,7 @@
127 // do nothing
128 }
129
130-void PortDock::init(EditorGameBase& egbase) {
131+bool PortDock::init(EditorGameBase& egbase) {
132 PlayerImmovable::init(egbase);
133
134 for (const Coords& coords : dockpoints_) {
135@@ -152,6 +152,7 @@
136 }
137
138 init_fleet(egbase);
139+ return true;
140 }
141
142 /**
143
144=== modified file 'src/economy/portdock.h'
145--- src/economy/portdock.h 2017-01-25 18:55:59 +0000
146+++ src/economy/portdock.h 2017-04-23 12:22:45 +0000
147@@ -102,7 +102,7 @@
148 float scale,
149 RenderTarget* dst) override;
150
151- void init(EditorGameBase&) override;
152+ bool init(EditorGameBase&) override;
153 void cleanup(EditorGameBase&) override;
154
155 void add_neighbours(std::vector<RoutingNodeNeighbour>& neighbours);
156
157=== modified file 'src/economy/road.cc'
158--- src/economy/road.cc 2017-01-25 18:55:59 +0000
159+++ src/economy/road.cc 2017-04-23 12:22:45 +0000
160@@ -222,11 +222,12 @@
161 /**
162 * Initialize the road.
163 */
164-void Road::init(EditorGameBase& egbase) {
165+bool Road::init(EditorGameBase& egbase) {
166 PlayerImmovable::init(egbase);
167
168 if (2 <= path_.get_nsteps())
169 link_into_flags(egbase);
170+ return true;
171 }
172
173 /**
174
175=== modified file 'src/economy/road.h'
176--- src/economy/road.h 2017-01-25 18:55:59 +0000
177+++ src/economy/road.h 2017-04-23 12:22:45 +0000
178@@ -115,7 +115,7 @@
179 void log_general_info(const EditorGameBase&) override;
180
181 protected:
182- void init(EditorGameBase&) override;
183+ bool init(EditorGameBase&) override;
184 void cleanup(EditorGameBase&) override;
185
186 void draw(uint32_t gametime,
187
188=== modified file 'src/economy/ware_instance.cc'
189--- src/economy/ware_instance.cc 2017-01-25 18:55:59 +0000
190+++ src/economy/ware_instance.cc 2017-04-23 12:22:45 +0000
191@@ -192,8 +192,8 @@
192 }
193 }
194
195-void WareInstance::init(EditorGameBase& egbase) {
196- MapObject::init(egbase);
197+bool WareInstance::init(EditorGameBase& egbase) {
198+ return MapObject::init(egbase);
199 }
200
201 void WareInstance::cleanup(EditorGameBase& egbase) {
202
203=== modified file 'src/economy/ware_instance.h'
204--- src/economy/ware_instance.h 2017-01-25 18:55:59 +0000
205+++ src/economy/ware_instance.h 2017-04-23 12:22:45 +0000
206@@ -72,7 +72,7 @@
207 return descr_index_;
208 }
209
210- void init(EditorGameBase&) override;
211+ bool init(EditorGameBase&) override;
212 void cleanup(EditorGameBase&) override;
213 void act(Game&, uint32_t data) override;
214 void update(Game&);
215
216=== modified file 'src/logic/map_objects/bob.cc'
217--- src/logic/map_objects/bob.cc 2017-02-25 20:03:40 +0000
218+++ src/logic/map_objects/bob.cc 2017-04-23 12:22:45 +0000
219@@ -118,7 +118,7 @@
220 *
221 * \note Make sure you call this from derived classes!
222 */
223-void Bob::init(EditorGameBase& egbase) {
224+bool Bob::init(EditorGameBase& egbase) {
225 MapObject::init(egbase);
226
227 if (upcast(Game, game, &egbase))
228@@ -126,6 +126,7 @@
229 else
230 // In editor: play idle task forever
231 set_animation(egbase, descr().get_animation("idle"));
232+ return true;
233 }
234
235 /**
236
237=== modified file 'src/logic/map_objects/bob.h'
238--- src/logic/map_objects/bob.h 2017-01-25 18:55:59 +0000
239+++ src/logic/map_objects/bob.h 2017-04-23 12:22:45 +0000
240@@ -235,7 +235,7 @@
241 return animstart_;
242 }
243
244- void init(EditorGameBase&) override;
245+ bool init(EditorGameBase&) override;
246 void cleanup(EditorGameBase&) override;
247 void act(Game&, uint32_t data) override;
248 void schedule_destroy(Game&);
249
250=== modified file 'src/logic/map_objects/immovable.cc'
251--- src/logic/map_objects/immovable.cc 2017-03-02 12:21:57 +0000
252+++ src/logic/map_objects/immovable.cc 2017-04-23 12:22:45 +0000
253@@ -395,7 +395,7 @@
254 /**
255 * Actually initialize the immovable.
256 */
257-void Immovable::init(EditorGameBase& egbase) {
258+bool Immovable::init(EditorGameBase& egbase) {
259 BaseImmovable::init(egbase);
260
261 set_position(egbase, position_);
262@@ -412,6 +412,7 @@
263 if (upcast(Game, game, &egbase)) {
264 switch_program(*game, "program");
265 }
266+ return true;
267 }
268
269 /**
270@@ -1289,8 +1290,8 @@
271 /**
272 * Initialize the immovable.
273 */
274-void PlayerImmovable::init(EditorGameBase& egbase) {
275- BaseImmovable::init(egbase);
276+bool PlayerImmovable::init(EditorGameBase& egbase) {
277+ return BaseImmovable::init(egbase);
278 }
279
280 /**
281
282=== modified file 'src/logic/map_objects/immovable.h'
283--- src/logic/map_objects/immovable.h 2017-01-25 18:55:59 +0000
284+++ src/logic/map_objects/immovable.h 2017-04-23 12:22:45 +0000
285@@ -224,7 +224,7 @@
286 increment_program_pointer();
287 }
288
289- void init(EditorGameBase&) override;
290+ bool init(EditorGameBase&) override;
291 void cleanup(EditorGameBase&) override;
292 void act(Game&, uint32_t data) override;
293 void draw(uint32_t gametime,
294@@ -383,7 +383,7 @@
295 void set_owner(Player*) override;
296
297 protected:
298- void init(EditorGameBase&) override;
299+ bool init(EditorGameBase&) override;
300 void cleanup(EditorGameBase&) override;
301
302 private:
303
304=== modified file 'src/logic/map_objects/map_object.cc'
305--- src/logic/map_objects/map_object.cc 2017-02-23 19:38:51 +0000
306+++ src/logic/map_objects/map_object.cc 2017-04-23 12:22:45 +0000
307@@ -439,8 +439,9 @@
308 *
309 * \warning Make sure you call this from derived classes!
310 */
311-void MapObject::init(EditorGameBase& egbase) {
312+bool MapObject::init(EditorGameBase& egbase) {
313 egbase.objects().insert(this);
314+ return true;
315 }
316
317 /**
318
319=== modified file 'src/logic/map_objects/map_object.h'
320--- src/logic/map_objects/map_object.h 2017-01-25 18:55:59 +0000
321+++ src/logic/map_objects/map_object.h 2017-04-23 12:22:45 +0000
322@@ -401,7 +401,7 @@
323 /// Called only when the oject is logically created in the simulation. If
324 /// called again, such as when the object is loaded from a savegame, it will
325 /// cause bugs.
326- virtual void init(EditorGameBase&);
327+ virtual bool init(EditorGameBase&);
328
329 virtual void cleanup(EditorGameBase&);
330
331
332=== modified file 'src/logic/map_objects/tribes/battle.cc'
333--- src/logic/map_objects/tribes/battle.cc 2017-01-25 18:55:59 +0000
334+++ src/logic/map_objects/tribes/battle.cc 2017-04-23 12:22:45 +0000
335@@ -74,7 +74,7 @@
336 init(game);
337 }
338
339-void Battle::init(EditorGameBase& egbase) {
340+bool Battle::init(EditorGameBase& egbase) {
341 MapObject::init(egbase);
342
343 creationtime_ = egbase.get_gametime();
344@@ -89,6 +89,7 @@
345 battle->cancel(game, *second_);
346 }
347 second_->set_battle(game, this);
348+ return true;
349 }
350
351 void Battle::cleanup(EditorGameBase& egbase) {
352
353=== modified file 'src/logic/map_objects/tribes/battle.h'
354--- src/logic/map_objects/tribes/battle.h 2017-01-25 18:55:59 +0000
355+++ src/logic/map_objects/tribes/battle.h 2017-04-23 12:22:45 +0000
356@@ -52,7 +52,7 @@
357 Battle(Game&, Soldier&, Soldier&); // to create a new battle in the game
358
359 // Implements MapObject.
360- void init(EditorGameBase&) override;
361+ bool init(EditorGameBase&) override;
362 void cleanup(EditorGameBase&) override;
363 bool has_new_save_support() override {
364 return true;
365
366=== modified file 'src/logic/map_objects/tribes/building.cc'
367--- src/logic/map_objects/tribes/building.cc 2017-03-02 12:21:57 +0000
368+++ src/logic/map_objects/tribes/building.cc 2017-04-23 12:22:45 +0000
369@@ -313,7 +313,7 @@
370 derived class' init.
371 ===============
372 */
373-void Building::init(EditorGameBase& egbase) {
374+bool Building::init(EditorGameBase& egbase) {
375 PlayerImmovable::init(egbase);
376
377 // Set the building onto the map
378@@ -351,6 +351,7 @@
379 start_animation(egbase, descr().get_animation("idle"));
380
381 leave_time_ = egbase.get_gametime();
382+ return true;
383 }
384
385 void Building::cleanup(EditorGameBase& egbase) {
386
387=== modified file 'src/logic/map_objects/tribes/building.h'
388--- src/logic/map_objects/tribes/building.h 2017-02-14 21:49:40 +0000
389+++ src/logic/map_objects/tribes/building.h 2017-04-23 12:22:45 +0000
390@@ -311,7 +311,7 @@
391
392 void start_animation(EditorGameBase&, uint32_t anim);
393
394- void init(EditorGameBase&) override;
395+ bool init(EditorGameBase&) override;
396 void cleanup(EditorGameBase&) override;
397 void act(Game&, uint32_t data) override;
398
399
400=== modified file 'src/logic/map_objects/tribes/constructionsite.cc'
401--- src/logic/map_objects/tribes/constructionsite.cc 2017-03-02 12:21:57 +0000
402+++ src/logic/map_objects/tribes/constructionsite.cc 2017-04-23 12:22:45 +0000
403@@ -110,7 +110,7 @@
404 Initialize the construction site by starting orders
405 ===============
406 */
407-void ConstructionSite::init(EditorGameBase& egbase) {
408+bool ConstructionSite::init(EditorGameBase& egbase) {
409 PartiallyFinishedBuilding::init(egbase);
410
411 const std::map<DescriptionIndex, uint8_t>* buildcost;
412@@ -139,6 +139,7 @@
413
414 work_steps_ += it->second;
415 }
416+ return true;
417 }
418
419 /*
420
421=== modified file 'src/logic/map_objects/tribes/constructionsite.h'
422--- src/logic/map_objects/tribes/constructionsite.h 2017-02-10 15:41:31 +0000
423+++ src/logic/map_objects/tribes/constructionsite.h 2017-04-23 12:22:45 +0000
424@@ -96,7 +96,7 @@
425 return *building_;
426 }
427
428- void init(EditorGameBase&) override;
429+ bool init(EditorGameBase&) override;
430 void cleanup(EditorGameBase&) override;
431
432 bool burn_on_destroy() override;
433
434=== modified file 'src/logic/map_objects/tribes/dismantlesite.cc'
435--- src/logic/map_objects/tribes/dismantlesite.cc 2017-02-28 12:59:39 +0000
436+++ src/logic/map_objects/tribes/dismantlesite.cc 2017-04-23 12:22:45 +0000
437@@ -106,7 +106,7 @@
438 Initialize the construction site by starting orders
439 ===============
440 */
441-void DismantleSite::init(EditorGameBase& egbase) {
442+bool DismantleSite::init(EditorGameBase& egbase) {
443 PartiallyFinishedBuilding::init(egbase);
444
445 for (const auto& ware : count_returned_wares(this)) {
446@@ -115,6 +115,7 @@
447 wares_.push_back(wq);
448 work_steps_ += ware.second;
449 }
450+ return true;
451 }
452
453 /*
454
455=== modified file 'src/logic/map_objects/tribes/dismantlesite.h'
456--- src/logic/map_objects/tribes/dismantlesite.h 2017-02-10 15:41:31 +0000
457+++ src/logic/map_objects/tribes/dismantlesite.h 2017-04-23 12:22:45 +0000
458@@ -74,7 +74,7 @@
459 Building::FormerBuildings& former_buildings);
460
461 bool burn_on_destroy() override;
462- void init(EditorGameBase&) override;
463+ bool init(EditorGameBase&) override;
464
465 bool get_building_work(Game&, Worker&, bool success) override;
466
467
468=== modified file 'src/logic/map_objects/tribes/militarysite.cc'
469--- src/logic/map_objects/tribes/militarysite.cc 2017-01-25 18:55:59 +0000
470+++ src/logic/map_objects/tribes/militarysite.cc 2017-04-23 12:22:45 +0000
471@@ -148,7 +148,7 @@
472 .str();
473 }
474
475-void MilitarySite::init(EditorGameBase& egbase) {
476+bool MilitarySite::init(EditorGameBase& egbase) {
477 Building::init(egbase);
478
479 upcast(Game, game, &egbase);
480@@ -167,6 +167,7 @@
481 nexthealtime_ = egbase.get_gametime() + 1000;
482 if (game)
483 schedule_act(*game, 1000);
484+ return true;
485 }
486
487 /**
488
489=== modified file 'src/logic/map_objects/tribes/militarysite.h'
490--- src/logic/map_objects/tribes/militarysite.h 2017-02-10 15:41:31 +0000
491+++ src/logic/map_objects/tribes/militarysite.h 2017-04-23 12:22:45 +0000
492@@ -84,7 +84,7 @@
493 MilitarySite(const MilitarySiteDescr&);
494 virtual ~MilitarySite();
495
496- void init(EditorGameBase&) override;
497+ bool init(EditorGameBase&) override;
498 void cleanup(EditorGameBase&) override;
499 void act(Game&, uint32_t data) override;
500 void remove_worker(Worker&) override;
501
502=== modified file 'src/logic/map_objects/tribes/partially_finished_building.cc'
503--- src/logic/map_objects/tribes/partially_finished_building.cc 2017-02-28 12:59:39 +0000
504+++ src/logic/map_objects/tribes/partially_finished_building.cc 2017-04-23 12:22:45 +0000
505@@ -66,13 +66,14 @@
506 Building::cleanup(egbase);
507 }
508
509-void PartiallyFinishedBuilding::init(EditorGameBase& egbase) {
510+bool PartiallyFinishedBuilding::init(EditorGameBase& egbase) {
511 Building::init(egbase);
512
513 if (upcast(Game, game, &egbase))
514 request_builder(*game);
515
516 Notifications::publish(NoteSound("create_construction_site", position_, 255));
517+ return true;
518 }
519
520 /*
521
522=== modified file 'src/logic/map_objects/tribes/partially_finished_building.h'
523--- src/logic/map_objects/tribes/partially_finished_building.h 2017-01-25 18:55:59 +0000
524+++ src/logic/map_objects/tribes/partially_finished_building.h 2017-04-23 12:22:45 +0000
525@@ -47,7 +47,7 @@
526 uint32_t get_playercaps() const override;
527 const Image* representative_image() const override;
528 void cleanup(EditorGameBase&) override;
529- void init(EditorGameBase&) override;
530+ bool init(EditorGameBase&) override;
531 void set_economy(Economy*) override;
532
533 uint32_t get_nrwaresqueues() {
534
535=== modified file 'src/logic/map_objects/tribes/productionsite.cc'
536--- src/logic/map_objects/tribes/productionsite.cc 2017-02-22 20:23:49 +0000
537+++ src/logic/map_objects/tribes/productionsite.cc 2017-04-23 12:22:45 +0000
538@@ -411,7 +411,7 @@
539 /**
540 * Initialize the production site.
541 */
542-void ProductionSite::init(EditorGameBase& egbase) {
543+bool ProductionSite::init(EditorGameBase& egbase) {
544 Building::init(egbase);
545
546 const BillOfMaterials& input_wares = descr().input_wares();
547@@ -440,6 +440,7 @@
548
549 if (upcast(Game, game, &egbase))
550 try_start_working(*game);
551+ return true;
552 }
553
554 /**
555
556=== modified file 'src/logic/map_objects/tribes/productionsite.h'
557--- src/logic/map_objects/tribes/productionsite.h 2017-02-14 20:24:36 +0000
558+++ src/logic/map_objects/tribes/productionsite.h 2017-04-23 12:22:45 +0000
559@@ -205,7 +205,7 @@
560
561 InputQueue& inputqueue(DescriptionIndex, WareWorker) override;
562
563- void init(EditorGameBase&) override;
564+ bool init(EditorGameBase&) override;
565 void cleanup(EditorGameBase&) override;
566 void act(Game&, uint32_t data) override;
567
568
569=== modified file 'src/logic/map_objects/tribes/ship.cc'
570--- src/logic/map_objects/tribes/ship.cc 2017-02-22 20:23:49 +0000
571+++ src/logic/map_objects/tribes/ship.cc 2017-04-23 12:22:45 +0000
572@@ -152,7 +152,7 @@
573 start_task_ship(game);
574 }
575
576-void Ship::init(EditorGameBase& egbase) {
577+bool Ship::init(EditorGameBase& egbase) {
578 Bob::init(egbase);
579 init_fleet(egbase);
580 Notifications::publish(NoteShipMessage(this, NoteShipMessage::Message::kGained));
581@@ -161,6 +161,7 @@
582 // Assigning a ship name
583 shipname_ = get_owner()->pick_shipname();
584 molog("New ship: %s\n", shipname_.c_str());
585+ return true;
586 }
587
588 /**
589@@ -168,11 +169,11 @@
590 * The fleet code will automatically merge us into a larger
591 * fleet, if one is reachable.
592 */
593-void Ship::init_fleet(EditorGameBase& egbase) {
594+bool Ship::init_fleet(EditorGameBase& egbase) {
595 assert(get_owner() != nullptr);
596 Fleet* fleet = new Fleet(*get_owner());
597 fleet->add_ship(this);
598- fleet->init(egbase);
599+ return fleet->init(egbase);
600 // fleet calls the set_fleet function appropriately
601 }
602
603@@ -898,7 +899,6 @@
604
605 if ((ship_state_ == ShipStates::kExpeditionColonizing) || !state_is_expedition())
606 return;
607- send_signal(game, "cancel_expedition");
608
609 // The workers were hold in an idle state so that they did not try
610 // to become fugitive or run to the next warehouse. But now, we
611@@ -920,8 +920,27 @@
612 // Bring us back into a fleet and a economy.
613 set_economy(game, nullptr);
614 init_fleet(game);
615+ if (!get_fleet() || !get_fleet()->has_ports()) {
616+ // We lost our last reachable port, so we reset the expedition's state
617+ ship_state_ = ShipStates::kExpeditionWaiting;
618+ set_economy(game, expedition_->economy.get());
619+
620+ worker = nullptr;
621+ for (ShippingItem& item : items_) {
622+ item.get(game, nullptr, &worker);
623+ if (worker) {
624+ worker->reset_tasks(game);
625+ worker->start_task_idle(game, 0, -1);
626+ }
627+ }
628+
629+ Notifications::publish(NoteShipWindow(serial(), NoteShipWindow::Action::kNoPortLeft));
630+ return;
631+ }
632 assert(get_economy() && get_economy() != expedition_->economy.get());
633
634+ send_signal(game, "cancel_expedition");
635+
636 // Delete the expedition and the economy it created.
637 expedition_.reset(nullptr);
638
639
640=== modified file 'src/logic/map_objects/tribes/ship.h'
641--- src/logic/map_objects/tribes/ship.h 2017-02-22 20:23:49 +0000
642+++ src/logic/map_objects/tribes/ship.h 2017-04-23 12:22:45 +0000
643@@ -59,7 +59,7 @@
644
645 Serial serial;
646
647- enum class Action { kRefresh, kClose };
648+ enum class Action { kRefresh, kClose, kNoPortLeft };
649 const Action action;
650
651 NoteShipWindow(Serial init_serial, const Action& init_action)
652@@ -120,7 +120,7 @@
653
654 void init_auto_task(Game&) override;
655
656- void init(EditorGameBase&) override;
657+ bool init(EditorGameBase&) override;
658 void cleanup(EditorGameBase&) override;
659
660 void start_task_ship(Game&);
661@@ -264,7 +264,7 @@
662 void ship_update_expedition(Game&, State&);
663 void ship_update_idle(Game&, State&);
664
665- void init_fleet(EditorGameBase&);
666+ bool init_fleet(EditorGameBase&);
667 void set_fleet(Fleet* fleet);
668
669 void send_message(Game& game,
670
671=== modified file 'src/logic/map_objects/tribes/soldier.cc'
672--- src/logic/map_objects/tribes/soldier.cc 2017-01-31 07:18:19 +0000
673+++ src/logic/map_objects/tribes/soldier.cc 2017-04-23 12:22:45 +0000
674@@ -234,7 +234,7 @@
675 combat_walkend_ = 0;
676 }
677
678-void Soldier::init(EditorGameBase& egbase) {
679+bool Soldier::init(EditorGameBase& egbase) {
680 health_level_ = 0;
681 attack_level_ = 0;
682 defense_level_ = 0;
683@@ -247,7 +247,7 @@
684 combat_walkstart_ = 0;
685 combat_walkend_ = 0;
686
687- Worker::init(egbase);
688+ return Worker::init(egbase);
689 }
690
691 void Soldier::cleanup(EditorGameBase& egbase) {
692
693=== modified file 'src/logic/map_objects/tribes/soldier.h'
694--- src/logic/map_objects/tribes/soldier.h 2017-01-25 18:55:59 +0000
695+++ src/logic/map_objects/tribes/soldier.h 2017-04-23 12:22:45 +0000
696@@ -175,7 +175,7 @@
697 public:
698 Soldier(const SoldierDescr&);
699
700- void init(EditorGameBase&) override;
701+ bool init(EditorGameBase&) override;
702 void cleanup(EditorGameBase&) override;
703
704 void set_level(uint32_t health, uint32_t attack, uint32_t defense, uint32_t evade);
705
706=== modified file 'src/logic/map_objects/tribes/trainingsite.cc'
707--- src/logic/map_objects/tribes/trainingsite.cc 2017-01-25 18:55:59 +0000
708+++ src/logic/map_objects/tribes/trainingsite.cc 2017-04-23 12:22:45 +0000
709@@ -218,7 +218,7 @@
710 /**
711 * Setup the building and request soldiers
712 */
713-void TrainingSite::init(EditorGameBase& egbase) {
714+bool TrainingSite::init(EditorGameBase& egbase) {
715 ProductionSite::init(egbase);
716
717 upcast(Game, game, &egbase);
718@@ -232,6 +232,7 @@
719 }
720 }
721 update_soldier_request();
722+ return true;
723 }
724
725 /**
726
727=== modified file 'src/logic/map_objects/tribes/trainingsite.h'
728--- src/logic/map_objects/tribes/trainingsite.h 2017-02-10 15:41:31 +0000
729+++ src/logic/map_objects/tribes/trainingsite.h 2017-04-23 12:22:45 +0000
730@@ -169,7 +169,7 @@
731 public:
732 TrainingSite(const TrainingSiteDescr&);
733
734- void init(EditorGameBase&) override;
735+ bool init(EditorGameBase&) override;
736 void cleanup(EditorGameBase&) override;
737 void act(Game&, uint32_t data) override;
738
739
740=== modified file 'src/logic/map_objects/tribes/warehouse.cc'
741--- src/logic/map_objects/tribes/warehouse.cc 2017-02-18 23:30:16 +0000
742+++ src/logic/map_objects/tribes/warehouse.cc 2017-04-23 12:22:45 +0000
743@@ -383,7 +383,7 @@
744 }
745 }
746
747-void Warehouse::init(EditorGameBase& egbase) {
748+bool Warehouse::init(EditorGameBase& egbase) {
749 Building::init(egbase);
750
751 Player& player = owner();
752@@ -448,6 +448,7 @@
753 }
754 }
755 cleanup_in_progress_ = false;
756+ return true;
757 }
758
759 void Warehouse::init_containers(Player& player) {
760
761=== modified file 'src/logic/map_objects/tribes/warehouse.h'
762--- src/logic/map_objects/tribes/warehouse.h 2017-02-22 20:23:49 +0000
763+++ src/logic/map_objects/tribes/warehouse.h 2017-04-23 12:22:45 +0000
764@@ -147,7 +147,7 @@
765 /// * Conquers land if the the warehouse type is configured to do that.
766 /// * Sends a message to the player about the creation of this warehouse.
767 /// * Sets up @ref PortDock for ports
768- void init(EditorGameBase&) override;
769+ bool init(EditorGameBase&) override;
770
771 void cleanup(EditorGameBase&) override;
772
773
774=== modified file 'src/logic/map_objects/tribes/worker.cc'
775--- src/logic/map_objects/tribes/worker.cc 2017-02-28 12:59:39 +0000
776+++ src/logic/map_objects/tribes/worker.cc 2017-04-23 12:22:45 +0000
777@@ -1071,7 +1071,7 @@
778 /**
779 * Initialize the worker
780 */
781-void Worker::init(EditorGameBase& egbase) {
782+bool Worker::init(EditorGameBase& egbase) {
783 Bob::init(egbase);
784
785 // a worker should always start out at a fixed location
786@@ -1081,6 +1081,7 @@
787
788 if (upcast(Game, game, &egbase))
789 create_needed_experience(*game);
790+ return true;
791 }
792
793 /**
794
795=== modified file 'src/logic/map_objects/tribes/worker.h'
796--- src/logic/map_objects/tribes/worker.h 2017-01-25 18:55:59 +0000
797+++ src/logic/map_objects/tribes/worker.h 2017-04-23 12:22:45 +0000
798@@ -115,7 +115,7 @@
799 void schedule_incorporate(Game&);
800 void incorporate(Game&);
801
802- void init(EditorGameBase&) override;
803+ bool init(EditorGameBase&) override;
804 void cleanup(EditorGameBase&) override;
805
806 bool wakeup_flag_capacity(Game&, Flag&);
807
808=== modified file 'src/wui/shipwindow.cc'
809--- src/wui/shipwindow.cc 2017-02-25 13:27:40 +0000
810+++ src/wui/shipwindow.cc 2017-04-23 12:22:45 +0000
811@@ -27,6 +27,7 @@
812 #include "logic/map_objects/tribes/worker.h"
813 #include "logic/player.h"
814 #include "ui_basic/box.h"
815+#include "ui_basic/messagebox.h"
816 #include "wui/actionconfirm.h"
817 #include "wui/game_debug_ui.h"
818 #include "wui/interactive_player.h"
819@@ -57,6 +58,20 @@
820 [this](const Widelands::NoteShipWindow& note) {
821 if (note.serial == ship_.serial()) {
822 switch (note.action) {
823+ // Unable to cancel the expedition
824+ case Widelands::NoteShipWindow::Action::kNoPortLeft:
825+ if (upcast(InteractiveGameBase, igamebase, ship_.get_owner()->egbase().get_ibase())) {
826+ if (igamebase->can_act(ship_.get_owner()->player_number())) {
827+ UI::WLMessageBox messagebox(
828+ get_parent(),
829+ /** TRANSLATORS: Window label when an expedition can't be canceled */
830+ _("Cancel expedition"), _("This expedition can’t be canceled, because the "
831+ "ship has no port to return to."),
832+ UI::WLMessageBox::MBoxType::kOk);
833+ messagebox.run<UI::Panel::Returncodes>();
834+ }
835+ }
836+ break;
837 // The ship state has changed, e.g. expedition canceled
838 case Widelands::NoteShipWindow::Action::kRefresh:
839 init(true);

Subscribers

People subscribed via source and target branches

to status/vote changes: