← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/remove-compatibility-wares into lp:widelands

 

Hans Joachim Desserud has proposed merging lp:~widelands-dev/widelands/remove-compatibility-wares into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1291554 in widelands: "Remove compatibility wares"
  https://bugs.launchpad.net/widelands/+bug/1291554

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/remove-compatibility-wares/+merge/210885

Remove the compatibility-sections I found in the conf-files. 

Also, I've removed what I could find on the code side responsible for reading/using these. I haven't done any thorough checks after these changes, but it compiles ;)

As before, I've included a couple of FIXMEs for specific issues.
-- 
https://code.launchpad.net/~widelands-dev/widelands/remove-compatibility-wares/+merge/210885
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/remove-compatibility-wares into lp:widelands.
=== modified file 'src/logic/immovable.cc'
--- src/logic/immovable.cc	2014-03-09 18:29:48 +0000
+++ src/logic/immovable.cc	2014-03-13 19:03:51 +0000
@@ -750,23 +750,8 @@
 				egbase.manually_load_tribe(owner);
 
 				if (Tribe_Descr const * const tribe = egbase.get_tribe(owner)) {
+//FIXME (REVIEW): I tried to skip this variable, but name didn't seem to have all the methods like this do :/
 					std::string effective_name = name;
-					const std::vector<std::string> & compat =
-						tribe->compatibility_immovable(name);
-
-					if (compat.size() >= 1) {
-						if (compat[0] == "replace") {
-							if (compat.size() != 2)
-								throw game_data_error
-									("incomplete compatibility_immovable replace for %s",
-									 name);
-
-							effective_name = compat[1];
-						} else
-							throw game_data_error
-								("bad compatibility_immovable code %s for %s",
-								 compat[0].c_str(), name);
-					}
 
 					int32_t const idx = tribe->get_immovable_index(effective_name);
 					if (idx != -1)

=== modified file 'src/logic/productionsite.cc'
--- src/logic/productionsite.cc	2014-03-04 13:24:58 +0000
+++ src/logic/productionsite.cc	2014-03-13 19:03:51 +0000
@@ -133,16 +133,6 @@
 			throw wexception("program %s: %s", program_name.c_str(), e.what());
 		}
 	}
-
-	if (Section * compat_s = prof.get_section("compatibility_programs")) {
-		while (const Section::Value * v = compat_s->get_next_val())
-			m_compatibility_programs[v->get_name()] = split_string(v->get_string(), " ");
-	}
-
-	if (Section * compat_s = prof.get_section("compatibility working positions")) {
-		while (const Section::Value * v = compat_s->get_next_val())
-			m_compatibility_working_positions[v->get_name()] = split_string(v->get_string(), " ");
-	}
 }
 
 ProductionSite_Descr::~ProductionSite_Descr()
@@ -168,32 +158,6 @@
 }
 
 /**
- * If there is a compatibility action for the given program, return it.
- *
- * Otherwise, return an empty vector.
- */
-const std::vector<std::string> & ProductionSite_Descr::compatibility_program
-	(const std::string & progname) const
-{
-	static const std::vector<std::string> empty;
-	Compatibility::const_iterator it = m_compatibility_programs.find(progname);
-	if (it != m_compatibility_programs.end())
-		return it->second;
-	return empty;
-}
-
-const std::vector<std::string> & ProductionSite_Descr::compatibility_working_positions
-	(const std::string & workername) const
-{
-	static const std::vector<std::string> empty;
-	Compatibility::const_iterator it = m_compatibility_working_positions.find(workername);
-	if (it != m_compatibility_working_positions.end())
-		return it->second;
-	return empty;
-}
-
-
-/**
  * Create a new building of this type
  */
 Building & ProductionSite_Descr::create_object() const {

=== modified file 'src/logic/productionsite.h'
--- src/logic/productionsite.h	2014-02-22 18:04:02 +0000
+++ src/logic/productionsite.h	2014-03-13 19:03:51 +0000
@@ -85,25 +85,12 @@
 	typedef std::map<std::string, ProductionProgram *> Programs;
 	const Programs & programs() const {return m_programs;}
 
-	const std::vector<std::string> & compatibility_program(const std::string & progname) const;
-	const std::vector<std::string> & compatibility_working_positions(const std::string & workername) const;
-
 private:
 	BillOfMaterials m_working_positions;
 	BillOfMaterials m_inputs;
 	Output   m_output_ware_types;
 	Output   m_output_worker_types;
 	Programs m_programs;
-
-	typedef std::map<std::string, std::vector<std::string> > Compatibility;
-
-	/**
-	 * For savegame compatibility purposes, associate with old program
-	 * names a string describing actions that should be taken to preserve
-	 * compatibility.
-	 */
-	Compatibility m_compatibility_programs;
-	Compatibility m_compatibility_working_positions;
 };
 
 class ProductionSite : public Building {

=== modified file 'src/logic/tribe.cc'
--- src/logic/tribe.cc	2014-03-04 13:24:58 +0000
+++ src/logic/tribe.cc	2014-03-13 19:03:51 +0000
@@ -93,14 +93,6 @@
 					 	(*this, _name, _descname, path, prof, global_s));
 			PARSE_MAP_OBJECT_TYPES_END;
 
