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; }
42 BattleState(SDL_Surface *background, const PartyLayout &monstersLayout, const PartyLayout &heroesLayout, const Resources *res)
43 : background(background)
44 , monstersLayout(&monstersLayout)
45 , heroesLayout(&heroesLayout)
47 , attackTypeMenu(res->attackIcons)
48 , moveMenu(res->moveIcons)
52 void AddMonster(const Monster &);
53 void AddHero(const Hero &);
56 virtual void EnterState(app::Application &ctrl, SDL_Surface *screen);
57 virtual void ExitState(app::Application &ctrl, SDL_Surface *screen);
58 virtual void ResumeState(app::Application &ctrl, SDL_Surface *screen);
59 virtual void PauseState(app::Application &ctrl, SDL_Surface *screen);
61 virtual void Resize(int width, int height);
63 virtual void HandleInput(const app::Input &);
64 virtual void UpdateWorld(float deltaT);
65 virtual void Render(SDL_Surface *);
68 const Resources &Res() const { return *res; }
69 AttackTypeMenu &GetAttackTypeMenu() { return attackTypeMenu; }
70 MoveMenu &GetMoveMenu() { return moveMenu; }
72 bool HasMoreHeroes() const { return activeHero < (int) heroes.size(); }
73 void NextHero() { ++activeHero; }
74 bool BeforeFirstHero() const { return activeHero < 0; }
75 void PreviousHero() { --activeHero; }
76 Hero &ActiveHero() { return heroes[activeHero]; }
77 const Hero &ActiveHero() const { return heroes[activeHero]; }
78 bool HasChosenAttackType() const { return attackChoices[activeHero].GetType() != AttackChoice::UNDECIDED; }
79 void SetAttackType(AttackChoice::Type t) { attackChoices[activeHero].SetType(t); }
80 bool AttackSelectionDone() const { return activeHero >= (int) heroes.size(); }
81 graphics::Menu</* Spell */ void *> &GetSpellMenu() { return spellMenus[activeHero]; }
82 const graphics::Menu</* Spell */ void *> &GetSpellMenu() const { return spellMenus[activeHero]; }
83 graphics::Menu</* Item */ void *> &GetItemMenu() { return itemMenu; }
84 const graphics::Menu</* Item */ void *> &GetItemMenu() const { return itemMenu; }
87 geometry::Vector<int> CalculateScreenOffset(SDL_Surface *screen) const {
88 return geometry::Vector<int>(
89 (screen->w - background->w) / 2,
90 (screen->h - background->h) / 2);
92 int BackgroundWidth() const { return background->w; }
93 int BackgroundHeight() const { return background->h; }
95 void RenderBackground(SDL_Surface *screen, const geometry::Vector<int> &offset);
96 void RenderMonsters(SDL_Surface *screen, const geometry::Vector<int> &offset);
97 void RenderHeroes(SDL_Surface *screen, const geometry::Vector<int> &offset);
98 void RenderHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
101 SDL_Surface *background;
102 const PartyLayout *monstersLayout;
103 const PartyLayout *heroesLayout;
104 const Resources *res;
105 AttackTypeMenu attackTypeMenu;
107 std::vector<geometry::Point<int> > monsterPositions;
108 std::vector<geometry::Point<int> > heroesPositions;
109 std::vector<Monster> monsters;
110 std::vector<Hero> heroes;
111 std::vector<graphics::Menu</* Spell */ void *> > spellMenus;
112 graphics::Menu</* Item */ void *> itemMenu;
113 std::vector<HeroTag> heroTags;
114 std::vector<AttackChoice> attackChoices;
121 #endif /* BATTLE_BATTLESTATE_H_ */