Labyrinth
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
character.hpp
1 //////////////////////////////
2 //
3 // File: swrs/character.hpp
4 // Author: Maciej Kaminski
5 // E-mail: maciej.a.kaminski@gmail.com
6 // Website: maciejkaminski.pl
7 //
8 // File creation date: Oct 30 2012
9 // This file is part of Project Labyrinth
10 // This file is going to be released under terms of GNU GPL in near future
11 //
12 //////////////////////////////
13 
14 #ifndef __SW_CHARACT_H_
15 #define __SW_CHARACT_H_
16 #include "helper/tr1.hpp"
17 #include <vector>
18 #include <string>
19 namespace SWRS
20 {
21  class Trait;
22  class TraitMap;
23  class HindranceMap;
24  class EdgeMap;
25  class PowerMap;
26  class Feature;
27  class Edge;
28  class Hindrance;
29  class Power;
30 
31 
32  //! vector of traits owned by character
33  typedef std::vector<std::auto_ptr<Trait> > TraitVector;
34  //! vector of features owned by character
35  typedef std::vector<std::auto_ptr<Feature> > FeatureVector;
36  //! vector of powers owned by character
37  typedef std::vector<std::auto_ptr<Power> > PowerVector;
38 
39  //! interface for representing characters - constant (readonly) version
41  {
42  public:
43  //! return vector of all traits of character
44  virtual const TraitVector & GetTraitVector()const =0;
45  //! return vector of all edges of a character
46  virtual const FeatureVector & GetHindranceVector()const =0;
47  //! return vector of all edges
48  virtual const FeatureVector & GetEdgeVector()const =0;
49  //! all magical powers
50  virtual const PowerVector & GetPowerVector()const =0;
51  //! maximum amount of wounds character can suffer before being assumed as
52  //! dead (default for savage worlds rules system is 3 but can be defined as more)
53  virtual int GetMaxWounds()const=0;
54  //! Amount of experience points accumulated by a particular character
55  virtual int GetXP()const=0;
56  //! return pointer to trait object of given trait ID
57  //! (0 is returned if character has no such trait)
58  virtual const Trait * GetTrait(unsigned int id) const =0;
59  //! return pointer to trait object of given trait name
60  //! (0 is returned if character has no such trait)
61  virtual const Trait * GetTrait(const std::string & name) const =0;
62  //! get charisma of a particular character. default is 0 but can be altered
63  //! by edges
64  virtual int GetCharisma()const =0;
65  //! how fast does the character move
66  virtual int GetPace()const=0;
67  //! defensive characteristic dependent of "Fighting" trait
68  virtual int GetParry()const =0;
69  //! defensive characteristic dependent of "Vigor" trait
70  virtual int GetToughness()const=0;
71  //! for point build system
72  virtual int GetPowerPoints()const=0;
73  //! for point build system - how many powers can be chosen
74  virtual int GetPowerAllowance()const=0;
75  //! return pointer to hindrance object of a particular name
76  virtual const Hindrance * GetHindrance(const std::string & name)const =0;
77 
78  //! return pointer to edge object of a particular name
79  virtual const Edge * GetEdge(const std::string & name)const =0;
80  //! return pointer to magical power object of a particular name
81  virtual const Power * GetPower(const std::string & name)const =0;
82  //! return individual name of a character
83  virtual const std::string & GetName()const=0;
84  //! return race of a particular character (default is human)
85  virtual const std::string & GetRace()const=0;
86  //! how many points can be allocated to skills
87  virtual int GetSkillsPoints() const =0;
88  //! how many points can be allocated to attributes
89  virtual int GetAttributesPoints() const =0;
90  //! how many points can be allocated to edges
91  virtual int GetEdgesPoints() const =0;
92  //! some hindrances/edges require player to spend certain amount
93  //! of skill points onto skills linked to particular attributes
94  //! (i.e. Elderly grants 5 skill points that MUST be spent on skills
95  //! linked to Smaers)
96  virtual int GetRequiredSkillsPerAttribute(const std::string& attr_name) const=0;
97 
98  //! some hindrances decrease particular attributes. I.e.
99  //! elderly decreases Strength and Vigor by one;
100  //! - this decrease can be also an effect of powers (i.e.
101  //! debuff spells);
102  virtual int GetTraitLevelModifier(const std::string & attr_name) const=0;
103  //! virtual destructor for a polymorphic class
104  virtual ~IConstCharacter();
105  };
106  //! interface of a character
108  {
109  public:
110  //! get value in point build system of allocated skills
111  virtual int GetSkillsPointValue()const =0;
112  // for point build system
113  //! get value in point build system of allocated attributes
114  virtual int GetAttributesPointValue()const =0;
115  //! get amount of points left for attributes
116  virtual int GetSkillsPointsLeft()const =0;
117  //! for point build system
118  virtual int GetAttributesPointsLeft()const =0;
119 
120  //! which traits can be added
121  virtual const TraitVector & GetPossibleTraitVector()const =0;
122  //! which hindrances can be added
123  virtual const FeatureVector & GetPossibleHindranceVector()const =0;
124  //! which edges can be added
125  virtual const FeatureVector & GetPossibleEdgeVector()const =0;
126  //! which races can be selected
127  virtual const FeatureVector & GetPossibleRaceVector()const =0;
128  //! what powers are possible
129  virtual const PowerVector & GetPossiblePowerVector()const =0;
130  //! set max amount of wounds for character
131  virtual int SetMaxWounds(int _w)=0;
132  //! grant XP to a particular character
133  virtual int GrantXP(int XP)=0;
134  //! set XP value for a character (effects of lowering XP rating are undefined);
135  virtual int SetXP(int XP)=0;
136  //! add a trait
137  virtual int GrantTrait(const std::string & id)=0; // affects all copies
138  //! take trait away
139  virtual int RevokeTrait(const std::string & id)=0;
140  //! increase trait a one die level
141  virtual int IncreaseTrait(const std::string & id)=0;
142  //! decrease trait a one die level
143  virtual int DecreaseTrait(const std::string & id)=0;
144  //! add hindrance
145  virtual int GrantHindrance(const std::string &name)=0;
146  //! remove hindrance
147  virtual int RevokeHindrance(const std::string& name)=0;
148  //! grant edge
149  virtual int GrantEdge(const std::string &name)=0;
150  //! revoke edge
151  virtual int RevokeEdge(const std::string& name)=0;
152  //! add magical power
153  virtual int GrantPower(const std::string &name)=0;
154  //! remove magical power
155  virtual int RevokePower(const std::string& name)=0;
156  //! some hindrances can be added as minor or major
157  virtual int SetHindranceSeverity(const std::string & name, int severity)=0;
158  //! onto stdout
159  virtual int PrintCharacterSheet()const=0;
160  //! get character summary as a string
161  virtual const std::string GetCharacterSheet()const=0;
162  //! set name
163  virtual void SetName(const std::string & n)=0;
164  //! set race (out of available ones; effects of setting race which doesn't
165  //! exist in system are undefined)
166  virtual void SetRace(const std::string & n)=0;
167  virtual ~ICharacter();
168  //! how many major minor hindrances does the character have
169  virtual int GetNumMinorHindrances()const=0;
170  //! how many major major hindrances does the character have
171  virtual int GetNumMajorHindrances()const=0;
172  //! how many points are there left for edges
173  virtual int GetEdgePointsLeft()const=0;
174  //! is point limit enabled ? (for editor)
175  virtual bool GetPointLimitEnabled()const=0;
176  //! enable point limit
177  virtual void SetPointLimitEnabled(bool pl)=0 ;
178  //! how many powers are allowed
179  virtual int GetPowerAllowanceLeft()const=0;
180  //! \brief prevent from decreasing characteristics below current level
181  //! (after rising they may however be decreaset down to current level)
182  virtual void LockLevel()=0;
183  //! cancel effects of LockLevel
184  virtual void UnlockLevel()=0;
185 
186  };
187  class FeatureMap;
188  class RaceMap;
189  //! how badly is character wounded/fatigued
191  {
192  int stunned;
193  int wounds; // up to 4; 3 is safe; - really generalized
194  int fatigue; // up to 3; 2 is safe;
195  public:
196  //! default constructor
198  {
199  stunned=wounds=fatigue=0;
200  }
201  //
202  //! get amount of wounds already suffered by a character
203  int GetWounds() const
204  {
205  return wounds;
206  }
207  //! inflicit wound upon a character
208  int Wound(int amount)
209  {
210  wounds+=amount;
211  return wounds;
212  }
213  //! set amount of wounds (may decrease them to 0) suffered by character
214  void SetWounds(int amount)
215  {
216  wounds=amount;
217  }
218  };
219 
220  //! proper representation of a character in rules system
221  class Character: public ICharacter
222  {
223  friend class RulesSystem;
224  CharacterCondition cond;
225  typedef std::tr1::shared_ptr<ICharacter> pCharacterImpl;
226  pCharacterImpl pimpl;
227  Character(const TraitMap & TM,
228  const HindranceMap & HM,
229  const EdgeMap & EM,
230  const RaceMap & RM,
231  const PowerMap & PM);
232  public:
233  //! returns false if in unusable state
234  bool IsInValidState() const {return !!pimpl.use_count();}
235  //! copy constructor. condition is copied, but ruleset is link-copied (multiple ownership)
236  Character(const Character & base)
237  :
238  cond(base.cond),
239  pimpl(base.pimpl)
240  {
241  }
242  ~Character() {}
243 
244  int GetMaxWounds()const
245  {
246  return pimpl->GetMaxWounds();
247  }
248  int GetXP()const
249  {
250  return pimpl->GetXP();
251  }
252 
253 
254  int SetMaxWounds(int _w)
255  {
256  return pimpl->SetMaxWounds(_w);
257  }
258  int SetXP(int XP)
259  {
260  return pimpl->SetXP(XP);
261  }
262 
263  int GrantXP(int XP)
264  {
265  return pimpl->GrantXP(XP);
266  }; // affects ALL copies;
267  /* Character Clone()
268  {
269  Character result = *this;
270  return result;
271  }*/
272  int GrantTrait(const std::string & id) // affects all copies
273  {
274  return pimpl->GrantTrait(id);
275  }
276  int RevokeTrait(const std::string & id)
277  {
278  return pimpl->RevokeTrait(id);
279  }
280  int GrantPower(const std::string & id) // affects all copies
281  {
282  return pimpl->GrantPower(id);
283  }
284  int RevokePower(const std::string & id)
285  {
286  return pimpl->RevokePower(id);
287  }
288  int IncreaseTrait(const std::string & id)
289  {
290  return pimpl->IncreaseTrait(id);
291  }
292  int DecreaseTrait(const std::string & id)
293  {
294  return pimpl->DecreaseTrait(id);
295  }
296  int GrantHindrance(const std::string & id) // affects all copies
297  {
298  return pimpl->GrantHindrance(id);
299  }
300  int RevokeHindrance(const std::string & id)
301  {
302  return pimpl->RevokeHindrance(id);
303  }
304  int GrantEdge(const std::string & id) // affects all copies
305  {
306  return pimpl->GrantEdge(id);
307  }
308  int RevokeEdge(const std::string & id)
309  {
310  return pimpl->RevokeEdge(id);
311  }
312  int SetHindranceSeverity(const std::string & name, int severity)
313  {
314  return pimpl->SetHindranceSeverity(name,severity);
315  }
317  {
318  return pimpl->PrintCharacterSheet();
319  }
320  const std::string GetCharacterSheet()const
321  {
322  return pimpl->GetCharacterSheet();
323  }
325  {
326  return pimpl->GetPowerVector();
327  }
329  {
330  return pimpl->GetPossiblePowerVector();
331  }
333  {
334  return pimpl->GetTraitVector();
335  }
337  {
338  return pimpl->GetPossibleTraitVector();
339  }
341  {
342  return pimpl->GetPossibleEdgeVector();
343  }
344 
346  {
347  return pimpl->GetPossibleHindranceVector();
348  }
350  {
351  return pimpl->GetPossibleRaceVector();
352  }
353 
355  {
356  return pimpl->GetHindranceVector();
357  }
359  {
360  return pimpl->GetEdgeVector();
361  }
362  // for point build system
364  {
365  return pimpl->GetSkillsPointValue();
366  }
367  // for point build system
369  {
370  return pimpl->GetAttributesPointValue();
371  }
373  {
374  return pimpl->GetSkillsPointsLeft();
375  }
376  // for point build system
378  {
379  return pimpl->GetAttributesPointsLeft();
380  }
382  {
383  return pimpl->GetPointLimitEnabled();
384  }
385  void SetPointLimitEnabled(bool pl)
386  {
387  pimpl->SetPointLimitEnabled(pl);
388  }
389 
390  const Trait * GetTrait(unsigned int id) const __attribute__((deprecated))
391  {
392  return pimpl->GetTrait(id);
393  }
394  const Trait * GetTrait(const std::string & name) const
395  {
396  return pimpl->GetTrait(name);
397  }
398 
399  int GetCharisma()const
400  {
401  return pimpl->GetCharisma();
402  }
403  int GetPace()const
404  {
405  return pimpl->GetPace();
406  }
407  int GetParry()const
408  {
409  return pimpl->GetParry();
410  }
411  int GetToughness()const
412  {
413  return pimpl->GetToughness();
414  }
415  int GetPowerPoints()const
416  {
417  return pimpl->GetPowerPoints();
418  }
419  int GetPowerAllowance()const
420  {
421  return pimpl->GetPowerAllowance();
422  }
424  {
425  return pimpl->GetPowerAllowanceLeft();
426  }
427 
428  const Hindrance * GetHindrance(const std::string & name) const
429  {
430  return pimpl->GetHindrance(name);
431  }
432  const Edge * GetEdge(const std::string & name) const
433  {
434  return pimpl->GetEdge(name);
435  }
436  const Power * GetPower(const std::string & name) const
437  {
438  return pimpl->GetPower(name);
439  }
440  const std::string & GetName()const
441  {
442  return pimpl->GetName();
443  }
444  void SetName(const std::string & n)
445  {
446  pimpl->SetName(n);
447  }
448  const std::string & GetRace()const
449  {
450  return pimpl->GetRace();
451  }
452  void SetRace(const std::string & n)
453  {
454  pimpl->SetRace(n);
455  }
457  {
458  return pimpl->GetNumMinorHindrances();
459  }
461  {
462  return pimpl->GetNumMajorHindrances();
463  }
464  int GetEdgePointsLeft()const
465  {
466  return pimpl->GetEdgePointsLeft();
467  }
468  int GetSkillsPoints() const
469  {
470  return pimpl->GetSkillsPoints();
471  }
472  int GetAttributesPoints() const
473  {
474  return pimpl->GetAttributesPoints();
475  }
476  int GetEdgesPoints() const
477  {
478  return pimpl->GetEdgesPoints();
479  } // for human
480  int GetRequiredSkillsPerAttribute(const std::string& attr_name) const
481  {
482  return pimpl->GetRequiredSkillsPerAttribute(attr_name);
483  }
484 
485  int GetTraitLevelModifier(const std::string & trait_name) const
486  {
487  return pimpl->GetTraitLevelModifier(trait_name);
488  }
489  //! get amount of wounds already suffered by a character
490  virtual int GetWounds()const
491  {
492  return cond.GetWounds();
493  }
494  //! set amount of wounds (may decrease them to 0) suffered by character
495  virtual void SetWounds(int amount)
496  {
497  cond.SetWounds(amount);
498  }
499  //! inflicit wound upon a character
500  virtual int Wound(int amount)
501  {
502  return cond.Wound(amount);
503  }
504  void LockLevel()
505  {
506  pimpl->LockLevel();
507  }
508  void UnlockLevel()
509  {
510  pimpl->UnlockLevel();
511  }
512 
513  };
514 }
515 
516 #endif