forked from Atlantis-PBEM/Atlantis
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patharegion.h
504 lines (397 loc) · 12.7 KB
/
aregion.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
#ifndef REGION_CLASS
#define REGION_CLASS
// START A3HEADER
//
// This source file is part of the Atlantis PBM game program.
// Copyright (C) 1995-1999 Geoff Dunbar
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program, in the file license.txt. If not, write
// to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
//
// See the Atlantis Project web page for details:
// http://www.prankster.com/project
//
// END A3HEADER
#include "production.h"
#include "market.h"
#include "gamedefs.h"
#include "alist.h"
#include <functional>
class Areport;
class Faction;
class JsonReport;
class Object;
class Unit;
class UnitId;
// defined locally
class ARegion;
class ARegionList;
class ARegionArray;
//----------------------------------------------------------------------------
/// Weather Types
enum
{
W_NORMAL,
W_WINTER,
W_MONSOON,
W_BLIZZARD,
W_MAX
};
///@return text representation of weather
const char* weatherString(int w);
//----------------------------------------------------------------------------
/// Raw materials produced in a region
struct Product
{
int product;
int chance;
int amount;
Product(int p, int c, int a);
Product(const char *item, int c, int a);
};
//----------------------------------------------------------------------------
/// Terrain in a region
class TerrainType
{
public:
TerrainType(const char *name, int similar_type, int flags, int pop,
int wages, int economy, int movepoints, const std::vector<Product> &prods,
const std::vector<const char*> &races, const std::vector<const char*> &coastal_races,
int wmonfreq, const char *smallmon, const char *bigmon,
const char *humanoid, int lairChance, const std::vector<int> &lairs);
public: // data
const char *name;
int similar_type;
enum
{
RIDINGMOUNTS = 0x1,
FLYINGMOUNTS = 0x2,
};
int flags;
int pop;
int wages;
int economy;
int movepoints;
std::vector<Product> prods;
// Race information
// A hex near water will have either one of the normal races or one
// of the coastal races in it. Non-coastal hexes will only have one
// of the normal races.
int races[4];
int coastal_races[3];
int wmonfreq;
int smallmon;
int bigmon;
int humanoid;
int lairChance;
int lairs[6];
};
extern TerrainType *TerrainDefs;
//----------------------------------------------------------------------------
class Location : public AListElem
{
public:
Unit *unit;
Object *obj;
ARegion *region;
};
///@return the location in 'location_list' containing 'unit_num' or NULL
Location* GetUnit(AList *location_list, int unit_num);
//----------------------------------------------------------------------------
class ARegionPtr : public AListElem
{
public:
ARegionPtr(ARegion *p = NULL)
: ptr(p)
{
}
ARegion *ptr;
};
///@return region_num in region_list, or NULL
ARegionPtr* GetRegion(AList *region_list, int region_num);
//----------------------------------------------------------------------------
class Farsight : public AListElem
{
public:
Farsight();
Faction *faction;
Unit *unit;
int level;
int exits_used[NDIRS];
};
///@return the farsight report for 'fac', or NULL
Farsight* GetFarsight(AList *farsight_list, Faction *fac);
//----------------------------------------------------------------------------
enum
{
TOWN_VILLAGE,
TOWN_TOWN,
TOWN_CITY,
NTOWNS
};
class TownInfo
{
public:
TownInfo();
~TownInfo();
void Readin(Ainfile *f, ATL_VER &v);
void Writeout(Aoutfile *f) const;
int TownType() const;
AString *name;
int pop;
int basepop;
int activity;
};
//----------------------------------------------------------------------------
class ARegion : public AListElem
{
friend class Game;
friend class ARegionArray;
public:
/// constructor
ARegion();
/// destructor
~ARegion();
void Setup(ARegionArray *pArr);
void Writeout(Aoutfile *f);
void Readin(Ainfile *f, AList *facs, ATL_VER v);
void WriteReport(JsonReport &of, Faction *fac, int month, ARegionList *pRegions);
void WriteTemplate(Areport *f, Faction *fac, ARegionList *pRegs, int month);
// defined in template.cpp
void WriteTemplateHeader(Areport *f, Faction *fac, ARegionList *pRegs, int month);
void GetMapLine(char *buffer, int line, ARegionList *pRegs);
AString ShortPrint(ARegionList *pRegs);
AString Print(ARegionList *pRegs);
void CPrint(JsonReport *f, ARegionList *pRegs, bool inc_town = true);
/// change the name of the region
void SetName(const char *new_name);
///@return 1 if 'fac' can make 'item'
int CanMakeAdv(Faction *fac, int item);
///@return 1 if a unit from 'fac' has 'item' in this
int HasItem(Faction *fac, int item);
/// take the items from 'u' and give them to a friend, then move 'u' to "Hell"
void Kill(Unit *u);
/// delete all the units that have died
void ClearHell();
///@return unit matching 'num', or NULL
Unit* GetUnit(int num);
///@return unit matching 'alias' for 'faction', or NULL
Unit* GetUnitAlias(int alias, int faction);
///@return unit matching 'id' for 'faction'
Unit* GetUnitId(const UnitId *id, int faction);
///@return new Location wrapping id, faction, this
Location* GetLocation(UnitId *id, int faction);
///@return 1 if a unit from 'f' is in this, else 0
int Present(Faction *f);
///@return new list of FactionPtr containing all the factions represented here
AList* PresentFactions();
int GetObservation(Faction *f, int use_passers);
int GetTrueSight(Faction *f, int use_passers);
///@return object 'num', or NULL
Object* GetObject(int num);
///@return the object representing open space
Object* GetDummy();
///@param[out] road message which is updated for road usage
///@return the cost to move into this region 'from_region' along 'dir' via 'movetype'
int MoveCost(int movetype, ARegion *from_region, int dir, AString *road);
///@return unit that is forbidding 'u' from entering this
Unit* Forbidden(Unit *u);
///@return allied unit that is forbidding 'u' from entering this
Unit* ForbiddenByAlly(Unit *u);
///@return 1 if 'u' can tax here
int CanTax(Unit *u);
///@return 1 if 'u' can pillage here
int CanPillage(Unit *u);
///@return 1 if any unit in 'ship' is forbidden from entering here
Unit* ForbiddenShip(Object *ship);
///@return 1 if city guard present here
int HasCityGuard();
/// post a report to all the units here
void NotifySpell(Unit *caster, int spell, ARegionList *pRegs);
/// notify all units in city about city name change
void NotifyCity(Unit *namer, const AString &oldname, const AString &newname);
/// reset orders for all units here
void DefaultOrders();
void PostTurn(ARegionList *pRegs);
void UpdateProducts();
void SetWeather(int newWeather);
///@return 1 for ocean-like (not lake) or number of adjacent ocean-like
int IsCoastal();
int IsCoastalOrLakeside();
void MakeStartingCity();
int IsStartingCity();
int IsSafeRegion();
int CanBeStartingCity(ARegionArray *pRA);
// just used for mapping; just check if there is an inner region
int HasShaft();
///@return 1 if this region has a road in any direction, else 0
///@NOTE: the destination region must have a corresponding road to be useful
int HasRoad();
///@return 1 if this region has a road in the specified direction
int HasExitRoad(int realDirection);
int CountConnectingRoads();
int HasConnectingRoad(int realDirection);
///@return the road direction corresponding to 'realDirection'
int GetRoadDirection(int realDirection);
int GetRealDirComp(int realDirection) const;
void RunDecayEvent(Object *o, ARegionList *pRegs);
int PillageCheck() const;
int GetPoleDistance(int dir);
int CountWMons();
int IsGuarded();
int Wages();
AString WagesForReport();
int Population() const;
// used by ARegionArray
void ZeroNeighbors();
void SetLoc(int x, int y, int z);
// used in object decay
int GetMaxClicks() const;
/// apply 'f' to all units
void applyToUnits(const std::function<void(Unit*)> &f);
/// apply 'f' to all units, until reaching false
void continueUnits(const std::function<bool(Unit*)> &f);
private: // methods
void SetupPop();
void SetupProds();
int GetNearestProd(int item);
void SetupCityMarket();
void AddTown();
void MakeLair(int lair_type);
void LairCheck();
void WriteProducts(JsonReport &of, Faction *fac, int present);
void WriteMarkets(JsonReport &of, Faction *fac, int present);
void WriteEconomy(JsonReport &of, Faction *fac, int present);
void WriteExits(JsonReport &of, ARegionList *pRegs, bool *exits_seen) const;
AString GetDecayFlavor() const;
/// apply variable economy effects
void UpdateTown();
public: // data
AString *name;
int num;
int type;
int buildingseq;
int weather;
int gate;
TownInfo *town;
int race;
int population;
int basepopulation;
int wages;
int maxwages;
int money;
// Potential bonuses to economy
int clearskies;
int earthlore;
ARegion *neighbors[NDIRS];
AList objects;
AList hell; // Where dead units go
AList farsees;
// List of units which passed through the region
AList passers;
ProductionList products;
MarketList markets;
int xloc, yloc, zloc;
ARegionArray *parentRegionArray;
};
//----------------------------------------------------------------------------
class ARegionArray
{
public:
ARegionArray(int x, int y);
~ARegionArray();
void SetRegion(int x, int y, ARegion *r);
ARegion* GetRegion(int x, int y);
void SetName(const char *name);
public: // data
int x;
int y;
ARegion **regions;
AString *strName;
enum
{
LEVEL_NEXUS,
LEVEL_SURFACE,
LEVEL_UNDERWORLD,
LEVEL_UNDERDEEP,
};
int levelType;
};
//----------------------------------------------------------------------------
class ARegionList : public AList
{
public:
ARegionList();
~ARegionList();
void WriteRegions(Aoutfile *f);
int ReadRegions(Ainfile *f, AList *factions, ATL_VER v);
ARegion* GetRegion(int region_num);
ARegion* GetRegion(int x, int y, int z);
Location* FindUnit(int unit_num);
void ChangeStartingCity(ARegion *, int);
ARegion* GetStartingCity(ARegion *AC, int num, int level, int maxX, int maxY);
ARegion* FindGate(int gate_id);
int GetDistance(ARegion *one, ARegion *two);
int GetPlanarDistance(ARegion *one, ARegion *two, int penalty);
int GetWeather(ARegion *pReg, int month);
ARegionArray* GetRegionArray(int level);
public: // data
int numberofgates;
int numLevels;
ARegionArray **pRegionArrays;
public: // Public world creation stuff
void CreateLevels(int numLevels);
void CreateAbyssLevel(int level, const char *name);
void CreateNexusLevel(int level, int xSize, int ySize, const char *name);
void CreateSurfaceLevel(int level, int xSize, int ySize,
int percentOcean, int continentSize, const char *name);
void CreateIslandLevel(int level, int nPlayers, const char *name);
void CreateUnderworldLevel(int level, int xSize, int ySize, const char *name);
void CreateUnderdeepLevel(int level, int xSize, int ySize, const char *name);
void MakeShaftLinks(int levelFrom, int levelTo, int odds);
void SetACNeighbors(int levelSrc, int levelTo, int maxX, int maxY);
void InitSetupGates(int level);
void FinalSetupGates();
void CleanUpWater(ARegionArray *pRegs);
void RemoveCoastalLakes(ARegionArray *pRegs);
void SeverLandBridges(ARegionArray *pRegs);
void CalcDensities();
int GetLevelXScale(int level);
int GetLevelYScale(int level);
private: // Private world creation stuff
void MakeRegions(int level, int xSize, int ySize);
void SetupNeighbors(ARegionArray *pRegs);
void NeighSetup(ARegion *r, ARegionArray *ar);
void SetRegTypes(ARegionArray *pRegs, int newType);
void MakeLand(ARegionArray *pRegs, int percentOcean, int continentSize);
void MakeCentralLand(ARegionArray *pRegs);
void SetupAnchors(ARegionArray *pArr);
void GrowTerrain(ARegionArray *pArr, int growOcean);
void RandomTerrain(ARegionArray *pArr);
void MakeUWMaze(ARegionArray *pArr);
void MakeIslands(ARegionArray *pArr, int nPlayers);
void MakeOneIsland(ARegionArray *pRegs, int xx, int yy);
void AssignTypes(ARegionArray *pArr);
void FinalSetup(ARegionArray *pArr);
void MakeShaft(ARegion *reg, ARegionArray *pFrom, ARegionArray *pTo);
// Game-specific world stuff (see world.cpp)
int GetRegType(ARegion *pReg);
int CheckRegionExit(ARegion *pFrom, ARegion *pTo);
};
//----------------------------------------------------------------------------
///@return a random name (defined in specific world.cpp)
int AGetName(int town);
const char* AGetNameString(int name);
#endif