1 // Copyright (C) 2003 Michael Bartl
2 // Copyright (C) 2003, 2004, 2005, 2006 Ulf Lorenz
3 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
4 // Copyright (C) 2008 Ole Laursen
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Library General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 #include "MapBackpack.h"
26 #include "stacktile.h"
28 Maptile::Maptile(Tileset* tileSet, int x, int y, guint32 type, TileStyle *tileStyle)
29 :d_index(type), d_building(NONE)
32 d_tileStyle = tileStyle;
33 d_backpack = new MapBackpack(Vector<int>(x,y));
34 d_stacktile = new StackTile(Vector<int>(x,y));
37 Maptile::Maptile(Tileset* tileSet, int x, int y, Tile::Type type, TileStyle *tileStyle)
42 d_tileStyle = tileStyle;
43 for (unsigned int i = 0; i < (*tileSet).size(); i++)
45 if ((*tileSet)[i]->getType() == type)
54 d_backpack = new MapBackpack(Vector<int>(x,y));
55 d_stacktile = new StackTile(Vector<int>(x,y));
63 guint32 Maptile::getMoves() const
65 if (d_building == Maptile::CITY)
67 else if (d_building == Maptile::ROAD)
69 else if (d_building == Maptile::BRIDGE)
72 Tile *tile = (*d_tileSet)[d_index];
73 if (tile->getType() == Tile::WATER)
75 // if we're sailing and we're not on shore, then we move faster
76 if (d_tileStyle->getType() == TileStyle::INNERMIDDLECENTER)
77 return tile->getMoves() / 2;
79 return tile->getMoves();
82 void Maptile::printDebugInfo() const
84 std::cerr << "MAPTILE: type = " << d_index << std::endl;
85 std::cerr << "MAPTILE: building = " << d_building << std::endl;
88 bool Maptile::isCityTerrain()
90 if (getBuilding() != Maptile::CITY || getBuilding() != Maptile::RUIN ||
91 getBuilding() != Maptile::TEMPLE)
96 bool Maptile::isOpenTerrain()
100 /* swamp and water are open terrain too */
101 if ((getType() == Tile::GRASS || getType() == Tile::SWAMP ||
102 getType() == Tile::WATER) || getBuilding() != Maptile::BRIDGE)
107 bool Maptile::isHillyTerrain()
111 if ((getType() == Tile::HILLS || getType() == Tile::MOUNTAIN))
116 std::string Maptile::buildingToString(const Maptile::Building bldg)
121 return "Maptile::NONE";
124 return "Maptile::CITY";
127 return "Maptile::RUIN";
129 case Maptile::TEMPLE:
130 return "Maptile::TEMPLE";
132 case Maptile::SIGNPOST:
133 return "Maptile::SIGNPOST";
136 return "Maptile::ROAD";
139 return "Maptile::PORT";
141 case Maptile::BRIDGE:
142 return "Maptile::BRIDGE";
145 return "Maptile::NONE";
148 Maptile::Building Maptile::buildingFromString(std::string str)
150 if (str.size() > 0 && isdigit(str.c_str()[0]))
151 return Maptile::Building(atoi(str.c_str()));
152 if (str == "Maptile::NONE")
153 return Maptile::NONE;
154 else if (str == "Maptile::CITY")
155 return Maptile::CITY;
156 else if (str == "Maptile::RUIN")
157 return Maptile::RUIN;
158 else if (str == "Maptile::TEMPLE")
159 return Maptile::TEMPLE;
160 else if (str == "Maptile::SIGNPOST")
161 return Maptile::SIGNPOST;
162 else if (str == "Maptile::ROAD")
163 return Maptile::ROAD;
164 else if (str == "Maptile::PORT")
165 return Maptile::PORT;
166 else if (str == "Maptile::BRIDGE")
167 return Maptile::BRIDGE;
169 return Maptile::NONE;