← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/bug-1512076-cleanup-static into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1512076-cleanup-static into lp:widelands.

Commit message:
Refactoring: Turned static functions in Tribes into standalone functions.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1512076 in widelands: "Post one_tribe cleanup"
  https://bugs.launchpad.net/widelands/+bug/1512076

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1512076-cleanup-static/+merge/315350
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1512076-cleanup-static into lp:widelands.
=== modified file 'src/editor/ui_menus/player_menu.cc'
--- src/editor/ui_menus/player_menu.cc	2017-01-21 09:41:07 +0000
+++ src/editor/ui_menus/player_menu.cc	2017-01-23 12:20:29 +0000
@@ -61,7 +61,7 @@
                          g_gr->images().get("images/ui_basic/but1.png"),
                          g_gr->images().get("images/ui_basic/scrollbar_down.png"),
                          _("Remove last player")),
-     tribenames_(eia().egbase().tribes().get_all_tribenames()) {
+	  tribenames_(Widelands::get_all_tribenames()) {
 	add_player_.set_enabled(parent.egbase().map().get_nrplayers() < kMaxPlayers);
 	add_player_.sigclicked.connect(
 	   boost::bind(&EditorPlayerMenu::clicked_add_player, boost::ref(*this)));
@@ -169,7 +169,7 @@
 		}
 
 		plr_set_tribes_buts_[p - 1]->set_title(
-		   eia().egbase().tribes().tribeinfo(selected_tribes_[p - 1]).descname);
+		   Widelands::tribeinfo(selected_tribes_[p - 1]).descname);
 
 		// Set default AI and closeable to false (always default - should be changed by hand)
 		map.set_scenario_player_ai(p, "");
