[Orxonox-commit 7521] r12127 - code/branches/wagnis_HS18/src/modules/wagnis

samuelbl at orxonox.net samuelbl at orxonox.net
Wed Nov 28 11:57:49 CET 2018


Author: samuelbl
Date: 2018-11-28 11:57:48 +0100 (Wed, 28 Nov 2018)
New Revision: 12127

Modified:
   code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.cc
   code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.h
Log:
Player moves implemented

Modified: code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.cc
===================================================================
--- code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.cc	2018-11-28 10:52:42 UTC (rev 12126)
+++ code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.cc	2018-11-28 10:57:48 UTC (rev 12127)
@@ -29,7 +29,8 @@
     void WagnisPlayer::tick(float dt){
         SUPER(WagnisPlayer, tick, dt);
 
-        if(this->is_active){
+        if(this->is_active)
+        {
             for(WagnisProvince* prov:this->gameBoard->provs){
                 if(prov->getHealth() < prov->getMaxHealth()){
                     if(prov->getHealth() <= prov->getMaxHealth()-1000.0f){
@@ -42,22 +43,67 @@
                 }
             }
 
-            if(this->province_selection_changed && this->origin_province != nullptr && this->target_province != nullptr){
+            if((this->province_selection_changed && this->origin_province != nullptr && this->target_province != nullptr)
+            ||(this->province_selection_changed && this->target_province != nullptr && ((gamestage == CHOOSE_PROVINCE_STAGE)||(gamestage == REINFORCEMENT_STAGE)))){
                 
                 this->province_selection_changed = false;
                 switch(gamestage){
                     case CHOOSE_PROVINCE_STAGE: 
                     {   
+                        if (checkMove(SET_TROOPS_INITIAL))
+                            this->target_province->owner_ID = this->Player_ID;
+                        
                         break;
                     }
+                    
                     case REINFORCEMENT_STAGE:
                     {
+                        if (checkMove(SET_TROOPS))
+                            this->target_province->troops += 1;
+                        
                         break;
                     }
                     case ATTACK_STAGE:{
+
+                        if (checkMove(ATTACK))
+                        {
+                            while ((this->origin_province->troops > 1) && (this->target_province->troops > 0)) //still troops available
+                            {
+                                while ((this->origin_province->troops >= 4) && (this->target_province->troops >= 2))
+                                {
+                                    //normal fight, 3 attackers, 2 defenders
+                                }
+
+                                if ((this->origin_province->troops == 3) && (this->target_province->troops >= 2))
+                                {
+                                    //2 attackers, 2 defenders
+                                }
+
+                                if((this->origin_province->troops == 2) && (this->target_province->troops >= 2))
+                                {
+                                    //1 attacker, 2 defenders
+                                }
+
+                                //TODO: implement other cases
+                            }
+
+                            if (this->target_province->troops == 0) //attacker won
+                            {
+                                this->target_province->owner_ID = this->Player_ID;
+                                this->target_province->troops = (this->origin_province->troops - 1);
+                                this->origin_province->troops = 1;
+                            }
+                        }
+                        
                         break;
                     }
                     case MOVE_STAGE:{
+
+                        if (checkMove(MOVE))
+                        {
+                            this->target_province->troops += ((this->origin_province->troops) - 1);
+                            this->origin_province->troops = 1;
+                        }
                         break;
                     }
                 }
@@ -72,11 +118,11 @@
         
     }
     //checks if a move is valid, possible MoveTypes: ATTACK, MOVE, SET_TROOPS, SET_TROOPS_INITIAL
-    bool WagnisPlayer::checkMove(WagnisProvince*,WagnisProvince*,MoveType move_type)
+    bool WagnisPlayer::checkMove(MoveType move_type)
     {
         if (move_type == ATTACK)
         {
-            if (isNeighbour(this->origin_province, this->target_province))//TODO: provinces neighbours
+            if (isNeighbour(this->origin_province, this->target_province))//provinces neighbours
             {
                 if (this->origin_province->getOwner_ID() == this->Player_ID) //origin belongs to player
                 {
@@ -88,7 +134,7 @@
 
         if (move_type == MOVE)
         {
-            if (existPath(this->origin_province, this->target_province))//TODO: path exists, all belong to same player
+            if (existPath(this->origin_province, this->target_province))//path exists, all belong to same player
             {
                 if (this->origin_province->getOwner_ID() == this->Player_ID)//origin belongs to player
                     return true;
@@ -104,7 +150,7 @@
 
         if (move_type == SET_TROOPS_INITIAL)
         {
-            if (this->target_province->getOwner_ID() == 0)//target belongs to nobody
+            if (this->target_province->getOwner_ID() == -1)//target belongs to nobody
                 return true;
         }
         
@@ -130,11 +176,11 @@
 
     //private function for CheckMove
     //checks if provinces are neighbours for move
-    bool WagnisPlayer::isNeighbour(WagnisProvince*,WagnisProvince*)
+    bool WagnisPlayer::isNeighbour(WagnisProvince* origin, WagnisProvince* target)
     {
-        for (unsigned int i = 0; i < this->origin_province->neighbors.size(); ++i)
+        for (unsigned int i = 0; i < origin->neighbors.size(); ++i)
         {
-            if (this->target_province == this->origin_province->neighbors[i])
+            if (target == origin->neighbors[i])
                 return true;
         }
 
@@ -143,15 +189,15 @@
 
     //private function for CheckMove
     //checks if path is complete with provinces owned by player
-    bool WagnisPlayer::existPath(WagnisProvince*,WagnisProvince*)
+    bool WagnisPlayer::existPath(WagnisProvince* origin, WagnisProvince* target)
     {
-        if (this->origin_province->getOwner_ID() == this->target_province->getOwner_ID() && isNeighbour(this->origin_province, this->target_province))
+        if (origin->getOwner_ID() == target->getOwner_ID() && isNeighbour(origin, target))
             return true;
         
-        for (unsigned int i = 0; i < this->origin_province->neighbors.size(); ++i)
+        for (unsigned int i = 0; i < origin->neighbors.size(); ++i)
         {
-            if (this->origin_province->getOwner_ID() == this->origin_province->neighbors[i]->getOwner_ID())
-                return existPath(this->origin_province->neighbors[i], this->target_province);
+            if (origin->getOwner_ID() == origin->neighbors[i]->getOwner_ID())
+                return existPath(origin->neighbors[i], target);
         }
             
         return false;

Modified: code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.h
===================================================================
--- code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.h	2018-11-28 10:52:42 UTC (rev 12126)
+++ code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.h	2018-11-28 10:57:48 UTC (rev 12127)
@@ -30,7 +30,7 @@
         void tick(float);
 
         void playerTurn();
-        bool checkMove(WagnisProvince*,WagnisProvince*,MoveType);
+        bool checkMove(MoveType);
         void setTroops(WagnisProvince*);
         void attack(WagnisProvince*,WagnisProvince*);
         void moveTroops(WagnisProvince*,WagnisProvince*);
@@ -45,8 +45,8 @@
         WagnisGameboard* gameBoard;
         WagnisProvince* origin_province;
         WagnisProvince* target_province;
-        bool isNeighbour(WagnisProvince*,WagnisProvince*);
-        bool existPath(WagnisProvince*,WagnisProvince*);
+        bool isNeighbour(WagnisProvince*, WagnisProvince*);
+        bool existPath(WagnisProvince*, WagnisProvince*);
     };
 }
 



More information about the Orxonox-commit mailing list