1 // Copyright (C) 2007, 2008 Ben Asselstine
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 std::string Bridge::d_tag = "bridge";
23 Bridge::Bridge(Vector<int> pos, int type)
24 :Location(pos), d_type(type)
26 //mark the location on the game map as occupied by a bridge
27 GameMap::getInstance()->getTile(getPos())->setBuilding(Maptile::BRIDGE);
30 Bridge::Bridge(XML_Helper* helper)
34 helper->getData(type_str, "type");
35 d_type = bridgeTypeFromString(type_str);
37 //mark the location on the game map as occupied by a bridge
38 GameMap::getInstance()->getTile(getPos())->setBuilding(Maptile::BRIDGE);
41 Bridge::Bridge(const Bridge& s)
42 :Location(s), d_type(s.d_type)
46 Bridge::Bridge(const Bridge& s, Vector<int> pos)
47 :Location(s, pos), d_type(s.d_type)
55 bool Bridge::save(XML_Helper* helper) const
59 retval &= helper->openTag(Bridge::d_tag);
60 retval &= helper->saveData("id", d_id);
61 retval &= helper->saveData("x", getPos().x);
62 retval &= helper->saveData("y", getPos().y);
63 std::string type_str = bridgeTypeToString(Bridge::Type(d_type));
64 retval &= helper->saveData("type", type_str);
65 retval &= helper->closeTag();
70 std::string Bridge::bridgeTypeToString(const Bridge::Type type)
74 case Bridge::CONNECTS_TO_EAST:
75 return "Bridge::CONNECTS_TO_EAST";
76 case Bridge::CONNECTS_TO_NORTH:
77 return "Bridge::CONNECTS_TO_NORTH";
78 case Bridge::CONNECTS_TO_WEST:
79 return "Bridge::CONNECTS_TO_WEST";
80 case Bridge::CONNECTS_TO_SOUTH:
81 return "Bridge::CONNECTS_TO_SOUTH";
83 return "Bridge::CONNECTS_TO_EAST";
86 Bridge::Type Bridge::bridgeTypeFromString(const std::string str)
88 if (str.size() > 0 && isdigit(str.c_str()[0]))
89 return Bridge::Type(atoi(str.c_str()));
90 if (str == "Bridge::CONNECTS_TO_EAST")
91 return Bridge::CONNECTS_TO_EAST;
92 else if (str == "Bridge::CONNECTS_TO_NORTH")
93 return Bridge::CONNECTS_TO_NORTH;
94 else if (str == "Bridge::CONNECTS_TO_WEST")
95 return Bridge::CONNECTS_TO_WEST;
96 else if (str == "Bridge::CONNECTS_TO_SOUTH")
97 return Bridge::CONNECTS_TO_SOUTH;
98 return Bridge::CONNECTS_TO_EAST;