1 /* 2 * Copyright (C) 2002-2020 by the Widelands Development Team 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 * 18 */ 19 20 #ifndef WL_LOGIC_MAP_OBJECTS_WORLD_WORLD_H 21 #define WL_LOGIC_MAP_OBJECTS_WORLD_WORLD_H 22 23 #include <memory> 24 25 #include "base/macros.h" 26 #include "logic/map_objects/description_maintainer.h" 27 28 class LuaTable; 29 30 namespace Widelands { 31 32 struct CritterDescr; 33 class EditorCategory; 34 class ImmovableDescr; 35 class ResourceDescription; 36 class TerrainDescription; 37 38 /// This is the in memory descriptions of the world and provides access to 39 /// terrains, immovables and resources. 40 class World { 41 public: 42 World(); 43 ~World(); 44 45 // TODO(sirver): Refactor these to only return the description_maintainer so that world 46 // becomes a pure container. 47 const DescriptionMaintainer<TerrainDescription>& terrains() const; 48 TerrainDescription& terrain_descr(DescriptionIndex i) const; 49 const TerrainDescription* terrain_descr(const std::string& name) const; 50 DescriptionIndex get_terrain_index(const std::string& name) const; 51 DescriptionIndex get_nr_terrains() const; 52 53 const DescriptionMaintainer<CritterDescr>& critters() const; 54 DescriptionIndex get_critter(char const* const l) const; 55 CritterDescr const* get_critter_descr(DescriptionIndex index) const; 56 CritterDescr const* get_critter_descr(const std::string& name) const; 57 58 const DescriptionMaintainer<ImmovableDescr>& immovables() const; 59 DescriptionIndex get_immovable_index(const std::string& name) const; 60 DescriptionIndex get_nr_immovables() const; 61 ImmovableDescr const* get_immovable_descr(DescriptionIndex index) const; 62 63 DescriptionIndex resource_index(const char* const name) const; 64 ResourceDescription const* get_resource(DescriptionIndex res) const; 65 DescriptionIndex get_nr_resources() const; 66 DescriptionIndex safe_resource_index(const char* const warename) const; 67 68 /// Add this new resource to the world description. 69 void add_resource_type(const LuaTable& table); 70 71 /// Add this new terrain to the world description. 72 void add_terrain_type(const LuaTable& table); 73 74 /// Add a new critter to the world description. 75 void add_critter_type(const LuaTable& table); 76 77 /// Add a new immovable to the world description. 78 void add_immovable_type(const LuaTable& table); 79 80 /// Add an editor categories for grouping items in the editor. 81 void add_editor_terrain_category(const LuaTable& table); 82 void add_editor_critter_category(const LuaTable& table); 83 void add_editor_immovable_category(const LuaTable& table); 84 85 /// Access to the editor categories. 86 const DescriptionMaintainer<EditorCategory>& editor_terrain_categories() const; 87 const DescriptionMaintainer<EditorCategory>& editor_critter_categories() const; 88 const DescriptionMaintainer<EditorCategory>& editor_immovable_categories() const; 89 90 // Load the graphics for the world. Animations are loaded on 91 // demand. 92 void load_graphics(); 93 void postload(); 94 95 private: 96 std::unique_ptr<DescriptionMaintainer<CritterDescr>> critters_; 97 std::unique_ptr<DescriptionMaintainer<ImmovableDescr>> immovables_; 98 std::unique_ptr<DescriptionMaintainer<TerrainDescription>> terrains_; 99 std::unique_ptr<DescriptionMaintainer<ResourceDescription>> resources_; 100 std::unique_ptr<DescriptionMaintainer<EditorCategory>> editor_terrain_categories_; 101 std::unique_ptr<DescriptionMaintainer<EditorCategory>> editor_critter_categories_; 102 std::unique_ptr<DescriptionMaintainer<EditorCategory>> editor_immovable_categories_; 103 104 DISALLOW_COPY_AND_ASSIGN(World); 105 }; 106 107 } // namespace Widelands 108 109 #endif // end of include guard: WL_LOGIC_MAP_OBJECTS_WORLD_WORLD_H 110