]> git.localhorst.tv Git - l2e.git/commitdiff
added dummy state that echoes all selected attacks
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 10 Aug 2012 23:11:46 +0000 (01:11 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 10 Aug 2012 23:11:46 +0000 (01:11 +0200)
12 files changed:
Debug/src/battle/states/subdir.mk
Release/src/battle/states/subdir.mk
src/battle/BattleState.cpp
src/battle/BattleState.h
src/battle/Monster.h
src/battle/states/PerformAttacks.cpp [new file with mode: 0644]
src/battle/states/PerformAttacks.h [new file with mode: 0644]
src/battle/states/SelectIkari.cpp
src/battle/states/SelectItem.cpp
src/battle/states/SelectSpell.cpp
src/main.cpp
test-data/large-font.png

index 3d78d840d224ea5229cc69b568b1648f7d7d8953..9b3a19672d3f46ad3ea6567e4335bb4fbea89474 100644 (file)
@@ -4,6 +4,7 @@
 
 # Add inputs and outputs from these tool invocations to the build variables 
 CPP_SRCS += \
+../src/battle/states/PerformAttacks.cpp \
 ../src/battle/states/RunState.cpp \
 ../src/battle/states/SelectAttackType.cpp \
 ../src/battle/states/SelectIkari.cpp \
@@ -14,6 +15,7 @@ CPP_SRCS += \
 ../src/battle/states/SwapHeroes.cpp 
 
 OBJS += \
+./src/battle/states/PerformAttacks.o \
 ./src/battle/states/RunState.o \
 ./src/battle/states/SelectAttackType.o \
 ./src/battle/states/SelectIkari.o \
@@ -24,6 +26,7 @@ OBJS += \
 ./src/battle/states/SwapHeroes.o 
 
 CPP_DEPS += \
+./src/battle/states/PerformAttacks.d \
 ./src/battle/states/RunState.d \
 ./src/battle/states/SelectAttackType.d \
 ./src/battle/states/SelectIkari.d \
index 0461161f816a4600c47a172b0d9ef3377f5b5e9f..0a764ce8246d577a92ce317be65de81e38c0977c 100644 (file)
@@ -4,6 +4,7 @@
 
 # Add inputs and outputs from these tool invocations to the build variables 
 CPP_SRCS += \
+../src/battle/states/PerformAttacks.cpp \
 ../src/battle/states/RunState.cpp \
 ../src/battle/states/SelectAttackType.cpp \
 ../src/battle/states/SelectIkari.cpp \
@@ -14,6 +15,7 @@ CPP_SRCS += \
 ../src/battle/states/SwapHeroes.cpp 
 
 OBJS += \
+./src/battle/states/PerformAttacks.o \
 ./src/battle/states/RunState.o \
 ./src/battle/states/SelectAttackType.o \
 ./src/battle/states/SelectIkari.o \
@@ -24,6 +26,7 @@ OBJS += \
 ./src/battle/states/SwapHeroes.o 
 
 CPP_DEPS += \
+./src/battle/states/PerformAttacks.d \
 ./src/battle/states/RunState.d \
 ./src/battle/states/SelectAttackType.d \
 ./src/battle/states/SelectIkari.d \
index c294e1a28feda13da5b9f81be3b9e15aa4aecdc3..b5c91f8ca6b03587bf9605111ed0e6814097e1c9 100644 (file)
@@ -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"
@@ -180,6 +181,7 @@ void BattleState::LoadInventory() {
                        itemMenu.AddEmptyEntry();
                }
        }
