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