]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/PerformAttacks.cpp
handle dead hero in BattleState
[l2e.git] / src / battle / states / PerformAttacks.cpp
1 /*
2  * PerformAttacks.cpp
3  *
4  *  Created on: Aug 10, 2012
5  *      Author: holy
6  */
7
8 #include "PerformAttacks.h"
9
10 #include "../BattleState.h"
11 #include "../Hero.h"
12 #include "../Monster.h"
13 #include "../../app/Application.h"
14 #include "../../app/Input.h"
15 #include "../../common/Ikari.h"
16 #include "../../common/Item.h"
17 #include "../../common/Spell.h"
18 #include "../../geometry/operators.h"
19 #include "../../geometry/Point.h"
20 #include "../../graphics/Font.h"
21 #include "../../graphics/Frame.h"
22
23 #include <cstring>
24
25 using app::Application;
26 using app::Input;
27 using geometry::Point;
28 using geometry::Vector;
29
30 namespace battle {
31
32 void PerformAttacks::EnterState(Application &c, SDL_Surface *screen) {
33         ctrl = &c;
34         // TODO: push battle animation if enemy is faster
35 }
36
37 void PerformAttacks::ExitState(Application &c, SDL_Surface *screen) {
38         ctrl = 0;
39 }
40
41 void PerformAttacks::ResumeState(Application &ctrl, SDL_Surface *screen) {
42         fakeMoveTimer = GraphicsTimers().StartCountdown(850);
43 }
44
45 void PerformAttacks::PauseState(Application &ctrl, SDL_Surface *screen) {
46
47 }
48
49
50 void PerformAttacks::Resize(int width, int height) {
51
52 }
53
54
55 void PerformAttacks::HandleEvents(const Input &input) {
56         if (fakeMoveTimer.JustHit()) {
57                 if (monsters) {
58                         if (titleBarText) {
59                                 titleBarText = 0;
60                                 ++cursor;
61                                 while (cursor < battle->MaxMonsters() && !battle->MonsterPositionOccupied(cursor)) {
62                                         ++cursor;
63                                 }
64                                 if (cursor >= battle->MaxMonsters()) {
65                                         battle->ClearAllAttacks();
66                                         ctrl->PopState();
67                                 }
68                         } else {
69                                 titleBarText = battle->MonsterAt(cursor).Name();
70                         }
71                 } else {
72                         if (titleBarText) {
73                                 titleBarText = 0;
74                                 ++cursor;
75                                 if (cursor == battle->NumHeroes()) {
76                                         cursor = 0;
77                                         monsters = true;
78                                 }
79                         } else {
80                                 const AttackChoice &ac(battle->AttackChoiceAt(cursor));
81                                 switch (ac.GetType()) {
82                                         case AttackChoice::SWORD:
83                                                 titleBarText = battle->HeroAt(cursor).HasWeapon() ? battle->HeroAt(cursor).Weapon()->Name() : "Gauntlet";
84                                                 break;
85                                         case AttackChoice::MAGIC:
86                                                 titleBarText = ac.GetSpell()->Name();
87                                                 break;
88                                         case AttackChoice::DEFEND:
89                                                 titleBarText = "Defends.";
90                                                 break;
91                                         case AttackChoice::IKARI:
92                                                 titleBarText = ac.GetItem()->HasIkari() ? ac.GetItem()->GetIkari()->Name() : "No Ikari?";
93                                                 break;
94                                         case AttackChoice::ITEM:
95                                                 titleBarText = ac.GetItem()->Name();
96                                                 break;
97                                         case AttackChoice::UNDECIDED:
98                                                 titleBarText = "WTF???";
99                                                 break;
100                                 }
101                         }
102                 }
103         }
104 }
105
106
107 void PerformAttacks::UpdateWorld(float deltaT) {
108
109 }
110
111 void PerformAttacks::Render(SDL_Surface *screen) {
112         Vector<int> offset(battle->CalculateScreenOffset(screen));
113         battle->RenderBackground(screen, offset);
114         battle->RenderMonsters(screen, offset);
115         battle->RenderHeroes(screen, offset);
116         battle->RenderSmallHeroTags(screen, offset);
117         RenderTitleBar(screen, offset);
118 }
119
120 void PerformAttacks::RenderTitleBar(SDL_Surface *screen, const Vector<int> &offset) {
121         if (!titleBarText) return;
122
123         int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight());
124         battle->Res().titleFrame->Draw(screen, Point<int>(offset.X(), offset.Y()), battle->BackgroundWidth(), height);
125
126         Point<int> textPosition(
127                         (battle->BackgroundWidth() - (std::strlen(titleBarText) * battle->Res().titleFont->CharWidth())) / 2,
128                         battle->Res().titleFrame->BorderHeight());
129         battle->Res().titleFont->DrawString(titleBarText, screen, textPosition + offset);
130 }
131
132 }