]> git.localhorst.tv Git - l2e.git/blob - src/battle/BattleState.h
preliminary solution for loading inventory in item select
[l2e.git] / src / battle / BattleState.h
1 /*
2  * BattleState.h
3  *
4  *  Created on: Aug 5, 2012
5  *      Author: holy
6  */
7
8 #ifndef BATTLE_BATTLESTATE_H_
9 #define BATTLE_BATTLESTATE_H_
10
11 #include "AttackChoice.h"
12 #include "AttackTypeMenu.h"
13 #include "Hero.h"
14 #include "HeroTag.h"
15 #include "Monster.h"
16 #include "MoveMenu.h"
17 #include "Resources.h"
18 #include "../app/State.h"
19 #include "../geometry/Point.h"
20 #include "../geometry/Vector.h"
21 #include "../graphics/Menu.h"
22
23 #include <vector>
24 #include <string>
25 #include <SDL.h>
26
27 namespace app { class Input; }
28 namespace common {
29         class Inventory;
30         class Item;
31 }
32 namespace graphics {
33         class Font;
34         class Frame;
35         class Gauge;
36         class Sprite;
37 }
38
39 namespace battle {
40
41 class PartyLayout;
42
43 class BattleState
44 : public app::State {
45
46 public:
47         BattleState(SDL_Surface *background, const PartyLayout &monstersLayout, const PartyLayout &heroesLayout, const Resources *res)
48         : background(background)
49         , monstersLayout(&monstersLayout)
50         , heroesLayout(&heroesLayout)
51         , res(res)
52         , attackTypeMenu(res->attackIcons)
53         , moveMenu(res->moveIcons)
54         , activeHero(-1) { }
55
56 public:
57         void AddMonster(const Monster &);
58         void AddHero(const Hero &);
59
60 public:
61         virtual void EnterState(app::Application &ctrl, SDL_Surface *screen);
62         virtual void ExitState(app::Application &ctrl, SDL_Surface *screen);
63         virtual void ResumeState(app::Application &ctrl, SDL_Surface *screen);
64         virtual void PauseState(app::Application &ctrl, SDL_Surface *screen);
65
66         virtual void Resize(int width, int height);
67
68         virtual void HandleInput(const app::Input &);
69         virtual void UpdateWorld(float deltaT);
70         virtual void Render(SDL_Surface *);
71
72 public:
73         const Resources &Res() const { return *res; }
74         AttackTypeMenu &GetAttackTypeMenu() { return attackTypeMenu; }
75         MoveMenu &GetMoveMenu() { return moveMenu; }
76
77         bool HasMoreHeroes() const { return activeHero < (int) heroes.size(); }
78         void NextHero() { ++activeHero; }
79         bool BeforeFirstHero() const { return activeHero < 0; }
80         void PreviousHero() { --activeHero; }
81         Hero &ActiveHero() { return heroes[activeHero]; }
82         const Hero &ActiveHero() const { return heroes[activeHero]; }
83         bool HasChosenAttackType() const { return attackChoices[activeHero].GetType() != AttackChoice::UNDECIDED; }
84         void SetAttackType(AttackChoice::Type t) { attackChoices[activeHero].SetType(t); }
85         bool AttackSelectionDone() const { return activeHero >= (int) heroes.size(); }
86         graphics::Menu</* Spell */ void *> &GetSpellMenu() { return spellMenus[activeHero]; }
87         const graphics::Menu</* Spell */ void *> &GetSpellMenu() const { return spellMenus[activeHero]; }
88         graphics::Menu</* Ikari or Item */ void *> &GetIkariMenu() { return ikariMenus[activeHero]; }
89         const graphics::Menu</* Ikari or Item */ void *> &GetIkariMenu() const { return ikariMenus[activeHero]; }
90         graphics::Menu<const common::Item *> &GetItemMenu() { return itemMenu; }
91         const graphics::Menu<const common::Item *> &GetItemMenu() const { return itemMenu; }
92
93 public:
94         geometry::Vector<int> CalculateScreenOffset(SDL_Surface *screen) const {
95                 return geometry::Vector<int>(
96                                 (screen->w - background->w) / 2,
97                                 (screen->h - background->h) / 2);
98         }
99         int BackgroundWidth() const { return background->w; }
100         int BackgroundHeight() const { return background->h; }
101
102         void RenderBackground(SDL_Surface *screen, const geometry::Vector<int> &offset);
103         void RenderMonsters(SDL_Surface *screen, const geometry::Vector<int> &offset);
104         void RenderHeroes(SDL_Surface *screen, const geometry::Vector<int> &offset);
105         void RenderHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
106
107 private:
108         void LoadInventory();
109
110 private:
111         SDL_Surface *background;
112         const PartyLayout *monstersLayout;
113         const PartyLayout *heroesLayout;
114         const Resources *res;
115         AttackTypeMenu attackTypeMenu;
116         MoveMenu moveMenu;
117         std::vector<geometry::Point<int> > monsterPositions;
118         std::vector<geometry::Point<int> > heroesPositions;
119         std::vector<Monster> monsters;
120         std::vector<Hero> heroes;
121         std::vector<graphics::Menu</* Spell */ void *> > spellMenus;
122         graphics::Menu<const common::Item *> itemMenu;
123         std::vector<std::string> itemMenuStrings;
124         std::vector<graphics::Menu</* Ikari or Item */ void *> > ikariMenus;
125         std::vector<HeroTag> heroTags;
126         std::vector<AttackChoice> attackChoices;
127         int activeHero;
128
129 };
130
131 }
132
133 #endif /* BATTLE_BATTLESTATE_H_ */