Merge lp:~widelands-dev/widelands/bug-863185-census-on-destroyed-building into lp:widelands
- bug-863185-census-on-destroyed-building
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 8186 | ||||
Proposed branch: | lp:~widelands-dev/widelands/bug-863185-census-on-destroyed-building | ||||
Merge into: | lp:widelands | ||||
Diff against target: |
371 lines (+89/-37) 6 files modified
src/logic/editor_game_base.cc (+13/-8) src/logic/editor_game_base.h (+6/-4) src/logic/map_objects/immovable.cc (+44/-14) src/logic/map_objects/immovable.h (+17/-6) src/logic/map_objects/tribes/building.cc (+4/-2) src/logic/map_objects/tribes/warehouse.cc (+5/-3) |
||||
To merge this branch: | bzr merge lp:~widelands-dev/widelands/bug-863185-census-on-destroyed-building | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
SirVer | Approve | ||
GunChleoc | Needs Resubmitting | ||
Review via email: mp+309818@code.launchpad.net |
Commit message
Show census information on destroyed building with the former building's name.
Description of the change
bunnybot (widelandsofficial) wrote : | # |
SirVer (sirver) : | # |
GunChleoc (gunchleoc) wrote : | # |
Next try.
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 1619. State: passed. Details: https:/
Appveyor build 1457. 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 1619. State: passed. Details: https:/
Appveyor build 1457. State: success. Details: https:/
SirVer (sirver) wrote : | # |
lgtm. minor nits inlined.
GunChleoc (gunchleoc) wrote : | # |
@bunnybot merge
Preview Diff
1 | === modified file 'src/logic/editor_game_base.cc' |
2 | --- src/logic/editor_game_base.cc 2016-11-04 18:00:36 +0000 |
3 | +++ src/logic/editor_game_base.cc 2016-11-22 20:26:46 +0000 |
4 | @@ -318,23 +318,27 @@ |
5 | Create an immovable at the given location. |
6 | If tribe is not zero, create a immovable of a player (not a PlayerImmovable |
7 | but an immovable defined by the players tribe) |
8 | -Does not perform any placability checks. |
9 | +Does not perform any placeability checks. |
10 | +If this immovable was created by a building, 'former_building' can be set in order to display |
11 | +information about it. |
12 | =============== |
13 | */ |
14 | Immovable& EditorGameBase::create_immovable(const Coords& c, |
15 | DescriptionIndex const idx, |
16 | - MapObjectDescr::OwnerType type) { |
17 | + MapObjectDescr::OwnerType type, |
18 | + const Building* former_building) { |
19 | const ImmovableDescr& descr = |
20 | *(type == MapObjectDescr::OwnerType::kTribe ? tribes().get_immovable_descr(idx) : |
21 | world().get_immovable_descr(idx)); |
22 | assert(&descr); |
23 | inform_players_about_immovable(Map::get_index(c, map().get_width()), &descr); |
24 | - return descr.create(*this, c); |
25 | + return descr.create(*this, c, former_building); |
26 | } |
27 | |
28 | Immovable& EditorGameBase::create_immovable(const Coords& c, |
29 | const std::string& name, |
30 | - MapObjectDescr::OwnerType type) { |
31 | + MapObjectDescr::OwnerType type, |
32 | + const Building* former_building) { |
33 | DescriptionIndex idx; |
34 | if (type == MapObjectDescr::OwnerType::kTribe) { |
35 | idx = tribes().immovable_index(name.c_str()); |
36 | @@ -351,7 +355,7 @@ |
37 | name.c_str()); |
38 | } |
39 | } |
40 | - return create_immovable(c, idx, type); |
41 | + return create_immovable(c, idx, type, former_building); |
42 | } |
43 | |
44 | /** |
45 | @@ -529,7 +533,8 @@ |
46 | |
47 | /// This conquers a given area because of a new (military) building that is set |
48 | /// there. |
49 | -void EditorGameBase::conquer_area(PlayerArea<Area<FCoords>> player_area, bool conquer_guarded_location) { |
50 | +void EditorGameBase::conquer_area(PlayerArea<Area<FCoords>> player_area, |
51 | + bool conquer_guarded_location) { |
52 | assert(0 <= player_area.x); |
53 | assert(player_area.x < map().get_width()); |
54 | assert(0 <= player_area.y); |
55 | @@ -603,8 +608,8 @@ |
56 | // testsuite). |
57 | void EditorGameBase::do_conquer_area(PlayerArea<Area<FCoords>> player_area, |
58 | bool const conquer, |
59 | - PlayerNumber const preferred_player, |
60 | - bool const conquer_guarded_location_by_superior_influence, |
61 | + PlayerNumber const preferred_player, |
62 | + bool const conquer_guarded_location_by_superior_influence, |
63 | bool const neutral_when_no_influence, |
64 | bool const neutral_when_competing_influence) { |
65 | assert(0 <= player_area.x); |
66 | |
67 | === modified file 'src/logic/editor_game_base.h' |
68 | --- src/logic/editor_game_base.h 2016-11-04 18:00:36 +0000 |
69 | +++ src/logic/editor_game_base.h 2016-11-22 20:26:46 +0000 |
70 | @@ -144,10 +144,12 @@ |
71 | Bob& create_critter(const Coords&, const std::string& name, Player* owner = nullptr); |
72 | Immovable& create_immovable(const Coords&, |
73 | DescriptionIndex idx, |
74 | - MapObjectDescr::OwnerType = MapObjectDescr::OwnerType::kWorld); |
75 | + MapObjectDescr::OwnerType = MapObjectDescr::OwnerType::kWorld, |
76 | + const Building* former_building = nullptr); |
77 | Immovable& create_immovable(const Coords&, |
78 | const std::string& name, |
79 | - MapObjectDescr::OwnerType = MapObjectDescr::OwnerType::kWorld); |
80 | + MapObjectDescr::OwnerType = MapObjectDescr::OwnerType::kWorld, |
81 | + const Building* former_building = nullptr); |
82 | Bob& create_ship(const Coords&, int ship_type_idx, Player* owner = nullptr); |
83 | Bob& create_ship(const Coords&, const std::string& name, Player* owner = nullptr); |
84 | |
85 | @@ -238,8 +240,8 @@ |
86 | /// influence becomes greater than the owner's influence. |
87 | virtual void do_conquer_area(PlayerArea<Area<FCoords>> player_area, |
88 | bool conquer, |
89 | - PlayerNumber preferred_player = 0, |
90 | - bool conquer_guarded_location_by_superior_influence = false, |
91 | + PlayerNumber preferred_player = 0, |
92 | + bool conquer_guarded_location_by_superior_influence = false, |
93 | bool neutral_when_no_influence = false, |
94 | bool neutral_when_competing_influence = false); |
95 | void cleanup_playerimmovables_area(PlayerArea<Area<FCoords>>); |
96 | |
97 | === modified file 'src/logic/map_objects/immovable.cc' |
98 | --- src/logic/map_objects/immovable.cc 2016-11-17 18:36:12 +0000 |
99 | +++ src/logic/map_objects/immovable.cc 2016-11-22 20:26:46 +0000 |
100 | @@ -1,5 +1,5 @@ |
101 | /* |
102 | - * Copyright (C) 2002-2003, 2006-2011, 2013 by the Widelands Development Team |
103 | + * Copyright (C) 2002-2016 by the Widelands Development Team |
104 | * |
105 | * This program is free software; you can redistribute it and/or |
106 | * modify it under the terms of the GNU General Public License |
107 | @@ -324,9 +324,13 @@ |
108 | |
109 | /** |
110 | * Create an immovable of this type |
111 | -*/ |
112 | -Immovable& ImmovableDescr::create(EditorGameBase& egbase, const Coords& coords) const { |
113 | - Immovable& result = *new Immovable(*this); |
114 | + * If this immovable was created by a building, 'former_building' can be set |
115 | + * in order to display information about it. |
116 | + */ |
117 | +Immovable& ImmovableDescr::create(EditorGameBase& egbase, |
118 | + const Coords& coords, |
119 | + const Building* former_building) const { |
120 | + Immovable& result = *new Immovable(*this, former_building); |
121 | result.position_ = coords; |
122 | result.init(egbase); |
123 | return result; |
124 | @@ -340,8 +344,9 @@ |
125 | ============================== |
126 | */ |
127 | |
128 | -Immovable::Immovable(const ImmovableDescr& imm_descr) |
129 | +Immovable::Immovable(const ImmovableDescr& imm_descr, const Widelands::Building* former_building) |
130 | : BaseImmovable(imm_descr), |
131 | + former_building_descr_(former_building ? &former_building->descr() : nullptr), |
132 | anim_(0), |
133 | animstart_(0), |
134 | program_(nullptr), |
135 | @@ -349,6 +354,9 @@ |
136 | anim_construction_total_(0), |
137 | anim_construction_done_(0), |
138 | program_step_(0) { |
139 | + if (former_building != nullptr) { |
140 | + set_owner(former_building->get_owner()); |
141 | + } |
142 | } |
143 | |
144 | Immovable::~Immovable() { |
145 | @@ -361,6 +369,11 @@ |
146 | return rv; |
147 | } |
148 | |
149 | +void BaseImmovable::set_owner(Player* player) { |
150 | + assert(owner_ == nullptr); |
151 | + owner_ = player; |
152 | +} |
153 | + |
154 | int32_t Immovable::get_size() const { |
155 | return descr().get_size(); |
156 | } |
157 | @@ -369,10 +382,6 @@ |
158 | return descr().get_size() < BIG; |
159 | } |
160 | |
161 | -void Immovable::set_owner(Player* player) { |
162 | - owner_ = player; |
163 | -} |
164 | - |
165 | void Immovable::start_animation(const EditorGameBase& egbase, uint32_t const anim) { |
166 | anim_ = anim; |
167 | animstart_ = egbase.get_gametime(); |
168 | @@ -449,6 +458,9 @@ |
169 | } |
170 | if (!anim_construction_total_) { |
171 | dst->blit_animation(point_on_dst, scale, anim_, gametime - animstart_); |
172 | + if (former_building_descr_) { |
173 | + do_draw_info(draw_text, former_building_descr_->descname(), "", point_on_dst, scale, dst); |
174 | + } |
175 | } else { |
176 | draw_construction(gametime, draw_text, point_on_dst, scale, dst); |
177 | } |
178 | @@ -520,7 +532,7 @@ |
179 | ============================== |
180 | */ |
181 | |
182 | -constexpr uint8_t kCurrentPacketVersionImmovable = 7; |
183 | +constexpr uint8_t kCurrentPacketVersionImmovable = 8; |
184 | |
185 | // Supporting older versions for map loading |
186 | void Immovable::Loader::load(FileRead& fr, uint8_t const packet_version) { |
187 | @@ -542,6 +554,16 @@ |
188 | imm.position_ = read_coords_32(&fr, egbase().map().extent()); |
189 | imm.set_position(egbase(), imm.position_); |
190 | |
191 | + if (packet_version >= 8) { |
192 | + Player* owner = imm.get_owner(); |
193 | + if (owner) { |
194 | + DescriptionIndex idx = owner->tribe().building_index(fr.string()); |
195 | + if (owner->tribe().has_building(idx)) { |
196 | + imm.set_former_building(*owner->tribe().get_building_descr(idx)); |
197 | + } |
198 | + } |
199 | + } |
200 | + |
201 | // Animation |
202 | char const* const animname = fr.c_string(); |
203 | try { |
204 | @@ -627,7 +649,7 @@ |
205 | |
206 | if (descr().owner_type() == MapObjectDescr::OwnerType::kTribe) { |
207 | if (get_owner() == nullptr) |
208 | - log(" Tribe immovable has no owner!! "); |
209 | + log(" Tribe immovable '%s' has no owner!! ", descr().name().c_str()); |
210 | fw.c_string("tribes"); |
211 | } else { |
212 | fw.c_string("world"); |
213 | @@ -640,6 +662,9 @@ |
214 | |
215 | fw.unsigned_8(get_owner() ? get_owner()->player_number() : 0); |
216 | write_coords_32(&fw, position_); |
217 | + if (get_owner()) { |
218 | + fw.string(former_building_descr_ ? former_building_descr_->name() : ""); |
219 | + } |
220 | |
221 | // Animations |
222 | fw.string(descr().get_animation_name(anim_)); |
223 | @@ -1234,14 +1259,19 @@ |
224 | throw wexception("PlayerImmovable::remove_worker: not in list"); |
225 | } |
226 | |
227 | +void Immovable::set_former_building(const BuildingDescr& building) { |
228 | + if (descr().owner_type() == MapObjectDescr::OwnerType::kTribe && get_owner() == nullptr) |
229 | + throw wexception("Set '%s' as former building for Tribe immovable '%s', but it has no owner.", |
230 | + building.name().c_str(), descr().name().c_str()); |
231 | + former_building_descr_ = &building; |
232 | +} |
233 | + |
234 | /** |
235 | * Set the immovable's owner. Currently, it can only be set once. |
236 | */ |
237 | -void PlayerImmovable::set_owner(Player* const new_owner) { |
238 | +void PlayerImmovable::set_owner(Player* new_owner) { |
239 | assert(owner_ == nullptr); |
240 | - |
241 | owner_ = new_owner; |
242 | - |
243 | Notifications::publish(NoteImmovable(this, NoteImmovable::Ownership::GAINED)); |
244 | } |
245 | |
246 | |
247 | === modified file 'src/logic/map_objects/immovable.h' |
248 | --- src/logic/map_objects/immovable.h 2016-11-03 07:20:57 +0000 |
249 | +++ src/logic/map_objects/immovable.h 2016-11-22 20:26:46 +0000 |
250 | @@ -1,5 +1,5 @@ |
251 | /* |
252 | - * Copyright (C) 2002-2004, 2006-2010 by the Widelands Development Team |
253 | + * Copyright (C) 2002-2016 by the Widelands Development Team |
254 | * |
255 | * This program is free software; you can redistribute it and/or |
256 | * modify it under the terms of the GNU General Public License |
257 | @@ -38,6 +38,7 @@ |
258 | |
259 | namespace Widelands { |
260 | |
261 | +class Building; |
262 | class Economy; |
263 | class Map; |
264 | class TerrainAffinity; |
265 | @@ -85,6 +86,8 @@ |
266 | virtual int32_t get_size() const = 0; |
267 | virtual bool get_passable() const = 0; |
268 | |
269 | + virtual void set_owner(Player* player); |
270 | + |
271 | using PositionList = std::vector<Coords>; |
272 | /** |
273 | * Return all coordinates occupied by this Immovable. We gurantee that the |
274 | @@ -136,7 +139,8 @@ |
275 | } |
276 | ImmovableProgram const* get_program(const std::string&) const; |
277 | |
278 | - Immovable& create(EditorGameBase&, const Coords&) const; |
279 | + Immovable& |
280 | + create(EditorGameBase&, const Coords&, const Widelands::Building* former_building) const; |
281 | |
282 | MapObjectDescr::OwnerType owner_type() const { |
283 | return owner_type_; |
284 | @@ -198,11 +202,11 @@ |
285 | MO_DESCR(ImmovableDescr) |
286 | |
287 | public: |
288 | - Immovable(const ImmovableDescr&); |
289 | + /// If this immovable was created by a building, 'former_building' can be set in order to display |
290 | + /// information about it. |
291 | + Immovable(const ImmovableDescr&, const Widelands::Building* former_building = nullptr); |
292 | ~Immovable(); |
293 | |
294 | - void set_owner(Player*); |
295 | - |
296 | Coords get_position() const { |
297 | return position_; |
298 | } |
299 | @@ -242,6 +246,9 @@ |
300 | } |
301 | |
302 | protected: |
303 | + // The building type that created this immovable, if any. |
304 | + const BuildingDescr* former_building_descr_; |
305 | + |
306 | Coords position_; |
307 | |
308 | uint32_t anim_; |
309 | @@ -299,6 +306,10 @@ |
310 | const TribesLegacyLookupTable& tribes_lookup_table); |
311 | |
312 | private: |
313 | + /// If this immovable was created by a building, this can be set in order to display information |
314 | + /// about it. If this is a player immovable, you will need to set the owner first. |
315 | + void set_former_building(const BuildingDescr& building); |
316 | + |
317 | void increment_program_pointer(); |
318 | void draw_construction(uint32_t gametime, |
319 | TextToDraw draw_text, |
320 | @@ -367,7 +378,7 @@ |
321 | virtual void receive_worker(Game&, Worker& worker); |
322 | /*@}*/ |
323 | |
324 | - void set_owner(Player*); |
325 | + void set_owner(Player*) override; |
326 | |
327 | protected: |
328 | void init(EditorGameBase&) override; |
329 | |
330 | === modified file 'src/logic/map_objects/tribes/building.cc' |
331 | --- src/logic/map_objects/tribes/building.cc 2016-11-03 07:37:58 +0000 |
332 | +++ src/logic/map_objects/tribes/building.cc 2016-11-22 20:26:46 +0000 |
333 | @@ -38,6 +38,7 @@ |
334 | #include "logic/game.h" |
335 | #include "logic/game_data_error.h" |
336 | #include "logic/map.h" |
337 | +#include "logic/map_objects/immovable.h" |
338 | #include "logic/map_objects/tribes/constructionsite.h" |
339 | #include "logic/map_objects/tribes/productionsite.h" |
340 | #include "logic/map_objects/tribes/tribe_descr.h" |
341 | @@ -443,8 +444,9 @@ |
342 | const Coords pos = position_; |
343 | PlayerImmovable::destroy(egbase); |
344 | // We are deleted. Only use stack variables beyond this point |
345 | - if (fire) |
346 | - egbase.create_immovable(pos, "destroyed_building", MapObjectDescr::OwnerType::kTribe); |
347 | + if (fire) { |
348 | + egbase.create_immovable(pos, "destroyed_building", MapObjectDescr::OwnerType::kTribe, this); |
349 | + } |
350 | } |
351 | |
352 | std::string Building::info_string(const InfoStringFormat& format) { |
353 | |
354 | === modified file 'src/logic/map_objects/tribes/warehouse.cc' |
355 | --- src/logic/map_objects/tribes/warehouse.cc 2016-11-13 15:08:39 +0000 |
356 | +++ src/logic/map_objects/tribes/warehouse.cc 2016-11-22 20:26:46 +0000 |
357 | @@ -427,9 +427,11 @@ |
358 | } |
359 | |
360 | if (uint32_t const conquer_radius = descr().get_conquers()) { |
361 | - egbase.conquer_area(PlayerArea<Area<FCoords>>( |
362 | - player.player_number(), |
363 | - Area<FCoords>(egbase.map().get_fcoords(get_position()), conquer_radius)), true); |
364 | + egbase.conquer_area( |
365 | + PlayerArea<Area<FCoords>>( |
366 | + player.player_number(), |
367 | + Area<FCoords>(egbase.map().get_fcoords(get_position()), conquer_radius)), |
368 | + true); |
369 | } |
370 | |
371 | if (descr().get_isport()) { |
Continuous integration builds have changed state:
Travis build 1560. State: passed. Details: https:/ /travis- ci.org/ widelands/ widelands/ builds/ 172537690. /ci.appveyor. com/project/ widelands- dev/widelands/ build/_ widelands_ dev_widelands_ bug_863185_ census_ on_destroyed_ building- 1399.
Appveyor build 1399. State: success. Details: https:/