]> git.localhorst.tv Git - l2e.git/blob - src/battle/BattleState.h
added item target selection
[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         Hero &HeroAt(std::vector<Hero>::size_type index) { return heroes[index]; }
83         const Hero &HeroAt(std::vector<Hero>::size_type index) const { return heroes[index]; }
84         const HeroTag &ActiveHeroTag() const { return heroTags[activeHero]; }
85         const HeroTag &HeroTagAt(std::vector<Hero>::size_type index) const { return heroTags[index]; }
86         const geometry::Point<int> &HeroTagPositionAt(std::vector<Hero>::size_type index) const { return heroTagPositions[index]; }
87         bool HasChosenAttackType() const { return attackChoices[activeHero].GetType() != AttackChoice::UNDECIDED; }
88         void SetAttackType(AttackChoice::Type t) { attackChoices[activeHero].SetType(t); }
89         AttackChoice &ActiveHeroAttackChoice() { return attackChoices[activeHero]; }
90         const AttackChoice &ActiveHeroAttackChoice() const { return attackChoices[activeHero]; }
91         TargetSelection &ActiveHeroTargets() { return attackChoices[activeHero].Selection(); }
92         const TargetSelection &ActiveHeroTargets() const { return attackChoices[activeHero].Selection(); }
93         bool AttackSelectionDone() const { return activeHero >= (int) heroes.size(); }
94
95         graphics::Menu</* Spell */ void *> &GetSpellMenu() { return spellMenus[activeHero]; }
96         const graphics::Menu</* Spell */ void *> &GetSpellMenu() const { return spellMenus[activeHero]; }
97         graphics::Menu</* Ikari or Item */ void *> &GetIkariMenu() { return ikariMenus[activeHero]; }
98         const graphics::Menu</* Ikari or Item */ void *> &GetIkariMenu() const { return ikariMenus[activeHero]; }
99         graphics::Menu<const common::Item *> &GetItemMenu() { return itemMenu; }
100         const graphics::Menu<const common::Item *> &GetItemMenu() const { return itemMenu; }
101
102         const std::vector<geometry::Point<int> > &MonsterPositions() const { return monsterPositions; }
103         bool MonsterPositionOccupied(int index) { return index >= 0 && index < int(monsters.size()) && monsters[index].Health() > 0; }
104         const std::vector<geometry::Point<int> > &HeroesPositions() const { return heroesPositions; }
105         bool HeroPositionOccupied(int index) { return index >= 0 && index < int(heroes.size()); }
106         std::vector<Hero> &Heroes() { return heroes; }
107         const std::vector<Hero> &Heroes() const { return heroes; }
108
109 public:
110         geometry::Vector<int> CalculateScreenOffset(SDL_Surface *screen) const {
111                 return geometry::Vector<int>(
112                                 (screen->w - background->w) / 2,
113                                 (screen->h - background->h) / 2);
114         }
115         int BackgroundWidth() const { return background->w; }
116         int BackgroundHeight() const { return background->h; }
117
118         void RenderBackground(SDL_Surface *screen, const geometry::Vector<int> &offset);
119         void RenderMonsters(SDL_Surface *screen, const geometry::Vector<int> &offset);
120         void RenderHeroes(SDL_Surface *screen, const geometry::Vector<int> &offset);
121         void RenderHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
122
123 private:
124         void LoadInventory();
125
126 private:
127         SDL_Surface *background;
128         const PartyLayout *monstersLayout;
129         const PartyLayout *heroesLayout;
130         const Resources *res;
131         AttackTypeMenu attackTypeMenu;
132         MoveMenu moveMenu;
133         // TODO: combine all data about heros or monsters
134         std::vector<geometry::Point<int> > monsterPositions;
135         std::vector<geometry::Point<int> > heroesPositions;
136         std::vector<Monster> monsters;
137         std::vector<Hero> heroes;
138         std::vector<graphics::Menu</* Spell */ void *> > spellMenus;
139         graphics::Menu<const common::Item *> itemMenu;
140         std::vector<graphics::Menu</* Ikari or Item */ void *> > ikariMenus;
141         HeroTag heroTags[4];
142         geometry::Point<int> heroTagPositions[4];
143         AttackChoice attackChoices[4];
144         int activeHero;
145
146 };
147
148 }
149
150 #endif /* BATTLE_BATTLESTATE_H_ */