~flosoft/s25rttr/trunk

« back to all changes in this revision

Viewing changes to src/GameWorld.h

  • Committer: FloSoft
  • Date: 2014-04-25 15:35:50 UTC
  • Revision ID: flosoft@siedler25.org-20140425153550-9muu4vodhlqu58m0
committing subversion revision 9357 by FloSoft
astyle

modified:
s25client/trunk/
s25client/trunk/contrib/lua/lin32/include/
s25client/trunk/contrib/lua/lin64/include/
s25client/trunk/contrib/lua/mac/include/
s25client/trunk/contrib/lua/win32/include/
s25client/trunk/contrib/lua/win64/include/
s25client/trunk/driver/audio/SDL/src/
s25client/trunk/driver/src/
s25client/trunk/driver/video/GLFW/src/
s25client/trunk/driver/video/SDL/src/
s25client/trunk/driver/video/WinAPI/src/
s25client/trunk/src/
s25client/trunk/win32/
s25client/trunk/win32/prebuild-mutex/src/

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// $Id: GameWorld.h 9167 2014-02-18 18:14:42Z marcus $
 
1
// $Id: GameWorld.h 9357 2014-04-25 15:35:25Z FloSoft $
2
2
//
3
3
// Copyright (c) 2005 - 2011 Settlers Freaks (sf-team at siedler25.org)
4
4
//
61
61
struct RoadsBuilding;
62
62
class FOWObject;
63
63
 
64
 
typedef bool (*FP_Node_OK_Callback)(const GameWorldBase& gwb, const MapCoord x, const MapCoord y, const unsigned char dir, const void *param);
 
64
typedef bool (*FP_Node_OK_Callback)(const GameWorldBase& gwb, const MapCoord x, const MapCoord y, const unsigned char dir, const void* param);
65
65
 
66
66
/// Eigenschaften von einem Punkt auf der Map
67
67
struct MapNode
68
68
{
69
 
        /// Straßen
70
 
        unsigned char roads[3];
71
 
        bool roads_real[3];
72
 
        /// Höhe
73
 
        unsigned char altitude;
74
 
        /// Schattierung
75
 
        unsigned char shadow;
76
 
        /// Terrain
77
 
        unsigned char t1,t2;
78
 
        /// Ressourcen
79
 
        unsigned char resources;
80
 
        /// Reservierungen
81
 
        bool reserved;
82
 
        /// Eigentümer (Spieler)
83
 
        unsigned char owner;
84
 
        /// Grenzsteine (der Punkt, und dann jeweils nach rechts, unten-links und unten-rechts die Zwischensteine)
85
 
        unsigned char boundary_stones[4];
86
 
        /// Bauqualität
87
 
        BuildingQuality bq;
88
 
        /// Visuelle Sachen für alle Spieler, die in Zusammenhang mit dem FoW stehen
89
 
        struct
90
 
        {
91
 
                /// Zeit (GF-Zeitpunkt), zu der, der Punkt zuletzt aktualisiert wurde
92
 
                unsigned last_update_time;
93
 
                /// Sichtbarkeit des Punktes
94
 
                Visibility visibility;
95
 
                /// FOW-Objekt
96
 
                FOWObject * object;
97
 
                /// Straßen im FoW
98
 
                unsigned char roads[3];
99
 
                /// Grenzsteine (der Punkt, und dann jeweils nach rechts, unten-links und unten-rechts die Zwischensteine)
100
 
                unsigned char owner;
101
 
                /// Grenzsteine (der Punkt, und dann jeweils nach rechts, unten-links und unten-rechts die Zwischensteine)
102
 
                unsigned char boundary_stones[4];
103
 
        } fow[MAX_PLAYERS];
104
 
 
105
 
        /// Meeres-ID, d.h. zu welchem Meer gehört dieser Punkt (0 = kein Meer)
106
 
        unsigned short sea_id;
107
 
        /// Hafenpunkt-ID (0 = kein Hafenpunkt)
108
 
        unsigned harbor_id;
109
 
 
110
 
        /// Objekt, welches sich dort befindet
111
 
        noBase * obj;
112
 
        /// Figuren, Kämpfe, die sich dort befinden
113
 
        list<noBase*> figures;
114
 
 
115
 
        MapNode();
116
 
        
 
69
    /// Straßen
 
70
    unsigned char roads[3];
 
71
    bool roads_real[3];
 
72
    /// Höhe
 
73
    unsigned char altitude;
 
74
    /// Schattierung
 
75
    unsigned char shadow;
 
76
    /// Terrain
 
77
    unsigned char t1, t2;
 
78
    /// Ressourcen
 
79
    unsigned char resources;
 
80
    /// Reservierungen
 
81
    bool reserved;
 
82
    /// Eigentümer (Spieler)
 
83
    unsigned char owner;
 
84
    /// Grenzsteine (der Punkt, und dann jeweils nach rechts, unten-links und unten-rechts die Zwischensteine)
 
85
    unsigned char boundary_stones[4];
 
86
    /// Bauqualität
 
87
    BuildingQuality bq;
 
88
    /// Visuelle Sachen für alle Spieler, die in Zusammenhang mit dem FoW stehen
 
89
    struct
 
90
    {
 
91
        /// Zeit (GF-Zeitpunkt), zu der, der Punkt zuletzt aktualisiert wurde
 
92
        unsigned last_update_time;
 
93
        /// Sichtbarkeit des Punktes
 
94
        Visibility visibility;
 
95
        /// FOW-Objekt
 
96
        FOWObject* object;
 
97
        /// Straßen im FoW
 
98
        unsigned char roads[3];
 
99
        /// Grenzsteine (der Punkt, und dann jeweils nach rechts, unten-links und unten-rechts die Zwischensteine)
 
100
        unsigned char owner;
 
101
        /// Grenzsteine (der Punkt, und dann jeweils nach rechts, unten-links und unten-rechts die Zwischensteine)
 
102
        unsigned char boundary_stones[4];
 
103
    } fow[MAX_PLAYERS];
 
104
 
 
105
    /// Meeres-ID, d.h. zu welchem Meer gehört dieser Punkt (0 = kein Meer)
 
106
    unsigned short sea_id;
 
107
    /// Hafenpunkt-ID (0 = kein Hafenpunkt)
 
108
    unsigned harbor_id;
 
109
 
 
110
    /// Objekt, welches sich dort befindet
 
111
    noBase* obj;
 
112
    /// Figuren, Kämpfe, die sich dort befinden
 
113
    list<noBase*> figures;
 
114
 
 
115
    MapNode();
 
116
 
117
117
};
118
118
 
119
119
enum LandscapeType
120
120
{
121
 
        LT_GREENLAND = 0,
122
 
        LT_WASTELAND,
123
 
        LT_WINTERWORLD
 
121
    LT_GREENLAND = 0,
 
122
    LT_WASTELAND,
 
123
    LT_WINTERWORLD
124
124
};
125
125
 
