-
Notifications
You must be signed in to change notification settings - Fork 37
/
unit.h
306 lines (275 loc) · 7.83 KB
/
unit.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
// 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
// MODIFICATIONS
// Date Person Comments
// ---- ------ --------
// 2000/MAR/14 Larry Stanbery Replaced specfic skill bonus functions with
// generic function.
// Added function to compute production bonus.
// 2001/FEB/07 Joseph Traub Changes to allow mage support for city guards.
// 2001/Feb/18 Joseph Traub Added support for Apprentices.
// 2001/Feb/25 Joseph Traub Added a flag preventing units from crossing
// water.
#ifndef UNIT_CLASS
#define UNIT_CLASS
class Unit;
class UnitId;
#include "faction.h"
#include "alist.h"
#include "gameio.h"
#include "orders.h"
#include "skills.h"
#include "items.h"
#include "object.h"
#include <set>
#include <string>
#include "external/nlohmann/json.hpp"
using json = nlohmann::json;
enum {
GUARD_NONE,
GUARD_GUARD,
GUARD_AVOID,
GUARD_SET,
GUARD_ADVANCE
};
enum {
TAX_NONE,
TAX_TAX,
TAX_PILLAGE,
TAX_AUTO,
};
enum {
REVEAL_NONE,
REVEAL_UNIT,
REVEAL_FACTION
};
enum {
U_NORMAL,
U_MAGE,
U_GUARD,
U_WMON,
U_GUARDMAGE,
U_APPRENTICE,
NUNITTYPES
};
#define MAX_READY 4 // maximum number of ready weapons or armors
#define FLAG_BEHIND 0x0001
#define FLAG_NOCROSS_WATER 0x0002
#define FLAG_AUTOTAX 0x0004
#define FLAG_HOLDING 0x0008
#define FLAG_NOAID 0x0010
#define FLAG_INVIS 0x0020
#define FLAG_CONSUMING_UNIT 0x0040
#define FLAG_CONSUMING_FACTION 0x0080
#define FLAG_NOSPOILS 0x0100
#define FLAG_FLYSPOILS 0x0200
#define FLAG_WALKSPOILS 0x0400
#define FLAG_RIDESPOILS 0x0800
#define FLAG_SHARING 0x1000
#define FLAG_SWIMSPOILS 0x2000
#define FLAG_SAILSPOILS 0x4000
class UnitId {
public:
UnitId();
~UnitId();
std::string Print();
int unitnum; /* if 0, it is a new unit */
int alias;
int faction;
};
class Unit
{
public:
Unit();
Unit(int,Faction *,int = 0);
~Unit();
void SetMonFlags();
void MakeWMon(char const *,int,int);
void Writeout(std::ostream& f);
void Readin(std::istream& f, AList *);
AString SpoilsReport(void);
int CanGetSpoil(Item& i);
json build_json_descriptor();
void build_json_report(json& j, int obs, int truesight, int detfac, int autosee, int attitude, int showattitudes);
json write_json_orders();
AString GetName(int);
AString MageReport();
AString ReadyItem();
AString StudyableSkills();
AString * BattleReport(int);
void ClearOrders();
void ClearCastOrders();
void DefaultOrders(Object *);
void SetName(AString *);
void SetDescribe(AString *);
void PostTurn(ARegion *reg);
int IsLeader();
int IsNormal();
int GetMons();
int GetMen();
int GetLeaders();
int GetSoldiers();
int GetMen(int);
void SetMen(int,int);
int GetMoney();
void SetMoney(int);
int GetSharedNum(int);
void ConsumeShared(int item, int needed);
int GetSharedMoney();
void ConsumeSharedMoney(int needed);
int IsAlive();
int MaintCost(ARegionList *regions, ARegion *current_region);
void Short(int, int);
int SkillLevels();
void SkillStarvation();
Skill *GetSkillObject(int);
int GetAttackRiding();
int GetDefenseRiding();
//
// These are rule-set specific, in extra.cpp.
//
// LLS
int GetAttribute(char const *ident);
int PracticeAttribute(char const *ident);
int GetProductionBonus(int);
int GetSkill(int);
void SetSkill(int,int);
int GetSkillMax(int);
int GetAvailSkill(int);
int GetRealSkill(int);
void ForgetSkill(int);
int CheckDepend(int,SkillDepend &s);
int CanStudy(int);
int Study(int,int); /* Returns 1 if it succeeds */
int Practice(int);
void AdjustSkills();
/* Return 1 if can see, 2 if can see faction */
int CanSee(ARegion *,Unit *, int practice = 0);
int CanCatch(ARegion *,Unit *);
int AmtsPreventCrime(Unit *);
int GetAttitude(ARegion *,Unit *); /* Get this unit's attitude toward
the Unit parameter */
int Hostile();
int Forbids(ARegion *,Unit *);
int Weight();
int FlyingCapacity();
int RidingCapacity();
int SwimmingCapacity();
int WalkingCapacity();
int CanFly(int);
int CanRide(int);
int CanWalk(int);
int CanFly();
int CanSwim();
int CanReallySwim();
int MoveType(ARegion *r = 0);
int CalcMovePoints(ARegion *r = 0);
int CanMoveTo(ARegion *,ARegion *);
int GetFlag(int);
void SetFlag(int,int);
void CopyFlags(Unit *);
int GetBattleItem(AString &itm);
int GetArmor(AString &itm, int ass);
int GetMount(AString &itm, int canFly, int canRide, int &bonus);
int GetWeapon(AString &itm, int riding, int ridingBonus,
int &attackBonus, int &defenseBonus, int &attacks, int &hitDamage);
int CanUseWeapon(WeaponType *pWep, int riding);
int CanUseWeapon(WeaponType *pWep);
int Taxers(int);
void MoveUnit( Object *newobj );
void DiscardUnfinishedShips();
void event(const std::string& message, const std::string& category, ARegion *r = nullptr);
void error(const std::string& message);
Faction *faction;
Faction *formfaction;
Object *object;
AString *name;
AString *describe;
int num;
int type;
int alias;
int gm_alias; /* used for gm manual creation of new units */
int guard; /* Also, avoid- see enum above */
int reveal;
int flags;
int taxing;
int movepoints;
int canattack;
int nomove;
int routed;
SkillList skills;
ItemList items;
ItemList transport_items;
int combat;
int readyItem;
int readyWeapon[MAX_READY];
int readyArmor[MAX_READY];
std::list<std::string> oldorders;
int needed; /* For assessing maintenance */
int hunger;
int stomach_space;
int losses;
int free;
int practiced; // Has this unit practiced a skill this turn
int moved;
int phase;
int savedmovement;
int savedmovedir;
/* Orders */
int destroy;
int enter;
int build;
UnitId *promote;
std::vector<std::shared_ptr<FindOrder>> findorders;
std::vector<std::shared_ptr<GiveOrder>> giveorders;
std::vector<std::shared_ptr<WithdrawOrder>> withdraworders;
std::vector<std::shared_ptr<BuyOrder>> buyorders;
std::vector<std::shared_ptr<SellOrder>> sellorders;
std::vector<std::shared_ptr<ForgetOrder>> forgetorders;
std::shared_ptr<CastOrder> castorders;
std::shared_ptr<TeleportOrder> teleportorders;
std::shared_ptr<StealthOrder>stealthorders;
std::shared_ptr<Order> monthorders;
std::shared_ptr<AttackOrder> attackorders;
std::shared_ptr<EvictOrder> evictorders;
std::shared_ptr<SacrificeOrder> sacrificeorders;
std::shared_ptr<AnnihilateOrder> annihilateorders;
ARegion *advancefrom;
std::vector<std::shared_ptr<ExchangeOrder>> exchangeorders;
std::list<std::shared_ptr<TurnOrder>> turnorders;
int inTurnBlock;
std::shared_ptr<Order> presentMonthOrders;
int presentTaxing;
std::vector<std::shared_ptr<TransportOrder>> transportorders;
std::shared_ptr<JoinOrder> joinorders;
Unit *former;
int format;
// Used for tracking VISIT quests
std::set<std::string> visited;
int raised;
// Used for tracking movement for NO7 victory condition
ARegion *initial_region;
};
#endif