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