JNR
rpgSkill.h
1 /*
2 
3 Jump'n'Run Engine
4 http://www.atanaslaskov.com/jnr/
5 
6 BSD LICENSE
7 Copyright (c) 2007-2013, Atanas Laskov
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 1. Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 2. Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 */
30 
31 
32 class rpgSkill
33 {
34 protected:
35  char _strName[64];
36  char _strDescription[64];
37  laPropertyList* _pTSE;
38 
39  unsigned _nLevelPererequisite;
40 
41  std::vector<rpgSheet_PlayableChar_Mods> _vUpgradeLevels;
42 
43  M_BOOL _bLearnt;
44  unsigned _nUpgradeLevel;
45 
46 public:
47  rpgSkill(void);
48 
49  // Get stuff
50  //
51  inline char* name(){
52  return _strName;
53  }
54 
55  inline char* desc(){
56  return _strDescription;
57  }
58 
59  inline unsigned prerequisite(){
60  return _nLevelPererequisite;
61  }
62 
63  inline laPropertyList* getTSEement(){
64  return _pTSE;
65  };
66 
67  // Active/inactive
68  //
69  inline M_BOOL isLearnt(){
70  return _bLearnt;
71  }
72 
73  inline void learn(){
74  _bLearnt = M_TRUE;
75  }
76 
77  // Upgrade levels
78  //
79  inline void upgrade(){
80  ASSERT( (!isLearnt()) || (_nUpgradeLevel + 1 < _vUpgradeLevels.size()),
81  "Upgrade level %d not defined", _nUpgradeLevel+1);
82 
83  if(!isLearnt()) learn();
84  else _nUpgradeLevel++;
85  }
86 
87  inline rpgSheet_PlayableChar_Mods* getUpgrade(unsigned nLevel){
88  ASSERT(nLevel < _vUpgradeLevels.size(),
89  "Upgrade level %d not defined", _nUpgradeLevel+1);
90  return &(_vUpgradeLevels[nLevel]);
91  }
92 
93  inline rpgSheet_PlayableChar_Mods* getCurrentUpgrade(){
94  return getUpgrade(_nUpgradeLevel);
95  }
96 
97  inline unsigned getCurrentIndex(){
98  return _nUpgradeLevel;
99  }
100 
101  inline unsigned getUpgradeCount(){
102  return _vUpgradeLevels.size();
103  }
104 
105  // Load from TS
106  virtual void load(class laPropertyList* pElement);
107 
112  virtual void load(class laFileParser *fp);
113  //void save(class laFileParser *fp);
114 };
115 
116 class rpgSkillsInventory{
117 protected:
118  std::vector<rpgSkill> _vSkills;
119  //NOTE: map? slower, probably no need;
120 
121 public:
122 
123  inline rpgSkill* skill(unsigned n)
124  {
125  ASSERT( n < _vSkills.size(), "Undefined skill %d.", n);
126  return &(_vSkills[n]);
127  }
128 
129  inline unsigned size(){
130  return _vSkills.size();
131  }
132 
133  // Load from TS
134  virtual void load(class laPropertyList* pElement);
135 
140  virtual void load(class laFileParser *fp);
141  //void save(class laFileParser *fp);
142 };
File Parser.
Definition: laFileParser.h:41