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; }
46 BattleState(SDL_Surface *background, const PartyLayout &monstersLayout, const PartyLayout &heroesLayout, const Resources *res)
47 : background(background)
48 , monstersLayout(&monstersLayout)
49 , heroesLayout(&heroesLayout)
51 , attackTypeMenu(res->attackIcons)
52 , moveMenu(res->moveIcons)
56 void AddMonster(const Monster &);
57 void AddHero(const Hero &);
60 virtual void EnterState(app::Application &ctrl, SDL_Surface *screen);
61 virtual void ExitState(app::Application &ctrl, SDL_Surface *screen);
62 virtual void ResumeState(app::Application &ctrl, SDL_Surface *screen);
63 virtual void PauseState(app::Application &ctrl, SDL_Surface *screen);
65 virtual void Resize(int width, int height);
67 virtual void HandleInput(const app::Input &);
68 virtual void UpdateWorld(float deltaT);
69 virtual void Render(SDL_Surface *);
72 const Resources &Res() const { return *res; }
73 AttackTypeMenu &GetAttackTypeMenu() { return attackTypeMenu; }
74 MoveMenu &GetMoveMenu() { return moveMenu; }
76 bool HasMoreHeroes() const { return activeHero < (int) heroes.size(); }
77 void NextHero() { ++activeHero; }
78 bool BeforeFirstHero() const { return activeHero < 0; }
79 void PreviousHero() { --activeHero; }
80 Hero &ActiveHero() { return heroes[activeHero]; }
81 const Hero &ActiveHero() const { return heroes[activeHero]; }
82 Hero &HeroAt(std::vector<Hero>::size_type index) { return heroes[index]; }
83 const Hero &HeroAt(std::vector<Hero>::size_type index) const { return heroes[index]; }
84 const HeroTag &ActiveHeroTag() const { return heroTags[activeHero]; }
85 const HeroTag &HeroTagAt(std::vector<Hero>::size_type index) const { return heroTags[index]; }
86 const geometry::Point<int> &HeroTagPositionAt(std::vector<Hero>::size_type index) const { return heroTagPositions[index]; }
87 bool HasChosenAttackType() const { return attackChoices[activeHero].GetType() != AttackChoice::UNDECIDED; }
88 void SetAttackType(AttackChoice::Type t) { attackChoices[activeHero].SetType(t); }
89 AttackChoice &ActiveHeroAttackChoice() { return attackChoices[activeHero]; }
90 const AttackChoice &ActiveHeroAttackChoice() const { return attackChoices[activeHero]; }
91 TargetSelection &ActiveHeroTargets() { return attackChoices[activeHero].Selection(); }
92 const TargetSelection &ActiveHeroTargets() const { return attackChoices[activeHero].Selection(); }
93 bool AttackSelectionDone() const { return activeHero >= (int) heroes.size(); }
95 graphics::Menu</* Spell */ void *> &GetSpellMenu() { return spellMenus[activeHero]; }
96 const graphics::Menu</* Spell */ void *> &GetSpellMenu() const { return spellMenus[activeHero]; }
97 graphics::Menu</* Ikari or Item */ void *> &GetIkariMenu() { return ikariMenus[activeHero]; }
98 const graphics::Menu</* Ikari or Item */ void *> &GetIkariMenu() const { return ikariMenus[activeHero]; }
99 graphics::Menu<const common::Item *> &GetItemMenu() { return itemMenu; }
100 const graphics::Menu<const common::Item *> &GetItemMenu() const { return itemMenu; }
102 const std::vector<geometry::Point<int> > &MonsterPositions() const { return monsterPositions; }
103 bool MonsterPositionOccupied(int index) { return index >= 0 && index < int(monsters.size()) && monsters[index].Health() > 0; }
104 const std::vector<geometry::Point<int> > &HeroesPositions() const { return heroesPositions; }
105 bool HeroPositionOccupied(int index) { return index >= 0 && index < int(heroes.size()); }
106 std::vector<Hero> &Heroes() { return heroes; }
107 const std::vector<Hero> &Heroes() const { return heroes; }
110 geometry::Vector<int> CalculateScreenOffset(SDL_Surface *screen) const {
111 return geometry::Vector<int>(
112 (screen->w - background->w) / 2,
113 (screen->h - background->h) / 2);
115 int BackgroundWidth() const { return background->w; }
116 int BackgroundHeight() const { return background->h; }
118 void RenderBackground(SDL_Surface *screen, const geometry::Vector<int> &offset);
119 void RenderMonsters(SDL_Surface *screen, const geometry::Vector<int> &offset);
120 void RenderHeroes(SDL_Surface *screen, const geometry::Vector<int> &offset);
121 void RenderHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
124 void LoadInventory();
127 SDL_Surface *background;
128 const PartyLayout *monstersLayout;
129 const PartyLayout *heroesLayout;
130 const Resources *res;
131 AttackTypeMenu attackTypeMenu;
133 // TODO: combine all data about heros or monsters
134 std::vector<geometry::Point<int> > monsterPositions;
135 std::vector<geometry::Point<int> > heroesPositions;
136 std::vector<Monster> monsters;
137 std::vector<Hero> heroes;
138 std::vector<graphics::Menu</* Spell */ void *> > spellMenus;
139 graphics::Menu<const common::Item *> itemMenu;
140 std::vector<graphics::Menu</* Ikari or Item */ void *> > ikariMenus;
142 geometry::Point<int> heroTagPositions[4];
143 AttackChoice attackChoices[4];
150 #endif /* BATTLE_BATTLESTATE_H_ */