]> git.localhorst.tv Git - l2e.git/blob - src/battle/BattleState.h
added item select state
[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 <SDL.h>
25
26 namespace app { class Input; }
27 namespace graphics {
28         class Font;
29         class Frame;
30         class Gauge;
31         class Sprite;
32 }
33
34 namespace battle {
35
36 class PartyLayout;
37
38 class BattleState
39 : public app::State {
40
41 public:
42         BattleState(SDL_Surface *background, const PartyLayout &monstersLayout, const PartyLayout &heroesLayout, const Resources *res)
43         : background(background)
44         , monstersLayout(&monstersLayout)
45         , heroesLayout(&heroesLayout)
46         , res(res)
47         , attackTypeMenu(res->attackIcons)
48         , moveMenu(res->moveIcons)
49         , activeHero(-1) { }
50
51 public:
52         void AddMonster(const Monster &);
53         void AddHero(const Hero &);
54
55 public:
56         virtual void EnterState(app::Application &ctrl, SDL_Surface *screen);
57         virtual void ExitState(app::Application &ctrl, SDL_Surface *screen);
58         virtual void ResumeState(app::Application &ctrl, SDL_Surface *screen);
59         virtual void PauseState(app::Application &ctrl, SDL_Surface *screen);
60
61         virtual void Resize(int width, int height);
62
63         virtual void HandleInput(const app::Input &);
64         virtual void UpdateWorld(float deltaT);
65         virtual void Render(SDL_Surface *);
66
67 public:
68         const Resources &Res() const { return *res; }
69         AttackTypeMenu &GetAttackTypeMenu() { return attackTypeMenu; }
70         MoveMenu &GetMoveMenu() { return moveMenu; }
71
72         bool HasMoreHeroes() const { return activeHero < (int) heroes.size(); }
73         void NextHero() { ++activeHero; }
74         bool BeforeFirstHero() const { return activeHero < 0; }
75         void PreviousHero() { --activeHero; }
76         Hero &ActiveHero() { return heroes[activeHero]; }
77         const Hero &ActiveHero() const { return heroes[activeHero]; }
78         bool HasChosenAttackType() const { return attackChoices[activeHero].GetType() != AttackChoice::UNDECIDED; }
79         void SetAttackType(AttackChoice::Type t) { attackChoices[activeHero].SetType(t); }
80         bool AttackSelectionDone() const { return activeHero >= (int) heroes.size(); }
81         graphics::Menu</* Spell */ void *> &GetSpellMenu() { return spellMenus[activeHero]; }
82         const graphics::Menu</* Spell */ void *> &GetSpellMenu() const { return spellMenus[activeHero]; }
83         graphics::Menu</* Item */ void *> &GetItemMenu() { return itemMenu; }
84                 const graphics::Menu</* Item */ void *> &GetItemMenu() const { return itemMenu; }
85
86 public:
87         geometry::Vector<int> CalculateScreenOffset(SDL_Surface *screen) const {
88                 return geometry::Vector<int>(
89                                 (screen->w - background->w) / 2,
90                                 (screen->h - background->h) / 2);
91         }
92         int BackgroundWidth() const { return background->w; }
93         int BackgroundHeight() const { return background->h; }
94
95         void RenderBackground(SDL_Surface *screen, const geometry::Vector<int> &offset);
96         void RenderMonsters(SDL_Surface *screen, const geometry::Vector<int> &offset);
97         void RenderHeroes(SDL_Surface *screen, const geometry::Vector<int> &offset);
98         void RenderHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
99
100 private:
101         SDL_Surface *background;
102         const PartyLayout *monstersLayout;
103         const PartyLayout *heroesLayout;
104         const Resources *res;
105         AttackTypeMenu attackTypeMenu;
106         MoveMenu moveMenu;
107         std::vector<geometry::Point<int> > monsterPositions;
108         std::vector<geometry::Point<int> > heroesPositions;
109         std::vector<Monster> monsters;
110         std::vector<Hero> heroes;
111         std::vector<graphics::Menu</* Spell */ void *> > spellMenus;
112         graphics::Menu</* Item */ void *> itemMenu;
113         std::vector<HeroTag> heroTags;
114         std::vector<AttackChoice> attackChoices;
115         int activeHero;
116
117 };
118
119 }
120
121 #endif /* BATTLE_BATTLESTATE_H_ */