126
126
/// Grundlegende Klasse, die die Gamewelt darstellt, enthält nur deren Daten
127
127
class GameWorldBase
128
128
{
129
 
protected:
130
 
 
131
 
        /// Interface zum GUI
132
 
        GameInterface * gi;
133
 
 
134
 
        /// Breite und Höhe der Karte in Kontenpunkten
135
 
        unsigned short width,height;
136
 
        /// Landschafts-Typ
137
 
        LandscapeType lt;
138
 
 
139
 
        unsigned short * handled_nodes; /// Array von abgeklapperten Knoten und deren Punktzahlen
140
 
 
141
 
        /// Eigenschaften von einem Punkt auf der Map
142
 
        MapNode *nodes;
143
 
 
144
 
        /// Rendert das Terrain
145
 
        TerrainRenderer tr;
146
 
 
147
 
        /// Informationen über die Weltmeere
148
 
        struct Sea
149
 
        {
150
 
                /// Anzahl der Knoten, welches sich in diesem Meer befinden
151
 
                unsigned nodes_count;
152
 
 
153
 
                Sea() : nodes_count(0) {}
154
 
                Sea(const unsigned nodes_count) : nodes_count(nodes_count) {}
155
 
        };
156
 
        std::vector<Sea> seas;
157
 
 
158
 
        /// Alle Hafenpositionen
159
 
        struct HarborPos
160
 
        {
161
 
                MapCoord x,y;
162
 
 
163
 
                struct CoastalPoint
164
 
                {
165
 
                        unsigned short sea_id;
166
 
                } cps[6];
167
 
 
168
 
                struct Neighbor
169
 
                {
170
 
                        unsigned id;
171
 
                        unsigned distance;
172
 
                        
173
 
                        Neighbor() {}
174
 
                        Neighbor(const unsigned id, const unsigned distance)
175
 
                                : id(id), distance(distance) {}
176
 
                        
177
 
                        bool operator<(const Neighbor& two) const
178
 
                        { return distance < two.distance; }
179
 
                };
180
 
 
181
 
                std::vector<Neighbor> neighbors[6];
182
 
        };
183
 
 
184
 
        std::vector< HarborPos > harbor_pos;
185
 
 
186
 
        /// Baustellen von Häfen, die vom Schiff aus errichtet wurden
187
 
        std::list<noBuildingSite*> harbor_building_sites_from_sea;
188
 
 
189
 
        GameClientPlayerList *players;
190
 
 
191
 
public:
192
 
        unsigned int map_size;
193
 
 
194
 
        std::list<CatapultStone*> catapult_stones; /// Liste von allen umherfliegenden Katapultsteinen.
195
 
 
196
 
        noNothing nothing; // nur Platzhalter bei der Rckgabe von GetNO
197
 
        /// Liste von Militärgebäuden (auch HQ und Haufengebäude, daher normale Gebäude) pro "Militärquadrat"
198
 
        list<nobBaseMilitary*> * military_squares;
199
 
 
200
 
public:
201
 
 
202
 
        GameWorldBase();
203
 
        virtual ~GameWorldBase();
204
 
 
205
 
        // Grundlegende Initialisierungen
206
 
        void Init();
207
 
        /// Aufräumen
208
 
        void Unload();
209
 
 
210
 
        /// Setzt GameInterface
211
 
        inline void SetGameInterface(GameInterface * const gi) { this->gi = gi; }
212
 
 
213
 
        /// Größe der Map abfragen
214
 
        inline unsigned short GetWidth() const { return width; }
215
 
        inline unsigned short GetHeight() const { return height; }
216
 
 
217
 
        /// Landschaftstyp abfragen
218
 
        LandscapeType GetLandscapeType() const { return lt; }
219
 
 
220
 
        /// Gibt Punkt um diesen Punkt (X-Koordinate) direkt zurück in einer Richtung von 0-5
221
 
        MapCoord GetXA(const MapCoord x, const MapCoord y, unsigned dir) const;
222
 
        /// Gibt Punkt um diesen Punkt (Y-Koordinate)  direkt zurück in einer Richtung von 0-5
223
 
        MapCoord GetYA(const MapCoord x, const MapCoord y, unsigned dir) const;
224
 
        /// Wie GetXA, bloß 2. Außenschale (dir zwischen 0 bis 11)
225
 
        MapCoord GetXA2(const MapCoord x, const MapCoord y, unsigned dir) const;
226
 
        /// Wie GetYA, bloß 2. Außenschale (dir zwischen 0 bis 11)
227
 
        MapCoord GetYA2(const MapCoord x, const MapCoord y, unsigned dir) const;
228
 
        /// Wandelt einen Punkt in einen Nachbarpunkt um
229
 
        inline void GetPointA(MapCoord& x, MapCoord& y, unsigned dir) const {x = GetXA(x, y, dir); y = GetYA(x, y, dir);}
230
 
        /// Returns neighbouring point
231
 
        inline Point<MapCoord> GetPointA(Point<MapCoord> p,const unsigned dir) const
232
 
        { GetPointA(p.x,p.y,dir); return p; }
233
 
        /// Berechnet die Differenz zweier Koordinaten von x1 zu x2, wenn man berücksichtigt, dass man über den 
234
 
        /// Rand weitergehen kann
235
 
        MapCoord CalcDistanceAroundBorderX(const MapCoord x1, const MapCoord x2) const;
236
 
        MapCoord CalcDistanceAroundBorderY(const MapCoord y1, const MapCoord y2) const;
237
 
 
238
 
        /// Ermittelt Abstand zwischen 2 Punkten auf der Map unter Berücksichtigung der Kartengrenzüberquerung
239
 
        unsigned CalcDistance(int x1, int y1, int x2, int y2) const;
240
 
        inline unsigned CalcDistance(const Point<MapCoord> p1, const Point<MapCoord> p2) const
241
 
        { return CalcDistance(p1.x,p1.y,p2.x,p2.y); }
242
 
 
243
 
        // Erzeugt eindeutige ID aus gegebenen X und Y-Werten
244
 
        inline unsigned MakeCoordID(const MapCoord x, const MapCoord y) const
245
 
        { return y*width+x; }
246
 
 
247
 
        /// Gibt Map-Knotenpunkt zurück
248
 
        inline const MapNode& GetNode(const MapCoord x, const MapCoord y) const { assert(x<width && y<height);  return nodes[y*width+x]; }
249
 
        MapNode& GetNode(const MapCoord x, const MapCoord y) { assert(x<width && y<height); return nodes[y*width+x]; }
250
 
        /// Gibt MapKnotenpunkt darum zurück
251
 
        inline const MapNode& GetNodeAround(const MapCoord x, const MapCoord y, const unsigned i) const
252
 
        { return GetNode(GetXA(x,y,i),GetYA(x,y,i));  }
253
 
        inline MapNode& GetNodeAround(const MapCoord x, const MapCoord y, const unsigned i)
254
 
        { return GetNode(GetXA(x,y,i),GetYA(x,y,i));  }
255
 
 
256
 
        // Gibt ein NO zurück, falls keins existiert, wird ein "Nothing-Objekt" zurückgegeben
257
 
        noBase * GetNO(const MapCoord x, const MapCoord y);
258
 
        // Gibt ein NO zurück, falls keins existiert, wird ein "Nothing-Objekt" zurückgegeben
259
 
        const noBase * GetNO(const MapCoord x, const MapCoord y) const;
260
 
        /// Gibt ein FOW-Objekt zurück, falls keins existiert, wird ein "Nothing-Objekt" zurückgegeben
261
 
        const FOWObject * GetFOWObject(const MapCoord x, const MapCoord y, const unsigned spectator_player) const;
262
 
        /// Gibt den GOT des an diesem Punkt befindlichen Objekts zurück bzw. GOT_NOTHING, wenn keins existiert
263
 
        GO_Type GetGOT(const MapCoord x, const MapCoord y) const;
264
 
 
265
 
        /// Gibt Figuren, die sich auf einem bestimmten Punkt befinden, zurück
266
 
        /// nicht bei laufenden Figuren oder
267
 
        list<noBase*>& GetFigures(const MapCoord x, const MapCoord y) const { return nodes[y*width+x].figures; }
268
 
        /// Gibt Dynamische Objekte, die von einem bestimmten Punkt aus laufen oder dort stehen sowie andere Objekte,
269
 
        /// die sich dort befinden, zurück
270
 
        void GetDynamicObjectsFrom(const MapCoord x, const MapCoord y,list<noBase*>& objects) const;
271
 
 
272
 
        // Gibt ein spezifisches Objekt zurück
273
 
        template<typename T> inline T * GetSpecObj(MapCoord x, MapCoord y) { return dynamic_cast<T*>( GetNode(x,y).obj ); }
274
 
        // Gibt ein spezifisches Objekt zurück
275
 
        template<typename T> inline const T * GetSpecObj(MapCoord x, MapCoord y) const { return dynamic_cast<const T*>( GetNode(x,y).obj ); }
276
 
 
277
 
        /// Gibt ein Terrain-Dreieck um einen Punkt herum zurück.
278
 
        unsigned char GetTerrainAround(int x, int y, unsigned char dir) const;
279
 
        /// Gibt das Terrain zurück, über das ein Mensch/Tier laufen müsste, von X,Y in Richtung DIR (Vorwärts).
280
 
        unsigned char GetWalkingTerrain1(MapCoord x, MapCoord y, unsigned char dir) const;
281
 
        /// Gibt das Terrain zurück, über das ein Mensch/Tier laufen müsste, von X,Y in Richtung DIR (Rückwärts).
282
 
        unsigned char GetWalkingTerrain2(MapCoord x, MapCoord y, unsigned char dir) const;
283
 
        /// Gibt zurück, ob ein Punkt vollständig von Wasser umgeben ist
284
 
        bool IsSeaPoint(MapCoord x, MapCoord y) const;
285
 
 
286
 
        /// liefert den Straßen-Wert an der Stelle X,Y
287
 
        unsigned char GetRoad(const MapCoord x, const MapCoord y, unsigned char dir, bool all = false) const;
288
 
        /// liefert den Straßen-Wert um den Punkt X,Y.
289
 
        unsigned char GetPointRoad(const MapCoord x, const MapCoord y, unsigned char dir, bool all = false) const;
290
 
        /// liefert FOW-Straßen-Wert um den punkt X,Y
291
 
        unsigned char GetPointFOWRoad(MapCoord x, MapCoord y, unsigned char dir, const unsigned char viewing_player) const;
292
 
 
293
 
        /// Kann dorthin eine Straße gebaut werden?
294
 
        bool RoadAvailable(const bool boat_road,const int x, const int y,unsigned char to_dir,const bool visual = true) const;
295
 
        /// Prüft ob exakt die gleiche Straße schon gebaut wurde
296
 
        bool RoadAlreadyBuilt(const bool boat_road, unsigned short start_x, unsigned short start_y, const std::vector<unsigned char>& route);
297
 
        /// Bauqualitäten berechnen, bei flagonly gibt er nur 1 zurück, wenn eine Flagge möglich ist
298
 
        BuildingQuality CalcBQ(const MapCoord x, const MapCoord y,const unsigned char player,const bool flagonly = false,const bool visual = true, const bool ignore_player = false) const;
299
 
        /// Setzt die errechnete BQ gleich mit
300
 
        inline void SetBQ(const MapCoord x, const MapCoord y,const unsigned char player,const bool flagonly = false,const bool visual = true)
301
 
        { GetNode(x,y).bq = CalcBQ(x,y,player,flagonly,visual); }
302
 
 
303
 
        /// Prüft, ob der Pkut zu dem Spieler gehört (wenn er der Besitzer ist und es false zurückliefert, ist es Grenzgebiet)
304
 
        bool IsPlayerTerritory(const MapCoord x, const MapCoord y) const;
305
 
        /// Berechnet BQ bei einer gebauten Straße
306
 
        void CalcRoad(const MapCoord x, const MapCoord y,const unsigned char player);
307
 
        /// Ist eine Flagge irgendwo um x,y ?
308
 
        bool FlagNear(const int x, const int y) const;
309
 
        /// Prüft, ob sich in unmittelbarer Nähe (im Radius von 4) Militärgebäude befinden
310
 
        bool IsMilitaryBuildingNearNode(const MapCoord nx, const MapCoord ny, const unsigned char player) const;
311
 
 
312
 
        /// setzt den virtuellen Straßen-Wert an der Stelle X,Y (berichtigt).
313
 
        void SetVirtualRoad(const MapCoord x, const MapCoord y, unsigned char dir, unsigned char type);
314
 
        /// setzt den virtuellen Straßen-Wert um den Punkt X,Y.
315
 
        void SetPointVirtualRoad(const MapCoord x, const MapCoord y, unsigned char dir, unsigned char type);
316
 
 
317
 
        /// Test, ob auf dem besagten Punkt ein Militärgebäude steht
318
 
        bool IsMilitaryBuilding(const MapCoord x, const MapCoord y) const;
319
 
 
320
 
        /// Erstellt eine Liste mit allen Militärgebäuden in der Umgebung, radius bestimmt wie viele Kästchen nach einer Richtung im Umkreis
321
 
        void LookForMilitaryBuildings(std::list<nobBaseMilitary*>& buildings,const MapCoord x, const MapCoord y, unsigned short radius) const;
322
 
 
323
 
        /// Prüft, ob von einem bestimmten Punkt aus der Untergrund für Figuren zugänglich ist (kein Wasser,Lava,Sumpf)
324
 
        bool IsNodeToNodeForFigure(const MapCoord x, const MapCoord y, const unsigned dir) const;
325
 
 
326
 
        /// Informationen, ob Grenzen überquert wurden
327
 
        struct CrossBorders
328
 
        {
329
 
                CrossBorders(void) : left(false), top(false), right(false), bottom(false) { }
330
 
                bool left, top, right, bottom;
331
 
        };
332
 
 
333
 
 
334
 
        /// Wegfindung in freiem Terrain - Basisroutine
335
 
        bool FindFreePath(const MapCoord x_start,const MapCoord y_start,
336
 
                                  const MapCoord x_dest, const MapCoord y_dest, const bool random_route, 
337
 
                                  const unsigned max_route, std::vector<unsigned char> * route, unsigned *length, unsigned char * first_dir, 
338
 
                                  FP_Node_OK_Callback IsNodeOK, FP_Node_OK_Callback IsNodeToDestOk, const void * param, const bool record) const;
339
 
        /// Ermittelt, ob eine freie Route noch passierbar ist und gibt den Endpunkt der Route zurück
340
 
        bool CheckFreeRoute(const MapCoord x_start,const MapCoord y_start, const std::vector<unsigned char>& route,
341
 
                const unsigned pos, FP_Node_OK_Callback IsNodeOK, FP_Node_OK_Callback IsNodeToDestOk,
342
 
                 MapCoord* x_dest,  MapCoord* y_dest, const void * const param = NULL) const;
343
 
        /// Wegfindung auf Straßen - Basisroutine
344
 
        bool FindPathOnRoads(const noRoadNode * const start, const noRoadNode * const goal,
345
 
                        const bool ware_mode, unsigned * length, unsigned char * first_dir, Point<MapCoord> * next_harbor,
346
 
                        const RoadSegment * const forbidden, const bool record = true, unsigned max = 0xFFFFFFFF) const;
347
 
        /// Findet einen Weg für Figuren
348
 
        unsigned char FindHumanPath(const MapCoord x_start,const MapCoord y_start,
349
 
                  const MapCoord x_dest, const MapCoord y_dest, const unsigned max_route = 0xFFFFFFFF, const bool random_route = false, unsigned *length = NULL, const bool record = true) const;
350
 
        /// Wegfindung für Schiffe auf dem Wasser
351
 
        bool FindShipPath(const MapCoord x_start,const MapCoord y_start, const MapCoord x_dest, const MapCoord y_dest, std::vector<unsigned char> * route, unsigned * length, const unsigned max_length = 200,
352
 
                                                                 CrossBorders * cb = NULL);
353
 
 
354
 
 
355
 
        /// Baut eine (bisher noch visuell gebaute) Straße wieder zurück
356
 
        void RemoveVisualRoad(unsigned short start_x, unsigned short start_y, const std::vector<unsigned char>& route);
357
 
 
358
 
        /// x,y ist ein Punkt auf irgendeinem Wegstck, gibt die Flagge zurück
359
 
        noFlag * GetRoadFlag(int x, int y,unsigned char& dir,unsigned last_i=255);
360
 
 
361
 
        /// Konvertiert die Koordinaten.
362
 
        void ConvertCoords(int x, int y, unsigned short * x_out, unsigned short * y_out) const;
363
 
 
364
 
        /// Erzeugt eine GUI-ID für die Fenster von Map-Objekten
365
 
        inline unsigned CreateGUIID(const MapCoord x, const MapCoord y) const
366
 
        { return 1000 + width*y+x; }
367
 
        /// Gibt Terrainkoordinaten zurück
368
 
        inline float GetTerrainX(const MapCoord x, const MapCoord y)
369
 
        { return tr.GetTerrainX(x,y); }
370
 
        inline float GetTerrainY(const MapCoord x, const MapCoord y)
371
 
        { return tr.GetTerrainY(x,y); }
372
 
 
373
 
        /// Verändert die Höhe eines Punktes und die damit verbundenen Schatten
374
 
        void ChangeAltitude(const MapCoord x, const MapCoord y, const unsigned char altitude);
375
 
        
376
 
        /// Ermittelt Sichtbarkeit eines Punktes auch unter Einbeziehung der Verbündeten des jeweiligen Spielers
377
 
        Visibility CalcWithAllyVisiblity(const MapCoord x, const MapCoord y, const unsigned char player) const; 
378
 
 
379
 
        /// Gibt die Anzahl an Hafenpunkten zurück
380
 
        inline unsigned GetHarborPointCount() const 
381
 
        { return harbor_pos.size()-1; }
382
 
        /// Ist es an dieser Stelle für einen Spieler möglich einen Hafen zu bauen
383
 
        bool IsHarborPointFree(const unsigned harbor_id, const unsigned char player, 
384
 
                const unsigned short sea_id) const;
385
 
        /// Gibt die Koordinaten eines bestimmten Hafenpunktes zurück
386
 
        Point<MapCoord> GetHarborPoint(const unsigned harbor_id) const;
387
 
        /// Gibt die ID eines Hafenpunktes zurück
388
 
        inline unsigned GetHarborPointID(const MapCoord x, const MapCoord y) const
389
 
        { return GetNode(x,y).harbor_id; }
390
 
        /// Ermittelt, ob ein Punkt Küstenpunkt ist, d.h. Zugang zu einem schiffbaren Meer hat 
391
 
        /// und gibt ggf. die Meeres-ID zurück, ansonsten 0
392
 
        unsigned short IsCoastalPoint(const MapCoord x, const MapCoord y) const;
393
 
        /// Ermittelt, ob ein Punkt Küstenpunkt ist, d.h. Zugang zu einem schiffbaren Meer, an dem auch mindestens 1 Hafenplatz liegt, hat 
394
 
        /// und gibt ggf. die Meeres-ID zurück, ansonsten 0
395
 
        unsigned short IsCoastalPointToSeaWithHarbor(const MapCoord x, const MapCoord y) const;
396
 
                /// Grenzt der Hafen an ein bestimmtes Meer an?
397
 
        bool IsAtThisSea(const unsigned harbor_id, const unsigned short sea_id) const;
398
 
        /// Gibt den Punkt eines bestimmtes Meeres um den Hafen herum an, sodass Schiffe diesen anfahren können
399
 
        void GetCoastalPoint(const unsigned harbor_id, MapCoord * px, MapCoord * py, const unsigned short sea_id) const;
400
 
        /// Sucht freie Hafenpunkte, also wo noch ein Hafen gebaut werden kann
401
 
        unsigned GetNextFreeHarborPoint(const MapCoord x, const MapCoord y, const unsigned origin_harbor_id, const unsigned char dir,
402
 
                                                                                   const unsigned char player) const;
403
 
        /// Gibt die angrenzenden Sea-IDs eines Hafenpunktes zurück
404
 
        void GetSeaIDs(const unsigned harbor_id, unsigned short * sea_ids) const;
405
 
        /// Berechnet die Entfernung zwischen 2 Hafenpunkten
406
 
        unsigned CalcHarborDistance(const unsigned habor_id1, const unsigned harbor_id2) const;
407
 
        /// Bestimmt für einen beliebigen Punkt auf der Karte die Entfernung zum nächsten Hafenpunkt
408
 
        unsigned CalcDistanceToNearestHarbor(const Point<MapCoord> pos) const;
409
 
        /// returns true when a harborpoint is in SEAATTACK_DISTANCE for figures!
410
 
        bool IsAHarborInSeaAttackDistance(const Point<MapCoord> pos) const;
411
 
        
412
 
        
413
 
 
414
 
        inline void SetPlayers(GameClientPlayerList *pls) { players = pls; }
415
 
        /// Liefert einen Player zurück
416
 
        inline GameClientPlayer * GetPlayer(const unsigned int id) const { return players->getElement(id); }
417
 
        
418
 
        struct PotentialSeaAttacker
419
 
        {
420
 
                /// Soldat, der als Angreifer in Frage kommt
421
 
                nofPassiveSoldier * soldier;
422
 
                /// Hafen, den der Soldat zuerst ansteuern soll
423
 
                nobHarborBuilding * harbor;
424
 
                /// Entfernung Hafen-Hafen (entscheidende)
425
 
                unsigned distance;
426
 
                
427
 
                /// Komperator zum Sortieren
428
 
                bool operator<(const PotentialSeaAttacker& pa) const;
429
 
        };
430
 
        
431
 
        
432
 
        /// Liefert Hafenpunkte im Umkreis von einem bestimmten Militärgebäude
433
 
        void GetHarborPointsAroundMilitaryBuilding(const MapCoord x, const MapCoord y, std::vector<unsigned> * harbor_points) const;
434
 
        /// returns all sea_ids from which a given building can be attacked by sea
435
 
        void GetValidSeaIDsAroundMilitaryBuildingForAttack(const MapCoord x,const MapCoord y, std::vector<bool> * use_seas, const unsigned char player_attacker,std::vector<unsigned>*harbor_points)const;
436
 
        /// returns all sea_ids found in the given vector from which a given building can be attacked by sea
437
 
        void GetValidSeaIDsAroundMilitaryBuildingForAttackCompare(const MapCoord x,const MapCoord y, std::vector<unsigned short> * use_seas, const unsigned char player_attacker)const;
438
 
        /// Sucht verfügbare Soldaten, um dieses Militärgebäude mit einem Seeangriff anzugreifen
439
 
        void GetAvailableSoldiersForSeaAttack(const unsigned char player_attacker, const MapCoord x, const MapCoord y, std::list<PotentialSeaAttacker> * attackers) const;
440
 
        /// Gibt Anzahl oder geschätzte Stärke(rang summe + anzahl) der verfügbaren Soldaten die zu einem Schiffsangriff starten können von einer bestimmten sea id aus
441
 
        unsigned int GetAvailableSoldiersForSeaAttackAtSea(const unsigned char player_attacker, unsigned short seaid, bool count=true) const;
442
 
 
443
 
 
444
 
protected:
445
 
 
446
 
        /// Berechnet die Schattierung eines Punktes neu
447
 
        void RecalcShadow(const MapCoord x, const MapCoord y);
448
 
 
449
 
        /// Für abgeleitete Klasse, die dann das Terrain entsprechend neu generieren kann
450
 
        virtual void AltitudeChanged(const MapCoord x, const MapCoord y) = 0;
451
 
        /// Für abgeleitete Klasse, die dann das Terrain entsprechend neu generieren kann
452
 
        virtual void VisibilityChanged(const MapCoord x, const MapCoord y) = 0;
453
 
 
454
 
        /// Gibt nächsten Hafenpunkt in einer bestimmten Richtung zurück, bzw. 0, wenn es keinen gibt 
455
 
        unsigned GetNextHarborPoint(const MapCoord x, const MapCoord y, const unsigned origin_harbor_id, const unsigned char dir,
456
 
                                                                                   const unsigned char player, bool (GameWorldBase::*IsPointOK)(const unsigned, const unsigned char, const unsigned short) const) const;
457
 
 
458
 
        lua_State *lua;
459
 
 
460
 
        static int LUA_DisableBuilding(lua_State *L);
461
 
        static int LUA_EnableBuilding(lua_State *L);
462
 
        static int LUA_SetRestrictedArea(lua_State *L);
463
 
        static int LUA_AddWares(lua_State *L);
464
 
        static int LUA_AddPeople(lua_State *L);
465
 
 
466
 
public:
467
 
        void EventExplored(unsigned player, MapCoord x, MapCoord y);
468
 
        void EventOccupied(unsigned player, MapCoord x, MapCoord y);
469
 
        void EventStart();
 
129
    protected:
 
130
 
 
131
        /// Interface zum GUI
 
132
        GameInterface* gi;
 
133
 
 
134
        /// Breite und Höhe der Karte in Kontenpunkten
 
135
        unsigned short width, height;
 
136
        /// Landschafts-Typ
 
137
        LandscapeType lt;
 
138
 
 
139
        unsigned short* handled_nodes;  /// Array von abgeklapperten Knoten und deren Punktzahlen
 
140
 
 
141
        /// Eigenschaften von einem Punkt auf der Map
 
142
        MapNode* nodes;
 
143
 
 
144
        /// Rendert das Terrain
 
145
        TerrainRenderer tr;
 
146
 
 
147
        /// Informationen über die Weltmeere
 
148
        struct Sea
 
149
        {
 
150
            /// Anzahl der Knoten, welches sich in diesem Meer befinden
 
151
            unsigned nodes_count;
 
152
 
 
153
            Sea() : nodes_count(0) {}
 
154
            Sea(const unsigned nodes_count) : nodes_count(nodes_count) {}
 
155
        };
 
156
        std::vector<Sea> seas;
 
157
 
 
158
        /// Alle Hafenpositionen
 
159
        struct HarborPos
 
160
        {
 
161
            MapCoord x, y;
 
162
 
 
163
            struct CoastalPoint
 
164
            {
 
165
                unsigned short sea_id;
 
166
            } cps[6];
 
167
 
 
168
            struct Neighbor
 
169
            {
 
170
                unsigned id;
 
171
                unsigned distance;
 
172
 
 
173
                Neighbor() {}
 
174
                Neighbor(const unsigned id, const unsigned distance)
 
175
                    : id(id), distance(distance) {}
 
176
 
 
177
                bool operator<(const Neighbor& two) const
 
178
                { return distance < two.distance; }
 
179
            };
 
180
 
 
181
            std::vector<Neighbor> neighbors[6];
 
182
        };
 
183
 
 
184
        std::vector< HarborPos > harbor_pos;
 
185
 
 
186
        /// Baustellen von Häfen, die vom Schiff aus errichtet wurden
 
187
        std::list<noBuildingSite*> harbor_building_sites_from_sea;
 
188
 
 
189
        GameClientPlayerList* players;
 
190
 
 
191
    public:
 
192
        unsigned int map_size;
 
193
 
 
194
        std::list<CatapultStone*> catapult_stones; /// Liste von allen umherfliegenden Katapultsteinen.
 
195
 
 
196
        noNothing nothing; // nur Platzhalter bei der Rckgabe von GetNO
 
197
        /// Liste von Militärgebäuden (auch HQ und Haufengebäude, daher normale Gebäude) pro "Militärquadrat"
 
198
        list<nobBaseMilitary*> * military_squares;
 
199
 
 
200
    public:
 
201
 
 
202
        GameWorldBase();
 
203
        virtual ~GameWorldBase();
 
204
 
 
205
        // Grundlegende Initialisierungen
 
206
        void Init();
 
207
        /// Aufräumen
 
208
        void Unload();
 
209
 
 
210
        /// Setzt GameInterface
 
211
        inline void SetGameInterface(GameInterface* const gi) { this->gi = gi; }
 
212
 
 
213
        /// Größe der Map abfragen
 
214
        inline unsigned short GetWidth() const { return width; }
 
215
        inline unsigned short GetHeight() const { return height; }
 
216
 
 
217
        /// Landschaftstyp abfragen
 
218
        LandscapeType GetLandscapeType() const { return lt; }
 
219
 
 
220
        /// Gibt Punkt um diesen Punkt (X-Koordinate) direkt zurück in einer Richtung von 0-5
 
221
        MapCoord GetXA(const MapCoord x, const MapCoord y, unsigned dir) const;
 
222
        /// Gibt Punkt um diesen Punkt (Y-Koordinate)  direkt zurück in einer Richtung von 0-5
 
223
        MapCoord GetYA(const MapCoord x, const MapCoord y, unsigned dir) const;
 
224
        /// Wie GetXA, bloß 2. Außenschale (dir zwischen 0 bis 11)
 
225
        MapCoord GetXA2(const MapCoord x, const MapCoord y, unsigned dir) const;
 
226
        /// Wie GetYA, bloß 2. Außenschale (dir zwischen 0 bis 11)
 
227
        MapCoord GetYA2(const MapCoord x, const MapCoord y, unsigned dir) const;
 
228
        /// Wandelt einen Punkt in einen Nachbarpunkt um
 
229
        inline void GetPointA(MapCoord& x, MapCoord& y, unsigned dir) const {x = GetXA(x, y, dir); y = GetYA(x, y, dir);}
 
230
        /// Returns neighbouring point
 
231
        inline Point<MapCoord> GetPointA(Point<MapCoord> p, const unsigned dir) const
 
232
        { GetPointA(p.x, p.y, dir); return p; }
 
233
        /// Berechnet die Differenz zweier Koordinaten von x1 zu x2, wenn man berücksichtigt, dass man über den
 
234
        /// Rand weitergehen kann
 
235
        MapCoord CalcDistanceAroundBorderX(const MapCoord x1, const MapCoord x2) const;
 
236
        MapCoord CalcDistanceAroundBorderY(const MapCoord y1, const MapCoord y2) const;
 
237
 
 
238
        /// Ermittelt Abstand zwischen 2 Punkten auf der Map unter Berücksichtigung der Kartengrenzüberquerung
 
239
        unsigned CalcDistance(int x1, int y1, int x2, int y2) const;
 
240
        inline unsigned CalcDistance(const Point<MapCoord> p1, const Point<MapCoord> p2) const
 
241
        { return CalcDistance(p1.x, p1.y, p2.x, p2.y); }
 
242
 
 
243
        // Erzeugt eindeutige ID aus gegebenen X und Y-Werten
 
244
        inline unsigned MakeCoordID(const MapCoord x, const MapCoord y) const
 
245
        { return y * width + x; }
 
246
 
 
247
        /// Gibt Map-Knotenpunkt zurück
 
248
        inline const MapNode& GetNode(const MapCoord x, const MapCoord y) const { assert(x < width && y < height);  return nodes[y * width + x]; }
 
249
        MapNode& GetNode(const MapCoord x, const MapCoord y) { assert(x < width && y < height); return nodes[y * width + x]; }
 
250
        /// Gibt MapKnotenpunkt darum zurück
 
251
        inline const MapNode& GetNodeAround(const MapCoord x, const MapCoord y, const unsigned i) const
 
252
        { return GetNode(GetXA(x, y, i), GetYA(x, y, i));  }
 
253
        inline MapNode& GetNodeAround(const MapCoord x, const MapCoord y, const unsigned i)
 
254
        { return GetNode(GetXA(x, y, i), GetYA(x, y, i));  }
 
255
 
 
256
        // Gibt ein NO zurück, falls keins existiert, wird ein "Nothing-Objekt" zurückgegeben
 
257
        noBase* GetNO(const MapCoord x, const MapCoord y);
 
258
        // Gibt ein NO zurück, falls keins existiert, wird ein "Nothing-Objekt" zurückgegeben
 
259
        const noBase* GetNO(const MapCoord x, const MapCoord y) const;
 
260
        /// Gibt ein FOW-Objekt zurück, falls keins existiert, wird ein "Nothing-Objekt" zurückgegeben
 
261
        const FOWObject* GetFOWObject(const MapCoord x, const MapCoord y, const unsigned spectator_player) const;
 
262
        /// Gibt den GOT des an diesem Punkt befindlichen Objekts zurück bzw. GOT_NOTHING, wenn keins existiert
 
263
        GO_Type GetGOT(const MapCoord x, const MapCoord y) const;
 
264
 
 
265
        /// Gibt Figuren, die sich auf einem bestimmten Punkt befinden, zurück
 
266
        /// nicht bei laufenden Figuren oder
 
267
        list<noBase*>& GetFigures(const MapCoord x, const MapCoord y) const { return nodes[y * width + x].figures; }
 
268
        /// Gibt Dynamische Objekte, die von einem bestimmten Punkt aus laufen oder dort stehen sowie andere Objekte,
 
269
        /// die sich dort befinden, zurück
 
270
        void GetDynamicObjectsFrom(const MapCoord x, const MapCoord y, list<noBase*>& objects) const;
 
271
 
 
272
        // Gibt ein spezifisches Objekt zurück
 
273
        template<typename T> inline T* GetSpecObj(MapCoord x, MapCoord y) { return dynamic_cast<T*>( GetNode(x, y).obj ); }
 
274
        // Gibt ein spezifisches Objekt zurück
 
275
        template<typename T> inline const T* GetSpecObj(MapCoord x, MapCoord y) const { return dynamic_cast<const T*>( GetNode(x, y).obj ); }
 
276
 
 
277
        /// Gibt ein Terrain-Dreieck um einen Punkt herum zurück.
 
278
        unsigned char GetTerrainAround(int x, int y, unsigned char dir) const;
 
279
        /// Gibt das Terrain zurück, über das ein Mensch/Tier laufen müsste, von X,Y in Richtung DIR (Vorwärts).
 
280
        unsigned char GetWalkingTerrain1(MapCoord x, MapCoord y, unsigned char dir) const;
 
281
        /// Gibt das Terrain zurück, über das ein Mensch/Tier laufen müsste, von X,Y in Richtung DIR (Rückwärts).
 
282
        unsigned char GetWalkingTerrain2(MapCoord x, MapCoord y, unsigned char dir) const;
 
283
        /// Gibt zurück, ob ein Punkt vollständig von Wasser umgeben ist
 
284
        bool IsSeaPoint(MapCoord x, MapCoord y) const;
 
285
 
 
286
        /// liefert den Straßen-Wert an der Stelle X,Y
 
287
        unsigned char GetRoad(const MapCoord x, const MapCoord y, unsigned char dir, bool all = false) const;
 
288
        /// liefert den Straßen-Wert um den Punkt X,Y.
 
289
        unsigned char GetPointRoad(const MapCoord x, const MapCoord y, unsigned char dir, bool all = false) const;
 
290
        /// liefert FOW-Straßen-Wert um den punkt X,Y
 
291
        unsigned char GetPointFOWRoad(MapCoord x, MapCoord y, unsigned char dir, const unsigned char viewing_player) const;
 
292
 
 
293
        /// Kann dorthin eine Straße gebaut werden?
 
294
        bool RoadAvailable(const bool boat_road, const int x, const int y, unsigned char to_dir, const bool visual = true) const;
 
295
        /// Prüft ob exakt die gleiche Straße schon gebaut wurde
 
296
        bool RoadAlreadyBuilt(const bool boat_road, unsigned short start_x, unsigned short start_y, const std::vector<unsigned char>& route);
 
297
        /// Bauqualitäten berechnen, bei flagonly gibt er nur 1 zurück, wenn eine Flagge möglich ist
 
298
        BuildingQuality CalcBQ(const MapCoord x, const MapCoord y, const unsigned char player, const bool flagonly = false, const bool visual = true, const bool ignore_player = false) const;
 
299
        /// Setzt die errechnete BQ gleich mit
 
300
        inline void SetBQ(const MapCoord x, const MapCoord y, const unsigned char player, const bool flagonly = false, const bool visual = true)
 
301
        { GetNode(x, y).bq = CalcBQ(x, y, player, flagonly, visual); }
 
302
 
 
303
        /// Prüft, ob der Pkut zu dem Spieler gehört (wenn er der Besitzer ist und es false zurückliefert, ist es Grenzgebiet)
 
304
        bool IsPlayerTerritory(const MapCoord x, const MapCoord y) const;
 
305
        /// Berechnet BQ bei einer gebauten Straße
 
306
        void CalcRoad(const MapCoord x, const MapCoord y, const unsigned char player);
 
307
        /// Ist eine Flagge irgendwo um x,y ?
 
308
        bool FlagNear(const int x, const int y) const;
 
309
        /// Prüft, ob sich in unmittelbarer Nähe (im Radius von 4) Militärgebäude befinden
 
310
        bool IsMilitaryBuildingNearNode(const MapCoord nx, const MapCoord ny, const unsigned char player) const;
 
311
 
 
312
        /// setzt den virtuellen Straßen-Wert an der Stelle X,Y (berichtigt).
 
313
        void SetVirtualRoad(const MapCoord x, const MapCoord y, unsigned char dir, unsigned char type);
 
314
        /// setzt den virtuellen Straßen-Wert um den Punkt X,Y.
 
315
        void SetPointVirtualRoad(const MapCoord x, const MapCoord y, unsigned char dir, unsigned char type);
 
316
 
 
317
        /// Test, ob auf dem besagten Punkt ein Militärgebäude steht
 
318
        bool IsMilitaryBuilding(const MapCoord x, const MapCoord y) const;
 
319
 
 
320
        /// Erstellt eine Liste mit allen Militärgebäuden in der Umgebung, radius bestimmt wie viele Kästchen nach einer Richtung im Umkreis
 
321
        void LookForMilitaryBuildings(std::list<nobBaseMilitary*>& buildings, const MapCoord x, const MapCoord y, unsigned short radius) const;
 
322
 
 
323
        /// Prüft, ob von einem bestimmten Punkt aus der Untergrund für Figuren zugänglich ist (kein Wasser,Lava,Sumpf)
 
324
        bool IsNodeToNodeForFigure(const MapCoord x, const MapCoord y, const unsigned dir) const;
 
325
 
 
326
        /// Informationen, ob Grenzen überquert wurden
 
327
        struct CrossBorders
 
328
        {
 
329
            CrossBorders(void) : left(false), top(false), right(false), bottom(false) { }
 
330
            bool left, top, right, bottom;
 
331
        };
 
332
 
 
333
 
 
334
        /// Wegfindung in freiem Terrain - Basisroutine
 
335
        bool FindFreePath(const MapCoord x_start, const MapCoord y_start,
 
336
                          const MapCoord x_dest, const MapCoord y_dest, const bool random_route,
 
337
                          const unsigned max_route, std::vector<unsigned char> * route, unsigned* length, unsigned char* first_dir,
 
338
                          FP_Node_OK_Callback IsNodeOK, FP_Node_OK_Callback IsNodeToDestOk, const void* param, const bool record) const;
 
339
        /// Ermittelt, ob eine freie Route noch passierbar ist und gibt den Endpunkt der Route zurück
 
340
        bool CheckFreeRoute(const MapCoord x_start, const MapCoord y_start, const std::vector<unsigned char>& route,
 
341
                            const unsigned pos, FP_Node_OK_Callback IsNodeOK, FP_Node_OK_Callback IsNodeToDestOk,
 
342
                            MapCoord* x_dest,  MapCoord* y_dest, const void* const param = NULL) const;
 
343
        /// Wegfindung auf Straßen - Basisroutine
 
344
        bool FindPathOnRoads(const noRoadNode* const start, const noRoadNode* const goal,
 
345
                             const bool ware_mode, unsigned* length, unsigned char* first_dir, Point<MapCoord> * next_harbor,
 
346
                             const RoadSegment* const forbidden, const bool record = true, unsigned max = 0xFFFFFFFF) const;
 
347
        /// Findet einen Weg für Figuren
 
348
        unsigned char FindHumanPath(const MapCoord x_start, const MapCoord y_start,
 
349
                                    const MapCoord x_dest, const MapCoord y_dest, const unsigned max_route = 0xFFFFFFFF, const bool random_route = false, unsigned* length = NULL, const bool record = true) const;
 
350
        /// Wegfindung für Schiffe auf dem Wasser
 
351
        bool FindShipPath(const MapCoord x_start, const MapCoord y_start, const MapCoord x_dest, const MapCoord y_dest, std::vector<unsigned char> * route, unsigned* length, const unsigned max_length = 200,
 
352
                          CrossBorders* cb = NULL);
 
353
 
 
354
 
 
355
        /// Baut eine (bisher noch visuell gebaute) Straße wieder zurück
 
356
        void RemoveVisualRoad(unsigned short start_x, unsigned short start_y, const std::vector<unsigned char>& route);
 
357
 
 
358
        /// x,y ist ein Punkt auf irgendeinem Wegstck, gibt die Flagge zurück
 
359
        noFlag* GetRoadFlag(int x, int y, unsigned char& dir, unsigned last_i = 255);
 
360
 
 
361
        /// Konvertiert die Koordinaten.
 
362
        void ConvertCoords(int x, int y, unsigned short* x_out, unsigned short* y_out) const;
 
363
 
 
364
        /// Erzeugt eine GUI-ID für die Fenster von Map-Objekten
 
365
        inline unsigned CreateGUIID(const MapCoord x, const MapCoord y) const
 
366
        { return 1000 + width * y + x; }
 
367
        /// Gibt Terrainkoordinaten zurück
 
368
        inline float GetTerrainX(const MapCoord x, const MapCoord y)
 
369
        { return tr.GetTerrainX(x, y); }
 
370
        inline float GetTerrainY(const MapCoord x, const MapCoord y)
 
371
        { return tr.GetTerrainY(x, y); }
 
372
 
 
373
        /// Verändert die Höhe eines Punktes und die damit verbundenen Schatten
 
374
        void ChangeAltitude(const MapCoord x, const MapCoord y, const unsigned char altitude);
 
375
 
 
376
        /// Ermittelt Sichtbarkeit eines Punktes auch unter Einbeziehung der Verbündeten des jeweiligen Spielers
 
377
        Visibility CalcWithAllyVisiblity(const MapCoord x, const MapCoord y, const unsigned char player) const;
 
378
 
 
379
        /// Gibt die Anzahl an Hafenpunkten zurück
 
380
        inline unsigned GetHarborPointCount() const
 
381
        { return harbor_pos.size() - 1; }
 
382
        /// Ist es an dieser Stelle für einen Spieler möglich einen Hafen zu bauen
 
383
        bool IsHarborPointFree(const unsigned harbor_id, const unsigned char player,
 
384
                               const unsigned short sea_id) const;
 
385
        /// Gibt die Koordinaten eines bestimmten Hafenpunktes zurück
 
386
        Point<MapCoord> GetHarborPoint(const unsigned harbor_id) const;
 
387
        /// Gibt die ID eines Hafenpunktes zurück
 
388
        inline unsigned GetHarborPointID(const MapCoord x, const MapCoord y) const
 
389
        { return GetNode(x, y).harbor_id; }
 
390
        /// Ermittelt, ob ein Punkt Küstenpunkt ist, d.h. Zugang zu einem schiffbaren Meer hat
 
391
        /// und gibt ggf. die Meeres-ID zurück, ansonsten 0
 
392
        unsigned short IsCoastalPoint(const MapCoord x, const MapCoord y) const;
 
393
        /// Ermittelt, ob ein Punkt Küstenpunkt ist, d.h. Zugang zu einem schiffbaren Meer, an dem auch mindestens 1 Hafenplatz liegt, hat
 
394
        /// und gibt ggf. die Meeres-ID zurück, ansonsten 0
 
395
        unsigned short IsCoastalPointToSeaWithHarbor(const MapCoord x, const MapCoord y) const;
 
396
        /// Grenzt der Hafen an ein bestimmtes Meer an?
 
397
        bool IsAtThisSea(const unsigned harbor_id, const unsigned short sea_id) const;
 
398
        /// Gibt den Punkt eines bestimmtes Meeres um den Hafen herum an, sodass Schiffe diesen anfahren können
 
399
        void GetCoastalPoint(const unsigned harbor_id, MapCoord* px, MapCoord* py, const unsigned short sea_id) const;
 
400
        /// Sucht freie Hafenpunkte, also wo noch ein Hafen gebaut werden kann
 
401
        unsigned GetNextFreeHarborPoint(const MapCoord x, const MapCoord y, const unsigned origin_harbor_id, const unsigned char dir,
 
402
                                        const unsigned char player) const;
 
403
        /// Gibt die angrenzenden Sea-IDs eines Hafenpunktes zurück
 
404
        void GetSeaIDs(const unsigned harbor_id, unsigned short* sea_ids) const;
 
405
        /// Berechnet die Entfernung zwischen 2 Hafenpunkten
 
406
        unsigned CalcHarborDistance(const unsigned habor_id1, const unsigned harbor_id2) const;
 
407
        /// Bestimmt für einen beliebigen Punkt auf der Karte die Entfernung zum nächsten Hafenpunkt
 
408
        unsigned CalcDistanceToNearestHarbor(const Point<MapCoord> pos) const;
 
409
        /// returns true when a harborpoint is in SEAATTACK_DISTANCE for figures!
 
410
        bool IsAHarborInSeaAttackDistance(const Point<MapCoord> pos) const;
 
411
 
 
412
 
 
413
 
 
414
        inline void SetPlayers(GameClientPlayerList* pls) { players = pls; }
 
415
        /// Liefert einen Player zurück
 
416
        inline GameClientPlayer* GetPlayer(const unsigned int id) const { return players->getElement(id); }
 
417
 
 
418
        struct PotentialSeaAttacker
 
419
        {
 
420
            /// Soldat, der als Angreifer in Frage kommt
 
421
            nofPassiveSoldier* soldier;
 
422
            /// Hafen, den der Soldat zuerst ansteuern soll
 
423
            nobHarborBuilding* harbor;
 
424
            /// Entfernung Hafen-Hafen (entscheidende)
 
425
            unsigned distance;
 
426
 
 
427
            /// Komperator zum Sortieren
 
428
            bool operator<(const PotentialSeaAttacker& pa) const;
 
429
        };
 
430
 
 
431
 
 
432
        /// Liefert Hafenpunkte im Umkreis von einem bestimmten Militärgebäude
 
433
        void GetHarborPointsAroundMilitaryBuilding(const MapCoord x, const MapCoord y, std::vector<unsigned> * harbor_points) const;
 
434
        /// returns all sea_ids from which a given building can be attacked by sea
 
435
        void GetValidSeaIDsAroundMilitaryBuildingForAttack(const MapCoord x, const MapCoord y, std::vector<bool> * use_seas, const unsigned char player_attacker, std::vector<unsigned>*harbor_points)const;
 
436
        /// returns all sea_ids found in the given vector from which a given building can be attacked by sea
 
437
        void GetValidSeaIDsAroundMilitaryBuildingForAttackCompare(const MapCoord x, const MapCoord y, std::vector<unsigned short> * use_seas, const unsigned char player_attacker)const;
 
438
        /// Sucht verfügbare Soldaten, um dieses Militärgebäude mit einem Seeangriff anzugreifen
 
439
        void GetAvailableSoldiersForSeaAttack(const unsigned char player_attacker, const MapCoord x, const MapCoord y, std::list<PotentialSeaAttacker> * attackers) const;
 
440
        /// Gibt Anzahl oder geschätzte Stärke(rang summe + anzahl) der verfügbaren Soldaten die zu einem Schiffsangriff starten können von einer bestimmten sea id aus
 
441
        unsigned int GetAvailableSoldiersForSeaAttackAtSea(const unsigned char player_attacker, unsigned short seaid, bool count = true) const;
 
442
 
 
443
 
 
444
    protected:
 
445
 
 
446
        /// Berechnet die Schattierung eines Punktes neu
 
447
        void RecalcShadow(const MapCoord x, const MapCoord y);
 
448
 
 
449
        /// Für abgeleitete Klasse, die dann das Terrain entsprechend neu generieren kann
 
450
        virtual void AltitudeChanged(const MapCoord x, const MapCoord y) = 0;
 
451
        /// Für abgeleitete Klasse, die dann das Terrain entsprechend neu generieren kann
 
452
        virtual void VisibilityChanged(const MapCoord x, const MapCoord y) = 0;
 
453
 
 
454
        /// Gibt nächsten Hafenpunkt in einer bestimmten Richtung zurück, bzw. 0, wenn es keinen gibt
 
455
        unsigned GetNextHarborPoint(const MapCoord x, const MapCoord y, const unsigned origin_harbor_id, const unsigned char dir,
 
456
                                    const unsigned char player, bool (GameWorldBase::*IsPointOK)(const unsigned, const unsigned char, const unsigned short) const) const;
 
457
 
 
458
        lua_State* lua;
 
459
 
 
460
        static int LUA_DisableBuilding(lua_State* L);
 
461
        static int LUA_EnableBuilding(lua_State* L);
 
462
        static int LUA_SetRestrictedArea(lua_State* L);
 
463
        static int LUA_AddWares(lua_State* L);
 
464
        static int LUA_AddPeople(lua_State* L);
 
465
 
 
466
    public:
 
467
        void EventExplored(unsigned player, MapCoord x, MapCoord y);
 
468
        void EventOccupied(unsigned player, MapCoord x, MapCoord y);
 
469
        void EventStart();
470
470
};
471
471
 
