1 /* 2 * common/Map.hpp 3 * 4 * This file is part of Leges Motus, a networked, 2D shooter set in zero gravity. 5 * 6 * Copyright 2009-2010 Andrew Ayer, Nathan Partlan, Jeffrey Pfau 7 * 8 * Leges Motus is free and open source software. You may redistribute it and/or 9 * modify it under the terms of version 2, or (at your option) version 3, of the 10 * GNU General Public License (GPL), as published by the Free Software Foundation. 11 * 12 * Leges Motus is distributed in the hope that it will be useful, but WITHOUT ANY 13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 14 * PARTICULAR PURPOSE. See the full text of the GNU General Public License for 15 * further detail. 16 * 17 * For a full copy of the GNU General Public License, please see the COPYING file 18 * in the root of the source code tree. You may also retrieve a copy from 19 * <http://www.gnu.org/licenses/gpl-2.0.txt>, or request a copy by writing to the 20 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 21 * 02111-1307 USA 22 * 23 */ 24 25 #ifndef LM_COMMON_MAP_HPP 26 #define LM_COMMON_MAP_HPP 27 28 #include <string> 29 #include <iosfwd> 30 #include "ConfigManager.hpp" 31 32 namespace LM { 33 class MapReader; 34 class StringTokenizer; 35 class PacketReader; 36 class PacketWriter; 37 38 /* 39 * A Map keeps track of things like the map name, dimensions, and spawn points 40 * The client should derive a class called GraphicalMap which handles graphics and stuff 41 * The server should derive a class called ServerMap which handles spawning 42 */ 43 class Map { 44 public: 45 enum ObjectType { 46 INVALID_OBJECT_TYPE = 0, 47 GATE = 2, 48 SPAWN_POINT = 3, 49 OBSTACLE = 4, 50 DECORATION = 5, 51 REPULSION = 6, 52 FORCE_FIELD = 7, 53 HAZARD = 8 54 }; 55 static ObjectType parse_object_type(const char* type_string); 56 57 protected: 58 std::string m_name; // Should be unique 59 int m_revision; 60 int m_width; 61 int m_height; 62 ConfigManager m_options; 63 64 public: 65 Map(); 66 virtual ~Map(); 67 68 // Standard getters get_name() const69 const char* get_name() const { return m_name.c_str(); } get_revision() const70 int get_revision() const { return m_revision; } get_width() const71 int get_width() const { return m_width; } get_height() const72 int get_height() const { return m_height; } get_options() const73 const ConfigManager& get_options() const { return m_options; } 74 75 bool is_loaded(const char* name, int revision) const; 76 77 // Read and parse the given input stream and load into the current map 78 virtual bool load(std::istream& in); 79 80 // load_file will preserve the current map if it can't open the new map 81 // (and return false to indicate error) 82 virtual bool load_file(const char* path); 83 84 // Remove all objects from the map: 85 virtual void clear(); 86 // Parse the given packet representation of a map object and add it to the map 87 virtual void add_object(MapReader& data) = 0; 88 89 friend PacketReader& operator>>(PacketReader& packet, Map& map); 90 friend PacketWriter& operator<<(PacketWriter& packet, const Map& map); 91 }; 92 93 StringTokenizer& operator>> (StringTokenizer&, Map::ObjectType&); 94 95 96 } 97 98 #endif 99