1 // Copyright (C) 2003 Michael Bartl
2 // Copyright (C) 2003, 2004, 2005, 2006 Ulf Lorenz
3 // Copyright (C) 2003, 2006 Andrea Paternesi
4 // Copyright (C) 2006, 2007, 2008, 2009, 2010, 2014, 2015, 2020 Ben Asselstine
5 // Copyright (C) 2008 Janek Kozicki
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 #pragma once
23 #ifndef GAMEMAP_H
24 #define GAMEMAP_H
25 
26 #include <sigc++/trackable.h>
27 
28 #include <vector>
29 
30 #include <gtkmm.h>
31 #include "vector.h"
32 #include "rectangle.h"
33 #include "maptile.h"
34 
35 class ArmyProto;
36 class Movable;
37 class Stack;
38 class Location;
39 class Shieldset;
40 class Cityset;
41 class MapGenerator;
42 class XML_Helper;
43 class Port;
44 class Road;
45 class Stone;
46 class City;
47 class Temple;
48 class Bridge;
49 class Ruin;
50 class Armyset;
51 class Signpost;
52 class LocationBox;
53 class Tileset;
54 class Army;
55 
56 //! The model of the map and an interface to interacting with everything on it.
57 /** Class representing the map in the game
58   *
59   * GameMap represents a single map. In most cases this will be the map that is
60   * currently played, but it might be used to preview a map in a mapeditor too.
61   * Notes: GameMap was prefered over Map, because of the potential confusion
62   * with the std::map from the STL.
63   */
64 
65 class GameMap: public sigc::trackable
66 {
67     public:
68 	//! The xml tag of this object in a saved-game file.
69 	static Glib::ustring d_tag;
70 
71 	//! The xml tag of the itemstack subobject in a saved-game file.
72 	static Glib::ustring d_itemstack_tag;
73 
74         /** Singleton function to get the GameMap instance
75           *
76           * @return singleton instance
77           */
getInstance()78         static GameMap* getInstance() {
79           return s_instance ? s_instance : getInstance("", "", ""); };
80 
81 
82         /** Returns singleton instance or creates a new one using the tileset
83           *
84           * @param TilesetName      the name of the tileset to be used
85           * @return singleton instance
86           */
87         static GameMap* getInstance(Glib::ustring TilesetName,
88 				    Glib::ustring Shieldsetname,
89 				    Glib::ustring Citysetname);
90 
91         /** Creates a new singleton instance from a savegame file
92           *
93           * @param helper           see XML_Helper for an explanation
94           *
95           * \note This function deletes an existing instance!
96           */
97         static GameMap* getInstance(XML_Helper* helper);
98 
99         //! Explicitly deletes the singleton instance
100         static void deleteInstance();
101 
102         //! Set the width of the game map
setWidth(int width)103         static void setWidth(int width){s_width = width;}
104 
105         //! Set the height of the game map
setHeight(int height)106         static void setHeight(int height){s_height = height;}
107 
108         //! Returns the width of the map
getWidth()109         static int getWidth() {return s_width;}
110 
111         //! Returns the height of the map
getHeight()112         static int getHeight() {return s_height;}
113 
114         //! Returns the dimensions of the map, as a vector.
get_dim()115 	static Vector<int> get_dim() { return Vector<int>(s_width, s_height); }
116 
117         //! Returns the dimensions of the map, as a Rectangle.
get_boundary()118 	static LwRectangle get_boundary()
119 	    { return LwRectangle(0, 0, s_width, s_height); }
120 
121         //! Returns a pointer to the current Tileset for the map.
122         static Tileset* getTileset();
123 
124         //! Returns a pointer to the current Cityset for the map.
125         static Cityset* getCityset();
126 
127         //! Returns a pointer to the current Shieldset for the map.
128         static Shieldset* getShieldset();
129 
130         /** Change the map's Tileset.
131           *
132           * @param tileset The name of the Tileset to change to.
133           *
134           * \note This just changes the pointer that GameMap returns when
135           * asked for the current Tileset.  switchTileset is more comprehensive.
136           */
137         void setTileset(Glib::ustring tileset);
138 
139         //! Return the width of a tile on the BigMap in pixels after scaling.
140         guint32 getTileSize() const;
141 
142         //! Return the width of a tile on the BigMap in pixels before scaling.
143         guint32 getUnscaledTileSize() const;
144 
145         //! Return the id of the current Tileset.  Returns zero if a valid tileset hasn't been set yet.
146         guint32 getTilesetId() const;
147 
148         //! Return the id of the current Cityset.  Returns zero if a valid cityset hasn't been set yet.
149         guint32 getCitysetId() const;
150 
151         //! Return the id of the current Shieldset.  Returns zero if a valid shieldset hasn't been set yet.
152         guint32 getShieldsetId() const;
153 
154         //! Return the basename of the current Tileset.
155         Glib::ustring getTilesetBaseName() const;
156 
157         //! Return the basename of the current Cityset.
158         Glib::ustring getCitysetBaseName() const;
159 
160         //! Return the basename of the current Shieldset.
161         Glib::ustring getShieldsetBaseName() const;
162 
163         /** Change the map's Shieldset.
164           *
165           * @param shieldset The name of the Shieldset to change to.
166           *
167           * \note This just changes the pointer that GameMap returns when
168           * asked for the current Shieldset.  switchShieldset is more
169           * comprehensive.
170           */
171         void setShieldset(Glib::ustring shieldset);
172 
173         /** Change the map's Cityset.
174           *
175           * @param cityset The name of the Cityset to change to.
176           *
177           * \note This just changes the pointer that GameMap returns when
178           * asked for the current Cityset.  switchCityset is more
179           * comprehensive.
180           */
181         void setCityset(Glib::ustring cityset);
182 
183         /** Change a Maptile on the map.
184           *
185           * @param x The horizontal index of the map.
186           * @param y The vertical index of the map.
187           * @param tile The new Maptile to install at x,y.
188           *
189           * \note This method deletes the old tile if one is already present.
190           * \note A new TileStyle is automatically assigned to the Maptile.
191           */
192 	//void setTile(int x, int y, Maptile *tile);
193 	void setTileIndex(int x, int y, guint32 new_index);
194 
195         /** Change a Maptile on the map.
196           *
197           * @param p The position on the map to modify.
198           * @param tile The new Maptile to install at p.
199           *
200           * \note This method deletes the old tile if one is already present.
201           * \note A new TileStyle is automatically assigned to the Maptile.
202           */
203         //void setTile(Vector<int> p, Maptile *t) {return setTile(p.x, p.y, t);}
setTileIndex(Vector<int> p,guint32 new_index)204         void setTileIndex(Vector<int> p, guint32 new_index) {return setTileIndex(p.x, p.y, new_index);}
205 
206         /** Return a pointer to the City at the given position on the map.
207           *
208           * @param pos The position on the map to look for a City at.
209           *
210           * @return Returns NULL if a City is not at the given position.
211           */
212 	static City* getCity(Vector<int> pos);
213 
214         /** Return a pointer to the City at the position of the given Movable.
215          *
216          * @param m The Movable object to look for a City under.
217          *
218          * \note Stack objects are Movable objects.  This method is used to
219          * return the city that a stack is sitting on.
220          * @return Returns NULL if no City is found.
221          */
222         static City* getCity(Movable *m);
223 
224         /** Return a pointer to the enemy City at the given position on the map.
225          *
226          * @param pos The position on the map to look for an enemy City at.
227          *
228          * \note Enemy cities are defined as cities not owned by the
229          * Playerlist::getActiveplayer().
230          * @return Returns NULL if a City owned by the enemy is not found.
231          */
232 	static City* getEnemyCity(Vector<int> pos);
233 
234         /** Return a pointer to a Ruin at the given position on the map.
235          *
236          * @param pos The position on the map to look for a Ruin at.
237          *
238          * @return Returns NULL if a Ruin is not found.
239          */
240 	static Ruin* getRuin(Vector<int> pos);
241 
242         /** Return a pointer to the Ruin at the position of the given Movable.
243          *
244          * @param m The Movable object to look for a Ruin under.
245          *
246          * @return Returns NULL if a Ruin is not found.
247          */
248         static Ruin* getRuin(Movable *m);
249 
250         /** Return a pointer to a Temple at the given position on the map.
251          *
252          * @param pos The position on the map to look for a Temple at.
253          *
254          * @return Returns NULL if a Temple is not found.
255          */
256 	static Temple* getTemple(Vector<int> pos);
257 
258         /** Return a pointer to the Temple at the position of the given Movable.
259          *
260          * @param m The Movable object to look for a Temple under.
261          *
262          * \note Stack objects are Movable objects.  This method is used to
263          * return the Temple that a Stack is sitting on.
264          *
265          * @return Returns NULL if a Temple is not found.
266          */
267         static Temple* getTemple(Movable *m);
268 
269         /** Return a pointer to a Port at the given position on the map.
270          *
271          * @param pos The position on the map to look for a Port at.
272          *
273          * @return Returns NULL if a Port is not found.
274          */
275 	static Port* getPort(Vector<int> pos);
276 
277         /** Return a pointer to a Road at the given position on the map.
278          *
279          * @param pos The position on the map to look for a Road at.
280          *
281          * @return Returns NULL if a Road is not found.
282          */
283 	static Road* getRoad(Vector<int> pos);
284 
285         /** Return a pointer to a Bridge at the given position on the map.
286          *
287          * @param pos The position on the map to look for a Bridge at.
288          *
289          * @return Returns NULL if a Bridge is not found.
290          */
291 	static Bridge* getBridge(Vector<int> pos);
292 
293         /** Return a pointer to a Signpost at the given position on the map.
294          *
295          * @param pos The position on the map to look for a Signpost at.
296          *
297          * @return Returns NULL if a Signpost is not found.
298          */
299 	static Signpost* getSignpost(Vector<int> pos);
300 
301         /** Return a pointer to a Signpost at the position of the given Movable.
302          *
303          * @param m The Movable object to look for a Signpost under.
304          *
305          * \note Stack objects are Movable objects.  This method is used to
306          * return the Signpost that a Stack is sitting on.
307          *
308          * @return Returns NULL if a Signpost is not found.
309          */
310         static Signpost* getSignpost(Movable *m);
311 
312         /** Return a pointer to the Stack at the given position on the map.
313          *
314          * @param pos The position on the map to look for a stack at.
315          *
316          * \note This method does not take into account the
317          * Playerlist::getActiveplayer().  It simply returns a pointer to the
318          * first stack it finds at the given location.
319          * \note More than one stack can sit on a tile.  This method just
320          * returns a pointer to a single stack.
321          *
322          * @return Returns NULL if a Stack is not found.
323          */
324 	static Stack* getStack(Vector<int> pos);
325 
326         /** Return a pointer to the Stacktile object at the given position on the map.
327          *
328          * @param pos The position on the map to return the Stacktile for.
329          *
330          * \note Every tile has a Stacktile object on it, even if it does not
331          * contain any stacks.
332          * \note This method is one way to return all of the stacks on a tile.
333          *
334          * @return A pointer to the Stacktile object, or NULL if the position
335          * is out of range.
336          */
337 	static StackTile* getStacks(Vector<int> pos);
338 
339         /** Merge all the stacks at the given position on the map into a single Stack.
340          *
341          * @param pos The position on the map to merge Stack objects on.
342          *
343          * \note Only stacks belonging to the Playerlist::getActiveplayer() are
344          * merged.
345          *
346          * @return When friendly stacks are found at the given position, this
347          * method returns a pointer to the Stack object that holds all of the
348          * army units.  Returns NULL if no stacks are present at the given
349          * position, or if the position is out of range.
350          */
351 	static Stack *groupStacks(Vector<int> pos);
352 
353         /** Merge all the stacks at the position of the given Stack into a single Stack.
354          *
355          * @param s A pointer to the Stack whose position will be used to
356          * merge Stack objects on.
357          *
358          * \note Only stacks belonging to the Playerlist::getActiveplayer() are
359          * merged.
360          * @return When friendly stacks are found at the given position, this
361          * method returns a pointer to the Stack object that holds all of the
362          * army units.  Returns NULL if no stacks are present at the given
363          * position.
364          */
365 	static void groupStacks(Stack *s);
366 
367         /** Merge the stacks owned by Player at the given position into a single Stack.
368          * @param pos The position on the map to merge Stack objects on.
369          * @param player Merge the stacks belonging to this Player.
370          *
371          * @return When stacks belonging to the Player are found at the given
372          * position, this method returns a pointer to the Stack object that
373          * holds all of the army units.  Returns NULL if no stacks belonging
374          * to Player are present at the given position, or if the position is
375          * out of range.
376          */
377         Stack *groupStacks(Vector<int> pos, Player *player);
378 
379         /** Check whether a Stack can join another one.
380          *
381          * @param src  The source Stack object.
382          * @param dest The destination Stack object that is checked to see if
383          * the source Stack can join.
384          *
385          *  \note Only Stack objects belonging to the owner of the src Stack
386          *  are considered.
387          *
388          *  @return Returns True if the number of Army units in the new Stack
389          *  would not exceed MAX_STACK_SIZE.   Returns False if the number of
390          *  Army units in the new Stack would exceed MAX_STACK_SIZE.
391          */
392 	static bool canJoin(const Stack *src, Stack *dest);
393 
394         /** Check whether a Stack can join stacks at the given position.
395          *
396          * @param stack  The Stack object to see if we can join elsewhere.
397          * @param pos  The position on the map.
398          *
399          *  \note Only Stack objects belonging to the owner of the src Stack
400          *  are considered.
401          *
402          *  @return Returns True if there are no stacks at the given position,
403          *  or if the number of Army units in the new Stack would not
404          *  exceed MAX_STACK_SIZE.  Returns False if the number of Army units
405          *  in the new Stack would exceed MAX_STACK_SIZE.
406          */
407 	static bool canJoin(const Stack *stack, Vector<int> pos);
408 
409         /** Check to see if an Army can be added to the given position.
410          *
411          * @param pos  The position on the map.
412          *
413          * @return Returns True if the number of Army units at the given
414          * position is less than MAX_ARMIES_ON_A_SINGLE_TILE.  Otherwise False
415          * is returned.
416          */
417 	static bool canAddArmy(Vector<int> pos);
418 
419         /** Check to see if Armies can be added to the given position.
420          *
421          * @param dest  The position on the map to check if armies can be added at.
422          * @param stackSize The number of Army units to check if can be added.
423          *
424          * @return Returns True if the number of Army units at the given
425          * position is less than MAX_ARMIES_ON_A_SINGLE_TILE.  Otherwise False
426          * is returned.
427          */
428 	static bool canAddArmies(Vector<int> dest, guint32 stackSize);
429 
430         /** Returns a pointer to a Stack belonging to the active player at the given position.
431          *
432          * @param pos The position on the map to check for a friendly Stack at.
433          *
434          * \note Friendly Stack objects are defined as stacks owned by the
435          * Playerlist::getActiveplayer().
436          * \note More than one stack can sit on a tile.  This method just
437          * returns a pointer to a single stack.
438          *
439          * @return Returns NULL if a Stack is not found.
440          */
441 	static Stack* getFriendlyStack(Vector<int> pos);
442 
443         /** Returns all of the stacks at the given position belonging to the given Player.
444          *
445          * @param pos The position on the map to check for Stack objects at.
446          * @param player Stacks owned by this Player will be returned.
447          *
448          * @return Returns an empty list if no stacks are found, otherwise a
449          * vector of pointers to Stack objects is returned.
450          */
451 	static std::vector<Stack*> getFriendlyStacks(Vector<int> pos, Player *player = NULL);
452 
453         /** Return a pointer to a Stack at the given position not belonging to the active player.
454          *
455          * @param pos The position on the map to check for a Stack at.
456          *
457          * \note Enemy Stack objects are defined as stacks not owned by the
458          * Playerlist::getActiveplayer().
459          *
460          * @return Returns NULL if a Stack is not found.
461          */
462 	static Stack* getEnemyStack(Vector<int> pos);
463 
464         /** Returns all of the stacks at the given position not belonging to the given Player.
465          *
466          * @param pos The position on the map to check for Stack objects at.
467          * @param player Stacks not owned by this Player will be returned.
468          *
469          * @return Returns an empty list if no stacks are found, otherwise a
470          * vector of pointers to Stack objects is returned.
471          */
472 	static std::vector<Stack*> getEnemyStacks(Vector<int> pos, Player *player = NULL);
473 
474         /** Returns all stacks not belonging to the active player at the given positions.
475          *
476          * @param posns A list of positions on the map to check for enemy stacks on.
477          * \note Enemy Stack objects are defined as stacks not owned by the
478          * Playerlist::getActiveplayer().
479          * @return Returns an empty list if no stacks are found, otherwise a
480          * list of pointers to Stack objects is returned.
481          */
482 	static std::vector<Stack*> getEnemyStacks(std::list<Vector<int> > posns);
483 
484         /** Returns all stacks belonging to the active player that are within a given distance from a given position.
485          *
486          * @param pos The center of the box to find friendly Stack objects in.
487          * @param dist Any tile this far from pos is deemed to be in the box.
488          *
489          * \note When dist is 1, the size of the box checked is 3x3.
490          * \note Friendly Stack objects are defined as stacks owned by the
491          * Playerlist::getActiveplayer().
492          * \note The returned list of Stack objects is sorted by their distance
493          * away from pos.
494          * @return Returns an empty list if no stacks are found, otherwise a
495          * vector of pointers to Stack objects is returned.
496          */
497 	static std::vector<Stack*> getNearbyFriendlyStacks(Vector<int> pos, int dist);
498 
499         /** Returns all stacks not belonging to the active player that are within a given distance from a given position.
500          *
501          * @param pos The center of the box to find enemy Stack objects in.
502          * @param dist Any tile this far from pos is deemed to be in the box.
503          *
504          * \note When dist is 1, the size of the box checked is 3x3.
505          * \note Enemy Stack objects are defined as stacks not owned by the
506          * Playerlist::getActiveplayer().
507          * \note The returned list of Stack objects is sorted by their distance
508          * away from pos.
509          *
510          * @return Returns an empty list if no stacks are found, otherwise a
511          * list of pointers to Stack objects is returned.
512          */
513 	static std::vector<Stack*> getNearbyEnemyStacks(Vector<int> pos, int dist);
514 
515         /** Returns a list of positions that are within a given distance from a given position.
516          *
517          * @param pos The center of the box to return positions for.
518          * @param dist Any tile this far from pos is deemed to be in the box.
519          *
520          * \note When dist is 1, the size of the box is 3x3.
521          * \note The returned list of positions is sorted by their distance away from pos (the center).
522          *
523          * @return Returns a vector of valid map positions.
524          */
525         static std::list<Vector<int> > getNearbyPoints(Vector<int> pos, int dist);
526 
527         /** Returns the number of Army units at a given position on the map.
528          *
529          * @param pos The position on the map to count Army units for.
530          *
531          * \note Only Army units in stacks belonging to the
532          * Playerlist::getActiveplayer are counted.
533          *
534          * @return Returns the number of army units, or zero if the position is
535          * out of range.
536          */
537 	static guint32 countArmyUnits(Vector<int> pos);
538 
539         /** Returns a pointer to the Backpack object at the given position.
540          *
541          * @param pos The position on the map to get the Backpack object for.
542          *
543          * \note There is a Backpack object on every tile.  However it is
544          * usually empty of Item objects.
545          *
546          * @return Returns NULL if pos is out of range.  Otherwise a pointer
547          * to a MapBackpack object is returned.
548          */
549 	static MapBackpack *getBackpack(Vector<int> pos);
550 
551         //! Return how many bags of stuff there are on the map.
552         static guint32 countBags ();
553 
554         /** Check if the given Stack is able to search the Maptile it is on.
555          *
556          * @param stack A pointer to the stack to check if it can search.
557          *
558          * \note This involves checking if the Stack is on a Temple, or if a
559          * Hero is on a Ruin.
560          *
561          * @return Returns True if the stack can search, otherwise False is
562          * returned.
563          */
564         static bool can_search(Stack *stack);
565 
566         /** Check if the Stack can plant a standard on the Maptile it is on.
567          *
568          * @param stack A pointer to the stack to check if it can plant a
569          * standard.
570          *
571          * \note This involves checking if the Stack contains a Hero, who has
572          * the standard Item, and isn't on Maptile that has a building.
573          *
574          * \note Standards are special items that can be vectored to, when
575          * planted in the ground.
576          *
577          * @return Returns True if the stack can plant the standard.  Otherwise
578          * false is returned.
579          */
580         static bool can_plant_flag(Stack *stack);
581 
582         /** Check if the Stack can go into defend mode.
583          *
584          * @param stack A pointer to the stack to check if it can go into
585          * defend mode.
586          *
587          * \note This involves checking if the Stack is on a suitable tile,
588          * namely, not on water, or in a building.
589          * \note If the stack is already in defend mode, this method will
590          * still return True.
591          *
592          * Returns True if the stack can go into defend mode.  Otherwise false
593          * is returned.
594          */
595         static bool can_defend(Stack *stack);
596 
597         /** Return a list of all MapBackpack objects that contain Item objects.
598          *
599          * \note This refers to the "bags of stuff" that can appear on the map.
600          *
601          * \note Planted Standards are a special case of a MapBackpack object.
602          *
603          * @return A list of pointers to MapBackpack objects that contain one
604          * or more items.
605          */
606         std::list<MapBackpack*> getBackpacks() const;
607 
608         /** Return a pointer to the Maptile object at position (x,y).
609          *
610          * @param x The horizontal index of the map.
611          * @param y The vertical index of the map.
612          *
613          * \note Every square of the map contains a MapTile object.
614          *
615          * @return Returns NULL when the given position is out of range.
616          * Otherwise a pointer to a Maptile object is returned.
617          */
getTile(int x,int y)618         inline Maptile* getTile(int x, int y) const { return &d_map[y*s_width + x]; };
619 
620         /** Return a pointer to the Maptile object at the given position.
621          *
622          * @param pos The position on the map to get a Maptile object for.
623          *
624          * \note Every square of the map contains a MapTile object.
625          *
626          * @return Returns NULL when the given position is out of range.
627          * Otherwise a pointer to a Maptile object is returned.
628          */
getTile(Vector<int> p)629         inline Maptile* getTile(Vector<int> p) const {return getTile(p.x, p.y);}
630 
631         /** Try to insert an Army in this Location on the map.
632          *
633          * @param l A pointer to the Location to insert the Army into.
634          * @param a A pointer to the Army object to insert.
635          *
636          * \note The tiles of the Location are checked-for in a left-to-right,
637          * top-to-bottom fashion.
638          *
639          * @return Returns a pointer to the Stack that the Army is added to.
640          * Otherwise, if the Location is too full too accept another Army,
641          * NULL is returned.
642          */
643 	Stack* addArmy(Location *l, Army *a);
644 
645         /** Try to insert an Army on or near the given position on the map.
646          *
647          * @param pos The position on the map to insert an Army at.
648          * @param a A pointer to the Army object to insert.
649          *
650          * \note If the given position cannot accept another Army, the next
651          * closest position is tried.  It must be on land if pos is on land,
652          * and water if pos is on water.
653          *
654          * @return Returns a pointer to the Stack that the Army is added to.
655          * Otherwise, if there is no suitable place for the Army unit, NULL
656          * is returned.
657          */
658         Stack* addArmyAtPos(Vector<int> pos, Army *a);
659 
660         /** Try to insert an Army on or near a building at the given position on map.
661          *
662          * @param pos The position on the map to insert an Army at.
663          * @param a A pointer to the Army object to insert.
664          *
665          * \note If the Army cannot be inserted into a building at the given
666          * position, addArmyAtPos is called as a last resort.
667          *
668          * @return Returns a pointer to the Stack that the Army is added to.
669          * Otherwise, if there is no suitable place for the Army unit, NULL
670          * is returned.
671          */
672         Stack* addArmy(Vector<int> pos, Army *a);
673 
674         /** Insert a given number of Army units at a given position.
675          *
676          * @param a  A pointer to the ArmyProto object describing the kind of
677          * Army unit to insert.
678          * @param num_allies The number of army units to try to insert.
679          * @param pos The position on the map to add the Army units to.
680          *
681          * \note Not all of the Army units are guaranteed to be inserted.
682          */
683         void addArmies(const ArmyProto *a, guint32 num_allies, Vector<int> pos);
684 
685         /** Returns the position of the planted standard owned by the given Player.
686          *
687          * @param p A pointer to the Player object to find the planted standard
688          * for.
689          *
690          * @return Returns the position of the planted standard on the map, or
691          * otherwise a position of -1,-1 is returned if the standard is not
692          * planted anywhere.
693          */
694         Vector<int> findPlantedStandard(Player *p);
695 
696         /** Fill the map using the data supplied by a map generator.
697           *
698           * @param generator A pointer to the MapGenrator which supplies the
699           * terrain data
700           *
701           * \note This method assigns new Maptile objects for every square of
702           * the map.
703           *
704           * @return Returns True on success, False on error.
705           */
706         bool fill(MapGenerator* generator);
707 
708         /** Fills the whole map with a single terrain.
709           *
710           * @param type The type of the terrain to fill the map with.  This is
711           * an index in the tileset.
712           *
713           * \note This method assigns new Maptile objects for every square of
714           * the map.
715           *
716           * @return Returns True on success, False on error.
717           */
718         bool fill(guint32 type);
719 
720         /** Save the contents of the map.
721           *
722           * @param helper A pointer to an XML file opened for writing.
723           *
724           * @return Returns True if saving went well, False otherwise.
725           */
726         bool save(XML_Helper* helper) const;
727 
728         /** Calculate what tiles can be traveled to by a non-flying Stack.
729          *
730          * For each tile on the map, check to see where land and water meet,
731          * along with cities, ports and bridges.  This method updates the
732          * internal state of which tile can be reached from an adjacent tile.
733          */
734         void calculateBlockedAvenues();
735 
736         /** Calculate what tiles can be traveled to by a non-flying Stack for the given position.
737          *
738          * This method updates the internal state of which of the adjacent
739          * tiles can be traveled to.  For example, the way is not blocked when
740          * a stack is on a bridge and the adjacent tile is water.
741          */
742 	void calculateBlockedAvenue(int i, int j);
743 
744         /** Load the Stack objects from Stacklist objects into StackTile objects.
745          * Loop over all players and all of their stacks, adding the stacks to
746          * the state of the StackTile objects associated with every square of
747          * map.
748          */
749 	void updateStackPositions();
750 
751         /** Forget the state of all of the StackTile objects.
752          */
753         void clearStackPositions();
754 
755 	/** Smooth a portion of the terrain on the big map.
756 	 *
757          * @param r The area of the map to modify.
758          * @param smooth_terrain Whether or not we want to demote lone tiles
759          * to be similar to the terrain of nearby tiles.
760          *
761 	 * Give each tile in the prescribed area the preferred picture for
762 	 * the underlying terrain tile.
763          *
764          * \note This method changes the TileStyle associated with a tile's
765          * Maptile object.
766 	 */
767 	void applyTileStyles (LwRectangle r, bool smooth_terrain);
768 
769 	/** Smooth a portion of the terrain on the big map.
770 	 *
771          * @param minx The top left horizontal coordinate.
772          * @param miny The top left vertical coordinate.
773          * @param maxx The bottom right horizontal coordinate.
774          * @param maxy  The bototm right vertical coordinate.
775          * @param smooth_terrain Whether or not we want to demote lone tiles
776          * to be similar to the terrain of nearby tiles.
777          *
778 	 * Give each tile in the prescribed area the preferred picture for
779 	 * the underlying terrain tile.
780          *
781          * \note This method changes the TileStyle associated with a tile's
782          * Maptile object.
783 	 */
784 	void applyTileStyles (int minx, int miny, int maxx, int maxy,
785 			      bool smooth_terrain);
786 
787 	/** Change how the terrain looks at given position on the big map.
788 	 *
789          * @param i The horizontal index of the map.
790          * @param j The vertical index of the map.
791          *
792          * This method determines what the appropriate TileStyle is for the
793          * given position on the map.  It's easy to figure out for regular old
794          * grass tiles, but it's more difficult for forest tiles.
795          *
796          * \note This method changes the TileStyle associated with a tile's
797          * Maptile object.
798 	 */
799 	void applyTileStyle (int i, int j);
800 
801         /** Make the mountains look right by making them transition to hills.
802          * Mountains are treated differently than every other terrain types
803          * because unlike all the other terrain types, they transition to
804          * hills, not grass.  This method ensures that mountain tiles
805          * transition to hill tiles.
806          * \note This method changes the TileStyle associated with a tile's
807          * Maptile object.
808          */
809 	void surroundMountains(int minx, int miny, int maxx, int maxy);
810 
811 	/** Returns the positions of all of the items on the game map (in bags).
812          *
813          * \note This does not include the position of items that heroes are
814          * carrying around.  It only includes dropped items, including planted
815          * standards.
816          *
817          * @return Returns a vector of positions of bags on the map.  An empty
818          * list is returned when there are no dropped items on the map.
819          */
820 	std::vector<Vector<int> > getItems();
821 
822         /** Find the closest road, bridge, city, ruin, or temple to the north of the given position.
823          *
824          * @pos The position to search for an object from.
825          *
826          * @return Returns the position of the closest object, or if there are
827          * none, -1,-1 is returned.
828          */
829 	Vector<int> findNearestObjectToTheNorth(Vector<int> pos);
830 
831         /** Find the closest road, bridge, city, ruin, or temple to the south of the given position.
832          *
833          * @pos The position to search for an object from.
834          *
835          * @return Returns the position of the closest object, or if there are
836          * none, -1,-1 is returned.
837          */
838 	Vector<int> findNearestObjectToTheSouth(Vector<int> pos);
839 
840         /** Find the closest road, bridge, city, ruin, or temple to the east of the given position.
841          *
842          * @pos The position to search for an object from.
843          *
844          * @return Returns the position of the closest object, or if there are
845          * none, -1,-1 is returned.
846          */
847 	Vector<int> findNearestObjectToTheEast(Vector<int> pos);
848 
849         /** Find the closest road, bridge, city, ruin, or temple to the west of the given position.
850          *
851          * @pos The position to search for an object from.
852          *
853          * @return Returns the position of the closest object, or if there are
854          * none, -1,-1 is returned.
855          */
856 	Vector<int> findNearestObjectToTheWest(Vector<int> pos);
857 
858         /** Change the current Armyset to a different one.
859          *
860          * @param armyset A pointer to the Armyset to change to.
861          *
862          * Loops through all of the players and changes their armyset to given
863          * one.  All Army units are updated, including ones in ruins, and the
864          * city production slots.  If the new armyset doesn't have an army
865          * type, army units of that type are erased.
866          *
867          */
868 	void switchArmysets(Armyset *armyset);
869 
870         /** Change the current Cityset to a different one.
871          *
872          * @param cityset A pointer to the Cityset to change to.
873          *
874          * Loops through all of the cities, temples and ruins to change the
875          * way they look.  These buildings may be moved to different tiles on
876          * the map because the number of tiles a city takes up, e.g. 2x2 can
877          * be changed to a bigger or smaller footprint.
878          */
879 	void switchCityset(Cityset *cityset);
880 
881         /** Change the current Shieldset to a different one.
882          *
883          * @param shieldset A pointer to the Shieldset to change to.
884          *
885          * Loops through all Shields and change the way they look.  This
886          * changes the colour of army units, flags, shields, and selector, as
887          * well as the graphics of the shields.
888          */
889 	void switchShieldset(Shieldset *shieldset);
890 
891         /** Change the current Tileset to a different one.
892          *
893          * @param tileset A pointer to the Tileset to change to.
894          *
895          * Change the way the terrain looks on the big map and the small map.
896          * Also change the way the flags look, the explosion, the roads, the
897          * fog, and the army unit selector animation.
898          *
899          * \note This method changes the TileStyle objects associated with
900          * every tile's associated Maptile object.
901          */
902 	void switchTileset(Tileset *tileset);
903 
904         /** Load the current Shieldset again.
905          * Throw away the state of the current Shieldset, and load it up from
906          * the shieldset file.  Includes loading images.
907          */
908         void reloadShieldset();
909 
910         /** Load the current Tileset again.
911          * Throw away the state of the current Tileset, and load it up from
912          * the tileset file.  Includes loading images.
913          */
914         void reloadTileset();
915 
916         /** Load the current Cityset again.
917          * Throw away the state of the current Cityset, and load it up from
918          * the cityset file.  Includes loading images.
919          */
920         void reloadCityset();
921 
922         /** Load the given Armyset again.
923          *
924          * @param armyset A pointer to the armyset to reload.
925          *
926          * Throw away the state of the given Armyset, and load it up from
927          * the armyet file.  Includes loading images.
928          */
929         void reloadArmyset(Armyset *armyset);
930 
931         /** Move a building from one place to another on the map.
932          *
933          * @param from The source position of a building.
934          * @param to The destination position for the building.
935          * @param new_width How many tiles the building should occupy.
936          *
937          * Move a city, ruin, temple, port, signpost, road tile or bridge tile
938          * on the map.
939          *
940          * \note The whole road or bridge does not get moved.  Just a single
941          * tile.  Whole cities, ruins, temples, etc get moved.
942          *
943          * \note The new_width is also the height in tiles.  0 means ignore.
944          *
945          * @return Returns True if successful.  Otherwise False.
946          */
947 	bool moveBuilding(Vector<int> from, Vector<int> to, guint32 new_width = 0);
948         /** Check if we can put a given building type, of a given size at a given location.
949          * @param bldg  The type of building to check if we can put down.
950          * @param size  The width in tiles of the building.  e.g. 2 means 2x2.
951          * @param to  The position on the map to check if we can put a building on.
952          * @param making_islands  Whether or not to create grass underneath a
953          * city, ruin, temple, orsignpost.  False means to create grass.
954          *
955          * @return Returns True if the desired building can be put down.
956          * Otherwise False.
957          */
958 	bool canPutBuilding(Maptile::Building bldg, guint32 size, Vector<int> to, bool making_islands = true);
959 
960 
961         /** Check if we can put some items here.
962          *
963          * @param pos  where on the map we're dropping the bag
964          *
965          * @return Returns True if we can drop it, otherwise false.
966          */
967         bool canDropBag (Vector<int> pos);
968 
969         /** Check if a stack of the given size, owned by the given player, can be added to the given position.
970          * @param size The number of army units to check if we can add.
971          * @param p Only stacks owned by this player are considered.
972          * @param to The position on the map to check if we can add them at.
973          * @return Returns True if the desired stack can be put down, otherwise
974          * False.
975          */
976 	bool canPutStack(guint32 size, Player *p, Vector<int> to);
977 
978         /** Move a given stack to a given position on the map.
979          *
980          * @param stack A pointer to the stack to be moved.
981          * @param to The destination position to move it to.
982          *
983          * \note This method is used to move a stack far distances, without
984          * losing any movement points.
985          * \note When moving a stack into an enemy city, it changes ownership
986          * of the stack to be the same owner as the city.
987          *
988          * @return Returns True if the stack is moved successfully, otherwise
989          * False.
990          */
991 	bool moveStack(Stack *stack, Vector<int> to);
992 
993         /** Move a bag of stuff from one position on the map, to another.
994          *
995          * @param bag The bag of stuff we're moving.
996          * @param to The destination position.
997          *
998          * \note Every square has a Backpack object, but only some of them
999          * contain Item objects.
1000          *
1001          * If there are items in the Backpack located at the source position,
1002          * they are removed and added to the destination position.
1003          */
1004 	void moveBackpack(MapBackpack *bag, Vector<int> to);
1005 
1006         /** Returns the size of the building at the given position on the map.
1007          *
1008          * @param tile  The position on the map of a building to get the size for.
1009          *
1010          * This method gets the width in tiles of any of the building objects
1011          * specified by Maptile::Building.  e.g. a size of 2 means 2x2 tiles.
1012          *
1013          * @return Returns the size of the building in tiles, or zero if there
1014          * isn't a building at that position.
1015          */
1016 	guint32 getBuildingSize(Vector<int> tile);
1017 
1018         /** Get the building type at a given position on the map.
1019          *
1020          * @param tile The position on the map to get a building type of.
1021          *
1022          * @return Returns a building type if one is present at the given
1023          * position, or Maptile::NONE if one is not present, or if the given
1024          * position is out of range.
1025          */
getBuilding(Vector<int> tile)1026 	inline Maptile::Building getBuilding(Vector<int> tile) const
1027           {
1028             Maptile *t = getTile(tile);
1029             return t ? t->getBuilding() : Maptile::NONE;
1030           }
1031 
1032         /** Count the number of tiles occupied by buildings of a given type.
1033          *
1034          * @param building_type A Maptile::Building representing the kind of
1035          * constructed entities that are to be counted.
1036          *
1037          * @return Returns the number of tiles occupied by building_type;
1038          */
1039         guint32 countBuildings(Maptile::Building building_type);
1040 
1041         /** Return the kind of terrain at a given position on the map.
1042          *
1043          * @param tile A position on the map to get the terrain kind for.
1044          *
1045          * @return Returns a Tile::Type for the given position.  Tile::NONE is
1046          * returned if the given position is out of bounds.
1047          */
getTerrainType(Vector<int> tile)1048 	inline Tile::Type getTerrainType(Vector<int> tile) const
1049           {
1050             Maptile *t = getTile(tile);
1051             return t ? t->getType() : Tile::NONE;
1052           }
1053 
1054         /** Change the building type of a tile.
1055          *
1056          * @param tile A position on the map to change the building type of.
1057          *
1058          * \note This is merely changing a lookup flag of what building is
1059          * present on this tile.  It isn't making a new City or Ruin.
1060          */
1061 	void setBuilding(Vector<int> tile, Maptile::Building building);
1062 
1063         /** Drop a new City at the given position on the map.
1064          *
1065          * @param tile The position to create a new City at.
1066          *
1067          * \note The terrain under the City is changed to grass.
1068          * \note The new City is owned by Playerlist::getActiveplayer().
1069          *
1070          * @return Returns True if a City was created.  Otherwise False if a
1071          * City is not placed at the given position.
1072          */
1073         bool putNewCity(Vector<int> tile);
1074 
1075         /** Put the given City on the map.
1076          *
1077          * @param c A pointer to the City to add to the map.
1078          * @param keep_owner Whether or not to reassign ownership to
1079          * Playerlist::getActiveplayer().
1080          *
1081          * \note The position of the City is held in the City object.
1082          *
1083          * \note This method doesn't do any checking if the City can be
1084          * added to the given position or not.  Callers are expected to do
1085          * this check beforehand.
1086          *
1087          * @return Always returns True.
1088          */
1089 	bool putCity(City *c, bool keep_owner = false);
1090 
1091         /** Erase a City from the given position from the map.
1092          *
1093          * @param pos The position on the map to erase a City from.
1094          *
1095          * @return Returns True if a City was erased.  Otherwise, False.
1096          */
1097 	bool removeCity(Vector<int> pos);
1098 
1099         /** Add a given Ruin to the map.
1100          *
1101          * @param r A pointer to the Ruin to add to the map.
1102          *
1103          * \note If the terrain under the Ruin is water, it is changed to grass.
1104          *
1105          * \note The position of the Ruin is held in the Ruin object.
1106          *
1107          * \note This method doesn't do any checking if the Ruin can be
1108          * added to the given position or not.  Callers are expected to do
1109          * this check beforehand.
1110          *
1111          * @return Always returns True.
1112          */
1113 	bool putRuin(Ruin *r);
1114 
1115         /** Drop a new Ruin at the given position on the map.
1116          *
1117          * @param tile The position to create a new Ruin at.
1118          *
1119          * @return Returns True if a Ruin was created.  Otherwise False if a
1120          * Ruin is not placed at the given position.
1121          */
1122         bool putNewRuin(Vector<int> tile);
1123 
1124         /** Erase a ruin from the given position from the map.
1125          *
1126          * @param pos The position on the map to erase a Ruin from.
1127          *
1128          * @return Returns True if a Ruin was erased.  Otherwise, False.
1129          */
1130 	bool removeRuin(Vector<int> pos);
1131 
1132         /** Add a given Temple to the map.
1133          *
1134          * @param t A pointer to the Temple to add to the map.
1135          *
1136          * \note If the terrain under the Temple is water, it is changed to
1137          * grass.
1138          *
1139          * \note The position of the Temple is held in the Temple object.
1140          *
1141          * \note This method doesn't do any checking if the Temple can be
1142          * added to the given position or not.  Callers are expected to do
1143          * this check beforehand.
1144          *
1145          * @return Always returns True.
1146          */
1147 	bool putTemple(Temple *t);
1148 
1149         /** Drop a new Temple at the given position on the map.
1150          *
1151          * @param tile The position on the map to create a new Temple at.
1152          *
1153          * @return Returns True if a Temple was created.  Otherwise False if a
1154          * Temple is not placed at the given position.
1155          */
1156         bool putNewTemple(Vector<int> tile);
1157 
1158         /** Erase a Temple from the given position from the map.
1159          *
1160          * @param pos The position on the map to erase a Temple from.
1161          *
1162          * @return Returns True if a Temple was erased.  Otherwise, False.
1163          */
1164 	bool removeTemple(Vector<int> pos);
1165 
1166 	static Stone* getStone(Vector<int> pos);
1167 	bool putStone(Stone *t);
1168         bool putNewStone(Vector<int> tile);
1169 	bool removeStone(Vector<int> pos);
1170 
1171         /** Add a given Road tile to the map.
1172          *
1173          * @param t A pointer to the Road tile to add to the map.
1174          *
1175          * @param smooth whether or not surrounding road types should be
1176          * changed to align.
1177          *
1178          * The road type is calculated and changed according to the other road
1179          * and bridge tiles nearby.
1180          *
1181          * \note If the terrain under the Road is water, it is changed to
1182          * grass.
1183          *
1184          * \note The position of the Road is held in the Road object.
1185          *
1186          * \note This method doesn't do any checking if the Road can be
1187          * added to the given position or not.  Callers are expected to do
1188          * this check beforehand.
1189          *
1190          * @return Always returns True.
1191          */
1192 	bool putRoad(Road *r, bool smooth=true);
1193 
1194         /** Drop a new Road tile at the given position on the map.
1195          *
1196          * @param tile The position on the map to create a new Road at.
1197          *
1198          * The road type is calculated and changed according to the other road
1199          * and bridge tiles nearby.
1200          *
1201          * @return Returns True if a Road was created.  Otherwise False if a
1202          * Road is not placed at the given position.
1203          */
1204         bool putNewRoad(Vector<int> tile);
1205 
1206         /** Erase a Road tile from the given position from the map.
1207          *
1208          * @param pos The position on the map to erase a Road from.
1209          *
1210          * \note The type of other nearby Road tiles are not modified as a
1211          * result of erasing this Road.
1212          *
1213          * @return Returns True if a Road was erased.  Otherwise, False.
1214          */
1215 	bool removeRoad(Vector<int> pos);
1216 
1217         /** Add a given Bridge tile to the map.
1218          *
1219          * @param t A pointer to the Bridge tile to add to the map.
1220          *
1221          * The bridge type is calculated and changed according to the other
1222          * road and bridge tiles nearby.
1223          *
1224          * \note If the terrain under the Bridge is water, it is changed to
1225          * grass.
1226          *
1227          * \note The position of the Bridge is held in the Bridge object.
1228          *
1229          * \note This method doesn't do any checking if the Bridge can be
1230          * added to the given position or not.  Callers are expected to do
1231          * this check beforehand.
1232          *
1233          * @return Always returns True.
1234          */
1235 	bool putBridge(Bridge *b);
1236 
1237         /** Erase a Bridge tile from the given position from the map.
1238          *
1239          * @param pos The position on the map to erase a Bridge from.
1240          *
1241          * @return Returns True if a Bridge was erased.  Otherwise, False.
1242          */
1243 	bool removeBridge(Vector<int> pos);
1244 
1245         /** Destroy both halves of a bridge.
1246          *
1247          * @param pos The position on the map to erase a Bridge from.
1248          *
1249          * Both halves of the bridge are removed, and the type of the
1250          * connecting Road tiles are recalculated.
1251          *
1252          * @return Returns True if a Bridge was burned.  Otherwise, False.
1253          */
1254         bool burnBridge(Vector<int> pos);
1255 
1256         /** Add a given Sign to the map.
1257          *
1258          * @param t A pointer to the Signpost to add to the map.
1259          *
1260          * \note If the terrain under the Sign is water, it is changed to
1261          * grass.
1262          *
1263          * \note The position of the Signpost is held in the Signpost object.
1264          *
1265          * \note This method doesn't do any checking if the Signpost can be
1266          * added to the given position or not.  Callers are expected to do
1267          * this check beforehand.
1268          *
1269          * @return Always returns True.
1270          */
1271 	bool putSignpost(Signpost *s);
1272 
1273         /** Erase a Signpost tile from the given position from the map.
1274          *
1275          * @param pos The position on the map to erase a Signpost from.
1276          *
1277          * @return Returns True if a Signpost was erased.  Otherwise, False.
1278          */
1279 	bool removeSignpost(Vector<int> pos);
1280 
1281         /** Add a given Port to the map.
1282          *
1283          * @param t A pointer to the Port to add to the map.
1284          *
1285          * \note If the terrain under the Port is water, it is changed to
1286          * grass.
1287          *
1288          * \note The position of the Port is held in the Port object.
1289          *
1290          * \note This method doesn't do any checking if the Port can be
1291          * added to the given position or not.  Callers are expected to do
1292          * this check beforehand.
1293          *
1294          * @return Always returns True.
1295          */
1296 	bool putPort(Port *p);
1297 
1298         /** Erase a Port tile from the given position from the map.
1299          *
1300          * @param pos The position on the map to erase a Port from.
1301          *
1302          * @return Returns True if a Port was erased.  Otherwise, False.
1303          */
1304 	bool removePort(Vector<int> pos);
1305 
1306         /** Add the given stack to the map.
1307          *
1308          * @param s A pointer to the stack to add to the map.
1309          *
1310          * \note This method doesn't do any checking if the stack can be
1311          * added to the given position or not.  Callers are expected to do
1312          * this check beforehand.
1313          *
1314          * \note The Stack is added to the Stacklist of the
1315          * Playerlist::getActiveplayer().
1316          * @return Always returns True.
1317          */
1318 	bool putStack(Stack *s);
1319 
1320         /** Remove the given stack from the map.
1321          *
1322          * @param s A pointer to the stack to be removed from the map.
1323          *
1324          */
1325 	void removeStack(Stack *s);
1326 
1327         /** Erase a building at the given location from the map.
1328          *
1329          * @param pos A position on the map to remove a building from.
1330          *
1331          * This method erases a City, Road, Ruin, Temple, Port, Bridge, or
1332          * a Signpost from the map.
1333          *
1334          * @return Returns True if a building was removed.  Otherwise, False.
1335          */
1336         bool removeLocation (Vector<int> pos);
1337 
1338         /** Erases everything except the terrain from the given position on the map.
1339          *
1340          * @param pos A position on the map to remove stuff from.
1341          *
1342          * This method erases a City, Road, Ruin, Temple, Port, Bridge,
1343          * Signpost, Stack or Backpack from the given position on the map.
1344          *
1345          * \note Every tile has a MapBackpack object.  It is not removed, but
1346          * the Item objects held within it are.
1347          *
1348          * @return Returns True if anything was removed.  Otherwise, False.
1349          */
1350         bool eraseTile(Vector<int> pos);
1351 
1352         /** Erase everything from a region of the map.
1353          *
1354          * @param r A Rectangle specifying the region to remove stuff from.
1355          *
1356          * This method erases any City, Road, Ruin, Temple, Port, Bridge,
1357          * Signpost, Stack or Backpack objects from the given region of the map.
1358          *
1359          * \note Every tile has a MapBackpack object.  It is not removed, but
1360          * the Item objects held within it are.
1361          *
1362          * @return Returns True if anything was removed.  Otherwise, False.
1363          */
1364         bool eraseTiles(LwRectangle r);
1365 
1366         /** Returns a Location from the given position on the map.
1367          *
1368          * @param pos The position on the map to check a building for.
1369          *
1370          * All buildings are also Location objects.
1371          *
1372          * @return Returns a pointer to a Location if a building a present,
1373          * otherwise NULL is returned.
1374          */
1375 	Location *getLocation(Vector<int> pos);
1376 
1377         /** Check if all City objects are reachable.
1378          *
1379          * Loop over all cities to see if they can all be reached via a
1380          * non-flying Stack.
1381          *
1382          * @return Returns True if all cities are accessible.  Otherwise, False.
1383          */
1384 	bool checkCityAccessibility();
1385 
1386         /** Check if buildings are on land or water.
1387          *
1388          * @param b The kind of building to check for.
1389          * @param land Whether or not the building should be on land or not.
1390          *
1391          * @return Returns True if the building was found to be on land, or
1392          * water, anywhere on the map.  Otherwise, False.
1393          */
1394         static bool checkBuildingTerrain(Maptile::Building b, bool land);
1395 
1396         /** Returns the center of the map.
1397          *
1398          * @return Returns the centermost tile of the map.
1399          */
1400         static Vector<int> getCenterOfMap();
1401 
1402         /** Change the terrain on a region of the map.
1403          *
1404          * @param r The region of the map to alter.
1405          * @param type  The type of terrain to change it to.
1406          * @param tile_style_id  The TileStyle id to change it to.  -1 means
1407          * automatically pick the id of a suitable TileStyle.
1408          * @param always_alter_tilestyles Reassign TileStyle ids even if the
1409          * terrain is already of the given type.
1410          *
1411          * \note This method will not change land to water under buildings.
1412          * \note This method will change Stack objects on land to be Stack
1413          * objects in water (e.g. in a boat).
1414          *
1415          * @return Returns the region altered as a Rectangle.
1416          */
1417         LwRectangle putTerrain(LwRectangle r, Tile::Type type,
1418                              int tile_style_id = -1,
1419                              bool always_alter_tilestyles = false);
1420 
1421 
1422         static int calculateTilesPerOverviewMapTile(int width, int height);
1423         static int calculateTilesPerOverviewMapTile();
1424 
1425         Vector<int> findNearestAreaForBuilding(Maptile::Building building_type, Vector<int> pos, guint32 width);
1426 
1427         static bool friendlyCitiesPresent();
1428         static bool enemyCitiesPresent();
1429         static bool neutralCitiesPresent();
1430         static Stack* getStrongestStack(Vector<int> pos);
1431     protected:
1432         //! Create the map with the given tileset
1433         GameMap(Glib::ustring TilesetName = "", Glib::ustring ShieldsetName = "",
1434 		Glib::ustring Citysetname = "");
1435 
1436         //! Load the map using the given XML_Helper
1437         GameMap(XML_Helper* helper);
1438 
1439         ~GameMap();
1440 
1441     private:
1442         //! Callback for item loading used during loading.
1443         bool loadItems(Glib::ustring tag, XML_Helper* helper);
1444         bool containsWater (LwRectangle rect);
1445         bool containsForest (LwRectangle rect);
1446         bool isBlockedAvenue(int x, int y, int destx, int desty);
1447         bool isDock(Vector<int> pos);
1448 	void close_circles (int minx, int miny, int maxx, int maxy);
1449 	void processStyles(Glib::ustring styles, int chars_per_style);
1450 	int determineCharsPerStyle(Glib::ustring styles);
1451 
1452 	TileStyle *calculatePreferredStyle(int i, int j);
1453 	void demote_lone_tile(int minx, int miny, int maxx, int maxy,
1454 			      Tile::Type intype, Tile::Type outtype);
1455 
1456 	int tile_is_connected_to_other_like_tiles (Tile::Type tile, int i,
1457 						   int j);
1458 	bool are_those_tiles_similar(Tile::Type outer_tile,Tile::Type inner_tile, bool checking_loneliness);
1459 	Vector<int> findNearestObjectInDir(Vector<int> pos, Vector<int> dir);
1460 	void putBuilding(LocationBox *b, Maptile::Building building);
1461         void clearBuilding(Vector<int> pos, guint32 width);
1462 	void removeBuilding(LocationBox *b);
1463 
1464 	void updateShips(Vector<int> pos);
1465         void updateTowers (Vector<int> pos);
1466 
1467         static void changeFootprintToSmallerCityset(Location *location, Maptile::Building building_type, guint32 old_tile_width);
1468 
1469         static void relocateLocation(Location *location, Maptile::Building building_type, guint32 tile_width);
1470 
1471 	static std::vector<Stack*> getNearbyStacks(Vector<int> pos, int dist, bool friendly);
1472 
1473 	static bool offmap(int x, int y);
1474 
1475         static bool compareStackStrength(Stack *lhs, Stack *rhs);
1476 
1477         // Data
1478         static GameMap* s_instance;
1479         static int s_width;
1480         static int s_height;
1481         static Tileset* s_tileset; //not saved
1482         static Cityset* s_cityset; //not saved
1483         static Shieldset* s_shieldset; //not saved
1484 
1485         Glib::ustring d_tileset; //the basename, not the friendly name.
1486         Glib::ustring d_shieldset; //the basename, not the friendly name.
1487         Glib::ustring d_cityset; //the basename, not the friendly name.
1488 
1489         Maptile* d_map;
1490 };
1491 
1492 #endif
1493 
1494 // End of file
1495