472
472
class GameWorldView
473
473
{
474
 
        /// Selektierter Punkt
475
 
        unsigned short selx,sely;
476
 
        int selxo,selyo;
477
 
 
478
 
        /// Koordinaten auf der Map anzeigen (zum Debuggen)?
479
 
        bool show_coordinates;
480
 
 
481
 
        bool show_bq;    ///< Bauqualitäten-Anzeigen ein oder aus
482
 
        bool show_names; ///< Gebäudenamen-Anzeigen ein oder aus
483
 
        bool show_productivity; ///< Produktivität-Anzeigen ein oder aus
484
 
 
485
 
        /// Scrolling-Zeug
486
 
        int xoffset,yoffset;
487
 
        /// Letzte Scrollposition, an der man war, bevor man weggesprungen ist
488
 
        int last_xoffset, last_yoffset;
489
 
        /// Erster gezeichneter Map-Punkt
490
 
        int fx,fy;
491
 
        /// Letzter gezeichneter Map-Punkt
492
 
        int lx,ly;
493
 
 
494
 
        GameWorldViewer *gwv;
495
 
 
496
 
protected:
497
 
        unsigned d_what;
498
 
        unsigned d_player;
499
 
        bool d_active;
500
 
 
501
 
        unsigned short x, y;
502
 
        unsigned short width, height;
503
 
 
504
 
public:
505
 
        bool terrain_rerender;
506
 
        unsigned int terrain_list;
507
 
        int terrain_last_xoffset, terrain_last_yoffset;
508
 
        unsigned int terrain_last_global_animation;
509
 
        unsigned int terrain_last_water;
510
 
 
511
 
        std::list<MapTile> sorted_textures[16];
512
 
        std::list<BorderTile> sorted_borders[5];
513
 
        std::list<PreparedRoad> sorted_roads[4];
514
 
 
515
 
        GameWorldView(GameWorldViewer *gwv, unsigned short x, unsigned short y, unsigned short width, unsigned short height);
516
 
        ~GameWorldView();
517
 
 
518
 
        GameWorldViewer *GetGameWorldViewer() {return(gwv);}
519
 
        GameWorldViewer *GetGameWorldViewer() const {return(gwv);};
520
 
 
521
 
 
522
 
        inline void SetX(unsigned short new_x) {x = new_x;}
523
 
        inline void SetY(unsigned short new_y) {y = new_y;}
524
 
 
525
 
        inline unsigned short GetX() {return(x);}
526
 
        inline unsigned short GetY() {return(y);}
527
 
 
528
 
        /// Bauqualitäten anzeigen oder nicht
529
 
        inline void ShowBQ() { show_bq = !show_bq; }
530
 
        /// Gebäudenamen zeigen oder nicht
531
 
        inline void ShowNames() { show_names = !show_names; }
532
 
        /// Produktivität zeigen oder nicht
533
 
        inline void ShowProductivity() { show_productivity = !show_productivity; };
534
 
        /// Schaltet Produktivitäten/Namen komplett aus oder an
535
 
        void ShowNamesAndProductivity();
536
 
 
537
 
 
538
 
        void Draw(const unsigned char player, unsigned * water, const bool draw_selected, const MapCoord selected_x, const MapCoord selected_y,const RoadsBuilding& rb);
539
 
/*
540
 
        void PrepareRendering(const unsigned char player, const bool draw_selected, const MapCoord selected_x, const MapCoord selected_y,const RoadsBuilding& rb);
541
 
        void Render();
542
 
*/
543
 
 
544
 
        /// Bewegt sich zu einer bestimmten Position in Pixeln auf der Karte
545
 
        void MoveTo(int x, int y, bool absolute = false);
546
 
        /// Zentriert den Bildschirm auf ein bestimmtes Map-Object
547
 
        void MoveToMapObject(const MapCoord x, const MapCoord y);
548
 
        /// Springt zur letzten Position, bevor man "weggesprungen" ist
549
 
        void MoveToLastPosition();
550
 
 
551
 
        inline void MoveToX(int x, bool absolute = false) { MoveTo( (absolute ? 0 : xoffset) + x, yoffset, true); }
552
 
        inline void MoveToY(int y, bool absolute = false) { MoveTo( xoffset, (absolute ? 0 : yoffset) + y, true); }
553
 
 
554
 
        void CalcFxLx();
555
 
 
556
 
        /// Koordinatenanzeige ein/aus
557
 
        inline void ShowCoordinates() { show_coordinates = !show_coordinates; }
558
 
 
559
 
        /// Gibt selektierten Punkt zurück
560
 
        inline unsigned short GetSelX() const { return selx; }
561
 
        inline unsigned short GetSelY() const { return sely; }
562
 
 
563
 
        inline int GetSelXo() const { return selxo; }
564
 
        inline int GetSelYo() const { return selyo; }
565
 
 
566
 
        /// Gibt Scrolling-Offset zurück
567
 
        inline int GetXOffset() const { return xoffset - x; }
568
 
        inline int GetYOffset() const { return yoffset - y; }
569
 
        /// Gibt ersten Punkt an, der beim Zeichnen angezeigt wird
570
 
        inline int GetFirstX() const { return fx; }
571
 
        inline int GetFirstY() const { return fy; }
572
 
        /// Gibt letzten Punkt an, der beim Zeichnen angezeigt wird
573
 
        inline int GetLastX() const { return lx; }
574
 
        inline int GetLastY() const { return ly; }
575
 
 
576
 
        void DrawBoundaryStone(const int x, const int y, const MapCoord tx, const MapCoord ty, const int xpos, const int ypos, Visibility vis);
577
 
 
578
 
        void Resize(unsigned short width, unsigned short height);
579
 
 
580
 
        void SetAIDebug(unsigned what, unsigned player, bool active) 
581
 
        {
582
 
                d_what = what; d_player = player; d_active = active; 
583
 
        }
 
474
        /// Selektierter Punkt
 
475
        unsigned short selx, sely;
 
476
        int selxo, selyo;
 
477
 
 
478
        /// Koordinaten auf der Map anzeigen (zum Debuggen)?
 
479
        bool show_coordinates;
 
480
 
 
481
        bool show_bq;    ///< Bauqualitäten-Anzeigen ein oder aus
 
482
        bool show_names; ///< Gebäudenamen-Anzeigen ein oder aus
 
483
        bool show_productivity; ///< Produktivität-Anzeigen ein oder aus
 
484
 
 
485
        /// Scrolling-Zeug
 
486
        int xoffset, yoffset;
 
487
        /// Letzte Scrollposition, an der man war, bevor man weggesprungen ist
 
488
        int last_xoffset, last_yoffset;
 
489
        /// Erster gezeichneter Map-Punkt
 
490
        int fx, fy;
 
491
        /// Letzter gezeichneter Map-Punkt
 
492
        int lx, ly;
 
493
 
 
494
        GameWorldViewer* gwv;
 
495
 
 
496
    protected:
 
497
        unsigned d_what;
 
498
        unsigned d_player;
 
499
        bool d_active;
 
500
 
 
501
        unsigned short x, y;
 
502
        unsigned short width, height;
 
503
 
 
504
    public:
 
505
        bool terrain_rerender;
 
506
        unsigned int terrain_list;
 
507
        int terrain_last_xoffset, terrain_last_yoffset;
 
508
        unsigned int terrain_last_global_animation;
 
509
        unsigned int terrain_last_water;
 
510
 
 
511
        std::list<MapTile> sorted_textures[16];
 
512
        std::list<BorderTile> sorted_borders[5];
 
513
        std::list<PreparedRoad> sorted_roads[4];
 
514
 
 
515
        GameWorldView(GameWorldViewer* gwv, unsigned short x, unsigned short y, unsigned short width, unsigned short height);
 
516
        ~GameWorldView();
 
517
 
 
518
        GameWorldViewer* GetGameWorldViewer() {return(gwv);}
 
519
        GameWorldViewer* GetGameWorldViewer() const {return(gwv);};
 
520
 
 
521
 
 
522
        inline void SetX(unsigned short new_x) {x = new_x;}
 
523
        inline void SetY(unsigned short new_y) {y = new_y;}
 
524
 
 
525
        inline unsigned short GetX() {return(x);}
 
526
        inline unsigned short GetY() {return(y);}
 
527
 
 
528
        /// Bauqualitäten anzeigen oder nicht
 
529
        inline void ShowBQ() { show_bq = !show_bq; }
 
530
        /// Gebäudenamen zeigen oder nicht
 
531
        inline void ShowNames() { show_names = !show_names; }
 
532
        /// Produktivität zeigen oder nicht
 
533
        inline void ShowProductivity() { show_productivity = !show_productivity; };
 
534
        /// Schaltet Produktivitäten/Namen komplett aus oder an
 
535
        void ShowNamesAndProductivity();
 
536
 
 
537
 
 
538
        void Draw(const unsigned char player, unsigned* water, const bool draw_selected, const MapCoord selected_x, const MapCoord selected_y, const RoadsBuilding& rb);
 
539
        /*
 
540
            void PrepareRendering(const unsigned char player, const bool draw_selected, const MapCoord selected_x, const MapCoord selected_y,const RoadsBuilding& rb);
 
541
            void Render();
 
542
        */
 
543
 
 
544
        /// Bewegt sich zu einer bestimmten Position in Pixeln auf der Karte
 
545
        void MoveTo(int x, int y, bool absolute = false);
 
546
        /// Zentriert den Bildschirm auf ein bestimmtes Map-Object
 
547
        void MoveToMapObject(const MapCoord x, const MapCoord y);
 
548
        /// Springt zur letzten Position, bevor man "weggesprungen" ist
 
549
        void MoveToLastPosition();
 
550
 
 
551
        inline void MoveToX(int x, bool absolute = false) { MoveTo( (absolute ? 0 : xoffset) + x, yoffset, true); }
 
552
        inline void MoveToY(int y, bool absolute = false) { MoveTo( xoffset, (absolute ? 0 : yoffset) + y, true); }
 
553
 
 
554
        void CalcFxLx();
 
555
 
 
556
        /// Koordinatenanzeige ein/aus
 
557
        inline void ShowCoordinates() { show_coordinates = !show_coordinates; }
 
558
 
 
559
        /// Gibt selektierten Punkt zurück
 
560
        inline unsigned short GetSelX() const { return selx; }
 
561
        inline unsigned short GetSelY() const { return sely; }
 
562
 
 
563
        inline int GetSelXo() const { return selxo; }
 
564
        inline int GetSelYo() const { return selyo; }
 
565
 
 
566
        /// Gibt Scrolling-Offset zurück
 
567
        inline int GetXOffset() const { return xoffset - x; }
 
568
        inline int GetYOffset() const { return yoffset - y; }
 
569
        /// Gibt ersten Punkt an, der beim Zeichnen angezeigt wird
 
570
        inline int GetFirstX() const { return fx; }
 
571
        inline int GetFirstY() const { return fy; }
 
572
        /// Gibt letzten Punkt an, der beim Zeichnen angezeigt wird
 
573
        inline int GetLastX() const { return lx; }
 
574
        inline int GetLastY() const { return ly; }
 
575
 
 
576
        void DrawBoundaryStone(const int x, const int y, const MapCoord tx, const MapCoord ty, const int xpos, const int ypos, Visibility vis);
 
577
 
 
578
        void Resize(unsigned short width, unsigned short height);
 
579
 
 
580
        void SetAIDebug(unsigned what, unsigned player, bool active)
 
581
        {
 
582
            d_what = what; d_player = player; d_active = active;
 
583
        }
584
584
};
585
585
 
