forked from nedbrek/Atlantis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.h
488 lines (425 loc) · 17.8 KB
/
game.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
#ifndef GAME_CLASS
#define GAME_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 "aregion.h"
#define CURRENT_ATL_VER MAKE_ATL_VER( 4, 2, 74 )
class Aorders;
class ExchangeOrder;
class Faction;
class GiveOrder;
class Order;
class OrdersCheck;
class ProduceOrder;
class WithdrawOrder;
/// All the state for running the game
class Game
{
public:
/// constructor
Game();
/// destructor
~Game();
// used in main
void ModifyTablesPerRuleset(); // enable/disable parts of the data tables
int NewGame(int seed);
int OpenGame();
int RunGame();
int EditGame(int *pSaveGame);
void DummyGame();
int DoOrdersCheck(const AString &strOrders, const AString &strCheck);
int SaveGame();
int WritePlayers();
int ViewMap(const AString &, const AString &);
void UnitFactionMap();
int GenRules(const AString &, const AString &, const AString &);
void ViewFactions(); // not used
///@return faction with id 'n'
Faction* getFaction(int n);
// Setup the array of units
void SetupUnitSeq();
void SetupUnitNums();
// Get a unit by its number
Unit* GetUnit(int num);
int currentMonth() const { return month; }
int currentYear() const { return year; }
int TurnNumber();
// Get average maintenance per man for use in economy
static
int GetAvgMaintPerMan();
// Faction limit functions
// Game specific and found in extra.cpp
// They may return -1 to indicate no limit
int AllowedMages(Faction *pFac);
int AllowedApprentices(Faction *pFact);
int AllowedTaxes(Faction *pFac);
int AllowedTrades(Faction *pFac);
ARegionList& getRegions() { return regions; }
const ARegionList& getRegions() const { return regions; }
private: // methods
// Game editing functions
ARegion* EditGameFindRegion();
void EditGameFindUnit();
void EditGameRegion(ARegion *pReg);
void EditGameUnit(Unit *pUnit);
void EditGameUnitItems(Unit *pUnit);
void EditGameUnitSkills(Unit *pUnit);
void EditGameUnitMove(Unit *pUnit);
void CreateOceanLairs();
void FixBoatNums(); // Fix broken boat numbers
void FixGateNums(); // Fix broken/missing gates
int ReadPlayers();
int ReadPlayersLine(AString *pToken, AString *pLine, Faction *pFac, int newPlayer);
// Handle special gm unit modification functions
Unit* ParseGMUnit(AString *tag, Faction *pFac);
// extra set up for faction. (in extra.cpp)
int SetupFaction(Faction *pFac);
// get a new unit, with its number assigned
Unit* GetNewUnit(Faction *fac, int an = 0);
void PreProcessTurn();
void ReadOrders();
void DefaultWorkOrder();
void RunOrders();
void ClearOrders(Faction *);
void MakeFactionReportLists();
void CountAllMages();
void CountAllApprentices();
void WriteReport();
void DeleteDeadFactions();
Faction* AddFaction(int setup);
// Standard creation functions
void CreateCityMons();
void CreateWMons();
void CreateLMons();
void CreateVMons();
// Game-specific creation functions (see world.cpp)
void CreateWorld();
void CreateNPCFactions();
void CreateCityMon(ARegion *pReg, int percent, int needmage);
int MakeWMon(ARegion *pReg);
void MakeLMon(Object *pObj);
void WriteSurfaceMap(Aoutfile *f, ARegionArray *pArr, int type);
void WriteUnderworldMap(Aoutfile *f, ARegionArray *pArr, int type);
char GetRChar(ARegion *r);
AString GetXtraMap(ARegion *, int);
// Functions to do upgrades to the ruleset -- should be in extras.cpp
int UpgradeMajorVersion(int savedVersion);
int UpgradeMinorVersion(int savedVersion);
int UpgradePatchLevel(int savedVersion);
// Functions to allow enabling/disabling parts of the data tables
void EnableSkill(int sk); // Enabled a disabled skill
void DisableSkill(int sk); // Prevents skill being studied or used
void ModifySkillDependancy(int sk, int i, int dep, int lev);
void ModifySkillFlags(int sk, int flags);
void ModifySkillCost(int sk, int cost);
void ModifySkillSpecial(int sk, int special);
void ModifySkillRange(int sk, int range);
void EnableItem(int it); // Enables a disabled item
void DisableItem(int it); // Prevents item being generated/produced
void ModifyItemFlags(int it, int flags);
void ModifyItemType(int it, int type);
void ModifyItemWeight(int it, int weight);
void ModifyItemBasePrice(int it, int price);
void ModifyItemCapacities(int it, int walk, int ride, int fly, int swim);
void ModifyItemProductionBooster(int it, int item, int bonus);
void ModifyItemHitch(int it, int i, int item, int capacity);
void ModifyItemProductionSkill(int it, int sk, int lev);
void ModifyItemProductionOutput(int it, int months, int count);
void ModifyItemProductionInput(int it, int i, int input, int amount);
void ModifyItemMagicSkill(int it, int sk, int lev);
void ModifyItemMagicOutput(int it, int count);
void ModifyItemMagicInput(int it, int i, int input, int amount);
void ModifyRaceSkillLevels(int race, int special, int def);
void ModifyRaceSkills(int race, int i, int sk);
void ModifyMonsterAttackLevel(int mon, int lev);
void ModifyMonsterDefense(int mon, int defenseType, int level);
void ModifyMonsterAttacksAndHits(int mon, int numattacks, int hits, int regen);
void ModifyMonsterSkills(int mon, int tact, int stealth, int obs);
void ModifyMonsterSpecial(int mon, int special, int lev);
void ModifyMonsterSpoils(int mon, int silver, int spoilType);
void ModifyMonsterThreat(int mon, int num, int hostileChance);
void ModifyWeaponSkills(int weap, int baseSkill, int orSkill);
void ModifyWeaponFlags(int weap, int flags);
void ModifyWeaponAttack(int weap, int wclass, int attackType, int numAtt);
void ModifyWeaponBonuses(int weap, int attack, int defense, int vsMount);
void ModifyArmorFlags(int armor, int flags);
void ModifyArmorSaveFrom(int armor, int from);
void ModifyArmorSaveValue(int armor, int wclass, int val);
void ModifyMountSkill(int mount, int skill);
void ModifyMountBonuses(int mount, int min, int max, int hampered);
void ModifyMountSpecial(int mount, int special, int level);
void EnableObject(int ob); // Enables a disabled object
void DisableObject(int ob); // Prevents object being built
void ModifyObjectFlags(int ob, int flags);
void ModifyObjectDecay(int ob, int maxMaint, int maxMonthDecay, int mFact);
void ModifyObjectProduction(int ob, int it);
void ModifyObjectMonster(int ob, int monster);
void ModifyObjectConstruction(int ob, int it, int num, int sk, int lev);
void ModifyObjectManpower(int ob, int prot, int cap, int sail, int mages);
void ClearTerrainRaces(int t);
void ModifyTerrainRace(int t, int i, int r);
void ModifyTerrainCoastRace(int t, int i, int r);
void ClearTerrainItems(int t);
void ModifyTerrainItems(int t, int i, int p, int c, int a);
void ModifyTerrainWMons(int t, int freq, int smon, int bigmon, int hum);
void ModifyTerrainLairChance(int t, int chance);
void ModifyTerrainLair(int t, int i, int lair);
void ModifyTerrainEconomy(int t, int pop, int wages, int econ, int move);
void ModifyBattleItemFlags(int item, int flags);
void ModifyBattleItemSpecial(int item, int special, int level);
void ModifySpecialTargetFlags(int special, int targetflags);
void ModifySpecialTargetObjects(int special, int index, int obj);
void ModifySpecialTargetItems(int special, int index, int item);
void ModifySpecialTargetEffects(int special, int index, int effect);
void ModifySpecialEffectFlags(int special, int effectflags);
void ModifySpecialShields(int special, int index, int type);
void ModifySpecialDefenseMods(int special, int index, int type, int val);
void ModifySpecialDamage(int special, int index, int type, int min,
int val, int flags, int cls, int effect);
void ModifyEffectFlags(int effect, int flags);
void ModifyEffectAttackMod(int effect, int val);
void ModifyEffectDefenseMod(int effect, int index, int type, int val);
void ModifyEffectCancelEffect(int effect, int uneffect);
void ModifyRangeFlags(int range, int flags);
void ModifyRangeClass(int range, int rclass);
void ModifyRangeMultiplier(int range, int mult);
void ModifyRangeLevelPenalty(int range, int pen);
// Parsing functions
void ParseError(OrdersCheck *pCheck, Unit *pUnit, Faction *pFac, const AString &strError);
int ParseDir(AString * token);
void ParseOrders(int faction, Aorders *ordersFile, OrdersCheck *pCheck);
Order* ProcessOrder(int orderNum, Unit *unit, AString *order, OrdersCheck *pCheck, int at_value);
void ProcessMoveOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessAdvanceOrder(Unit *,AString *, OrdersCheck *pCheck);
Unit *ProcessFormOrder(Unit *former, AString *order, OrdersCheck *pCheck);
void ProcessAddressOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessAvoidOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessGuardOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessNameOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessDescribeOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessBehindOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessGiveOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessWithdrawOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessDeclareOrder(Faction *,AString *, OrdersCheck *pCheck);
void ProcessStudyOrder(Unit *,AString *, OrdersCheck *pCheck);
Order* ProcessTeachOrder(Unit *,AString *, OrdersCheck *pCheck, int at_value);
void ProcessWorkOrder(Unit *, OrdersCheck *pCheck);
void ProcessProduceOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessBuyOrder(Unit *, AString *, OrdersCheck *pCheck);
void ProcessSellOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessAttackOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessBuildOrder(Unit *, AString *, OrdersCheck *pCheck);
void ProcessSailOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessEnterOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessLeaveOrder(Unit *, OrdersCheck *pCheck);
void ProcessPromoteOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessEvictOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessTaxOrder(Unit *, OrdersCheck *pCheck);
void ProcessPillageOrder(Unit *, OrdersCheck *pCheck);
void ProcessConsumeOrder(Unit *, AString *, OrdersCheck *pCheck);
void ProcessRevealOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessFindOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessDestroyOrder(Unit *, OrdersCheck *pCheck);
void ProcessQuitOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessRestartOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessAssassinateOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessStealOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessFactionOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessClaimOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessCombatOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessPrepareOrder(Unit *, AString *, OrdersCheck *pCheck);
void ProcessWeaponOrder(Unit *u, AString *o, OrdersCheck *pCheck);
void ProcessArmorOrder(Unit *u, AString *o, OrdersCheck *pCheck);
void ProcessCastOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessEnchantSpell(Unit *u, AString *o, int spell, OrdersCheck *pCheck);
void ProcessEntertainOrder(Unit *, OrdersCheck *pCheck);
void ProcessForgetOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessReshowOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessHoldOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessNoaidOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessNocrossOrder(Unit *, AString *, OrdersCheck *pCheck);
void ProcessNospoilsOrder(Unit *, AString *, OrdersCheck *pCheck);
void ProcessSpoilsOrder(Unit *, AString *, OrdersCheck *pCheck);
void ProcessFlagOrder(unsigned flag, Unit *,AString *, OrdersCheck *pCheck);
void ProcessOptionOrder(Unit *,AString *, OrdersCheck *pCheck);
void ProcessPasswordOrder(Unit *, AString *, OrdersCheck *pCheck);
void ProcessExchangeOrder(Unit *, AString *, OrdersCheck *pCheck);
AString *ProcessTurnOrder(Unit *, Aorders *, OrdersCheck *pCheck, int);
void RemoveInactiveFactions();
// Game running functions
// This can be called by parse functions
int CountMages(Faction *);
int CountApprentices(Faction *);
void FindDeadFactions();
void DeleteEmptyUnits();
void DeleteEmptyInRegion(ARegion *);
void EmptyHell();
void DoGuard1Orders();
void DoGiveOrders();
void DoWithdrawOrders();
void DoExchangeOrders();
void DoExchangeOrder(ARegion *, Unit *, ExchangeOrder *);
// Faction limit functions
int TaxCheck(ARegion *pReg, Faction *pFac);
int TradeCheck(ARegion *pReg, Faction *pFac);
// returns 0 normally, or 1 if no more GIVE orders should be allowed
int DoGiveOrder(ARegion *, Unit *, GiveOrder *);
// returns 0 normally, or 1 if no more WITHDRAW orders should be allowed
int DoWithdrawOrder(ARegion *, Unit *, WithdrawOrder *);
// These are game specific, and can be found in extra.cpp
void CheckUnitMaintenance(int consume);
void CheckFactionMaintenance(int consume);
void CheckAllyMaintenance();
// Similar to the above, but for minimum food requirements
void CheckUnitHunger();
void CheckFactionHunger();
void CheckAllyHunger();
void CheckUnitMaintenanceItem(int item, int value, int consume);
void CheckFactionMaintenanceItem(int item, int value, int consume);
void CheckAllyMaintenanceItem(int item, int value);
// Hunger again
void CheckUnitHungerItem(int item, int value);
void CheckFactionHungerItem(int item, int value);
void CheckAllyHungerItem(int item, int value);
void AssessMaintenance();
void GrowWMons(int);
void GrowLMons(int);
void GrowVMons();
void PostProcessUnit(ARegion *,Unit *);
void MidProcessUnit(ARegion *, Unit *);
// Mid and PostProcessUnitExtra can be used to provide game-specific
// unit processing at the approrpriate times
void MidProcessUnitExtra(ARegion *, Unit *);
void MidProcessTurn();
void PostProcessUnitExtra(ARegion *,Unit *);
void PostProcessTurn();
// Handle escaped monster check
void MonsterCheck(ARegion *r, Unit *u);
// CheckVictory is used to see if the game is over
Faction* CheckVictory();
void EndGame(Faction *pVictor);
void RunBuyOrders();
void DoBuy(ARegion *,Market *);
int GetBuyAmount(ARegion *,Market *);
void RunSellOrders();
void DoSell(ARegion *,Market *);
int GetSellAmount(ARegion *,Market *);
void DoAttackOrders();
void CheckWMonAttack(ARegion *,Unit *);
Unit *GetWMonTar(ARegion *,int,Unit *);
int CountWMonTars(ARegion *,Unit *);
void AttemptAttack(ARegion *,Unit *,Unit *,int,int=0);
void DoAutoAttacks();
void DoAutoAttacksRegion(ARegion *);
void DoAdvanceAttack(ARegion *,Unit *);
void DoAutoAttack(ARegion *,Unit *);
void DoAdvanceAttacks(AList *);
void DoAutoAttackOn(ARegion *,Unit *);
void RemoveEmptyObjects();
void RunEnterOrders();
void Do1EnterOrder(ARegion *,Object *,Unit *);
void RunPromoteOrders();
void Do1PromoteOrder(Object *,Unit *);
void Do1EvictOrder(Object *,Unit *);
void RunPillageOrders();
int CountPillagers(ARegion *);
void ClearPillagers(ARegion *);
void RunPillageRegion(ARegion *);
void RunTaxOrders();
void RunTaxRegion(ARegion *);
int CountTaxers(ARegion *);
void RunFindOrders();
void RunFindUnit(Unit *);
void RunDestroyOrders();
void Do1Destroy(ARegion *,Object *,Unit *);
void RunQuitOrders();
void RunForgetOrders();
void Do1Quit(Faction *);
void SinkUncrewedShips();
void DrownUnits();
void RunStealOrders();
AList* CanSeeSteal(ARegion *,Unit *);
void Do1Steal(ARegion *,Object *,Unit *);
void Do1Assassinate(ARegion *,Object *,Unit *);
void AdjustCityMons(ARegion *pReg);
void AdjustCityMon(ARegion *pReg, Unit *u);
// Month long orders
void RunMoveOrders();
Location* DoAMoveOrder(Unit *, ARegion *, Object *);
void DoMoveEnter(Unit *, ARegion *, Object **);
void RunMonthOrders();
void RunStudyOrders(ARegion *);
void Do1StudyOrder(Unit *,Object *);
void RunTeachOrders();
void Do1TeachOrder(ARegion *,Unit *);
void RunProduceOrders(ARegion *);
int ValidProd(Unit *,ARegion *,Production *);
int FindAttemptedProd(ARegion *,Production *);
void RunAProduction(ARegion *,Production *);
bool RunUnitProduce(ARegion *,Unit *, ProduceOrder *o, struct ProduceIntermediates *pi);
void Run1BuildOrder(ARegion *,Object *,Unit *);
void RunBuildHelpers(ARegion *);
void RunSailOrders();
ARegion* Do1SailOrder(ARegion *, Object *, Unit *);
void ClearCastEffects();
void RunCastOrders();
void RunACastOrder(ARegion *,Object *,Unit *);
void RunTeleportOrders();
// include spells.h for spell function declarations
#define GAME_SPELLS
#include "spells.h"
#undef GAME_SPELLS
// Battle function
void KillDead(Location *);
int RunBattle(ARegion *,Unit *,Unit *,int = 0,int = 0);
void GetSides(ARegion *,AList &,AList &,AList &,AList &,Unit *,Unit *,
int = 0,int = 0);
int CanAttack(ARegion *,AList *,Unit *);
void GetAFacs(ARegion *,Unit *,Unit *,AList &,AList &,AList &);
void GetDFacs(ARegion *,Unit *,AList &);
private: // data
AList factions;
AList battles;
ARegionList regions;
int factionseq = 1;
unsigned unitseq = 1;
Unit **ppUnits = nullptr;
unsigned maxppunits = 0;
int shipseq = 100;
int year = 1;
int month = -1;
enum Status
{
GAME_STATUS_UNINIT,
GAME_STATUS_NEW,
GAME_STATUS_RUNNING,
GAME_STATUS_FINISHED,
};
Status gameStatus = GAME_STATUS_UNINIT;
int guardfaction = 0;
int monfaction = 0;
int doExtraInit = 0;
};
#endif