JNR
rpgSkill.cpp
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 */
29 
30 #include "stdafx.h"
31 #include "RPG.h"
32 #include <Core\Core-Level-JR.h>
33 
34 rpgSkill::rpgSkill(void)
35 {
36  _strName[0] = '\0';
37  _strDescription[0] = '\0';
38  _pTSE = NULL;
39 
40  _bLearnt = M_FALSE;
41  _nLevelPererequisite = 1;
42  _nUpgradeLevel = 0;
43 
44 }
45 
46 // Load from TS
47 //
48 void rpgSkill::load(class laPropertyList* pElement)
49 {
50  _pTSE = pElement;
51 
52  // Load training status
53  //
54  try{
55  _bLearnt = pElement->getBool("learnt");
56  } catch(laError_PropertyNotDefined&){ _bLearnt = M_FALSE; }
57 
58  try{
59  _nUpgradeLevel = pElement->getInt("upgrade-level");
60  } catch(laError_PropertyNotDefined&){ _nUpgradeLevel = 0; }
61 
62  // Load core data about the skill
63  //
64  strcpy(_strName, pElement->name());
65  strcpy(_strDescription, pElement->getText("description"));
66 
67  try{
68  unsigned nLevel = 0;
69  while(1)
70  {
71  char strUpgrade[64];
72  sprintf(strUpgrade, "upgrade-%d", nLevel++);
73 
74  rpgSheet_PlayableChar_Mods upgrade_mods;
75  upgrade_mods.load(pElement->getChild(strUpgrade)); // load upgrade level
76 
77  _vUpgradeLevels.push_back(upgrade_mods);
78  }
79  } catch(laError_PropertyNotDefined&){ }
80 
81  _nLevelPererequisite = pElement->getInt("level-prerequisite");
82  pElement->getText("description");
83 }
84 
89 void rpgSkill::load(class laFileParser *fp)
90 {
91  ASSERT(M_FALSE, "Not implemented.");
92 }
93 
94 //void save(class laFileParser *fp);
95 
96 // Load from TS
97 //
98 void rpgSkillsInventory::load(laPropertyList* pElement)
99 {
100  unsigned nSkill = 0;
101 
102  try{
103  while(1)
104  {
105  char strPropertyName[64], strSkillName[64];
106  sprintf(strPropertyName, "skill-%d", nSkill++);
107  strcpy(strSkillName, pElement->getText(strPropertyName));
108 
109  rpgSkill skill;
110  laPropertyList* pSkillElem = pElement->getParent()->getChild(strSkillName);
111 
112  skill.load( pSkillElem ); // load the skill
113  _vSkills.push_back(skill);
114 
115  MLOG("Skill '%s' loaded.", skill.name());
116  }
117  } catch(laError_PropertyNotDefined&){ MLOG("%d Skills loaded", nSkill-1); }
118 }
119 
124 void rpgSkillsInventory::load(class laFileParser *fp)
125 {
126  ASSERT(M_FALSE, "Not implemented.");
127 }
128 //void save(class laFileParser *fp);
File Parser.
Definition: laFileParser.h:41