[12069] | 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 |
---|
[12109] | 16 | WagnisPlayer::WagnisPlayer(Context* context) : HumanPlayer(context){ |
---|
[12069] | 17 | RegisterObject(WagnisPlayer); |
---|
[12109] | 18 | this->gameBoard = nullptr; |
---|
[12114] | 19 | this->is_active = false; |
---|
| 20 | this->origin_province = nullptr; |
---|
| 21 | this->target_province = nullptr; |
---|
| 22 | this->province_selection_changed = false; |
---|
[12069] | 23 | } |
---|
| 24 | //Destructor |
---|
| 25 | WagnisPlayer::~WagnisPlayer(){ |
---|
| 26 | |
---|
| 27 | } |
---|
[12114] | 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 | this->province_selection_changed = false; |
---|
| 47 | switch(gamestage){ |
---|
| 48 | case CHOOSE_PROVINCE_STAGE: |
---|
| 49 | { |
---|
| 50 | break; |
---|
| 51 | } |
---|
| 52 | case REINFORCEMENT_STAGE: |
---|
| 53 | { |
---|
| 54 | break; |
---|
| 55 | } |
---|
| 56 | case ATTACK_STAGE:{ |
---|
| 57 | break; |
---|
| 58 | } |
---|
| 59 | case MOVE_STAGE:{ |
---|
| 60 | break; |
---|
| 61 | } |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | |
---|
[12069] | 69 | //Manages a Players turn |
---|
[12100] | 70 | void WagnisPlayer::playerTurn(){ |
---|
[12069] | 71 | |
---|
| 72 | } |
---|
[12100] | 73 | //checks if a move is valid, possible MoveTypes: ATTACK, MOVE, SET_TROOPS, SET_TROOPS_INITIAL |
---|
[12109] | 74 | bool WagnisPlayer::checkMove(WagnisProvince*,WagnisProvince*,MoveType move_type) |
---|
[12100] | 75 | { |
---|
[12109] | 76 | if (move_type == ATTACK) |
---|
[12100] | 77 | { |
---|
[12114] | 78 | if (isNeighbour(this->origin_province, this->target_province))//TODO: provinces neighbours |
---|
[12100] | 79 | { |
---|
[12114] | 80 | if (this->origin_province->getOwner_ID() == this->Player_ID) //origin belongs to player |
---|
[12100] | 81 | { |
---|
[12114] | 82 | if (this->target_province->getOwner_ID() != this->Player_ID)//target belongs to enemy |
---|
[12100] | 83 | return true; |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | |
---|
[12109] | 88 | if (move_type == MOVE) |
---|
[12100] | 89 | { |
---|
[12114] | 90 | if (existPath(this->origin_province, this->target_province))//TODO: path exists, all belong to same player |
---|
[12100] | 91 | { |
---|
[12114] | 92 | if (this->origin_province->getOwner_ID() == this->Player_ID)//origin belongs to player |
---|
[12100] | 93 | return true; |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | } |
---|
| 97 | |
---|
[12109] | 98 | if (move_type == SET_TROOPS) |
---|
[12100] | 99 | { |
---|
[12114] | 100 | if (this->target_province->getOwner_ID() == this->Player_ID)//target belongs to player |
---|
[12100] | 101 | return true; |
---|
| 102 | } |
---|
| 103 | |
---|
[12109] | 104 | if (move_type == SET_TROOPS_INITIAL) |
---|
[12100] | 105 | { |
---|
[12114] | 106 | if (this->target_province->getOwner_ID() == 0)//target belongs to nobody |
---|
[12100] | 107 | return true; |
---|
| 108 | } |
---|
| 109 | |
---|
[12080] | 110 | return false; |
---|
| 111 | } |
---|
[12100] | 112 | |
---|
[12069] | 113 | // |
---|
[12100] | 114 | void WagnisPlayer::setTroops(WagnisProvince*){ |
---|
[12069] | 115 | |
---|
| 116 | } |
---|
[12100] | 117 | void WagnisPlayer::attack(WagnisProvince*,WagnisProvince*){ |
---|
[12069] | 118 | |
---|
| 119 | } |
---|
[12100] | 120 | void WagnisPlayer::moveTroops(WagnisProvince*,WagnisProvince*){ |
---|
[12069] | 121 | |
---|
| 122 | } |
---|
| 123 | //Return a "Player x" String |
---|
| 124 | std::string WagnisPlayer::toString(){ |
---|
| 125 | std::string str = "Player "; |
---|
[12109] | 126 | str.append(std::to_string(Player_ID)); |
---|
[12069] | 127 | return str; |
---|
| 128 | } |
---|
[12103] | 129 | |
---|
| 130 | //private function for CheckMove |
---|
| 131 | //checks if provinces are neighbours for move |
---|
[12105] | 132 | bool WagnisPlayer::isNeighbour(WagnisProvince*,WagnisProvince*) |
---|
[12103] | 133 | { |
---|
[12114] | 134 | for (unsigned int i = 0; i < this->origin_province->neighbors.size(); ++i) |
---|
[12103] | 135 | { |
---|
[12114] | 136 | if (this->target_province == this->origin_province->neighbors[i]) |
---|
[12103] | 137 | return true; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | return false; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | //private function for CheckMove |
---|
| 144 | //checks if path is complete with provinces owned by player |
---|
[12105] | 145 | bool WagnisPlayer::existPath(WagnisProvince*,WagnisProvince*) |
---|
[12103] | 146 | { |
---|
[12114] | 147 | if (this->origin_province->getOwner_ID() == this->target_province->getOwner_ID() && isNeighbour(this->origin_province, this->target_province)) |
---|
[12105] | 148 | return true; |
---|
| 149 | |
---|
[12114] | 150 | for (unsigned int i = 0; i < this->origin_province->neighbors.size(); ++i) |
---|
[12105] | 151 | { |
---|
[12114] | 152 | if (this->origin_province->getOwner_ID() == this->origin_province->neighbors[i]->getOwner_ID()) |
---|
| 153 | return existPath(this->origin_province->neighbors[i], this->target_province); |
---|
[12105] | 154 | } |
---|
| 155 | |
---|
| 156 | return false; |
---|
[12103] | 157 | } |
---|
[12069] | 158 | } |
---|