Review: Needs Fixing > This avoids having to get the tribes' Immovable_Descr through the Lua > interface. If you think this is a problem, I can have a go at it though. > Otherwise, ready for merging.
I do not think this is a problem. Wrapping those too might make sense in the future anyways though. Diff comments: > === modified file 'campaigns/atl01.wmf/scripting/init.lua' > --- campaigns/atl01.wmf/scripting/init.lua 2014-07-15 10:02:22 +0000 > +++ campaigns/atl01.wmf/scripting/init.lua 2014-07-16 21:09:18 +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.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-15 10:02:22 > +0000 > +++ campaigns/tutorial01.wmf/scripting/init.lua 2014-07-16 21:09:18 > +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.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.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-15 10:02:22 +0000 > +++ scripting/format_help.lua 2014-07-16 21:09:18 +0000 > @@ -331,23 +331,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. > @@ -695,7 +695,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-16 21:09:18 +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/economy/flag.h' > --- src/economy/flag.h 2014-07-14 14:40:42 +0000 > +++ src/economy/flag.h 2014-07-16 21:09:18 +0000 > @@ -33,6 +33,16 @@ > class WareInstance; > > > +class Flag_Descr : public Map_Object_Descr > +{ > + > +public: > + Flag_Descr(char const * const name, char const * const descname); > + virtual ~Flag_Descr(); > + > + char const * type_name() const override {return "flag";} > +}; > + > > /** > * Flag represents a flag, obviously. > @@ -59,6 +69,8 @@ > friend struct Map_Waredata_Data_Packet; // has to look at pending wares > friend struct Router; > > + MO_DESCR(Flag_Descr); > + > Flag(); /// empty flag for savegame loading > Flag(Editor_Game_Base &, Player & owner, Coords); /// create a new flag > virtual ~Flag(); > @@ -67,7 +79,6 @@ > 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; > > > === modified file 'src/economy/fleet.cc' > --- src/economy/fleet.cc 2014-07-14 22:18:03 +0000 > +++ src/economy/fleet.cc 2014-07-16 21:09:18 +0000 > @@ -40,14 +40,11 @@ > > namespace Widelands { > > -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; > -} > > } // namespace > > @@ -70,11 +67,6 @@ > return FLEET; > } > > -char const * Fleet::type_name() const > -{ > - return "fleet"; > -} > - > /** > * Whether the fleet is in fact useful for transporting goods. > */ > > === modified file 'src/economy/fleet.h' > --- src/economy/fleet.h 2014-07-05 16:41:51 +0000 > +++ src/economy/fleet.h 2014-07-16 21:09:18 +0000 > @@ -32,6 +32,16 @@ > struct RoutingNodeNeighbour; > struct Ship; > > +class Fleet_Descr : public Map_Object_Descr > +{ > + > +public: > + Fleet_Descr(char const * const name, char const * const descname); > + virtual ~Fleet_Descr(); > + > + char const * type_name() const override {return "fleet";} > +}; > + > /** > * Manage all ships and ports of a player that are connected > * by ocean. > @@ -58,6 +68,8 @@ > PortPath() : cost(-1) {} > }; > > + MO_DESCR(Fleet_Descr); > + > Fleet(Player & player); > > Player * get_owner() const {return &m_owner;} > @@ -70,7 +82,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; > > === modified file 'src/economy/portdock.cc' > --- src/economy/portdock.cc 2014-07-16 05:33:19 +0000 > +++ src/economy/portdock.cc 2014-07-16 21:09:18 +0000 > @@ -99,11 +99,6 @@ > 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-16 21:09:18 +0000 > @@ -34,6 +34,16 @@ > 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(); > + > + char const * type_name() const override {return "portdock";} > +}; > + > /** > * The PortDock occupies the fields in the water at which ships > * dock at a port. As such, this class cooperates closely with > @@ -62,6 +72,8 @@ > */ > class PortDock : public PlayerImmovable { > public: > + MO_DESCR(PortDock_Descr); > + > PortDock(Warehouse* warehouse); > virtual ~PortDock(); > > @@ -77,7 +89,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 > > === modified file 'src/economy/road.h' > --- src/economy/road.h 2014-07-14 14:40:42 +0000 > +++ src/economy/road.h 2014-07-16 21:09:18 +0000 > @@ -30,6 +30,16 @@ > struct Carrier; > class Request; > > +class Road_Descr : public Map_Object_Descr > +{ > + > +public: > + Road_Descr(char const * const name, char const * const descname); > + virtual ~Road_Descr(); > + > + char const * type_name() const override {return "road";} > +}; > + > /** > * Road is a special object which connects two flags. > * The Road itself is never rendered; however, the appropriate Field::roads > are > @@ -49,6 +59,8 @@ > friend class Map_Roaddata_Data_Packet; // For saving > friend class Map_Road_Data_Packet; // For init() > > + MO_DESCR(Road_Descr); > + > static bool IsRoadDescr(Map_Object_Descr const *); > > enum FlagId { > @@ -75,7 +87,6 @@ > > 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/ware_instance.h' > --- src/economy/ware_instance.h 2014-07-05 16:41:51 +0000 > +++ src/economy/ware_instance.h 2014-07-16 21:09:18 +0000 > @@ -62,9 +62,6 @@ > ~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/logic/battle.cc' > --- src/logic/battle.cc 2014-07-03 20:11:14 +0000 > +++ src/logic/battle.cc 2014-07-16 21:09:18 +0000 > @@ -34,10 +34,7 @@ > > namespace Widelands { > > -namespace { > -Battle::Descr g_Battle_Descr("battle", "Battle"); > -} // namespace > - > +Map_Object_Descr g_Battle_Descr("battle", "Battle"); keep this in an anonymous namespace - it should not be used outside of the file. Also, road.cc, flag.cc, ship and so on will have a similar variable. Change these too to the new 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-16 21:09:18 +0000 > @@ -24,6 +24,16 @@ > namespace Widelands { > class Soldier; > > +class Battle_Descr : public Map_Object_Descr > +{ > + > +public: > + Battle_Descr(char const * const name, char const * const descname); > + virtual ~Battle_Descr(); > + > + char const * type_name() const override {return "battle";} > +}; > + > /** > * Manages the battle between two opposing soldiers. > * > @@ -34,14 +44,14 @@ > */ > class Battle : public Map_Object { > public: > - typedef Map_Object_Descr Descr; > + > + MO_DESCR(Battle_Descr); > > 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.h' > --- src/logic/bob.h 2014-07-15 10:02:22 +0000 > +++ src/logic/bob.h 2014-07-16 21:09:18 +0000 > @@ -55,7 +55,7 @@ > public: > friend struct Map_Bobdata_Data_Packet; > > - std::string type() const override {return "bob";} > + char const * type_name() const override {return "bob";} > > BobDescr(const std::string& init_name, > const std::string& init_descname, > @@ -229,7 +229,6 @@ > 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; > > === modified file 'src/logic/building.h' > --- src/logic/building.h 2014-07-16 05:54:49 +0000 > +++ src/logic/building.h 2014-07-16 21:09:18 +0000 > @@ -65,7 +65,7 @@ > const std::string & directory, Profile &, Section & global_s, > const Tribe_Descr &); > > - std::string type() const override { > + char const * type_name() const override { > return "building"; > } > > @@ -183,7 +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; > virtual uint32_t get_ui_anim () const; > > === modified file 'src/logic/carrier.h' > --- src/logic/carrier.h 2014-07-11 22:53:34 +0000 > +++ src/logic/carrier.h 2014-07-16 21:09:18 +0000 > @@ -43,7 +43,7 @@ > > 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";} > + char const * type_name() const override {return "carrier";} > > protected: > virtual Bob & create_object() const override {return *new > Carrier(*this);} > > === modified file 'src/logic/constructionsite.h' > --- src/logic/constructionsite.h 2014-07-11 22:53:34 +0000 > +++ src/logic/constructionsite.h 2014-07-16 21:09:18 +0000 > @@ -56,7 +56,7 @@ > const Tribe_Descr & tribe); > > virtual Building & create_object() const override; > - std::string type() const override {return "constructionsite";} > + char const * type_name() const override {return "constructionsite";} > }; > > class ConstructionSite : public Partially_Finished_Building { > @@ -69,7 +69,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.h' > --- src/logic/critter_bob.h 2014-07-14 11:30:37 +0000 > +++ src/logic/critter_bob.h 2014-07-16 21:09:18 +0000 > @@ -43,7 +43,7 @@ > virtual ~Critter_Bob_Descr(); > > Bob & create_object() const override; > - std::string type() const override {return "critterbob";} > + char const * type_name() const override {return "critterbob";} > > bool is_swimming() const; > uint32_t movecaps() const override; > @@ -67,7 +67,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; > > === modified file 'src/logic/dismantlesite.h' > --- src/logic/dismantlesite.h 2014-07-11 22:53:34 +0000 > +++ src/logic/dismantlesite.h 2014-07-16 21:09:18 +0000 > @@ -48,7 +48,7 @@ > const Tribe_Descr & tribe); > > virtual Building & create_object() const override; > - std::string type() const override {return "dismantlesite";} > + char const * type_name() const override {return "dismantlesite";} > }; > > class DismantleSite : public Partially_Finished_Building { > @@ -64,7 +64,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/immovable.h' > --- src/logic/immovable.h 2014-07-15 10:02:22 +0000 > +++ src/logic/immovable.h 2014-07-16 21:09:18 +0000 > @@ -102,7 +102,7 @@ > > ~Immovable_Descr(); > > - std::string type() const override {return "immovable";} > + char const * type_name() const override {return "immovable";} > > int32_t get_size() const {return m_size;} > ImmovableProgram const * get_program(const std::string &) const; > @@ -163,7 +163,6 @@ > 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-16 21:09:18 +0000 > @@ -58,7 +58,7 @@ > } > virtual ~Map_Object_Descr() {m_anims.clear();} > > - virtual std::string type() const { > + virtual char const * type_name() const { > return "mapobject"; > } > > @@ -201,7 +201,6 @@ > > 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/militarysite.h' > --- src/logic/militarysite.h 2014-07-11 22:53:34 +0000 > +++ src/logic/militarysite.h 2014-07-16 21:09:18 +0000 > @@ -39,7 +39,7 @@ > const Tribe_Descr & tribe, const World& world); > > virtual Building & create_object() const override; > - virtual std::string type() const override { > + char const * type_name() const override { > return "militarysite"; > } > > @@ -82,7 +82,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/productionsite.h' > --- src/logic/productionsite.h 2014-07-11 22:53:34 +0000 > +++ src/logic/productionsite.h 2014-07-16 21:09:18 +0000 > @@ -62,7 +62,7 @@ > > virtual Building & create_object() const override; > > - virtual std::string type() const override { > + char const * type_name() const override { > return "productionsite"; > } > > @@ -146,7 +146,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.h' > --- src/logic/ship.h 2014-07-15 10:02:22 +0000 > +++ src/logic/ship.h 2014-07-16 21:09:18 +0000 > @@ -44,7 +44,7 @@ > > virtual Bob & create_object() const override; > > - std::string type() const override { > + char const * type_name() const override { > return "ship"; > } > > > === modified file 'src/logic/soldier.h' > --- src/logic/soldier.h 2014-07-15 10:02:22 +0000 > +++ src/logic/soldier.h 2014-07-16 21:09:18 +0000 > @@ -49,7 +49,7 @@ > // 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";} > + char const * type_name() const override {return "soldier";} > > virtual void load_graphics() override; > > > === modified file 'src/logic/trainingsite.h' > --- src/logic/trainingsite.h 2014-07-11 22:53:34 +0000 > +++ src/logic/trainingsite.h 2014-07-16 21:09:18 +0000 > @@ -36,7 +36,7 @@ > const std::string & directory, Profile &, Section & global_s, > const Tribe_Descr & tribe, const World& world); > > - std::string type() const override {return "trainingsite";} > + char const * type_name() const override {return "trainingsite";} > > virtual Building & create_object() const override; > > @@ -121,7 +121,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/ware_descr.h' > --- src/logic/ware_descr.h 2014-07-11 22:53:34 +0000 > +++ src/logic/ware_descr.h 2014-07-16 21:09:18 +0000 > @@ -52,7 +52,7 @@ > > virtual ~WareDescr() {} > > - std::string type() const override {return "ware";} > + char const * type_name() const override {return "ware";} > > const Tribe_Descr & tribe() const {return m_tribe;} > > > === modified file 'src/logic/warehouse.cc' > --- src/logic/warehouse.cc 2014-07-15 10:02:22 +0000 > +++ src/logic/warehouse.cc 2014-07-16 21:09:18 +0000 > @@ -450,7 +450,7 @@ > schedule_act > (ref_cast<Game, Editor_Game_Base>(egbase), > 4000); > > - log("Message: adding (wh) (%s) %i \n", type_name(), > player.player_number()); > + log("Message: adding (wh) (%s) %i \n", descr().type_name(), > player.player_number()); > char message[2048]; > snprintf > (message, sizeof(message), > > === modified file 'src/logic/warehouse.h' > --- src/logic/warehouse.h 2014-07-11 22:53:34 +0000 > +++ src/logic/warehouse.h 2014-07-16 21:09:18 +0000 > @@ -53,7 +53,7 @@ > const std::string & directory, Profile &, Section & global_s, > const Tribe_Descr &); > > - std::string type() const override {return "warehouse";} > + char const * type_name() const override {return "warehouse";} > > virtual Building & create_object() const override; > > @@ -115,8 +115,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.h' > --- src/logic/worker.h 2014-07-15 10:02:22 +0000 > +++ src/logic/worker.h 2014-07-16 21:09:18 +0000 > @@ -80,7 +80,7 @@ > virtual Worker_Descr::Worker_Type get_worker_type() const { > return descr().get_worker_type(); > } > - char const * type_name() const override {return "worker";} > + > virtual Bob::Type get_bob_type() const override {return Bob::WORKER;} > > uint32_t get_animation(char const * const str) const { > > === 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-16 21:09:18 +0000 > @@ -55,7 +55,7 @@ > const Tribe_Descr &); > virtual ~Worker_Descr(); > > - std::string type() const override {return "worker";} > + char const * type_name() const override {return "worker";} > > virtual Bob & create_object() const override; > > > === 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-16 21:09:18 > +0000 > @@ -64,7 +64,7 @@ > if (existing != m_objects.end()) { > //delete &object; can not do this > throw game_data_error > - ("already loaded (%s)", > existing->second->type_name()); > + ("already loaded (%s)", > existing->second->descr().type_name()); > } > m_objects.insert(std::pair<Serial, Map_Object *>(n, &object)); > m_loaded_obj[&object] = false; > @@ -80,7 +80,7 @@ > else > throw game_data_error > ("is a %s, expected a %s", > - it->second->type_name(), typeid(T).name()); > + it->second->descr().type_name(), 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-16 21:09:18 > +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-16 21:09:18 +0000 > @@ -112,7 +112,7 @@ > 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()); > + throw wexception("load_pointers for %s: %s", > (*i.current)->get_object()->descr().type_name(), e.what()); > } > } > > @@ -121,7 +121,7 @@ > 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()); > + throw wexception("load_finish for %s: %s", > (*i.current)->get_object()->descr().type_name(), e.what()); > } > > (*i.current)->mol().mark_object_as_loaded(*(*i.current)->get_object()); > } > > === modified file 'src/scripting/lua_map.cc' > --- src/scripting/lua_map.cc 2014-07-16 06:05:23 +0000 > +++ src/scripting/lua_map.cc 2014-07-16 21:09:18 +0000 > @@ -562,7 +562,7 @@ > switch (mo->get_type()) { > case Map_Object::BUILDING: > { > - const char * type_name = mo->type_name(); > + const char * type_name = mo->descr().type_name(); > if (!strcmp(type_name, "constructionsite")) > return CAST_TO_LUA(ConstructionSite); > else if (!strcmp(type_name, "productionsite")) > @@ -606,6 +606,9 @@ > else if (is_a(ProductionSite_Descr, desc)) { > return CAST_TO_LUA(ProductionSite_Descr, > L_ProductionSiteDescription); > } > + else if (is_a(ConstructionSite_Descr, desc)) { > + return CAST_TO_LUA(ConstructionSite_Descr, > L_ConstructionSiteDescription); > + } > else if (is_a(Warehouse_Descr, desc)) { > return CAST_TO_LUA(Warehouse_Descr, L_WarehouseDescription); > } > @@ -1023,7 +1026,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 +1062,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 +1292,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 +1727,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 +1766,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 +1913,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 +1964,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 +1976,43 @@ > 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) { > + //TODO(GunChleoc) Flag_Descr would be nice for getting the type of > immovables, > + // at the moment the type for these can be faked by using their name > instead > + 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 > > /* > ========================================================== > @@ -3983,6 +4016,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-15 10:02:22 +0000 > +++ src/scripting/lua_map.h 2014-07-16 21:09:18 +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. _______________________________________________ Mailing list: https://launchpad.net/~widelands-dev Post to : widelands-dev@lists.launchpad.net Unsubscribe : https://launchpad.net/~widelands-dev More help : https://help.launchpad.net/ListHelp