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/Menu.h"
27 namespace app { class Input; }
48 BattleState(SDL_Surface *background, const PartyLayout &monstersLayout, const PartyLayout &heroesLayout, const Resources *res)
49 : background(background)
50 , monstersLayout(&monstersLayout)
51 , heroesLayout(&heroesLayout)
53 , attackTypeMenu(res->attackIcons)
54 , moveMenu(res->moveIcons)
60 void AddMonster(const Monster &);
61 void AddHero(const Hero &);
64 virtual void EnterState(app::Application &ctrl, SDL_Surface *screen);
65 virtual void ExitState(app::Application &ctrl, SDL_Surface *screen);
66 virtual void ResumeState(app::Application &ctrl, SDL_Surface *screen);
67 virtual void PauseState(app::Application &ctrl, SDL_Surface *screen);
69 virtual void Resize(int width, int height);
71 virtual void HandleEvents(const app::Input &);
72 virtual void UpdateWorld(float deltaT);
73 virtual void Render(SDL_Surface *);
76 const Resources &Res() const { return *res; }
77 AttackTypeMenu &GetAttackTypeMenu() { return attackTypeMenu; }
78 MoveMenu &GetMoveMenu() { return moveMenu; }
80 graphics::Menu<const common::Spell *> &GetSpellMenu() { return spellMenus[activeHero]; }
81 const graphics::Menu<const common::Spell *> &GetSpellMenu() const { return spellMenus[activeHero]; }
82 graphics::Menu<const common::Item *> &GetIkariMenu() { return ikariMenus[activeHero]; }
83 const graphics::Menu<const common::Item *> &GetIkariMenu() const { return ikariMenus[activeHero]; }
84 graphics::Menu<const common::Item *> &GetItemMenu() { return itemMenu; }
85 const graphics::Menu<const common::Item *> &GetItemMenu() const { return itemMenu; }
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 MaxHeroes() const { return 4; }
110 int MaxMonsters() const { return monsters.size(); }
112 const std::vector<geometry::Point<int> > &MonsterPositions() const { return monsterPositions; }
113 bool MonsterPositionOccupied(int index) { return index >= 0 && index < int(monsters.size()) && monsters[index].Health() > 0; }
114 const std::vector<geometry::Point<int> > &HeroesPositions() const { return heroesPositions; }
115 bool HeroPositionOccupied(int index) const { return index >= 0 && index < numHeroes; }
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);
133 void RenderSmallHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
136 void LoadSpellMenu(std::vector<Hero>::size_type heroIndex);
137 void LoadIkariMenu(std::vector<Hero>::size_type heroIndex);
138 void LoadInventory();
141 SDL_Surface *background;
142 const PartyLayout *monstersLayout;
143 const PartyLayout *heroesLayout;
144 const Resources *res;
145 AttackTypeMenu attackTypeMenu;
147 // TODO: combine all data about heros or monsters
148 std::vector<geometry::Point<int> > monsterPositions;
149 std::vector<geometry::Point<int> > heroesPositions;
150 std::vector<Monster> monsters;
152 graphics::Menu<const common::Spell *> spellMenus[4];
153 graphics::Menu<const common::Item *> itemMenu;
154 graphics::Menu<const common::Item *> ikariMenus[4];
156 SmallHeroTag smallHeroTags[4];
157 geometry::Point<int> heroTagPositions[4];
158 geometry::Point<int> smallHeroTagPositions[4];
159 AttackChoice attackChoices[4];
168 #endif /* BATTLE_BATTLESTATE_H_ */