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)
59 void AddMonster(const Monster &);
60 void AddHero(const Hero &);
63 virtual void EnterState(app::Application &ctrl, SDL_Surface *screen);
64 virtual void ExitState(app::Application &ctrl, SDL_Surface *screen);
65 virtual void ResumeState(app::Application &ctrl, SDL_Surface *screen);
66 virtual void PauseState(app::Application &ctrl, SDL_Surface *screen);
68 virtual void Resize(int width, int height);
70 virtual void HandleEvents(const app::Input &);
71 virtual void UpdateWorld(float deltaT);
72 virtual void Render(SDL_Surface *);
75 const Resources &Res() const { return *res; }
76 AttackTypeMenu &GetAttackTypeMenu() { return attackTypeMenu; }
77 MoveMenu &GetMoveMenu() { return moveMenu; }
79 graphics::Menu<const common::Spell *> &GetSpellMenu() { return spellMenus[activeHero]; }
80 const graphics::Menu<const common::Spell *> &GetSpellMenu() const { return spellMenus[activeHero]; }
81 graphics::Menu<const common::Item *> &GetIkariMenu() { return ikariMenus[activeHero]; }
82 const graphics::Menu<const common::Item *> &GetIkariMenu() const { return ikariMenus[activeHero]; }
83 graphics::Menu<const common::Item *> &GetItemMenu() { return itemMenu; }
84 const graphics::Menu<const common::Item *> &GetItemMenu() const { return itemMenu; }
86 bool HasMoreHeroes() const { return activeHero < numHeroes; }
87 void NextHero() { ++activeHero; }
88 bool BeforeFirstHero() const { return activeHero < 0; }
89 void PreviousHero() { --activeHero; }
90 void SwapHeroes(int lhs, int rhs);
91 Hero &ActiveHero() { return heroes[activeHero]; }
92 const Hero &ActiveHero() const { return heroes[activeHero]; }
94 Hero &HeroAt(int index) { return heroes[index]; }
95 const Hero &HeroAt(int index) const { return heroes[index]; }
96 Monster &MonsterAt(int index) { return monsters[index]; }
97 const Monster &MonsterAt(int index) const { return monsters[index]; }
99 const HeroTag &HeroTagAt(int index) const { return heroTags[index]; }
100 const geometry::Point<int> &HeroTagPositionAt(int index) const { return heroTagPositions[index]; }
102 bool HasChosenAttackType() const { return attackChoices[activeHero].GetType() != AttackChoice::UNDECIDED; }
103 AttackChoice &ActiveHeroAttackChoice() { return attackChoices[activeHero]; }
104 const AttackChoice &ActiveHeroAttackChoice() const { return attackChoices[activeHero]; }
105 const AttackChoice &AttackChoiceAt(int index) const { return attackChoices[index]; }
106 bool AttackSelectionDone() const { return activeHero >= numHeroes; }
108 int NumHeroes() const { return numHeroes; }
109 int MaxMonsters() const { return monsters.size(); }
111 const std::vector<geometry::Point<int> > &MonsterPositions() const { return monsterPositions; }
112 bool MonsterPositionOccupied(int index) { return index >= 0 && index < int(monsters.size()) && monsters[index].Health() > 0; }
113 const std::vector<geometry::Point<int> > &HeroesPositions() const { return heroesPositions; }
114 bool HeroPositionOccupied(int index) { return index >= 0 && index < numHeroes; }
116 void SetRunaway() { ranAway = true; }
117 void ClearAllAttacks();
120 geometry::Vector<int> CalculateScreenOffset(SDL_Surface *screen) const {
121 return geometry::Vector<int>(
122 (screen->w - background->w) / 2,
123 (screen->h - background->h) / 2);
125 int BackgroundWidth() const { return background->w; }
126 int BackgroundHeight() const { return background->h; }
128 void RenderBackground(SDL_Surface *screen, const geometry::Vector<int> &offset);
129 void RenderMonsters(SDL_Surface *screen, const geometry::Vector<int> &offset);
130 void RenderHeroes(SDL_Surface *screen, const geometry::Vector<int> &offset);
131 void RenderHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
134 void LoadSpellMenu(std::vector<Hero>::size_type heroIndex);
135 void LoadIkariMenu(std::vector<Hero>::size_type heroIndex);
136 void LoadInventory();
139 SDL_Surface *background;
140 const PartyLayout *monstersLayout;
141 const PartyLayout *heroesLayout;
142 const Resources *res;
143 AttackTypeMenu attackTypeMenu;
145 // TODO: combine all data about heros or monsters
146 std::vector<geometry::Point<int> > monsterPositions;
147 std::vector<geometry::Point<int> > heroesPositions;
148 std::vector<Monster> monsters;
150 graphics::Menu<const common::Spell *> spellMenus[4];
151 graphics::Menu<const common::Item *> itemMenu;
152 graphics::Menu<const common::Item *> ikariMenus[4];
154 geometry::Point<int> heroTagPositions[4];
155 AttackChoice attackChoices[4];
164 #endif /* BATTLE_BATTLESTATE_H_ */