initial commit, lordsawar source, slightly modified
[lordsawar] / src / vectoredunit.h
1 //  Copyright (C) 2007, 2008, 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 #ifndef VECTOREDUNIT_H
19 #define VECTOREDUNIT_H
20
21 #include <string>
22 #include <sigc++/trackable.h>
23 #include "armyprodbase.h"
24 #include "Ownable.h"
25 #include "LocationBox.h"
26
27 //! An Army that is being vectored to another city.
28 /**
29  *  When Army objects are "vectored" to another city, they disappear for two 
30  *  turns.   While an Army is "in the air", it is represented in one of these 
31  *  objects.
32  */
33 class VectoredUnit: public Ownable, public LocationBox, public sigc::trackable
34 {
35     public:
36         //! The xml tag of this object in a saved-game file.
37         static std::string d_tag; 
38
39         //! Default constructor.
40         /** 
41          * Make a new vectored unit.
42          *
43          * @param pos         The position of the source of the vectored unit.
44          * @param dest        The destination location for the unit.
45          * @param army        The Army prototype that is being vectored.
46          * @param duration    How many turns it takes for the armytype to
47          *                    show up at dest.
48          * @param player      The player that owns the vectored Army unit.
49          */
50         VectoredUnit(Vector<int> pos, Vector<int> dest, ArmyProdBase *army, 
51                      int duration, Player *player);
52
53         //! Copy constructor.
54         /**
55          * Make a new vectored unit by copying it from another one.
56          */
57         VectoredUnit(const VectoredUnit&);
58
59         //! Loading constructor.
60         /**
61          * Make a new vectored unit by loading from an opened saved-game file.
62          * This method loads the lordsawar.vectoredunitlist.vectoredunit XML
63          * entities in the saved-game file.
64          *
65          * @param helper  The opened-saved game file to load the vectored unit
66          *                from.
67          */
68         VectoredUnit(XML_Helper* helper);
69
70         //! Destructor.
71         ~VectoredUnit();
72
73         // Get Methods
74
75         //! Return the position of the destination for this vectored unit.
76         /**
77          * @return The position of a tile on the game map where the vectored
78          *         unit will show up (eventually).
79          */
80         Vector<int>getDestination() const {return d_destination;};
81
82         //! Return how long it will take for the vectored unit to arrive.
83         /**
84          * Returns the number of turns that it takes for this vectored unit
85          * to show up at the destination position on the game map.
86          */
87         int getDuration () const { return d_duration; };
88
89         //! Return a pointer to the Army prototype that is being vectored.
90         /**
91          * @return A pointer to an Army in an Armyset.
92          */
93         ArmyProdBase *getArmy() const { return d_army; };
94
95
96         // Set Methods
97
98         //! Set the position of the destination target for this vectored unit.
99         /**
100          * @param dest  The position of a tile on the game map to have the
101          *              vectored unit show up at.
102          */
103         void setDestination(Vector<int>dest) {d_destination = dest;};
104
105         //! Sets how long it will take for the vectored unit to arrive.
106         /**
107          * @param duration  The number of turns to take before showing up at
108          *                  the destination posititon on the game map.
109          */
110         void setDuration(int duration) {d_duration = duration;};
111
112         //! Set the Army prototype that is being vectored.
113         void setArmy(ArmyProdBase *army) {d_army = army;}
114
115
116         // Methods that operate on class data but do not modify the class
117
118         //! Saves the vectored unit data to an opened saved-game file.
119         bool save(XML_Helper* helper) const;
120
121         //! Called when a vectored unit arrives at the destination.
122         Army *armyArrives() const;
123
124
125         // Methods that operate on class data and modify the class.
126
127         //! Process the vectored unit at the start of a new turn.
128         /**
129          * @return True when this vectored unit has shown up at the destination
130          *         position on the game map.  Otherwise false.
131          */
132         bool nextTurn();
133
134     private:
135
136         // DATA
137
138         //!  The position on the game map that this vectored unit is going to.
139         Vector<int> d_destination;
140
141         //! A pointer to the Army prototype to vector.
142         ArmyProdBase *d_army;
143
144         //! The number of turns remaining until the Army shows up.
145         int d_duration;
146 };
147
148 #endif // VECTOREDUNIT_H
149