1 #ifndef BATTLE_BATTLESTATE_H_
2 #define BATTLE_BATTLESTATE_H_
5 #include "AttackTypeMenu.h"
11 #include "Resources.h"
12 #include "SmallHeroTag.h"
13 #include "../app/fwd.h"
14 #include "../app/State.h"
15 #include "../common/GameConfig.h"
16 #include "../common/fwd.h"
17 #include "../common/Stats.h"
18 #include "../geometry/Vector.h"
19 #include "../graphics/Animation.h"
20 #include "../graphics/fwd.h"
21 #include "../graphics/Menu.h"
33 BattleState(common::GameConfig *game, SDL_Surface *background, const PartyLayout *monstersLayout)
35 , background(background)
36 , monstersLayout(monstersLayout)
37 , heroesLayout(game->heroesLayout)
38 , res(game->battleResources)
39 , attackTypeMenu(res->attackIcons)
40 , moveMenu(res->moveIcons)
46 , ranAway(false) { assert(background && monstersLayout && game); }
49 void AddMonster(const Monster &);
50 void AddHero(const Hero &);
51 void SetCapsule(const Capsule &);
54 virtual void HandleEvents(const app::Input &);
55 virtual void UpdateWorld(float deltaT);
56 virtual void Render(SDL_Surface *);
59 const Resources &Res() const { return *res; }
60 AttackTypeMenu &GetAttackTypeMenu() { return attackTypeMenu; }
61 MoveMenu &GetMoveMenu() { return moveMenu; }
63 graphics::Menu<const common::Item *> &ItemMenu() { return itemMenu; }
64 const graphics::Menu<const common::Item *> &ItemMenu() const { return itemMenu; }
67 bool BeforeFirstHero() const { return activeHero < 0; }
69 void SwapHeroes(int lhs, int rhs);
70 Hero &ActiveHero() { assert(activeHero >= 0 && activeHero < NumHeroes()); return heroes[activeHero]; }
71 const Hero &ActiveHero() const { assert(activeHero >= 0 && activeHero < NumHeroes()); return heroes[activeHero]; }
73 Hero &HeroAt(int index) { assert(index >= 0 && index < NumHeroes()); return heroes[index]; }
74 const Hero &HeroAt(int index) const { assert(index >= 0 && index < NumHeroes()); return heroes[index]; }
75 Monster &MonsterAt(int index) { assert(index >= 0 && index < NumHeroes()); return monsters[index]; }
76 const Monster &MonsterAt(int index) const { assert(index >= 0 && index < NumHeroes()); return monsters[index]; }
78 const HeroTag &HeroTagAt(int index) const { assert(index >= 0 && index < NumHeroes()); return heroTags[index]; }
79 const geometry::Vector<int> &HeroTagPositionAt(int index) const { assert(index >= 0 && index < NumHeroes()); return heroTagPositions[index]; }
81 bool HasChosenAttackType() const { return ActiveHero().GetAttackChoice().GetType() != AttackChoice::UNDECIDED; }
82 bool AttackSelectionDone() const { return activeHero >= numHeroes; }
84 int NumHeroes() const { return numHeroes; }
85 int MaxHeroes() const { return 4; }
86 int MaxMonsters() const { return monsters.size(); }
88 bool MonsterPositionOccupied(int index) { return index >= 0 && index < int(monsters.size()) && monsters[index].Health() > 0; }
89 bool HeroPositionOccupied(int index) const { return index >= 0 && index < numHeroes; }
91 void SetRunaway() { ranAway = true; }
94 Order(int index, bool isMonster)
95 : index(index), isMonster(isMonster) { }
100 void CalculateAttackOrder();
102 bool AttacksFinished() const;
103 void CalculateDamage();
105 const Order &CurrentAttack() const { assert(attackCursor >= 0 && attackCursor < int(attackOrder.size())); return attackOrder[attackCursor]; };
106 AttackChoice &CurrentAttackAttackChoice();
107 void ClearAllAttacks();
109 bool Victory() const;
113 geometry::Vector<int> CalculateScreenOffset(SDL_Surface *screen) const {
114 return geometry::Vector<int>(
115 (screen->w - background->w) / 2,
116 (screen->h - background->h) / 2);
118 int Width() const { return background->w; }
119 int Height() const { return background->h; }
120 geometry::Vector<int> Size() const { return geometry::Vector<int>(Width(), Height()); }
122 void RenderBackground(SDL_Surface *screen, const geometry::Vector<int> &offset);
123 void RenderMonsters(SDL_Surface *screen, const geometry::Vector<int> &offset);
124 void RenderHeroes(SDL_Surface *screen, const geometry::Vector<int> &offset);
125 void RenderCapsule(SDL_Surface *screen, const geometry::Vector<int> &offset);
126 void RenderHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
127 void RenderSmallHeroTags(SDL_Surface *screen, const geometry::Vector<int> &offset);
130 virtual void OnEnterState(SDL_Surface *screen);
131 virtual void OnExitState(SDL_Surface *screen);
132 virtual void OnResumeState(SDL_Surface *screen);
133 virtual void OnPauseState(SDL_Surface *screen);
135 virtual void OnResize(int width, int height);
138 void LoadInventory();
140 void DecideMonsterAttack(Monster &) const;
141 void CalculateDamage(const common::Stats &attackerStats, TargetSelection &targets) const;
142 Uint16 CalculateDamage(const common::Stats &attacker, const common::Stats &defender) const;
145 common::GameConfig *game;
146 SDL_Surface *background;
147 const PartyLayout *monstersLayout;
148 const PartyLayout *heroesLayout;
149 const Resources *res;
150 AttackTypeMenu attackTypeMenu;
152 std::vector<Monster> monsters;
153 std::vector<Order> attackOrder;
155 graphics::Menu<const common::Item *> itemMenu;
157 SmallHeroTag smallHeroTags[4];
158 geometry::Vector<int> heroTagPositions[4];
159 geometry::Vector<int> smallHeroTagPositions[4];
172 #endif /* BATTLE_BATTLESTATE_H_ */