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