forked from erwin47/alh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatlaparser.h
345 lines (303 loc) · 14.2 KB
/
atlaparser.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
/*
* This source file is part of the Atlantis Little Helper program.
* Copyright (C) 2001 Maxim Shariy.
*
* Atlantis Little Helper 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.
*
* Atlantis Little Helper 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 Atlantis Little Helper; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __AH_REP_PARSER_H__
#define __AH_REP_PARSER_H__
#include <map>
#include "data.h"
#include "files.h"
#include "hash.h"
extern const char * Monthes[];
extern const char * EOL_MS ;
extern const char * EOL_UNIX ;
extern const char * EOL_SCR ;
extern const char * EOL_FILE ;
#define DEFAULT_PLANE "Overworld"
typedef enum { North=0, Northeast, Southeast, South, Southwest, Northwest, Center } eDirection;
extern int ExitFlags [];
extern int EntryFlags[];
extern int Flags_NW_N_NE;
extern int Flags_N ;
extern int Flags_SW_S_SE;
extern int Flags_S ;
// MZ - O_SHARE added for Arcadia
enum {
O_ADDRESS = 1,
O_ADVANCE,
O_ARMOR,
O_ASSASSINATE,
O_ATTACK,
O_AUTOTAX,
O_AVOID,
O_BEHIND,
O_BUILD,
O_BUY,
O_CAST,
O_CLAIM,
O_COMBAT,
O_CONSUME,
O_DECLARE,
O_DESCRIBE,
O_DESTROY,
O_ENDFORM,
O_ENTER,
O_ENTERTAIN,
O_EVICT,
O_EXCHANGE,
O_FACTION,
O_FIND,
O_FORGET,
O_FORM,
O_GIVE,
O_GIVEIF,
O_TAKE,
O_SEND,
O_GUARD,
O_HOLD,
O_LEAVE,
O_MOVE,
O_NAME,
O_NOAID,
O_NOCROSS,
O_NOSPOILS,
O_OPTION,
O_PASSWORD,
O_PILLAGE,
O_PREPARE,
O_PRODUCE,
O_PROMOTE,
O_QUIT,
O_RESTART,
O_REVEAL,
O_SAIL,
O_SELL,
O_SHARE,
O_SHOW,
O_SPOILS,
O_STEAL,
O_STUDY,
O_TAX,
O_TEACH,
O_WEAPON,
O_WITHDRAW,
O_WORK,
O_RECRUIT,
O_TYPE,
O_LABEL,
// must be in this sequence! O_ENDXXX == O_XXX+1
O_TURN,
O_ENDTURN,
O_TEMPLATE,
O_ENDTEMPLATE,
O_ALL,
O_ENDALL,
NORDERS
};
enum SHARE_TYPE {
SHARE_BUY,
SHARE_STUDY,
SHARE_UPKEEP
};
typedef struct SAVE_HEX_OPTIONS_STRUCT
{
BOOL SaveStructs;
BOOL AlwaysSaveImmobStructs;
BOOL SaveUnits;
BOOL SaveResources;
long WriteTurnNo; // Add turn number atlaclient style
} SAVE_HEX_OPTIONS;
//======================================================================
class CAtlaParser
{
public:
CAtlaParser();
CAtlaParser(CGameDataHelper * pHelper);
~CAtlaParser();
void Clear();
int ParseRep(const char * FNameIn, BOOL Join, BOOL IsHistory); // History is a rep!
int SaveOrders (const char * FNameOut, const char * password, BOOL decorate, int factid);
int LoadOrders (const char * FNameIn, int & FactionId); // return an id of the order's faction
void RunOrders(CLand * pLand, const char * sCheckTeach = NULL);
BOOL ShareSilver(CUnit * pMainUnit);
BOOL GenOrdersTeach(CUnit * pMainUnit);
BOOL GenGiveEverything(CUnit * pFrom, const char * To);
BOOL DiscardJunkItems(CUnit * pUnit, const char * junk);
BOOL DetectSpies(CUnit * pUnit, long lonum, long hinum, long amount);
BOOL ApplyDefaultOrders(BOOL EmptyOnly);
int ParseCBDataFile(const char * FNameIn);
void WriteMagesCSV(const char * FName, BOOL vertical, const char * separator, int format);
bool IsLandExitClosed(CLand * pLand, int direction) const;
CLand * GetLandExit(CLand * pLand, int direction) const;
CLand * GetLand(int x, int y, int nPlane, BOOL AdjustForEdge=FALSE) const;
CLand * GetLand(long LandId) const;
CLand * GetLand(const char * landcoords) const; // "48,52[,somewhere]"
CLand * GetLandFlexible(const wxString & description) const;
CLand * GetLandWithCity(const wxString & cityName) const;
void GetUnitList(CCollection * pResultColl, int x, int y, int z);
void CountMenForTheFaction(int FactionId);
void ComposeProductsLine(CLand * pLand, const char * eol, CStr & S);
BOOL LandStrCoordToId(const char * landcoords, long & id) const;
int NormalizeHexX(int NoX, CPlane *) const;
void ComposeLandStrCoord(CLand * pLand, CStr & LandStr);
CFaction * GetFaction(int id);
BOOL SaveOneHex(CFileWriter & Dest, CLand * pLand, CPlane * pPlane, SAVE_HEX_OPTIONS * pOptions);
long SkillDaysToLevel(long days);
CUnit * SplitUnit(CUnit * pOrigUnit, long newId);
bool LinkShaft(CLand * pLand, CLand * pLandDest, int structIdx);
wxString getFullStrLandCoord(CLand *);
BOOL CheckResourcesForProduction(CUnit * pUnit, CLand * pLand, CStr & Error);
void ExtrapolateLandCoord(int &x, int &y, int z, int direction) const;
// Movement
int GetTerrainMovementCost(wxString Terrain) const;
bool IsRoadConnected(CLand *, CLand *, int direction) const;
bool IsBadWeatherHex(CLand * pLand, int month) const;
int GetMovementCost(int terrainCost, bool isBadWeather, bool hasRoad, int movementMode, bool noCross) const;
void GetMovementMode(CUnit * pUnit, int & movementMode, bool & noCross, long order) const;
int m_CrntFactionId;
CStr m_CrntFactionPwd;
CLongColl m_OurFactions;
CBaseObject m_Events;
CBaseObject m_SecurityEvents;
CBaseObject m_HexEvents;
CBaseObject m_Errors;
CBaseColl m_NewProducts;
CBaseCollById m_Factions;
CBaseCollById m_Units;
CBaseColl m_Planes;
long m_YearMon; // Current year/month accumulated for all loaded files
CStringSortColl m_UnitPropertyNames;
CStrIntColl m_UnitPropertyTypes;
CStringSortColl m_LandPropertyNames;
//CStringSortColl m_LandPropertyTypes;
CBaseColl m_Skills;
CBaseColl m_Items;
CBaseColl m_Objects;
// CBaseCollByName m_Battles;
CBaseColl m_Battles;
CBaseCollById m_Gates;
long m_nCurLine;
long m_GatesCount;
int m_ParseErr;
BOOL m_OrdersLoaded;
CStr m_FactionInfo;
BOOL m_ArcadiaSkills;
std::map<wxString, int> TerrainMovementCost;
bool m_EconomyTaxPillage;
bool m_EconomyShareAfterBuy;
bool m_EconomyWork;
bool m_EconomyMaintainanceCosts;
bool m_EconomyShareMaintainance;
const char * ReadPropertyName(const char * src, CStr & Name);
protected:
int ParseFactionInfo(BOOL GetNo, BOOL Join);
int ParseEvents(BOOL IsEvents=TRUE);
int ParseUnclSilver(CStr & Line);
int ParseAttitudes(CStr & Line, BOOL Join);
int ParseTerrain (CLand * pMotherLand, int ExitDir, CStr & FirstLine, BOOL FullMode, CLand ** ppParsedLand);
int AnalyzeTerrain(CLand * pMotherLand, CLand * pLand, BOOL IsExit, int ExitDir, CStr & Description);
void ComposeHexDescriptionForArnoGame(const char * olddescr, const char * newdescr, CStr & CompositeDescr);
void ParseWages(CLand * pLand, const char * str1, const char * str2);
void CheckExit(CPlane * pPlane, int Direction, CLand * pLandSrc, CLand * pLandExit);
int ParseUnit(CStr & FirstLine, BOOL Join);
int ParseStructure (CStr & FirstLine);
int ParseErrors();
int ParseLines(BOOL Join);
BOOL ParseOneUnitEvent(CStr & EventLine, BOOL IsEvent, int UnitId);
BOOL ParseOneLandEvent(CStr & EventLine, BOOL IsEvent);
void ParseOneMovementEvent(const char * params, const char * structid, const char * fullevent);
int ParseOneEvent(CStr & EventLine, BOOL IsEvent);
void ParseWeather(const char * src, CLand * pLand);
int ApplyLandFlags();
int SetLandFlag(const char * p, long flag);
int SetLandFlag(long LandId, long flag);
int ParseBattles();
int ParseSkills();
int ParseItems();
int ParseObjects();
void SetExitFlagsAndTropicZone();
int SetUnitProperty(CUnit * pUnit, const char * name, EValueType type, const void * value, EPropertyType proptype);
int SetLandProperty(CLand * pLand, const char * name, EValueType type, const void * value, EPropertyType proptype);
int LoadOrders (CFileReader & F, int FactionId, BOOL GetComments);
void StoreBattle(CStr & Source);
void AnalyzeBattle(const char * src, CStr & Details);
void AnalyzeBattle_OneSide(const char * src, CStr & Details);
const char * AnalyzeBattle_ParseUnit(const char * src, CUnit *& pUnit, BOOL & InFrontLine);
void AnalyzeBattle_SummarizeUnits(CBaseColl & Units, CStr & Details);
void SetShaftLinks();
void ApplySailingEvents();
BOOL GetTargetUnitId(const char *& p, long FactionId, long & nId);
int ParseOneImportantEvent(CStr & EventLine);
int ParseImportantEvents();
CUnit * MakeUnit(long Id);
CPlane * MakePlane(const char * planename);
BOOL ReadNextLine(CStr & s);
BOOL ReadNextLineMerged(CStr & s);
void PutLineBack (CStr & s);
void GenericErr(int Severity, const char * Msg);
void OrderErr(int Severity, int UnitId, const char * Msg, const char * UnitName = NULL, CUnit * = NULL);
void OrderErrFinalize();
void RunLandOrders(CLand * pLand, const char * sCheckTeach = NULL);
void OrderProcess_Teach(BOOL skiperror, CUnit * pUnit);
// Order handlers and helpers
void RunOrder_Teach (CStr & Line, CStr & ErrorLine, BOOL skiperror, CUnit * pUnit, CLand * pLand, const char * params, BOOL TeachCheckGlb);
void RunOrder_Move (CStr & Line, CStr & ErrorLine, BOOL skiperror, CUnit * pUnit, CLand * pLand, const char * params, int & X, int & Y, int & LocA3, long order);
void RunOrder_Promote (CStr & Line, CStr & ErrorLine, BOOL skiperror, CUnit * pUnit, CLand * pLand, const char * params);
void RunOrder_Sell (CStr & Line, CStr & ErrorLine, BOOL skiperror, CUnit * pUnit, CLand * pLand, const char * params);
void RunOrder_Buy (CStr & Line, CStr & ErrorLine, BOOL skiperror, CUnit * pUnit, CLand * pLand, const char * params);
void RunOrder_Give (CStr & Line, CStr & ErrorLine, BOOL skiperror, CUnit * pUnit, CLand * pLand, const char * params, BOOL IgnoreMissingTarget);
void RunOrder_Take (CStr & Line, CStr & ErrorLine, BOOL skiperror, CUnit * pUnit, CLand * pLand, const char * params, BOOL IgnoreMissingTarget);
void RunOrder_Send (CStr & Line, CStr & ErrorLine, BOOL skiperror, CUnit * pUnit, CLand * pLand, const char * params);
void RunOrder_Produce (CStr & Line, CStr & ErrorLine, BOOL skiperror, CUnit * pUnit, CLand * pLand, const char * params);
void RunOrder_Study (CStr & Line, CStr & ErrorLine, BOOL skiperror, CUnit * pUnit, CLand * pLand, const char * params);
void RunOrder_Name (CStr & Line, CStr & ErrorLine, BOOL skiperror, CUnit * pUnit, CLand * pLand, const char * params);
void RunOrder_SailAIII (CStr & Line, CStr & ErrorLine, BOOL skiperror, CUnit * pUnit, CLand * pLand, const char * params, int & X, int & Y, int & LocA3);
BOOL FindTargetsForSend (CStr & Line, CStr & ErrorLine, BOOL skiperror, CUnit * pUnit, CLand * pLand, const char *& params, CUnit *& pUnit2, CLand *& pLand2);
BOOL GetItemAndAmountForGive (CStr & Line, CStr & ErrorLine, BOOL skiperror, CUnit * pUnit, CLand * pLand, const char * params, CStr & Item, int & amount, const char * command, CUnit * pUnit2);
void RunOrder_Withdraw (CStr & Line, CStr & ErrorLine, BOOL skiperror, CUnit * pUnit, CLand * pLand, const char * params);
void RunPseudoComment (CStr & Line, CStr & ErrorLine, BOOL skiperror, CUnit * pUnit, CLand * pLand, const char * params, int sequence, wxString &destination);
void RunOrder_TaxPillage (CLand *);
void RunOrder_Entertain (CLand *);
void RunOrder_Work (CLand *);
void RunOrder_ShareSilver (CStr & Line, CStr & ErrorLine, BOOL skiperror, CLand *, SHARE_TYPE, wxString shareName);
void RunOrder_Upkeep (CLand *);
void RunOrder_Upkeep (CUnit *, int turns);
void DistributeSilver (CLand *, int unitFlag, int silver, int menCount);
int CountMenWithFlag (CLand *, int unitFlag) const;
void AdjustSkillsAfterGivingMen(CUnit * pUnitGive, CUnit * pUnitTake, CStr & item, long AmountGiven);
void LookupAdvancedResourceVisibility(CUnit * pUnit, CLand * pLand);
int ParseCBHex (const char * FirstLine);
int ParseCBStruct(const char * FirstLine);
CFileReader * m_pSource;
CStringSortColl m_TaxLandStrs;
CStringSortColl m_TradeLandStrs;
CStringSortColl m_BattleLandStrs;
CLongSortColl m_TradeUnitIds;
CBaseCollByName m_PlanesNamed;
CBaseColl m_LandsToBeLinked;
CHashStrToLong m_UnitFlagsHash;
CBaseColl m_TempSailingEvents;
CLand * m_pCurLand ;
CStruct * m_pCurStruct ;
int m_NextStructId;
CStr m_sOrderErrors;
BOOL m_JoiningRep; // joining an allies' report
BOOL m_IsHistory; // parsing history file
long m_CurYearMon; // Year/month for the file being loaded
CStr m_WeatherLine[8];
};
#endif