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
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.
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.
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
20 #ifndef LOCATION_BOX_H
21 #define LOCATION_BOX_H
26 #include "Immovable.h"
27 #include "rectangle.h"
34 //! A reference to a rectangular place on the game map.
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.
39 class LocationBox : public Immovable
43 //! Default constructor.
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.
49 LocationBox(Vector<int> pos, guint32 size = 1);
51 //! Non-Standard constructor.
53 * Make a LocationBox from two points.
55 LocationBox(Vector<int> src, Vector<int> dest);
58 LocationBox(const LocationBox&);
60 //! Alternative copy constructor that gives the object a new position.
61 LocationBox(const LocationBox&, Vector<int> pos);
63 //! Loading constructor.
65 * Load the location box from an opened saved-game file.
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.
71 LocationBox(XML_Helper* helper, guint32 size = 1);
74 virtual ~LocationBox();
78 //! Return the size of the location.
79 guint32 getSize() const {return d_size;}
81 //! Returns a rectangle that describes the location.
82 Rectangle getArea() const
83 { return Rectangle(getPos().x, getPos().y, d_size, d_size); }
86 // Methods that operate on the class data and do not modify the class.
88 //! Add an army to a tile that is included in this location.
90 * @param army The army instance to add to a tile in the location.
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.
95 Stack *addArmy(Army *army) const;
97 //! Returns whether this location is at least partially viewable.
99 * This method returns true if the location has parts that are completely
101 * If the location is completely fogged or partially fogged then this
102 * method returns false.
104 * @param player The player whose map to query.
106 bool isVisible(Player *player) const;
108 bool isCompletelyObscuredByFog(Player *player) const;
110 //! Returns whether or not the Location contains the given point?
111 bool contains(Vector<int> pos) const;
113 //! Unobscures the view of this location in the active player's FogMap.
116 //! Unobscures the view of this location in the given player's FogMap.
117 void deFog(Player *p) const;
119 //! Which tile of the location is the fewest number of tiles away from pos.
120 Vector<int> getNearestPos(Vector<int> pos) const;
122 Vector<int> getNearestPos(Movable *m) const;
126 //! Obtains a stack in the location to put an Army unit in.
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
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
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.
143 Stack* getFreeStack(Player *owner, Vector<int> &tile) const;
145 //! Check the location to see if a player can fit another army unit here.
146 bool isFull(Player *owner) const;
150 //! The size of the location.
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.