Labyrinth
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
trait.hpp
1 //////////////////////////////
2 //
3 // File: swrs/trait.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_TRAIT_H_
15 #define __SW_TRAIT_H_
16 #include "swrs/option.hpp"
17 #include <string>
18 namespace SWRS
19 {
20  //! \brief dataset associated with particular trait type
21  //! (class of multiple ownership, one instance per trait per ruleset)
23  {
24  public:
25  //! name of trait (displayable)
26  std::string name;
27  //! flavor text to be displayed in character editor
28  std::string flavor_text;
29  //! if empty string, than no particular edge is required
30  std::string required_edge;
31  //!for attributes it's undefined;
32  std::string linked_attribute_name;
33  //! \brief id of attrinbute linked to trait;
34  //! if trait has linked attribute,
35  //! it is a skill, otherwise it is an attribute itself
37  };
38  //! roll a die in SW rules system - exploding dice; recursive implementation;
39  //! function does not do trait test, it's just a dice roll
40  //! \param die 4,6,8,10,12, potentially other
41  //! \param modifier is a number added to final result
42  int RollDie(int die, int modifier);
43 
44  //! generic class for character binary trait - requirements, modifiers etcetera
45  class Trait:public IOption
46  {
47  friend class Skill;
48  friend class TraitMap;
49  protected:
50  //! from race/edges/whatever
52  //! roll additional d6 to chose higher result?
54  //! proper trait value
55  int main_die;
56  //! untrained? If so, -2 to both main and heroic die
57  bool untrained;
58  //! For point build system; affects how real level is calculated
60  //! constructor is protected for object of this class can only be factory
61  //! generated, and never constructed of nothing
62  Trait(const TraitRecord * tr) ;
63 
64  //!cannot be decreased below
65  int min_level;
66  //! 0 - untrained; 1-d4, 2-d6, 3-d8, 4-d10, 5-d12
67  int GetObjectiveLevel()const;
68  //! alternative names of traits
69  std::string custom_name;
70  //! data record pointer
72  //! set custom name (see above)
73  void SetCustomName(std::string s) {custom_name.assign(s);}
74  //! For limitations in point build system
75  virtual int GetMaxObjectiveLevel()const;
76  //! For limitations in point build system
77  virtual int GetMinObjectiveLevel()const;
78  public:
79  //! Generic name of trait
80  const std::string & GetBaseName()const
81  {
82  return trait_record->name;
83  }
84 
85  //! make it impossible to decrease trait below current level
86  void LockLevel()
87  {
89  }
90  //! cancel effect of LockLevel;
91  void UnlockLevel()
92  {
93  min_level=0;
94  }
95  //! if an edge is required to posess a trait
96  const std::string & GetRequiredEdge()const
97  {
99  }
100  //! return customized name (if exists);
101  const std::string & GetCustomName()const
102  {
103  return custom_name;
104  }
105  //! Get fluff description
106  const std::string & GetFlavorText() const
107  {
108  return trait_record->flavor_text;
109  }
110  //! Copy constructor
111  Trait(const Trait & cSource)
112  {
113  custom_name=cSource.custom_name;
114  trait_record=cSource.trait_record;
116  heroic_die=cSource.heroic_die;
117  main_die=cSource.main_die;
118  untrained=cSource.untrained;
120  }
121  //! Set level modifier for particular trait (i.e. it
122  //! may always count as one die higher)
123  void SetLevelModifier(int i);
124  //! get trait name; if custom name is set, it is returned; otherwise
125  //! default name is returned
126  const std::string & GetName()const
127  {
128  if (custom_name.empty())
129  return trait_record->name;
130  else
131  return custom_name;
132  }
133  //! increase by one level; true is returned if it was impossible; false
134  //! is returned upon success
135  virtual bool Increase() ;
136  //! decrease by one level; true is returned if it was impossible; false
137  //! is returned upon success
138  virtual bool Decrease();
139  //! if trait is at d6 level, 6 is returned; for d12+2, 12 is returned
140  int GetMainDie()const{return main_die;}
141  //! set if heroic die is used
142  bool SetHeroic(bool heroic);
143  //! if roll is marginally successful - result is 0;
144  //! if roll is failed - result is negative (amount of pips missing to success)
145  //! if roll is successful over requirement - result is positive (as above).
146  int Roll(int modifier) const;
147  //! Returns SW description of trait level
148  std::string GetSW() const;
149  //! returns detailet version of GetSW()
150  std::string GetSWVerbose() const;
151  //! print GetSW() to stdout
152  int PrintSW() const;
153  //! in point build system;
154  virtual int GetPointValue() const{return 0;}
155  //! Print verbal representation of a trait (i.e. "novice (1)" or "skilled (3)")
156  int PrintVerbal() const;
157  //! Get verbal representation of a trait (i.e. "novice (1)" or "skilled (3)")
158  std::string GetVerbal() const;
159  //! data dump, all modifiers etc to stdout
160 
161  int PrintVerbatim() const;
162  //! 0-2-3-4-5-6 ; i.e. for purpose of parry/toughness calculation
163  int GetHalfNumericValue() const;
164  //! if it is an untrained characteristic, return true
165  bool IsUntrained() const
166  {
167  return untrained;
168  }
169  };
170  //! attributes, or characteristics that do not depend on others
171  class Attribute: public Trait
172  {
173  friend class TraitMap;
174  //! Attribute constructor
175  Attribute(const TraitRecord * tr) ;
176  public:
177  virtual int GetMinObjectiveLevel()const;
178  //bool Decrease();
179  int GetPointValue() const;
180  };
181  //! skills, traits that depends on atteibutes
182  class Skill: public Trait
183  {
184  friend class TraitMap;
185  //! attribute linked to particular skill - used in calculating point values etc
186  const Attribute * linked_attribute;
187  //! Constructor (called from TraitMap)
188  Skill(const Attribute * linked,const TraitRecord * tr)
189  : Trait(tr),linked_attribute(linked) {}
190  public:
191  int GetPointValue() const;
192  //! get parent attribute of skill
193  const Attribute * GetParent()const { return linked_attribute;}
194  };
195 }
196 #endif