]> git.localhorst.tv Git - l2e.git/blob - src/battle/BattleState.h
reworked Application's state stack
[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 { class Sprite; }
26
27 namespace battle {
28
29 class PartyLayout;
30
31 // TODO: maybe split battle state into substates for each menu?
32 class BattleState
33 : public app::State {
34
35 public:
36         BattleState(SDL_Surface *background, const PartyLayout &monstersLayout, const PartyLayout &heroesLayout, const graphics::Sprite *attackIcons, const graphics::Sprite *moveIcons)
37         : background(background)
38         , monstersLayout(&monstersLayout)
39         , heroesLayout(&heroesLayout)
40         , attackTypeMenu(attackIcons)
41         , moveMenu(moveIcons)
42         , activeHero(-1) { }
43
44 public:
45         void AddMonster(const Monster &);
46         void AddHero(const Hero &);
47
48 public:
49         virtual void EnterState(app::Application &ctrl, SDL_Surface *screen);
50         virtual void ExitState(app::Application &ctrl, SDL_Surface *screen);
51         virtual void ResumeState(app::Application &ctrl, SDL_Surface *screen);
52         virtual void PauseState(app::Application &ctrl, SDL_Surface *screen);
53
54         virtual void Resize(int width, int height);
55
56         virtual void HandleInput(const app::Input &);
57         virtual void UpdateWorld(float deltaT);
58         virtual void Render(SDL_Surface *);
59
60 public:
61         AttackTypeMenu &GetAttackTypeMenu() { return attackTypeMenu; }
62         MoveMenu &GetMoveMenu() { return moveMenu; }
63
64         bool HasMoreHeroes() const { return activeHero < (int) heroes.size(); }
65         void NextHero() { ++activeHero; }
66         bool HasChosenAttackType() const { return attackChoices[activeHero].GetType() != AttackChoice::UNDECIDED; }
67         void SetAttackType(AttackChoice::Type t) { attackChoices[activeHero].SetType(t); }
68         bool AttackSelectionDone() const { return activeHero >= (int) heroes.size(); }
69
70 public:
71         geometry::Vector<int> CalculateScreenOffset(SDL_Surface *screen) const {
72                 return geometry::Vector<int>(
73                                 (screen->w - background->w) / 2,
74                                 (screen->h - background->h) / 2);
75         }
76         int BackgroundWidth() const { return background->w; }
77         int BackgroundHeight() const { return background->h; }
78
79         void RenderBackground(SDL_Surface *screen, const geometry::Vector<int> &offset);
80         void RenderMonsters(SDL_Surface *screen, const geometry::Vector<int> &offset);
81         void RenderHeroes(SDL_Surface *screen, const geometry::Vector<int> &offset);
82         void RenderHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
83
84 private:
85         SDL_Surface *background;
86         const PartyLayout *monstersLayout;
87         const PartyLayout *heroesLayout;
88         AttackTypeMenu attackTypeMenu;
89         MoveMenu moveMenu;
90         std::vector<geometry::Point<int> > monsterPositions;
91         std::vector<geometry::Point<int> > heroesPositions;
92         std::vector<Monster> monsters;
93         std::vector<Hero> heroes;
94         std::vector<HeroTag> heroTags;
95         std::vector<AttackChoice> attackChoices;
96         int activeHero;
97
98 };
99
100 }
101
102 #endif /* BATTLE_BATTLESTATE_H_ */