← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/militarysites into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/militarysites into lp:widelands.

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/militarysites/+merge/280069

Cleaning up some more historical baggage: Militarysites no longer inherit from productionsites.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/militarysites into lp:widelands.
=== modified file 'src/logic/militarysite.cc'
--- src/logic/militarysite.cc	2015-11-21 11:34:10 +0000
+++ src/logic/militarysite.cc	2015-12-09 20:23:44 +0000
@@ -46,8 +46,8 @@
 												 const LuaTable& table,
 												 const EditorGameBase& egbase)
 	:
-	ProductionSiteDescr
-		(init_descname, "", MapObjectType::MILITARYSITE, table, egbase),
+	BuildingDescr
+		(init_descname, MapObjectType::MILITARYSITE, table, egbase),
 	m_conquer_radius     (0),
 	m_num_soldiers       (0),
 	m_heal_per_second    (0)
@@ -89,7 +89,7 @@
 */
 
 MilitarySite::MilitarySite(const MilitarySiteDescr & ms_descr) :
-ProductionSite(ms_descr),
+Building(ms_descr),
 m_didconquer  (false),
 m_capacity    (ms_descr.get_max_number_of_soldiers()),
 m_nexthealtime(0),
@@ -151,7 +151,7 @@
 
 void MilitarySite::init(EditorGameBase & egbase)
 {
-	ProductionSite::init(egbase);
+	Building::init(egbase);
 
 	upcast(Game, game, &egbase);
 
@@ -180,7 +180,7 @@
 */
 void MilitarySite::set_economy(Economy * const e)
 {
-	ProductionSite::set_economy(e);
+	Building::set_economy(e);
 
 	if (m_normal_soldier_request && e)
 		m_normal_soldier_request->set_economy(e);
@@ -204,10 +204,15 @@
 			 	 	(egbase.map().get_fcoords(get_position()), descr().get_conquers())),
 			 m_defeating_player);
 
-	ProductionSite::cleanup(egbase);
-
-	// Note that removing workers during ProductionSite::cleanup can generate
-	// new requests; that's why we delete it at the end of this function.
+	Building::cleanup(egbase);
+
+	// Evict soldiers to get rid of requests
+	while (m_capacity > 0) {
+		update_soldier_request();
+		--m_capacity;
+	}
+	update_soldier_request();
+
 	m_normal_soldier_request.reset();
 	m_upgrade_soldier_request.reset();
 }
