Planeshift
psitemstats.h
Go to the documentation of this file.
1 /*
2  * psitemstats.h
3  *
4  * Copyright (C) 2001 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */
19 
20 #ifndef __PSITEMSTATS_H__
21 #define __PSITEMSTATS_H__
22 //=============================================================================
23 // Crystal Space Includes
24 //=============================================================================
25 #include <csutil/parray.h>
26 #include <csutil/set.h>
27 
28 //=============================================================================
29 // Project Includes
30 //=============================================================================
31 #include "util/poolallocator.h"
32 #include "util/slots.h"
33 #include "util/psxmlparser.h"
34 #include "util/scriptvar.h"
35 #include "util/psconst.h"
36 
37 #include "rpgrules/psmoney.h"
38 
39 #include <idal.h>
40 
41 //=============================================================================
42 // Local Includes
43 //=============================================================================
44 #include "psskills.h"
45 
46 class ApplicativeScript;
47 class CacheManager;
48 class psCharacter;
49 class psItem;
50 struct psItemCategory;
51 
53 {
58 };
59 
61 {
67 };
68 
70 {
81 };
82 
83 //TODO these should supposedly go away...
84 
87 
88 
90 {
95  //PSITEMSTATS_DAMAGETYPE_FORCE,
96  //PSITEMSTATS_DAMAGETYPE_FIRE,
97  //PSITEMSTATS_DAMAGETYPE_ICE,
98  //PSITEMSTATS_DAMAGETYPE_AIR,
99  //PSITEMSTATS_DAMAGETYPE_POISON,
100  //PSITEMSTATS_DAMAGETYPE_DISEASE,
101  //PSITEMSTATS_DAMAGETYPE_HOLY,
102  //PSITEMSTATS_DAMAGETYPE_UNHOLY,
104 };
105 
107 {
113 };
114 
116 {
121 };
122 
124 {
128  PSITEMSTATS_CREATOR_UNKNOWN // e.g. creator player deleted
129 };
130 
131 /******************************************************/
132 /* Slots are treated as boolean flag-like values here */
133 /******************************************************/
134 #define PSITEMSTATS_SLOT_BULK 0x00000001
135 #define PSITEMSTATS_SLOT_RIGHTHAND 0x00000002
136 #define PSITEMSTATS_SLOT_LEFTHAND 0x00000004
137 #define PSITEMSTATS_SLOT_BOTHHANDS 0x00000008
138 #define PSITEMSTATS_SLOT_RIGHTFINGER 0x00000010
139 #define PSITEMSTATS_SLOT_LEFTFINGER 0x00000020
140 #define PSITEMSTATS_SLOT_HELM 0x00000040
141 #define PSITEMSTATS_SLOT_NECK 0x00000080
142 #define PSITEMSTATS_SLOT_BACK 0x00000100
143 #define PSITEMSTATS_SLOT_ARMS 0x00000200
144 #define PSITEMSTATS_SLOT_GLOVES 0x00000400
145 #define PSITEMSTATS_SLOT_BOOTS 0x00000800
146 #define PSITEMSTATS_SLOT_LEGS 0x00001000
147 #define PSITEMSTATS_SLOT_BELT 0x00002000
148 #define PSITEMSTATS_SLOT_BRACERS 0x00004000
149 #define PSITEMSTATS_SLOT_TORSO 0x00008000
150 #define PSITEMSTATS_SLOT_MIND 0x00010000
151 #define PSITEMSTATS_SLOT_BANK 0x00020000
152 #define PSITEMSTATS_SLOT_CRYSTAL 0x00040000
153 #define PSITEMSTATS_SLOT_AZURE 0x00080000
154 #define PSITEMSTATS_SLOT_RED 0x00100000
155 #define PSITEMSTATS_SLOT_DARK 0x00200000
156 #define PSITEMSTATS_SLOT_BROWN 0x00400000
157 #define PSITEMSTATS_SLOT_BLUE 0x00800000
158 
159 typedef unsigned int PSITEMSTATS_SLOTLIST;
160 
161 #define PSITEMSTATS_FLAG_IS_A_MELEE_WEAPON 0x00000001
162 #define PSITEMSTATS_FLAG_IS_A_RANGED_WEAPON 0x00000002
163 #define PSITEMSTATS_FLAG_IS_A_SHIELD 0x00000004
164 #define PSITEMSTATS_FLAG_IS_AMMO 0x00000008
165 #define PSITEMSTATS_FLAG_IS_A_CONTAINER 0x00000010
166 #define PSITEMSTATS_FLAG_USES_AMMO 0x00000020
167 #define PSITEMSTATS_FLAG_IS_STACKABLE 0x00000040
168 #define PSITEMSTATS_FLAG_IS_GLYPH 0x00000080
169 #define PSITEMSTATS_FLAG_CAN_TRANSFORM 0x00000100
170 #define PSITEMSTATS_FLAG_TRIA 0x00000200
171 #define PSITEMSTATS_FLAG_HEXA 0x00000400
172 #define PSITEMSTATS_FLAG_OCTA 0x00000800
173 #define PSITEMSTATS_FLAG_CIRCLE 0x00001000
174 #define PSITEMSTATS_FLAG_CONSUMABLE 0x00002000
175 #define PSITEMSTATS_FLAG_IS_READABLE 0x00004000
176 #define PSITEMSTATS_FLAG_IS_ARMOR 0x00008000
177 #define PSITEMSTATS_FLAG_IS_EQUIP_STACKABLE 0x00010000
178 #define PSITEMSTATS_FLAG_IS_WRITEABLE 0x00020000
179 #define PSITEMSTATS_FLAG_NOPICKUP 0x00040000
180 #define PSITEMSTATS_FLAG_AVERAGEQUALITY 0x00080000
181 #define PSITEMSTATS_FLAG_CREATIVE 0x00100000
182 #define PSITEMSTATS_FLAG_BUY_PERSONALISE 0x00200000
183 #define PSITEMSTATS_FLAG_IS_RECHARGEABLE 0x00400000
184 #define PSITEMSTATS_FLAG_IS_A_TRAP 0x00800000
185 #define PSITEMSTATS_FLAG_IS_CONSTRUCTIBLE 0x01000000
186 #define PSITEMSTATS_FLAG_IS_RENAMEABLE 0x02000000
187 
188 #define CREATIVEDEF_MAX 65535 // Max length for 'text' field in MySQL db.
189 
190 typedef unsigned int PSITEMSTATS_FLAGS;
191 
193 {
195  short bonus_max;
196 };
197 
198 #define PSITEMSTATS_STAT_BONUS_COUNT 3
199 
206 {
207  csString name;
208  float min_value;
209 };
210 
212 {
213  unsigned int id;
214  csString name;
215  PSSKILL skill; // a skill that it may be effected by
216 };
217 
223 {
224  int id;
225  csString anim_name;
226  csStringID anim_id;
228  int flags;
229 };
230 
231 
232 //-----------------------------------------------------------------------------
233 
238 {
239 public:
240  friend class psItemStats;
242 
244  void ReadStats(iResultRow &row);
245 
247  {
248  return armor_type;
249  }
250  char Class()
251  {
252  return armor_class;
253  }
254  float Protection(PSITEMSTATS_DAMAGETYPE dmgtype);
255  float Hardness()
256  {
257  return hardness;
258  }
259 
260 private:
261  PSITEMSTATS_ARMORTYPE armor_type;
262  char armor_class;
263  float damage_protection[PSITEMSTATS_DAMAGETYPE_COUNT];
264  float hardness;
265 };
266 
272 {
273 
274 public:
275  friend class psItemStats;
277 
281  void ReadStats(iResultRow &row);
282 
283  psWeaponType *Type() { return weapon_type; }
284 
286 
287  float Latency()
288  {
289  return latency;
290  }
291  float Damage(PSITEMSTATS_DAMAGETYPE dmgtype);
292  float ExtraDamagePercent(PSITEMSTATS_DAMAGETYPE dmgtype);
293 
294  float Penetration()
295  {
296  return penetration;
297  }
299  {
300  return untargeted_block_value;
301  }
303  {
304  return targeted_block_value;
305  }
307  {
308  return counter_block_value;
309  }
310 
311  PSITEMSTATS_STAT AttributeBonusType(int index);
312  float AttributeBonusMax(int index);
313 
314 private:
315  psWeaponType *weapon_type;
318  float latency;
319  float damages[PSITEMSTATS_DAMAGETYPE_COUNT]; // 4.3 precision
320  float penetration;
321  float untargeted_block_value;
322  float targeted_block_value;
323  float counter_block_value;
324 };
325 
330 {
331 public:
332  psItemAmmoStats();
333  ~psItemAmmoStats();
334 
338  void ReadStats(iResultRow &row);
339 
341  {
342  return ammunition_type;
343  }
344 private:
345  PSITEMSTATS_AMMOTYPE ammunition_type;
346 };
347 
352 {
353 public:
354 
355  //Both psitemstats and psitem make use of this structure. So they need to access
356  //all it's elements
357  friend class psItemStats;
358  friend class psItem;
359 
364 
371  bool IsThisTheCreator(PID characterID);
372 
380  void SetCreator(PID characterID, PSITEMSTATS_CREATORSTATUS creatorStatus);
381 
390  PID GetCreator(PSITEMSTATS_CREATORSTATUS &creatorStatus);
391 
392 private:
398  void ReadStats(iResultRow &row);
399 
403  void ReadStats();
404 
408  bool SetCreativeContent(PSITEMSTATS_CREATIVETYPE, const csString &, uint32);
409 
413  bool FormatCreativeContent(void);
414 
418  void SaveCreation(uint32);
419 
423  csString UpdateDescription(PSITEMSTATS_CREATIVETYPE, csString, csString);
424 
433  void setInstanceBased(bool value)
434  {
435  instanceBased = value;
436  }
437 
438  PSITEMSTATS_CREATIVETYPE creativeType;
439 
440  psXMLString creativeDefinitionXML;
441  csString content;
442  csString backgroundImg;
443 
444  PID creatorID;
445  PSITEMSTATS_CREATORSTATUS creatorIDStatus;
446 
451  bool instanceBased;
452 
453 };
454 
455 //-----------------------------------------------------------------------------
456 
464 {
465 public:
466  psItemStats();
467  ~psItemStats();
468 
469 private:
470  uint32 uid;
471  csString uid_str;
472  csString name;
473  csString description;
475  float item_quality;
477  csString sketch_def;
478 
479  psItemArmorStats armorStats;
480  psItemWeaponStats weaponStats;
481  psItemAmmoStats ammoStats;
482  psItemCreativeStats creativeStats;
483 
484  float weight;
485 
490  float size;
491 
497  unsigned short container_max_size;
498 
503  int container_max_slots;
504 
506  float decay_rate;
507 
509  ApplicativeScript* equipScript;
510  csString consumeScriptName;
511 
512  PSITEMSTATS_SLOTLIST valid_slots;
513  csArray<INVENTORY_SLOT_NUMBER> valid_slots_array;
514  PSITEMSTATS_FLAGS flags;
515 
528  float visible_distance;
529 
530  csSet<unsigned int> ammo_types;
531 
532  csString stat_type;
533 
534  csArray<ItemRequirement> reqs;
535  int spell_id_on_hit;
536  float spell_on_hit_probability;
537  int spell_id_feature;
538  int spell_feature_charges;
539  int spell_feature_timing;
540 
544  int maxCharges;
545 
547  bool isConsumable;
548 
550  bool spawnable;
551 
553  csPDelArray<psItemAnimation>* anim_list;
554 
556  csString mesh_name;
557 
559  csString texture_name;
560 
562  csString texturepart_name;
563 
565  csString partmesh_name;
566 
567  csString image_name;
568 
569  /* mesh names, texture names, texture part names, and image names are currently stored as strings
570  * on the server and passed over to the client in normal communication. This is inefficient, and
571  * ultimately the client should use a numeric index of these resources, and the server should not
572  * need to be aware of the resource name at all.
573  *
574  * Higher level design tools should be aware of the mapping between resource name and index, and
575  * should be able to adjust both the server database references to the index as well as the client
576  * index->resource mapping.
577  */
578  /*
579  unsigned int mesh_index;
580  unsigned int texture_index;
581  unsigned int texturepart_index;
582  unsigned int image_index;
583  */
584 
585 
586  psMoney price;
587  psItemCategory* category;
588 
589  csString sound;
590  csString weapon_type;
591 
592  csString itemCommand;
593 
594  csHash<csHash<csString,int> > meshRemovalInfo;
595 
601  void LoadMeshRemoval(iResultRow &row);
602 
608  void LoadSlots(iResultRow &row);
609 
615  void ParseFlags(iResultRow &row);
616 
617 public:
619  {
620  return armorStats;
621  }
623  {
624  return weaponStats;
625  }
627  {
628  return ammoStats;
629  }
630 
631  bool ReadItemStats(iResultRow &row);
633  {
634  return flags;
635  }
636  // Interface
637  bool GetIsMeleeWeapon();
638  bool GetIsBothHandsWeapon();
639  bool GetIsArmor();
640  bool GetIsRangeWeapon();
641  bool GetIsAmmo();
642  bool GetIsShield();
643  bool GetIsContainer();
644  bool GetIsTrap();
645  bool GetIsConstructible();
646  bool GetCanTransform();
647  bool GetUnmovable();
648  bool GetUsesAmmo();
649  bool GetIsStackable();
650  bool GetIsEquipStackable();
651  bool GetIsGlyph();
652  bool GetIsRenameable();
653  bool GetIsConsumable();
654  bool GetIsReadable();
655  bool GetIsWriteable();
656 
662  bool IsSpawnable();
663  PSITEMSTATS_CREATIVETYPE GetCreative();
664  bool GetBuyPersonalise();
665  float GetRange() const;
666  PID GetCreator(PSITEMSTATS_CREATORSTATUS &creatorStatus);
667  bool UsesAmmoType(uint32_t id) const
668  {
669  return ammo_types.In(id);
670  }
671 
672  float weaponRange;
673 
677  bool IsMoney();
678 
679  uint32 GetUID();
680  const char* GetUIDStr();
681  const char* GetDescription() const;
682  void SetDescription(const char* v);
683  void SaveDescription(void);
684  PSITEMSTATS_AMMOTYPE GetAmmoType();
685  float GetQuality() const
686  {
687  return item_quality;
688  }
689  void SetQuality(float f)
690  {
691  item_quality = f;
692  }
693 
694  void GetArmorVsWeaponType(csString &buff);
695  void SetArmorVsWeaponType(const char* v);
696 
697  float GetWeight();
698  float GetSize();
699  unsigned short GetContainerMaxSize();
700 
707  int GetContainerMaxSlots();
708  float GetVisibleDistance();
709  PSITEMSTATS_SLOTLIST GetValidSlots();
710  bool FitsInSlots(PSITEMSTATS_SLOTLIST slotmask);
711 
720  csString GetSlotRemovedMesh(int slot, csString meshName = "");
721  float GetDecayRate();
722 
723  int GetAttackAnimID(unsigned int skill_level);
724 
725  csString FlagsToText();
726 
727 
728  const char* GetName() const;
729  const csString GetDownCaseName();
730  void SetUnique();
731  bool GetUnique();
732  void SetRandom();
733  bool GetRandom();
734 
741  {
742  return creativeStats.creativeDefinitionXML;
743  }
744  void SetName(const char* v);
745  void SaveName(void);
746 
752  const char* GetMeshName();
753 
754  void SetMeshName(const char* v);
755 
761  const char* GetTextureName();
762 
763  void SetTextureName(const char* v);
764 
771  const char* GetPartName();
772 
773  void SetPartName(const char* v);
774 
781  const char* GetPartMeshName();
782 
783  void SetPartMeshName(const char* v);
784 
791  const char* GetImageName();
792 
793  void SetImageName(const char* v);
794 
795  // For future use, see notes for mesh_index variables, etc.
796  /*
797  unsigned int GetMeshIndex();
798  void SetMeshIndex(unsigned int v);
799  unsigned int GetTextureIndex();
800  void SetTextureIndex(unsigned int v);
801  unsigned int GetTexturePartIndex();
802  void SetTexturePartIndex(unsigned int v);
803  unsigned int GetImageIndex();
804  void SetImageIndex(unsigned int v);
805  */
806 
807  void SetPrice(int trias);
808  psMoney &GetPrice();
809  void SetCategory(psItemCategory* category);
810  psItemCategory* GetCategory();
811  const csArray<INVENTORY_SLOT_NUMBER>& GetSlots() const
812  {
813  return valid_slots_array;
814  }
815 
816  //
817  const char* GetSound();
818  void SetSound(const char* v);
819 
821  {
822  return equipScript;
823  }
824  const csString &GetConsumeScriptName()
825  {
826  return consumeScriptName;
827  }
828 
832  bool SetEquipScript(const csString &script);
833 
839  csArray<ItemRequirement> &GetRequirements();
840  bool SetRequirement(const csString &statName, float statValue);
841 
848  psItem* InstantiateBasicItem(bool transient=false);
849 
850  bool Save();
851  bool SetAttribute(const csString &op, const csString &attrName, float modifier);
852 
854  const csString &GetMusicalSheet(void)
855  {
856  return creativeStats.content;
857  }
858  const csString &GetSketch(void)
859  {
860  return creativeStats.content;
861  }
862  const csString &GetLiteratureText(void)
863  {
864  return creativeStats.content;
865  }
866 
870  bool SetCreation(PSITEMSTATS_CREATIVETYPE, const csString &, csString);
871 
875  void SetCreator(PID, PSITEMSTATS_CREATORSTATUS);
876  bool IsThisTheCreator(PID);
877 
883  const csString &GetCreativeBackgroundImg();
884 
886  bool HasCharges() const;
887  bool IsRechargeable() const;
888  void SetMaxCharges(int charges);
889  int GetMaxCharges() const;
890 
892  csString GetItemCommand()
893  {
894  return itemCommand;
895  }
896 
903  const char* ToString()
904  {
905  return name.GetDataSafe();
906  }
907 
913  double CalcFunction(MathEnvironment* env, const char* functionName, const double* params);
914 
924  double GetProperty(MathEnvironment* env, const char* ptr);
925 
926 
927 public:
928 
930  void* operator new(size_t);
932  void operator delete(void*);
933 
934 private:
936  static PoolAllocator<psItemStats> itempool;
937 };
938 
941 #endif
942 
csString name
Definition: psitemstats.h:214
PSITEMSTATS_WEAPONSKILL_INDEX
Definition: psitemstats.h:52
bool UsesAmmoType(uint32_t id) const
Definition: psitemstats.h:667
ApplicativeScript * GetEquipScript()
Definition: psitemstats.h:820
PSSKILL skill
Definition: psitemstats.h:215
unsigned int PSITEMSTATS_SLOTLIST
Definition: psitemstats.h:159
This is a struct used by item stats to say that a person must have a certain level at a certain skill...
Definition: psitemstats.h:205
PSITEMSTATS_AMMOTYPE AmmoType()
Definition: psitemstats.h:340
psItemAmmoStats & Ammunition()
Definition: psitemstats.h:626
This class stores an items various armour related information.
Definition: psitemstats.h:237
const csString & GetLiteratureText(void)
Definition: psitemstats.h:862
A specific MathEnvironment to be used in a MathScript.
Definition: mathscript.h:188
csString GetItemCommand()
returns the special command assigned to this item
Definition: psitemstats.h:892
float CounterBlockValue()
Definition: psitemstats.h:306
This little class holds info about Ammunition for Ranged Weapons.
Definition: psitemstats.h:329
const char * GetName(int id)
float UntargetedBlockValue()
Definition: psitemstats.h:298
PSITEMSTATS_CREATIVETYPE
Definition: psitemstats.h:115
psWeaponType * Type()
Definition: psitemstats.h:283
PSITEMSTATS_AMMOTYPE
Definition: psitemstats.h:106
PSITEMSTATS_DAMAGETYPE
Definition: psitemstats.h:89
Each weapon specifies what anims can be used with it.
Definition: psitemstats.h:222
void SetQuality(float f)
Definition: psitemstats.h:689
PSITEMSTATS_STAT
Definition: psitemstats.h:69
PSITEMSTATS_ARMORTYPE Type()
Definition: psitemstats.h:246
void SetCreator(PID, PSITEMSTATS_CREATORSTATUS)
sets the creator (i.e. author, artist, etc) of creative things
unsigned int id
Definition: psitemstats.h:213
PSITEMSTATS_FLAGS GetFlags()
Definition: psitemstats.h:632
const csString & GetConsumeScriptName()
Definition: psitemstats.h:824
float GetQuality() const
Definition: psitemstats.h:685
unsigned int PSITEMSTATS_FLAGS
Definition: psitemstats.h:190
A structure that holds the knowledge/practice/rank of each player skill.
Definition: pscharacter.h:322
csStringID anim_id
Definition: psitemstats.h:226
PID GetCreator(PSITEMSTATS_CREATORSTATUS &creatorStatus)
Gets the creator of this creative and the creator setting status.
PSSKILL
Definition: psskills.h:44
PSITEMSTATS_STAT attribute_id
Definition: psitemstats.h:194
const csString & GetMusicalSheet(void)
return creative contents
Definition: psitemstats.h:854
psItemWeaponStats & Weapon()
Definition: psitemstats.h:622
#define PSITEMSTATS_STAT_BONUS_COUNT
Definition: psitemstats.h:198
csString anim_name
Definition: psitemstats.h:225
float TargetedBlockValue()
Definition: psitemstats.h:302
ApplicativeScript is the applied script container.
Definition: scripting.h:143
bool IsThisTheCreator(PID pid)
Checks if the creator of the book is the one passed as argument.
This class holds info about Creative items such as books, etc.
Definition: psitemstats.h:351
PSITEMSTATS_ARMORTYPE
Definition: psitemstats.h:60
This huge class stores all the properties of any object a player can have in the game.
Definition: psitemstats.h:463
PSITEMSTATS_CREATORSTATUS
Definition: psitemstats.h:123
psXMLString getCreativeXML()
Used to get the creative definition so psitem can make it&#39;s own copy of it.
Definition: psitemstats.h:740
This class manages the caching of data that is unchanging during server operation.
Definition: cachemanager.h:234
const char * ToString()
Returns the name of the item.
Definition: psitemstats.h:903
const csString & GetSketch(void)
Definition: psitemstats.h:858
const csArray< INVENTORY_SLOT_NUMBER > & GetSlots() const
Definition: psitemstats.h:811
psItemArmorStats & Armor()
Definition: psitemstats.h:618
PSSKILL statToSkill(PSITEMSTATS_STAT stat)
Convenience function to convert between STAT and SKILL.
float weaponRange
Definition: psitemstats.h:672
This class holds the various cached database information relating to the weapon skills of a an item_s...
Definition: psitemstats.h:271
This class embodies item instances in the game.
Definition: psitem.h:238