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