]> git.localhorst.tv Git - l2e.git/blob - src/battle/BattleState.h
renamed Animation to SimpleAnimation
[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 "SmallHeroTag.h"
19 #include "../app/State.h"
20 #include "../geometry/Point.h"
21 #include "../geometry/Vector.h"
22 #include "../graphics/Menu.h"
23 #include "../graphics/SimpleAnimation.h"
24
25 #include <vector>
26 #include <SDL.h>
27
28 namespace app { class Input; }
29 namespace common {
30         class Inventory;
31         class Item;
32         class Spell;
33 }
34 namespace graphics {
35         class Font;
36         class Frame;
37         class Gauge;
38         class Sprite;
39 }
40
41 namespace battle {
42
43 class PartyLayout;
44
45 class BattleState
46 : public app::State {
47
48 public:
49         BattleState(SDL_Surface *background, const PartyLayout &monstersLayout, const PartyLayout &heroesLayout, const Resources *res)
50         : background(background)
51         , monstersLayout(&monstersLayout)
52         , heroesLayout(&heroesLayout)
53         , res(res)
54         , attackTypeMenu(res->attackIcons)
55         , moveMenu(res->moveIcons)
56         , numHeroes(0)
57         , activeHero(-1)
58         , ranAway(false) { }
59
60 public:
61         void AddMonster(const Monster &);
62         void AddHero(const Hero &);
63
64 public:
65         virtual void EnterState(app::Application &ctrl, SDL_Surface *screen);
66         virtual void ExitState(app::Application &ctrl, SDL_Surface *screen);
67         virtual void ResumeState(app::Application &ctrl, SDL_Surface *screen);
68         virtual void PauseState(app::Application &ctrl, SDL_Surface *screen);
69
70         virtual void Resize(int width, int height);
71
72         virtual void HandleEvents(const app::Input &);
73         virtual void UpdateWorld(float deltaT);
74         virtual void Render(SDL_Surface *);
75
76 public:
77         const Resources &Res() const { return *res; }
78         AttackTypeMenu &GetAttackTypeMenu() { return attackTypeMenu; }
79         MoveMenu &GetMoveMenu() { return moveMenu; }
80
81         graphics::Menu<const common::Spell *> &GetSpellMenu() { return spellMenus[activeHero]; }
82         const graphics::Menu<const common::Spell *> &GetSpellMenu() const { return spellMenus[activeHero]; }
83         graphics::Menu<const common::Item *> &GetIkariMenu() { return ikariMenus[activeHero]; }
84         const graphics::Menu<const common::Item *> &GetIkariMenu() const { return ikariMenus[activeHero]; }
85         graphics::Menu<const common::Item *> &GetItemMenu() { return itemMenu; }
86         const graphics::Menu<const common::Item *> &GetItemMenu() const { return itemMenu; }
87
88         void NextHero();
89         bool BeforeFirstHero() const { return activeHero < 0; }
90         void PreviousHero() { --activeHero; }
91         void SwapHeroes(int lhs, int rhs);
92         Hero &ActiveHero() { return heroes[activeHero]; }
93         const Hero &ActiveHero() const { return heroes[activeHero]; }
94
95         Hero &HeroAt(int index) { return heroes[index]; }
96         const Hero &HeroAt(int index) const { return heroes[index]; }
97         Monster &MonsterAt(int index) { return monsters[index]; }
98         const Monster &MonsterAt(int index) const { return monsters[index]; }
99
100         graphics::SimpleAnimation &HeroAnimationAt(int index) { return heroAnimations[index]; }
101         const graphics::SimpleAnimation &HeroAnimationAt(int index) const { return heroAnimations[index]; }
102
103         const HeroTag &HeroTagAt(int index) const { return heroTags[index]; }
104         const geometry::Point<int> &HeroTagPositionAt(int index) const { return heroTagPositions[index]; }
105
106         bool HasChosenAttackType() const { return attackChoices[activeHero].GetType() != AttackChoice::UNDECIDED; }
107         AttackChoice &ActiveHeroAttackChoice() { return attackChoices[activeHero]; }
108         const AttackChoice &ActiveHeroAttackChoice() const { return attackChoices[activeHero]; }
109         const AttackChoice &AttackChoiceAt(int index) const { return attackChoices[index]; }
110         bool AttackSelectionDone() const { return activeHero >= numHeroes; }
111
112         int NumHeroes() const { return numHeroes; }
113         int MaxHeroes() const { return 4; }
114         int MaxMonsters() const { return monsters.size(); }
115
116         const std::vector<geometry::Point<int> > &MonsterPositions() const { return monsterPositions; }
117         bool MonsterPositionOccupied(int index) { return index >= 0 && index < int(monsters.size()) && monsters[index].Health() > 0; }
118         const std::vector<geometry::Point<int> > &HeroesPositions() const { return heroesPositions; }
119         bool HeroPositionOccupied(int index) const { return index >= 0 && index < numHeroes; }
120
121         void SetRunaway() { ranAway = true; }
122         void ClearAllAttacks();
123
124 public:
125         geometry::Vector<int> CalculateScreenOffset(SDL_Surface *screen) const {
126                 return geometry::Vector<int>(
127                                 (screen->w - background->w) / 2,
128                                 (screen->h - background->h) / 2);
129         }
130         int BackgroundWidth() const { return background->w; }
131         int BackgroundHeight() const { return background->h; }
132
133         void RenderBackground(SDL_Surface *screen, const geometry::Vector<int> &offset);
134         void RenderMonsters(SDL_Surface *screen, const geometry::Vector<int> &offset);
135         void RenderHeroes(SDL_Surface *screen, const geometry::Vector<int> &offset);
136         void RenderHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
137         void RenderSmallHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
138
139 private:
140         void LoadSpellMenu(std::vector<Hero>::size_type heroIndex);
141         void LoadIkariMenu(std::vector<Hero>::size_type heroIndex);
142         void LoadInventory();
143
144 private:
145         SDL_Surface *background;
146         const PartyLayout *monstersLayout;
147         const PartyLayout *heroesLayout;
148         const Resources *res;
149         AttackTypeMenu attackTypeMenu;
150         MoveMenu moveMenu;
151         // TODO: combine all data about heros or monsters
152         std::vector<geometry::Point<int> > monsterPositions;
153         std::vector<geometry::Point<int> > heroesPositions;
154         std::vector<Monster> monsters;
155         Hero heroes[4];
156         graphics::SimpleAnimation heroAnimations[4];
157         graphics::Menu<const common::Spell *> spellMenus[4];
158         graphics::Menu<const common::Item *> itemMenu;
159         graphics::Menu<const common::Item *> ikariMenus[4];
160         HeroTag heroTags[4];
161         SmallHeroTag smallHeroTags[4];
162         geometry::Point<int> heroTagPositions[4];
163         geometry::Point<int> smallHeroTagPositions[4];
164         AttackChoice attackChoices[4];
165         int numHeroes;
166         int activeHero;
167         bool ranAway;
168
169 };
170
171 }
172
173 #endif /* BATTLE_BATTLESTATE_H_ */