X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fbattle%2FBattleState.cpp;h=0f3fad94838f56e88a16bda2b6efbce8a788b624;hb=adb1e3d5eafba2ef3de1499be286be330afaefef;hp=3f734f84d8ce5bc868f15ad8ea041f2439fce99b;hpb=4170813213bafe6f4a01a79bf42308ddb7f3c545;p=l2e.git diff --git a/src/battle/BattleState.cpp b/src/battle/BattleState.cpp index 3f734f8..0f3fad9 100644 --- a/src/battle/BattleState.cpp +++ b/src/battle/BattleState.cpp @@ -9,6 +9,7 @@ #include "PartyLayout.h" #include "states/SelectMoveAction.h" +#include "states/PerformAttacks.h" #include "../app/Application.h" #include "../app/Input.h" #include "../common/Ikari.h" @@ -18,6 +19,7 @@ #include "../geometry/operators.h" #include "../graphics/Sprite.h" +#include #include using app::Application; @@ -41,10 +43,16 @@ void BattleState::AddMonster(const Monster &m) { } void BattleState::AddHero(const Hero &h) { - if (heroes.size() >= heroesLayout->NumPositions()) { + if (numHeroes >= 4 || numHeroes >= (int)heroesLayout->NumPositions()) { throw std::overflow_error("too many heroes for layout"); } - heroes.push_back(h); + heroes[numHeroes] = h; + ++numHeroes; +} + +void BattleState::SwapHeroes(int lhs, int rhs) { + if (lhs < 0 || lhs >= numHeroes || rhs < 0 || rhs >= numHeroes || lhs == rhs) return; + std::swap(heroes[lhs], heroes[rhs]); } @@ -56,12 +64,12 @@ void BattleState::Resize(int w, int h) { void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) { monstersLayout->CalculatePositions(background->w, background->h, monsterPositions); heroesLayout->CalculatePositions(background->w, background->h, heroesPositions); - for (vector::size_type i(0), end(heroes.size()); i < end; ++i) { - spellMenus.push_back(res->spellMenuPrototype); + for (int i(0); i < 4; ++i) { + spellMenus[i] = res->spellMenuPrototype; LoadSpellMenu(i); - ikariMenus.push_back(res->ikariMenuPrototype); + ikariMenus[i] = res->ikariMenuPrototype; LoadIkariMenu(i); - heroTags[i] = HeroTag(&heroes[i], attackChoices + i, res, HeroTag::Alignment((i + 1) % 2)); + heroTags[i] = HeroTag(this, i); } int tagHeight(attackTypeMenu.Height()); @@ -174,6 +182,7 @@ void BattleState::LoadInventory() { itemMenu.AddEmptyEntry(); } } + ClearAllAttacks(); } void BattleState::ExitState(Application &ctrl, SDL_Surface *screen) { @@ -181,13 +190,16 @@ void BattleState::ExitState(Application &ctrl, SDL_Surface *screen) { } void BattleState::ResumeState(Application &ctrl, SDL_Surface *screen) { - // TODO: check for victory, defeat or run - // reset attack choices - activeHero = -1; - for (vector::size_type i(0), end(heroes.size()); i < end; ++i) { - attackChoices[i] = AttackChoice(this); + // TODO: check for victory or defeat + if (ranAway) { + ctrl.PopState(); // quit the battle scene + return; + } + if (AttackSelectionDone()) { + ctrl.PushState(new PerformAttacks(this)); + } else { + ctrl.PushState(new SelectMoveAction(this)); } - ctrl.PushState(new SelectMoveAction(this)); } void BattleState::PauseState(Application &ctrl, SDL_Surface *screen) { @@ -195,7 +207,15 @@ void BattleState::PauseState(Application &ctrl, SDL_Surface *screen) { } -void BattleState::HandleInput(const Input &input) { +void BattleState::ClearAllAttacks() { + activeHero = -1; + for (int i(0); i < numHeroes; ++i) { + attackChoices[i] = AttackChoice(this); + } +} + + +void BattleState::HandleEvents(const Input &input) { } @@ -230,8 +250,8 @@ void BattleState::RenderMonsters(SDL_Surface *screen, const Vector &offset) } void BattleState::RenderHeroes(SDL_Surface *screen, const Vector &offset) { - for (vector::size_type i(0), end(heroes.size()); i < end; ++i) { - heroes[i].Sprite()->DrawCenterBottom(screen, heroesPositions[i] + offset); + for (int i(0); i < numHeroes; ++i) { + heroes[i].Sprite()->DrawCenterBottom(screen, heroesPositions[i] + offset, 0, 1); } } @@ -239,7 +259,7 @@ void BattleState::RenderHeroTags(SDL_Surface *screen, const Vector &offset) int tagHeight(attackTypeMenu.Height()); int tagWidth(attackTypeMenu.Width() * 2 + attackTypeMenu.Width() / 2); - for (vector::size_type i(0), end(heroes.size()); i < end; ++i) { + for (int i(0); i < numHeroes; ++i) { heroTags[i].Render(screen, tagWidth, tagHeight, heroTagPositions[i] + offset, (int)i == activeHero); } }