]> git.localhorst.tv Git - l2e.git/blob - src/battle/states/SelectAttackType.cpp
removed invalid TODO :o
[l2e.git] / src / battle / states / SelectAttackType.cpp
1 /*
2  * SelectAttackType.cpp
3  *
4  *  Created on: Aug 7, 2012
5  *      Author: holy
6  */
7
8 #include "SelectAttackType.h"
9
10 #include "SelectIkari.h"
11 #include "SelectItem.h"
12 #include "SelectMoveAction.h"
13 #include "SelectSpell.h"
14 #include "SelectTarget.h"
15 #include "../AttackChoice.h"
16 #include "../BattleState.h"
17 #include "../../app/Application.h"
18 #include "../../app/Input.h"
19 #include "../../common/Item.h"
20 #include "../../geometry/operators.h"
21
22 #include <stdexcept>
23
24 using app::Application;
25 using app::Input;
26 using common::Item;
27 using geometry::Point;
28 using geometry::Vector;
29
30 namespace battle {
31
32 void SelectAttackType::EnterState(Application &c, SDL_Surface *screen) {
33         ctrl = &c;
34 }
35
36 void SelectAttackType::ExitState(Application &c, SDL_Surface *screen) {
37         ctrl = 0;
38 }
39
40 void SelectAttackType::ResumeState(Application &ctrl, SDL_Surface *screen) {
41         if (battle->ActiveHero().GetAttackChoice().Selection().HasSelected()) {
42                 battle->ActiveHero().GetAttackChoice().SetType(battle->GetAttackTypeMenu().Selected());
43                 battle->NextHero();
44         }
45         if (battle->AttackSelectionDone()) {
46                 // pass through
47                 ctrl.PopState();
48         }
49 }
50
51 void SelectAttackType::PauseState(Application &ctrl, SDL_Surface *screen) {
52
53 }
54
55
56 void SelectAttackType::Resize(int width, int height) {
57
58 }
59
60
61 void SelectAttackType::HandleEvents(const Input &input) {
62         if (input.IsDown(Input::PAD_UP)) {
63                 battle->GetAttackTypeMenu().Select(AttackChoice::MAGIC);
64         } else if (input.IsDown(Input::PAD_RIGHT)) {
65                 battle->GetAttackTypeMenu().Select(AttackChoice::DEFEND);
66         } else if (input.IsDown(Input::PAD_DOWN)) {
67                 battle->GetAttackTypeMenu().Select(AttackChoice::IKARI);
68         } else if (input.IsDown(Input::PAD_LEFT)) {
69                 battle->GetAttackTypeMenu().Select(AttackChoice::ITEM);
70         } else {
71                 battle->GetAttackTypeMenu().Select(AttackChoice::SWORD);
72         }
73
74         Hero &hero(battle->ActiveHero());
75         AttackChoice &ac(hero.GetAttackChoice());
76         if (input.JustPressed(Input::ACTION_A)) {
77                 switch (battle->GetAttackTypeMenu().Selected()) {
78                         case AttackChoice::SWORD:
79                                 if (hero.HasWeapon()) {
80                                         if (hero.Weapon()->GetTargetingMode().TargetsAll()) {
81                                                 ac.SetType(AttackChoice::SWORD);
82                                                 battle->NextHero();
83                                                 break;
84                                         } else {
85                                                 ac.Selection().ReadMode(hero.Weapon()->GetTargetingMode());
86                                         }
87                                 } else {
88                                         ac.Selection().SetSingle();
89                                 }
90                                 ac.Selection().Reset();
91                                 ctrl->PushState(new SelectTarget(battle, this, &ac.Selection(), battle->Res().weaponTargetCursor));
92                                 break;
93                         case AttackChoice::MAGIC:
94                                 if (battle->ActiveHero().CanUseMagic()) {
95                                         ctrl->PushState(new SelectSpell(battle, this));
96                                 }
97                                 break;
98                         case AttackChoice::DEFEND:
99                                 ac.SetType(AttackChoice::DEFEND);
100                                 battle->NextHero();
101                                 break;
102                         case AttackChoice::IKARI:
103                                 ctrl->PushState(new SelectIkari(battle, this));
104                                 break;
105                         case AttackChoice::ITEM:
106                                 ctrl->PushState(new SelectItem(battle, this));
107                                 break;
108                         default:
109                                 throw std::logic_error("selected invalid attack type");
110                 }
111         } else if (input.JustPressed(Input::ACTION_B)) {
112                 ac.Reset();
113                 battle->PreviousHero();
114                 if (battle->BeforeFirstHero()) {
115                         ctrl->ChangeState(new SelectMoveAction(battle));
116                 } else {
117                         ac.Reset();
118                 }
119         }
120
121         if (battle->AttackSelectionDone()) {
122                 ctrl->PopState();
123         }
124 }
125
126 void SelectAttackType::UpdateWorld(float deltaT) {
127
128 }
129
130 void SelectAttackType::Render(SDL_Surface *screen) {
131         Vector<int> offset(battle->CalculateScreenOffset(screen));
132         battle->RenderBackground(screen, offset);
133         battle->RenderMonsters(screen, offset);
134         battle->RenderHeroTags(screen, offset);
135         RenderMenu(screen, offset);
136 }
137
138 void SelectAttackType::RenderMenu(SDL_Surface *screen, const Vector<int> &offset) {
139         Point<int> position(
140                         (battle->Width() - battle->GetAttackTypeMenu().Width()) / 2,
141                         battle->Height() - battle->GetAttackTypeMenu().Height() - battle->GetAttackTypeMenu().Height() / 2);
142         battle->GetAttackTypeMenu().Render(screen, position + offset);
143 }
144
145 }