4 * Created on: Aug 5, 2012
8 #ifndef BATTLE_BATTLESTATE_H_
9 #define BATTLE_BATTLESTATE_H_
11 #include "AttackChoice.h"
12 #include "AttackTypeMenu.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"
26 namespace app { class Input; }
47 BattleState(SDL_Surface *background, const PartyLayout &monstersLayout, const PartyLayout &heroesLayout, const Resources *res)
48 : background(background)
49 , monstersLayout(&monstersLayout)
50 , heroesLayout(&heroesLayout)
52 , attackTypeMenu(res->attackIcons)
53 , moveMenu(res->moveIcons)
57 void AddMonster(const Monster &);
58 void AddHero(const Hero &);
61 virtual void EnterState(app::Application &ctrl, SDL_Surface *screen);
62 virtual void ExitState(app::Application &ctrl, SDL_Surface *screen);
63 virtual void ResumeState(app::Application &ctrl, SDL_Surface *screen);
64 virtual void PauseState(app::Application &ctrl, SDL_Surface *screen);
66 virtual void Resize(int width, int height);
68 virtual void HandleInput(const app::Input &);
69 virtual void UpdateWorld(float deltaT);
70 virtual void Render(SDL_Surface *);
73 const Resources &Res() const { return *res; }
74 AttackTypeMenu &GetAttackTypeMenu() { return attackTypeMenu; }
75 MoveMenu &GetMoveMenu() { return moveMenu; }
77 bool HasMoreHeroes() const { return activeHero < (int) heroes.size(); }
78 void NextHero() { ++activeHero; }
79 bool BeforeFirstHero() const { return activeHero < 0; }
80 void PreviousHero() { --activeHero; }
81 Hero &ActiveHero() { return heroes[activeHero]; }
82 const Hero &ActiveHero() const { return heroes[activeHero]; }
83 Hero &HeroAt(std::vector<Hero>::size_type index) { return heroes[index]; }
84 const Hero &HeroAt(std::vector<Hero>::size_type index) const { return heroes[index]; }
85 const HeroTag &ActiveHeroTag() const { return heroTags[activeHero]; }
86 const HeroTag &HeroTagAt(std::vector<Hero>::size_type index) const { return heroTags[index]; }
87 const geometry::Point<int> &HeroTagPositionAt(std::vector<Hero>::size_type index) const { return heroTagPositions[index]; }
88 bool HasChosenAttackType() const { return attackChoices[activeHero].GetType() != AttackChoice::UNDECIDED; }
89 void SetAttackType(AttackChoice::Type t) { attackChoices[activeHero].SetType(t); }
90 AttackChoice &ActiveHeroAttackChoice() { return attackChoices[activeHero]; }
91 const AttackChoice &ActiveHeroAttackChoice() const { return attackChoices[activeHero]; }
92 TargetSelection &ActiveHeroTargets() { return attackChoices[activeHero].Selection(); }
93 const TargetSelection &ActiveHeroTargets() const { return attackChoices[activeHero].Selection(); }
94 bool AttackSelectionDone() const { return activeHero >= (int) heroes.size(); }
96 graphics::Menu<const common::Spell *> &GetSpellMenu() { return spellMenus[activeHero]; }
97 const graphics::Menu<const common::Spell *> &GetSpellMenu() const { return spellMenus[activeHero]; }
98 graphics::Menu</* Ikari or Item */ void *> &GetIkariMenu() { return ikariMenus[activeHero]; }
99 const graphics::Menu</* Ikari or Item */ void *> &GetIkariMenu() const { return ikariMenus[activeHero]; }
100 graphics::Menu<const common::Item *> &GetItemMenu() { return itemMenu; }
101 const graphics::Menu<const common::Item *> &GetItemMenu() const { return itemMenu; }
103 const std::vector<geometry::Point<int> > &MonsterPositions() const { return monsterPositions; }
104 bool MonsterPositionOccupied(int index) { return index >= 0 && index < int(monsters.size()) && monsters[index].Health() > 0; }
105 const std::vector<geometry::Point<int> > &HeroesPositions() const { return heroesPositions; }
106 bool HeroPositionOccupied(int index) { return index >= 0 && index < int(heroes.size()); }
107 std::vector<Hero> &Heroes() { return heroes; }
108 const std::vector<Hero> &Heroes() const { return heroes; }
111 geometry::Vector<int> CalculateScreenOffset(SDL_Surface *screen) const {
112 return geometry::Vector<int>(
113 (screen->w - background->w) / 2,
114 (screen->h - background->h) / 2);
116 int BackgroundWidth() const { return background->w; }
117 int BackgroundHeight() const { return background->h; }
119 void RenderBackground(SDL_Surface *screen, const geometry::Vector<int> &offset);
120 void RenderMonsters(SDL_Surface *screen, const geometry::Vector<int> &offset);
121 void RenderHeroes(SDL_Surface *screen, const geometry::Vector<int> &offset);
122 void RenderHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
125 void LoadSpellMenu(std::vector<Hero>::size_type heroIndex);
126 void LoadInventory();
129 SDL_Surface *background;
130 const PartyLayout *monstersLayout;
131 const PartyLayout *heroesLayout;
132 const Resources *res;
133 AttackTypeMenu attackTypeMenu;
135 // TODO: combine all data about heros or monsters
136 std::vector<geometry::Point<int> > monsterPositions;
137 std::vector<geometry::Point<int> > heroesPositions;
138 std::vector<Monster> monsters;
139 std::vector<Hero> heroes;
140 std::vector<graphics::Menu<const common::Spell *> > spellMenus;
141 graphics::Menu<const common::Item *> itemMenu;
142 std::vector<graphics::Menu</* Ikari or Item */ void *> > ikariMenus;
144 geometry::Point<int> heroTagPositions[4];
145 AttackChoice attackChoices[4];
152 #endif /* BATTLE_BATTLESTATE_H_ */