-			// Read compatibility wares (removed wares existing in saved games from older builds
-			if (Section * const section = root_conf.get_section("compatibility_wares")) {
-				while (Section::Value const * const v = section->get_next_val()) {
-					log("Compatibility ware \"%s\"=\"%s\" loaded.\n", v->get_name(), v->get_string());
-					m_compatibility_wares[v->get_name()] = v->get_string();
-				}
-			}
-
 			PARSE_MAP_OBJECT_TYPES_BEGIN("immovable")
 				m_immovables.add
 					(new Immovable_Descr
@@ -325,11 +317,6 @@
 		} catch (const std::exception & e) {
 			throw game_data_error("root conf: %s", e.what());
 		}
-
-		if (Section * compatibility_s = root_conf.get_section("compatibility_immovable")) {
-			while (const Section::Value * v = compatibility_s->get_next_val())
-				m_compatibility_immovable[v->get_name()] = split_string(v->get_string(), " ");
-		}
 	} catch (const _wexception & e) {
 		throw game_data_error("tribe %s: %s", tribename.c_str(), e.what());
 	}
@@ -530,41 +517,21 @@
 	if (Ware_Index const result = ware_index(warename))
 		return result;
 	else
-		// If this point is reached, the defined ware is neither defined as normal ware nor as a compatibility.
 		throw game_data_error("tribe %s does not define ware type \"%s\"", name().c_str(), warename.c_str());
 }
 Ware_Index Tribe_Descr::safe_ware_index(const char * const warename) const {
 	if (Ware_Index const result = ware_index(warename))
 		return result;
 	else
-		// If this point is reached, the defined ware is neither defined as normal ware nor as a compatibility.
 		throw game_data_error("tribe %s does not define ware type \"%s\"", name().c_str(), warename);
 }
 
 Ware_Index Tribe_Descr::ware_index(const std::string & warename) const {
 	Ware_Index const wi = m_wares.get_index(warename);
-	if (!wi) {
-		// try to find the ware in compatibility wares std::map
-		std::map<std::string, std::string>::const_iterator it = m_compatibility_wares.find(warename);
-		if (m_compatibility_wares.find(warename) != m_compatibility_wares.end()) {
-			log ("ware %s found in compatibility map: %s!\n", warename.c_str(), it->second.c_str());
-			if (Ware_Index const result = m_wares.get_index(it->second))
-				return result;
-		}
-	}
 	return wi;
 }
 Ware_Index Tribe_Descr::ware_index(char const * const warename) const {
 	Ware_Index const wi = m_wares.get_index(warename);
-	if (!wi) {
-		// try to find the ware in compatibility wares std::map
-		std::map<std::string, std::string>::const_iterator it = m_compatibility_wares.find(warename);
-		if (m_compatibility_wares.find(warename) != m_compatibility_wares.end()) {
-			log ("ware %s found in compatibility map: %s!\n", warename, it->second.c_str());
-			if (Ware_Index const result = m_wares.get_index(it->second))
-				return result;
-		}
-	}
 	return wi;
 }
 
@@ -605,19 +572,6 @@
 	return result;
 }
 
