]> git.localhorst.tv Git - l2e.git/blob - src/battle/BattleState.h
added spell selection battle 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 "../app/State.h"
18 #include "../geometry/Point.h"
19 #include "../geometry/Vector.h"
20
21 #include <vector>
22 #include <SDL.h>
23
24 namespace app { class Input; }
25 namespace graphics {
26         class Font;
27         class Frame;
28         class Gauge;
29         class Sprite;
30 }
31
32 namespace battle {
33
34 class PartyLayout;
35
36 class BattleState
37 : public app::State {
38
39 public:
40         BattleState(SDL_Surface *background, const PartyLayout &monstersLayout, const PartyLayout &heroesLayout, const graphics::Sprite *attackIcons, const graphics::Sprite *moveIcons, const graphics::Frame *heroTagFrame, const graphics::Frame *activeHeroTagFrame, const graphics::Gauge *healthGauge, const graphics::Gauge *manaGauge, const graphics::Gauge *ikariGauge, const graphics::Sprite *heroTagSprites, const graphics::Font *heroTagFont, const graphics::Frame *selectFrame)
41         : background(background)
42         , monstersLayout(&monstersLayout)
43         , heroesLayout(&heroesLayout)
44         , heroTagFrame(heroTagFrame)
45         , activeHeroTagFrame(activeHeroTagFrame)
46         , healthGauge(healthGauge)
47         , manaGauge(manaGauge)
48         , ikariGauge(ikariGauge)
49         , heroTagSprites(heroTagSprites)
50         , heroTagFont(heroTagFont)
51         , selectFrame(selectFrame)
52         , attackTypeMenu(attackIcons)
53         , moveMenu(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         AttackTypeMenu &GetAttackTypeMenu() { return attackTypeMenu; }
74         MoveMenu &GetMoveMenu() { return moveMenu; }
75         const graphics::Frame &GetSelectFrame() const { return *selectFrame; }
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
87 public:
88         geometry::Vector<int> CalculateScreenOffset(SDL_Surface *screen) const {
89                 return geometry::Vector<int>(
90                                 (screen->w - background->w) / 2,
91                                 (screen->h - background->h) / 2);
92         }
93         int BackgroundWidth() const { return background->w; }
94         int BackgroundHeight() const { return background->h; }
95
96         void RenderBackground(SDL_Surface *screen, const geometry::Vector<int> &offset);
97         void RenderMonsters(SDL_Surface *screen, const geometry::Vector<int> &offset);
98         void RenderHeroes(SDL_Surface *screen, const geometry::Vector<int> &offset);
99         void RenderHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
100
101 private:
102         SDL_Surface *background;
103         const PartyLayout *monstersLayout;
104         const PartyLayout *heroesLayout;
105         const graphics::Frame *heroTagFrame;
106         const graphics::Frame *activeHeroTagFrame;
107         const graphics::Gauge *healthGauge;
108         const graphics::Gauge *manaGauge;
109         const graphics::Gauge *ikariGauge;
110         const graphics::Sprite *heroTagSprites;
111         const graphics::Font *heroTagFont;
112         const graphics::Frame *selectFrame;
113         AttackTypeMenu attackTypeMenu;
114         MoveMenu moveMenu;
115         std::vector<geometry::Point<int> > monsterPositions;
116         std::vector<geometry::Point<int> > heroesPositions;
117         std::vector<Monster> monsters;
118         std::vector<Hero> heroes;
119         std::vector<HeroTag> heroTags;
120         std::vector<AttackChoice> attackChoices;
121         int activeHero;
122
123 };
124
125 }
126
127 #endif /* BATTLE_BATTLESTATE_H_ */