+/*
+ * 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);
+}
+
+}