@@ -558,12 +563,12 @@
 void MilitarySite::act(Game & game, uint32_t const data)
 {
 	// TODO(unknown): do all kinds of stuff, but if you do nothing, let
-	// ProductionSite::act() handle all this. Also note, that some ProductionSite
-	// commands rely, that ProductionSite::act() is not called for a certain
+	// Building::act() handle all this. Also note, that some Building
+	// commands rely, that Building::act() is not called for a certain
 	// period (like cmdAnimation). This should be reworked.
 	// Maybe a new queueing system like MilitaryAct could be introduced.
 
-	ProductionSite::act(game, data);
+	Building::act(game, data);
 
 	const int32_t timeofgame = game.get_gametime();
 	if (m_normal_soldier_request && m_upgrade_soldier_request)
@@ -624,7 +629,7 @@
  */
 void MilitarySite::remove_worker(Worker & w)
 {
-	ProductionSite::remove_worker(w);
+	Building::remove_worker(w);
 
 	if (upcast(Soldier, soldier, &w))
 		pop_soldier_job(soldier, nullptr);

=== modified file 'src/logic/militarysite.h'
--- src/logic/militarysite.h	2015-11-11 09:52:55 +0000
+++ src/logic/militarysite.h	2015-12-09 20:23:44 +0000
@@ -23,8 +23,9 @@
 #include <memory>
 
 #include "base/macros.h"
+#include "economy/request.h"
 #include "logic/attackable.h"
-#include "logic/productionsite.h"
+#include "logic/building.h"
 #include "logic/requirements.h"
 #include "logic/soldiercontrol.h"
 #include "scripting/lua_table.h"
@@ -34,7 +35,7 @@
 class Soldier;
 class World;
 
-class MilitarySiteDescr : public ProductionSiteDescr {
+class MilitarySiteDescr : public BuildingDescr {
 public:
 	MilitarySiteDescr(const std::string& init_descname, const LuaTable& t, const EditorGameBase& egbase);
 	~MilitarySiteDescr() override {}
@@ -65,7 +66,7 @@
 };
 
 class MilitarySite :
-	public ProductionSite, public SoldierControl, public Attackable
+	public Building, public SoldierControl, public Attackable
 {
 	friend class MapBuildingdataPacket;
 	MO_DESCR(MilitarySiteDescr)

=== modified file 'src/map_io/map_buildingdata_packet.cc'
--- src/map_io/map_buildingdata_packet.cc	2015-11-11 09:53:54 +0000
+++ src/map_io/map_buildingdata_packet.cc	2015-12-09 20:23:44 +0000
@@ -59,7 +59,7 @@
 constexpr uint16_t kCurrentPacketVersionConstructionsite = 3;
 constexpr uint16_t kCurrentPacketPFBuilding = 1;
 constexpr uint16_t kCurrentPacketVersionWarehouse = 6;
-constexpr uint16_t kCurrentPacketVersionMilitarysite = 4;
+constexpr uint16_t kCurrentPacketVersionMilitarysite = 5;
 constexpr uint16_t kCurrentPacketVersionProductionsite = 5;
 constexpr uint16_t kCurrentPacketVersionTrainingsite = 4;
 
@@ -187,12 +187,12 @@
 						read_constructionsite(*constructionsite, fr, game, mol);
 					} else if (upcast(DismantleSite, dms, &building)) {
 						read_dismantlesite(*dms, fr, game, mol);
+					} else if (upcast(MilitarySite, militarysite, &building)) {
+						read_militarysite(*militarysite, fr, game, mol);
 					} else if (upcast(Warehouse, warehouse, &building)) {
 						read_warehouse(*warehouse, fr, game, mol);
 					} else if (upcast(ProductionSite, productionsite, &building)) {
-						if (upcast(MilitarySite, militarysite, productionsite)) {
-							read_militarysite(*militarysite, fr, game, mol);
-						} else if (upcast(TrainingSite, trainingsite, productionsite)) {
+						if (upcast(TrainingSite, trainingsite, productionsite)) {
 							read_trainingsite(*trainingsite, fr, game, mol);
 						} else {
 							read_productionsite(*productionsite, fr, game, mol);
@@ -509,8 +509,6 @@
 	try {
 		uint16_t const packet_version = fr.unsigned_16();
 		if (packet_version == kCurrentPacketVersionMilitarysite) {
-			read_productionsite(militarysite, fr, game, mol);
-
 			militarysite.m_normal_soldier_request.reset();
 
 			if (fr.unsigned_8()) {
@@ -946,13 +944,12 @@
 				write_constructionsite(*constructionsite, fw, game, mos);
 			} else if (upcast(DismantleSite const, dms, building)) {
 				write_dismantlesite(*dms, fw, game, mos);
+			} else if (upcast(MilitarySite const, militarysite, building)) {
+				write_militarysite(*militarysite, fw, game, mos);
 			} else if (upcast(Warehouse const, warehouse, building)) {
 				write_warehouse (*warehouse, fw, game, mos);
 			} else if (upcast(ProductionSite const, productionsite, building)) {
-				if (upcast(MilitarySite const, militarysite, productionsite)) {
-					write_militarysite(*militarysite, fw, game, mos);
-				}
-				else if (upcast(TrainingSite const, trainingsite, productionsite)) {
+				if (upcast(TrainingSite const, trainingsite, productionsite)) {
 					write_trainingsite(*trainingsite, fw, game, mos);
 				}
 				else {
@@ -1135,7 +1132,6 @@
 	 MapObjectSaver & mos)
 {
 	fw.unsigned_16(kCurrentPacketVersionMilitarysite);
-	write_productionsite(militarysite, fw, game, mos);
 
 	if (militarysite.m_normal_soldier_request) {
 		fw.unsigned_8(1);

=== modified file 'src/scripting/lua_map.cc'
--- src/scripting/lua_map.cc	2015-11-21 11:47:05 +0000
+++ src/scripting/lua_map.cc	2015-12-09 20:23:44 +0000
@@ -4938,7 +4938,6 @@
 	lua_pop(L, 1); // Pop the meta table
 
 	register_class<LuaMilitarySiteDescription>(L, "map", true);
-	add_parent<LuaMilitarySiteDescription, LuaProductionSiteDescription>(L);
 	add_parent<LuaMilitarySiteDescription, LuaBuildingDescription>(L);
 	add_parent<LuaMilitarySiteDescription, LuaMapObjectDescription>(L);
 	lua_pop(L, 1); // Pop the meta table

=== modified file 'src/scripting/lua_map.h'
--- src/scripting/lua_map.h	2015-11-03 12:12:02 +0000
+++ src/scripting/lua_map.h	2015-12-09 20:23:44 +0000
@@ -328,17 +328,17 @@
 };
 
 
-class LuaMilitarySiteDescription : public LuaProductionSiteDescription {
+class LuaMilitarySiteDescription : public LuaBuildingDescription {
 public:
 	LUNA_CLASS_HEAD(LuaMilitarySiteDescription);
 
 	virtual ~LuaMilitarySiteDescription() {}
 
 	LuaMilitarySiteDescription() {}
-	LuaMilitarySiteDescription(const Widelands::ProductionSiteDescr* const militarysitedescr)
-		: LuaProductionSiteDescription(militarysitedescr) {
+	LuaMilitarySiteDescription(const Widelands::MilitarySiteDescr* const militarysitedescr)
+		: LuaBuildingDescription(militarysitedescr) {
 	}
-	LuaMilitarySiteDescription(lua_State* L) : LuaProductionSiteDescription(L) {
+	LuaMilitarySiteDescription(lua_State* L) : LuaBuildingDescription(L) {
 	}
 
 	/*
@@ -367,7 +367,7 @@
 	virtual ~LuaTrainingSiteDescription() {}
 
 	LuaTrainingSiteDescription() {}
-	LuaTrainingSiteDescription(const Widelands::ProductionSiteDescr* const trainingsitedescr)
+	LuaTrainingSiteDescription(const Widelands::TrainingSiteDescr* const trainingsitedescr)
 		: LuaProductionSiteDescription(trainingsitedescr) {
 	}
 	LuaTrainingSiteDescription(lua_State* L) : LuaProductionSiteDescription(L) {

=== modified file 'tribes/buildings/militarysites/atlanteans/castle/init.lua'
--- tribes/buildings/militarysites/atlanteans/castle/init.lua	2015-11-05 12:53:49 +0000
+++ tribes/buildings/militarysites/atlanteans/castle/init.lua	2015-12-09 20:23:44 +0000
@@ -38,10 +38,6 @@
       prohibited_till = 1500
    },
 
-   outputs = {
-      "atlanteans_soldier",
-   },
-
    max_soldiers = 12,
    heal_per_second = 200,
    conquers = 12,

=== modified file 'tribes/buildings/militarysites/atlanteans/guardhall/init.lua'
--- tribes/buildings/militarysites/atlanteans/guardhall/init.lua	2015-11-05 12:53:49 +0000
+++ tribes/buildings/militarysites/atlanteans/guardhall/init.lua	2015-12-09 20:23:44 +0000
@@ -33,10 +33,6 @@
       }
    },
 
-   outputs = {
-      "atlanteans_soldier",
-   },
-
    max_soldiers = 7,
    heal_per_second = 140,
    conquers = 7,

=== modified file 'tribes/buildings/militarysites/atlanteans/guardhouse/init.lua'
--- tribes/buildings/militarysites/atlanteans/guardhouse/init.lua	2015-11-05 12:53:49 +0000
+++ tribes/buildings/militarysites/atlanteans/guardhouse/init.lua	2015-12-09 20:23:44 +0000
@@ -31,11 +31,6 @@
       }
    },
 
-   -- TODO(GunChleoc): Get rid of this when we inherit from BuildingDescr directly.
-   outputs = {
-      "atlanteans_soldier",
-   },
-
    max_soldiers = 2,
    heal_per_second = 75,
    conquers = 6,

=== modified file 'tribes/buildings/militarysites/atlanteans/tower/init.lua'
--- tribes/buildings/militarysites/atlanteans/tower/init.lua	2015-11-05 12:53:49 +0000
+++ tribes/buildings/militarysites/atlanteans/tower/init.lua	2015-12-09 20:23:44 +0000
@@ -37,10 +37,6 @@
       }
    },
 
-   outputs = {
-      "atlanteans_soldier",
-   },
-
    max_soldiers = 4,
    heal_per_second = 120,
    conquers = 9,

=== modified file 'tribes/buildings/militarysites/atlanteans/tower_high/init.lua'
--- tribes/buildings/militarysites/atlanteans/tower_high/init.lua	2015-11-05 12:53:49 +0000
+++ tribes/buildings/militarysites/atlanteans/tower_high/init.lua	2015-12-09 20:23:44 +0000
@@ -29,10 +29,6 @@
 
    aihints = {},
 
-   outputs = {
-      "atlanteans_soldier",
-   },
-
    max_soldiers = 5,
    heal_per_second = 170,
    conquers = 9,

=== modified file 'tribes/buildings/militarysites/atlanteans/tower_small/init.lua'
--- tribes/buildings/militarysites/atlanteans/tower_small/init.lua	2015-11-05 12:53:49 +0000
+++ tribes/buildings/militarysites/atlanteans/tower_small/init.lua	2015-12-09 20:23:44 +0000
@@ -32,10 +32,6 @@
       fighting = true
    },
 
-   outputs = {
-      "atlanteans_soldier",
-   },
-
    max_soldiers = 3,
    heal_per_second = 100,
    conquers = 5,

=== modified file 'tribes/buildings/militarysites/barbarians/barrier/init.lua'
--- tribes/buildings/militarysites/barbarians/barrier/init.lua	2015-11-05 12:53:49 +0000
+++ tribes/buildings/militarysites/barbarians/barrier/init.lua	2015-12-09 20:23:44 +0000
@@ -37,10 +37,6 @@
       }
    },
 
-   outputs = {
-      "barbarians_soldier",
-   },
-
    aihints = {},
 
    max_soldiers = 5,

=== modified file 'tribes/buildings/militarysites/barbarians/citadel/init.lua'
--- tribes/buildings/militarysites/barbarians/citadel/init.lua	2015-11-05 12:53:49 +0000
+++ tribes/buildings/militarysites/barbarians/citadel/init.lua	2015-12-09 20:23:44 +0000
@@ -43,10 +43,6 @@
 
    aihints = {},
 
-   outputs = {
-      "barbarians_soldier",
-   },
-
    max_soldiers = 12,
    heal_per_second = 220,
    conquers = 12,

=== modified file 'tribes/buildings/militarysites/barbarians/fortress/init.lua'
--- tribes/buildings/militarysites/barbarians/fortress/init.lua	2015-11-05 12:53:49 +0000
+++ tribes/buildings/militarysites/barbarians/fortress/init.lua	2015-12-09 20:23:44 +0000
@@ -49,10 +49,6 @@
       prohibited_till=1500
    },
 
-   outputs = {
-      "barbarians_soldier",
-   },
-
    max_soldiers = 8,
    heal_per_second = 170,
    conquers = 11,

=== modified file 'tribes/buildings/militarysites/barbarians/sentry/init.lua'
--- tribes/buildings/militarysites/barbarians/sentry/init.lua	2015-11-05 12:53:49 +0000
+++ tribes/buildings/militarysites/barbarians/sentry/init.lua	2015-12-09 20:23:44 +0000
@@ -41,10 +41,6 @@
       mountain_conqueror = true
    },
 
-   outputs = {
-      "barbarians_soldier",
-   },
-
    max_soldiers = 2,
    heal_per_second = 80,
    conquers = 6,

=== modified file 'tribes/buildings/militarysites/barbarians/tower/init.lua'
--- tribes/buildings/militarysites/barbarians/tower/init.lua	2015-11-05 12:53:49 +0000
+++ tribes/buildings/militarysites/barbarians/tower/init.lua	2015-12-09 20:23:44 +0000
@@ -46,10 +46,6 @@
       prohibited_till = 1200
    },
 
-   outputs = {
-      "barbarians_soldier",
-   },
-
    max_soldiers = 5,
    heal_per_second = 150,
    conquers = 8,

=== modified file 'tribes/buildings/militarysites/empire/barrier/init.lua'
--- tribes/buildings/militarysites/empire/barrier/init.lua	2015-11-05 12:53:49 +0000
+++ tribes/buildings/militarysites/empire/barrier/init.lua	2015-12-09 20:23:44 +0000
@@ -43,10 +43,6 @@
       fighting = true
    },
 
-   outputs = {
-      "empire_soldier",
-   },
-
    max_soldiers = 5,
    heal_per_second = 130,
    conquers = 8,

=== modified file 'tribes/buildings/militarysites/empire/blockhouse/init.lua'
--- tribes/buildings/militarysites/empire/blockhouse/init.lua	2015-11-05 12:53:49 +0000
+++ tribes/buildings/militarysites/empire/blockhouse/init.lua	2015-12-09 20:23:44 +0000
@@ -28,10 +28,6 @@
 
    aihints = {},
 
-   outputs = {
-      "empire_soldier",
-   },
-
    max_soldiers = 1,
    heal_per_second = 60, -- very low -> smallest building
    conquers = 6,

=== modified file 'tribes/buildings/militarysites/empire/castle/init.lua'
--- tribes/buildings/militarysites/empire/castle/init.lua	2015-11-05 12:53:49 +0000
+++ tribes/buildings/militarysites/empire/castle/init.lua	2015-12-09 20:23:44 +0000
@@ -32,10 +32,6 @@
 
    aihints = {},
 
-   outputs = {
-      "empire_soldier",
-   },
-
    max_soldiers = 12,
    heal_per_second = 220,
    conquers = 12,

=== modified file 'tribes/buildings/militarysites/empire/fortress/init.lua'
--- tribes/buildings/militarysites/empire/fortress/init.lua	2015-11-05 12:53:49 +0000
+++ tribes/buildings/militarysites/empire/fortress/init.lua	2015-12-09 20:23:44 +0000
@@ -38,10 +38,6 @@
       }
    },
 
-   outputs = {
-      "empire_soldier",
-   },
-
    aihints = {
       expansion = true,
       fighting = true,

=== modified file 'tribes/buildings/militarysites/empire/outpost/init.lua'
--- tribes/buildings/militarysites/empire/outpost/init.lua	2015-11-05 12:53:49 +0000
+++ tribes/buildings/militarysites/empire/outpost/init.lua	2015-12-09 20:23:44 +0000
@@ -34,10 +34,6 @@
       prohibited_till=600
    },
 
-   outputs = {
-      "empire_soldier",
-   },
-
    max_soldiers = 3,
    heal_per_second = 100,
    conquers = 7,

=== modified file 'tribes/buildings/militarysites/empire/sentry/init.lua'
--- tribes/buildings/militarysites/empire/sentry/init.lua	2015-11-05 12:53:49 +0000
+++ tribes/buildings/militarysites/empire/sentry/init.lua	2015-12-09 20:23:44 +0000
@@ -40,10 +40,6 @@
       mountain_conqueror = true
    },
 
-   outputs = {
-      "empire_soldier",
-   },
-
    max_soldiers = 2,
    heal_per_second = 80,
    conquers = 6,

=== modified file 'tribes/buildings/militarysites/empire/tower/init.lua'
--- tribes/buildings/militarysites/empire/tower/init.lua	2015-11-05 12:53:49 +0000
+++ tribes/buildings/militarysites/empire/tower/init.lua	2015-12-09 20:23:44 +0000
@@ -40,10 +40,6 @@
       prohibited_till = 300
    },
 
-   outputs = {
-      "empire_soldier",
-   },
-
    max_soldiers = 5,
    heal_per_second = 150,
    conquers = 9,

=== modified file 'tribes/scripting/help/building_help.lua'
--- tribes/scripting/help/building_help.lua	2015-12-03 21:12:12 +0000
+++ tribes/scripting/help/building_help.lua	2015-12-09 20:23:44 +0000
@@ -174,15 +174,16 @@
 
 
 -- RST
--- .. function building_help_general_string(building_description)
+-- .. function building_help_general_string(tribe, building_description)
 --
 --    Creates the string for the general section in building help
 --
+--    :arg tribe: The :class:`LuaTribeDescription` for the tribe that has this building.
 --    :arg building_description: The :class:`LuaBuildingDescription` for the building
 --                               that we are displaying this help for.
 --    :returns: rt of the formatted text
 --
-function building_help_general_string(building_description)
+function building_help_general_string(tribe, building_description)
    -- TRANSLATORS: Heading for a flavour text in the building help.
    local result = rt(h2(_"Lore")) ..
       rt("image=" .. building_description.representative_image, p(building_helptext_lore()))
@@ -199,12 +200,13 @@
 -- TODO(GunChleoc) use aihints for gamekeeper, forester?
    local representative_resource = nil
    if (building_description.type_name == "productionsite" or
-       building_description.type_name == "militarysite" or
        building_description.type_name == "trainingsite") then
       representative_resource = building_description.output_ware_types[1]
       if(not representative_resource) then
          representative_resource = building_description.output_worker_types[1]
       end
+   elseif (building_description.type_name == "militarysite") then
+      representative_resource = wl.Game():get_worker_description(tribe.soldier)
 -- TODO(GunChleoc) need a bob_descr for the ship -> port and shipyard
 -- TODO(GunChleoc) create descr objects for flag, portdock, ...
    elseif (building_description.is_port or building_description.name == "shipyard") then
@@ -720,33 +722,33 @@
    include(building_description.helptext_script)
 
    if (building_description.type_name == "productionsite") then
-      return building_help_general_string(building_description) ..
+      return building_help_general_string(tribe, building_description) ..
          building_help_dependencies_production(tribe, building_description) ..
          building_help_crew_string(tribe, building_description) ..
          building_help_building_section(building_description) ..
          building_help_production_section()
    elseif (building_description.type_name == "militarysite") then
-      return building_help_general_string(building_description) ..
+      return building_help_general_string(tribe, building_description) ..
          building_help_building_section(building_description)
    elseif (building_description.type_name == "warehouse") then
       if (building_description.is_port) then
-         return building_help_general_string(building_description) ..
+         return building_help_general_string(tribe, building_description) ..
             -- TODO(GunChleoc) expedition costs here?
             building_help_building_section(building_description) ..
             building_help_production_section()
       else
-         return building_help_general_string(building_description) ..
+         return building_help_general_string(tribe, building_description) ..
             building_help_building_section(building_description)
       end
    elseif (building_description.type_name == "trainingsite") then
-      return building_help_general_string(building_description) ..
+      return building_help_general_string(tribe, building_description) ..
          building_help_dependencies_training(tribe, building_description) ..
          building_help_crew_string(tribe, building_description) ..
          building_help_building_section(building_description) ..building_help_production_section()
    elseif (building_description.type_name == "constructionsite" or
             building_description.type_name == "dismantlesite") then
             -- TODO(GunChleoc) Get them a crew string for the builder
-      return building_help_general_string(building_description)
+      return building_help_general_string(tribe, building_description)
    else
       return ""
    end


Follow ups