ScummVM API documentation
player.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  *
21  * Based on the original sources
22  * Faery Tale II -- The Halls of the Dead
23  * (c) 1993-1996 The Wyrmkeep Entertainment Co.
24  */
25 
26 #ifndef SAGA2_PLAYER_H
27 #define SAGA2_PLAYER_H
28 
29 #include "saga2/actor.h"
30 
31 namespace Saga2 {
32 
33 #define FTA_JULIAN (PlayerActorID)0
34 #define FTA_PHILIP (PlayerActorID)1
35 #define FTA_KEVIN (PlayerActorID)2
36 
37 /* ======================================================================= *
38  PlayerActor -- data specific to possible center actors
39  * ======================================================================= */
40 
41 class ContainerNode;
42 
43 class PlayerActor {
44  friend class Actor;
45 
46  friend void initPlayerActors();
47  friend void cleanupPlayerActors();
48 
49  ObjectID _actorID; // ID of player's actor
50 
51 public:
52  int16 _portraitType; // Integer representing portrait state
53  // for this player actor
54  uint16 _flags; // various flags
55 
56  ActorAttributes _baseStats; // Base stats for this actor
57  enum PlayerActorFlags {
58  kPlayerAggressive = (1 << 0), // Player is in aggressive mode
59  kPlayerBanded = (1 << 1), // Player is banded
60  kPlayerHasCartography = (1 << 2) // Player has ability to map
61  };
62 
63  // recovery information
64  enum Recovery {
65  kBaseManaRec = 1,
66  kAttribPointsPerUpdate = 1,
67  kAttribPointsPerValue = 10
68  };
69 
70  enum {
71  kVitalityLevelBump = 50
72  };
73 
74  // Container node for ready containers
75  ContainerNode *_readyNode;
76 
77  // mana 'experience' pool
78  int16 _manaMemory[kNumManas];
79 
80  // attrib recovery pools
81  uint8 _attribRecPools[kNumSkills];
82 
83  // skills 'expericene' pool
84  uint8 _attribMemPools[kNumSkills];
85 
86  // vitality pool
87  uint8 _vitalityMemory;
88 
89  // Flag indicating whether the user has been notified that this player
90  // actor has been attacked since the last combat
91  bool _notifiedOfAttack;
92 
93  // Constructor
94  PlayerActor(ObjectID a) : _actorID(a), _portraitType(0), _flags(0), _readyNode(NULL),
95  _vitalityMemory(0), _notifiedOfAttack(false) {
96 
97  assert(ActorAttributes::kSkillFracPointsPerLevel > 0); // this is used in a divide
98 
99  memset(&_baseStats, 0, sizeof(_baseStats));
100 
101  for (int i = 0; i < kNumManas; i++)
102  _manaMemory[i] = 0;
103 
104  for (int i = 0; i < kNumSkills; i++) {
105  _attribRecPools[i] = 0;
106  _attribMemPools[i] = 0;
107  }
108  }
109 
110  // gets level of skill
111  int8 getSkillLevel(SkillProto *, bool base = false);
112 
113  // get the actorAttributes allskills index from proto
114  uint8 getStatIndex(SkillProto *);
115 
116  // get the effective stats of this player actor
117  ActorAttributes *getEffStats();
118 
119  // these update a players baseStat skills
120  void skillAdvance(uint8 stat,
121  uint8 advanceChance,
122  uint8 points,
123  uint8 useMult = 1);
124 
125  void skillAdvance(SkillProto *proto,
126  uint8 points,
127  uint8 useMult = 1);
128 
129  void skillAdvance(ActorSkillID stat,
130  uint8 points,
131  uint8 useMult = 1);
132 
133  void vitalityAdvance(uint8 points);
134 
135  // Return Actor structure pointer
136  Actor *getActor() {
137  return (Actor *)GameObject::objectAddress(_actorID);
138  }
139 
140  // Return Actor's object ID
141  ObjectID getActorID() {
142  return _actorID;
143  }
144 
145  // Set player to be aggressive
146  void setAggression() {
147  _flags |= kPlayerAggressive;
148  }
149 
150  // Set player to not aggressive
151  void clearAggression() {
152  _flags &= ~kPlayerAggressive;
153  }
154 
155  // Determine if actor is in aggressive state
156  bool isAggressive() {
157  return (_flags & kPlayerAggressive) != 0;
158  }
159 
160  // Set the player to be banded
161  void setBanded() {
162  _flags |= kPlayerBanded;
163  }
164 
165  // Set the player to not be banded
166  void clearBanded() {
167  _flags &= ~kPlayerBanded;
168  }
169 
170  // Determine if this player actor is banded
171  bool isBanded() {
172  return (_flags & kPlayerBanded) != 0;
173  }
174 
175  // Resolve the banding state of this actor
176  void resolveBanding();
177 
178  // Re-evaluate the portrait type for this player actor
179  void recalcPortraitType();
180 
181  // Return the integer representing the portrait type for this
182  // player actor
183  int16 getPortraitType() {
184  return _portraitType;
185  }
186 
187  // figures out what what ( if any ) changes are required to
188  // the charaters vitality
189  void recoveryUpdate();
190  void manaUpdate();
191  void AttribUpdate();
192  void stdAttribUpdate(uint8 &stat, uint8 baseStat, int16 index);
193 
194  // get this player actor's base stats
195  ActorAttributes &getBaseStats() {
196  return _baseStats;
197  }
198 
199  // Notify the user of attack if necessary
200  void handleAttacked();
201 
202  // Simply reset the attack notification flag
203  void resetAttackNotification() {
204  _notifiedOfAttack = false;
205  }
206 };
207 
208 // Return a pointer to a PlayerActor given it's ID
209 PlayerActor *getPlayerActorAddress(PlayerActorID id);
210 
211 // Return a PlayerActor ID given it's address
212 PlayerActorID getPlayerActorID(PlayerActor *p);
213 
214 // Return a pointer to the center actor
215 Actor *getCenterActor();
216 // Return the center actor's object ID
217 ObjectID getCenterActorID();
218 // Return the center actor's player actor ID
219 PlayerActorID getCenterActorPlayerID();
220 
221 // Set a new center actor based upon the PlayerActor ID
222 void setCenterActor(PlayerActorID newCenter);
223 
224 // Set a new center actor based upon the address of the actor's struct
225 void setCenterActor(Actor *newCenter);
226 
227 // Set a new center actor based upon the address of the PlayerActor
228 // struct
229 void setCenterActor(PlayerActor *newCenter);
230 
231 // Get the coordinates of the center actor
232 TilePoint centerActorCoords();
233 
234 // Set a player actor's aggression
235 void setAggression(PlayerActorID player, bool aggression);
236 
237 // Set the center actor's aggression
238 inline void setCenterActorAggression(bool aggression) {
239  setAggression(getCenterActorPlayerID(), aggression);
240 }
241 
242 // Determine the state of a player actor's aggression
243 bool isAggressive(PlayerActorID player);
244 
245 // Determine if center actor is aggressive
246 inline bool isCenterActorAggressive() {
247  return isAggressive(getCenterActorPlayerID());
248 }
249 
250 // Set a player actor's banding
251 void setBanded(PlayerActorID player, bool banded);
252 
253 // Determine if a player actor is banded
254 bool isBanded(PlayerActorID player);
255 
256 // Globally enable or disable player actor banding
257 void setBrotherBanding(bool enabled);
258 
259 // Adjust the player actors aggression setting based upon their
260 // proximity to enemies
261 void autoAdjustAggression();
262 
263 // Calculate the portrait for this brother's current state.
264 void recalcPortraitType(PlayerActorID id);
265 
266 // Returns an integer value representing this player actor's portrait
267 // state
268 int16 getPortraitType(PlayerActorID id);
269 
270 bool actorToPlayerID(Actor *a, PlayerActorID &result);
271 bool actorIDToPlayerID(ObjectID id, PlayerActorID &result);
272 
273 void handlePlayerActorDeath(PlayerActorID id);
274 
275 // Transport the center actor and the banded brothers who have a path
276 // the center actor
277 void transportCenterBand(const Location &loc);
278 
279 void handlePlayerActorAttacked(PlayerActorID id);
280 
281 void handleEndOfCombat();
282 
283 /* ======================================================================= *
284  PlayerActor list management function prototypes
285  * ======================================================================= */
286 
287 
288 // Initialize the player actor list
289 void initPlayerActors();
290 
291 void savePlayerActors(Common::OutSaveFile *out);
292 void loadPlayerActors(Common::InSaveFile *in);
293 
294 // Cleanup the player actor list
295 void cleanupPlayerActors();
296 
297 /* ======================================================================= *
298  CenterActor management function prototypes
299  * ======================================================================= */
300 
301 // Initialize the center actor ID and view object ID
302 void initCenterActor();
303 
304 void saveCenterActor(Common::OutSaveFile *outS);
305 void loadCenterActor(Common::InSaveFile *in);
306 
307 // Do nothing
308 inline void cleanupCenterActor() {}
309 
310 /* ======================================================================= *
311  PlayerActor iteration class
312  * ======================================================================= */
313 
315 protected:
316  int16 _index;
317 
318 public:
320  _index = 0;
321  }
322 
323  PlayerActor *first();
324  PlayerActor *next();
325 };
326 
327 // Iterates through all player actors that are not dead.
328 
330 
331 public:
333 
334  PlayerActor *first();
335  PlayerActor *next();
336 };
337 
338 } // end of namespace Saga2
339 
340 #endif
Definition: player.h:329
Definition: objproto.h:105
Definition: savefile.h:54
Definition: actor.h:32
Definition: contain.h:354
Definition: tcoords.h:127
Definition: stream.h:745
Definition: actor.h:589
Definition: player.h:314
Definition: player.h:43
Definition: objproto.h:1493
Definition: actor.h:96