586
586
/// "Interface-Klasse" für GameWorldBase, die die Daten grafisch anzeigt
587
587
class GameWorldViewer : public virtual GameWorldBase
588
588
{
589
 
        /// Wird gerade gescrollt?
590
 
        bool scroll;
591
 
        int sx,sy;
592
 
 
593
 
        GameWorldView view;
594
 
public:
595
 
 
596
 
        GameWorldViewer();
597
 
 
598
 
        // Wege und Grenzsteine zeichnen ( nur reingenommen, da die Position sowieso hier berechnet wird, da bietet es sich an )
599
 
        void DrawWays(const int x, const int y, const float xpos, const float ypos);
600
 
 
601
 
        void Draw(const unsigned char player, unsigned * water, const bool draw_selected, const MapCoord selected_x, const MapCoord selected_y,const RoadsBuilding& rb)
602
 
        {
603
 
                view.Draw(player, water, draw_selected, selected_x, selected_y, rb);
604
 
        }
605
 
 
606
 
        inline GameWorldView *GetView() {return(&view);}
607
 
 
608
 
        inline TerrainRenderer *GetTerrainRenderer() {return(&tr);}
609
 
 
610
 
        /// Bauqualitäten anzeigen oder nicht
611
 
        inline void ShowBQ() {view.ShowBQ();}
612
 
        /// Gebäudenamen zeigen oder nicht
613
 
        inline void ShowNames() {view.ShowNames();}
614
 
        /// Produktivität zeigen oder nicht
615
 
        inline void ShowProductivity() {view.ShowProductivity();};
616
 
        /// Schaltet Produktivitäten/Namen komplett aus oder an
617
 
        inline void ShowNamesAndProductivity() {view.ShowNamesAndProductivity();}
618
 
 
619
 
        /// Wegfinden ( A* ) --> Wegfindung auf allgemeinen Terrain ( ohne Straäcn ) ( fr Wegebau oder frei herumlaufende )
620
 
        bool FindRoadPath(const MapCoord x_start,const MapCoord y_start, const MapCoord x_dest, const MapCoord y_dest,std::vector<unsigned char>& route, const bool boat_road);
621
 
        /// Sucht die Anzahl der verfügbaren Soldaten, um das Militärgebäude an diesem Punkt anzugreifen
622
 
        unsigned GetAvailableSoldiersForAttack(const unsigned char player_attacker,const MapCoord x, const MapCoord y);
623
 
 
624
 
        /// Scrolling-Zeug
625
 
        void MouseMove(const MouseCoords& mc);
626
 
        void MouseDown(const MouseCoords& mc);
627
 
        void MouseUp();
628
 
        inline void DontScroll() { scroll = false; }
629
 
 
630
 
        /// Bewegt sich zu einer bestimmten Position in Pixeln auf der Karte
631
 
        inline void MoveTo(int x, int y, bool absolute = false) {view.MoveTo(x, y, absolute);};
632
 
        /// Zentriert den Bildschirm auf ein bestimmtes Map-Object
633
 
        inline void MoveToMapObject(const MapCoord x, const MapCoord y) {view.MoveToMapObject(x, y);};
634
 
        /// Springt zur letzten Position, bevor man "weggesprungen" ist
635
 
        inline void MoveToLastPosition() {view.MoveToLastPosition();};
636
 
 
637
 
        void MoveToX(int x, bool absolute = false) {view.MoveToX(x, absolute);}
638
 
        void MoveToY(int y, bool absolute = false) {view.MoveToY(y, absolute);}
639
 
 
640
 
        /// Koordinatenanzeige ein/aus
641
 
        inline void ShowCoordinates() { view.ShowCoordinates(); }
642
 
 
643
 
        /// Gibt selektierten Punkt zurück
644
 
        inline unsigned short GetSelX() const { return(view.GetSelX()); }
645
 
        inline unsigned short GetSelY() const { return(view.GetSelY()); }
646
 
 
647
 
        /// Gibt ersten Punkt an, der beim Zeichnen angezeigt wird
648
 
        inline int GetFirstX() const { return(view.GetFirstX()); }
649
 
        inline int GetFirstY() const { return(view.GetFirstY()); }
650
 
        /// Gibt letzten Punkt an, der beim Zeichnen angezeigt wird
651
 
        inline int GetLastX() const { return(view.GetLastX()); }
652
 
        inline int GetLastY() const { return(view.GetLastY()); }
653
 
 
654
 
        /// Ermittelt Sichtbarkeit eines Punktes für den lokalen Spieler, berücksichtigt ggf. Teamkameraden
655
 
        Visibility GetVisibility(const MapCoord x, const MapCoord y) const; 
656
 
 
657
 
        /// Höhe wurde verändert: TerrainRenderer Bescheid sagen, damit es entsprechend verändert werden kann
658
 
        void AltitudeChanged(const MapCoord x, const MapCoord y);
659
 
        /// Sichtbarkeit wurde verändert: TerrainRenderer Bescheid sagen, damit es entsprechend verändert werden kann
660
 
        void VisibilityChanged(const MapCoord x, const MapCoord y);
661
 
 
662
 
        /// liefert sichtbare Strasse, im Nebel entsprechend die FoW-Strasse
663
 
        unsigned char GetVisibleRoad(const MapCoord x, const MapCoord y, unsigned char dir, const Visibility visibility) const;
664
 
 
665
 
        /// Get the "youngest" FOWObject of all players who share the view with the local player
666
 
        const FOWObject * GetYoungestFOWObject(const Point<MapCoord> pos) const;
667
 
        
668
 
        /// Gets the youngest fow node of all visible objects of all players who are connected
669
 
        /// with the local player via team view
670
 
        unsigned char GetYoungestFOWNodePlayer(const Point<MapCoord> pos) const;
671
 
 
672
 
        /// Schattierungen (vor allem FoW) neu berechnen
673
 
        void RecalcAllColors();
674
 
 
675
 
        /// Gibt das erste Schiff, was gefunden wird von diesem Spieler, zurück, ansonsten NULL, falls es nicht
676
 
        /// existiert
677
 
        noShip * GetShip(const MapCoord x, const MapCoord y, const unsigned char player) const;
678
 
 
679
 
        /// Gibt die verfügbar Anzahl der Angreifer für einen Seeangriff zurück
680
 
        unsigned GetAvailableSoldiersForSeaAttackCount(const unsigned char player_attacker, const MapCoord x, const MapCoord y) const;
681
 
 
682
 
        inline void Resize(unsigned short width, unsigned short height) {view.Resize(width, height);}
683
 
 
684
 
        inline void SetAIDebug(unsigned what, unsigned player, bool active) {view.SetAIDebug(what, player, active);}
 
589
        /// Wird gerade gescrollt?
 
590
        bool scroll;
 
591
        int sx, sy;
 
592
 
 
593
        GameWorldView view;
 
594
    public:
 
595
 
 
596
        GameWorldViewer();
 
597
 
 
598
        // Wege und Grenzsteine zeichnen ( nur reingenommen, da die Position sowieso hier berechnet wird, da bietet es sich an )
 
599
        void DrawWays(const int x, const int y, const float xpos, const float ypos);
 
600
 
 
601
        void Draw(const unsigned char player, unsigned* water, const bool draw_selected, const MapCoord selected_x, const MapCoord selected_y, const RoadsBuilding& rb)
 
602
        {
 
603
            view.Draw(player, water, draw_selected, selected_x, selected_y, rb);
 
604
        }
 
605
 
 
606
        inline GameWorldView* GetView() {return(&view);}
 
607
 
 
608
        inline TerrainRenderer* GetTerrainRenderer() {return(&tr);}
 
609
 
 
610
        /// Bauqualitäten anzeigen oder nicht
 
611
        inline void ShowBQ() {view.ShowBQ();}
 
612
        /// Gebäudenamen zeigen oder nicht
 
613
        inline void ShowNames() {view.ShowNames();}
 
614
        /// Produktivität zeigen oder nicht
 
615
        inline void ShowProductivity() {view.ShowProductivity();};
 
616
        /// Schaltet Produktivitäten/Namen komplett aus oder an
 
617
        inline void ShowNamesAndProductivity() {view.ShowNamesAndProductivity();}
 
618
 
 
619
        /// Wegfinden ( A* ) --> Wegfindung auf allgemeinen Terrain ( ohne Straäcn ) ( fr Wegebau oder frei herumlaufende )
 
620
        bool FindRoadPath(const MapCoord x_start, const MapCoord y_start, const MapCoord x_dest, const MapCoord y_dest, std::vector<unsigned char>& route, const bool boat_road);
 
621
        /// Sucht die Anzahl der verfügbaren Soldaten, um das Militärgebäude an diesem Punkt anzugreifen
 
622
        unsigned GetAvailableSoldiersForAttack(const unsigned char player_attacker, const MapCoord x, const MapCoord y);
 
623
 
 
624
        /// Scrolling-Zeug
 
625
        void MouseMove(const MouseCoords& mc);
 
626
        void MouseDown(const MouseCoords& mc);
 
627
        void MouseUp();
 
628
        inline void DontScroll() { scroll = false; }
 
629
 
 
630
        /// Bewegt sich zu einer bestimmten Position in Pixeln auf der Karte
 
631
        inline void MoveTo(int x, int y, bool absolute = false) {view.MoveTo(x, y, absolute);};
 
632
        /// Zentriert den Bildschirm auf ein bestimmtes Map-Object
 
633
        inline void MoveToMapObject(const MapCoord x, const MapCoord y) {view.MoveToMapObject(x, y);};
 
634
        /// Springt zur letzten Position, bevor man "weggesprungen" ist
 
635
        inline void MoveToLastPosition() {view.MoveToLastPosition();};
 
636
 
 
637
        void MoveToX(int x, bool absolute = false) {view.MoveToX(x, absolute);}
 
638
        void MoveToY(int y, bool absolute = false) {view.MoveToY(y, absolute);}
 
639
 
 
640
        /// Koordinatenanzeige ein/aus
 
641
        inline void ShowCoordinates() { view.ShowCoordinates(); }
 
642
 
 
643
        /// Gibt selektierten Punkt zurück
 
644
        inline unsigned short GetSelX() const { return(view.GetSelX()); }
 
645
        inline unsigned short GetSelY() const { return(view.GetSelY()); }
 
646
 
 
647
        /// Gibt ersten Punkt an, der beim Zeichnen angezeigt wird
 
648
        inline int GetFirstX() const { return(view.GetFirstX()); }
 
649
        inline int GetFirstY() const { return(view.GetFirstY()); }
 
650
        /// Gibt letzten Punkt an, der beim Zeichnen angezeigt wird
 
651
        inline int GetLastX() const { return(view.GetLastX()); }
 
652
        inline int GetLastY() const { return(view.GetLastY()); }
 
653
 
 
654
        /// Ermittelt Sichtbarkeit eines Punktes für den lokalen Spieler, berücksichtigt ggf. Teamkameraden
 
655
        Visibility GetVisibility(const MapCoord x, const MapCoord y) const;
 
656
 
 
657
        /// Höhe wurde verändert: TerrainRenderer Bescheid sagen, damit es entsprechend verändert werden kann
 
658
        void AltitudeChanged(const MapCoord x, const MapCoord y);
 
659
        /// Sichtbarkeit wurde verändert: TerrainRenderer Bescheid sagen, damit es entsprechend verändert werden kann
 
660
        void VisibilityChanged(const MapCoord x, const MapCoord y);
 
661
 
 
662
        /// liefert sichtbare Strasse, im Nebel entsprechend die FoW-Strasse
 
663
        unsigned char GetVisibleRoad(const MapCoord x, const MapCoord y, unsigned char dir, const Visibility visibility) const;
 
664
 
 
665
        /// Get the "youngest" FOWObject of all players who share the view with the local player
 
666
        const FOWObject* GetYoungestFOWObject(const Point<MapCoord> pos) const;
 
667
 
 
668
        /// Gets the youngest fow node of all visible objects of all players who are connected
 
669
        /// with the local player via team view
 
670
        unsigned char GetYoungestFOWNodePlayer(const Point<MapCoord> pos) const;
 
671
 
 
672
        /// Schattierungen (vor allem FoW) neu berechnen
 
673
        void RecalcAllColors();
 
674
 
 
675
        /// Gibt das erste Schiff, was gefunden wird von diesem Spieler, zurück, ansonsten NULL, falls es nicht
 
676
        /// existiert
 
677
        noShip* GetShip(const MapCoord x, const MapCoord y, const unsigned char player) const;
 
678
 
 
679
        /// Gibt die verfügbar Anzahl der Angreifer für einen Seeangriff zurück
 
680
        unsigned GetAvailableSoldiersForSeaAttackCount(const unsigned char player_attacker, const MapCoord x, const MapCoord y) const;
 
681
 
 
682
        inline void Resize(unsigned short width, unsigned short height) {view.Resize(width, height);}
 
683
 
 
684
        inline void SetAIDebug(unsigned what, unsigned player, bool active) {view.SetAIDebug(what, player, active);}
685
685
};
686
686
 
