← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-863185-census-on-destroyed-building into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-863185-census-on-destroyed-building into lp:widelands.

Commit message:
Show census information on destroyed building with the former building's name.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #863185 in widelands: "Show census information as long as fires burn"
  https://bugs.launchpad.net/widelands/+bug/863185

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-863185-census-on-destroyed-building/+merge/309818
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-863185-census-on-destroyed-building into lp:widelands.
=== modified file 'src/logic/map_objects/immovable.cc'
--- src/logic/map_objects/immovable.cc	2016-10-26 19:43:40 +0000
+++ src/logic/map_objects/immovable.cc	2016-11-02 07:52:51 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2002-2003, 2006-2011, 2013 by the Widelands Development Team
+ * Copyright (C) 2002-2016 by the Widelands Development Team
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -339,6 +339,7 @@
 
 Immovable::Immovable(const ImmovableDescr& imm_descr)
    : BaseImmovable(imm_descr),
+     antecedent_(nullptr),
      anim_(0),
      animstart_(0),
      program_(nullptr),
@@ -446,6 +447,9 @@
 	}
 	if (!anim_construction_total_) {
 		dst->blit_animation(point_on_dst, scale, anim_, gametime - animstart_);
+		if (antecedent_) {
+			do_draw_info(draw_text, antecedent_->descname(), "", point_on_dst, scale, dst);
+		}
 	} else {
 		draw_construction(gametime, draw_text, point_on_dst, scale, dst);
 	}
@@ -519,7 +523,7 @@
 ==============================
 */
 
-constexpr uint8_t kCurrentPacketVersionImmovable = 7;
+constexpr uint8_t kCurrentPacketVersionImmovable = 8;
 
 // Supporting older versions for map loading
 void Immovable::Loader::load(FileRead& fr, uint8_t const packet_version) {
@@ -541,6 +545,13 @@
 	imm.position_ = read_coords_32(&fr, egbase().map().extent());
 	imm.set_position(egbase(), imm.position_);
 
+	if (packet_version >= 8) {
+		DescriptionIndex idx = fr.unsigned_8();
+		if (idx != INVALID_INDEX) {
+			imm.set_antecedent(*imm.get_owner()->tribe().get_building_descr(idx));
+		}
+	}
+
 	// Animation
 	char const* const animname = fr.c_string();
 	try {
@@ -626,7 +637,7 @@
 
 	if (descr().owner_type() == MapObjectDescr::OwnerType::kTribe) {
 		if (get_owner() == nullptr)
-			log(" Tribe immovable has no owner!! ");
+			log(" Tribe immovable '%s' has no owner!! ", descr().name().c_str());
 		fw.c_string("tribes");
 	} else {
 		fw.c_string("world");
@@ -639,6 +650,8 @@
 
 	fw.unsigned_8(get_owner() ? get_owner()->player_number() : 0);
 	write_coords_32(&fw, position_);
+	fw.unsigned_8(antecedent_ ? get_owner()->tribe().building_index(antecedent_->name()) :
+	                            INVALID_INDEX);
 
 	// Animations
 	fw.string(descr().get_animation_name(anim_));
@@ -1233,6 +1246,15 @@
 	throw wexception("PlayerImmovable::remove_worker: not in list");
 }
 
+void Immovable::set_antecedent(const BuildingDescr& building) {
+	if (descr().owner_type() == MapObjectDescr::OwnerType::kTribe) {
+		if (get_owner() == nullptr)
+			throw wexception("Set '%s' as antecedent for Tribe immovable '%s', but it has no owner.",
+			                 building.name().c_str(), descr().name().c_str());
+	}
+	antecedent_ = &building;
+}
+
 /**
  * Set the immovable's owner. Currently, it can only be set once.
 */

=== modified file 'src/logic/map_objects/immovable.h'
--- src/logic/map_objects/immovable.h	2016-10-26 19:43:40 +0000
+++ src/logic/map_objects/immovable.h	2016-11-02 07:52:51 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2002-2004, 2006-2010 by the Widelands Development Team
+ * Copyright (C) 2002-2016 by the Widelands Development Team
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -201,7 +201,11 @@
 	Immovable(const ImmovableDescr&);
 	~Immovable();
 
-	void set_owner(Player*);
+	/// If this immovable was created by a building, this can be set in order to display information
+	/// about it. If this is a player immovable, you will need to set the owner first.
+	void set_antecedent(const BuildingDescr& building);
+
+	void set_owner(Player* player);
 
 	Coords get_position() const {
 		return position_;
@@ -242,6 +246,9 @@
 	}
 
 protected:
+	// The building type that created this immovable, if any.
+	const BuildingDescr* antecedent_;
+
 	Coords position_;
 
 	uint32_t anim_;

=== modified file 'src/logic/map_objects/tribes/building.cc'
--- src/logic/map_objects/tribes/building.cc	2016-10-26 19:43:40 +0000
+++ src/logic/map_objects/tribes/building.cc	2016-11-02 07:52:51 +0000
@@ -38,6 +38,7 @@
 #include "logic/game.h"
 #include "logic/game_data_error.h"
 #include "logic/map.h"
+#include "logic/map_objects/immovable.h"
 #include "logic/map_objects/tribes/constructionsite.h"
 #include "logic/map_objects/tribes/productionsite.h"
 #include "logic/map_objects/tribes/tribe_descr.h"
@@ -441,8 +442,12 @@
 	const Coords pos = position_;
 	PlayerImmovable::destroy(egbase);
 	// We are deleted. Only use stack variables beyond this point
-	if (fire)
-		egbase.create_immovable(pos, "destroyed_building", MapObjectDescr::OwnerType::kTribe);
+	if (fire) {
+		Immovable& destroyed_building =
+		   egbase.create_immovable(pos, "destroyed_building", MapObjectDescr::OwnerType::kTribe);
+		destroyed_building.set_owner(get_owner());
+		destroyed_building.set_antecedent(descr());
+	}
 }
 
 std::string Building::info_string(const InfoStringFormat& format) {


Follow ups