-/**
- * If there is a savegame compatibility information string concerning the
- * given immovable name, return it. Otherwise, return an empty string.
- */
-const std::vector<std::string> & Tribe_Descr::compatibility_immovable(const std::string & imm_name) const
-{
-	static const std::vector<std::string> empty;
-	Compatibility::const_iterator it = m_compatibility_immovable.find(imm_name);
-	if (it != m_compatibility_immovable.end())
-		return it->second;
-	return empty;
-}
-
 void Tribe_Descr::resize_ware_orders(size_t maxLength) {
 	bool need_resize = false;
 

=== modified file 'src/logic/tribe.h'
--- src/logic/tribe.h	2014-02-22 18:04:02 +0000
+++ src/logic/tribe.h	2014-03-13 19:03:51 +0000
@@ -234,8 +234,6 @@
 
 	void resize_ware_orders(size_t maxLength);
 
-	const std::vector<std::string> & compatibility_immovable(const std::string & name) const;
-
 private:
 	const std::string m_name;
 	const World & m_world;
@@ -260,15 +258,6 @@
 	Initializations m_initializations;
 
 	Military_Data   m_military_data;
-
-	typedef std::map<std::string, std::vector<std::string> > Compatibility;
-	/**
-	 * For savegame compatibility, this maps immovable names to strings
-	 * describing the appropriate compatibility preserving action.
-	 */
-	Compatibility m_compatibility_immovable;
-	std::map<std::string, std::string> m_compatibility_wares;
-
 };
 
 }

=== modified file 'src/logic/widelands_streamread.cc'
--- src/logic/widelands_streamread.cc	2013-07-26 20:19:36 +0000
+++ src/logic/widelands_streamread.cc	2014-03-13 19:03:51 +0000
@@ -27,9 +27,6 @@
 	(const Tribe_Descr & tribe)
 {
 	std::string name = CString();
-	const std::vector<std::string> & compat = tribe.compatibility_immovable(name);
-	if (compat.size() == 2 && compat[0] == "replace")
-		name = compat[1];
 	int32_t const index = tribe.get_immovable_index(name);
 	if (index == -1)
 		throw tribe_immovable_nonexistent(tribe.name(), name);

=== modified file 'src/logic/worker.cc'
--- src/logic/worker.cc	2014-03-10 09:53:33 +0000
+++ src/logic/worker.cc	2014-03-13 19:03:51 +0000
@@ -1336,19 +1336,6 @@
 }
 
 /**
- * Change this worker into a different type.
- *
- * \warning Using this function is very dangerous. The only reason it exists
- * is to fix certain savegame compatibility issues.
- */
-void Worker::flash(const std::string & newname)
-{
-	log("WARNING: Flashing worker of type %s to %s\n", name().c_str(), newname.c_str());
-
-	m_descr = tribe().get_worker_descr(tribe().safe_worker_index(newname));
-}
-
-/**
  * Set a fallback task.
  */
 void Worker::init_auto_task(Game & game) {
@@ -3046,14 +3033,8 @@
 const BobProgramBase * Worker::Loader::get_program(const std::string & name)
 {
 	Worker & worker = get<Worker>();
-	const std::string & compatibility = worker.descr().compatibility_program(name);
-
-	if (compatibility == "fail") {
-		if (upcast(Game, game, &egbase()))
-			add_finish(boost::bind(&Worker::send_signal, &worker, boost::ref(*game), "fail"));
-		return nullptr;
-	}
-
+//FIXME (REVIEW): Have to admit I'm not 100% how the old code worked. (I don't see how the result would be "fail")
+//But it seems it would look up the compatibility program, and then return the result of the get() below either way...
 	return worker.descr().get_program(name);
 }
 

=== modified file 'src/logic/worker.h'
--- src/logic/worker.h	2014-02-22 18:04:02 +0000
+++ src/logic/worker.h	2014-03-13 19:03:51 +0000
@@ -146,8 +146,6 @@
 	void create_needed_experience(Game &);
 	Ware_Index level             (Game &);
 
-	void flash(const std::string & newname);
-
 	int32_t get_needed_experience() const {
 		return descr().get_level_experience();
 	}

=== modified file 'src/logic/worker_descr.cc'
--- src/logic/worker_descr.cc	2014-02-22 18:04:02 +0000
+++ src/logic/worker_descr.cc	2014-03-13 19:03:51 +0000
@@ -131,12 +131,6 @@
 			throw wexception("program %s: %s", program_name.c_str(), e.what());
 		}
 	}
