initial commit, lordsawar source, slightly modified
[lordsawar] / src / temple.cpp
1 // Copyright (C) 2001, 2003 Michael Bartl
2 // Copyright (C) 2002, 2003, 2004, 2005, 2006 Ulf Lorenz
3 // Copyright (C) 2006 Andrea Paternesi
4 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
5 // Copyright (C) 2007 Ole Laursen
6 //
7 //  This program is free software; you can redistribute it and/or modify
8 //  it under the terms of the GNU General Public License as published by
9 //  the Free Software Foundation; either version 3 of the License, or
10 //  (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU Library General Public License for more details.
16 //
17 //  You should have received a copy of the GNU General Public License
18 //  along with this program; if not, write to the Free Software
19 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
20 //  02110-1301, USA.
21
22 #include "temple.h"
23 #include "GameMap.h"
24 #include "QuestsManager.h"
25 #include "stack.h"
26
27 std::string Temple::d_tag = "temple";
28
29 Temple::Temple(Vector<int> pos, guint32 width, std::string name, int type)
30 :NamedLocation(pos, width, name,
31                name + _(" can bless your armies or give you quests.")), 
32     d_type(type)
33 {
34     //mark the location on the game map as occupied by a temple
35     for (unsigned int i = 0; i < getSize(); i++)
36       for (unsigned int j = 0; j < getSize(); j++)
37         {
38           Vector<int> pos = getPos() + Vector<int>(i, j);
39           GameMap::getInstance()->getTile(pos)->setBuilding(Maptile::TEMPLE);
40         }
41 }
42
43 Temple::Temple(XML_Helper* helper, guint32 width)
44     :NamedLocation(helper, width)
45 {
46     //mark the location on the game map as occupied by a temple
47     helper->getData(d_type, "type");
48     for (unsigned int i = 0; i < getSize(); i++)
49       for (unsigned int j = 0; j < getSize(); j++)
50         {
51           Vector<int> pos = getPos() + Vector<int>(i, j);
52           GameMap::getInstance()->getTile(pos)->setBuilding(Maptile::TEMPLE);
53         }
54 }
55
56 Temple::Temple(const Temple& t)
57   :NamedLocation(t), d_type(t.d_type)
58 {
59 }
60
61 Temple::Temple(const Temple& t, Vector<int> pos)
62   :NamedLocation(t, pos), d_type(t.d_type)
63 {
64 }
65
66 Temple::~Temple()
67 {
68 }
69
70 bool Temple::save(XML_Helper* helper) const
71 {
72     bool retval = true;
73
74     retval &= helper->openTag(Temple::d_tag);
75     retval &= helper->saveData("id", d_id);
76     retval &= helper->saveData("x", getPos().x);
77     retval &= helper->saveData("y", getPos().y);
78     retval &= helper->saveData("name", getName(false));
79     retval &= helper->saveData("description", getDescription());
80     retval &= helper->saveData("type", d_type);
81     retval &= helper->closeTag();
82     
83     return retval;
84 }