687
687
/// "Interface-Klasse" für das Spiel
688
688
class GameWorldGame : public virtual GameWorldBase
689
689
{
690
 
protected:
691
 
        /// rade graphs, one for each player
692
 
        std::vector<TradeGraph*> tgs;
693
 
private:
694
 
 
695
 
 
696
 
 
697
 
        /// vergleicht 2 Punkte, ob sie von unterschiedlichen Spielern sind und setzt
698
 
        /// Punkt ggf. zu gar keinem Spieler, 2. Funktion wird für Punkte im 2er Abstand verwendet, da es dort ein bisschen anders läuft!
699
 
        void AdjustNodes(const MapCoord x1, const MapCoord y1, const MapCoord x2, const MapCoord y2);
700
 
        void AdjustNodes2(const MapCoord x1, const MapCoord y1, const MapCoord x2, const MapCoord y2);
701
 
        /// Zerstört Spielerteile auf einem Punkt, wenn der Punkt dem Spieler nun nich mehr gehört
702
 
        void DestroyPlayerRests(const MapCoord x, const MapCoord y, const unsigned char new_player,const noBaseBuilding * exception);
703
 
 
704
 
        /// Prüft, ob auf diesem Punkt Deko-Objekte liegen, die für den Wegbau entfernt werden können
705
 
        bool IsObjectionableForRoad(const MapCoord x, const MapCoord y);
706
 
 
707
 
        
708
 
        /// Punkt vollständig sichtbar?
709
 
        bool IsPointCompletelyVisible(const MapCoord x, const MapCoord y, const unsigned char player, const noBaseBuilding * const exception) const;
710
 
        /// Prüft, ob auf angegebenen Punkt sich ein Späher von player befindet
711
 
        bool IsScoutingFigureOnNode(const MapCoord x, const MapCoord y, const unsigned player, const unsigned distance) const;
712
 
        /// Berechnet die Sichtbarkeit eines Punktes neu für den angegebenen Spieler
713
 
        /// exception ist ein Gebäude (Spähturm, Militärgebäude), was nicht mit in die Berechnugn einbezogen
714
 
        /// werden soll, z.b. weil es abgerissen wird
715
 
        void RecalcVisibility(const MapCoord x, const MapCoord y, const unsigned char player, const noBaseBuilding * const exception);
716
 
        /// Setzt Punkt auf jeden Fall auf sichtbar
717
 
        void SetVisibility(const MapCoord x, const MapCoord y,  const unsigned char player);
718
 
        
719
 
        /// Prüfen, ob zu einem bestimmten Küsenpunkt ein Hafenpunkt gehört und wenn ja, wird dieser zurückgegeben
720
 
        unsigned short GetHarborPosID(const MapCoord x, const MapCoord y);
721
 
        /// Bestimmt die Schifffahrtrichtung, in der ein Punkt relativ zu einem anderen liegt 
722
 
        unsigned char GetShipDir(Point<int> pos1, Point<int> pos2);
723
 
        
724
 
 
725
 
protected:
726
 
 
727
 
        /// Erzeugt FOW-Objekte, -Straßen und -Grensteine von aktuellen Punkt für einen bestimmten Spieler
728
 
        void SaveFOWNode(const MapCoord x, const MapCoord y, const unsigned player);
729
 
        /// Berechnet für alle Hafenpunkt jeweils die Richtung und Entfernung zu allen anderen Hafenpunkten
730
 
        /// über die Kartenränder hinweg
731
 
        void CalcHarborPosNeighbors();
732
 
        /// Create Trade graphs
733
 
        void CreateTradeGraphs();
734
 
 
735
 
public:
736
 
 
737
 
        virtual ~GameWorldGame();
738
 
 
739
 
        /// Stellt anderen Spielern/Spielobjekten das Game-GUI-Interface zur Verfüung
740
 
        inline GameInterface * GetGameInterface() const { return gi; }
741
 
 
742
 
        inline void SetNO(noBase * obj, const MapCoord x, const MapCoord y) { GetNode(x,y).obj = obj; }
743
 
        void AddFigure(noBase * fig,const MapCoord x, const MapCoord y);
744
 
        void RemoveFigure(const noBase * fig,const MapCoord x, const MapCoord y);
745
 
 
746
 
        /// Berechnet Bauqualitäten an Punkt x;y und den ersten Kreis darum neu
747
 
        void RecalcBQAroundPoint(const MapCoord x, const MapCoord y);
748
 
        /// Berechnet Bauqualitäten wie bei letzterer Funktion, bloß noch den 2. Kreis um x;y herum
749
 
        void RecalcBQAroundPointBig(const MapCoord x, const MapCoord y);
750
 
 
751
 
        /// Prüft, ob dieser Punkt von Menschen betreten werden kann
752
 
        bool IsNodeForFigures(const MapCoord x, const MapCoord y) const;
753
 
        /// Kann dieser Punkt von auf Straßen laufenden Menschen betreten werden? (Kämpfe!)
754
 
        bool IsRoadNodeForFigures(const MapCoord x, const MapCoord y,const unsigned char dir);
755
 
        /// Lässt alle Figuren, die auf diesen Punkt  auf Wegen zulaufen, anhalten auf dem Weg (wegen einem Kampf)
756
 
        void StopOnRoads(const MapCoord x, const MapCoord y, const unsigned char dir = 0xff);
757
 
 
758
 
        /// Sagt Bescheid, dass der Punkt wieder freigeworden ist und lässt ggf. Figuren drumherum wieder weiterlaufen
759
 
        void RoadNodeAvailable(const MapCoord x, const MapCoord y);
760
 
 
761
 
        /// Flagge an x,y setzen, dis_dir ist der aus welche Richtung der Weg kommt, wenn man einen Weg mit Flagge baut
762
 
        /// kann ansonsten auf 255 gesetzt werden
763
 
        void SetFlag(const MapCoord x, const MapCoord y, const unsigned char player,const unsigned char dis_dir = 255);
764
 
        /// Flagge soll zerstrört werden
765
 
        void DestroyFlag(const MapCoord x, const MapCoord y);
766
 
        /// Baustelle setzen
767
 
        void SetBuildingSite(const BuildingType type,const MapCoord x, const MapCoord y, const unsigned char player);
768
 
        /// Gebäude bzw Baustelle abreißen
769
 
        void DestroyBuilding(const MapCoord x, const MapCoord y, const unsigned char playe);
770
 
 
771
 
        /// Wegfindung für Menschen im Straßennetz
772
 
        unsigned char FindHumanPathOnRoads(const noRoadNode * const start, const noRoadNode * const goal,unsigned * length = NULL, Point<MapCoord> * next_harbor = NULL, const RoadSegment * const forbidden = NULL);
773
 
        /// Wegfindung für Waren im Straßennetz
774
 
        unsigned char FindPathForWareOnRoads(const noRoadNode * const start, const noRoadNode * const goal,unsigned * length = NULL, Point<MapCoord> * next_harbor = NULL, unsigned max = 0xFFFFFFFF);
775
 
        /// Prüft, ob eine Schiffsroute noch Gültigkeit hat
776
 
        bool CheckShipRoute(const MapCoord x_start,const MapCoord y_start, const std::vector<unsigned char>& route, const unsigned pos, 
777
 
                 MapCoord* x_dest,  MapCoord* y_dest);
778
 
        /// Find a route for trade caravanes
779
 
        unsigned char FindTradePath(const Point<MapCoord> start,
780
 
                const Point<MapCoord> dest, const unsigned char player, const unsigned max_route = 0xffffffff, const bool random_route = false,
781
 
                 std::vector<unsigned char> * route = NULL, unsigned *length = NULL, 
782
 
                const bool record = false) const;
783
 
        /// Check whether trade path is still valid
784
 
        bool CheckTradeRoute(const Point<MapCoord> start, const std::vector<unsigned char>& route, const unsigned pos, const unsigned char player,
785
 
                 Point<MapCoord> * dest = NULL) const;
786
 
 
787
 
 
788
 
        /// setzt den Straßen-Wert an der Stelle X,Y (berichtigt).
789
 
        void SetRoad(const MapCoord x, const MapCoord y, unsigned char dir, unsigned char type);
790
 
 
791
 
        /// setzt den Straßen-Wert um den Punkt X,Y.
792
 
        void SetPointRoad(const MapCoord x, const MapCoord y, unsigned char dir, unsigned char type);
793
 
 
794
 
        /// Funktionen aus ehemaligen Game
795
 
        /// Baut eine Straße ( nicht nur visuell, sondern auch wirklich )
796
 
        void BuildRoad(const unsigned char playerid,const bool boat_road,
797
 
                unsigned short start_x,unsigned short start_y, const std::vector<unsigned char>& route);
798
 
        /// Reißt eine Straße ab
799
 
        void DestroyRoad(const MapCoord x, const MapCoord y, const unsigned char dir);
800
 
        /// baut eine Straße aus
801
 
        void UpgradeRoad(const MapCoord x, const MapCoord y, const unsigned char dir);
802
 
 
803
 
        /// Berechnet das Land in einem bestimmten Bereich (um ein neues, abgerissenes oder eingenommenes
804
 
        /// Militärgebäude rum) neu, destroyed gibt an, ob building abgerissen wurde und somit nicht einberechnet werden soll
805
 
        void RecalcTerritory(const noBaseBuilding * const building,const unsigned short radius, const bool destroyed, const bool newBuilt);
806
 
        /// Berechnet das Land in einem bestimmten Bereich um ein aktuelles Militärgebäude rum neu und gibt zurück ob sich etwas verändern würde (auf für ki wichtigem untergrund) wenn das Gebäude zerstört werden würde
807
 
        bool TerritoryChange(const noBaseBuilding * const building,const unsigned short radius, const bool destroyed, const bool newBuilt);
808
 
        /// Greift ein Militärgebäude auf x,y an (entsendet dafür die Soldaten etc.)
809
 
        void Attack(const unsigned char player_attacker, const MapCoord x, const MapCoord y, const unsigned short soldiers_count, const bool strong_soldiers);
810
 
        /// Greift ein Militäregebäude mit Schiffen an 
811
 
        void AttackViaSea(const unsigned char player_attacker, const MapCoord x, const MapCoord y, const unsigned short soldiers_count, const bool strong_soldiers);
812
 
        // Liefert das entsprechende Militärquadrat für einen bestimmten Punkt auf der Karte zurück (normale Koordinaten)
813
 
        list<nobBaseMilitary*>& GetMilitarySquare(const MapCoord x, const MapCoord y)
814
 
        { return military_squares[(y/MILITARY_SQUARE_SIZE)*(width/MILITARY_SQUARE_SIZE+1)+x/MILITARY_SQUARE_SIZE]; }
815
 
 
816
 
        /// Fügt einen Katapultstein der Welt hinzu, der gezeichnt werden will
817
 
        inline void AddCatapultStone(CatapultStone * cs) {catapult_stones.push_back(cs); }
818
 
        inline void RemoveCatapultStone(CatapultStone * cs) {catapult_stones.remove(cs); }
819
 
 
820
 
        /// Lässt alles spielerische abbrennen, indem es alle Flaggen der Spieler zerstört
821
 
        void Armageddon();
822
 
 
823
 
  /// Lässt alles spielerische eines Spielers abbrennen, indem es alle Flaggen eines Spieler zerstört
824
 
        void Armageddon(const unsigned char player);
825
 
 
826
 
        /// Sagt der GW Bescheid, dass ein Objekt von Bedeutung an x,y vernichtet wurde, damit dieser
827
 
        /// dass ggf. an den WindowManager weiterleiten kann, damit auch ein Fenster wieder geschlossen wird
828
 
        virtual void ImportantObjectDestroyed(const MapCoord x, const MapCoord y) = 0;
829
 
        /// Sagt, dass ein Militärgebäude eingenommen wurde und ggf. ein entsprechender "Fanfarensound" abgespielt werden sollte
830
 
        virtual void MilitaryBuildingCaptured(const MapCoord x, const MapCoord y, const unsigned char player) = 0;
831
 
 
832
 
        /// Ist der Punkt ein geeigneter Platz zum Warten vor dem Militärgebäude
833
 
        bool ValidWaitingAroundBuildingPoint(const MapCoord x, const MapCoord y, nofAttacker * attacker, const MapCoord goal_x, const MapCoord goal_y);
834
 
        /// Geeigneter Punkt für Kämpfe?
835
 
        bool ValidPointForFighting(const MapCoord x, const MapCoord y, const bool avoid_military_building_flags, nofActiveSoldier *exception = NULL);
836
 
 
837
 
        /// Berechnet die Sichtbarkeiten neu um einen Punkt mit radius
838
 
        void RecalcVisibilitiesAroundPoint(const MapCoord x, const MapCoord y, const MapCoord radius, const unsigned char player, const noBaseBuilding * const exception);
839
 
        /// Setzt die Sichtbarkeiten um einen Punkt auf sichtbar (aus Performancegründen Alternative zu oberem)
840
 
        void SetVisibilitiesAroundPoint(const MapCoord x, const MapCoord y, const MapCoord radius, const unsigned char player);
841
 
        /// Berechet die ganzen Sichtbarkeiten der Karte neu
842
 
        void RecalcAllVisibilities();
843
 
        /// Bestimmt bei der Bewegung eines spähenden Objekts die Sichtbarkeiten an
844
 
        /// den Rändern neu
845
 
        void RecalcMovingVisibilities(const MapCoord x, const MapCoord y, const unsigned char player, const MapCoord radius, 
846
 
                const unsigned char moving_dir, Point<MapCoord> * enemy_territory);
847
 
 
848
 
        /// Stellt fest, ob auf diesem Punkt ein Grenzstein steht (ob das Grenzgebiet ist)
849
 
        bool IsBorderNode(const MapCoord x, const MapCoord y, const unsigned char player) const;
850
 
        
851
 
        // Konvertiert Ressourcen zwischen Typen hin und her oder löscht sie.
852
 
        // Für Spiele ohne Gold.
853
 
        void ConvertMineResourceTypes(unsigned char from, unsigned char to);
854
 
 
855
 
        /// Gründet vom Schiff aus eine neue Kolonie, gibt true zurück bei Erfolg
856
 
        bool FoundColony(const unsigned harbor_point, const unsigned char player, const unsigned short sea_id);
857
 
        /// Registriert eine Baustelle eines Hafens, die vom Schiff aus gesetzt worden ist
858
 
        void AddHarborBuildingSiteFromSea(noBuildingSite * building_site)
859
 
        { this->harbor_building_sites_from_sea.push_back(building_site); }
860
 
        /// Entfernt diese wieder
861
 
        void RemoveHarborBuildingSiteFromSea(noBuildingSite * building_site)
862
 
        { this->harbor_building_sites_from_sea.remove(building_site); }
863
 
        /// Gibt zurück, ob eine bestimmte Baustellen eine Baustelle ist, die vom Schiff aus errichtet wurde
864
 
        bool IsHarborBuildingSiteFromSea(const noBuildingSite * building_site) const;
865
 
        /// Liefert eine Liste der Hafenpunkte, die von einem bestimmten Hafenpunkt erreichbar sind
866
 
        void GetHarborPointsWithinReach(const unsigned hp,std::vector<unsigned>& hps) const;
867
 
 
868
 
        /// Creates a Trade Route from one point to another
869
 
        void CreateTradeRoute(const Point<MapCoord> start, Point<MapCoord> dest,const unsigned char player,TradeRoute ** tr);
870
 
        /// Retrieves a trade graph
871
 
        TradeGraph * GetTradeGraph(const unsigned char player) const { return tgs[player]; }
 
690
    protected:
 
691
        /// rade graphs, one for each player
 
692
        std::vector<TradeGraph*> tgs;
 
693
    private:
 
694
 
 
695
 
 
696
 
 
697
        /// vergleicht 2 Punkte, ob sie von unterschiedlichen Spielern sind und setzt
 
698
        /// Punkt ggf. zu gar keinem Spieler, 2. Funktion wird für Punkte im 2er Abstand verwendet, da es dort ein bisschen anders läuft!
 
699
        void AdjustNodes(const MapCoord x1, const MapCoord y1, const MapCoord x2, const MapCoord y2);
 
700
        void AdjustNodes2(const MapCoord x1, const MapCoord y1, const MapCoord x2, const MapCoord y2);
 
701
        /// Zerstört Spielerteile auf einem Punkt, wenn der Punkt dem Spieler nun nich mehr gehört
 
702
        void DestroyPlayerRests(const MapCoord x, const MapCoord y, const unsigned char new_player, const noBaseBuilding* exception);
 
703
 
 
704
        /// Prüft, ob auf diesem Punkt Deko-Objekte liegen, die für den Wegbau entfernt werden können
 
705
        bool IsObjectionableForRoad(const MapCoord x, const MapCoord y);
 
706
 
 
707
 
 
708
        /// Punkt vollständig sichtbar?
 
709
        bool IsPointCompletelyVisible(const MapCoord x, const MapCoord y, const unsigned char player, const noBaseBuilding* const exception) const;
 
710
        /// Prüft, ob auf angegebenen Punkt sich ein Späher von player befindet
 
711
        bool IsScoutingFigureOnNode(const MapCoord x, const MapCoord y, const unsigned player, const unsigned distance) const;
 
712
        /// Berechnet die Sichtbarkeit eines Punktes neu für den angegebenen Spieler
 
713
        /// exception ist ein Gebäude (Spähturm, Militärgebäude), was nicht mit in die Berechnugn einbezogen
 
714
        /// werden soll, z.b. weil es abgerissen wird
 
715
        void RecalcVisibility(const MapCoord x, const MapCoord y, const unsigned char player, const noBaseBuilding* const exception);
 
716
        /// Setzt Punkt auf jeden Fall auf sichtbar
 
717
        void SetVisibility(const MapCoord x, const MapCoord y,  const unsigned char player);
 
718
 
 
719
        /// Prüfen, ob zu einem bestimmten Küsenpunkt ein Hafenpunkt gehört und wenn ja, wird dieser zurückgegeben
 
720
        unsigned short GetHarborPosID(const MapCoord x, const MapCoord y);
 
721
        /// Bestimmt die Schifffahrtrichtung, in der ein Punkt relativ zu einem anderen liegt
 
722
        unsigned char GetShipDir(Point<int> pos1, Point<int> pos2);
 
723
 
 
724
 
 
725
    protected:
 
726
 
 
727
        /// Erzeugt FOW-Objekte, -Straßen und -Grensteine von aktuellen Punkt für einen bestimmten Spieler
 
728
        void SaveFOWNode(const MapCoord x, const MapCoord y, const unsigned player);
 
729
        /// Berechnet für alle Hafenpunkt jeweils die Richtung und Entfernung zu allen anderen Hafenpunkten
 
730
        /// über die Kartenränder hinweg
 
731
        void CalcHarborPosNeighbors();
 
732
        /// Create Trade graphs
 
733
        void CreateTradeGraphs();
 
734
 
 
735
    public:
 
736
 
 
737
        virtual ~GameWorldGame();
 
738
 
 
739
        /// Stellt anderen Spielern/Spielobjekten das Game-GUI-Interface zur Verfüung
 
740
        inline GameInterface* GetGameInterface() const { return gi; }
 
741
 
 
742
        inline void SetNO(noBase* obj, const MapCoord x, const MapCoord y) { GetNode(x, y).obj = obj; }
 
743
        void AddFigure(noBase* fig, const MapCoord x, const MapCoord y);
 
744
        void RemoveFigure(const noBase* fig, const MapCoord x, const MapCoord y);
 
745
 
 
746
        /// Berechnet Bauqualitäten an Punkt x;y und den ersten Kreis darum neu
 
747
        void RecalcBQAroundPoint(const MapCoord x, const MapCoord y);
 
748
        /// Berechnet Bauqualitäten wie bei letzterer Funktion, bloß noch den 2. Kreis um x;y herum
 
749
        void RecalcBQAroundPointBig(const MapCoord x, const MapCoord y);
 
750
 
 
751
        /// Prüft, ob dieser Punkt von Menschen betreten werden kann
 
752
        bool IsNodeForFigures(const MapCoord x, const MapCoord y) const;
 
753
        /// Kann dieser Punkt von auf Straßen laufenden Menschen betreten werden? (Kämpfe!)
 
754
        bool IsRoadNodeForFigures(const MapCoord x, const MapCoord y, const unsigned char dir);
 
755
        /// Lässt alle Figuren, die auf diesen Punkt  auf Wegen zulaufen, anhalten auf dem Weg (wegen einem Kampf)
 
756
        void StopOnRoads(const MapCoord x, const MapCoord y, const unsigned char dir = 0xff);
 
757
 
 
758
        /// Sagt Bescheid, dass der Punkt wieder freigeworden ist und lässt ggf. Figuren drumherum wieder weiterlaufen
 
759
        void RoadNodeAvailable(const MapCoord x, const MapCoord y);
 
760
 
 
761
        /// Flagge an x,y setzen, dis_dir ist der aus welche Richtung der Weg kommt, wenn man einen Weg mit Flagge baut
 
762
        /// kann ansonsten auf 255 gesetzt werden
 
763
        void SetFlag(const MapCoord x, const MapCoord y, const unsigned char player, const unsigned char dis_dir = 255);
 
764
        /// Flagge soll zerstrört werden
 
765
        void DestroyFlag(const MapCoord x, const MapCoord y);
 
766
        /// Baustelle setzen
 
767
        void SetBuildingSite(const BuildingType type, const MapCoord x, const MapCoord y, const unsigned char player);
 
768
        /// Gebäude bzw Baustelle abreißen
 
769
        void DestroyBuilding(const MapCoord x, const MapCoord y, const unsigned char playe);
 
770
 
 
771
        /// Wegfindung für Menschen im Straßennetz
 
772
        unsigned char FindHumanPathOnRoads(const noRoadNode* const start, const noRoadNode* const goal, unsigned* length = NULL, Point<MapCoord> * next_harbor = NULL, const RoadSegment* const forbidden = NULL);
 
773
        /// Wegfindung für Waren im Straßennetz
 
774
        unsigned char FindPathForWareOnRoads(const noRoadNode* const start, const noRoadNode* const goal, unsigned* length = NULL, Point<MapCoord> * next_harbor = NULL, unsigned max = 0xFFFFFFFF);
 
775
        /// Prüft, ob eine Schiffsroute noch Gültigkeit hat
 
776
        bool CheckShipRoute(const MapCoord x_start, const MapCoord y_start, const std::vector<unsigned char>& route, const unsigned pos,
 
777
                            MapCoord* x_dest,  MapCoord* y_dest);
 
778
        /// Find a route for trade caravanes
 
779
        unsigned char FindTradePath(const Point<MapCoord> start,
 
780
                                    const Point<MapCoord> dest, const unsigned char player, const unsigned max_route = 0xffffffff, const bool random_route = false,
 
781
                                    std::vector<unsigned char> * route = NULL, unsigned* length = NULL,
 
782
                                    const bool record = false) const;
 
783
        /// Check whether trade path is still valid
 
784
        bool CheckTradeRoute(const Point<MapCoord> start, const std::vector<unsigned char>& route, const unsigned pos, const unsigned char player,
 
785
                             Point<MapCoord> * dest = NULL) const;
 
786
 
 
787
 
 
788
        /// setzt den Straßen-Wert an der Stelle X,Y (berichtigt).
 
789
        void SetRoad(const MapCoord x, const MapCoord y, unsigned char dir, unsigned char type);
 
790
 
 
791
        /// setzt den Straßen-Wert um den Punkt X,Y.
 
792
        void SetPointRoad(const MapCoord x, const MapCoord y, unsigned char dir, unsigned char type);
 
793
 
 
794
        /// Funktionen aus ehemaligen Game
 
795
        /// Baut eine Straße ( nicht nur visuell, sondern auch wirklich )
 
796
        void BuildRoad(const unsigned char playerid, const bool boat_road,
 
797
                       unsigned short start_x, unsigned short start_y, const std::vector<unsigned char>& route);
 
798
        /// Reißt eine Straße ab
 
799
        void DestroyRoad(const MapCoord x, const MapCoord y, const unsigned char dir);
 
800
        /// baut eine Straße aus
 
801
        void UpgradeRoad(const MapCoord x, const MapCoord y, const unsigned char dir);
 
802
 
 
803
        /// Berechnet das Land in einem bestimmten Bereich (um ein neues, abgerissenes oder eingenommenes
 
804
        /// Militärgebäude rum) neu, destroyed gibt an, ob building abgerissen wurde und somit nicht einberechnet werden soll
 
805
        void RecalcTerritory(const noBaseBuilding* const building, const unsigned short radius, const bool destroyed, const bool newBuilt);
 
806
        /// Berechnet das Land in einem bestimmten Bereich um ein aktuelles Militärgebäude rum neu und gibt zurück ob sich etwas verändern würde (auf für ki wichtigem untergrund) wenn das Gebäude zerstört werden würde
 
807
        bool TerritoryChange(const noBaseBuilding* const building, const unsigned short radius, const bool destroyed, const bool newBuilt);
 
808
        /// Greift ein Militärgebäude auf x,y an (entsendet dafür die Soldaten etc.)
 
809
        void Attack(const unsigned char player_attacker, const MapCoord x, const MapCoord y, const unsigned short soldiers_count, const bool strong_soldiers);
 
810
        /// Greift ein Militäregebäude mit Schiffen an
 
811
        void AttackViaSea(const unsigned char player_attacker, const MapCoord x, const MapCoord y, const unsigned short soldiers_count, const bool strong_soldiers);
 
812
        // Liefert das entsprechende Militärquadrat für einen bestimmten Punkt auf der Karte zurück (normale Koordinaten)
 
813
        list<nobBaseMilitary*>& GetMilitarySquare(const MapCoord x, const MapCoord y)
 
814
        { return military_squares[(y / MILITARY_SQUARE_SIZE) * (width / MILITARY_SQUARE_SIZE + 1) + x / MILITARY_SQUARE_SIZE]; }
 
815
 
 
816
        /// Fügt einen Katapultstein der Welt hinzu, der gezeichnt werden will
 
817
        inline void AddCatapultStone(CatapultStone* cs) {catapult_stones.push_back(cs); }
 
818
        inline void RemoveCatapultStone(CatapultStone* cs) {catapult_stones.remove(cs); }
 
819
 
 
820
        /// Lässt alles spielerische abbrennen, indem es alle Flaggen der Spieler zerstört
 
821
        void Armageddon();
 
822
 
 
823
        /// Lässt alles spielerische eines Spielers abbrennen, indem es alle Flaggen eines Spieler zerstört
 
824
        void Armageddon(const unsigned char player);
 
825
 
 
826
        /// Sagt der GW Bescheid, dass ein Objekt von Bedeutung an x,y vernichtet wurde, damit dieser
 
827
        /// dass ggf. an den WindowManager weiterleiten kann, damit auch ein Fenster wieder geschlossen wird
 
828
        virtual void ImportantObjectDestroyed(const MapCoord x, const MapCoord y) = 0;
 
829
        /// Sagt, dass ein Militärgebäude eingenommen wurde und ggf. ein entsprechender "Fanfarensound" abgespielt werden sollte
 
830
        virtual void MilitaryBuildingCaptured(const MapCoord x, const MapCoord y, const unsigned char player) = 0;
 
831
 
 
832
        /// Ist der Punkt ein geeigneter Platz zum Warten vor dem Militärgebäude
 
833
        bool ValidWaitingAroundBuildingPoint(const MapCoord x, const MapCoord y, nofAttacker* attacker, const MapCoord goal_x, const MapCoord goal_y);
 
834
        /// Geeigneter Punkt für Kämpfe?
 
835
        bool ValidPointForFighting(const MapCoord x, const MapCoord y, const bool avoid_military_building_flags, nofActiveSoldier* exception = NULL);
 
836
 
 
837
        /// Berechnet die Sichtbarkeiten neu um einen Punkt mit radius
 
838
        void RecalcVisibilitiesAroundPoint(const MapCoord x, const MapCoord y, const MapCoord radius, const unsigned char player, const noBaseBuilding* const exception);
 
839
        /// Setzt die Sichtbarkeiten um einen Punkt auf sichtbar (aus Performancegründen Alternative zu oberem)
 
840
        void SetVisibilitiesAroundPoint(const MapCoord x, const MapCoord y, const MapCoord radius, const unsigned char player);
 
841
        /// Berechet die ganzen Sichtbarkeiten der Karte neu
 
842
        void RecalcAllVisibilities();
 
843
        /// Bestimmt bei der Bewegung eines spähenden Objekts die Sichtbarkeiten an
 
844
        /// den Rändern neu
 
845
        void RecalcMovingVisibilities(const MapCoord x, const MapCoord y, const unsigned char player, const MapCoord radius,
 
846
                                      const unsigned char moving_dir, Point<MapCoord> * enemy_territory);
 
847
 
 
848
        /// Stellt fest, ob auf diesem Punkt ein Grenzstein steht (ob das Grenzgebiet ist)
 
849
        bool IsBorderNode(const MapCoord x, const MapCoord y, const unsigned char player) const;
 
850
 
 
851
        // Konvertiert Ressourcen zwischen Typen hin und her oder löscht sie.
 
852
        // Für Spiele ohne Gold.
 
853
        void ConvertMineResourceTypes(unsigned char from, unsigned char to);
 
854
 
 
855
        /// Gründet vom Schiff aus eine neue Kolonie, gibt true zurück bei Erfolg
 
856
        bool FoundColony(const unsigned harbor_point, const unsigned char player, const unsigned short sea_id);
 
857
        /// Registriert eine Baustelle eines Hafens, die vom Schiff aus gesetzt worden ist
 
858
        void AddHarborBuildingSiteFromSea(noBuildingSite* building_site)
 
859
        { this->harbor_building_sites_from_sea.push_back(building_site); }
 
860
        /// Entfernt diese wieder
 
861
        void RemoveHarborBuildingSiteFromSea(noBuildingSite* building_site)
 
862
        { this->harbor_building_sites_from_sea.remove(building_site); }
 
863
        /// Gibt zurück, ob eine bestimmte Baustellen eine Baustelle ist, die vom Schiff aus errichtet wurde
 
864
        bool IsHarborBuildingSiteFromSea(const noBuildingSite* building_site) const;
 
865
        /// Liefert eine Liste der Hafenpunkte, die von einem bestimmten Hafenpunkt erreichbar sind
 
866
        void GetHarborPointsWithinReach(const unsigned hp, std::vector<unsigned>& hps) const;
 
867
 
 
868
        /// Creates a Trade Route from one point to another
 
869
        void CreateTradeRoute(const Point<MapCoord> start, Point<MapCoord> dest, const unsigned char player, TradeRoute** tr);
 
870
        /// Retrieves a trade graph
 
871
        TradeGraph* GetTradeGraph(const unsigned char player) const { return tgs[player]; }
872
872
};
873
873
 
