Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.cc @ 12114

Last change on this file since 12114 was 12114, checked in by stadlero, 5 years ago

WIP 21 nov

File size: 4.7 KB
Line 
1
2
3
4
5
6
7#include "WagnisPlayer.h"
8#include <vector>
9#include <string>
10
11namespace 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                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
69    //Manages a Players turn
70    void WagnisPlayer::playerTurn(){
71       
72    }
73    //checks if a move is valid, possible MoveTypes: ATTACK, MOVE, SET_TROOPS, SET_TROOPS_INITIAL
74    bool WagnisPlayer::checkMove(WagnisProvince*,WagnisProvince*,MoveType move_type)
75    {
76        if (move_type == ATTACK)
77        {
78            if (isNeighbour(this->origin_province, this->target_province))//TODO: provinces neighbours
79            {
80                if (this->origin_province->getOwner_ID() == this->Player_ID) //origin belongs to player
81                {
82                    if (this->target_province->getOwner_ID() != this->Player_ID)//target belongs to enemy
83                        return true;
84                }
85            }
86        }
87
88        if (move_type == MOVE)
89        {
90            if (existPath(this->origin_province, this->target_province))//TODO: path exists, all belong to same player
91            {
92                if (this->origin_province->getOwner_ID() == this->Player_ID)//origin belongs to player
93                    return true;
94            }
95
96        }
97
98        if (move_type == SET_TROOPS)
99        {
100            if (this->target_province->getOwner_ID() == this->Player_ID)//target belongs to player
101                return true;
102        }
103
104        if (move_type == SET_TROOPS_INITIAL)
105        {
106            if (this->target_province->getOwner_ID() == 0)//target belongs to nobody
107                return true;
108        }
109       
110        return false;
111    }
112   
113    //
114    void WagnisPlayer::setTroops(WagnisProvince*){
115
116    }
117    void WagnisPlayer::attack(WagnisProvince*,WagnisProvince*){
118
119    }
120    void WagnisPlayer::moveTroops(WagnisProvince*,WagnisProvince*){
121
122    }
123    //Return a "Player x" String
124    std::string WagnisPlayer::toString(){
125        std::string str = "Player ";
126        str.append(std::to_string(Player_ID));
127        return str;
128    }
129
130    //private function for CheckMove
131    //checks if provinces are neighbours for move
132    bool WagnisPlayer::isNeighbour(WagnisProvince*,WagnisProvince*)
133    {
134        for (unsigned int i = 0; i < this->origin_province->neighbors.size(); ++i)
135        {
136            if (this->target_province == this->origin_province->neighbors[i])
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
145    bool WagnisPlayer::existPath(WagnisProvince*,WagnisProvince*)
146    {
147        if (this->origin_province->getOwner_ID() == this->target_province->getOwner_ID() && isNeighbour(this->origin_province, this->target_province))
148            return true;
149       
150        for (unsigned int i = 0; i < this->origin_province->neighbors.size(); ++i)
151        {
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);
154        }
155           
156        return false;
157    }
158}
Note: See TracBrowser for help on using the repository browser.