Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields

spell.h

00001 /***************************************************************************
00002                           spell.h  -  description
00003                              -------------------
00004     begin                : Sun Sep 28 2003
00005     copyright            : (C) 2003 by Gabor Torok
00006     email                : cctorok@yahoo.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 #ifndef SPELL_H
00018 #define SPELL_H
00019 
00020 #include <map>
00021 #include <string>
00022 #include <vector>
00023 #include "../constants.h"
00024 #include "../persist.h"
00025 
00026 using namespace std;
00027 
00028 class Dice {
00029 private:
00030   char *s;
00031   int count;
00032   int sides;
00033   int mod;
00034   bool frees;
00035 
00036 public:
00037   Dice(char *s);
00038   Dice(int count, int sides, int mod);
00039   ~Dice();
00040   inline char *toString() { return s;}
00041   inline int roll() { 
00042     float n = (float)sides * rand()/RAND_MAX;
00043     n *= count;
00044     n += mod;
00045     return(int)n;
00046   }
00047 
00048   DiceInfo *save();
00049   static DiceInfo *saveEmpty();
00050   static Dice *load(Session *session, DiceInfo *info);
00051 };
00052 
00053 class MagicSchool;
00054 
00055 class Spell {
00056  private:
00057   char *name;
00058   char *sound;
00059   int level;
00060   int mp;
00061   int exp;
00062   int failureRate;
00063   Dice *action;
00064   int distance;
00065   int targetType;
00066   char notes[1000];
00067   int speed;
00068   int effect;
00069   MagicSchool *school;  
00070   bool creatureTarget, locationTarget, itemTarget, partyTarget;
00071   int iconTileX, iconTileY;
00072 
00073   static map<string, Spell*> spellMap;
00074 
00075  public:
00076 
00077   Spell(char *name, int level, int mp, int exp, int failureRate, Dice *action, 
00078                 int distance, int targetType, int speed, int effect, bool creatureTarget, 
00079                 bool locationTarget, bool itemTarget, bool partyTarget, MagicSchool *school,
00080                 int iconTileX, int iconTileY);
00081   ~Spell();
00082 
00083   inline int getIconTileX() { return iconTileX; }
00084   inline int getIconTileY() { return iconTileY; }
00085   inline char *getName() { return name; }
00086   inline int getAction() { return action->roll(); }
00087   inline int getLevel()  { return level; }
00088   inline int getMp() { return mp; }
00089   inline int getExp() { return exp; }
00090   inline int getFailureRate() { return failureRate; }
00091   inline int getDistance() { return distance; }
00092   inline int getTargetType() { return targetType; }  
00093   inline char *getNotes() { return notes; }
00094   inline int getSpeed() { return speed; }
00095   inline int getEffect() { return effect; }
00096   inline MagicSchool *getSchool() { return school; }
00097   inline bool isRangedSpell() { return distance > 1; }  
00098   inline void describe(char *s) { sprintf(s, "%s (L:%d)(M:%d)", name, level, mp); }
00099   inline void addNotes(char *s) { strcat(notes, s); }
00100   inline void setSound(char *s) { sound = s; }
00101   inline char *getSound() { return sound; }
00102 
00103   // what kind of target is allowed for this spell
00104   inline bool isCreatureTargetAllowed() { return creatureTarget; }
00105   inline bool isLocationTargetAllowed() { return locationTarget; }
00106   inline bool isItemTargetAllowed() { return itemTarget; }
00107   inline bool isPartyTargetAllowed() { return partyTarget; }
00108 
00109   static Spell *getSpellByName(char *name);
00110 };
00111 
00112 
00113 
00114 class MagicSchool {
00115  private:
00116   char *name;
00117   char *shortName;
00118   char *deity;
00119   char deityDescription[3000];
00120   int skill, resistSkill;
00121   vector<Spell*> spells;
00122 
00123   static MagicSchool *schools[10];
00124   static int schoolCount;
00125   static map<string, MagicSchool*> schoolMap;
00126 
00127  public:
00128   MagicSchool(char *name, char *deity, int skill, int resistSkill);
00129   ~MagicSchool();
00130 
00131   inline char *getName() { return name; }
00132   inline char *getShortName() { return shortName; }
00133   inline char *getDeity() { return deity; }
00134   inline char *getDeityDescription() { return deityDescription; }
00135   inline int getSkill() { return skill; }
00136   inline int getResistSkill() { return resistSkill; }
00137   inline int getSpellCount() { return spells.size(); }
00138   inline Spell *getSpell(int index) { return spells[index]; }
00139   inline void addToDeityDescription( char *s ) { if( strlen( deityDescription ) ) strcat( deityDescription, " " ); strcat( deityDescription, s ); }
00140 
00141   static void initMagic();
00142   inline static int getMagicSchoolCount() { return schoolCount; }
00143   inline static MagicSchool *getMagicSchool( int index ) { return schools[index]; }
00144   static Spell *getRandomSpell(int level);
00145   static MagicSchool *getMagicSchoolByName( char *s ) { string name = s; return (schoolMap.find(name) == schoolMap.end() ? NULL : schoolMap[name]); }
00146 
00147  protected:
00148   inline void addSpell( Spell *spell ) { spells.push_back( spell ); }
00149 };
00150 
00151 #endif

Generated on Thu Jun 16 21:50:43 2005 for scourge by  doxygen 1.4.0