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 "SmallHeroTag.h"
19 #include "../app/State.h"
20 #include "../geometry/Point.h"
21 #include "../geometry/Vector.h"
22 #include "../graphics/Animation.h"
23 #include "../graphics/Menu.h"
28 namespace app { class Input; }
49 BattleState(SDL_Surface *background, const PartyLayout &monstersLayout, const PartyLayout &heroesLayout, const Resources *res)
50 : background(background)
51 , monstersLayout(&monstersLayout)
52 , heroesLayout(&heroesLayout)
54 , attackTypeMenu(res->attackIcons)
55 , moveMenu(res->moveIcons)
61 void AddMonster(const Monster &);
62 void AddHero(const Hero &);
65 virtual void EnterState(app::Application &ctrl, SDL_Surface *screen);
66 virtual void ExitState(app::Application &ctrl, SDL_Surface *screen);
67 virtual void ResumeState(app::Application &ctrl, SDL_Surface *screen);
68 virtual void PauseState(app::Application &ctrl, SDL_Surface *screen);
70 virtual void Resize(int width, int height);
72 virtual void HandleEvents(const app::Input &);
73 virtual void UpdateWorld(float deltaT);
74 virtual void Render(SDL_Surface *);
77 const Resources &Res() const { return *res; }
78 AttackTypeMenu &GetAttackTypeMenu() { return attackTypeMenu; }
79 MoveMenu &GetMoveMenu() { return moveMenu; }
81 graphics::Menu<const common::Spell *> &GetSpellMenu() { return spellMenus[activeHero]; }
82 const graphics::Menu<const common::Spell *> &GetSpellMenu() const { return spellMenus[activeHero]; }
83 graphics::Menu<const common::Item *> &GetIkariMenu() { return ikariMenus[activeHero]; }
84 const graphics::Menu<const common::Item *> &GetIkariMenu() const { return ikariMenus[activeHero]; }
85 graphics::Menu<const common::Item *> &GetItemMenu() { return itemMenu; }
86 const graphics::Menu<const common::Item *> &GetItemMenu() const { return itemMenu; }
89 bool BeforeFirstHero() const { return activeHero < 0; }
90 void PreviousHero() { --activeHero; }
91 void SwapHeroes(int lhs, int rhs);
92 Hero &ActiveHero() { return heroes[activeHero]; }
93 const Hero &ActiveHero() const { return heroes[activeHero]; }
95 Hero &HeroAt(int index) { return heroes[index]; }
96 const Hero &HeroAt(int index) const { return heroes[index]; }
97 Monster &MonsterAt(int index) { return monsters[index]; }
98 const Monster &MonsterAt(int index) const { return monsters[index]; }
100 const HeroTag &HeroTagAt(int index) const { return heroTags[index]; }
101 const geometry::Point<int> &HeroTagPositionAt(int index) const { return heroTagPositions[index]; }
103 bool HasChosenAttackType() const { return attackChoices[activeHero].GetType() != AttackChoice::UNDECIDED; }
104 AttackChoice &ActiveHeroAttackChoice() { return attackChoices[activeHero]; }
105 const AttackChoice &ActiveHeroAttackChoice() const { return attackChoices[activeHero]; }
106 const AttackChoice &AttackChoiceAt(int index) const { return attackChoices[index]; }
107 bool AttackSelectionDone() const { return activeHero >= numHeroes; }
109 int NumHeroes() const { return numHeroes; }
110 int MaxHeroes() const { return 4; }
111 int MaxMonsters() const { return monsters.size(); }
113 const std::vector<geometry::Point<int> > &MonsterPositions() const { return monsterPositions; }
114 bool MonsterPositionOccupied(int index) { return index >= 0 && index < int(monsters.size()) && monsters[index].Health() > 0; }
115 const std::vector<geometry::Point<int> > &HeroesPositions() const { return heroesPositions; }
116 bool HeroPositionOccupied(int index) const { return index >= 0 && index < numHeroes; }
118 void SetRunaway() { ranAway = true; }
119 void ClearAllAttacks();
122 Order(int index, bool isMonster)
123 : index(index), isMonster(isMonster) { }
128 void WriteOrder(std::vector<Order> &);
131 geometry::Vector<int> CalculateScreenOffset(SDL_Surface *screen) const {
132 return geometry::Vector<int>(
133 (screen->w - background->w) / 2,
134 (screen->h - background->h) / 2);
136 int BackgroundWidth() const { return background->w; }
137 int BackgroundHeight() const { return background->h; }
139 void RenderBackground(SDL_Surface *screen, const geometry::Vector<int> &offset);
140 void RenderMonsters(SDL_Surface *screen, const geometry::Vector<int> &offset);
141 void RenderHeroes(SDL_Surface *screen, const geometry::Vector<int> &offset);
142 void RenderHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
143 void RenderSmallHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
146 void LoadSpellMenu(std::vector<Hero>::size_type heroIndex);
147 void LoadIkariMenu(std::vector<Hero>::size_type heroIndex);
148 void LoadInventory();
151 SDL_Surface *background;
152 const PartyLayout *monstersLayout;
153 const PartyLayout *heroesLayout;
154 const Resources *res;
155 AttackTypeMenu attackTypeMenu;
157 // TODO: combine all data about heros or monsters
158 std::vector<geometry::Point<int> > monsterPositions;
159 std::vector<geometry::Point<int> > heroesPositions;
160 std::vector<Monster> monsters;
162 graphics::Menu<const common::Spell *> spellMenus[4];
163 graphics::Menu<const common::Item *> itemMenu;
164 graphics::Menu<const common::Item *> ikariMenus[4];
166 SmallHeroTag smallHeroTags[4];
167 geometry::Point<int> heroTagPositions[4];
168 geometry::Point<int> smallHeroTagPositions[4];
169 AttackChoice attackChoices[4];
178 #endif /* BATTLE_BATTLESTATE_H_ */