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