Planeshift
|
00001 /* 00002 * psitemstats.h 00003 * 00004 * Copyright (C) 2001 Atomic Blue ([email protected], http://www.atomicblue.org) 00005 * 00006 * 00007 * This program is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU General Public License 00009 * as published by the Free Software Foundation (version 2 of the License) 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 * 00018 */ 00019 00020 #ifndef __PSITEMSTATS_H__ 00021 #define __PSITEMSTATS_H__ 00022 //============================================================================= 00023 // Crystal Space Includes 00024 //============================================================================= 00025 #include <csutil/parray.h> 00026 #include <csutil/set.h> 00027 00028 //============================================================================= 00029 // Project Includes 00030 //============================================================================= 00031 #include "util/poolallocator.h" 00032 #include "util/slots.h" 00033 #include "util/psxmlparser.h" 00034 #include "util/scriptvar.h" 00035 #include "util/psconst.h" 00036 00037 #include "rpgrules/psmoney.h" 00038 00039 #include <idal.h> 00040 00041 //============================================================================= 00042 // Local Includes 00043 //============================================================================= 00044 #include "psskills.h" 00045 00046 class ApplicativeScript; 00047 class CacheManager; 00048 class psCharacter; 00049 class psItem; 00050 struct psItemCategory; 00051 00052 enum PSITEMSTATS_WEAPONSKILL_INDEX 00053 { 00054 PSITEMSTATS_WEAPONSKILL_INDEX_0 = 0, 00055 PSITEMSTATS_WEAPONSKILL_INDEX_1, 00056 PSITEMSTATS_WEAPONSKILL_INDEX_2, 00057 PSITEMSTATS_WEAPONSKILL_INDEX_COUNT 00058 }; 00059 00060 enum PSITEMSTATS_ARMORTYPE 00061 { 00062 PSITEMSTATS_ARMORTYPE_NONE = -1, 00063 PSITEMSTATS_ARMORTYPE_LIGHT, 00064 PSITEMSTATS_ARMORTYPE_MEDIUM, 00065 PSITEMSTATS_ARMORTYPE_HEAVY, 00066 PSITEMSTATS_ARMORTYPE_COUNT 00067 }; 00068 00069 enum PSITEMSTATS_STAT 00070 { 00071 PSITEMSTATS_STAT_NONE = -1, 00072 PSITEMSTATS_STAT_STRENGTH, 00073 PSITEMSTATS_STAT_AGILITY, 00074 PSITEMSTATS_STAT_ENDURANCE, 00075 PSITEMSTATS_STAT_INTELLIGENCE, 00076 PSITEMSTATS_STAT_WILL, 00077 PSITEMSTATS_STAT_CHARISMA, 00078 PSITEMSTATS_STAT_CONSTITUTION, 00079 PSITEMSTATS_STAT_STAMINA, 00080 PSITEMSTATS_STAT_COUNT 00081 }; 00082 00083 //TODO these should supposedly go away... 00084 00086 PSSKILL statToSkill(PSITEMSTATS_STAT stat); 00087 00088 00089 enum PSITEMSTATS_DAMAGETYPE 00090 { 00091 PSITEMSTATS_DAMAGETYPE_NONE = -1, 00092 PSITEMSTATS_DAMAGETYPE_SLASH, 00093 PSITEMSTATS_DAMAGETYPE_BLUNT, 00094 PSITEMSTATS_DAMAGETYPE_PIERCE, 00095 //PSITEMSTATS_DAMAGETYPE_FORCE, 00096 //PSITEMSTATS_DAMAGETYPE_FIRE, 00097 //PSITEMSTATS_DAMAGETYPE_ICE, 00098 //PSITEMSTATS_DAMAGETYPE_AIR, 00099 //PSITEMSTATS_DAMAGETYPE_POISON, 00100 //PSITEMSTATS_DAMAGETYPE_DISEASE, 00101 //PSITEMSTATS_DAMAGETYPE_HOLY, 00102 //PSITEMSTATS_DAMAGETYPE_UNHOLY, 00103 PSITEMSTATS_DAMAGETYPE_COUNT 00104 }; 00105 00106 enum PSITEMSTATS_AMMOTYPE 00107 { 00108 PSITEMSTATS_AMMOTYPE_NONE = -1, 00109 PSITEMSTATS_AMMOTYPE_ARROWS, 00110 PSITEMSTATS_AMMOTYPE_BOLTS, 00111 PSITEMSTATS_AMMOTYPE_ROCKS, 00112 PSITEMSTATS_AMMOTYPE_COUNT 00113 }; 00114 00115 enum PSITEMSTATS_CREATIVETYPE 00116 { 00117 PSITEMSTATS_CREATIVETYPE_NONE = -1, 00118 PSITEMSTATS_CREATIVETYPE_LITERATURE, 00119 PSITEMSTATS_CREATIVETYPE_SKETCH, 00120 PSITEMSTATS_CREATIVETYPE_MUSIC 00121 }; 00122 00123 enum PSITEMSTATS_CREATORSTATUS 00124 { 00125 PSITEMSTATS_CREATOR_VALID = 0, 00126 PSITEMSTATS_CREATOR_PUBLIC, 00127 PSITEMSTATS_CREATOR_UNASSIGNED, 00128 PSITEMSTATS_CREATOR_UNKNOWN // e.g. creator player deleted 00129 }; 00130 00131 /******************************************************/ 00132 /* Slots are treated as boolean flag-like values here */ 00133 /******************************************************/ 00134 #define PSITEMSTATS_SLOT_BULK 0x00000001 00135 #define PSITEMSTATS_SLOT_RIGHTHAND 0x00000002 00136 #define PSITEMSTATS_SLOT_LEFTHAND 0x00000004 00137 #define PSITEMSTATS_SLOT_BOTHHANDS 0x00000008 00138 #define PSITEMSTATS_SLOT_RIGHTFINGER 0x00000010 00139 #define PSITEMSTATS_SLOT_LEFTFINGER 0x00000020 00140 #define PSITEMSTATS_SLOT_HELM 0x00000040 00141 #define PSITEMSTATS_SLOT_NECK 0x00000080 00142 #define PSITEMSTATS_SLOT_BACK 0x00000100 00143 #define PSITEMSTATS_SLOT_ARMS 0x00000200 00144 #define PSITEMSTATS_SLOT_GLOVES 0x00000400 00145 #define PSITEMSTATS_SLOT_BOOTS 0x00000800 00146 #define PSITEMSTATS_SLOT_LEGS 0x00001000 00147 #define PSITEMSTATS_SLOT_BELT 0x00002000 00148 #define PSITEMSTATS_SLOT_BRACERS 0x00004000 00149 #define PSITEMSTATS_SLOT_TORSO 0x00008000 00150 #define PSITEMSTATS_SLOT_MIND 0x00010000 00151 #define PSITEMSTATS_SLOT_BANK 0x00020000 00152 #define PSITEMSTATS_SLOT_CRYSTAL 0x00040000 00153 #define PSITEMSTATS_SLOT_AZURE 0x00080000 00154 #define PSITEMSTATS_SLOT_RED 0x00100000 00155 #define PSITEMSTATS_SLOT_DARK 0x00200000 00156 #define PSITEMSTATS_SLOT_BROWN 0x00400000 00157 #define PSITEMSTATS_SLOT_BLUE 0x00800000 00158 00159 typedef unsigned int PSITEMSTATS_SLOTLIST; 00160 00161 #define PSITEMSTATS_FLAG_IS_A_MELEE_WEAPON 0x00000001 00162 #define PSITEMSTATS_FLAG_IS_A_RANGED_WEAPON 0x00000002 00163 #define PSITEMSTATS_FLAG_IS_A_SHIELD 0x00000004 00164 #define PSITEMSTATS_FLAG_IS_AMMO 0x00000008 00165 #define PSITEMSTATS_FLAG_IS_A_CONTAINER 0x00000010 00166 #define PSITEMSTATS_FLAG_USES_AMMO 0x00000020 00167 #define PSITEMSTATS_FLAG_IS_STACKABLE 0x00000040 00168 #define PSITEMSTATS_FLAG_IS_GLYPH 0x00000080 00169 #define PSITEMSTATS_FLAG_CAN_TRANSFORM 0x00000100 00170 #define PSITEMSTATS_FLAG_TRIA 0x00000200 00171 #define PSITEMSTATS_FLAG_HEXA 0x00000400 00172 #define PSITEMSTATS_FLAG_OCTA 0x00000800 00173 #define PSITEMSTATS_FLAG_CIRCLE 0x00001000 00174 #define PSITEMSTATS_FLAG_CONSUMABLE 0x00002000 00175 #define PSITEMSTATS_FLAG_IS_READABLE 0x00004000 00176 #define PSITEMSTATS_FLAG_IS_ARMOR 0x00008000 00177 #define PSITEMSTATS_FLAG_IS_EQUIP_STACKABLE 0x00010000 00178 #define PSITEMSTATS_FLAG_IS_WRITEABLE 0x00020000 00179 #define PSITEMSTATS_FLAG_NOPICKUP 0x00040000 00180 #define PSITEMSTATS_FLAG_AVERAGEQUALITY 0x00080000 ///< Flag if the item can stack and average out quality. 00181 #define PSITEMSTATS_FLAG_CREATIVE 0x00100000 ///< A creative thing, eg book, sketch 00182 #define PSITEMSTATS_FLAG_BUY_PERSONALISE 0x00200000 ///< duplicate & personalise at purchase 00183 #define PSITEMSTATS_FLAG_IS_RECHARGEABLE 0x00400000 00184 #define PSITEMSTATS_FLAG_IS_A_TRAP 0x00800000 00185 #define PSITEMSTATS_FLAG_IS_CONSTRUCTIBLE 0x01000000 00186 #define PSITEMSTATS_FLAG_IS_RENAMEABLE 0x02000000 00187 00188 #define CREATIVEDEF_MAX 65535 // Max length for 'text' field in MySQL db. 00189 00190 typedef unsigned int PSITEMSTATS_FLAGS; 00191 00192 struct st_attribute_bonus 00193 { 00194 PSITEMSTATS_STAT attribute_id; 00195 short bonus_max; 00196 }; 00197 00198 #define PSITEMSTATS_STAT_BONUS_COUNT 3 00199 00205 struct ItemRequirement 00206 { 00207 csString name; 00208 float min_value; 00209 }; 00210 00211 struct psWeaponType 00212 { 00213 unsigned int id; 00214 csString name; 00215 PSSKILL skill; // a skill that it may be effected by 00216 }; 00217 00222 struct psItemAnimation 00223 { 00224 int id; 00225 csString anim_name; 00226 csStringID anim_id; 00227 int min_level_required; 00228 int flags; 00229 }; 00230 00231 00232 //----------------------------------------------------------------------------- 00233 00237 class psItemArmorStats 00238 { 00239 public: 00240 friend class psItemStats; 00241 psItemArmorStats(); 00242 00244 void ReadStats(iResultRow &row); 00245 00246 PSITEMSTATS_ARMORTYPE Type() 00247 { 00248 return armor_type; 00249 } 00250 char Class() 00251 { 00252 return armor_class; 00253 } 00254 float Protection(PSITEMSTATS_DAMAGETYPE dmgtype); 00255 float Hardness() 00256 { 00257 return hardness; 00258 } 00259 00260 private: 00261 PSITEMSTATS_ARMORTYPE armor_type; 00262 char armor_class; 00263 float damage_protection[PSITEMSTATS_DAMAGETYPE_COUNT]; 00264 float hardness; 00265 }; 00266 00271 class psItemWeaponStats 00272 { 00273 00274 public: 00275 friend class psItemStats; 00276 psItemWeaponStats(); 00277 00281 void ReadStats(iResultRow &row); 00282 00283 psWeaponType *Type() { return weapon_type; } 00284 00285 PSSKILL Skill(PSITEMSTATS_WEAPONSKILL_INDEX index); 00286 00287 float Latency() 00288 { 00289 return latency; 00290 } 00291 float Damage(PSITEMSTATS_DAMAGETYPE dmgtype); 00292 float ExtraDamagePercent(PSITEMSTATS_DAMAGETYPE dmgtype); 00293 00294 float Penetration() 00295 { 00296 return penetration; 00297 } 00298 float UntargetedBlockValue() 00299 { 00300 return untargeted_block_value; 00301 } 00302 float TargetedBlockValue() 00303 { 00304 return targeted_block_value; 00305 } 00306 float CounterBlockValue() 00307 { 00308 return counter_block_value; 00309 } 00310 00311 PSITEMSTATS_STAT AttributeBonusType(int index); 00312 float AttributeBonusMax(int index); 00313 00314 private: 00315 psWeaponType *weapon_type; 00316 PSSKILL weapon_skill[PSITEMSTATS_WEAPONSKILL_INDEX_COUNT]; 00317 st_attribute_bonus attribute_bonuses[PSITEMSTATS_STAT_BONUS_COUNT]; 00318 float latency; 00319 float damages[PSITEMSTATS_DAMAGETYPE_COUNT]; // 4.3 precision 00320 float penetration; 00321 float untargeted_block_value; 00322 float targeted_block_value; 00323 float counter_block_value; 00324 }; 00325 00329 class psItemAmmoStats 00330 { 00331 public: 00332 psItemAmmoStats(); 00333 ~psItemAmmoStats(); 00334 00338 void ReadStats(iResultRow &row); 00339 00340 PSITEMSTATS_AMMOTYPE AmmoType() 00341 { 00342 return ammunition_type; 00343 } 00344 private: 00345 PSITEMSTATS_AMMOTYPE ammunition_type; 00346 }; 00347 00351 class psItemCreativeStats 00352 { 00353 public: 00354 00355 //Both psitemstats and psitem make use of this structure. So they need to access 00356 //all it's elements 00357 friend class psItemStats; 00358 friend class psItem; 00359 00361 psItemCreativeStats(); 00363 ~psItemCreativeStats(); 00364 00371 bool IsThisTheCreator(PID characterID); 00372 00380 void SetCreator(PID characterID, PSITEMSTATS_CREATORSTATUS creatorStatus); 00381 00390 PID GetCreator(PSITEMSTATS_CREATORSTATUS &creatorStatus); 00391 00392 private: 00398 void ReadStats(iResultRow &row); 00399 00403 void ReadStats(); 00404 00408 bool SetCreativeContent(PSITEMSTATS_CREATIVETYPE, const csString &, uint32); 00409 00413 bool FormatCreativeContent(void); 00414 00418 void SaveCreation(uint32); 00419 00423 csString UpdateDescription(PSITEMSTATS_CREATIVETYPE, csString, csString); 00424 00433 void setInstanceBased(bool value) 00434 { 00435 instanceBased = value; 00436 } 00437 00438 PSITEMSTATS_CREATIVETYPE creativeType; 00439 00440 psXMLString creativeDefinitionXML; 00441 csString content; 00442 csString backgroundImg; 00443 00444 PID creatorID; 00445 PSITEMSTATS_CREATORSTATUS creatorIDStatus; 00446 00451 bool instanceBased; 00452 00453 }; 00454 00455 //----------------------------------------------------------------------------- 00456 00463 class psItemStats : public iScriptableVar 00464 { 00465 public: 00466 psItemStats(); 00467 ~psItemStats(); 00468 00469 private: 00470 uint32 uid; 00471 csString uid_str; 00472 csString name; 00473 csString description; 00475 float item_quality; 00477 csString sketch_def; 00478 00479 psItemArmorStats armorStats; 00480 psItemWeaponStats weaponStats; 00481 psItemAmmoStats ammoStats; 00482 psItemCreativeStats creativeStats; 00483 00484 float weight; 00485 00490 float size; 00491 00497 unsigned short container_max_size; 00498 00503 int container_max_slots; 00504 00506 float decay_rate; 00507 00509 ApplicativeScript* equipScript; 00510 csString consumeScriptName; 00511 00512 PSITEMSTATS_SLOTLIST valid_slots; 00513 csArray<INVENTORY_SLOT_NUMBER> valid_slots_array; 00514 PSITEMSTATS_FLAGS flags; 00515 00528 float visible_distance; 00529 00530 csSet<unsigned int> ammo_types; 00531 00532 csString stat_type; 00533 00534 csArray<ItemRequirement> reqs; 00535 int spell_id_on_hit; 00536 float spell_on_hit_probability; 00537 int spell_id_feature; 00538 int spell_feature_charges; 00539 int spell_feature_timing; 00540 00544 int maxCharges; 00545 00547 bool isConsumable; 00548 00550 bool spawnable; 00551 00553 csPDelArray<psItemAnimation>* anim_list; 00554 00556 csString mesh_name; 00557 00559 csString texture_name; 00560 00562 csString texturepart_name; 00563 00565 csString partmesh_name; 00566 00567 csString image_name; 00568 00569 /* mesh names, texture names, texture part names, and image names are currently stored as strings 00570 * on the server and passed over to the client in normal communication. This is inefficient, and 00571 * ultimately the client should use a numeric index of these resources, and the server should not 00572 * need to be aware of the resource name at all. 00573 * 00574 * Higher level design tools should be aware of the mapping between resource name and index, and 00575 * should be able to adjust both the server database references to the index as well as the client 00576 * index->resource mapping. 00577 */ 00578 /* 00579 unsigned int mesh_index; 00580 unsigned int texture_index; 00581 unsigned int texturepart_index; 00582 unsigned int image_index; 00583 */ 00584 00585 00586 psMoney price; 00587 psItemCategory* category; 00588 00589 csString sound; 00590 csString weapon_type; 00591 00592 csString itemCommand; 00593 00594 csHash<csHash<csString,int> > meshRemovalInfo; 00595 00601 void LoadMeshRemoval(iResultRow &row); 00602 00608 void LoadSlots(iResultRow &row); 00609 00615 void ParseFlags(iResultRow &row); 00616 00617 public: 00618 psItemArmorStats &Armor() 00619 { 00620 return armorStats; 00621 } 00622 psItemWeaponStats &Weapon() 00623 { 00624 return weaponStats; 00625 } 00626 psItemAmmoStats &Ammunition() 00627 { 00628 return ammoStats; 00629 } 00630 00631 bool ReadItemStats(iResultRow &row); 00632 PSITEMSTATS_FLAGS GetFlags() 00633 { 00634 return flags; 00635 } 00636 // Interface 00637 bool GetIsMeleeWeapon(); 00638 bool GetIsBothHandsWeapon(); 00639 bool GetIsArmor(); 00640 bool GetIsRangeWeapon(); 00641 bool GetIsAmmo(); 00642 bool GetIsShield(); 00643 bool GetIsContainer(); 00644 bool GetIsTrap(); 00645 bool GetIsConstructible(); 00646 bool GetCanTransform(); 00647 bool GetUnmovable(); 00648 bool GetUsesAmmo(); 00649 bool GetIsStackable(); 00650 bool GetIsEquipStackable(); 00651 bool GetIsGlyph(); 00652 bool GetIsRenameable(); 00653 bool GetIsConsumable(); 00654 bool GetIsReadable(); 00655 bool GetIsWriteable(); 00656 00662 bool IsSpawnable(); 00663 PSITEMSTATS_CREATIVETYPE GetCreative(); 00664 bool GetBuyPersonalise(); 00665 float GetRange() const; 00666 PID GetCreator(PSITEMSTATS_CREATORSTATUS &creatorStatus); 00667 bool UsesAmmoType(uint32_t id) const 00668 { 00669 return ammo_types.In(id); 00670 } 00671 00672 float weaponRange; 00673 00677 bool IsMoney(); 00678 00679 uint32 GetUID(); 00680 const char* GetUIDStr(); 00681 const char* GetDescription() const; 00682 void SetDescription(const char* v); 00683 void SaveDescription(void); 00684 PSITEMSTATS_AMMOTYPE GetAmmoType(); 00685 float GetQuality() const 00686 { 00687 return item_quality; 00688 } 00689 void SetQuality(float f) 00690 { 00691 item_quality = f; 00692 } 00693 00694 void GetArmorVsWeaponType(csString &buff); 00695 void SetArmorVsWeaponType(const char* v); 00696 00697 float GetWeight(); 00698 float GetSize(); 00699 unsigned short GetContainerMaxSize(); 00700 00707 int GetContainerMaxSlots(); 00708 float GetVisibleDistance(); 00709 PSITEMSTATS_SLOTLIST GetValidSlots(); 00710 bool FitsInSlots(PSITEMSTATS_SLOTLIST slotmask); 00711 00720 csString GetSlotRemovedMesh(int slot, csString meshName = ""); 00721 float GetDecayRate(); 00722 00723 int GetAttackAnimID(unsigned int skill_level); 00724 00725 csString FlagsToText(); 00726 00727 00728 const char* GetName() const; 00729 const csString GetDownCaseName(); 00730 void SetUnique(); 00731 bool GetUnique(); 00732 void SetRandom(); 00733 bool GetRandom(); 00734 00740 psXMLString getCreativeXML() 00741 { 00742 return creativeStats.creativeDefinitionXML; 00743 } 00744 void SetName(const char* v); 00745 void SaveName(void); 00746 00752 const char* GetMeshName(); 00753 00754 void SetMeshName(const char* v); 00755 00761 const char* GetTextureName(); 00762 00763 void SetTextureName(const char* v); 00764 00771 const char* GetPartName(); 00772 00773 void SetPartName(const char* v); 00774 00781 const char* GetPartMeshName(); 00782 00783 void SetPartMeshName(const char* v); 00784 00791 const char* GetImageName(); 00792 00793 void SetImageName(const char* v); 00794 00795 // For future use, see notes for mesh_index variables, etc. 00796 /* 00797 unsigned int GetMeshIndex(); 00798 void SetMeshIndex(unsigned int v); 00799 unsigned int GetTextureIndex(); 00800 void SetTextureIndex(unsigned int v); 00801 unsigned int GetTexturePartIndex(); 00802 void SetTexturePartIndex(unsigned int v); 00803 unsigned int GetImageIndex(); 00804 void SetImageIndex(unsigned int v); 00805 */ 00806 00807 void SetPrice(int trias); 00808 psMoney &GetPrice(); 00809 void SetCategory(psItemCategory* category); 00810 psItemCategory* GetCategory(); 00811 const csArray<INVENTORY_SLOT_NUMBER>& GetSlots() const 00812 { 00813 return valid_slots_array; 00814 } 00815 00816 // 00817 const char* GetSound(); 00818 void SetSound(const char* v); 00819 00820 ApplicativeScript* GetEquipScript() 00821 { 00822 return equipScript; 00823 } 00824 const csString &GetConsumeScriptName() 00825 { 00826 return consumeScriptName; 00827 } 00828 00832 bool SetEquipScript(const csString &script); 00833 00839 csArray<ItemRequirement> &GetRequirements(); 00840 bool SetRequirement(const csString &statName, float statValue); 00841 00848 psItem* InstantiateBasicItem(bool transient=false); 00849 00850 bool Save(); 00851 bool SetAttribute(const csString &op, const csString &attrName, float modifier); 00852 00854 const csString &GetMusicalSheet(void) 00855 { 00856 return creativeStats.content; 00857 } 00858 const csString &GetSketch(void) 00859 { 00860 return creativeStats.content; 00861 } 00862 const csString &GetLiteratureText(void) 00863 { 00864 return creativeStats.content; 00865 } 00866 00870 bool SetCreation(PSITEMSTATS_CREATIVETYPE, const csString &, csString); 00871 00875 void SetCreator(PID, PSITEMSTATS_CREATORSTATUS); 00876 bool IsThisTheCreator(PID); 00877 00883 const csString &GetCreativeBackgroundImg(); 00884 00886 bool HasCharges() const; 00887 bool IsRechargeable() const; 00888 void SetMaxCharges(int charges); 00889 int GetMaxCharges() const; 00890 00892 csString GetItemCommand() 00893 { 00894 return itemCommand; 00895 } 00896 00903 const char* ToString() 00904 { 00905 return name.GetDataSafe(); 00906 } 00907 00913 double CalcFunction(MathEnvironment* env, const char* functionName, const double* params); 00914 00924 double GetProperty(MathEnvironment* env, const char* ptr); 00925 00926 00927 public: 00928 00930 void* operator new(size_t); 00932 void operator delete(void*); 00933 00934 private: 00936 static PoolAllocator<psItemStats> itempool; 00937 }; 00938 00941 #endif 00942