-
-	// Read compatibility information
-	if (Section * compat_s = prof.get_section("compatibility_program")) {
-		while (const Section::Value * v = compat_s->get_next_val())
-			m_compatibility_programs[v->get_name()] = v->get_string();
-	}
 }
 
 
@@ -174,20 +168,6 @@
 }
 
 /**
- * Get the compatibility information for the given program name.
- *
- * Returns an empty string if no compatibility information for this program is found.
- */
-const std::string & Worker_Descr::compatibility_program(const std::string & programname) const
-{
-	static const std::string empty;
-	std::map<std::string, std::string>::const_iterator it = m_compatibility_programs.find(programname);
-	if (it != m_compatibility_programs.end())
-		return it->second;
-	return empty;
-}
-
-/**
  * Custom creation routing that accounts for the location.
  */
 Worker & Worker_Descr::create

=== modified file 'src/logic/worker_descr.h'
--- src/logic/worker_descr.h	2014-02-22 18:04:02 +0000
+++ src/logic/worker_descr.h	2014-03-13 19:03:51 +0000
@@ -114,8 +114,6 @@
 	typedef std::map<std::string, WorkerProgram *> Programs;
 	const Programs & programs() const {return m_programs;}
 
-	const std::string & compatibility_program(const std::string & programname) const;
-
 protected:
 
 	std::string       m_helptext;   ///< Short (tooltip-like) help text
@@ -139,14 +137,6 @@
 	 */
 	Ware_Index  m_becomes;
 	Programs    m_programs;
-
-	/**
-	 * Compatibility hints for loading save games of older versions.
-	 *
-	 * Maps program name to a string that is to be interpreted by the
-	 * game loading logic.
-	 */
-	std::map<std::string, std::string> m_compatibility_programs;
 };
 
 }

