]> git.localhorst.tv Git - l2e.git/blob - src/battle/TargetSelection.h
06d6f44198cda86c59341b314d4034a824cddd8a
[l2e.git] / src / battle / TargetSelection.h
1 /*
2  * TargetSelection.h
3  *
4  *  Created on: Aug 9, 2012
5  *      Author: holy
6  */
7
8 #ifndef BATTLE_TARGETSELECTION_H_
9 #define BATTLE_TARGETSELECTION_H_
10
11 #include "fwd.h"
12 #include "../common/fwd.h"
13
14 #include <vector>
15
16 namespace battle {
17
18 class TargetSelection {
19
20 public:
21         explicit TargetSelection(BattleState *battle = 0, bool multiple = false, bool atEnemy = true);
22
23 public:
24         bool TargetsMonsters() const { return enemy; }
25         bool TargetsHeroes() const { return !TargetsMonsters(); }
26         bool IsSelected(int index) const { return index >= 0 && index < int(selected.size()) && selected[index].type != State::IGNORE; }
27         bool HasSelected() const { return selection >= 0; }
28         int SingleSelection() const { return selection; }
29
30         bool SelectMultiple() const { return multiple; }
31         void SetMultiple() { multiple = true; }
32         bool SelectSingle() const { return !SelectMultiple(); }
33         void SetSingle() { multiple = false; }
34
35         void ReadMode(const common::TargetingMode &);
36
37         void SelectMonsters();
38         void SelectHeroes();
39         void Select(int index) { selected[index].type = State::SELECTED; selection = index; }
40         void Unselect(int index) { selected[index].type = State::IGNORE; }
41         void UnselectAll() { selected.assign(selected.size(), State()); selection = -1; }
42
43         void Reset();
44         void Resize(int num) { selected.resize(num); }
45
46         void MoveUp();
47         void MoveRight();
48         void MoveDown();
49         void MoveLeft();
50         void Select() { Select(cursor); }
51         void Unselect() { Unselect(cursor); }
52         int Current() const { return cursor; }
53         bool CurrentIsSelected() { return IsSelected(cursor); }
54
55         void SetMiss(int index) { selected[index].type = State::MISS; }
56         void SetFull(int index) { selected[index].type = State::FULL; }
57         void SetGood(int index, int amount) { selected[index].type = State::GOOD; selected[index].number = amount; }
58         void SetBad(int index, int amount) { selected[index].type = State::BAD; selected[index].number = amount; }
59         int GetAmount(int index) const { return selected[index].number; }
60         bool Missed(int index) const { return selected[index].type == State::MISS; }
61         bool IsGood(int index) const { return selected[index].type == State::GOOD; }
62         bool IsBad(int index) const { return selected[index].type == State::BAD; }
63
64 private:
65         void FindNextEnemy();
66
67 private:
68         struct State {
69                 enum Type {
70                         IGNORE,
71                         SELECTED,
72                         MISS,
73                         FULL,
74                         GOOD,
75                         BAD,
76                 } type;
77                 int number;
78                 explicit State(Type type = IGNORE, int num = 0) : type(type), number(num) { }
79         };
80         BattleState *battle;
81         std::vector<State> selected;
82         int selection;
83         int cursor;
84         bool multiple;
85         bool enemy;
86
87 };
88
89 }
90
91 #endif /* BATTLE_TARGETSELECTION_H_ */