X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2FBattleState.h;h=347afc3f744e7bc3bfb2cec893c16f9aee48288e;hb=222167ba3722dc7f47ff7510006bd516e0010a50;hp=397e5e3b02a59314bd97dc7518c2746d25ab54b7;hpb=867fd5d9b79c3b9c1d0fb17ba9f55cfe971b93d5;p=l2e.git diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index 397e5e3..347afc3 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -8,16 +8,33 @@ #ifndef BATTLE_BATTLESTATE_H_ #define BATTLE_BATTLESTATE_H_ +#include "AttackChoice.h" +#include "AttackTypeMenu.h" #include "Hero.h" +#include "HeroTag.h" #include "Monster.h" +#include "MoveMenu.h" +#include "Resources.h" #include "../app/State.h" #include "../geometry/Point.h" #include "../geometry/Vector.h" +#include "../graphics/Menu.h" #include #include namespace app { class Input; } +namespace common { + class Inventory; + class Item; + class Spell; +} +namespace graphics { + class Font; + class Frame; + class Gauge; + class Sprite; +} namespace battle { @@ -27,10 +44,15 @@ class BattleState : public app::State { public: - BattleState(SDL_Surface *background, const PartyLayout &monstersLayout, const PartyLayout &heroesLayout) + BattleState(SDL_Surface *background, const PartyLayout &monstersLayout, const PartyLayout &heroesLayout, const Resources *res) : background(background) , monstersLayout(&monstersLayout) - , heroesLayout(&heroesLayout) { } + , heroesLayout(&heroesLayout) + , res(res) + , attackTypeMenu(res->attackIcons) + , moveMenu(res->moveIcons) + , activeHero(-1) + , ranAway(false) { } public: void AddMonster(const Monster &); @@ -38,27 +60,102 @@ public: public: virtual void EnterState(app::Application &ctrl, SDL_Surface *screen); - virtual void ExitState(); + virtual void ExitState(app::Application &ctrl, SDL_Surface *screen); + virtual void ResumeState(app::Application &ctrl, SDL_Surface *screen); + virtual void PauseState(app::Application &ctrl, SDL_Surface *screen); virtual void Resize(int width, int height); - virtual void HandleInput(const app::Input &); + virtual void HandleEvents(const app::Input &); virtual void UpdateWorld(float deltaT); virtual void Render(SDL_Surface *); -private: +public: + const Resources &Res() const { return *res; } + AttackTypeMenu &GetAttackTypeMenu() { return attackTypeMenu; } + MoveMenu &GetMoveMenu() { return moveMenu; } + + bool HasMoreHeroes() const { return activeHero < (int) heroes.size(); } + void NextHero() { ++activeHero; } + bool BeforeFirstHero() const { return activeHero < 0; } + void PreviousHero() { --activeHero; } + Hero &ActiveHero() { return heroes[activeHero]; } + const Hero &ActiveHero() const { return heroes[activeHero]; } + Hero &HeroAt(std::vector::size_type index) { return heroes[index]; } + const Hero &HeroAt(std::vector::size_type index) const { return heroes[index]; } + Monster &MonsterAt(std::vector::size_type index) { return monsters[index]; } + const Monster &MonsterAt(std::vector::size_type index) const { return monsters[index]; } + void SwapHeroes(std::vector::size_type lhs, std::vector::size_type rhs); + const HeroTag &ActiveHeroTag() const { return heroTags[activeHero]; } + const HeroTag &HeroTagAt(std::vector::size_type index) const { return heroTags[index]; } + const geometry::Point &HeroTagPositionAt(std::vector::size_type index) const { return heroTagPositions[index]; } + bool HasChosenAttackType() const { return attackChoices[activeHero].GetType() != AttackChoice::UNDECIDED; } + void SetAttackType(AttackChoice::Type t) { attackChoices[activeHero].SetType(t); } + AttackChoice &ActiveHeroAttackChoice() { return attackChoices[activeHero]; } + const AttackChoice &ActiveHeroAttackChoice() const { return attackChoices[activeHero]; } + const AttackChoice &AttackChoiceAt(std::vector::size_type index) const { return attackChoices[index]; } + TargetSelection &ActiveHeroTargets() { return attackChoices[activeHero].Selection(); } + const TargetSelection &ActiveHeroTargets() const { return attackChoices[activeHero].Selection(); } + bool AttackSelectionDone() const { return activeHero >= (int) heroes.size(); } + + graphics::Menu &GetSpellMenu() { return spellMenus[activeHero]; } + const graphics::Menu &GetSpellMenu() const { return spellMenus[activeHero]; } + graphics::Menu &GetIkariMenu() { return ikariMenus[activeHero]; } + const graphics::Menu &GetIkariMenu() const { return ikariMenus[activeHero]; } + graphics::Menu &GetItemMenu() { return itemMenu; } + const graphics::Menu &GetItemMenu() const { return itemMenu; } + + const std::vector > &MonsterPositions() const { return monsterPositions; } + bool MonsterPositionOccupied(int index) { return index >= 0 && index < int(monsters.size()) && monsters[index].Health() > 0; } + const std::vector > &HeroesPositions() const { return heroesPositions; } + bool HeroPositionOccupied(int index) { return index >= 0 && index < int(heroes.size()); } + std::vector &Heroes() { return heroes; } + const std::vector &Heroes() const { return heroes; } + std::vector &Monsters() { return monsters; } + const std::vector &Monsters() const { return monsters; } + + void SetRunaway() { ranAway = true; } + void ClearAllAttacks(); + +public: + geometry::Vector CalculateScreenOffset(SDL_Surface *screen) const { + return geometry::Vector( + (screen->w - background->w) / 2, + (screen->h - background->h) / 2); + } + int BackgroundWidth() const { return background->w; } + int BackgroundHeight() const { return background->h; } + void RenderBackground(SDL_Surface *screen, const geometry::Vector &offset); void RenderMonsters(SDL_Surface *screen, const geometry::Vector &offset); void RenderHeroes(SDL_Surface *screen, const geometry::Vector &offset); + void RenderHeroTags(SDL_Surface *screen, const geometry::Vector &offset); + +private: + void LoadSpellMenu(std::vector::size_type heroIndex); + void LoadIkariMenu(std::vector::size_type heroIndex); + void LoadInventory(); private: SDL_Surface *background; const PartyLayout *monstersLayout; const PartyLayout *heroesLayout; + const Resources *res; + AttackTypeMenu attackTypeMenu; + MoveMenu moveMenu; + // TODO: combine all data about heros or monsters std::vector > monsterPositions; std::vector > heroesPositions; std::vector monsters; std::vector heroes; + std::vector > spellMenus; + graphics::Menu itemMenu; + std::vector > ikariMenus; + HeroTag heroTags[4]; + geometry::Point heroTagPositions[4]; + AttackChoice attackChoices[4]; + int activeHero; + bool ranAway; };