widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #02435
Re: [Merge] lp:~widelands-dev/widelands/bug-1341081 into lp:widelands
Since I did a resubmit, we have a new diff for comments :)
Diff comments:
> === modified file 'campaigns/atl01.wmf/scripting/init.lua'
> --- campaigns/atl01.wmf/scripting/init.lua 2014-07-17 15:26:32 +0000
> +++ campaigns/atl01.wmf/scripting/init.lua 2014-07-22 16:03:20 +0000
> @@ -324,7 +324,7 @@
> if not f.immovable then return end
>
> -- Flags are not so interesting
> - if f.immovable.type == "flag" and
> + if f.immovable.descr.type_name == "flag" and
> (f.tln.immovable and is_building(f.tln.immovable)) then
> f = f.tln
> end
>
> === modified file 'campaigns/tutorial01.wmf/scripting/init.lua'
> --- campaigns/tutorial01.wmf/scripting/init.lua 2014-07-17 15:26:32 +0000
> +++ campaigns/tutorial01.wmf/scripting/init.lua 2014-07-22 16:03:20 +0000
> @@ -311,7 +311,7 @@
> end
>
> -- buildings and constructionsite have a flag
> - if is_building(i) or i.type == "constructionsite" then
> + if is_building(i) or i.descr.type_name == "constructionsite" then
> registered_player_immovables[_fmt(i.fields[1].brn)] = true
> end
> end
> @@ -350,15 +350,15 @@
> -- Allows constructionsites for the given buildings, all others are invalid
> -- as is any other immovable build by the player
> function allow_constructionsite(i, buildings)
> - if i.type == "constructionsite" then
> + if i.descr.type_name == "constructionsite" then
> if not buildings then return i end
> for idx,n in ipairs(buildings) do
> if i.building == n then return i end
> end
> return false
> - elseif i.type == "flag" then
> + elseif i.descr.type_name == "flag" then
> local tr = i.fields[1].tln.immovable
> - if tr and tr.type == "constructionsite" then
> + if tr and tr.descr.type_name == "constructionsite" then
> return allow_constructionsite(tr, buildings)
> end
> end
> @@ -442,7 +442,7 @@
> blocker:lift_blocks()
>
> -- Wait for flag
> - while not (f.immovable and f.immovable.type == "flag") do sleep(300) end
> + while not (f.immovable and f.immovable.name == "flag") do sleep(300) end
> o.done = true
>
> sleep(300)
> @@ -506,7 +506,7 @@
>
> local function _rip_road()
> for idx,f in ipairs(cs.fields[1].brn:region(2)) do
> - if f.immovable and f.immovable.type == "road" then
> + if f.immovable and f.immovable.descr.type_name == "road" then
> click_on_field(f)
> click_on_panel(wl.ui.MapView().windows.
> field_action.buttons.destroy_road, 300)
> @@ -671,7 +671,7 @@
> local function _find_nearby_flag()
> for i=2,8 do
> for idx, f in ipairs(conquer_field:region(i)) do
> - if f.immovable and f.immovable.type == "flag" then
> + if f.immovable and f.immovable.name == "flag" then
> return f
> end
> end
>
> === modified file 'scripting/format_help.lua'
> --- scripting/format_help.lua 2014-07-17 09:42:13 +0000
> +++ scripting/format_help.lua 2014-07-22 16:03:20 +0000
> @@ -330,23 +330,23 @@
> image_line("tribes/" .. tribename .. "/" .. resourcename .. "/menu.png", 1, p(purpose))
> if (note) then result = result .. rt(h3(_"Note:")) .. rt(p(note)) end
>
> - if(building_description.type == "productionsite") then
> + if(building_description.type_name == "productionsite") then
> if(building_description.workarea_radius and building_description.workarea_radius > 0) then
> result = result .. text_line(_"Working radius:", building_description.workarea_radius)
> end
>
> - elseif(building_description.type == "warehouse") then
> + elseif(building_description.type_name == "warehouse") then
> result = result .. rt(h3(_"Healing:")
> .. p(_"Garrisoned soldiers heal %s per second":bformat(building_description.heal_per_second)))
> result = result .. text_line(_"Conquer range:", building_description.conquers)
>
> - elseif(building_description.type == "militarysite") then
> + elseif(building_description.type_name == "militarysite") then
> result = result .. rt(h3(_"Healing:")
> .. p(_"Garrisoned soldiers heal %s per second":bformat(building_description.heal_per_second)))
> result = result .. text_line(_"Capacity:", building_description.max_number_of_soldiers)
> result = result .. text_line(_"Conquer range:", building_description.conquers)
>
> - elseif(building_description.type == "trainingsite") then
> + elseif(building_description.type_name == "trainingsite") then
> result = result .. rt(h3(_"Training:"))
> if(building_description.max_attack and building_description.min_attack) then
> -- TRANSLATORS: %1$s = Health, Evade, Attack or Defense. %2$s and %3$s are numbers.
> @@ -693,7 +693,7 @@
> local building_description = wl.Game():get_building_description(tribename, building_description.name)
> local result = ""
>
> - if(building_description.type == "productionsite" or building_description.type == "trainingsite") then
> + if(building_description.type_name == "productionsite" or building_description.type_name == "trainingsite") then
>
> result = result .. rt(h2(_"Workers")) .. rt(h3(_"Crew required:"))
>
>
> === modified file 'scripting/infrastructure.lua'
> --- scripting/infrastructure.lua 2014-06-18 18:08:20 +0000
> +++ scripting/infrastructure.lua 2014-07-22 16:03:20 +0000
> @@ -169,8 +169,8 @@
> --
> -- :returns: true if the immovable is a building
> function is_building(immovable)
> - return immovable.type == "productionsite" or
> - immovable.type == "warehouse" or
> - immovable.type == "militarysite" or
> - immovable.type == "trainingsite"
> + return immovable.descr.type_name == "productionsite" or
> + immovable.descr.type_name == "warehouse" or
> + immovable.descr.type_name == "militarysite" or
> + immovable.descr.type_name == "trainingsite"
> end
>
> === modified file 'src/ai/defaultai.cc'
> --- src/ai/defaultai.cc 2014-07-17 12:34:35 +0000
> +++ src/ai/defaultai.cc 2014-07-22 16:03:20 +0000
> @@ -294,7 +294,7 @@
> // Read all interesting data from ware producing buildings
> if (typeid(bld) == typeid(ProductionSite_Descr)) {
> const ProductionSite_Descr& prod =
> - ref_cast<ProductionSite_Descr const, Building_Descr const>(bld);
> + ref_cast<ProductionSite_Descr const, Building_Descr const>(bld);
> bo.type = bld.get_ismine() ? BuildingObserver::MINE : BuildingObserver::PRODUCTIONSITE;
> container_iterate_const(BillOfMaterials, prod.inputs(), j)
> bo.inputs_.push_back(j.current->first);
>
> === modified file 'src/economy/flag.cc'
> --- src/economy/flag.cc 2014-07-14 14:40:42 +0000
> +++ src/economy/flag.cc 2014-07-22 16:03:20 +0000
> @@ -38,7 +38,11 @@
>
> namespace Widelands {
>
> -Map_Object_Descr g_flag_descr("flag", "Flag");
> +Flag_Descr g_flag_descr("flag", "Flag");
> +
> +const Flag_Descr& Flag::descr() const {
> + return g_flag_descr;
> +}
>
> /**
> * Create the flag. Initially, it doesn't have any attachments.
> @@ -146,11 +150,6 @@
> m_position = coords;
> }
>
> -int32_t Flag::get_type() const
> -{
> - return FLAG;
> -}
> -
> int32_t Flag::get_size() const
> {
> return SMALL;
>
> === modified file 'src/economy/flag.h'
> --- src/economy/flag.h 2014-07-14 14:40:42 +0000
> +++ src/economy/flag.h 2014-07-22 16:03:20 +0000
> @@ -23,6 +23,7 @@
> #include <list>
> #include <vector>
>
> +#include "base/macros.h"
> #include "logic/immovable.h"
> #include "economy/routing_node.h"
>
> @@ -32,7 +33,21 @@
> struct Road;
> class WareInstance;
>
> -
> +class Flag_Descr : public Map_Object_Descr {
> +public:
> + Flag_Descr(char const* const _name, char const* const _descname)
> + :
> + Map_Object_Descr(_name, _descname),
> + m_typename ("flag")
> + {}
> + virtual ~Flag_Descr() override {}
> +
> + const std::string& type_name() const override {return m_typename;}
> +
> +private:
> + std::string const m_typename;
> + DISALLOW_COPY_AND_ASSIGN(Flag_Descr);
> +};
>
> /**
> * Flag represents a flag, obviously.
> @@ -59,6 +74,8 @@
> friend struct Map_Waredata_Data_Packet; // has to look at pending wares
> friend struct Router;
>
> + const Flag_Descr& descr() const;
> +
> Flag(); /// empty flag for savegame loading
> Flag(Editor_Game_Base &, Player & owner, Coords); /// create a new flag
> virtual ~Flag();
> @@ -66,8 +83,6 @@
> void load_finish(Editor_Game_Base &) override;
> virtual void destroy(Editor_Game_Base &) override;
>
> - virtual int32_t get_type () const override;
> - char const * type_name() const override {return "flag";}
> virtual int32_t get_size () const override;
> virtual bool get_passable() const override;
>
> @@ -165,6 +180,7 @@
> FlagJobs m_flag_jobs;
> };
>
> +extern Flag_Descr g_flag_descr;
> }
>
> #endif // end of include guard: WL_ECONOMY_FLAG_H
>
> === modified file 'src/economy/fleet.cc'
> --- src/economy/fleet.cc 2014-07-14 22:18:03 +0000
> +++ src/economy/fleet.cc 2014-07-22 16:03:20 +0000
> @@ -40,17 +40,16 @@
>
> namespace Widelands {
>
> -namespace {
> -
> +namespace {
> // Every Map_Object() needs to have a description. So we make a dummy one for
> // Fleet.
> -Map_Object_Descr* fleet_description() {
> - static Map_Object_Descr fleet_descr("fleet", "Fleet");
> - return &fleet_descr;
> -}
> -
> +Fleet_Descr g_fleet_descr("fleet", "Fleet");
> } // namespace
>
> +const Fleet_Descr& Fleet::descr() const {
> + return g_fleet_descr;
> +}
> +
> /**
> * Fleets are initialized empty.
> *
> @@ -59,22 +58,12 @@
> * The Fleet takes care of merging with existing fleets, if any.
> */
> Fleet::Fleet(Player & player) :
> - Map_Object(fleet_description()),
> + Map_Object(&g_fleet_descr),
> m_owner(player),
> m_act_pending(false)
> {
> }
>
> -int32_t Fleet::get_type() const
> -{
> - return FLEET;
> -}
> -
> -char const * Fleet::type_name() const
> -{
> - return "fleet";
> -}
> -
> /**
> * Whether the fleet is in fact useful for transporting goods.
> */
> @@ -171,7 +160,7 @@
> FCoords cur;
> while (astar.step(cur, cost)) {
> if (BaseImmovable * imm = cur.field->get_immovable()) {
> - if (imm->get_type() == PORTDOCK) {
> + if (imm->descr().type_name() == "portdock") {
> if (upcast(PortDock, dock, imm)) {
> if (dock->get_fleet() != this && dock->get_owner() == get_owner()) {
> dock->get_fleet()->merge(egbase, this);
> @@ -182,7 +171,7 @@
> }
>
> for (Bob * bob = cur.field->get_first_bob(); bob != nullptr; bob = bob->get_next_bob()) {
> - if (bob->get_bob_type() != Bob::SHIP)
> + if (bob->descr().type_name() == "ship")
> continue;
>
> if (upcast(Ship, ship, bob)) {
> @@ -475,7 +464,7 @@
> FCoords cur;
> while (!se.targets.empty() && astar.step(cur, cost)) {
> BaseImmovable * imm = cur.field->get_immovable();
> - if (!imm || imm->get_type() != PORTDOCK)
> + if (!imm || imm->descr().type_name() != "portdock")
> continue;
>
> if (upcast(PortDock, pd, imm)) {
>
> === modified file 'src/economy/fleet.h'
> --- src/economy/fleet.h 2014-07-05 16:41:51 +0000
> +++ src/economy/fleet.h 2014-07-22 16:03:20 +0000
> @@ -22,6 +22,7 @@
>
> #include <boost/shared_ptr.hpp>
>
> +#include "base/macros.h"
> #include "logic/instances.h"
>
> namespace Widelands {
> @@ -32,6 +33,22 @@
> struct RoutingNodeNeighbour;
> struct Ship;
>
> +class Fleet_Descr : public Map_Object_Descr {
> +public:
> + Fleet_Descr(char const* const _name, char const* const _descname)
> + :
> + Map_Object_Descr(_name, _descname),
> + m_typename ("fleet")
> + {}
> + virtual ~Fleet_Descr() override {}
> +
> + const std::string& type_name() const override {return m_typename;}
> +
> +private:
> + std::string const m_typename;
> + DISALLOW_COPY_AND_ASSIGN(Fleet_Descr);
> +};
> +
> /**
> * Manage all ships and ports of a player that are connected
> * by ocean.
> @@ -58,6 +75,8 @@
> PortPath() : cost(-1) {}
> };
>
> + const Fleet_Descr& descr() const;
> +
> Fleet(Player & player);
>
> Player * get_owner() const {return &m_owner;}
> @@ -69,9 +88,6 @@
>
> bool active() const;
>
> - virtual int32_t get_type() const override;
> - virtual char const * type_name() const override;
> -
> virtual void init(Editor_Game_Base &) override;
> virtual void cleanup(Editor_Game_Base &) override;
> void update(Editor_Game_Base &);
>
> === modified file 'src/economy/portdock.cc'
> --- src/economy/portdock.cc 2014-07-16 05:33:19 +0000
> +++ src/economy/portdock.cc 2014-07-22 16:03:20 +0000
> @@ -40,7 +40,19 @@
>
> namespace Widelands {
>
> -Map_Object_Descr g_portdock_descr("portdock", "Port Dock");
> +PortDock_Descr g_portdock_descr("portdock", "Port Dock");
> +
> +const PortDock_Descr& PortDock::descr() const {
> + return g_portdock_descr;
> +}
> +
> +
> +PortDock_Descr::PortDock_Descr(char const* const _name, char const* const _descname)
> + :
> + Map_Object_Descr(_name, _descname),
> + m_typename ("portdock")
> +{
> +}
>
> PortDock::PortDock(Warehouse* wh) :
> PlayerImmovable(g_portdock_descr),
> @@ -94,16 +106,6 @@
> return true;
> }
>
> -int32_t PortDock::get_type() const
> -{
> - return PORTDOCK;
> -}
> -
> -char const * PortDock::type_name() const
> -{
> - return "portdock";
> -}
> -
> PortDock::PositionList PortDock::get_positions
> (const Editor_Game_Base &) const
> {
>
> === modified file 'src/economy/portdock.h'
> --- src/economy/portdock.h 2014-07-14 14:40:42 +0000
> +++ src/economy/portdock.h 2014-07-22 16:03:20 +0000
> @@ -22,6 +22,7 @@
>
> #include <memory>
>
> +#include "base/macros.h"
> #include "logic/immovable.h"
> #include "logic/wareworker.h"
> #include "economy/shippingitem.h"
> @@ -34,6 +35,18 @@
> class Warehouse;
> class ExpeditionBootstrap;
>
> +class PortDock_Descr : public Map_Object_Descr {
> +public:
> + PortDock_Descr(char const* const _name, char const* const _descname);
> + virtual ~PortDock_Descr() override {}
> +
> + const std::string& type_name() const override {return m_typename;}
> +
> +private:
> + std::string const m_typename;
> + DISALLOW_COPY_AND_ASSIGN(PortDock_Descr);
> +};
> +
> /**
> * The PortDock occupies the fields in the water at which ships
> * dock at a port. As such, this class cooperates closely with
> @@ -62,6 +75,9 @@
> */
> class PortDock : public PlayerImmovable {
> public:
> +
> + const PortDock_Descr& descr() const;
> +
> PortDock(Warehouse* warehouse);
> virtual ~PortDock();
>
> @@ -76,8 +92,6 @@
>
> virtual int32_t get_size() const override;
> virtual bool get_passable() const override;
> - virtual int32_t get_type() const override;
> - virtual char const * type_name() const override;
>
> virtual Flag & base_flag() override;
> virtual PositionList get_positions
> @@ -156,6 +170,8 @@
> (Editor_Game_Base &, Map_Map_Object_Loader &, FileRead &);
> };
>
> +extern PortDock_Descr g_portdock_descr;
> +
> } // namespace Widelands
>
> #endif // end of include guard: WL_ECONOMY_PORTDOCK_H
>
> === modified file 'src/economy/road.cc'
> --- src/economy/road.cc 2014-07-14 14:40:42 +0000
> +++ src/economy/road.cc 2014-07-22 16:03:20 +0000
> @@ -33,7 +33,13 @@
> namespace Widelands {
>
> // dummy instance because Map_Object needs a description
> -const Map_Object_Descr g_road_descr("road", "Road");
> +namespace {
> +const Road_Descr g_road_descr("road", "Road");
> +}
> +
> +const Road_Descr& Road::descr() const {
> + return g_road_descr;
> +}
>
> bool Road::IsRoadDescr(Map_Object_Descr const * const descr)
> {
> @@ -105,11 +111,6 @@
> return road;
> }
>
> -int32_t Road::get_type() const
> -{
> - return ROAD;
> -}
> -
> int32_t Road::get_size() const
> {
> return SMALL;
>
> === modified file 'src/economy/road.h'
> --- src/economy/road.h 2014-07-14 14:40:42 +0000
> +++ src/economy/road.h 2014-07-22 16:03:20 +0000
> @@ -22,6 +22,7 @@
>
> #include <vector>
>
> +#include "base/macros.h"
> #include "logic/immovable.h"
> #include "logic/path.h"
> #include "logic/roadtype.h"
> @@ -30,6 +31,23 @@
> struct Carrier;
> class Request;
>
> +class Road_Descr : public Map_Object_Descr {
> +
> +public:
> + Road_Descr(char const* const _name, char const* const _descname)
> + :
> + Map_Object_Descr(_name, _descname),
> + m_typename ("road")
> + {}
> + virtual ~Road_Descr() override {}
> +
> + const std::string& type_name() const override {return m_typename;}
> +
> +private:
> + std::string const m_typename;
> + DISALLOW_COPY_AND_ASSIGN(Road_Descr);
> +};
> +
> /**
> * Road is a special object which connects two flags.
> * The Road itself is never rendered; however, the appropriate Field::roads are
> @@ -49,6 +67,8 @@
> friend class Map_Roaddata_Data_Packet; // For saving
> friend class Map_Road_Data_Packet; // For init()
>
> + const Road_Descr& descr() const;
> +
> static bool IsRoadDescr(Map_Object_Descr const *);
>
> enum FlagId {
> @@ -73,9 +93,7 @@
>
> Flag & get_flag(FlagId const flag) const {return *m_flags[flag];}
>
> - virtual int32_t get_type () const override;
> uint8_t get_roadtype() const {return m_type;}
> - char const * type_name() const override {return "road";}
> virtual int32_t get_size () const override;
> virtual bool get_passable() const override;
> virtual PositionList get_positions(const Editor_Game_Base &) const override;
>
> === modified file 'src/economy/shippingitem.cc'
> --- src/economy/shippingitem.cc 2014-05-11 07:38:01 +0000
> +++ src/economy/shippingitem.cc 2014-07-22 16:03:20 +0000
> @@ -49,20 +49,17 @@
> }
>
> if (Map_Object* obj = m_object.get(game)) {
> - switch (obj->get_type()) {
> - case Map_Object::WARE:
> - if (ware) {
> + const std::string& type_name = obj->descr().type_name();
> + if (type_name == "ware") {
> + if (ware)
> *ware = dynamic_cast<WareInstance*>(obj);
> - }
> - break;
> - case Map_Object::BOB:
> - if (worker) {
> + }
> + else if (type_name == "worker") {
> + if (worker)
> *worker = dynamic_cast<Worker*>(obj);
> - }
> - break;
> - default:
> + }
> + else {
> assert(false); // never here or unknown map object being shipped.
> - break;
> }
> }
> }
>
> === modified file 'src/economy/ware_instance.cc'
> --- src/economy/ware_instance.cc 2014-07-14 14:40:42 +0000
> +++ src/economy/ware_instance.cc 2014-07-22 16:03:20 +0000
> @@ -201,11 +201,6 @@
> }
> }
>
> -int32_t WareInstance::get_type() const
> -{
> - return WARE;
> -}
> -
> void WareInstance::init(Editor_Game_Base & egbase)
> {
> Map_Object::init(egbase);
>
> === modified file 'src/economy/ware_instance.h'
> --- src/economy/ware_instance.h 2014-07-05 16:41:51 +0000
> +++ src/economy/ware_instance.h 2014-07-22 16:03:20 +0000
> @@ -61,11 +61,6 @@
> WareInstance(Ware_Index, const WareDescr* const);
> ~WareInstance();
>
> - virtual int32_t get_type() const override;
> - char const* type_name() const override {
> - return "ware";
> - }
> -
> Map_Object* get_location(Editor_Game_Base& egbase) {
> return m_location.get(egbase);
> }
>
> === modified file 'src/graphic/render/gamerenderer.cc'
> --- src/graphic/render/gamerenderer.cc 2014-07-03 19:26:30 +0000
> +++ src/graphic/render/gamerenderer.cc 2014-07-22 16:03:20 +0000
> @@ -220,7 +220,7 @@
> m_dst->drawanim(pos[F], pic, 0, owner);
> } else if (const uint32_t pic = map_object_descr->main_animation()) {
> m_dst->drawanim(pos[F], pic, 0, owner);
> - } else if (map_object_descr == &Widelands::g_flag_descr) {
> + } else if (map_object_descr->type_name() == "flag") {
> m_dst->drawanim(pos[F], owner->tribe().flag_animation(), 0, owner);
> }
> }
>
> === modified file 'src/logic/battle.cc'
> --- src/logic/battle.cc 2014-07-03 20:11:14 +0000
> +++ src/logic/battle.cc 2014-07-22 16:03:20 +0000
> @@ -34,10 +34,13 @@
>
> namespace Widelands {
>
> -namespace {
> -Battle::Descr g_Battle_Descr("battle", "Battle");
> -} // namespace
> +namespace {
> +Battle_Descr g_Battle_Descr("battle", "Battle");
> +}
>
> +const Battle_Descr& Battle::descr() const {
> + return g_Battle_Descr;
> +}
>
> Battle::Battle ()
> :
>
> === modified file 'src/logic/battle.h'
> --- src/logic/battle.h 2014-07-05 16:41:51 +0000
> +++ src/logic/battle.h 2014-07-22 16:03:20 +0000
> @@ -24,6 +24,23 @@
> namespace Widelands {
> class Soldier;
>
> +class Battle_Descr : public Map_Object_Descr {
> +public:
> + Battle_Descr(char const* const _name, char const* const _descname)
> + :
> + Map_Object_Descr(_name, _descname),
> + m_typename ("battle")
> + {
> + }
> + virtual ~Battle_Descr() override {}
> +
> + const std::string& type_name() const override {return m_typename;}
> +
> +private:
> + std::string const m_typename;
> + DISALLOW_COPY_AND_ASSIGN(Battle_Descr);
> +};
> +
> /**
> * Manages the battle between two opposing soldiers.
> *
> @@ -34,14 +51,12 @@
> */
> class Battle : public Map_Object {
> public:
> - typedef Map_Object_Descr Descr;
> + const Battle_Descr& descr() const;
>
> Battle(); // for loading an existing battle from a savegame
> Battle(Game &, Soldier &, Soldier &); // to create a new battle in the game
>
> // Implements Map_Object.
> - virtual int32_t get_type() const override {return BATTLE;}
> - virtual char const * type_name() const override {return "battle";}
> virtual void init(Editor_Game_Base &) override;
> virtual void cleanup(Editor_Game_Base &) override;
> virtual bool has_new_save_support() override {return true;}
>
> === modified file 'src/logic/bob.cc'
> --- src/logic/bob.cc 2014-07-15 10:02:22 +0000
> +++ src/logic/bob.cc 2014-07-22 16:03:20 +0000
> @@ -53,7 +53,11 @@
> BobDescr::BobDescr(const std::string& init_name,
> const std::string& init_descname,
> Tribe_Descr const* tribe)
> - : Map_Object_Descr(init_name, init_descname), owner_tribe_(tribe) {
> + :
> + Map_Object_Descr(init_name, init_descname),
> + m_typename("bob"),
> + owner_tribe_(tribe)
> +{
> }
>
> /**
>
> === modified file 'src/logic/bob.h'
> --- src/logic/bob.h 2014-07-16 08:25:35 +0000
> +++ src/logic/bob.h 2014-07-22 16:03:20 +0000
> @@ -55,13 +55,13 @@
> public:
> friend struct Map_Bobdata_Data_Packet;
>
> - std::string type() const override {return "bob";}
> -
> BobDescr(const std::string& init_name,
> const std::string& init_descname,
> - Tribe_Descr const* tribe);
> -
> - virtual ~BobDescr() {}
> + Tribe_Descr const* tribe);
> + virtual ~BobDescr() override {}
> +
> + const std::string& type_name() const override {return m_typename;}
> +
> Bob& create(Editor_Game_Base&, Player* owner, const Coords&) const;
>
> Tribe_Descr const* get_owner_tribe() const {
> @@ -77,7 +77,9 @@
> virtual Bob& create_object() const = 0;
>
> private:
> + std::string const m_typename;
> const Tribe_Descr* const owner_tribe_; // nullptr if world bob
> + DISALLOW_COPY_AND_ASSIGN(BobDescr);
> };
>
> /**
> @@ -159,7 +161,6 @@
> struct State;
> typedef void (Bob::*Ptr)(Game &, State &);
> typedef void (Bob::*PtrSignal)(Game &, State &, const std::string &);
> - enum Type {CRITTER, WORKER, SHIP};
>
> /// \see struct Bob for in-depth explanation
> struct Task {
> @@ -228,10 +229,6 @@
> uint32_t get_current_anim() const {return m_anim;}
> int32_t get_animstart() const {return m_animstart;}
>
> - virtual int32_t get_type() const override {return BOB;}
> - virtual char const * type_name() const override {return "bob";}
> - virtual Type get_bob_type() const = 0;
> -
> virtual void init(Editor_Game_Base &) override;
> virtual void cleanup(Editor_Game_Base &) override;
> virtual void act(Game &, uint32_t data) override;
>
> === modified file 'src/logic/building.cc'
> --- src/logic/building.cc 2014-07-16 08:25:35 +0000
> +++ src/logic/building.cc 2014-07-22 16:03:20 +0000
> @@ -57,6 +57,7 @@
> const Tribe_Descr & _descr)
> :
> Map_Object_Descr(_name, _descname),
> + m_typename ("building"),
> m_tribe (_descr),
> m_buildable (true),
> m_buildicon (nullptr),
> @@ -317,8 +318,6 @@
> m_leave_queue.end());
> }
>
> -int32_t Building::get_type() const {return BUILDING;}
> -
> int32_t Building::get_size() const {return descr().get_size();}
>
> bool Building::get_passable() const {return false;}
>
> === modified file 'src/logic/building.h'
> --- src/logic/building.h 2014-07-16 08:25:35 +0000
> +++ src/logic/building.h 2014-07-22 16:03:20 +0000
> @@ -27,6 +27,7 @@
> #include <boost/signals2.hpp>
>
> #include "ai/ai_hints.h"
> +#include "base/macros.h"
> #include "logic/bill_of_materials.h"
> #include "logic/buildcost.h"
> #include "logic/immovable.h"
> @@ -64,11 +65,9 @@
> (char const * _name, char const * _descname,
> const std::string & directory, Profile &, Section & global_s,
> const Tribe_Descr &);
> -
> - std::string type() const override {
> - return "building";
> - }
> -
> + virtual ~Building_Descr() override {}
> +
> + const std::string& type_name() const override {return m_typename;}
>
> bool is_buildable () const {return m_buildable;}
> bool is_destructible() const {return m_destructible;}
> @@ -137,6 +136,7 @@
> Building & create_constructionsite() const;
>
> private:
> + std::string const m_typename;
> const Tribe_Descr & m_tribe;
> bool m_buildable; // the player can build this himself
> bool m_destructible; // the player can destruct this himself
> @@ -157,6 +157,7 @@
>
> // for migration, 0 is the default, meaning get_conquers() + 4
> uint32_t m_vision_range;
> + DISALLOW_COPY_AND_ASSIGN(Building_Descr);
> };
>
>
> @@ -182,8 +183,6 @@
>
> void load_finish(Editor_Game_Base &) override;
>
> - virtual int32_t get_type () const override;
> - char const * type_name() const override {return "building";}
> virtual int32_t get_size () const override;
> virtual bool get_passable() const override;
>
>
> === modified file 'src/logic/carrier.cc'
> --- src/logic/carrier.cc 2014-07-03 19:26:30 +0000
> +++ src/logic/carrier.cc 2014-07-22 16:03:20 +0000
> @@ -626,4 +626,9 @@
> fw.Signed32(m_promised_pickup_to);
> }
>
> +/**
> + * Create a new carrier
> + */
> +Bob & Carrier_Descr::create_object() const {return *new Carrier(*this);}
> +
> }
>
> === modified file 'src/logic/carrier.h'
> --- src/logic/carrier.h 2014-07-11 22:53:34 +0000
> +++ src/logic/carrier.h 2014-07-22 16:03:20 +0000
> @@ -20,37 +20,44 @@
> #ifndef WL_LOGIC_CARRIER_H
> #define WL_LOGIC_CARRIER_H
>
> +#include "base/macros.h"
> #include "logic/worker.h"
>
> namespace Widelands {
>
> +struct Carrier_Descr : public Worker_Descr {
> + Carrier_Descr(char const* const _name,
> + char const* const _descname,
> + const std::string& directory,
> + Profile& prof,
> + Section& global_s,
> + const Tribe_Descr& _tribe)
> + :
> + Worker_Descr(_name, _descname, directory, prof, global_s, _tribe),
> + m_typename ("carrier")
> + {
> + }
> + virtual ~Carrier_Descr() override {}
> +
> + const std::string& type_name() const override {return m_typename;}
> +
> +protected:
> + virtual Bob & create_object() const override;
> +
> +private:
> + std::string const m_typename;
> + DISALLOW_COPY_AND_ASSIGN(Carrier_Descr);
> +};
> +
> /**
> * Carrier is a worker who is employed by a Road.
> */
> struct Carrier : public Worker {
> friend struct Map_Bobdata_Data_Packet;
>
> - struct Descr : public Worker_Descr {
> - Descr
> - (char const * const _name, char const * const _descname,
> - const std::string & directory, Profile & prof, Section & global_s,
> - const Tribe_Descr & _tribe)
> - :
> - Worker_Descr
> - (_name, _descname, directory,
> - prof, global_s, _tribe)
> - {}
> -
> - virtual Worker_Type get_worker_type() const override {return CARRIER;}
> - // class type needed for Lua stuffl TODO: redundant with get_worker_type()?
> - std::string type() const override {return "carrier";}
> -
> - protected:
> - virtual Bob & create_object() const override {return *new Carrier(*this);}
> - };
> -
> -
> - Carrier(const Descr & carrier_descr)
> + MO_DESCR(Carrier_Descr)
> +
> + Carrier(const Carrier_Descr & carrier_descr)
> : Worker(carrier_descr), m_promised_pickup_to(-1)
> {}
> virtual ~Carrier() {}
> @@ -64,8 +71,11 @@
>
> virtual void log_general_info(const Editor_Game_Base &) override;
>
> + // NOCOM(GunChleoc) I had to change this from private to public
Here's the NOCOM for item 1.
> + // to make the compiler happy - it's used in road.cc
> + static Task const taskRoad;
> +
> private:
> - MO_DESCR(Descr)
>
> void find_pending_ware(Game &);
> int32_t find_closest_flag(Game &);
> @@ -75,7 +85,6 @@
> void road_pop (Game &, State &);
> void transport_update (Game &, State &);
>
> - static Task const taskRoad;
> static Task const taskTransport;
>
> void deliver_to_building(Game &, State &);
>
> === modified file 'src/logic/constructionsite.cc'
> --- src/logic/constructionsite.cc 2014-07-16 08:25:35 +0000
> +++ src/logic/constructionsite.cc 2014-07-22 16:03:20 +0000
> @@ -46,7 +46,9 @@
> (char const * const _name, char const * const _descname,
> const std::string & directory, Profile & prof, Section & global_s,
> const Tribe_Descr & _tribe)
> -: Building_Descr(_name, _descname, directory, prof, global_s, _tribe)
> + :
> + Building_Descr(_name, _descname, directory, prof, global_s, _tribe),
> + m_typename ("constructionsite")
> {
> add_attribute(Map_Object::CONSTRUCTIONSITE);
>
>
> === modified file 'src/logic/constructionsite.h'
> --- src/logic/constructionsite.h 2014-07-11 22:53:34 +0000
> +++ src/logic/constructionsite.h 2014-07-22 16:03:20 +0000
> @@ -22,6 +22,7 @@
>
> #include <vector>
>
> +#include "base/macros.h"
> #include "logic/partially_finished_building.h"
> #include "logic/player.h"
>
> @@ -54,9 +55,13 @@
> (char const * name, char const * descname,
> const std::string & directory, Profile &, Section & global_s,
> const Tribe_Descr & tribe);
> -
> + virtual ~ConstructionSite_Descr() override {}
> + const std::string& type_name() const override {return m_typename;}
> virtual Building & create_object() const override;
> - std::string type() const override {return "constructionsite";}
> +
> +private:
> + std::string const m_typename;
> + DISALLOW_COPY_AND_ASSIGN(ConstructionSite_Descr);
> };
>
> class ConstructionSite : public Partially_Finished_Building {
> @@ -69,7 +74,6 @@
> public:
> ConstructionSite(const ConstructionSite_Descr & descr);
>
> - char const * type_name() const override {return "constructionsite";}
> virtual std::string get_statistics_string() override;
>
> const Player::Constructionsite_Information & get_info() {return m_info;}
>
> === modified file 'src/logic/critter_bob.cc'
> --- src/logic/critter_bob.cc 2014-06-21 10:24:12 +0000
> +++ src/logic/critter_bob.cc 2014-07-22 16:03:20 +0000
> @@ -136,8 +136,11 @@
> const std::string& directory,
> Profile& prof,
> Section& global_s,
> - Tribe_Descr const* const _tribe)
> - : BobDescr(_name, _descname, _tribe) {
> + Tribe_Descr & _tribe)
> + :
> + BobDescr(_name, _descname, &_tribe),
> + m_typename("critterbob")
> +{
> { // global options
> Section & idle_s = prof.get_safe_section("idle");
> add_animation("idle", g_gr->animations().load(directory, idle_s));
>
> === modified file 'src/logic/critter_bob.h'
> --- src/logic/critter_bob.h 2014-07-16 08:25:35 +0000
> +++ src/logic/critter_bob.h 2014-07-22 16:03:20 +0000
> @@ -20,6 +20,7 @@
> #ifndef WL_LOGIC_CRITTER_BOB_H
> #define WL_LOGIC_CRITTER_BOB_H
>
> +#include "base/macros.h"
> #include "logic/bob.h"
> #include "graphic/diranimations.h"
>
> @@ -34,16 +35,20 @@
> //
> // Description
> //
> -struct Critter_Bob_Descr : public BobDescr {
> +struct Critter_Bob_Descr : BobDescr {
> Critter_Bob_Descr
> - (char const * name, char const * descname,
> - const std::string & directory, Profile &, Section & global_s,
> - const Tribe_Descr *);
> + (char const* const _name,
> + char const* const _descname,
> + const std::string& directory,
> + Profile& prof,
> + Section& global_s,
> + Tribe_Descr & _tribe);
> Critter_Bob_Descr(const LuaTable&);
> - virtual ~Critter_Bob_Descr();
> + virtual ~Critter_Bob_Descr() override;
> +
> + const std::string& type_name() const override {return m_typename;}
>
> Bob & create_object() const override;
> - std::string type() const override {return "critterbob";}
>
> bool is_swimming() const;
> uint32_t movecaps() const override;
> @@ -53,9 +58,11 @@
>
>
> private:
> + std::string const m_typename;
> DirAnimations m_walk_anims;
> typedef std::map<std::string, Critter_BobProgram *> Programs;
> Programs m_programs;
> + DISALLOW_COPY_AND_ASSIGN(Critter_Bob_Descr);
> };
>
> class Critter_Bob : public Bob {
> @@ -67,9 +74,6 @@
> public:
> Critter_Bob(const Critter_Bob_Descr &);
>
> - char const * type_name() const override {return "critter";}
> - virtual Bob::Type get_bob_type() const override {return Bob::CRITTER;}
> -
> virtual void init_auto_task(Game &) override;
>
> void start_task_program(Game &, const std::string & name);
>
> === modified file 'src/logic/dismantlesite.cc'
> --- src/logic/dismantlesite.cc 2014-07-15 07:44:14 +0000
> +++ src/logic/dismantlesite.cc 2014-07-22 16:03:20 +0000
> @@ -40,7 +40,9 @@
> (char const * const _name, char const * const _descname,
> const std::string & directory, Profile & prof, Section & global_s,
> const Tribe_Descr & _tribe)
> -: Building_Descr(_name, _descname, directory, prof, global_s, _tribe)
> + :
> + Building_Descr(_name, _descname, directory, prof, global_s, _tribe),
> + m_typename ("dismantlesite")
> {
> add_attribute(Map_Object::CONSTRUCTIONSITE); // Yep, this is correct.
> }
>
> === modified file 'src/logic/dismantlesite.h'
> --- src/logic/dismantlesite.h 2014-07-11 22:53:34 +0000
> +++ src/logic/dismantlesite.h 2014-07-22 16:03:20 +0000
> @@ -20,6 +20,7 @@
> #ifndef WL_LOGIC_DISMANTLESITE_H
> #define WL_LOGIC_DISMANTLESITE_H
>
> +#include "base/macros.h"
> #include "logic/building.h"
> #include "logic/partially_finished_building.h"
> #include "logic/player.h"
> @@ -42,13 +43,19 @@
> class DismantleSite;
>
> struct DismantleSite_Descr : public Building_Descr {
> - DismantleSite_Descr
> - (char const * name, char const * descname,
> - const std::string & directory, Profile &, Section & global_s,
> - const Tribe_Descr & tribe);
> + DismantleSite_Descr(char const* name,
> + char const* descname,
> + const std::string& directory,
> + Profile&,
> + Section& global_s,
> + const Tribe_Descr& tribe);
> + virtual ~DismantleSite_Descr() override {}
> + const std::string& type_name() const override {return m_typename;}
> + virtual Building& create_object() const override;
>
> - virtual Building & create_object() const override;
> - std::string type() const override {return "dismantlesite";}
> +private:
> + std::string const m_typename;
> + DISALLOW_COPY_AND_ASSIGN(DismantleSite_Descr);
> };
>
> class DismantleSite : public Partially_Finished_Building {
> @@ -64,7 +71,6 @@
> (const DismantleSite_Descr & descr, Editor_Game_Base &,
> Coords const, Player &, bool, Building::FormerBuildings & former_buildings);
>
> - char const * type_name() const override {return "dismantlesite";}
> virtual std::string get_statistics_string() override;
>
> virtual bool burn_on_destroy() override;
>
> === modified file 'src/logic/findbob.cc'
> --- src/logic/findbob.cc 2014-07-14 10:45:44 +0000
> +++ src/logic/findbob.cc 2014-07-22 16:03:20 +0000
> @@ -44,12 +44,12 @@
>
> bool FindBobShip::accept(Bob * bob) const
> {
> - return bob->get_bob_type() == Bob::SHIP;
> + return bob->descr().type_name() == "ship";
> }
>
> bool FindBobCritter::accept(Bob * bob) const
> {
> - return bob->get_bob_type() == Bob::CRITTER;
> + return bob->descr().type_name() == "critterbob";
> }
>
>
>
> === modified file 'src/logic/findimmovable.cc'
> --- src/logic/findimmovable.cc 2014-07-03 19:26:30 +0000
> +++ src/logic/findimmovable.cc 2014-07-22 16:03:20 +0000
> @@ -43,7 +43,7 @@
> }
>
> bool FindImmovableType ::accept(const BaseImmovable & imm) const {
> - return m_type == imm.get_type();
> + return m_typename == imm.descr().type_name();
> }
>
> bool FindImmovableAttribute ::accept(const BaseImmovable & imm) const {
>
> === modified file 'src/logic/findimmovable.h'
> --- src/logic/findimmovable.h 2014-07-05 16:41:51 +0000
> +++ src/logic/findimmovable.h 2014-07-22 16:03:20 +0000
> @@ -21,6 +21,7 @@
> #define WL_LOGIC_FINDIMMOVABLE_H
>
> #include <stdint.h>
> +#include <string>
>
> namespace Widelands {
>
> @@ -91,13 +92,14 @@
> private:
> int32_t m_min, m_max;
> };
> +
> struct FindImmovableType {
> - FindImmovableType(int32_t const type) : m_type(type) {}
> + FindImmovableType(char * _typename) : m_typename(_typename) {}
>
> bool accept(const BaseImmovable &) const;
>
> private:
> - int32_t m_type;
> + std::string const m_typename;
> };
> struct FindImmovableAttribute {
> FindImmovableAttribute(uint32_t const attrib) : m_attrib(attrib) {}
>
> === modified file 'src/logic/game.cc'
> --- src/logic/game.cc 2014-07-15 10:02:22 +0000
> +++ src/logic/game.cc 2014-07-22 16:03:20 +0000
> @@ -996,7 +996,7 @@
> ++workerid)
> if
> (not
> - dynamic_cast<Carrier::Descr const *>
> + dynamic_cast<Carrier_Descr const *>
> (tribe.get_worker_descr(workerid)))
> wostock += eco->stock_worker(workerid);
> }
>
> === modified file 'src/logic/immovable.cc'
> --- src/logic/immovable.cc 2014-07-16 08:23:42 +0000
> +++ src/logic/immovable.cc 2014-07-22 16:03:20 +0000
> @@ -228,6 +228,7 @@
> Tribe_Descr const * const owner_tribe)
> :
> Map_Object_Descr(_name, _descname),
> + m_typename ("immovable"),
> m_size (BaseImmovable::NONE),
> m_owner_tribe (owner_tribe)
> {
> @@ -410,10 +411,6 @@
> {
> }
>
> -int32_t Immovable::get_type() const
> -{
> - return IMMOVABLE;
> -}
>
> BaseImmovable::PositionList Immovable::get_positions
> (const Editor_Game_Base &) const
>
> === modified file 'src/logic/immovable.h'
> --- src/logic/immovable.h 2014-07-16 08:23:42 +0000
> +++ src/logic/immovable.h 2014-07-22 16:03:20 +0000
> @@ -22,6 +22,7 @@
>
> #include <memory>
>
> +#include "base/macros.h"
> #include "graphic/animation.h"
> #include "logic/buildcost.h"
> #include "logic/instances.h"
> @@ -115,10 +116,9 @@
> const std::string & directory, Profile &, Section & global_s,
> Tribe_Descr const * const);
> Immovable_Descr(const LuaTable&, const World&);
> -
> - ~Immovable_Descr();
> -
> - std::string type() const override {return "immovable";}
> + ~Immovable_Descr() override;
> +
> + const std::string& type_name() const override {return m_typename;}
>
> int32_t get_size() const {return m_size;}
> ImmovableProgram const * get_program(const std::string &) const;
> @@ -154,11 +154,14 @@
> Buildcost m_buildcost;
>
> private:
> + std::string const m_typename;
> +
> // Adds a default program if none was defined.
> void make_sure_default_program_is_there();
>
> EditorCategory* editor_category_; // not owned.
> std::unique_ptr<TerrainAffinity> terrain_affinity_;
> + DISALLOW_COPY_AND_ASSIGN(Immovable_Descr);
> };
>
> class Immovable : public BaseImmovable {
> @@ -178,8 +181,6 @@
> Coords get_position() const {return m_position;}
> virtual PositionList get_positions (const Editor_Game_Base &) const override;
>
> - virtual int32_t get_type () const override;
> - char const * type_name() const override {return "immovable";}
> virtual int32_t get_size () const override;
> virtual bool get_passable() const override;
> void start_animation(const Editor_Game_Base &, uint32_t anim);
>
> === modified file 'src/logic/instances.h'
> --- src/logic/instances.h 2014-07-15 10:02:22 +0000
> +++ src/logic/instances.h 2014-07-22 16:03:20 +0000
> @@ -54,13 +54,11 @@
> */
> struct Map_Object_Descr {
> Map_Object_Descr(const std::string& init_name, const std::string& init_descname)
> - : m_name(init_name), m_descname(init_descname) {
> - }
> + : m_name(init_name), m_descname(init_descname), m_typename("mapobject") {
> + }
> virtual ~Map_Object_Descr() {m_anims.clear();}
>
> - virtual std::string type() const {
> - return "mapobject";
> - }
> + virtual const std::string& type_name() const {return m_typename;}
>
> const std::string & name() const {return m_name;}
> const std::string & descname() const {return m_descname;}
> @@ -100,6 +98,7 @@
>
> std::string const m_name;
> std::string const m_descname; ///< Descriptive name
> + std::string const m_typename;
> Attributes m_attributes;
> Anims m_anims;
> static uint32_t s_dyn_attribhigh; ///< highest attribute ID used
> @@ -109,13 +108,6 @@
> };
>
> /**
> - * dummy instance because Map_Object needs a description
> - * \todo move this to another header??
> - */
> -extern Map_Object_Descr g_flag_descr;
> -extern Map_Object_Descr g_portdock_descr;
> -
> -/**
> * \par Notes on Map_Object
> *
> * Map_Object is the base class for everything that can be on the map:
> @@ -159,23 +151,6 @@
> MO_DESCR(Map_Object_Descr)
>
> public:
> - enum {
> - AREAWATCHER,
> - BOB, // class Bob
> -
> - WARE, // class WareInstance
> - BATTLE,
> - FLEET,
> -
> - // everything below is at least a BaseImmovable
> - IMMOVABLE,
> -
> - // everything below is at least a PlayerImmovable
> - BUILDING,
> - FLAG,
> - ROAD,
> - PORTDOCK
> - };
> /// Some default, globally valid, attributes.
> /// Other attributes (such as "harvestable corn") could be
> /// allocated dynamically (?)
> @@ -200,9 +175,6 @@
> virtual ~Map_Object() {}
>
> public:
> - virtual int32_t get_type() const = 0;
> - virtual char const * type_name() const {return "map object";}
> -
> Serial serial() const {return m_serial;}
>
> /**
>
> === modified file 'src/logic/map.cc'
> --- src/logic/map.cc 2014-07-17 13:26:23 +0000
> +++ src/logic/map.cc 2014-07-22 16:03:20 +0000
> @@ -1100,7 +1100,7 @@
> // restrictions
> if (caps & MOVECAPS_WALK) {
> // 4b) Flags must be at least 2 edges apart
> - if (consider_mobs && find_immovables(Area<FCoords>(f, 1), nullptr, FindImmovableType(Map_Object::FLAG)))
> + if (consider_mobs && find_immovables(Area<FCoords>(f, 1), nullptr, FindImmovableType("flag")))
> return static_cast<NodeCaps>(caps);
> caps |= BUILDCAPS_FLAG;
> }
> @@ -1134,7 +1134,7 @@
> if
> (!(br.field->caps & BUILDCAPS_FLAG)
> &&
> - (!br.field->get_immovable() || br.field->get_immovable()->get_type() != Map_Object::FLAG))
> + (!br.field->get_immovable() || br.field->get_immovable()->descr().type_name() != "flag"))
> return static_cast<NodeCaps>(caps);
> } else {
> if (!(_calc_nodecaps_pass1(world, br, false) & BUILDCAPS_FLAG))
> @@ -1286,7 +1286,7 @@
> int objsize = obj->get_size();
> if (objsize == BaseImmovable::NONE)
> continue;
> - if (avoidnature && obj->get_type() == Map_Object::IMMOVABLE)
> + if (avoidnature && obj->descr().type_name() == "immovable")
> objsize += 1;
> if (objsize + buildsize > BaseImmovable::BIG)
> buildsize = BaseImmovable::BIG - objsize + 1;
>
> === modified file 'src/logic/militarysite.cc'
> --- src/logic/militarysite.cc 2014-07-17 12:08:01 +0000
> +++ src/logic/militarysite.cc 2014-07-22 16:03:20 +0000
> @@ -46,12 +46,13 @@
> const std::string & directory, Profile & prof, Section & global_s,
> const Tribe_Descr & _tribe,
> const World& world)
> -:
> + :
> ProductionSite_Descr
> (_name, _descname, directory, prof, global_s, _tribe, world),
> -m_conquer_radius (0),
> -m_num_soldiers (0),
> -m_heal_per_second (0)
> + m_typename ("militarysite"),
> + m_conquer_radius (0),
> + m_num_soldiers (0),
> + m_heal_per_second (0)
> {
> m_conquer_radius = global_s.get_safe_int("conquers");
> m_num_soldiers = global_s.get_safe_int("max_soldiers");
>
> === modified file 'src/logic/militarysite.h'
> --- src/logic/militarysite.h 2014-07-11 22:53:34 +0000
> +++ src/logic/militarysite.h 2014-07-22 16:03:20 +0000
> @@ -22,6 +22,7 @@
>
> #include <memory>
>
> +#include "base/macros.h"
> #include "logic/attackable.h"
> #include "logic/productionsite.h"
> #include "logic/requirements.h"
> @@ -37,11 +38,11 @@
> (char const * name, char const * descname,
> const std::string & directory, Profile &, Section & global_s,
> const Tribe_Descr & tribe, const World& world);
> + virtual ~MilitarySite_Descr() override {}
> +
> + const std::string& type_name() const override {return m_typename;}
>
> virtual Building & create_object() const override;
> - virtual std::string type() const override {
> - return "militarysite";
> - }
>
> virtual uint32_t get_conquers() const override {return m_conquer_radius;}
> uint32_t get_max_number_of_soldiers () const {
> @@ -60,9 +61,11 @@
>
>
> private:
> + std::string const m_typename;
> uint32_t m_conquer_radius;
> uint32_t m_num_soldiers;
> uint32_t m_heal_per_second;
> + DISALLOW_COPY_AND_ASSIGN(MilitarySite_Descr);
> };
>
> class MilitarySite :
> @@ -82,7 +85,6 @@
> MilitarySite(const MilitarySite_Descr &);
> virtual ~MilitarySite();
>
> - char const * type_name() const override {return "militarysite";}
> virtual std::string get_statistics_string() override;
>
> virtual void init(Editor_Game_Base &) override;
>
> === modified file 'src/logic/player.cc'
> --- src/logic/player.cc 2014-07-17 09:15:53 +0000
> +++ src/logic/player.cc 2014-07-22 16:03:20 +0000
> @@ -96,8 +96,6 @@
>
> namespace Widelands {
>
> -extern const Map_Object_Descr g_road_descr;
> -
> const RGBColor Player::Colors[MAX_PLAYERS] = {
> RGBColor(2, 2, 198), // blue
> RGBColor(255, 41, 0), // red
> @@ -870,7 +868,7 @@
> void Player::drop_soldier(PlayerImmovable & imm, Soldier & soldier) {
> if (&imm.owner() != this)
> return;
> - if (soldier.descr().get_worker_type() != Worker_Descr::SOLDIER)
> + if (soldier.descr().type_name() != "soldier")
> return;
> if (upcast(SoldierControl, ctrl, &imm))
> ctrl->dropSoldier(soldier);
>
> === modified file 'src/logic/playercommand.h'
> --- src/logic/playercommand.h 2014-07-05 16:41:51 +0000
> +++ src/logic/playercommand.h 2014-07-22 16:03:20 +0000
> @@ -444,7 +444,7 @@
>
> private:
> Serial m_serial;
> - int32_t m_type; ///< this is always WARE right now
> + int32_t m_type; ///< this is always 0 right now
> Ware_Index m_index;
> int32_t m_priority;
> };
>
> === modified file 'src/logic/productionsite.cc'
> --- src/logic/productionsite.cc 2014-07-15 10:02:22 +0000
> +++ src/logic/productionsite.cc 2014-07-22 16:03:20 +0000
> @@ -58,7 +58,8 @@
> const std::string & directory, Profile & prof, Section & global_s,
> const Tribe_Descr & _tribe, const World& world)
> :
> - Building_Descr(_name, _descname, directory, prof, global_s, _tribe)
> + Building_Descr(_name, _descname, directory, prof, global_s, _tribe),
> + m_typename ("productionsite")
> {
> while
> (Section::Value const * const op = global_s.get_next_val("output"))
>
> === modified file 'src/logic/productionsite.h'
> --- src/logic/productionsite.h 2014-07-11 22:53:34 +0000
> +++ src/logic/productionsite.h 2014-07-22 16:03:20 +0000
> @@ -26,6 +26,7 @@
> #include <string>
> #include <vector>
>
> +#include "base/macros.h"
> #include "logic/bill_of_materials.h"
> #include "logic/building.h"
> #include "logic/production_program.h"
> @@ -58,14 +59,12 @@
> (char const * name, char const * descname,
> const std::string & directory, Profile &, Section & global_s,
> const Tribe_Descr &, const World&);
> - virtual ~ProductionSite_Descr();
> + virtual ~ProductionSite_Descr() override;
> +
> + const std::string& type_name() const override {return m_typename;}
>
> virtual Building & create_object() const override;
>
> - virtual std::string type() const override {
> - return "productionsite";
> - }
> -
> uint32_t nr_working_positions() const {
> uint32_t result = 0;
> container_iterate_const(BillOfMaterials, working_positions(), i)
> @@ -91,11 +90,13 @@
>
>
> private:
> + std::string const m_typename;
> BillOfMaterials m_working_positions;
> BillOfMaterials m_inputs;
> Output m_output_ware_types;
> Output m_output_worker_types;
> Programs m_programs;
> + DISALLOW_COPY_AND_ASSIGN(ProductionSite_Descr);
> };
>
> class ProductionSite : public Building {
> @@ -146,7 +147,6 @@
>
> virtual WaresQueue & waresqueue(Ware_Index) override;
>
> - char const * type_name() const override {return "productionsite";}
> virtual void init(Editor_Game_Base &) override;
> virtual void cleanup(Editor_Game_Base &) override;
> virtual void act(Game &, uint32_t data) override;
>
> === modified file 'src/logic/ship.cc'
> --- src/logic/ship.cc 2014-07-16 08:23:42 +0000
> +++ src/logic/ship.cc 2014-07-22 16:03:20 +0000
> @@ -53,7 +53,9 @@
> (const char * given_name, const char * gdescname,
> const std::string & directory, Profile & prof, Section & global_s,
> const Tribe_Descr & gtribe)
> -: BobDescr(given_name, gdescname, >ribe)
> + :
> + BobDescr(given_name, gdescname, >ribe),
> + m_typename("ship")
> {
> { // global options
> Section & idle_s = prof.get_safe_section("idle");
> @@ -91,10 +93,6 @@
> close_window();
> }
>
> -Bob::Type Ship::get_bob_type() const {
> - return SHIP;
> -}
> -
> PortDock* Ship::get_destination(Editor_Game_Base& egbase) const {
> return m_destination.get(egbase);
> }
>
> === modified file 'src/logic/ship.h'
> --- src/logic/ship.h 2014-07-15 10:02:22 +0000
> +++ src/logic/ship.h 2014-07-22 16:03:20 +0000
> @@ -23,6 +23,7 @@
> #include <list>
> #include <memory>
>
> +#include "base/macros.h"
> #include "logic/bob.h"
> #include "economy/shippingitem.h"
> #include "graphic/diranimations.h"
> @@ -41,13 +42,12 @@
> (char const * name, char const * descname,
> const std::string & directory, Profile &, Section & global_s,
> const Tribe_Descr &);
> + virtual ~Ship_Descr() override {}
> +
> + const std::string& type_name() const override {return m_typename;}
>
> virtual Bob & create_object() const override;
>
> - std::string type() const override {
> - return "ship";
> - }
> -
> virtual uint32_t movecaps() const override;
> const DirAnimations & get_sail_anims() const {return m_sail_anims;}
>
> @@ -56,9 +56,11 @@
>
>
> private:
> + std::string const m_typename;
> DirAnimations m_sail_anims;
> uint32_t m_capacity;
> uint32_t m_vision_range;
> + DISALLOW_COPY_AND_ASSIGN(Ship_Descr);
> };
>
> /**
> @@ -83,10 +85,6 @@
> // the last visited was removed.
> PortDock* get_lastdock(Editor_Game_Base& egbase) const;
>
> -
> -
> - virtual Type get_bob_type() const override;
> -
> Economy * get_economy() const {return m_economy;}
> void set_economy(Game &, Economy * e);
> void set_destination(Game &, PortDock &);
>
> === modified file 'src/logic/soldier.cc'
> --- src/logic/soldier.cc 2014-07-16 08:25:35 +0000
> +++ src/logic/soldier.cc 2014-07-22 16:03:20 +0000
> @@ -75,7 +75,9 @@
> (char const * const _name, char const * const _descname,
> const std::string & directory, Profile & prof, Section & global_s,
> const Tribe_Descr & _tribe)
> - : Worker_Descr(_name, _descname, directory, prof, global_s, _tribe)
> + :
> + Worker_Descr(_name, _descname, directory, prof, global_s, _tribe),
> + m_typename ("soldier")
> {
> add_attribute(Map_Object::SOLDIER);
>
>
> === modified file 'src/logic/soldier.h'
> --- src/logic/soldier.h 2014-07-15 10:02:22 +0000
> +++ src/logic/soldier.h 2014-07-22 16:03:20 +0000
> @@ -20,6 +20,7 @@
> #ifndef WL_LOGIC_SOLDIER_H
> #define WL_LOGIC_SOLDIER_H
>
> +#include "base/macros.h"
> #include "logic/tattribute.h"
> #include "logic/worker.h"
>
> @@ -44,12 +45,9 @@
> (char const * const _name, char const * const _descname,
> const std::string & directory, Profile &, Section & global_s,
> const Tribe_Descr &);
> -
> - // NOTE we have to explicitly return Worker_Descr::SOLDIER, as SOLDIER is
> - // NOTE as well defined in an enum in instances.h
> - virtual Worker_Type get_worker_type() const override {return Worker_Descr::SOLDIER;}
> -
> - std::string type() const override {return "soldier";}
> + virtual ~Soldier_Descr() override {}
> +
> + const std::string& type_name() const override {return m_typename;}
>
> virtual void load_graphics() override;
>
> @@ -133,6 +131,9 @@
> (const std::string & directory, Profile & prof, Section & global_s,
> const char * anim_name);
>
> +private:
> + std::string const m_typename;
> + DISALLOW_COPY_AND_ASSIGN(Soldier_Descr);
> };
>
> class Building;
>
> === modified file 'src/logic/trainingsite.cc'
> --- src/logic/trainingsite.cc 2014-07-14 21:52:13 +0000
> +++ src/logic/trainingsite.cc 2014-07-22 16:03:20 +0000
> @@ -46,24 +46,24 @@
> :
> ProductionSite_Descr
> (_name, _descname, directory, prof, global_s, _tribe, world),
> -
> + m_typename ("trainingsite"),
> // FIXME This is currently hardcoded for "soldier" but should allow any
> // FIXME soldier type name.
> m_num_soldiers (global_s.get_safe_int("soldier_capacity")),
> - m_max_stall (global_s.get_safe_int("trainer_patience")),
> + m_max_stall (global_s.get_safe_int("trainer_patience")),
>
> -m_train_hp (false),
> -m_train_attack (false),
> -m_train_defense (false),
> -m_train_evade (false),
> -m_min_hp (0),
> -m_min_attack (0),
> -m_min_defense (0),
> -m_min_evade (0),
> -m_max_hp (0),
> -m_max_attack (0),
> -m_max_defense (0),
> -m_max_evade (0)
> + m_train_hp (false),
> + m_train_attack (false),
> + m_train_defense (false),
> + m_train_evade (false),
> + m_min_hp (0),
> + m_min_attack (0),
> + m_min_defense (0),
> + m_min_evade (0),
> + m_max_hp (0),
> + m_max_attack (0),
> + m_max_defense (0),
> + m_max_evade (0)
> {
> // Read the range of levels that can update this building
> // FIXME This is currently hardcoded to "soldier" but it should search for
>
> === modified file 'src/logic/trainingsite.h'
> --- src/logic/trainingsite.h 2014-07-11 22:53:34 +0000
> +++ src/logic/trainingsite.h 2014-07-22 16:03:20 +0000
> @@ -20,6 +20,7 @@
> #ifndef WL_LOGIC_TRAININGSITE_H
> #define WL_LOGIC_TRAININGSITE_H
>
> +#include "base/macros.h"
> #include "logic/productionsite.h"
> #include "logic/soldiercontrol.h"
> #include "logic/tattribute.h"
> @@ -35,8 +36,9 @@
> (char const * name, char const * descname,
> const std::string & directory, Profile &, Section & global_s,
> const Tribe_Descr & tribe, const World& world);
> + virtual ~TrainingSite_Descr() override {}
>
> - std::string type() const override {return "trainingsite";}
> + const std::string& type_name() const override {return m_typename;}
>
> virtual Building & create_object() const override;
>
> @@ -53,6 +55,8 @@
> int32_t get_max_stall() const;
>
> private:
> + std::string const m_typename;
> +
> // FIXME These variables should be per soldier type. They should be in a
> // FIXME struct and there should be a vector, indexed by Soldier_Index,
> // FIXME with that struct structs as element type.
> @@ -90,6 +94,7 @@
>
> // Re-use of m_inputs to get the resources
> // TrainingMap m_programs;
> + DISALLOW_COPY_AND_ASSIGN(TrainingSite_Descr);
> };
>
> /**
> @@ -121,7 +126,6 @@
> public:
> TrainingSite(const TrainingSite_Descr &);
>
> - char const * type_name() const override {return "trainingsite";}
> virtual std::string get_statistics_string() override;
>
> virtual void init(Editor_Game_Base &) override;
>
> === modified file 'src/logic/tribe.cc'
> --- src/logic/tribe.cc 2014-07-20 13:51:48 +0000
> +++ src/logic/tribe.cc 2014-07-22 16:03:20 +0000
> @@ -78,6 +78,15 @@
> {
> std::set<std::string> names; // To enforce name uniqueness.
>
> +<<<<<<< TREE
> +=======
> + PARSE_MAP_OBJECT_TYPES_BEGIN("critter bob")
> + m_bobs.add
> + (new Critter_Bob_Descr
> + (_name, _descname, path, prof, global_s, *this));
> + PARSE_MAP_OBJECT_TYPES_END;
> +
> +>>>>>>> MERGE-SOURCE
> PARSE_MAP_OBJECT_TYPES_BEGIN("ship")
> m_bobs.add
> (new Ship_Descr
> @@ -110,7 +119,7 @@
> m_worker_types_without_cost.push_back(worker_idx); \
> PARSE_MAP_OBJECT_TYPES_END;
>
> - PARSE_WORKER_TYPES("carrier", Carrier::Descr);
> + PARSE_WORKER_TYPES("carrier", Carrier_Descr);
> PARSE_WORKER_TYPES("soldier", Soldier_Descr);
> PARSE_WORKER_TYPES("worker", Worker_Descr);
>
>
> === modified file 'src/logic/ware_descr.cc'
> --- src/logic/ware_descr.cc 2014-07-11 22:53:34 +0000
> +++ src/logic/ware_descr.cc 2014-07-22 16:03:20 +0000
> @@ -33,9 +33,10 @@
> const std::string & directory, Profile & prof, Section & global_s)
> :
> Map_Object_Descr(_name, _descname),
> - m_tribe(gtribe),
> - m_helptext(global_s.get_string("help", "")),
> - m_icon_fname(directory + "/menu.png"),
> + m_typename ("ware"),
> + m_tribe (gtribe),
> + m_helptext (global_s.get_string("help", "")),
> + m_icon_fname (directory + "/menu.png"),
> m_icon(g_gr ? g_gr->images().get("pics/but0.png") : nullptr) // because of dedicated
> {
> m_default_target_quantity =
>
> === modified file 'src/logic/ware_descr.h'
> --- src/logic/ware_descr.h 2014-07-11 22:53:34 +0000
> +++ src/logic/ware_descr.h 2014-07-22 16:03:20 +0000
> @@ -25,6 +25,7 @@
>
> #include <stdint.h>
>
> +#include "base/macros.h"
> #include "logic/instances.h"
>
> class Profile;
> @@ -49,10 +50,9 @@
> (const Tribe_Descr & tribe, char const * const name,
> char const * const descname, const std::string & directory,
> Profile &, Section & global_s);
> -
> - virtual ~WareDescr() {}
> -
> - std::string type() const override {return "ware";}
> + virtual ~WareDescr() override {}
> +
> + const std::string& type_name() const override {return m_typename;}
>
> const Tribe_Descr & tribe() const {return m_tribe;}
>
> @@ -87,12 +87,14 @@
> uint8_t preciousness() const {return m_preciousness;}
>
> private:
> + std::string const m_typename;
> const Tribe_Descr & m_tribe;
> std::string m_helptext; ///< Long descriptive text
> uint32_t m_default_target_quantity;
> std::string m_icon_fname; ///< Filename of ware's main picture
> const Image* m_icon; ///< Index of ware's picture in picture stack
> uint8_t m_preciousness;
> + DISALLOW_COPY_AND_ASSIGN(WareDescr);
> };
>
> }
>
> === modified file 'src/logic/warehouse.cc'
> --- src/logic/warehouse.cc 2014-07-16 08:25:35 +0000
> +++ src/logic/warehouse.cc 2014-07-22 16:03:20 +0000
> @@ -256,8 +256,9 @@
> (char const* const _name, char const* const _descname,
> const std::string& directory, Profile& prof, Section& global_s, const Tribe_Descr& _tribe)
> : Building_Descr(_name, _descname, directory, prof, global_s, _tribe),
> - m_conquers(0),
> - m_heal_per_second(0)
> + m_typename ("warehouse"),
> + m_conquers (0),
> + m_heal_per_second (0)
> {
> m_heal_per_second = global_s.get_safe_int("heal_per_second");
> if ((m_conquers = prof.get_safe_section("global").get_positive("conquers", 0)))
> @@ -450,19 +451,19 @@
> schedule_act
> (ref_cast<Game, Editor_Game_Base>(egbase), 4000);
>
> - log("Message: adding (wh) (%s) %i \n", type_name(), player.player_number());
> - char message[2048];
> - snprintf
> - (message, sizeof(message),
> - _("A new %s was added to your economy."),
> - descr().descname().c_str());
> - send_message
> - (ref_cast<Game, Editor_Game_Base>(egbase),
> - "warehouse",
> - descr().descname(),
> - message,
> - true);
> - }
> + log("Message: adding (wh) (%s) %i \n", descr().type_name().c_str(), player.player_number());
> + char message[2048];
> + snprintf
> + (message, sizeof(message),
> + _("A new %s was added to your economy."),
> + descr().descname().c_str());
> + send_message
> + (ref_cast<Game, Editor_Game_Base>(egbase),
> + "warehouse",
> + descr().descname(),
> + message,
> + true);
> + }
>
> if (uint32_t const conquer_radius = descr().get_conquers())
> egbase.conquer_area
>
> === modified file 'src/logic/warehouse.h'
> --- src/logic/warehouse.h 2014-07-11 22:53:34 +0000
> +++ src/logic/warehouse.h 2014-07-22 16:03:20 +0000
> @@ -20,6 +20,7 @@
> #ifndef WL_LOGIC_WAREHOUSE_H
> #define WL_LOGIC_WAREHOUSE_H
>
> +#include "base/macros.h"
> #include "base/wexception.h"
> #include "economy/request.h"
> #include "logic/attackable.h"
> @@ -52,8 +53,9 @@
> (char const * name, char const * descname,
> const std::string & directory, Profile &, Section & global_s,
> const Tribe_Descr &);
> + virtual ~Warehouse_Descr() override {}
>
> - std::string type() const override {return "warehouse";}
> + const std::string& type_name() const override {return m_typename;}
>
> virtual Building & create_object() const override;
>
> @@ -64,8 +66,10 @@
> }
>
> private:
> + std::string const m_typename;
> int32_t m_conquers;
> uint32_t m_heal_per_second;
> + DISALLOW_COPY_AND_ASSIGN(Warehouse_Descr);
> };
>
>
> @@ -115,8 +119,6 @@
>
> void load_finish(Editor_Game_Base &) override;
>
> - char const * type_name() const override {return "warehouse";}
> -
> /// Called only when the oject is logically created in the simulation. If
> /// called again, such as when the object is loaded from a savegame, it will
> /// cause bugs.
>
> === modified file 'src/logic/worker.cc'
> --- src/logic/worker.cc 2014-07-17 09:15:53 +0000
> +++ src/logic/worker.cc 2014-07-22 16:03:20 +0000
> @@ -662,8 +662,8 @@
> dest = immovable->get_position();
> else
> throw wexception
> - ("MO(%u): [actWalk]: bad object type = %i",
> - serial(), obj->get_type());
> + ("MO(%u): [actWalk]: bad object type = %s",
> + serial(), obj->descr().type_name().c_str());
>
> // Only take one step, then rethink (object may have moved)
> max_steps = 1;
> @@ -766,12 +766,12 @@
> w ->start_task_program(game, action.sparam1);
> } else
> throw wexception
> - ("MO(%i): [actObject]: bab bob type = %i",
> - serial(), bob->get_bob_type());
> + ("MO(%i): [actObject]: bab bob type = %s",
> + serial(), bob->descr().type_name().c_str());
> } else
> throw wexception
> - ("MO(%u): [actObject]: bad object type = %i",
> - serial(), obj->get_type());
> + ("MO(%u): [actObject]: bad object type = %s",
> + serial(), obj->descr().type_name().c_str());
>
> ++state.ivar1;
> schedule_act(game, 10);
> @@ -1135,9 +1135,7 @@
> if (location) {
> Economy * const eco = location->get_economy();
>
> - // NOTE we have to explicitly check Worker_Descr::SOLDIER, as SOLDIER is
> - // NOTE as well defined in an enum in instances.h
> - if (!m_economy || (descr().get_worker_type() == Worker_Descr::SOLDIER)) {
> + if (!m_economy || (descr().type_name() == "soldier")) {
> set_economy(eco);
> } else if (m_economy != eco) {
> throw wexception
> @@ -1358,8 +1356,7 @@
> void Worker::init_auto_task(Game & game) {
> if (PlayerImmovable * location = get_location(game)) {
> if
> - (get_economy()->warehouses().size() ||
> - location->get_type() == BUILDING)
> + (get_economy()->warehouses().size() || is_a(Building, location))
> return start_task_gowarehouse(game);
>
> set_location(nullptr);
> @@ -1544,7 +1541,7 @@
> serial(), nextstep->serial());
> } else if (upcast(Road, road, location)) {
> // Road to Flag
> - if (nextstep->get_type() == FLAG) {
> + if (nextstep->descr().type_name() == "flag") {
> const Path & path = road->get_path();
> int32_t const index =
> nextstep == &road->get_flag(Road::FlagStart) ? 0 :
> @@ -1793,7 +1790,7 @@
> {
> PlayerImmovable * const location = get_location(game);
>
> - if (!location || location->get_type() != BUILDING)
> + if (!(location && is_a(Building, location)))
> throw wexception
> ("MO(%u): start_task_return(): not owned by building", serial());
>
> @@ -2035,7 +2032,7 @@
>
> // Always leave buildings in an orderly manner,
> // even when no warehouses are left to return to
> - if (location->get_type() == BUILDING)
> + if (is_a(Building, location))
> return start_task_leavebuilding(game, true);
>
> if (!get_economy()->warehouses().size()) {
> @@ -2152,7 +2149,7 @@
> }
>
> // We don't have the ware any more, return home
> - if (location->get_type() == Map_Object::FLAG)
> + if (location->descr().type_name() == "flag")
> return
> start_task_move
> (game,
> @@ -2160,7 +2157,7 @@
> descr().get_right_walk_anims(does_carry_ware()),
> true);
>
> - if (location->get_type() != Map_Object::BUILDING)
> + if (!is_a(Building, location))
> throw wexception
> ("MO(%u): [dropoff]: not on building on return", serial());
>
>
> === modified file 'src/logic/worker.h'
> --- src/logic/worker.h 2014-07-16 08:25:35 +0000
> +++ src/logic/worker.h 2014-07-22 16:03:20 +0000
> @@ -77,9 +77,6 @@
> Worker(const Worker_Descr &);
> virtual ~Worker();
>
> - char const * type_name() const override {return "worker";}
> - virtual Bob::Type get_bob_type() const override {return Bob::WORKER;}
> -
> Player & owner() const {assert(get_owner()); return *get_owner();}
> PlayerImmovable * get_location(Editor_Game_Base & egbase) {
> return m_location.get(egbase);
>
> === modified file 'src/logic/worker_descr.cc'
> --- src/logic/worker_descr.cc 2014-07-05 13:18:57 +0000
> +++ src/logic/worker_descr.cc 2014-07-22 16:03:20 +0000
> @@ -41,13 +41,14 @@
> const Tribe_Descr & _tribe)
> :
> BobDescr(_name, _descname, &_tribe),
> - m_helptext(global_s.get_string("help", "")),
> - m_ware_hotspot(global_s.get_Point("ware_hotspot", Point(0, 15))),
> - m_icon_fname(directory + "/menu.png"),
> - m_icon(nullptr),
> - m_buildable (false),
> - m_level_experience(-1),
> - m_becomes (INVALID_INDEX)
> + m_helptext (global_s.get_string("help", "")),
> + m_ware_hotspot (global_s.get_Point("ware_hotspot", Point(0, 15))),
> + m_icon_fname (directory + "/menu.png"),
> + m_icon (nullptr),
> + m_buildable (false),
> + m_level_experience (-1),
> + m_becomes (INVALID_INDEX),
> + m_typename ("worker")
> {
> { // global options
> Section & idle_s = prof.get_safe_section("idle");
>
> === modified file 'src/logic/worker_descr.h'
> --- src/logic/worker_descr.h 2014-07-11 22:53:34 +0000
> +++ src/logic/worker_descr.h 2014-07-22 16:03:20 +0000
> @@ -20,6 +20,7 @@
> #ifndef WL_LOGIC_WORKER_DESCR_H
> #define WL_LOGIC_WORKER_DESCR_H
>
> +#include "base/macros.h"
> #include "logic/bob.h"
> #include "graphic/diranimations.h"
> #include "logic/immovable.h"
> @@ -43,19 +44,13 @@
> public:
> typedef std::map<std::string, uint8_t> Buildcost;
>
> - enum Worker_Type {
> - NORMAL = 0,
> - CARRIER,
> - SOLDIER,
> - };
> -
> Worker_Descr
> (char const * const name, char const * const descname,
> const std::string & directory, Profile &, Section & global_s,
> const Tribe_Descr &);
> - virtual ~Worker_Descr();
> + virtual ~Worker_Descr() override;
>
> - std::string type() const override {return "worker";}
> + const std::string& type_name() const override {return m_typename;}
>
> virtual Bob & create_object() const override;
>
> @@ -98,8 +93,6 @@
> }
> WorkerProgram const * get_program(const std::string &) const;
>
> - virtual Worker_Type get_worker_type() const {return NORMAL;}
> -
> // For leveling
> int32_t get_level_experience() const {return m_level_experience;}
> Ware_Index becomes() const {return m_becomes;}
> @@ -138,6 +131,10 @@
> */
> Ware_Index m_becomes;
> Programs m_programs;
> +private:
> + std::string const m_typename;
> +
> + DISALLOW_COPY_AND_ASSIGN(Worker_Descr);
> };
>
> }
>
> === modified file 'src/map_io/widelands_map_map_object_loader.h'
> --- src/map_io/widelands_map_map_object_loader.h 2014-07-05 16:41:51 +0000
> +++ src/map_io/widelands_map_map_object_loader.h 2014-07-22 16:03:20 +0000
> @@ -63,8 +63,7 @@
> m_objects.find(n);
> if (existing != m_objects.end()) {
> //delete &object; can not do this
> - throw game_data_error
> - ("already loaded (%s)", existing->second->type_name());
> + throw game_data_error("already loaded (%s)", existing->second->descr().type_name().c_str());
> }
> m_objects.insert(std::pair<Serial, Map_Object *>(n, &object));
> m_loaded_obj[&object] = false;
> @@ -78,9 +77,8 @@
> else if (upcast(T, result, it->second))
> return *result;
> else
> - throw game_data_error
> - ("is a %s, expected a %s",
> - it->second->type_name(), typeid(T).name());
> + throw game_data_error(
> + "is a %s, expected a %s", it->second->descr().type_name().c_str(), typeid(T).name());
> }
>
> int32_t get_nr_unloaded_objects();
>
> === modified file 'src/map_io/widelands_map_map_object_saver.cc'
> --- src/map_io/widelands_map_map_object_saver.cc 2014-07-05 12:17:03 +0000
> +++ src/map_io/widelands_map_map_object_saver.cc 2014-07-22 16:03:20 +0000
> @@ -61,7 +61,7 @@
>
> MapObjectRec rec;
> #ifndef NDEBUG
> - rec.description = obj.type_name();
> + rec.description = obj.descr().type_name();
> rec.description += " (";
> rec.description += obj.serial();
> rec.description += ')';
>
> === modified file 'src/map_io/widelands_map_object_packet.cc'
> --- src/map_io/widelands_map_object_packet.cc 2014-06-21 10:24:12 +0000
> +++ src/map_io/widelands_map_object_packet.cc 2014-07-22 16:03:20 +0000
> @@ -111,8 +111,9 @@
> container_iterate_const(LoaderSet, loaders, i) {
> try {
> (*i.current)->load_pointers();
> - } catch (const std::exception & e) {
> - throw wexception("load_pointers for %s: %s", (*i.current)->get_object()->type_name(), e.what());
> + } catch (const std::exception& e) {
> + throw wexception(
> + "load_pointers for %s: %s", (*i.current)->get_object()->descr().type_name().c_str(), e.what());
> }
> }
>
> @@ -120,8 +121,9 @@
> container_iterate_const(LoaderSet, loaders, i) {
> try {
> (*i.current)->load_finish();
> - } catch (const std::exception & e) {
> - throw wexception("load_finish for %s: %s", (*i.current)->get_object()->type_name(), e.what());
> + } catch (const std::exception& e) {
> + throw wexception(
> + "load_finish for %s: %s", (*i.current)->get_object()->descr().type_name().c_str(), e.what());
> }
> (*i.current)->mol().mark_object_as_loaded(*(*i.current)->get_object());
> }
>
> === modified file 'src/map_io/widelands_map_players_view_data_packet.cc'
> --- src/map_io/widelands_map_players_view_data_packet.cc 2014-07-14 10:45:44 +0000
> +++ src/map_io/widelands_map_players_view_data_packet.cc 2014-07-22 16:03:20 +0000
> @@ -24,13 +24,13 @@
>
> #include "base/log.h"
> #include "base/macros.h"
> +#include "economy/flag.h"
> #include "economy/road.h"
> #include "io/fileread.h"
> #include "io/filewrite.h"
> #include "logic/editor_game_base.h"
> #include "logic/field.h"
> #include "logic/game_data_error.h"
> -#include "logic/instances.h" //for g_flag_descr
> #include "logic/player.h"
> #include "logic/tribe.h"
> #include "logic/world/world.h"
> @@ -999,7 +999,7 @@
> else if (upcast(Immovable_Descr const, immovable_descr, map_object_descr)) {
> immovable_kind = 1;
> WriteImmovable_Type(&immovables_file, *immovable_descr);
> - } else if (map_object_descr == &g_flag_descr)
> + } else if (map_object_descr->type_name() == "flag")
> immovable_kind = 2;
> else if (upcast(Building_Descr const, building_descr, map_object_descr)) {
> immovable_kind = 3;
> @@ -1020,7 +1020,7 @@
> immovables_file.Unsigned32(csi.totaltime);
> immovables_file.Unsigned32(csi.completedtime);
> }
> - } else if (map_object_descr == &g_portdock_descr)
> + } else if (map_object_descr->type_name() == "portdock")
> immovable_kind = 4;
> else
> {
>
> === modified file 'src/scripting/lua_bases.cc'
> --- src/scripting/lua_bases.cc 2014-07-11 22:53:34 +0000
> +++ src/scripting/lua_bases.cc 2014-07-22 16:03:20 +0000
> @@ -438,7 +438,7 @@
> r = &get(L, egbase).force_road(path);
> } else {
> BaseImmovable * bi = map.get_immovable(current);
> - if (!bi or bi->get_type() != Map_Object::FLAG) {
> + if (!bi or bi->descr().type_name() != "flag") {
> if (!get(L, egbase).build_flag(current))
> report_error(L, "Could not place end flag!");
> }
>
> === modified file 'src/scripting/lua_map.cc'
> --- src/scripting/lua_map.cc 2014-07-17 14:49:37 +0000
> +++ src/scripting/lua_map.cc 2014-07-22 16:03:20 +0000
> @@ -540,52 +540,43 @@
> if (!mo)
> return 0;
>
> - switch (mo->get_bob_type()) {
> - case Bob::CRITTER:
> - return to_lua<L_Bob>(L, new L_Bob(*mo));
> - case Bob::WORKER:
> - if (mo->descr().name() == "soldier")
> - return CAST_TO_LUA(Soldier);
> - return CAST_TO_LUA(Worker);
> - case Bob::SHIP:
> - return CAST_TO_LUA(Ship);
> - default:
> - assert(false); // Never here, hopefully.
> - return 0;
> + const std::string& type_name = mo->descr().type_name();
> + if (type_name == "critterbob")
> + return to_lua<L_Bob>(L, new L_Bob(*mo));
> + else if (type_name == "ship")
> + return CAST_TO_LUA(Ship);
> + else if (type_name == "soldier")
> + return CAST_TO_LUA(Soldier);
> + else if (type_name == "worker")
> + return CAST_TO_LUA(Worker);
> + else {
> + assert(false); // Never here, hopefully.
> + return 0;
> }
> }
>
> int upcasted_immovable_to_lua(lua_State * L, BaseImmovable * mo) {
> if (!mo)
> return 0;
> -
> - switch (mo->get_type()) {
> - case Map_Object::BUILDING:
> - {
> - const char * type_name = mo->type_name();
> - if (!strcmp(type_name, "constructionsite"))
> - return CAST_TO_LUA(ConstructionSite);
> - else if (!strcmp(type_name, "productionsite"))
> - return CAST_TO_LUA(ProductionSite);
> - else if (!strcmp(type_name, "militarysite"))
> - return CAST_TO_LUA(MilitarySite);
> - else if (!strcmp(type_name, "warehouse"))
> - return CAST_TO_LUA(Warehouse);
> - else if (!strcmp(type_name, "trainingsite"))
> - return CAST_TO_LUA(TrainingSite);
> - else
> - return CAST_TO_LUA(Building);
> - }
> -
> - case Map_Object::FLAG:
> + const std::string& type_name = mo->descr().type_name();
> + if (type_name == "constructionsite")
> + return CAST_TO_LUA(ConstructionSite);
> + else if (type_name == "productionsite")
> + return CAST_TO_LUA(ProductionSite);
> + else if (type_name == "militarysite")
> + return CAST_TO_LUA(MilitarySite);
> + else if (type_name == "warehouse")
> + return CAST_TO_LUA(Warehouse);
> + else if (type_name == "trainingsite")
> + return CAST_TO_LUA(TrainingSite);
> + else if (type_name == "building")
> + return CAST_TO_LUA(Building);
> + else if (type_name == "flag")
> return CAST_TO_LUA(Flag);
> - case Map_Object::ROAD:
> - return CAST_TO_LUA(Road);
> - case Map_Object::PORTDOCK:
> - return CAST_TO_LUA(PortDock);
> - default:
> - break;
> - }
> + else if (type_name == "road")
> + return CAST_TO_LUA(Road);
> + else if (type_name == "portdock")
> + return CAST_TO_LUA(PortDock);
> return to_lua<L_BaseImmovable>(L, new L_BaseImmovable(*mo));
> }
> #undef CAST_TO_LUA
> @@ -597,18 +588,18 @@
> int upcasted_building_descr_to_lua(lua_State* L, const Building_Descr* const desc) {
> assert(desc != nullptr);
>
> - if (is_a(MilitarySite_Descr, desc)) {
> + const std::string& type_name = desc->type_name();
> + if (type_name == "militarysite")
> return CAST_TO_LUA(MilitarySite_Descr, L_MilitarySiteDescription);
> - }
And here (and in the lines below) we have the changes for item 2.
> - else if (is_a(TrainingSite_Descr, desc)) {
> + else if (type_name == "trainingsite")
> return CAST_TO_LUA(TrainingSite_Descr, L_TrainingSiteDescription);
> - }
> - else if (is_a(ProductionSite_Descr, desc)) {
> + else if (type_name == "productionsite")
> return CAST_TO_LUA(ProductionSite_Descr, L_ProductionSiteDescription);
> - }
> - else if (is_a(Warehouse_Descr, desc)) {
> + else if (type_name == "constructionsite")
> + return CAST_TO_LUA(ConstructionSite_Descr, L_ConstructionSiteDescription);
> + else if (type_name == "warehouse")
> return CAST_TO_LUA(Warehouse_Descr, L_WarehouseDescription);
> - }
> +
> return CAST_TO_LUA(Building_Descr, L_BuildingDescription);
> }
> #undef CAST_TO_LUA
> @@ -1023,7 +1014,7 @@
> const PropertyType<L_MapObjectDescription> L_MapObjectDescription::Properties[] = {
> PROP_RO(L_MapObjectDescription, descname),
> PROP_RO(L_MapObjectDescription, name),
> - PROP_RO(L_MapObjectDescription, type),
> + PROP_RO(L_MapObjectDescription, type_name),
> {nullptr, nullptr, nullptr},
> };
>
> @@ -1059,8 +1050,8 @@
>
> (RO) the name of the building, e.g. building.
> */
> -int L_MapObjectDescription::get_type(lua_State * L) {
> - lua_pushstring(L, get()->type());
> +int L_MapObjectDescription::get_type_name(lua_State * L) {
> + lua_pushstring(L, get()->type_name());
> return 1;
> }
>
> @@ -1289,6 +1280,24 @@
> return 1;
> }
>
> +/* RST
> +ConstructionSiteDescription
> +----------
> +
> +.. class:: ConstructionSiteDescription
> +
> + A static description of a tribe's constructionsite, so it can be used in help files
> + without having to access an actual building on the map.
> + See also class BuildingDescription and class MapObjectDescription for more properties.
> +*/
> +const char L_ConstructionSiteDescription::className[] = "ConstructionSiteDescription";
> +const MethodType<L_ConstructionSiteDescription> L_ConstructionSiteDescription::Methods[] = {
> + {nullptr, nullptr},
> +};
> +const PropertyType<L_ConstructionSiteDescription> L_ConstructionSiteDescription::Properties[] = {
> + {nullptr, nullptr, nullptr},
> +};
> +
>
> /* RST
> ProductionSiteDescription
> @@ -1706,7 +1715,7 @@
> if (std::string(get()->name()) ==
> std::string(tribe.get_ware_descr(ware_index)->name())) {
> lua_pushint32(L, index++);
> - upcasted_building_descr_to_lua(L, tribe.get_building_descr(i));
> + upcasted_building_descr_to_lua(L, tribe.get_building_descr(i));
> lua_rawset(L, -3);
> }
> }
> @@ -1745,7 +1754,7 @@
> if (std::string(get()->name()) ==
> std::string(tribe.get_ware_descr(ware_amount.first)->name())) {
> lua_pushint32(L, index++);
> - upcasted_building_descr_to_lua(L, tribe.get_building_descr(i));
> + upcasted_building_descr_to_lua(L, tribe.get_building_descr(i));
> lua_rawset(L, -3);
> }
> }
> @@ -1892,10 +1901,9 @@
> };
> const PropertyType<L_MapObject> L_MapObject::Properties[] = {
> PROP_RO(L_MapObject, __hash),
> + PROP_RO(L_MapObject, descr),
> + PROP_RO(L_MapObject, name),
> PROP_RO(L_MapObject, serial),
> - PROP_RO(L_MapObject, type),
> - PROP_RO(L_MapObject, name),
> - PROP_RO(L_MapObject, descname),
> {nullptr, nullptr, nullptr},
> };
>
> @@ -1944,17 +1952,6 @@
> return 1;
> }
>
> -/* RST
> - .. attribute:: type
> -
> - (RO) the type name of this map object. You can determine with what kind
> - of object you cope by looking at this attribute. Some example types:
> - immovable, flag, road, productionsite, warehouse, militarysite...
> -*/
> -int L_MapObject::get_type(lua_State * L) {
> - lua_pushstring(L, get(L, get_egbase(L))->type_name());
> - return 1;
> -}
>
> /* RST
> .. attribute:: name
> @@ -1967,19 +1964,41 @@
> return 1;
> }
>
> +// use the dynamic type of BuildingDescription
> +#define CAST_TO_LUA(klass, lua_klass) to_lua<lua_klass> \
> + (L, new lua_klass(static_cast<const klass *>(desc)))
> +
> /* RST
> - .. attribute:: descname
> + .. attribute:: descr
>
> - (RO) The descriptive (and translated) name of this Map Object. Use this
> - in messages to the player instead of name.
> + (RO) The description object for this immovable, e.g. BuildingDescription.
> */
> -int L_MapObject::get_descname(lua_State * L) {
> - lua_pushstring(L, get(L, get_egbase(L))->descr().descname().c_str());
> - return 1;
> +int L_MapObject::get_descr(lua_State * L) {
> + const Map_Object_Descr* desc = &get(L, get_egbase(L))->descr();
> + assert(desc != nullptr);
> +
> + if (is_a(MilitarySite_Descr, desc)) {
> + return CAST_TO_LUA(MilitarySite_Descr, L_MilitarySiteDescription);
> + }
> + else if (is_a(TrainingSite_Descr, desc)) {
> + return CAST_TO_LUA(TrainingSite_Descr, L_TrainingSiteDescription);
> + }
> + else if (is_a(ProductionSite_Descr, desc)) {
> + return CAST_TO_LUA(ProductionSite_Descr, L_ProductionSiteDescription);
> + }
> + else if (is_a(Warehouse_Descr, desc)) {
> + return CAST_TO_LUA(Warehouse_Descr, L_WarehouseDescription);
> + }
> + else if (is_a(ConstructionSite_Descr, desc)) {
> + return CAST_TO_LUA(ConstructionSite_Descr, L_ConstructionSiteDescription);
> + }
> + else if (is_a(Building_Descr, desc)) {
> + return CAST_TO_LUA(Building_Descr, L_BuildingDescription);
> + }
> + return CAST_TO_LUA(Map_Object_Descr, L_MapObjectDescription);
> }
>
> -
> -
> +#undef CAST_TO_LUA
>
> /*
> ==========================================================
> @@ -3982,6 +4001,11 @@
> add_parent<L_BuildingDescription, L_MapObjectDescription>(L);
> lua_pop(L, 1); // Pop the meta table
>
> + register_class<L_ConstructionSiteDescription>(L, "map", true);
> + add_parent<L_ConstructionSiteDescription, L_BuildingDescription>(L);
> + add_parent<L_ConstructionSiteDescription, L_MapObjectDescription>(L);
> + lua_pop(L, 1); // Pop the meta table
> +
> register_class<L_ProductionSiteDescription>(L, "map", true);
> add_parent<L_ProductionSiteDescription, L_BuildingDescription>(L);
> add_parent<L_ProductionSiteDescription, L_MapObjectDescription>(L);
>
> === modified file 'src/scripting/lua_map.h'
> --- src/scripting/lua_map.h 2014-07-16 08:23:42 +0000
> +++ src/scripting/lua_map.h 2014-07-22 16:03:20 +0000
> @@ -112,7 +112,7 @@
> * Properties
> */
> int get_name(lua_State *);
> - int get_type(lua_State *);
> + int get_type_name(lua_State *);
> int get_descname(lua_State *);
>
> /*
> @@ -189,6 +189,36 @@
> };
>
>
> +class L_ConstructionSiteDescription : public L_BuildingDescription {
> +public:
> + LUNA_CLASS_HEAD(L_ConstructionSiteDescription);
> +
> + virtual ~L_ConstructionSiteDescription() {}
> +
> + L_ConstructionSiteDescription() {}
> + L_ConstructionSiteDescription(const Widelands::ConstructionSite_Descr* const constructionsitedescr)
> + : L_BuildingDescription(constructionsitedescr) {
> + }
> + L_ConstructionSiteDescription(lua_State* L) : L_BuildingDescription(L) {
> + }
> +
> + /*
> + * Properties
> + */
> +
> + /*
> + * Lua methods
> + */
> +
> + /*
> + * C methods
> + */
> +
> +private:
> + CASTED_GET_DESCRIPTION(ConstructionSite_Descr);
> +};
> +
> +
> class L_ProductionSiteDescription : public L_BuildingDescription {
> public:
> LUNA_CLASS_HEAD(L_ProductionSiteDescription);
> @@ -428,10 +458,9 @@
> * attributes
> */
> int get___hash(lua_State *);
> + int get_descr(lua_State *);
> + int get_name(lua_State *);
> int get_serial(lua_State *);
> - int get_type(lua_State *);
> - int get_name(lua_State *);
> - int get_descname(lua_State *);
>
> /*
> * Lua Methods
>
--
https://code.launchpad.net/~widelands-dev/widelands/bug-1341081/+merge/227107
Your team Widelands Developers is subscribed to branch lp:~widelands-dev/widelands/bug-1341081.
References