~ubuntu-branches/ubuntu/maverick/lordsawar/maverick

« back to all changes in this revision

Viewing changes to src/GameMap.h

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2010-04-10 09:29:33 UTC
  • mfrom: (1.1.9 upstream) (5.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100410092933-23uq4dxig30kmtcw
Tags: 0.1.8-1
* New upstream release.
* Add misc:Depends for -data package.
* Bump Standards Version to 3.8.4. (No changes needed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// Copyright (C) 2003 Michael Bartl
2
2
// Copyright (C) 2003, 2004, 2005, 2006 Ulf Lorenz
3
3
// Copyright (C) 2003, 2006 Andrea Paternesi
4
 
// Copyright (C) 2006, 2007, 2008, 2009 Ben Asselstine
 
4
// Copyright (C) 2006, 2007, 2008, 2009, 2010 Ben Asselstine
5
5
// Copyright (C) 2008 Janek Kozicki
6
6
//
7
7
//  This program is free software; you can redistribute it and/or modify
34
34
#include "Location.h"
35
35
#include "shieldset.h"
36
36
#include "cityset.h"
 
37
#include "stackreflist.h"
37
38
 
38
39
class MapGenerator;
39
40
class XML_Helper;
43
44
class Temple;
44
45
class Bridge;
45
46
class Ruin;
 
47
class Armyset;
46
48
 
47
49
/** Class representing the map in the game
48
50
  * 
124
126
        void setTile(Vector<int> p, Maptile *t) {return setTile(p.x, p.y, t);}
125
127
 
126
128
        static City* getCity(Vector<int> pos);
 
129
        static City* getCity(Movable *m) {return getCity(m->getPos());}
 
130
 
 
131
        static City* getEnemyCity(Vector<int> pos);
127
132
        static Ruin* getRuin(Vector<int> pos);
 
133
        static Ruin* getRuin(Movable *m) {return getRuin(m->getPos());}
128
134
        static Temple* getTemple(Vector<int> pos);
 
135
        static Temple* getTemple(Movable *m) {return getTemple(m->getPos());}
129
136
        static Port* getPort(Vector<int> pos);
130
137
        static Road* getRoad(Vector<int> pos);
131
138
        static Bridge* getBridge(Vector<int> pos);
132
139
        static Signpost* getSignpost(Vector<int> pos);
 
140
        static Signpost* getSignpost(Movable *m) {return getSignpost(m->getPos());}
133
141
        static Stack* getStack(Vector<int> pos);
 
142
        static StackTile* getStacks(Vector<int> pos);
 
143
        static Stack *groupStacks(Vector<int> pos);
 
144
        static void groupStacks(Stack *s);
 
145
        static bool canJoin(const Stack *src, Stack *dest);
 
146
        static bool canJoin(const Stack *stack, Vector<int> pos);
 
147
        static bool canAddArmy(Vector<int> pos);
 
148
        static bool canAddArmies(Vector<int> dest, guint32 stackSize);
 
149
        static Stack* getFriendlyStack(Vector<int> pos);
 
150
        //static StackReflist getFriendlyStacks(Vector<int> pos, Player *player = NULL);
 
151
        static std::list<Stack*> getFriendlyStacks(Vector<int> pos, Player *player = NULL);
 
152
        static Stack* getEnemyStack(Vector<int> pos);
 
153
        static std::list<Stack*> getEnemyStacks(std::list<Vector<int> > posns);
 
154
        static std::list<Stack*> getEnemyStacks(Vector<int> pos, Player *player = NULL);
 
155
        static std::list<Stack*> getNearbyFriendlyStacks(Vector<int> pos, int dist);
 
156
        static std::list<Stack*> getNearbyEnemyStacks(Vector<int> pos, int dist);
 
157
 
 
158
        static std::list<Vector<int> > getNearbyPoints(Vector<int> pos, int dist);
 
159
        static guint32 countArmyUnits(Vector<int> pos);
 
160
        static MapBackpack *getBackpack(Vector<int> pos);
 
161
        std::list<MapBackpack*> getBackpacks() const;
134
162
 
135
163
        //! Get the tile object at position (x,y)
136
164
        Maptile* getTile(int x, int y) const;
141
169
        //! Add an army to this location on the map
142
170
        Stack* addArmy(Location *l, Army *a);
143
171
        Stack* addArmy(Vector<int> pos, Army *a);
 
172
        Stack* addArmyAtPos(Vector<int> pos, Army *a);
144
173
 
145
174
        //! Go find a player's planted standard on the map
146
175
        Vector<int> findPlantedStandard(Player *p);
147
176
 
 
177
        //! go find the player's stack, the slow way.
 
178
        Vector<int> findStack(guint32 id);
 
179
 
148
180
        /** Fill the map using the data supplied by a map generator
149
181
          * 
150
182
          * @param generator        the generator which supplies the data
169
201
        //! figure out where a non-flying unit can't go
170
202
        void calculateBlockedAvenues();
171
203
        void calculateBlockedAvenue(int i, int j);
 
204
        void updateStackPositions();
172
205
 
173
206
        /** Smooth a portion of the map.
174
207
         *
175
208
         * Give each tile in the prescribed area the preferred picture for 
176
209
         * the underlying terrain tile.
177
210
         */
 
211
        void applyTileStyles (Rectangle r, bool smooth_terrain);
178
212
        void applyTileStyles (int minx, int miny, int maxx, int maxy,
179
213
                              bool smooth_terrain);
180
214
        void applyTileStyle (int i, int j);
188
222
        Vector<int> findNearestObjectToTheEast(Vector<int> pos);
189
223
        Vector<int> findNearestObjectToTheWest(Vector<int> pos);
190
224
 
 
225
        void switchArmysets(Armyset *armyset);
 
226
        void switchCityset(Cityset *cityset);
 
227
        void switchShieldset(Shieldset *shieldset);
 
228
        void switchTileset(Tileset *tileset);
 
229
 
 
230
        bool moveBuilding(Vector<int> from, Vector<int> to);
 
231
        bool canPutBuilding(Maptile::Building bldg, guint32 size, Vector<int> to, bool making_islands = true);
 
232
        bool canPutStack(guint32 size, Player *p, Vector<int> to);
 
233
        bool moveStack(Stack *stack, Vector<int> to);
 
234
 
 
235
        void moveBackpack(Vector<int> from, Vector<int> to);
 
236
        guint32 getBuildingSize(Vector<int> tile);
 
237
        Maptile::Building getBuilding(Vector<int> tile);
 
238
        Tile::Type getTerrainType(Vector<int> tile);
 
239
        void setBuilding(Vector<int> tile, Maptile::Building building);
 
240
 
 
241
        bool putCity(City *c, bool keep_owner = false);
 
242
        bool removeCity(Vector<int> pos);
 
243
        bool putRuin(Ruin *r);
 
244
        bool removeRuin(Vector<int> pos);
 
245
        bool putTemple(Temple *t);
 
246
        bool removeTemple(Vector<int> pos);
 
247
        bool putRoad(Road *r);
 
248
        bool removeRoad(Vector<int> pos);
 
249
        bool putBridge(Bridge *b);
 
250
        bool removeBridge(Vector<int> pos);
 
251
        bool putSignpost(Signpost *s);
 
252
        bool removeSignpost(Vector<int> pos);
 
253
        bool putPort(Port *p);
 
254
        bool removePort(Vector<int> pos);
 
255
        bool putStack(Stack *s);
 
256
        void removeStack(Stack *s);
 
257
 
 
258
        Location *getLocation(Vector<int> pos);
 
259
 
 
260
        bool checkCityAccessibility();
 
261
 
 
262
        static Vector<int> getCenterOfMap();
 
263
 
 
264
        Rectangle putTerrain(Rectangle r, Tile::Type type, 
 
265
                             int tile_style_id = -1, 
 
266
                             bool always_alter_tilestyles = false);
 
267
 
 
268
 
 
269
        static int calculateTilesPerOverviewMapTile(int width, int height);
 
270
        static int calculateTilesPerOverviewMapTile();
 
271
 
191
272
    protected:
192
273
        //! Create the map with the given tileset
193
274
        GameMap(std::string TilesetName, std::string ShieldsetName,
201
282
    private:
202
283
        //! Callback for item loading used during loading.
203
284
        bool loadItems(std::string tag, XML_Helper* helper);
204
 
        Stack* addArmyAtPos(Vector<int> pos, Army *a);
205
285
        bool isBlockedAvenue(int x, int y, int destx, int desty);
206
286
        bool isDock(Vector<int> pos);
207
287
        void close_circles (int minx, int miny, int maxx, int maxy);
216
296
                                                   int j);
217
297
        bool are_those_tiles_similar(Tile::Type outer_tile,Tile::Type inner_tile, bool checking_loneliness);
218
298
        Vector<int> findNearestObjectInDir(Vector<int> pos, Vector<int> dir);
 
299
        void putBuilding(LocationBox *b, Maptile::Building building);
 
300
        void removeBuilding(LocationBox *b);
 
301
 
 
302
        void updateShips(Vector<int> pos);
 
303
 
 
304
 
 
305
        static std::list<Stack*> getNearbyStacks(Vector<int> pos, int dist, bool friendly);
 
306
 
 
307
        static bool offmap(int x, int y);
219
308
 
220
309
        // Data
221
310
        static GameMap* s_instance;