PageRenderTime 35ms CodeModel.GetById 14ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

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