initial commit, lordsawar source, slightly modified
[lordsawar] / src / LocationBox.h
1 // Copyright (C) 2000, 2001, 2003 Michael Bartl
2 // Copyright (C) 2000, 2001, 2002, 2004, 2005 Ulf Lorenz
3 // Copyright (C) 2006 Andrea Paternesi
4 // Copyright (C) 2006, 2007, 2008, 2009 Ben Asselstine
5 //
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.
10 //
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.
15 //
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 
19 //  02110-1301, USA.
20 #ifndef LOCATION_BOX_H
21 #define LOCATION_BOX_H
22
23 #include <gtkmm.h>
24 #include <string>
25 #include "vector.h"
26 #include "Immovable.h"
27 #include "rectangle.h"
28
29
30 class Movable;
31 class Player;
32 class Stack;
33 class Army;
34 //! A reference to a rectangular place on the game map.
35 /** 
36  * A LocationBox is a place on the map that has a size.   The size is how many
37  * tiles the place is tall and wide.
38  */
39 class LocationBox : public Immovable
40 {
41  public:
42
43      //! Default constructor.
44      /**
45       * @param pos     The top-right corner of the feature is located at this
46       *                position on the game map.
47       * @param size    The number of tiles wide and high the feature is.
48       */
49      LocationBox(Vector<int> pos, guint32 size = 1);
50
51      //! Non-Standard constructor.
52      /**
53       * Make a LocationBox from two points.
54       */
55      LocationBox(Vector<int> src, Vector<int> dest);
56
57      //! Copy constructor.
58      LocationBox(const LocationBox&);
59
60      //! Alternative copy constructor that gives the object a new position.
61      LocationBox(const LocationBox&, Vector<int> pos);
62
63      //! Loading constructor.
64      /**
65       * Load the location box from an opened saved-game file.
66       *
67       * @param helper  The opened saved-game file to read the location from.
68       * @param size    The size of the place.  This value is not read in
69       *                from the saved-game file.
70       */
71      LocationBox(XML_Helper* helper, guint32 size = 1);
72
73      //! Destructor.
74     virtual ~LocationBox();
75     
76     // Get Methods
77
78     //! Return the size of the location.
79     guint32 getSize() const {return d_size;}
80
81     //! Returns a rectangle that describes the location.
82     Rectangle getArea() const
83         { return Rectangle(getPos().x, getPos().y, d_size, d_size); }
84
85
86     // Methods that operate on the class data and do not modify the class.
87    
88     //! Add an army to a tile that is included in this location.
89     /**
90      * @param army    The army instance to add to a tile in the location.
91      *
92      * @return A pointer to the stack where the Army was added.  Returns NULL
93      *         when the Army couldn't be added because the location is full.
94      */
95     Stack *addArmy(Army *army) const;
96
97     //! Returns whether this location is at least partially viewable.
98     /**
99      * This method returns true if the location has parts that are completely
100      * defogged.
101      * If the location is completely fogged or partially fogged then this 
102      * method returns false.
103      *
104      * @param player The player whose map to query.
105      */
106     bool isVisible(Player *player) const;
107
108     bool isCompletelyObscuredByFog(Player *player) const;
109
110     //! Returns whether or not the Location contains the given point?
111     bool contains(Vector<int> pos) const;
112
113     //! Unobscures the view of this location in the active player's FogMap.
114     void deFog() const;
115
116     //! Unobscures the view of this location in the given player's FogMap.
117     void deFog(Player *p) const;
118
119     //! Which tile of the location is the fewest number of tiles away from pos.
120     Vector<int> getNearestPos(Vector<int> pos) const;
121
122     Vector<int> getNearestPos(Movable *m) const;
123
124  protected:
125
126     //! Obtains a stack in the location to put an Army unit in.
127     /**
128      * This method scans the tiles of the location for a place to put a new
129      * Army unit.  If a stack containing fewer than eight Army units is found, 
130      * that stack is returned.  If there is an open spot in the location where
131      * no Stack exists already, then the TILE parameter is filled up with that
132      * location.  If no open spots could be found at all, and no stacks with 
133      * fewer than eight army units could be found, NULL is returned
134      *
135      * @param owner  The player to own the new stack if one needs to be created.
136      * @param tile   This position on the map is filled up if no stacks with
137      *               enough space for one more army unit could be found in the
138      *               location.
139      *
140      * @return The stack that has room for one Army unit in the Location.  If
141      *         an available stack could not be found, NULL is returned.
142      */
143     Stack* getFreeStack(Player *owner, Vector<int> &tile) const;
144
145     //! Check the location to see if a player can fit another army unit here.
146     bool isFull(Player *owner) const;
147
148     //DATA
149
150     //! The size of the location.
151     /**
152      * This size is the number tiles high and wide the location is.
153      * This value is always 1, except for City objects which are always 2.
154      */
155     guint32 d_size;
156 };
157
158 #endif