=== modified file 'src/map_io/widelands_map_buildingdata_data_packet.cc'
--- src/map_io/widelands_map_buildingdata_data_packet.cc	2014-03-05 20:20:37 +0000
+++ src/map_io/widelands_map_buildingdata_data_packet.cc	2014-03-13 19:03:51 +0000
@@ -926,49 +926,6 @@
 			for (uint16_t i = nr_workers; i; --i) {
 				Worker * worker = &mol.get<Worker>(fr.Unsigned32());
 
-				const std::vector<std::string> & compat =
-					pr_descr.compatibility_working_positions(worker->descr().name());
-				if (!compat.empty()) {
-					if (compat[0] == "flash") {
-						if (compat.size() != 2)
-							throw game_data_error
-								("working position '%s' compat usage: flash other-name",
-								 worker->descr().name().c_str());
-
-						worker->flash(compat[1]);
-					} else if (compat[0] == "replace") {
-						if (compat.size() != 2)
-							throw game_data_error
-								("working position '%s' compat usage: replace other-name",
-								 worker->descr().name().c_str());
-
-						const Tribe_Descr & tribe = worker->tribe();
-
-						log
-							("COMPAT(%s): replace '%s' (%u) by '%s' in '%s' (%u)\n",
-							 tribe.name().c_str(),
-							 worker->descr().name().c_str(), worker->serial(),
-							 compat[1].c_str(),
-							 pr_descr.name().c_str(), productionsite.serial());
-
-						mol.schedule_destroy(*worker);
-
-						const Worker_Descr & worker_descr =
-							*tribe.get_worker_descr
-							(tribe.safe_worker_index(compat[1]));
-						worker = &worker_descr.create
-							(game,
-							 productionsite.owner(),
-							 &productionsite,
-							 worker->get_position());
-						worker->start_task_buildingwork(game);
-						mol.schedule_act(*worker);
-					} else
-						throw game_data_error
-							("unknown compat '%s' for working position '%s'",
-							 compat[0].c_str(), worker->descr().name().c_str());
-				}
-
 				//  Find a working position that matches this worker.
 				const Worker_Descr & worker_descr = worker->descr();
 				ProductionSite::Working_Position * wp = &wp_begin;
@@ -1035,20 +992,6 @@
 				std::transform
 					(program_name.begin(), program_name.end(), program_name.begin(),
 					 tolower);
-				const std::vector<std::string> & compat = pr_descr.compatibility_program(program_name);
-				if (!compat.empty()) {
-					if (compat[0] == "replace") {
-						if (compat.size() != 2)
-							throw game_data_error
-								("Program '%s' compatibility: usage: replace other-name",
-								 program_name.c_str());
-
-						program_name = compat[1];
-					} else
-						throw game_data_error
-							("Unknown compatibility code '%s' for program '%s'",
-							 compat[0].c_str(), program_name.c_str());
-				}
 
 				productionsite.m_stack[i].program =
 					productionsite.descr().get_program(program_name);

=== modified file 'tribes/barbarians/battlearena/conf'
--- tribes/barbarians/battlearena/conf	2014-03-10 10:45:21 +0000
+++ tribes/barbarians/battlearena/conf	2014-03-13 19:03:51 +0000
@@ -19,9 +19,6 @@
 [working positions]
 trainer=1
 
-[compatibility working positions]
-carrier=replace trainer
-
 [inputs]
 pittabread=10
 fish=6

=== modified file 'tribes/barbarians/conf'
--- tribes/barbarians/conf	2014-03-10 09:15:02 +0000
+++ tribes/barbarians/conf	2014-03-13 19:03:51 +0000
@@ -29,13 +29,6 @@
 fps=5
 playercolor=true
 
-[compatibility_immovable]
-# For compatibility with build15 and earlier
-flax0s=replace reed0s
-flax0t=replace reed0t
-flax0=replace reed0
-flax1=replace reed1
-
 [immovable types]
 ashes=_Ashes
 destroyed_building=_Destroyed building
@@ -64,10 +57,6 @@
 deer=_Deer
 wildboar=_Wild Boar
 
-[compatibility_wares]
-# for compatibility with build15 and earlier
-flax=thatchreed
-
 [ware types]
 axe=_Ax
 bakingtray=_Bread Paddle

=== modified file 'tribes/barbarians/ferner/conf'
--- tribes/barbarians/ferner/conf	2014-02-22 16:49:17 +0000
+++ tribes/barbarians/ferner/conf	2014-03-13 19:03:51 +0000
@@ -2,11 +2,6 @@
 program=plantreed
 program=harvestreed
 
-[compatibility_program]
-# For compatibility with build15 and earlier
-plantflax=fail
-harvestflax=fail
-
 [buildcost]
 carrier=1
 shovel=1

=== modified file 'tribes/barbarians/fernery/conf'
--- tribes/barbarians/fernery/conf	2014-03-10 10:45:21 +0000
+++ tribes/barbarians/fernery/conf	2014-03-13 19:03:51 +0000
@@ -20,14 +20,6 @@
 harvest_reed=_Harvest reed
 work=_Work
 
-[compatibility_programs]
-# For compatibility with savegames from build15 and older
-plant_flax=replace plant_reed
-harvest_flax=replace harvest_reed
-# For compatibility with savegames from build13 and older
-plantflax=replace plant_reed
-harvestflax=replace harvest_reed
-
 [plant_reed]
 sleep=18000  #orig sleep=20000 but ferner animation was increased by 2sec
 worker=plantreed

=== modified file 'tribes/barbarians/metalworks/conf'
--- tribes/barbarians/metalworks/conf	2014-03-03 20:59:04 +0000
+++ tribes/barbarians/metalworks/conf	2014-03-13 19:03:51 +0000
@@ -47,9 +47,6 @@
 produce_hunting_spear=_Produce hunting spear
 work=_Work
 
-[compatibility_programs]
-produce_axe=replace produce_felling_axe
-
 [produce_felling_axe]
 return=skipped unless economy needs felling_axe
 consume=iron trunk

=== modified file 'tribes/empire/sawmill/conf'
--- tribes/empire/sawmill/conf	2013-07-23 13:40:00 +0000
+++ tribes/empire/sawmill/conf	2014-03-13 19:03:51 +0000
@@ -16,9 +16,6 @@
 [working positions]
 carpenter=1
 
-[compatibility working positions]
-toolsmith=flash carpenter
-
 [inputs]
 trunk=8
 


Follow ups