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