]> git.localhorst.tv Git - l2e.git/blob - src/battle/BattleState.h
show battle results interactively
[l2e.git] / src / battle / BattleState.h
1 #ifndef BATTLE_BATTLESTATE_H_
2 #define BATTLE_BATTLESTATE_H_
3
4 namespace battle {
5         class PartyLayout;
6 }
7 namespace common {
8         class Item;
9         struct GameConfig;
10 }
11 namespace math {
12         template<class>
13         class Vector;
14 }
15
16 #include "AttackTypeMenu.h"
17 #include "Battle.h"
18 #include "Capsule.h"
19 #include "Hero.h"
20 #include "HeroTag.h"
21 #include "Monster.h"
22 #include "MoveMenu.h"
23 #include "Resources.h"
24 #include "SmallHeroTag.h"
25 #include "../app/State.h"
26 #include "../common/GameConfig.h"
27 #include "../common/Stats.h"
28 #include "../graphics/Animation.h"
29 #include "../graphics/Menu.h"
30
31 #include <cassert>
32 #include <vector>
33 #include <SDL.h>
34
35 namespace battle {
36
37 class BattleState
38 : public app::State {
39
40 public:
41         BattleState(common::GameConfig *game, SDL_Surface *background, const PartyLayout *monstersLayout)
42         : game(game)
43         , background(background)
44         , res(game->battleResources)
45         , battle(game->heroesLayout, monstersLayout)
46         , attackTypeMenu(res->attackIcons)
47         , moveMenu(res->moveIcons)
48         , ranAway(false), alreadyPushed(false)
49         { assert(background && game); }
50
51 public:
52         void AddMonster(const Monster &);
53         void AddHero(const Hero &);
54         void SetCapsule(const Capsule &);
55
56 public:
57         virtual void HandleEvents(const app::Input &);
58         virtual void UpdateWorld(Uint32 deltaT);
59         virtual void Render(SDL_Surface *);
60
61 public:
62         Battle &GetBattle() { return battle; }
63         const Battle &GetBattle() const { return battle; }
64         const common::GameConfig &Game() const { return *game; }
65         const Resources &Res() const { return *res; }
66         AttackTypeMenu &GetAttackTypeMenu() { return attackTypeMenu; }
67         MoveMenu &GetMoveMenu() { return moveMenu; }
68
69         graphics::Menu<const common::Item *> &ItemMenu() { return itemMenu; }
70         const graphics::Menu<const common::Item *> &ItemMenu() const { return itemMenu; }
71
72         Hero &HeroAt(int index) { return battle.HeroAt(index); }
73         const Hero &HeroAt(int index) const { return battle.HeroAt(index); }
74         Monster &MonsterAt(int index) { return battle.MonsterAt(index); }
75         const Monster &MonsterAt(int index) const { return battle.MonsterAt(index); }
76
77         const HeroTag &HeroTagAt(int index) const { assert(index >= 0 && index < NumHeroes()); return heroTags[index]; }
78         const math::Vector<int> &HeroTagPositionAt(int index) const { assert(index >= 0 && index < NumHeroes()); return heroTagPositions[index]; }
79
80         int NumHeroes() const { return battle.NumHeroes(); }
81         int MaxHeroes() const { return battle.MaxHeroes(); }
82         int NumMonsters() const { return battle.NumMonsters(); }
83         int MaxMonsters() const { return battle.MaxMonsters(); }
84
85         void SetRunaway() { ranAway = true; }
86
87 public:
88         const math::Vector<int> &ScreenOffset() const { return offset; }
89         int Width() const { return background->w; }
90         int Height() const { return background->h; }
91         math::Vector<int> Size() const { return math::Vector<int>(Width(), Height()); }
92
93         void RenderBackground(SDL_Surface *screen);
94         void RenderMonsters(SDL_Surface *screen);
95         void RenderHeroes(SDL_Surface *screen);
96         void RenderCapsule(SDL_Surface *screen);
97         void RenderHeroTags(SDL_Surface *screen);
98         void RenderSmallHeroTags(SDL_Surface *screen);
99
100 private:
101         virtual void OnEnterState(SDL_Surface *screen);
102         virtual void OnExitState(SDL_Surface *screen);
103         virtual void OnResumeState(SDL_Surface *screen);
104         virtual void OnPauseState(SDL_Surface *screen);
105
106         virtual void OnResize(int width, int height);
107
108 private:
109         void LoadInventory();
110
111 private:
112         common::GameConfig *game;
113         SDL_Surface *background;
114         const Resources *res;
115         Battle battle;
116         AttackTypeMenu attackTypeMenu;
117         MoveMenu moveMenu;
118         graphics::Menu<const common::Item *> itemMenu;
119         HeroTag heroTags[4];
120         SmallHeroTag smallHeroTags[4];
121         math::Vector<int> heroTagPositions[4];
122         math::Vector<int> smallHeroTagPositions[4];
123
124         math::Vector<int> offset;
125
126         bool ranAway;
127         bool alreadyPushed;
128
129 };
130
131 }
132
133 #endif