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