initial commit, lordsawar source, slightly modified
[lordsawar] / src / OwnerId.cpp
1 //  Copyright (C) 2009 Ben Asselstine
2 //
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.
7 //
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.
12 //
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 
16 //  02110-1301, USA.
17
18 #include "OwnerId.h"
19 #include "playerlist.h"
20 #include "xmlhelper.h"
21
22 OwnerId::OwnerId()
23 {
24   d_owner_id = 0;
25   owner_id_set = false;
26 }
27
28 OwnerId::OwnerId(guint32 owner)
29   :d_owner_id(owner)
30 {
31   owner_id_set = true;
32 }
33
34 OwnerId::OwnerId(const OwnerId& own)
35   :d_owner_id(own.d_owner_id), owner_id_set(own.owner_id_set)
36 {
37 }
38
39 OwnerId OwnerId::load(XML_Helper *helper)
40 {
41   OwnerId result;
42   int i = -1;
43   helper->getData(i, "owner");
44   if (i == -1)
45     result.setOwnerId(0);
46   else
47     result.setOwnerId(i);
48   return result;
49 }
50
51 OwnerId::OwnerId(XML_Helper* helper)
52 {
53   if (!helper)
54     return;
55   OwnerId result = load(helper);
56   d_owner_id = result.d_owner_id;
57   owner_id_set = true;
58 }
59
60 OwnerId::~OwnerId()
61 {
62 }
63       
64 Player * OwnerId::getOwner() const
65 {
66   if (owner_id_set == false)
67     return NULL;
68
69  return Playerlist::getInstance()->getPlayer(d_owner_id); 
70 }
71   
72 bool OwnerId::save(XML_Helper *helper) const
73 {
74   bool retval = true;
75   retval &= helper->saveData("owner", d_owner_id);
76   return retval;
77 }