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

item.h

00001 /***************************************************************************
00002                           item.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 
00018 #ifndef ITEM_H
00019 #define ITEM_H
00020 
00021 #include "constants.h"
00022 #include "persist.h"
00023 #include "glshape.h"
00024 #include "shapepalette.h"
00025 #include "rpg/rpgitem.h"
00026 #include "rpg/spell.h"
00027 #include <vector>
00028 
00029 class Scourge;
00030 class Session;
00031 
00040 class Item {
00041  private:
00042   RpgItem *rpgItem;
00043   int shapeIndex;
00044   Color *color;
00045   GLShape *shape;
00046   bool blocking;
00047   Item *containedItems[MAX_CONTAINED_ITEMS];
00048   int containedItemCount;
00049   int currentCharges;
00050   Spell *spell;
00051   char itemName[255];
00052   bool containsMagicItem;
00053   bool showCursed;
00054 
00055 
00056 
00057   // Things that change with item level (override rpgitem values)
00058   int level;
00059   float weight; 
00060   int price;
00061   int action; // damage, defence, potion str.
00062   int speed; // 0-100, 100-slowest, 0-fastest
00063   int distance; // how far can it reach?
00064   int maxCharges;
00065   int duration;
00066   int quality;
00067 
00068   // former magic attrib stuff
00069   int magicLevel;
00070   int bonus; // e.g.: sword +2
00071   int damageMultiplier; // 2=double damage, 3=triple, etc.
00072   char *monsterType; // if not NULL, damageMultiplier only for this type of monster.
00073   MagicSchool *school; // magic damage by a school (or NULL if N/A)
00074   Dice *magicDamage; 
00075   bool cursed;
00076   int stateMod[Constants::STATE_MOD_COUNT]; // 0=nothing, 1=sets, 2=clears/protects against state mod when worn
00077   bool stateModSet;
00078   map<int, int> skillBonus;
00079   Session *session;
00080 
00081 public:
00082   Item(Session *session, RpgItem *rpgItem, int level=1, bool loading=false);
00083   ~Item();
00084 
00085   ItemInfo *save();
00086   //ContainedItemInfo saveContainedItems();
00087   static Item *load(Session *session, ItemInfo *info);
00088 
00089   static map<int, vector<string> *> soundMap;
00090   
00091   inline Color *getColor() { return color; }
00092   inline void setColor(Color *c) { color = c; }
00093   inline void setShape(GLShape *s) { shape = s; }
00094   inline GLShape *getShape() { return shape; }
00095   inline RpgItem *getRpgItem() { return rpgItem; }
00096   inline bool isBlocking() { return blocking; }
00097   inline void setBlocking(bool b) { blocking = b; }
00098   inline int getCurrentCharges() { return currentCharges; }
00099   inline void setCurrentCharges(int n) { if(n < 0)n=0; if(n>rpgItem->getMaxChargesRpg())n=rpgItem->getMaxChargesRpg(); currentCharges = n; } 
00100   inline void setWeight(float f) { if(f < 0.0f)f=0.1f; weight=f; }
00101   inline void setSpell(Spell *spell) { this->spell = spell; sprintf(this->itemName, "Scroll of %s", spell->getName()); }
00102   inline Spell *getSpell() { return spell; }
00103 
00104   inline void setShowCursed( bool b ) { showCursed = b; }
00105   inline bool getShowCursed() { return showCursed; }
00106 
00107   void getDetailedDescription(char *s, bool precise=true);
00108   inline char *getItemName() { return itemName; }
00109 
00110   inline int getContainedItemCount() { return containedItemCount; }
00111   // return true if successful
00112   bool addContainedItem(Item *item, bool force=false);
00113   // return removed item, or NULL
00114   Item *removeContainedItem(int index);
00115   Item *getContainedItem(int index);
00116   bool isContainedItem(Item *item);
00117   inline bool getContainsMagicItem() { return containsMagicItem; }
00118 
00119   // return true if the item is used up
00120   // this method also adjusts weight
00121   bool decrementCharges();
00122 
00123   const char *getRandomSound();
00124   
00125   static void initItems(ShapePalette *shapePal);
00126 
00127   void enchant(int level);
00128 
00129 
00130   // level-based attributes
00131   inline int getLevel() { return level; }
00132   inline float getWeight() { return weight; }
00133   inline int getPrice() { return price; }
00134   inline int getAction() { return action; }
00135   inline int getSpeed() { return speed; }
00136   inline int getDistance() { return distance; }
00137   inline int getMaxCharges() { return maxCharges; }
00138   inline int getDuration() { return duration; }
00139   inline int getQuality() { return quality; }
00140 
00141   inline bool isMagicItem() { return ( magicLevel > -1 ); }
00142   inline map<int,int> *getSkillBonusMap() { return &skillBonus; }
00143   inline int getSkillBonus(int skill) { return (skillBonus.find(skill) == skillBonus.end() ? 0 : skillBonus[skill]); }
00144   inline int getMagicLevel() { return magicLevel; }
00145   inline int getBonus() { return bonus; }
00146   inline int getDamageMultiplier() { return damageMultiplier; }
00147   inline char *getMonsterType() { return monsterType; }
00148   inline MagicSchool *getSchool() { return school; }
00149   int rollMagicDamage();
00150   inline int getMagicResistance() { return (7 * (getLevel() + getMagicLevel())); }
00151   char *describeMagicDamage();
00152   inline bool isCursed() { return cursed; }
00153   inline bool isStateModSet(int mod) { return(stateMod[mod] == 1); }
00154   inline bool isStateModProtected(int mod) { return(stateMod[mod] == 2); }
00155 
00156   void debugMagic(char *s);
00157 
00158  protected:
00159   void commonInit( bool loading=false );
00160   float getRandomSum( float base, int count );
00161   void describeMagic(char *s, char *itemName);
00162 };
00163 
00164 #endif

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