1 | |
---|
2 | |
---|
3 | |
---|
4 | |
---|
5 | |
---|
6 | |
---|
7 | #include "WagnisPlayer.h" |
---|
8 | #include <vector> |
---|
9 | #include <string> |
---|
10 | |
---|
11 | namespace orxonox |
---|
12 | { |
---|
13 | RegisterClass(WagnisPlayer); |
---|
14 | |
---|
15 | //Constructor |
---|
16 | WagnisPlayer::WagnisPlayer(Context* context) : HumanPlayer(context){ |
---|
17 | RegisterObject(WagnisPlayer); |
---|
18 | this->gameBoard = nullptr; |
---|
19 | this->is_active = false; |
---|
20 | this->origin_province = nullptr; |
---|
21 | this->target_province = nullptr; |
---|
22 | this->province_selection_changed = false; |
---|
23 | } |
---|
24 | //Destructor |
---|
25 | WagnisPlayer::~WagnisPlayer(){ |
---|
26 | |
---|
27 | } |
---|
28 | //Tick |
---|
29 | void WagnisPlayer::tick(float dt){ |
---|
30 | SUPER(WagnisPlayer, tick, dt); |
---|
31 | |
---|
32 | if(this->is_active){ |
---|
33 | for(WagnisProvince* prov:this->gameBoard->provs){ |
---|
34 | if(prov->getHealth() < prov->getMaxHealth()){ |
---|
35 | if(prov->getHealth() <= prov->getMaxHealth()-1000.0f){ |
---|
36 | this->target_province = prov; |
---|
37 | this->province_selection_changed = true; |
---|
38 | }else{ |
---|
39 | this->origin_province = prov; |
---|
40 | this->province_selection_changed = true; |
---|
41 | } |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | if(this->province_selection_changed && this->origin_province != nullptr && this->target_province != nullptr){ |
---|
46 | |
---|
47 | this->province_selection_changed = false; |
---|
48 | switch(gamestage){ |
---|
49 | case CHOOSE_PROVINCE_STAGE: |
---|
50 | { |
---|
51 | break; |
---|
52 | } |
---|
53 | case REINFORCEMENT_STAGE: |
---|
54 | { |
---|
55 | break; |
---|
56 | } |
---|
57 | case ATTACK_STAGE:{ |
---|
58 | break; |
---|
59 | } |
---|
60 | case MOVE_STAGE:{ |
---|
61 | break; |
---|
62 | } |
---|
63 | } |
---|
64 | } |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | |
---|
69 | |
---|
70 | //Manages a Players turn |
---|
71 | void WagnisPlayer::playerTurn(){ |
---|
72 | |
---|
73 | } |
---|
74 | //checks if a move is valid, possible MoveTypes: ATTACK, MOVE, SET_TROOPS, SET_TROOPS_INITIAL |
---|
75 | bool WagnisPlayer::checkMove(WagnisProvince*,WagnisProvince*,MoveType move_type) |
---|
76 | { |
---|
77 | if (move_type == ATTACK) |
---|
78 | { |
---|
79 | if (isNeighbour(this->origin_province, this->target_province))//TODO: provinces neighbours |
---|
80 | { |
---|
81 | if (this->origin_province->getOwner_ID() == this->Player_ID) //origin belongs to player |
---|
82 | { |
---|
83 | if (this->target_province->getOwner_ID() != this->Player_ID)//target belongs to enemy |
---|
84 | return true; |
---|
85 | } |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | if (move_type == MOVE) |
---|
90 | { |
---|
91 | if (existPath(this->origin_province, this->target_province))//TODO: path exists, all belong to same player |
---|
92 | { |
---|
93 | if (this->origin_province->getOwner_ID() == this->Player_ID)//origin belongs to player |
---|
94 | return true; |
---|
95 | } |
---|
96 | |
---|
97 | } |
---|
98 | |
---|
99 | if (move_type == SET_TROOPS) |
---|
100 | { |
---|
101 | if (this->target_province->getOwner_ID() == this->Player_ID)//target belongs to player |
---|
102 | return true; |
---|
103 | } |
---|
104 | |
---|
105 | if (move_type == SET_TROOPS_INITIAL) |
---|
106 | { |
---|
107 | if (this->target_province->getOwner_ID() == 0)//target belongs to nobody |
---|
108 | return true; |
---|
109 | } |
---|
110 | |
---|
111 | return false; |
---|
112 | } |
---|
113 | |
---|
114 | // |
---|
115 | void WagnisPlayer::setTroops(WagnisProvince*){ |
---|
116 | |
---|
117 | } |
---|
118 | void WagnisPlayer::attack(WagnisProvince*,WagnisProvince*){ |
---|
119 | |
---|
120 | } |
---|
121 | void WagnisPlayer::moveTroops(WagnisProvince*,WagnisProvince*){ |
---|
122 | |
---|
123 | } |
---|
124 | //Return a "Player x" String |
---|
125 | std::string WagnisPlayer::toString(){ |
---|
126 | std::string str = "Player "; |
---|
127 | str.append(std::to_string(Player_ID)); |
---|
128 | return str; |
---|
129 | } |
---|
130 | |
---|
131 | //private function for CheckMove |
---|
132 | //checks if provinces are neighbours for move |
---|
133 | bool WagnisPlayer::isNeighbour(WagnisProvince*,WagnisProvince*) |
---|
134 | { |
---|
135 | for (unsigned int i = 0; i < this->origin_province->neighbors.size(); ++i) |
---|
136 | { |
---|
137 | if (this->target_province == this->origin_province->neighbors[i]) |
---|
138 | return true; |
---|
139 | } |
---|
140 | |
---|
141 | return false; |
---|
142 | } |
---|
143 | |
---|
144 | //private function for CheckMove |
---|
145 | //checks if path is complete with provinces owned by player |
---|
146 | bool WagnisPlayer::existPath(WagnisProvince*,WagnisProvince*) |
---|
147 | { |
---|
148 | if (this->origin_province->getOwner_ID() == this->target_province->getOwner_ID() && isNeighbour(this->origin_province, this->target_province)) |
---|
149 | return true; |
---|
150 | |
---|
151 | for (unsigned int i = 0; i < this->origin_province->neighbors.size(); ++i) |
---|
152 | { |
---|
153 | if (this->origin_province->getOwner_ID() == this->origin_province->neighbors[i]->getOwner_ID()) |
---|
154 | return existPath(this->origin_province->neighbors[i], this->target_province); |
---|
155 | } |
---|
156 | |
---|
157 | return false; |
---|
158 | } |
---|
159 | } |
---|