X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2FBattleState.h;h=806b4af59154525475ce3765532dc9600e2c3c6b;hb=3ecf065f3bcef720e82bb137a2be734ed7e16746;hp=77e2b5dbdfa214db81bcd6a8f1313b18e05ce49f;hpb=b9fdb4fd361fbc0c8e2c0df9615e6eed540917a1;p=l2e.git diff --git a/src/battle/BattleState.h b/src/battle/BattleState.h index 77e2b5d..806b4af 100644 --- a/src/battle/BattleState.h +++ b/src/battle/BattleState.h @@ -8,7 +8,6 @@ #ifndef BATTLE_BATTLESTATE_H_ #define BATTLE_BATTLESTATE_H_ -#include "AttackChoice.h" #include "AttackTypeMenu.h" #include "Hero.h" #include "HeroTag.h" @@ -17,11 +16,11 @@ #include "Resources.h" #include "SmallHeroTag.h" #include "../app/State.h" -#include "../geometry/Point.h" #include "../geometry/Vector.h" +#include "../graphics/Animation.h" #include "../graphics/Menu.h" -#include "../graphics/SimpleAnimation.h" +#include #include #include @@ -40,7 +39,9 @@ namespace graphics { namespace battle { +class AttackChoice; class PartyLayout; +class Stats; class BattleState : public app::State { @@ -55,7 +56,10 @@ public: , moveMenu(res->moveIcons) , numHeroes(0) , activeHero(-1) - , ranAway(false) { } + , attackCursor(-1) + , expReward(0) + , goldReward(0) + , ranAway(false) { assert(background && res); } public: void AddMonster(const Monster &); @@ -78,57 +82,64 @@ public: AttackTypeMenu &GetAttackTypeMenu() { return attackTypeMenu; } MoveMenu &GetMoveMenu() { return moveMenu; } - 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; } + graphics::Menu &ItemMenu() { return itemMenu; } + const graphics::Menu &ItemMenu() const { return itemMenu; } void NextHero(); bool BeforeFirstHero() const { return activeHero < 0; } - void PreviousHero() { --activeHero; } + void PreviousHero(); void SwapHeroes(int lhs, int rhs); - Hero &ActiveHero() { return heroes[activeHero]; } - const Hero &ActiveHero() const { return heroes[activeHero]; } + Hero &ActiveHero() { assert(activeHero >= 0 && activeHero < NumHeroes()); return heroes[activeHero]; } + const Hero &ActiveHero() const { assert(activeHero >= 0 && activeHero < NumHeroes()); return heroes[activeHero]; } - Hero &HeroAt(int index) { return heroes[index]; } - const Hero &HeroAt(int index) const { return heroes[index]; } - Monster &MonsterAt(int index) { return monsters[index]; } - const Monster &MonsterAt(int index) const { return monsters[index]; } + Hero &HeroAt(int index) { assert(index >= 0 && index < NumHeroes()); return heroes[index]; } + const Hero &HeroAt(int index) const { assert(index >= 0 && index < NumHeroes()); return heroes[index]; } + Monster &MonsterAt(int index) { assert(index >= 0 && index < NumHeroes()); return monsters[index]; } + const Monster &MonsterAt(int index) const { assert(index >= 0 && index < NumHeroes()); return monsters[index]; } - graphics::SimpleAnimation &HeroAnimationAt(int index) { return heroAnimations[index]; } - const graphics::SimpleAnimation &HeroAnimationAt(int index) const { return heroAnimations[index]; } + const HeroTag &HeroTagAt(int index) const { assert(index >= 0 && index < NumHeroes()); return heroTags[index]; } + const geometry::Vector &HeroTagPositionAt(int index) const { assert(index >= 0 && index < NumHeroes()); return heroTagPositions[index]; } - const HeroTag &HeroTagAt(int index) const { return heroTags[index]; } - const geometry::Point &HeroTagPositionAt(int index) const { return heroTagPositions[index]; } - - bool HasChosenAttackType() const { return attackChoices[activeHero].GetType() != AttackChoice::UNDECIDED; } - AttackChoice &ActiveHeroAttackChoice() { return attackChoices[activeHero]; } - const AttackChoice &ActiveHeroAttackChoice() const { return attackChoices[activeHero]; } - const AttackChoice &AttackChoiceAt(int index) const { return attackChoices[index]; } + bool HasChosenAttackType() const { return ActiveHero().GetAttackChoice().GetType() != AttackChoice::UNDECIDED; } bool AttackSelectionDone() const { return activeHero >= numHeroes; } int NumHeroes() const { return numHeroes; } int MaxHeroes() const { return 4; } int MaxMonsters() const { return monsters.size(); } - 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) const { return index >= 0 && index < numHeroes; } void SetRunaway() { ranAway = true; } + + struct Order { + Order(int index, bool isMonster) + : index(index), isMonster(isMonster) { } + int index; + bool isMonster; + }; + + void CalculateAttackOrder(); + void NextAttack(); + bool AttacksFinished() const; + void CalculateDamage(); + void ApplyDamage(); + const Order &CurrentAttack() const { assert(attackCursor >= 0 && attackCursor < int(attackOrder.size())); return attackOrder[attackCursor]; }; + AttackChoice &CurrentAttackAttackChoice(); void ClearAllAttacks(); + bool Victory() const; + bool Defeat() const; + 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; } + int Width() const { return background->w; } + int Height() const { return background->h; } + geometry::Vector Size() const { return geometry::Vector(Width(), Height()); } void RenderBackground(SDL_Surface *screen, const geometry::Vector &offset); void RenderMonsters(SDL_Surface *screen, const geometry::Vector &offset); @@ -137,10 +148,12 @@ public: void RenderSmallHeroTags(SDL_Surface *screen, const geometry::Vector &offset); private: - void LoadSpellMenu(std::vector::size_type heroIndex); - void LoadIkariMenu(std::vector::size_type heroIndex); void LoadInventory(); + void DecideMonsterAttack(Monster &) const; + void CalculateDamage(const Stats &attackerStats, TargetSelection &targets) const; + Uint16 CalculateDamage(const Stats &attacker, const Stats &defender) const; + private: SDL_Surface *background; const PartyLayout *monstersLayout; @@ -148,22 +161,19 @@ private: 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 attackOrder; Hero heroes[4]; - graphics::SimpleAnimation heroAnimations[4]; - graphics::Menu spellMenus[4]; graphics::Menu itemMenu; - graphics::Menu ikariMenus[4]; HeroTag heroTags[4]; SmallHeroTag smallHeroTags[4]; - geometry::Point heroTagPositions[4]; - geometry::Point smallHeroTagPositions[4]; - AttackChoice attackChoices[4]; + geometry::Vector heroTagPositions[4]; + geometry::Vector smallHeroTagPositions[4]; int numHeroes; int activeHero; + int attackCursor; + int expReward; + int goldReward; bool ranAway; };