1 //
2 // nazghul - an old-school RPG engine
3 // Copyright (C) 2002, 2003 Gordon McNutt
4 //
5 // This program is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by the Free
7 // Software Foundation; either version 2 of the License, or (at your option)
8 // any later version.
9 //
10 // This program is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13 // more details.
14 //
15 // You should have received a copy of the GNU General Public License along with
16 // this program; if not, write to the Free Foundation, Inc., 59 Temple Place,
17 // Suite 330, Boston, MA 02111-1307 USA
18 //
19 // Gordon McNutt
20 // gmcnutt@users.sourceforge.net
21 //
22 #ifndef character_h
23 #define character_h
24 
25 #include "Being.h"
26 #include "Arms.h"
27 #include "species.h"
28 #include "clock.h"
29 #include "sound.h"
30 
31 #undef RAM_ATTACK
32 
33 // Weird C++-isms ensue at compile-time if I try to include combat.h directly
34 // here...
35 extern void combatKIA(class Character *);
36 
37 struct ready_spell {
38 	struct list list;
39 	struct spell *spell;
40 };
41 
42 struct point {
43 	int x, y;
44 };
45 
46 struct TypicalObjectInfo {
47 	int probability;
48 	class ObjectType *type;
49 	int n_max;
50 };
51 
52 
53 class Character:public Being {
54  public:
55 
56 	enum ReadyResult {
57 		Readied,
58 		NoAvailableSlot,
59 		WrongType,
60 		TooHeavy
61 	};
62 
63 	Character();
64         Character(const char *tag, const char *name,
65                   struct sprite *sprite,
66                   struct species *species, struct occ *occ,
67                   int str, int intl,
68                   int dex, int hpmod, int hpmult,
69                   int mpmod, int mpmult,
70                   int hp, int xp, int mp,
71 		  int AP_per_round,
72                   int lvl);
73 	virtual ~ Character();
74 
75         virtual int getActivity();
76         int getArmor();
77         int getDefend();
78         int getToHitPenalty();
79         int getBaseAttackBonus(class ArmsType * weapon);
80         int getAttackBonus(class ArmsType * weapon);
81         int getDamageBonus(class ArmsType * weapon);
82         int getAvoidBonus();
83         virtual class Party * getParty();
84 	virtual int getType();
85 	int  getHp();
86 	void setHp(int hp);
87 	int  getMana();
88         void setMana(int mana);
89 	int getMaxMana();
90         class Container *getInventoryContainer();
91 	virtual int getMaxHp();
92 	virtual int getOrder();
93         int getXpForLevel(int lvl);
94 	virtual void addExperience(int delta);
95 	virtual int getExperience();
96 	virtual unsigned char getStrength();
97 	virtual unsigned char getIntelligence();
98 	virtual unsigned char getDexterity();
99 	virtual unsigned char getBaseStrength();
100 	virtual unsigned char getBaseIntelligence();
101 	virtual unsigned char getBaseDexterity();
102 	virtual void setStrength(unsigned char newstat);
103 	virtual void setIntelligence(unsigned char newstat);
104 	virtual void setDexterity(unsigned char newstat);
105 	int getLevel();
106         void setLevel(int level);
107         virtual struct mmode *getMovementMode();
108         virtual void setMovementMode(struct mmode *mmode);
109 	virtual int getArmourClass();
110 	virtual const char *getWoundDescription();
111 	virtual class Character *getAttackTarget(class ArmsType * weapon);
112 	virtual class ArmsType *getNextArms(int * armsIndex);
113 	virtual class ArmsType *getNextWeapon(int * armsIndex);
114 	virtual int getLight();
115 	virtual int getVisionRadius();
116 	virtual int getSpeed();
117 	virtual int setSpeed(int val);
118 	virtual struct sprite *getSprite();
119         virtual sound_t *getDamageSound();
120         virtual sound_t *get_movement_sound();
121 
122 
123         virtual bool isCharmed();
124         virtual bool isCamping();
125         virtual bool isCompanionOf(class Object *other);
126         virtual bool isGuarding();
127         virtual bool isLeader();
128         virtual bool isResting();
129 	virtual bool isType(int classID);
130 	virtual bool isDead();
131 	virtual bool isAsleep();
132 	virtual bool isIncapacitated();
133 	virtual bool isPlayerControlled();
134 	virtual bool hasReadied(class ArmsType * arms);
135 	virtual bool isSolo();
136 	virtual int  hasAmmo(class ArmsType * weapon);
137         virtual bool hasInInventory(class ObjectType *type);
138 	virtual bool isFleeing();
139 	virtual bool isVisible();
140 	virtual bool isShaded();
141         virtual bool isPlayerPartyMember();
142         virtual bool canWanderTo(int newx, int newy);
143 
144         virtual void addDefense(int val);
145 	virtual void changeArmourClass(int val);
146 	virtual void changeSleep(bool val);
147 	virtual void setLight(int delta);
148 	virtual void addMana(int delta);
149 
150         virtual void setActivity(int val);
151         virtual void setControlMode(enum control_mode mode);
152         virtual void setInventoryContainer(class Container *container);
153         virtual void setLeader(bool val);
154         virtual void setSchedule(struct sched *sched);
155         virtual void setSolo(bool val);
156 	virtual void setOrder(int order);
157 	virtual void setPlayerControlled(bool val);
158 	virtual void setAttackTarget(class Character * target);
159 	virtual void setFleeing(bool val);
160 	virtual void setCombat(bool val);
161         virtual void ambushWhileCamping();
162 	virtual void awaken(void);
163         virtual void beginCamping(int hours);
164         virtual void beginGuarding(int hours);
165         virtual void beginResting(int hours);
166 	virtual void damage(int amount);
167 	virtual void inflictDamage(int amount,class Character *attacker);
168         virtual void endCamping(void);
169         virtual void endGuarding();
170         virtual void endResting(void);
171         virtual void exec();
172         virtual void groupExitTo(struct place *dest_place,
173                                  int dest_x, int dest_y,
174                                  struct closure *closure);
175         virtual void heal(int amount);
176         bool joinPlayer(void);
177         void leavePlayer(void);
178 	virtual void kill();
179 	virtual void remove();
180 	virtual enum ReadyResult ready(class ArmsType * arms);
181 	virtual void synchronize();
182 	virtual bool unready(class ArmsType * arms);
183 	virtual enum MoveResult move(int dx, int dy);
184 	virtual void armThyself();
185 	virtual bool needToRearm();
186 	virtual void resurrect();
187 	virtual void rest(int hours);
188 	virtual class Object *clone();
189 	virtual void describe();
190  	virtual void examine();
191        virtual void burn();
192         virtual void save(struct save *save);
193         virtual void sleep();
194         virtual bool tryToRelocateToNewPlace(struct place *place,
195                                              int x, int y,
196                                              struct closure *closure);
197 	virtual class ArmsType *enumerateArms(int *armsIndex);
198 	virtual class ArmsType *enumerateWeapons(int *armsIndex);
199         class ArmsType *getArmsInSlot(int slot);
200         virtual bool addFood(int quantity);
201         virtual bool addGold(int quantity);
202         virtual bool add(ObjectType *type, int amount);
203         virtual bool takeOut(ObjectType *type, int amount);
204         virtual void setCurrentFaction(int faction);
205         virtual bool isStationary();
206 
207         void charm(int faction);
208         void unCharm();
209 	void useAmmo(class ArmsType *weapon);
210         bool canSee(class Object *obj);
211 	bool commute();
212         int getExperienceValue();
213 	bool initStock(struct species * species, struct occ * occ,
214 		       struct sprite * sprite, char *name, int order);
215 
216         bool canBeLeader();
217         void setAI(struct closure *val);
218         struct closure *getAI();
219         void setDead(bool val);
220         void introduce();
221         void setForceContainerDrop(bool val);
222         bool getForceContainerDrop();
223 
224         void beginLoitering(int hours);
225         void endLoitering();
226         bool isLoitering();
227 	bool flee();
228         bool isKnown();
229         void setKnown(bool val);
230 
231         void taskAbort();
232         void taskBegin(char *taskname, struct closure *taskproc, struct gob *taskgob);
233         void taskContinue(char *taskname, struct closure *taskproc, struct gob *taskgob);
234         void taskEnd();
235         bool engagedInTask();
236         const char *getTaskName();
237 
238         struct node *plnode; // pointer back to party list node
239 	class Party *party;
240 	struct species *species;
241 	struct occ *occ;
242 	bool is_clone;
243 
244         int hp_mod;
245         int hp_mult;
246         int mp_mod;
247         int mp_mult;
248 
249  protected:
250 	bool initCommon(void);
251 	bool isAttackTargetInRange(class ArmsType *weapon);
252         void getAppointment();
253 
254 	int hm;
255 
256         // -------------------------------------------------
257         // Custom attribute modifiers
258         // -------------------------------------------------
259 
260 
261 	int xp;
262 	int order;
263 	bool sleeping;
264 	int ac; // used by spells
265 	int str;
266 	int intl;
267 	int dex;
268 	int mana;
269 	int AP_per_round;  // Action Points per round (speed)
270 	int lvl;
271         int defenseBonus;
272 	bool playerControlled;
273 	bool solo;
274 	class Character *target;
275 	class ArmsType **rdyArms;
276 	bool fleeing;
277 	int burden;
278 	bool inCombat;
279         sound_t *damage_sound;
280 
281 	// *** NPC fields
282 	virtual void dropRdyArms();
283 	virtual bool dropItems();
284 	class Container *container;
285 	bool rearm;
286 
287 	// *** PC fields
288 	//struct sprite *sprite;
289 
290         bool charmed;
291 
292         // --------------------------------------------------------------------
293         // Stuff for resting/camping:
294         // --------------------------------------------------------------------
295         clock_alarm_t wakeup_alarm;
296         clock_alarm_t rest_alarm;
297         bool resting;
298         bool guarding;
299         bool loitering;
300 
301 	struct sched *sched;
302         int activity;
303         int appt;
304 
305         bool is_leader;
306         void (*ctrl)(class Character *character);
307 
308         int factionSwitch;
309         int tmpFaction;
310         bool ambushedWhileCamping;
311         struct closure *ai; // should be moved up to Being...
312         bool dead;
313 
314         struct node *sched_chars_node;   /* for chars with multiplace scheds */
315         bool forceContainerDrop; // ensure the container is dropped on death
316 
317   protected:
318         virtual void switchPlaces(class Being *);
319 
320  private:
321         bool atAppointment();
322         bool nextToAppointment();
323         bool playerIsInMyBed();
324         void kickPlayerOutOfMyBed();
325         void unreadyAll();
326         void getEvasionVector(int *dx, int *dy);
327         bool locationIsOk(int x2, int y2);
328         bool mapHasEdge();
329         bool followFleePath();
330         bool findFleePath();
331         bool pathfindToMapEdge();
332         bool fleeToMapEdge();
333         bool evade();
334         bool exitMap();
335         void taskCleanup();
336         void taskSetup(char *taskname, struct closure *taskproc, struct gob *taskgob);
337         void taskPromptToAbort();
338 
339         bool fleePathFound;
340         int fleeX, fleeY, fleePathFlags;
341         struct mmode *currentMmode;
342         bool known;
343 
344         char *taskname;
345         struct closure *taskproc;
346         struct gob *taskgob;
347         bool taskInterruptOnDamage;
348 };
349 
350 extern void char_dtor(void *val);
351 extern void char_save(struct save *save, void *val);
352 
353 #endif
354