]> git.localhorst.tv Git - l2e.git/blobdiff - src/battle/states/SwapHeroes.cpp
extracted battle logic into a class
[l2e.git] / src / battle / states / SwapHeroes.cpp
index af867477bc3d44477ebf933dddbc67656e3bc94e..799cff8d07213cd56d8d4dee59f1e9cb59240feb 100644 (file)
@@ -13,6 +13,16 @@ using std::vector;
 
 namespace battle {
 
+SwapHeroes::SwapHeroes(Battle *battle, SelectMoveAction *parent)
+: battle(battle)
+, parent(parent)
+, cursor(0)
+, selected(-1)
+, flipFlop(true) {
+
+}
+
+
 void SwapHeroes::OnEnterState(SDL_Surface *screen) {
        OnResize(screen->w, screen->h);
 }
@@ -31,21 +41,21 @@ void SwapHeroes::OnPauseState(SDL_Surface *screen) {
 
 
 void SwapHeroes::OnResize(int width, int height) {
-       Vector<int> offset(battle->ScreenOffset());
+       Vector<int> offset(parent->ScreenOffset());
        // offset the cursor by 1/8th to the left and bottom
-       cursorOffset = Vector<int>(battle->Res().swapCursor->Width() / -8, battle->Res().swapCursor->Height() / 8);
+       cursorOffset = Vector<int>(parent->Res().swapCursor->Width() / -8, parent->Res().swapCursor->Height() / 8);
        indicatorOffset = Vector<int>(0, 0);
 
        positions.clear();
        positions.reserve(battle->NumHeroes());
        for (int i(0), end(battle->NumHeroes()); i < end; ++i) {
                Vector<int> positionCorrection(
-                               battle->Res().swapCursor->Width() / 2,
-                               battle->HeroTagAt(i).HeroSprite()->Height() - battle->Res().swapCursor->Height() / 2);
+                               parent->Res().swapCursor->Width() / 2,
+                               parent->HeroTagAt(i).HeroSprite()->Height() - parent->Res().swapCursor->Height() / 2);
                // indicator offsets are inverted for heroes
                positionCorrection -= cursorOffset;
-               positions.push_back(battle->HeroTagPositionAt(i)
-                               + battle->HeroTagAt(i).HeroOffset()
+               positions.push_back(parent->HeroTagPositionAt(i)
+                               + parent->HeroTagAt(i).HeroOffset()
                                + positionCorrection
                                + offset);
        }
@@ -135,12 +145,12 @@ void SwapHeroes::RenderCursors(SDL_Surface *screen) {
                for (vector<Vector<int> >::size_type i(0), end(positions.size());
                                i != end; ++i) {
                        if (selected == int(i)) {
-                               battle->Res().swapCursor->DrawTopRight(screen, positions[i]);
+                               parent->Res().swapCursor->DrawTopRight(screen, positions[i]);
                        }
                }
        }
        flipFlop = !flipFlop;
-       battle->Res().swapCursor->DrawTopRight(screen, positions[cursor] + cursorOffset);
+       parent->Res().swapCursor->DrawTopRight(screen, positions[cursor] + cursorOffset);
 }
 
 }