/src/LootManager.h

http://github.com/clintbellanger/flare · C Header · 120 lines · 65 code · 26 blank · 29 comment · 0 complexity · 97f0582a8d2310092d1927b36d5340f4 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 LootManager
  15. *
  16. * Handles floor loot
  17. */
  18. #ifndef LOOT_MANAGER_H
  19. #define LOOT_MANAGER_H
  20. #include "Utils.h"
  21. #include "ItemManager.h"
  22. #include "WidgetTooltip.h"
  23. #include "EnemyManager.h"
  24. #include "SharedResources.h"
  25. #include <SDL.h>
  26. #include <SDL_image.h>
  27. #include <SDL_mixer.h>
  28. #include <string>
  29. struct LootDef {
  30. ItemStack stack;
  31. int frame;
  32. Point pos;
  33. int gold;
  34. TooltipData tip;
  35. };
  36. // this means that normal items are 10x more common than epic items
  37. // these numbers have to be balanced by various factors
  38. const int RARITY_LOW = 7;
  39. const int RARITY_NORMAL = 10;
  40. const int RARITY_HIGH = 3;
  41. const int RARITY_EPIC = 1;
  42. // how close (map units) does the hero have to be to pick up loot?
  43. const int LOOT_RANGE = 3 * UNITS_PER_TILE;
  44. class LootManager {
  45. private:
  46. ItemManager *items;
  47. WidgetTooltip *tip;
  48. EnemyManager *enemies;
  49. MapIso *map;
  50. // functions
  51. void loadGraphics();
  52. void calcTables();
  53. int lootLevel(int base_level);
  54. SDL_Surface *flying_loot[64];
  55. SDL_Surface *flying_gold[3];
  56. std::string animation_id[64];
  57. int animation_count;
  58. Mix_Chunk *loot_flip;
  59. Point frame_size;
  60. int frame_count; // the last frame is the "at-rest" floor loot graphic
  61. // loot refers to ItemManager indices
  62. LootDef loot[256]; // TODO: change to dynamic list without limits
  63. // loot tables multiplied out
  64. // currently loot can range from levels 0-20
  65. int loot_table[21][1024]; // level, number. the int is an item id
  66. int loot_table_count[21]; // total number per level
  67. // animation vars
  68. int anim_loot_frames;
  69. int anim_loot_duration;
  70. public:
  71. LootManager(ItemManager *_items, EnemyManager *_enemies, MapIso *_map);
  72. ~LootManager();
  73. void handleNewMap();
  74. void logic();
  75. void renderTooltips(Point cam);
  76. void checkEnemiesForLoot();
  77. void checkMapForLoot();
  78. bool isFlying(int loot_index);
  79. void determineLoot(int base_level, Point pos);
  80. int randomItem(int base_level);
  81. void addLoot(ItemStack stack, Point pos);
  82. void addGold(int count, Point pos);
  83. void removeLoot(int index);
  84. ItemStack checkPickup(Point mouse, Point cam, Point hero_pos, int &gold, bool inv_full);
  85. Renderable getRender(int index);
  86. int tooltip_margin;
  87. int loot_count;
  88. bool full_msg;
  89. };
  90. #endif