+       ClearAllAttacks();
 }
 
 void BattleState::ExitState(Application &ctrl, SDL_Surface *screen) {
@@ -192,12 +194,11 @@ void BattleState::ResumeState(Application &ctrl, SDL_Surface *screen) {
                ctrl.PopState(); // quit the battle scene
                return;
        }
-       // reset attack choices
-       activeHero = -1;
-       for (vector<Hero>::size_type i(0), end(heroes.size()); i < end; ++i) {
-               attackChoices[i] = AttackChoice(this);
+       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) {
@@ -205,6 +206,14 @@ void BattleState::PauseState(Application &ctrl, SDL_Surface *screen) {
 }
 
 
+void BattleState::ClearAllAttacks() {
+       activeHero = -1;
+       for (vector<Hero>::size_type i(0), end(heroes.size()); i < end; ++i) {
+               attackChoices[i] = AttackChoice(this);
+       }
+}
+
+
 void BattleState::HandleEvents(const Input &input) {
 
 }
index e94ed417b689807e580bf20a6925d0371327ef59..347afc3f744e7bc3bfb2cec893c16f9aee48288e 100644 (file)
@@ -83,6 +83,8 @@ public:
        const Hero &ActiveHero() const { return heroes[activeHero]; }
        Hero &HeroAt(std::vector<Hero>::size_type index) { return heroes[index]; }
        const Hero &HeroAt(std::vector<Hero>::size_type index) const { return heroes[index]; }
+       Monster &MonsterAt(std::vector<Monster>::size_type index) { return monsters[index]; }
+       const Monster &MonsterAt(std::vector<Monster>::size_type index) const { return monsters[index]; }
        void SwapHeroes(std::vector<Hero>::size_type lhs, std::vector<Hero>::size_type rhs);
        const HeroTag &ActiveHeroTag() const { return heroTags[activeHero]; }
        const HeroTag &HeroTagAt(std::vector<Hero>::size_type index) const { return heroTags[index]; }
@@ -109,8 +111,11 @@ public:
        bool HeroPositionOccupied(int index) { return index >= 0 && index < int(heroes.size()); }
        std::vector<Hero> &Heroes() { return heroes; }
        const std::vector<Hero> &Heroes() const { return heroes; }
+       std::vector<Monster> &Monsters() { return monsters; }
+       const std::vector<Monster> &Monsters() const { return monsters; }
 
        void SetRunaway() { ranAway = true; }
+       void ClearAllAttacks();
 
 public:
        geometry::Vector<int> CalculateScreenOffset(SDL_Surface *screen) const {
index d3a7162111939c1f887cf4c63fa548f4575b0beb..f37786a076f3f8618449a7148a2faf8539716ff8 100644 (file)
@@ -51,6 +51,7 @@ public:
 
 // temporary setters until loader is implemented
 public:
+       void SetName(const char *n) { name = n; }
        void SetSprite(graphics::Sprite *s) { sprite = s; }
        void SetMaxHealth(Uint16 m) { maxHealth = m; }
        void SetHealth(Uint16 h) { health = h; }
diff --git a/src/battle/states/PerformAttacks.cpp b/src/battle/states/PerformAttacks.cpp
new file mode 100644 (file)
index 0000000..35253ce
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ * PerformAttacks.cpp
+ *
+ *  Created on: Aug 10, 2012
+ *      Author: holy
+ */
+
+#include "PerformAttacks.h"
+
+#include "../BattleState.h"
+#include "../Hero.h"
+#include "../Monster.h"
+#include "../../app/Application.h"
+#include "../../app/Input.h"
+#include "../../common/Ikari.h"
+#include "../../common/Item.h"
+#include "../../common/Spell.h"
+#include "../../geometry/operators.h"
+#include "../../geometry/Point.h"
+#include "../../graphics/Font.h"
+#include "../../graphics/Frame.h"
+
+#include <cstring>
+
+using app::Application;
+using app::Input;
+using geometry::Point;
+using geometry::Vector;
+
+namespace battle {
+
+void PerformAttacks::EnterState(Application &c, SDL_Surface *screen) {
+       ctrl = &c;
+       // TODO: push battle animation if enemy is faster
+}
+
+void PerformAttacks::ExitState(Application &c, SDL_Surface *screen) {
+       ctrl = 0;
+}
+
+void PerformAttacks::ResumeState(Application &ctrl, SDL_Surface *screen) {
+       fakeMoveTimer = GraphicsTimers().StartCountdown(850);
+}
+
+void PerformAttacks::PauseState(Application &ctrl, SDL_Surface *screen) {
+
+}
+
+
+void PerformAttacks::Resize(int width, int height) {
+
+}
+
+
+void PerformAttacks::HandleEvents(const Input &input) {
+       if (fakeMoveTimer.JustHit()) {
+               if (monsters) {
+                       if (titleBarText) {
+                               titleBarText = 0;
+                               ++cursor;
+                               while (cursor < (int)battle->Monsters().size() && !battle->MonsterPositionOccupied(cursor)) {
+                                       ++cursor;
+                               }
+                               if (cursor >= (int)battle->Monsters().size()) {
+                                       battle->ClearAllAttacks();
+                                       ctrl->PopState();
+                               }
+                       } else {
+                               titleBarText = battle->MonsterAt(cursor).Name();
+                       }
+               } else {
+                       if (titleBarText) {
+                               titleBarText = 0;
+                               ++cursor;
+                               if (cursor == (int)battle->Heroes().size()) {
+                                       cursor = 0;
+                                       monsters = true;
+                               }
+                       } else {
+                               const AttackChoice &ac(battle->AttackChoiceAt(cursor));
+                               switch (ac.GetType()) {
+                                       case AttackChoice::SWORD:
+                                               titleBarText = battle->HeroAt(cursor).HasWeapon() ? battle->HeroAt(cursor).Weapon()->Name() : "Gauntlet";
+                                               break;
+                                       case AttackChoice::MAGIC:
+                                               titleBarText = ac.GetSpell()->Name();
+                                               break;
+                                       case AttackChoice::DEFEND:
+                                               titleBarText = "Defends.";
+                                               break;
+                                       case AttackChoice::IKARI:
+                                               titleBarText = ac.GetItem()->HasIkari() ? ac.GetItem()->GetIkari()->Name() : "No Ikari?";
+                                               break;
+                                       case AttackChoice::ITEM:
+                                               titleBarText = ac.GetItem()->Name();
+                                               break;
+                                       case AttackChoice::UNDECIDED:
+                                               titleBarText = "WTF???";
+                                               break;
+                               }
+                       }
+               }
+       }
+}
+
+
+void PerformAttacks::UpdateWorld(float deltaT) {
+
+}
+
+void PerformAttacks::Render(SDL_Surface *screen) {
+       Vector<int> offset(battle->CalculateScreenOffset(screen));
+       battle->RenderBackground(screen, offset);
+       battle->RenderMonsters(screen, offset);
+       battle->RenderHeroes(screen, offset);
+       // render small tags
+       RenderTitleBar(screen, offset);
+}
+
+void PerformAttacks::RenderTitleBar(SDL_Surface *screen, const Vector<int> &offset) {
+       if (!titleBarText) return;
+
+       int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight());
+       battle->Res().titleFrame->Draw(screen, Point<int>(offset.X(), offset.Y()), battle->BackgroundWidth(), height);
+
+       Point<int> textPosition(
+                       (battle->BackgroundWidth() - (std::strlen(titleBarText) * battle->Res().titleFont->CharWidth())) / 2,
+                       battle->Res().titleFrame->BorderHeight());
+       battle->Res().titleFont->DrawString(titleBarText, screen, textPosition + offset);
+}
+
+}
diff --git a/src/battle/states/PerformAttacks.h b/src/battle/states/PerformAttacks.h
new file mode 100644 (file)
index 0000000..f6157e1
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * PerformAttacks.h
+ *
+ *  Created on: Aug 10, 2012
+ *      Author: holy
+ */
+
+#ifndef BATTLE_PERFORMATTACKS_H_
+#define BATTLE_PERFORMATTACKS_H_
+
+#include "../../app/State.h"
+
+#include "../../geometry/Vector.h"
+
+namespace battle {
+
+class BattleState;
+
+class PerformAttacks
+: public app::State {
+
+public:
+       explicit PerformAttacks(BattleState *battle)
+       : ctrl(0), battle(battle), titleBarText(0), cursor(0), monsters(false) { }
+
+public:
+       virtual void EnterState(app::Application &ctrl, SDL_Surface *screen);
+       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 HandleEvents(const app::Input &);
+       virtual void UpdateWorld(float deltaT);
+       virtual void Render(SDL_Surface *);
+
+private:
+       void RenderTitleBar(SDL_Surface *screen, const geometry::Vector<int> &offset);
+
+private:
+       app::Application *ctrl;
+       BattleState *battle;
+       const char *titleBarText;
+       app::Timer<Uint32> fakeMoveTimer;
+       int cursor;
+       bool monsters;
+
+};
+
+}
+
+#endif /* BATTLE_PERFORMATTACKS_H_ */
index adeafb29fd7ca5ebfefe6825024e3867eb1aea5f..605ba2caef9ea52670ee5e898b4bea3bb29dab4a 100644 (file)
@@ -37,6 +37,8 @@ void SelectIkari::ExitState(Application &c, SDL_Surface *screen) {
 
 void SelectIkari::ResumeState(Application &ctrl, SDL_Surface *screen) {
        if (battle->ActiveHeroTargets().HasSelected()) {
+               battle->SetAttackType(AttackChoice::IKARI);
+               battle->ActiveHeroAttackChoice().SetItem(battle->GetIkariMenu().Selected());
                ctrl.PopState();
        }
 }
index 4701fb94c2a3efbdce8232b698694eb966b419f5..a8c23bb763a9acaf9682dfd841044ae33d3bf8f6 100644 (file)
@@ -36,6 +36,8 @@ void SelectItem::ExitState(Application &c, SDL_Surface *screen) {
 
 void SelectItem::ResumeState(Application &ctrl, SDL_Surface *screen) {
        if (battle->ActiveHeroTargets().HasSelected()) {
+               battle->SetAttackType(AttackChoice::ITEM);
+               battle->ActiveHeroAttackChoice().SetItem(battle->GetItemMenu().Selected());
                ctrl.PopState();
        }
 }
index 56f750fd6d17d3f0f326fe0ffeb43e99f1739a6d..a9c06cceccc912ca59e3530ce361e52b7fbb2880 100644 (file)
@@ -37,6 +37,8 @@ void SelectSpell::ExitState(Application &c, SDL_Surface *screen) {
 
 void SelectSpell::ResumeState(Application &ctrl, SDL_Surface *screen) {
        if (battle->ActiveHeroTargets().HasSelected()) {
+               battle->SetAttackType(AttackChoice::MAGIC);
+               battle->ActiveHeroAttackChoice().SetSpell(battle->GetSpellMenu().Selected());
                ctrl.PopState();
        }
 }
index e39d31830976b38b40e396da5f38a28dc114770a..cb4ad91317aa4d311a6dba3fe133e7b62ee36ec1 100644 (file)
@@ -81,6 +81,7 @@ int main(int argc, char **argv) {
                SDL_Surface *monsterImg(IMG_Load("test-data/monster.png"));
                Sprite dummySprite(monsterImg, 64, 64);
                Monster monster;
+               monster.SetName("Monster");
                monster.SetSprite(&dummySprite);
                monster.SetMaxHealth(10);
                monster.SetHealth(10);
index c01542a7aa7f44cfea9ad7c323923dabeefde6ba..30f5576ca6a9ac1737a326700db36a365d597bb8 100644 (file)
Binary files a/test-data/large-font.png and b/test-data/large-font.png differ