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

rpgitem.h

00001 /***************************************************************************
00002                           rpgitem.cpp  -  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 RPG_ITEM_H
00018 #define RPG_ITEM_H
00019 
00020 #include <map>
00021 #include <string>
00022 #include <vector>
00023 #include "../constants.h"
00024 #include "character.h"
00025 #include "../persist.h"
00026 
00027 using namespace std;
00028 
00029 /*
00030  * Remember to change isWeaponItem=, getRandomEnchantableItem, 
00031  * getRandomItem, getRandomContainer, getRandomContainerNS
00032  * 
00033  * when adding a new item or type.
00034  */
00035 
00036 class Monster;
00037 class Dice;
00038 class MagicSchool;
00039 class Spell;
00040 class RpgItem;
00041 
00042 /*
00043 class MagicAttrib {
00044 private:
00045   int bonus; // e.g.: sword +2
00046   int damageMultiplier; // 2=double damage, 3=triple, etc.
00047   char *monsterType; // if not NULL, damageMultiplier only for this type of monster.
00048   MagicSchool *school; // magic damage by a school (or NULL if N/A)
00049   Dice *magicDamage; 
00050   bool cursed;
00051   int stateMod[Constants::STATE_MOD_COUNT]; // 0=nothing, 1=sets, 2=clears/protects against state mod when worn
00052   int level;
00053   bool stateModSet;
00054   map<int, int> skillBonus;
00055 
00056 public:
00057   MagicAttrib();
00058   ~MagicAttrib();
00059 
00060   MagicAttribInfo *save();
00061   static MagicAttribInfo *saveEmpty();
00062   static MagicAttrib *load(Session *session, MagicAttribInfo *info);
00063 
00064   inline map<int,int> *getSkillBonusMap() { return &skillBonus; }
00065   inline int getSkillBonus(int skill) { return (skillBonus.find(skill) == skillBonus.end() ? 0 : skillBonus[skill]); }
00066   inline int getLevel() { return level; }
00067   inline int getBonus() { return bonus; }
00068   inline int getDamageMultiplier() { return damageMultiplier; }
00069   inline char *getMonsterType() { return monsterType; }
00070   inline MagicSchool *getSchool() { return school; }
00071   int rollMagicDamage();
00072   inline int getMagicResistance() { return (7 * getLevel()); }
00073   char *describeMagicDamage();
00074   inline bool isCursed() { return cursed; }
00075   inline bool isStateModSet(int mod) { return(stateMod[mod] == 1); }
00076   inline bool isStateModProtected(int mod) { return(stateMod[mod] == 2); }
00077   void debug(char *s, RpgItem *item);
00078 
00079    //Create a magic attribute obj. depending on the level.
00080    //(0=lesser,1=greater,2=champion,3=divine)
00081   void enchant(int level, bool isWeapon);
00082 
00083    //Write the description of this item into buffer s.
00084    //S has to be large enough to hold the description. (~255 chars)
00085   void describe(char *s, char *itemName);
00086 };
00087 */
00088 
00089 class RpgItem {
00090  private:
00091 
00092   int index;
00093   char *name, *desc, *shortDesc;
00094   int level;
00095   int rareness;
00096   int type;
00097   float weight; 
00098   int price, quality;
00099   int action; // damage, defence, potion str.
00100   int speed; // 0-100, 100-slowest, 0-fastest
00101   int shape_index;
00102   int twohanded;
00103   int distance; // how far can it reach?
00104   int equip; // where can it be worn?
00105   int skill; // which skill to check when using the item
00106   int minDepth; // 0-based min. depth where the item occurs
00107   int maxCharges;
00108   int potionSkill; // which skill does this potion effect?
00109   int potionTime;
00110   GLuint acl; // 1 bit per character class
00111   bool isWeaponItem;
00112   int iconTileX, iconTileY;
00113 
00114   static map<int, map<int, vector<const RpgItem*>*>*> typesMap;
00115   static map<string, const RpgItem *> itemsByName;
00116   static vector<RpgItem*> containers;
00117   static vector<RpgItem*> containersNS;
00118 
00119  public:
00120 
00121   enum itemTypes {
00122         SWORD=0,
00123         AXE,
00124         BOW,
00125     MACE,
00126         CONTAINER,
00127         ARMOR,
00128         FOOD,
00129         DRINK,
00130         POTION,
00131         OTHER,
00132         MISSION,
00133   SCROLL,
00134         
00135         // must be last
00136         ITEM_TYPE_COUNT
00137   };
00138   static char itemTypeStr[ITEM_TYPE_COUNT][40];
00139 
00140   enum twoHandedType {
00141         NOT_TWO_HANDED=0,
00142         ONLY_TWO_HANDED,
00143         OPTIONAL_TWO_HANDED
00144   };
00145 
00146   static RpgItem *items[1000];
00147   static int itemCount;
00148 
00149   static int enchantableTypes[];
00150   static int enchantableTypeCount;
00151   
00152   RpgItem(int index, char *name, int level, int rareness, int type, float weight, int price, int quality, 
00153                   int action, int speed, char *desc, char *shortDesc, int equip, int shape_index, 
00154                   int twohanded=NOT_TWO_HANDED, int distance=1, int skill=-1, int minDepth=0, int maxCharges=0,
00155                   int potionSkill=-1, int potionTime=0, int iconTileX=0, int iconTileY=0);
00156   ~RpgItem();
00157 
00158 
00159   // -Rpg in the name to not accidentally call it instead of item->getXYZ().
00160   inline int getLevelRpg()  { return level; }  
00161   inline float getWeightRpg() { return weight; }
00162   inline int getPriceRpg() { return price; }
00163   inline int getActionRpg() { return action; }
00164   inline int getSpeedRpg() { return speed; }
00165   inline int getDistanceRpg() { return distance; }
00166   inline int getMaxChargesRpg() { return maxCharges; }
00167   inline int getDurationRpg() { return potionTime; }
00168   inline int getQualityRpg() { return quality; }
00169 
00170   inline int getIndex() { return index; }
00171   inline char *getName() { return name; }
00172   inline int getRareness()  { return rareness; }
00173   inline int getShapeIndex() { return shape_index; }
00174   inline char *getShortDesc() { return shortDesc; }  
00175   inline char *getLongDesc() { return desc; }  
00176   inline int getEquip() { return equip; }
00177   inline int getSkill() { return skill; } 
00178   inline int getMinDepth() { return minDepth; }
00179   inline int getType() { return type; }
00180   inline int getPotionSkill() { return potionSkill; }
00181   inline bool getAcl(int index) { return (acl & (1 << index) ? true : false); }
00182   inline void setAcl(int index, bool value) { if(value) acl |= (1 << index); else acl &= ((GLuint)0xffff - (GLuint)(1 << index)); }
00183   inline void setAllAcl(bool value) { if(value) acl = (GLuint)0xffff; else acl = (GLuint)0; }
00184   inline GLuint getAllAcl() { return acl; }
00185   inline bool isWeapon() { return this->isWeaponItem; }
00186   inline int getIconTileX() { return this->iconTileX; }
00187   inline int getIconTileY() { return this->iconTileY; }
00188 
00189   // FIXME: make this more specific to item
00190   // e.g. multi-attack items, like sword of fireballs
00191   inline bool isRangedWeapon() { return type == BOW; }
00192 
00193   bool isEnchantable();
00194 
00195   static RpgItem *getRandomItem(int depth);
00196   static RpgItem *getRandomContainer();
00197   static RpgItem *getRandomContainerNS();
00198   inline static RpgItem *getItem(int index) { return items[index]; }
00199 
00200   static int getTypeByName(char *name);
00201   static void addItem(RpgItem *item, int width, int depth, int height);
00202   static RpgItem *getItemByName(char *name);
00203 
00204 protected:
00205   static RpgItem *getRandomItemFromTypes(int level, int types[], int typeCount);
00206 };
00207 
00208 #endif

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