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