874
874
 
875
875
class GameWorld : public GameWorldViewer, public GameWorldGame
876
876
{
877
 
public:
878
 
 
879
 
        /// Lädt eine Karte
880
 
        bool LoadMap(const std::string& filename);
881
 
 
882
 
        /// Serialisiert den gesamten GameWorld
883
 
        void Serialize(SerializedGameData *sgd) const;
884
 
        void Deserialize(SerializedGameData *sgd);
885
 
 
886
 
        /// Sagt der GW Bescheid, dass ein Objekt von Bedeutung an x,y vernichtet wurde, damit dieser
887
 
        /// dass ggf. an den WindowManager weiterleiten kann, damit auch ein Fenster wieder geschlossen wird
888
 
        void ImportantObjectDestroyed(const MapCoord x, const MapCoord y);
889
 
        /// Sagt, dass ein Militärgebäude eingenommen wurde und ggf. ein entsprechender "Fanfarensound" abgespielt werden sollte
890
 
        void MilitaryBuildingCaptured(const MapCoord x, const MapCoord y, const unsigned char player);
891
 
 
892
 
private:
893
 
        /// Vermisst ein neues Weltmeer von einem Punkt aus, indem es alle mit diesem Punkt verbundenen
894
 
        /// Wasserpunkte mit der gleichen sea_id belegt und die Anzahl zurückgibt
895
 
        unsigned MeasureSea(const MapCoord x, const MapCoord y, const unsigned short sea_id);
896
 
 
897
 
        /// Erstellt Objekte anhand der ausgelesenen S2map
898
 
        void Scan(glArchivItem_Map *map);
899
 
 
900
 
        /// random function using RANDOM.Rand(...) for std::random_shuffle
901
 
        static ptrdiff_t myRandom(ptrdiff_t max);
 
877
    public:
 
878
 
 
879
        /// Lädt eine Karte
 
880
        bool LoadMap(const std::string& filename);
 
881
 
 
882
        /// Serialisiert den gesamten GameWorld
 
883
        void Serialize(SerializedGameData* sgd) const;
 
884
        void Deserialize(SerializedGameData* sgd);
 
885
 
 
886
        /// Sagt der GW Bescheid, dass ein Objekt von Bedeutung an x,y vernichtet wurde, damit dieser
 
887
        /// dass ggf. an den WindowManager weiterleiten kann, damit auch ein Fenster wieder geschlossen wird
 
888
        void ImportantObjectDestroyed(const MapCoord x, const MapCoord y);
 
889
        /// Sagt, dass ein Militärgebäude eingenommen wurde und ggf. ein entsprechender "Fanfarensound" abgespielt werden sollte
 
890
        void MilitaryBuildingCaptured(const MapCoord x, const MapCoord y, const unsigned char player);
 
891
 
 
892
    private:
 
893
        /// Vermisst ein neues Weltmeer von einem Punkt aus, indem es alle mit diesem Punkt verbundenen
 
894
        /// Wasserpunkte mit der gleichen sea_id belegt und die Anzahl zurückgibt
 
895
        unsigned MeasureSea(const MapCoord x, const MapCoord y, const unsigned short sea_id);
 
896
 
 
897
        /// Erstellt Objekte anhand der ausgelesenen S2map
 
898
        void Scan(glArchivItem_Map* map);
 
899
 
 
900
        /// random function using RANDOM.Rand(...) for std::random_shuffle
 
901
        static ptrdiff_t myRandom(ptrdiff_t max);
902
902
};
903
903
 
904
904