/src/ItemDatabase.h

http://github.com/clintbellanger/flare · C Header · 165 lines · 127 code · 19 blank · 19 comment · 0 complexity · 5170d28813b6c2d8a8ef8d3274b974d9 MD5 · raw file

  1. /*
  2. Copyright 2011 Clint Bellanger
  3. This file is part of FLARE.
  4. FLARE is free software: you can redistribute it and/or modify it under the terms
  5. of the GNU General Public License as published by the Free Software Foundation,
  6. either version 3 of the License, or (at your option) any later version.
  7. FLARE is distributed in the hope that it will be useful, but WITHOUT ANY
  8. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  9. PARTICULAR PURPOSE. See the GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License along with
  11. FLARE. If not, see http://www.gnu.org/licenses/
  12. */
  13. /**
  14. * class ItemDatabase
  15. */
  16. #ifndef ITEM_DATABASE_H
  17. #define ITEM_DATABASE_H
  18. #include <string>
  19. #include <sstream>
  20. #include <fstream>
  21. #include "SDL.h"
  22. #include "SDL_image.h"
  23. #include "SDL_mixer.h"
  24. #include "UtilsParsing.h"
  25. #include "StatBlock.h"
  26. #include "MenuTooltip.h"
  27. #include "MessageEngine.h"
  28. using namespace std;
  29. const int MAX_ITEM_ID = 10000;
  30. const int ICON_SIZE_32 = 32;
  31. const int ICON_SIZE_64 = 64;
  32. const int ITEM_TYPE_OTHER = -1;
  33. const int ITEM_TYPE_MAIN = 0;
  34. const int ITEM_TYPE_BODY = 1;
  35. const int ITEM_TYPE_OFF = 2;
  36. const int ITEM_TYPE_ARTIFACT = 3;
  37. const int ITEM_TYPE_CONSUMABLE = 4;
  38. const int ITEM_TYPE_GEM = 5;
  39. const int ITEM_TYPE_QUEST = 6;
  40. const int REQUIRES_PHYS = 0;
  41. const int REQUIRES_MENT = 1;
  42. const int REQUIRES_OFF = 2;
  43. const int REQUIRES_DEF = 3;
  44. const int SFX_NONE = -1;
  45. const int SFX_BOOK = 0;
  46. const int SFX_CLOTH = 1;
  47. const int SFX_COINS = 2;
  48. const int SFX_GEM = 3;
  49. const int SFX_LEATHER = 4;
  50. const int SFX_METAL = 5;
  51. const int SFX_PAGE = 6;
  52. const int SFX_MAILLE = 7;
  53. const int SFX_OBJECT = 8;
  54. const int SFX_HEAVY = 9;
  55. const int SFX_WOOD = 10;
  56. const int SFX_POTION = 11;
  57. const int ITEM_QUALITY_LOW = 0;
  58. const int ITEM_QUALITY_NORMAL = 1;
  59. const int ITEM_QUALITY_HIGH = 2;
  60. const int ITEM_QUALITY_EPIC = 3;
  61. const int ITEM_MAX_BONUSES = 8;
  62. struct Item {
  63. string name; // item name displayed on long and short tool tips
  64. int level; // rough estimate of quality, used in the loot algorithm
  65. int quality; // low, normal, high, epic; corresponds to item name color
  66. int type; // equipment slot or base item type
  67. int icon32; // icon index on the 32x32 pixel sheet
  68. int icon64; // icon index on the 64x64 pixel sheet (used for equippable items)
  69. int dmg_min; // minimum damage amount (weapons only)
  70. int dmg_max; // maximum damage amount (weapons only)
  71. int abs_min; // minimum absorb amount (armors and shields only)
  72. int abs_max; // maximum absorb amount (armors and shields only)
  73. int req_stat; // physical, mental, offense, defense
  74. int req_val; // 1-5 (used with req_stat)
  75. string *bonus_stat; // stat to increase/decrease e.g. hp, accuracy, speed
  76. int *bonus_val; // amount to increase (used with bonus_stat)
  77. int sfx; // the item sound when it hits the floor or inventory, etc
  78. string gfx; // the sprite layer shown when this item is equipped
  79. string loot; // the flying loot animation for this item
  80. int power; // this item can be dragged to the action bar and used as a power
  81. int power_mod; // alter powers when this item is equipped (e.g. shoot arrows from bows)
  82. string power_desc; // shows up in green text on the tooltip
  83. int price; // if price = 0 the item cannot be sold
  84. int max_quantity; // max count per stack
  85. int rand_loot; // max amount appearing in a loot stack
  86. int rand_vendor; // max amount appearing in a vendor stack
  87. string pickup_status; // when this item is picked up, set a campaign state (usually for quest items)
  88. Item() {
  89. name = "";
  90. level = 0;
  91. quality = ITEM_QUALITY_NORMAL;
  92. icon32 = 0;
  93. icon64 = 0;
  94. type = -1;
  95. dmg_min = 0;
  96. dmg_max = 0;
  97. abs_min = 0;
  98. abs_max = 0;
  99. req_stat = 0;
  100. req_val = 0;
  101. sfx = SFX_NONE;
  102. gfx = "";
  103. loot = "";
  104. power = -1;
  105. power_mod = -1;
  106. power_desc = "";
  107. price = 0;
  108. max_quantity = 1;
  109. rand_loot = 1;
  110. rand_vendor = 1;
  111. pickup_status = "";
  112. }
  113. };
  114. struct ItemStack {
  115. int item;
  116. int quantity;
  117. bool operator > (ItemStack param);
  118. };
  119. class ItemDatabase {
  120. private:
  121. SDL_Surface *screen;
  122. SDL_Surface *icons32;
  123. SDL_Surface *icons64; // item db is the only module that currently uses the 64px icons
  124. FontEngine *font;
  125. SDL_Rect src;
  126. SDL_Rect dest;
  127. Mix_Chunk *sfx[12];
  128. public:
  129. ItemDatabase(SDL_Surface *_screen, FontEngine *_font);
  130. ~ItemDatabase();
  131. void load();
  132. void loadSounds();
  133. void loadIcons();
  134. void renderIcon(ItemStack stack, int x, int y, int size);
  135. void playSound(int item);
  136. void playCoinsSound();
  137. TooltipData getTooltip(int item, StatBlock *stats, bool vendor_view);
  138. TooltipData getShortTooltip(ItemStack item);
  139. Item *items;
  140. int vendor_ratio;
  141. };
  142. #endif