1 /*************************************************************************** 2 rpg.h - Classes for character attributes 3 ------------------- 4 begin : Sat May 3 2003 5 copyright : (C) 2003 by Gabor Torok 6 email : cctorok@yahoo.com 7 ***************************************************************************/ 8 9 /*************************************************************************** 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 ***************************************************************************/ 17 18 #ifndef RPG_H 19 #define RPG_H 20 #pragma once 21 22 #include "../configlang.h" 23 #include "../util.h" 24 #include <vector> 25 #include <map> 26 27 class SkillGroup; 28 29 /// Inits the RPG framework. 30 class Rpg { 31 private: 32 static std::vector<std::string> firstSyl; 33 static std::vector<std::string> midSyl; 34 static std::vector<std::string> endSyl; 35 36 public: 37 static void initRpg(); 38 static void unInitRpg(); 39 static std::string createName(); 40 41 protected: 42 static void initSkills( ConfigLang *config ); 43 static void initNames( ConfigLang *config ); 44 static void initStateMods( ConfigLang *config ); 45 }; 46 47 /// An attribute or skill. 48 class Skill { 49 private: 50 char name[80]; 51 char displayName[255]; 52 char description[120]; 53 char symbol[80]; 54 float alignment; 55 std::vector<Skill*> preReqStats; 56 int preReqStatMultiplier; 57 int index; 58 SkillGroup *group; 59 60 public: 61 62 // FIXME: this should be generated from professions.txt 63 // ======================================= 64 // Note: order must match that in world/rpg.txt! 65 // ======================================= 66 enum { 67 SPEED = 0, 68 COORDINATION, 69 POWER, 70 IQ, 71 LEADERSHIP, 72 LUCK, 73 PIETY, 74 LORE, 75 76 MELEE_WEAPON, 77 RANGED_WEAPON, 78 LARGE_WEAPON, 79 HAND_TO_HAND_COMBAT, 80 81 SHIELD_DEFEND, 82 ARMOR_DEFEND, 83 DODGE_ATTACK, 84 85 LIFE_AND_DEATH_MAGIC, 86 DECEIT_MAGIC, 87 CONFRONTATION_MAGIC, 88 RESIST_LIFE_AND_DEATH_MAGIC, 89 RESIST_DECEIT_MAGIC, 90 RESIST_CONFRONTATION_MAGIC, 91 92 NATURE_MAGIC, 93 AWARENESS_MAGIC, 94 RESIST_NATURE_MAGIC, 95 RESIST_AWARENESS_MAGIC, 96 97 HISTORY_MAGIC, 98 RESIST_HISTORY_MAGIC, 99 ENCHANT_ITEM, 100 IDENTIFY_ITEM, 101 IDENTIFY_CREATURE, 102 103 OPEN_LOCK, 104 FIND_TRAP, 105 FIND_SECRET_DOOR, 106 MOVE_UNDETECTED, 107 STEALING, 108 109 SKILL_COUNT 110 }; 111 112 Skill( char *name, char *displayName, char *description, char *symbol, float alignment, SkillGroup *group ); 113 ~Skill(); 114 setPreReqMultiplier(int n)115 inline void setPreReqMultiplier( int n ) { 116 preReqStatMultiplier = n; 117 } getPreReqMultiplier()118 inline int getPreReqMultiplier() { 119 return preReqStatMultiplier; 120 } addPreReqStat(Skill * stat)121 inline void addPreReqStat( Skill *stat ) { 122 preReqStats.push_back( stat ); 123 } getPreReqStatCount()124 inline int getPreReqStatCount() { 125 return preReqStats.size(); 126 } getPreReqStat(int index)127 inline Skill *getPreReqStat( int index ) { 128 return preReqStats[ index ]; 129 } 130 getName()131 inline char *getName() { 132 return name; 133 } getDisplayName()134 inline char const* getDisplayName() { 135 return displayName; 136 } getDescription()137 inline char *getDescription() { 138 return description; 139 } getSymbol()140 inline char *getSymbol() { 141 return symbol; 142 } getAlignment()143 inline float getAlignment() { 144 return alignment; 145 } getGroup()146 inline SkillGroup *getGroup() { 147 return group; 148 } getIndex()149 inline int getIndex() { 150 return index; 151 } 152 153 static std::map<std::string, Skill*> skillsByName; 154 getSkillByName(char const * name)155 static inline Skill *getSkillByName( char const* name ) { 156 std::string s = name; 157 return( skillsByName.find( s ) == skillsByName.end() ? NULL : skillsByName[ s ] ); 158 } 159 getSkillIndexByName(char const * name)160 static inline int getSkillIndexByName( char const* name ) { 161 Skill *skill = getSkillByName( name ); 162 return( skill ? skill->getIndex() : -1 ); 163 } 164 165 // fast access 166 static std::vector<Skill*> skills; 167 }; 168 169 /// A group of related skills. 170 class SkillGroup { 171 private: 172 char name[80]; 173 char displayName[255]; 174 char description[255]; 175 int index; 176 bool isStatSkill; 177 std::vector<Skill*> skills; 178 179 public: 180 SkillGroup( char *name, char *displayName, char *description ); 181 ~SkillGroup(); 182 isStat()183 inline bool isStat() { 184 return isStatSkill; 185 } getName()186 inline char *getName() { 187 return name; 188 } getDisplayName()189 inline char *getDisplayName() { 190 return displayName; 191 } getDescription()192 inline char *getDescription() { 193 return description; 194 } getIndex()195 inline int getIndex() { 196 return index; 197 } 198 getSkillCount()199 inline int getSkillCount() { 200 return skills.size(); 201 } getSkill(int index)202 inline Skill *getSkill( int index ) { 203 return skills[ index ]; 204 } addSkill(Skill * skill)205 inline void addSkill( Skill *skill ) { 206 skills.push_back( skill ); 207 } getRandomSkill()208 inline Skill *getRandomSkill() { 209 return getSkill( Util::dice( getSkillCount() ) ); 210 } 211 212 static SkillGroup *stats; 213 static std::map<std::string, SkillGroup *> groupsByName; getGroupByName(char const * name)214 static inline SkillGroup *getGroupByName( char const* name ) { 215 std::string s = name; 216 return( groupsByName.find( s ) == groupsByName.end() ? NULL : groupsByName[ s ] ); 217 } 218 219 // fast access 220 static std::vector<SkillGroup*> groups; 221 }; 222 223 /// A state mod. 224 class StateMod { 225 private: 226 char name[80]; 227 char displayName[255]; 228 char symbol[255]; 229 char setState[255]; 230 char unsetState[255]; 231 int type; 232 int index; 233 234 public: 235 enum { 236 blessed = 0, 237 empowered, 238 enraged, 239 ac_protected, 240 magic_protected, 241 drunk, 242 poisoned, 243 cursed, 244 possessed, 245 blinded, 246 paralysed, 247 invisible, 248 overloaded, 249 dead, 250 asleep, 251 252 // must be last 253 STATE_MOD_COUNT 254 }; 255 256 enum { 257 NEITHER = 0, 258 BAD, 259 GOOD 260 }; 261 262 StateMod( char const* name, char const* displayName, char const* symbol 263 , char const* setState, char const* unsetState, int type, int index ); 264 ~StateMod(); 265 266 static std::map<std::string, StateMod*> stateModsByName; 267 static std::vector<StateMod*> stateMods; 268 static std::vector<StateMod*> goodStateMods; 269 static std::vector<StateMod*> badStateMods; getStateModByName(char * name)270 static inline StateMod *getStateModByName( char *name ) { 271 std::string s = name; 272 return( stateModsByName.find( s ) == stateModsByName.end() ? NULL : stateModsByName[ s ] ); 273 } 274 275 static StateMod *getRandomGood(); 276 static StateMod *getRandomBad(); 277 278 bool isStateModTransitionWanted( bool setting ); 279 getName()280 inline char *getName() { 281 return name; 282 } getDisplayName()283 inline char *getDisplayName() { 284 return displayName; 285 } getSetState()286 inline char *getSetState() { 287 return setState; 288 } getUnsetState()289 inline char *getUnsetState() { 290 return unsetState; 291 } getType()292 inline int getType() { 293 return type; 294 } getSymbol()295 inline char *getSymbol() { 296 return symbol; 297 } getIndex()298 inline int getIndex() { 299 return index; 300 } 301 }; 302 303 #endif 304 305