Labyrinth
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
characterimpl.hpp
1 //////////////////////////////
2 //
3 // File: swrs/characterimpl.hpp
4 // Author: Maciej Kaminski
5 // E-mail: maciej.a.kaminski@gmail.com
6 // Website: maciejkaminski.pl
7 //
8 // File creation date: Feb 12 2013
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_IMPL_H_
15 #define __SW_CHARACT_IMPL_H_
16 #include "swrs/character.hpp"
17 #include <string>
18 #include "swrs/racemap.hpp"
19 #include "swrs/powermap.hpp"
20 #include <memory>
21 namespace SWRS
22 {
23 
24  //! implementation of a character in rules system[pIMPL idiom]
25  class CharacterImpl: public ICharacter
26  {
27  friend class Character;
28  const TraitMap & trait_map;
29  const HindranceMap & hindrance_map;
30  const EdgeMap & edge_map;
31  const RaceMap & race_map;
32  const PowerMap & power_map;
33  //! experience points
34  int XP;
35  //! max amount of wounds suffered by character
36  int maxwounds;
37  //! is character "heroic"
38  bool heroic;
39  //! race of a character
40  std::unique_ptr<Race> race;
41  //! id/value pairs
42  mutable TraitVector possible_trait_vector;
43  //! current character traits
44  TraitVector trait_vector;
45  //! possible traits
46  mutable FeatureVector possible_hindrance_vector;
47  //! possible edges
48  mutable FeatureVector possible_edge_vector;
49  //! possible races
50  mutable FeatureVector possible_race_vector;
51  //!hindrances
52  FeatureVector hindrance_vector;
53  //! edges
54  FeatureVector edge_vector;
55  //! possible (to acquire) powers
56  mutable PowerVector possible_power_vector;
57  //! powers posessed by character
58  PowerVector power_vector;
59  //! when enabled, class disallows rising traits above limitations
60  bool point_limit_enabled;
61  //! character name
62  std::string name;
63  //! recompute (rearrange) features stack
64  void StackFeatures();
65  //! recompute (rearrange) stacked trait modifiers
66  void StackTraitModifiers();
67  //! first feature on stack
68  IConstCharacter * features_stack_top;
69 
70  //! template class for setting options
71  template<class OPTION_TYPE, class VECTOR_TYPE>
72  OPTION_TYPE *GetOption(const std::string & name,
73  const VECTOR_TYPE & source_vector) const;
74 
75 
76  //! template class for granting options
77  template<class OPTION_TYPE, class VECTOR_TYPE>
78  int GrantOption(const std::string & name,
79  VECTOR_TYPE & source_vector,
80  VECTOR_TYPE & possibilities_vector,
81  OPTION_TYPE * option)
82  ;
83  //! template class for revoking options
84  template<class OPTION_TYPE, class VECTOR_TYPE>
85  int RevokeOption(const std::string & name,
86  VECTOR_TYPE & source_vector,
87  VECTOR_TYPE & possibilities_vector);
88 
89 
90  //! get feature by name
91  Feature *GetFeature(const std::string & name,
92  const FeatureVector & source_vector) const;
93 
94 
95  //! grant feature to character
96  int GrantFeature(const std::string & name,
97  FeatureVector & source_vector,
98  FeatureVector & possibilities_vector,
99  Feature * feature)
100  ;
101  //! revoke feature from character
102  int RevokeFeature(const std::string & name,
103  FeatureVector & source_vector,
104  FeatureVector & possibilities_vector);
105  //! \brief return possible features vector based on reference vector
106  //! (what is possible - what we have)
107  const FeatureVector & GetPossibleFeaturesVector
108  (FeatureVector & target_vector, const FeatureVector & reference_vector,
109  const OptionsMap & map)const;
110  protected:
111  //! name of trait by id
112  const std::string& GetTraitName(int id)const;
113  //! id of trait by name
114  int GetTraitId(const std::string & name) const;
115  //! how many points for skills
116  int GetDefaultSkillsPoints() const {return 15;}
117  //! how many points for attributes
118  int GetDefaultAttributesPoints() const {return 5;}
119  //! how many points for edges
120  int GetDefaultEdgesPoints() const {return 0;} // for human
121  //! any extra points from having hindrances?
122  int GetExtraPointsFromHindrances() const;
123  //! character advancement
125  {return 2*GetXP()/5;}
126  //! how many extra points are already used on skills
127  int GetExtraPointsUsedOnSkills() const;
128  //! how many extra points are already used on attributes
129  int GetExtraPointsUsedOnAttributes() const;
130  //! how many extra points are already used on edges
131  int GetExtraPointsUsedOnEdges() const;
132  //! how many extra points are left for skils
133  int GetExtraPointsForSkills() const;
134  //! how many extra points are left for attributes
135  int GetExtraPointsForAttributes() const;
136  //! how many extra points are left for edges
137  int GetExtraPointsForEdges() const;
138 
139  public:
140  int GetSkillsPoints() const ;
141  int GetAttributesPoints() const ;
142  int GetEdgesPoints() const ;
143  //! some hindrances/edges require player to spend certain amount
144  //! of skill points onto skills linked to particular attributes
145  //! (i.e. Elderly grants 5 skill points that MUST be spent on skills
146  //! linked to Smaers)
147  int GetRequiredSkillsPerAttribute(const std::string& attr_name) const ;
148 
149  //! some hindrances decrease particular attributes. I.e.
150  //! elderly decreases Strength and Vigor by one;
151  //! - this decrease can be also an effect of powers (i.e.
152  //! debuff spells);
153  int GetTraitLevelModifier(const std::string & trait_name) const ;
154  //! constructor (only possible)
155  CharacterImpl(const TraitMap & TM,
156  const HindranceMap & HM,
157  const EdgeMap & EM,
158  const RaceMap & RM,
159  const PowerMap & PM);
160  //! destructor
162 
163  int GetMaxWounds()const
164  {
165  return maxwounds;
166  }
167  int GetXP()const
168  {
169  return XP;
170  }
171 
172 
173  int SetMaxWounds(int _w)
174  {
175  maxwounds=_w;
176  return 0;
177  }
178  int SetXP(int XP)
179  {
180  this->XP=XP;
181  return 0;
182  }
183 
184 
185  int GrantXP(int XP)
186  {
187  this->XP+=XP;
188  return 0;
189  };
190  //! set if character counts as heroic (it affects advancement options etc.)
191  bool SetHeroic(bool heroic);
192  const std::string & GetRace()const;
193  void SetRace(const std::string & n);
194 
195  //! add a trait
196  int GrantTrait(unsigned int id); // affects all copies
197  //! take trait away
198  int RevokeTrait(unsigned int id);
199  //! increase trait a one die level
200  int IncreaseTrait(unsigned int id);
201  //! decrease trait a one die level
202  int DecreaseTrait(unsigned int id);
203  int GrantTrait(const std::string & id); // affects all copies
204  int RevokeTrait(const std::string & id);
205  int IncreaseTrait(const std::string & id);
206  int DecreaseTrait(const std::string & id);
207  int GrantHindrance(const std::string & name);
208  int RevokeHindrance(const std::string & name);
209  int GrantEdge(const std::string & name);
210  int RevokeEdge(const std::string & name);
211  //! roll on a trait by id
212  int RequestRoll(unsigned int trait_id, int modifier);
213  int SetHindranceSeverity(const std::string & name, int severity);
214  int PrintCharacterSheet()const ;
215  const std::string GetCharacterSheet()const;
216  const TraitVector & GetPossibleTraitVector()const;
218  {
219  return trait_vector;
220  }
222  const FeatureVector & GetPossibleEdgeVector()const;
223  const FeatureVector & GetPossibleRaceVector()const;
224 
226  {
227  return hindrance_vector;
228  }
230  {
231  return edge_vector;
232  }
233  bool GetPointLimitEnabled()const {return point_limit_enabled;}
234  void SetPointLimitEnabled(bool pl) { point_limit_enabled=pl;}
235  int GetSkillsPointValue()const;
236  int GetAttributesPointValue()const;
237  int GetSkillsPointsLeft()const;
238  int GetAttributesPointsLeft()const;
239  //! if both skills and attributes are within point build system
240  //! limitations?
242  {
243  return GetAttributesPointsLeft()>=0
244  && GetSkillsPointsLeft()>=0;
245  }
246  const Trait * GetTrait(unsigned int id) const
247  {
248  if (id>=trait_vector.size())
249  return 0;
250  else
251  return trait_vector[id].get();
252  }
253  const Trait * GetTrait(const std::string & name) const;
254  const Hindrance * GetHindrance(const std::string & name) const;
255  const Edge * GetEdge(const std::string & name) const;
256  const Power * GetPower(const std::string & name) const;
257 
258  int GetCharisma()const;
259  int GetPace()const;
260  int GetParry()const;
261  int GetToughness()const;
262  int GetPowerPoints()const;
263  int GetPowerAllowance()const;
265  {
266  return GetPowerAllowance()-power_vector.size();
267  }
268 
269  const std::string & GetName()const
270  {
271  return name;
272  }
273  void SetName(const std::string & n)
274  {
275  name.assign(n);
276  }
277  int GetNumMinorHindrances()const;
278  int GetNumMajorHindrances()const;
279  int GetEdgePointsLeft()const;
280 
282  {
283  return power_vector;
284  }
285  const PowerVector & GetPossiblePowerVector()const;
286  int GrantPower(const std::string & id);
287  int RevokePower(const std::string & id);
288 
289  void LockLevel();
290  void UnlockLevel();
291  };
292 }
293 
294 #endif