@@ -249,7 +249,7 @@
 void EditorPlayerMenu::player_tribe_clicked(uint8_t n) {
 	EditorInteractive& menu = eia();
 	if (!menu.is_player_tribe_referenced(n + 1)) {
-		if (!Widelands::Tribes::tribe_exists(selected_tribes_[n])) {
+		if (!Widelands::tribe_exists(selected_tribes_[n])) {
 			throw wexception(
 			   "Map defines tribe %s, but it does not exist!", selected_tribes_[n].c_str());
 		}
@@ -330,7 +330,7 @@
 		// place a hq and reference the tribe
 		// so that this tribe can not be changed
 		egbase.add_player(n, 0,  // TODO(SirVer): initialization index makes no sense here
-		                  eia().egbase().tribes().tribeinfo(selected_tribes_[n]).descname,
+		                  Widelands::tribeinfo(selected_tribes_[n]).descname,
 		                  plr_names_[n - 1]->text());
 
 		p = egbase.get_player(n);

=== modified file 'src/logic/map.cc'
--- src/logic/map.cc	2016-09-07 09:30:49 +0000
+++ src/logic/map.cc	2017-01-23 12:20:29 +0000
@@ -305,7 +305,7 @@
 	// Set first tribe found as the "basic" tribe
 	// <undefined> (as set before) is useless and will lead to a
 	// crash -> Widelands will search for tribe "<undefined>"
-	set_scenario_player_tribe(1, Tribes::get_all_tribenames()[0]);
+	set_scenario_player_tribe(1, Widelands::get_all_tribenames()[0]);
 	set_scenario_player_name(1, (boost::format(_("Player %u")) % 1).str());
 	set_scenario_player_ai(1, "");
 	set_scenario_player_closeable(1, false);

=== modified file 'src/logic/map_objects/tribes/ship.cc'
--- src/logic/map_objects/tribes/ship.cc	2016-12-03 13:32:28 +0000
+++ src/logic/map_objects/tribes/ship.cc	2017-01-23 12:20:29 +0000
@@ -1176,7 +1176,7 @@
 				if (packet_version < 5) {
 					std::string tribe_name = fr.string();
 					fr.c_string();  // This used to be the ship's name, which we don't need any more.
-					if (!(egbase.tribes().tribe_exists(tribe_name))) {
+					if (!Widelands::tribe_exists(tribe_name)) {
 						throw GameDataError("Tribe %s does not exist for ship", tribe_name.c_str());
 					}
 					const DescriptionIndex& tribe_index = egbase.tribes().tribe_index(tribe_name);

=== modified file 'src/logic/map_objects/tribes/tribes.cc'
--- src/logic/map_objects/tribes/tribes.cc	2017-01-06 09:00:11 +0000
+++ src/logic/map_objects/tribes/tribes.cc	2017-01-23 12:20:29 +0000
@@ -27,16 +27,7 @@
 
 namespace Widelands {
 
-Tribes::Tribes()
-   : buildings_(new DescriptionMaintainer<BuildingDescr>()),
-     immovables_(new DescriptionMaintainer<ImmovableDescr>()),
-     ships_(new DescriptionMaintainer<ShipDescr>()),
-     wares_(new DescriptionMaintainer<WareDescr>()),
-     workers_(new DescriptionMaintainer<WorkerDescr>()),
-     tribes_(new DescriptionMaintainer<TribeDescr>()) {
-}
-
-std::vector<std::string> Tribes::get_all_tribenames() {
+std::vector<std::string> get_all_tribenames() {
 	std::vector<std::string> tribenames;
 	LuaInterface lua;
 	std::unique_ptr<LuaTable> table(lua.run_script("tribes/preload.lua"));
@@ -48,7 +39,7 @@
 	return tribenames;
 }
 
-std::vector<TribeBasicInfo> Tribes::get_all_tribeinfos() {
+std::vector<TribeBasicInfo> get_all_tribeinfos() {
 	std::vector<TribeBasicInfo> tribeinfos;
 	LuaInterface lua;
 	std::unique_ptr<LuaTable> table(lua.run_script("tribes/preload.lua"));
@@ -58,9 +49,9 @@
 	return tribeinfos;
 }
 
-TribeBasicInfo Tribes::tribeinfo(const std::string& tribename) {
-	if (tribe_exists(tribename)) {
-		for (const TribeBasicInfo& info : get_all_tribeinfos()) {
+TribeBasicInfo tribeinfo(const std::string& tribename) {
+	if (Widelands::tribe_exists(tribename)) {
+		for (const TribeBasicInfo& info : Widelands::get_all_tribeinfos()) {
 			if (info.name == tribename) {
 				return info;
 			}
@@ -69,7 +60,7 @@
 	throw GameDataError("The tribe '%s'' does not exist.", tribename.c_str());
 }
 
-bool Tribes::tribe_exists(const std::string& tribename) {
+bool tribe_exists(const std::string& tribename) {
 	for (const std::string& name : get_all_tribenames()) {
 		if (name == tribename) {
 			return true;
@@ -78,6 +69,15 @@
 	return false;
 }
 
+Tribes::Tribes()
+   : buildings_(new DescriptionMaintainer<BuildingDescr>()),
+     immovables_(new DescriptionMaintainer<ImmovableDescr>()),
+     ships_(new DescriptionMaintainer<ShipDescr>()),
+     wares_(new DescriptionMaintainer<WareDescr>()),
+     workers_(new DescriptionMaintainer<WorkerDescr>()),
+     tribes_(new DescriptionMaintainer<TribeDescr>()) {
+}
+
 void Tribes::add_constructionsite_type(const LuaTable& table, const EditorGameBase& egbase) {
 	i18n::Textdomain td("tribes");
 	buildings_->add(new ConstructionSiteDescr(
@@ -163,8 +163,8 @@
 
 void Tribes::add_tribe(const LuaTable& table, const EditorGameBase& egbase) {
 	const std::string name = table.get_string("name");
-	if (tribe_exists(name)) {
-		tribes_->add(new TribeDescr(table, Tribes::tribeinfo(name), egbase.tribes()));
+	if (Widelands::tribe_exists(name)) {
+		tribes_->add(new TribeDescr(table, Widelands::tribeinfo(name), egbase.tribes()));
 	} else {
 		throw GameDataError("The tribe '%s'' has no preload file.", name.c_str());
 	}

=== modified file 'src/logic/map_objects/tribes/tribes.h'
--- src/logic/map_objects/tribes/tribes.h	2016-08-04 15:49:05 +0000
+++ src/logic/map_objects/tribes/tribes.h	2017-01-23 12:20:29 +0000
@@ -46,24 +46,24 @@
 class WareDescr;
 class WorkerDescr;
 
+/// Returns a string vector with the names of all tribes.
+std::vector<std::string> get_all_tribenames();
+
+/// Returns a vector with the basic info for all tribes.
+std::vector<TribeBasicInfo> get_all_tribeinfos();
+
+/// Returns the basic preload info for a tribe.
+TribeBasicInfo tribeinfo(const std::string& tribename);
+
+/// Returns whether this tribe is listed in tribes/preload.lua.
+bool tribe_exists(const std::string& tribename);
+
 class Tribes {
 public:
 	Tribes();
 	~Tribes() {
 	}
 
-	/// Returns a string vector with the names of all tribes.
-	static std::vector<std::string> get_all_tribenames();
-
-	/// Returns a vector with the basic info for all tribes.
-	static std::vector<TribeBasicInfo> get_all_tribeinfos();
-
-	/// Returns the basic preload info for a tribe.
-	static TribeBasicInfo tribeinfo(const std::string& tribename);
-
-	/// Returns whether this tribe is listed in tribes/preload.lua.
-	static bool tribe_exists(const std::string& tribename);
-
 	/// Adds this building type to the tribe description.
 	void add_constructionsite_type(const LuaTable& table, const EditorGameBase& egbase);
 

=== modified file 'src/logic/map_objects/tribes/worker.cc'
--- src/logic/map_objects/tribes/worker.cc	2016-12-18 17:19:24 +0000
+++ src/logic/map_objects/tribes/worker.cc	2017-01-23 12:20:29 +0000
@@ -2667,7 +2667,7 @@
 		std::string name = fr.c_string();
 		// Some maps contain worker info, so we need compatibility here.
 		if (packet_version == 1) {
-			if (!(egbase.tribes().tribe_exists(name))) {
+			if (!Widelands::tribe_exists(name)) {
 				throw GameDataError("unknown tribe '%s'", name.c_str());
 			}
 			name = lookup_table.lookup_worker(name, fr.c_string());

=== modified file 'src/logic/single_player_game_settings_provider.cc'
--- src/logic/single_player_game_settings_provider.cc	2016-09-22 17:40:14 +0000
+++ src/logic/single_player_game_settings_provider.cc	2017-01-23 12:20:29 +0000
@@ -26,7 +26,7 @@
 #include "logic/map_objects/tribes/tribes.h"
 
 SinglePlayerGameSettingsProvider::SinglePlayerGameSettingsProvider() {
-	s.tribes = Widelands::Tribes::get_all_tribeinfos();
+	s.tribes = Widelands::get_all_tribeinfos();
 	s.scenario = false;
 	s.multiplayer = false;
 	s.playernum = 0;

=== modified file 'src/network/netclient.cc'
--- src/network/netclient.cc	2016-11-20 09:12:29 +0000
+++ src/network/netclient.cc	2017-01-23 12:20:29 +0000
@@ -734,7 +734,7 @@
 	case NETCMD_SETTING_TRIBES: {
 		d->settings.tribes.clear();
 		for (uint8_t i = packet.unsigned_8(); i; --i) {
-			TribeBasicInfo info = Widelands::Tribes::tribeinfo(packet.string());
+			TribeBasicInfo info = Widelands::tribeinfo(packet.string());
 
 			// Get initializations (we have to do this locally, for translations)
 			LuaInterface lua;

=== modified file 'src/network/nethost.cc'
--- src/network/nethost.cc	2017-01-01 19:29:01 +0000
+++ src/network/nethost.cc	2017-01-23 12:20:29 +0000
@@ -590,7 +590,7 @@
 	d->syncreport_pending = false;
 	d->syncreport_time = 0;
 
-	d->settings.tribes = Widelands::Tribes::get_all_tribeinfos();
+	d->settings.tribes = Widelands::get_all_tribeinfos();
 	set_multiplayer_game_settings();
 	d->settings.playernum = UserSettings::none();
 	d->settings.usernum = 0;

=== modified file 'src/scripting/lua_bases.cc'
--- src/scripting/lua_bases.cc	2016-10-21 08:21:41 +0000
+++ src/scripting/lua_bases.cc	2017-01-23 12:20:29 +0000
@@ -219,7 +219,7 @@
 	}
 	EditorGameBase& egbase = get_egbase(L);
 	const std::string tribe_name = luaL_checkstring(L, 2);
-	if (!egbase.tribes().tribe_exists(tribe_name)) {
+	if (!Widelands::tribe_exists(tribe_name)) {
 		report_error(L, "Tribe %s does not exist", tribe_name.c_str());
 	}
 	const TribeDescr* descr =

=== modified file 'src/scripting/lua_map.cc'
--- src/scripting/lua_map.cc	2017-01-22 09:42:03 +0000
+++ src/scripting/lua_map.cc	2017-01-23 12:20:29 +0000
@@ -2723,7 +2723,7 @@
 int LuaWareDescription::is_construction_material(lua_State* L) {
 	std::string tribename = luaL_checkstring(L, -1);
 	const Tribes& tribes = get_egbase(L).tribes();
-	if (tribes.tribe_exists(tribename)) {
+	if (Widelands::tribe_exists(tribename)) {
 		const DescriptionIndex& ware_index = tribes.safe_ware_index(get()->name());
 		int tribeindex = tribes.tribe_index(tribename);
 		lua_pushboolean(L, tribes.get_tribe_descr(tribeindex)->is_construction_material(ware_index));

=== modified file 'src/website/map_object_info.cc'
--- src/website/map_object_info.cc	2016-12-05 09:24:10 +0000
+++ src/website/map_object_info.cc	2017-01-23 12:20:29 +0000
@@ -479,7 +479,7 @@
 	egbase.mutable_tribes()->postload();  // Make sure that all values have been set.
 	const Tribes& tribes = egbase.tribes();
 
-	std::vector<TribeBasicInfo> tribeinfos = tribes.get_all_tribeinfos();
+	std::vector<TribeBasicInfo> tribeinfos = Widelands::get_all_tribeinfos();
 	for (size_t tribe_index = 0; tribe_index < tribeinfos.size(); ++tribe_index) {
 		const TribeBasicInfo& tribe_info = tribeinfos[tribe_index];
 		log("\n\n=========================\nWriting tribe: %s\n=========================\n",

=== modified file 'src/wui/playerdescrgroup.cc'
--- src/wui/playerdescrgroup.cc	2016-10-24 14:04:00 +0000
+++ src/wui/playerdescrgroup.cc	2017-01-23 12:20:29 +0000
@@ -161,7 +161,7 @@
 			}
 			d->btnPlayerType->set_title(title);
 
-			TribeBasicInfo info = Widelands::Tribes::tribeinfo(player.tribe);
+			TribeBasicInfo info = Widelands::tribeinfo(player.tribe);
 			if (!tribenames_[player.tribe].size()) {
 				// Tribe's localized name
 				tribenames_[player.tribe] = info.descname;


Follow ups