[Orxonox-commit 7547] r12150 - in code/branches/wagnis_HS18: data/levels src/modules/wagnis

stadlero at orxonox.net stadlero at orxonox.net
Wed Dec 5 11:54:14 CET 2018


Author: stadlero
Date: 2018-12-05 11:54:14 +0100 (Wed, 05 Dec 2018)
New Revision: 12150

Modified:
   code/branches/wagnis_HS18/data/levels/Wagnis_testlevel.oxw
   code/branches/wagnis_HS18/src/modules/wagnis/Wagnis.cc
   code/branches/wagnis_HS18/src/modules/wagnis/Wagnis.h
   code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.cc
   code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.h
   code/branches/wagnis_HS18/src/modules/wagnis/WagnisProvince.cc
Log:
Game progression finished. still bugs.

Modified: code/branches/wagnis_HS18/data/levels/Wagnis_testlevel.oxw
===================================================================
--- code/branches/wagnis_HS18/data/levels/Wagnis_testlevel.oxw	2018-12-05 10:43:36 UTC (rev 12149)
+++ code/branches/wagnis_HS18/data/levels/Wagnis_testlevel.oxw	2018-12-05 10:54:14 UTC (rev 12150)
@@ -31,7 +31,7 @@
     <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
     <SpawnPoint position="-100, 45, 75" lookat="0,45,75" spawnclass=SpaceShip pawndesign=wagnisCursor />
 
-<WagnisGameboard position="20,20,20" connections_string="1=2+3, 2=1, 3=1">
+<WagnisGameboard position="20,20,20" connections_string="1=2+4+5, 2=1+3, 3=2+4, 4=3+1, 5=1+6, 6=7+5, 7=6+8, 8=7">
 
 
   <Provinces>

Modified: code/branches/wagnis_HS18/src/modules/wagnis/Wagnis.cc
===================================================================
--- code/branches/wagnis_HS18/src/modules/wagnis/Wagnis.cc	2018-12-05 10:43:36 UTC (rev 12149)
+++ code/branches/wagnis_HS18/src/modules/wagnis/Wagnis.cc	2018-12-05 10:54:14 UTC (rev 12150)
@@ -15,8 +15,10 @@
     this->gameBoard = nullptr;
     this->gameStage = NOT_READY;
     this->active_player = 1;
+    this->initial_reinforcements_left = 5;
+    this->empty_provinces_left = 0;
 
-    int n = 8;
+    int n = 3;
     for(int i = 0;i < n;i++){
         WagnisPlayer* p = new WagnisPlayer(context);
         p->Player_ID = i+1;
@@ -40,8 +42,10 @@
     }
 
     this->gameStage = CHOOSE_PROVINCE_STAGE;
+    this->empty_provinces_left = this->provinceCount();
     this->players.at(0)->gameStage = this->gameStage;
-    this->players.at(0)->is_active = true;
+    this->players.at(0)->setActive(true);
+    this->players.at(0)->reinforcements = 0;
     orxout()<<"Player "<<1<<"\'s turn. Please choose province."<<endl;
 }
 
@@ -65,24 +69,66 @@
     }
     switch(this->gameStage){
         case CHOOSE_PROVINCE_STAGE:{
-            player->is_active = false;
-            if(this->active_player < this->players.size()){
-                this->active_player++;
+            player->setActive(false);
+            this->empty_provinces_left -= 1;
+            if(this->empty_provinces_left > 0){
+                //Still empty provinces left
+                orxout()<<"DEBUG: Empty provs: "<<this->empty_provinces_left<<endl;
+
+                if(this->active_player < this->players.size()){
+                    this->active_player++;
+                }else{
+                    this->active_player = 1;
+                }
+
                 WagnisPlayer* next = this->players[this->active_player - 1];
                 next->gameStage = CHOOSE_PROVINCE_STAGE;
-                next->is_active = true;
+                next->setActive(true);
+                next->reinforcements = 0;
                 orxout()<<"Player "<<next->Player_ID<<"\'s turn. Please choose province."<<endl;
             }else{
+                //no empty provinces left
+                orxout()<<"DEBUG: Empty provs: "<<this->empty_provinces_left<<endl;
                 this->active_player = 1;
                 WagnisPlayer* next = this->players[this->active_player - 1];
                 next->gameStage = REINFORCEMENT_STAGE;
                 this->gameStage = REINFORCEMENT_STAGE;
-                next->is_active = true;
+                next->setActive(true);
+                next->reinforcements = 1;
                 orxout()<<"Player "<<next->Player_ID<<"\'s turn. Reinforcement."<<endl;
             }
             break;
         }
         case REINFORCEMENT_STAGE:{
+            
+            if(this->initial_reinforcements_left > 0){
+                player->setActive(false);
+                if(this->active_player == this->players.size()){
+                    //Last player finished this round of initial troops.
+                    this->initial_reinforcements_left -= 1;
+                    WagnisPlayer* next = this->players.at(0);
+                    this->active_player = 1;
+                    next->setActive(true);
+                    next->gameStage = REINFORCEMENT_STAGE;
+                    if(this->initial_reinforcements_left > 0){
+                        //Still more troops left to place and player 1 is next.
+                        next->reinforcements = 1;
+                    }else{
+                        //No more troops left to place and player 1 is next.
+                        next->reinforcements = provincesOfPlayerCounter(1);
+                    }
+                }else{
+                    //Player who finished was not the last player
+                    WagnisPlayer* next = this->players.at(this->active_player);
+                    this->active_player += 1;
+                    next->setActive(true);
+                    next->gameStage = REINFORCEMENT_STAGE;
+                    next->reinforcements = 1;
+                }
+                break;
+            }
+            //Standard Reinforcement
+
             player->gameStage = ATTACK_STAGE;
             this->gameStage = ATTACK_STAGE;
             orxout()<<"Player "<<player->Player_ID<<"\'s turn. Attack."<<endl;
@@ -95,7 +141,7 @@
             break;
         }
         case MOVE_STAGE:{
-            player->is_active = false;
+            player->setActive(false);
             if(this->active_player < this->players.size()){
                 this->active_player++;
             }else{
@@ -105,7 +151,7 @@
             orxout()<<"Player "<<next->Player_ID<<"\'s turn. Reinforcement."<<endl;
             next->gameStage = REINFORCEMENT_STAGE;
             this->gameStage = REINFORCEMENT_STAGE;
-            next->is_active = true;
+            next->setActive(true);
             break;
         }
         default:{}
@@ -142,7 +188,34 @@
     return false;
 }
 
+//Counts legit provinces(not including buttons)
+int Wagnis::provinceCount(){
+    int n = 0;
+    for(WagnisProvince* p: this->gameBoard->provs){
+        if(p != nullptr){
+            if(p->ID < 1000){
+                n++;
+            }
+        }else{
+            orxout()<<"Nullpointer found in provines!!!"<<endl;
+        }
+    }
+    return n;
+}
 
+int Wagnis::provincesOfPlayerCounter(int player){
+    int n = 0;
+    for(WagnisProvince* p:this->gameBoard->provs){
+        if(p != nullptr){
+            if(p->getOwner_ID() == player){
+                n++;
+            }
+        }else{
+            orxout()<<"Nullpointer found in provines!!!"<<endl;
+        }
+    }
+    return n;
+}
 
 
 
@@ -154,6 +227,8 @@
 
 
 
+
+
 }
 
 

Modified: code/branches/wagnis_HS18/src/modules/wagnis/Wagnis.h
===================================================================
--- code/branches/wagnis_HS18/src/modules/wagnis/Wagnis.h	2018-12-05 10:43:36 UTC (rev 12149)
+++ code/branches/wagnis_HS18/src/modules/wagnis/Wagnis.h	2018-12-05 10:54:14 UTC (rev 12150)
@@ -45,10 +45,14 @@
 
         private:
         int active_player;
+        int initial_reinforcements_left;
+        int empty_provinces_left;
         GameStage gameStage;
         std::vector<WagnisPlayer*> players;
         void createGame();
         bool findGameBoard();
+        int provinceCount();
+        int provincesOfPlayerCounter(int);
     };
 }
 #endif

Modified: code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.cc
===================================================================
--- code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.cc	2018-12-05 10:43:36 UTC (rev 12149)
+++ code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.cc	2018-12-05 10:54:14 UTC (rev 12150)
@@ -79,6 +79,7 @@
                             if (checkMove(SET_TROOPS))
                             {
                                 this->target_province->setTroops(this->target_province->getTroops()+1);
+                                this->reinforcements -= 1;
                                 orxout()<<"Province "<<this->target_province->getID()<<" owned by Player "<<this->target_province->getOwner_ID()<<" troops: "<<this->target_province->getTroops()<<endl;
                             }
                         }   
@@ -88,7 +89,9 @@
                     case ATTACK_STAGE:{
 
                         if (checkMove(ATTACK))
+                        
                         {
+                            orxout()<<"Attack move check returned valid"<<endl;
                             while ((this->origin_province->getTroops() > 1) && (this->target_province->getTroops() > 0)) //still troops available
                             {
                                 while ((this->origin_province->getTroops() >= 4) && (this->target_province->getTroops() >= 2))
@@ -198,6 +201,8 @@
                                 this->target_province->setTroops(this->origin_province->getTroops() - 1);
                                 this->origin_province->setTroops(1);
                             }
+                        }else{
+                            orxout()<<"Attack move check returned false"<<endl;
                         }
                         
                         break;
@@ -336,4 +341,13 @@
         else 
             return b;    
     }
+
+    void WagnisPlayer::setActive(bool b){
+        this->is_active = b;
+        if(b == true) orxout()<<"Player "<<this->Player_ID<<"\'s turn"<<endl;
+    }
+
+    bool WagnisPlayer::isActive() const {
+        return this->is_active;
+    }
 }

Modified: code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.h
===================================================================
--- code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.h	2018-12-05 10:43:36 UTC (rev 12149)
+++ code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.h	2018-12-05 10:54:14 UTC (rev 12150)
@@ -35,6 +35,8 @@
         void attack(WagnisProvince*,WagnisProvince*);
         void moveTroops(WagnisProvince*,WagnisProvince*);
         std::string toString();
+        void setActive(bool);
+        bool isActive() const;
 
 
 
@@ -41,7 +43,6 @@
         Wagnis* master;
         GameStage gameStage;
         bool province_selection_changed;
-        bool is_active;
         int Player_ID;
         WagnisGameboard* gameBoard;
         WagnisProvince* origin_province;
@@ -54,6 +55,9 @@
         int best2(int, int);
         int second3(int, int, int);
         int second2(int, int);
+
+        private:
+        bool is_active;
     };
 }
 

Modified: code/branches/wagnis_HS18/src/modules/wagnis/WagnisProvince.cc
===================================================================
--- code/branches/wagnis_HS18/src/modules/wagnis/WagnisProvince.cc	2018-12-05 10:43:36 UTC (rev 12149)
+++ code/branches/wagnis_HS18/src/modules/wagnis/WagnisProvince.cc	2018-12-05 10:54:14 UTC (rev 12150)
@@ -55,9 +55,9 @@
                     break;
             case 2: this->setRadarObjectColour( colour({0,255,0}, 100.0f) );
                     break;
-            case 3: this->setRadarObjectColour( colour({0,0,255}, 100.0f) );
+            case 3: this->setRadarObjectColour( colour({255,255,0}, 100.0f) );
                     break;
-            case 4: this->setRadarObjectColour( colour({255,255,0}, 100.0f) );
+            case 4: this->setRadarObjectColour( colour({0,0,255}, 100.0f) );
                     break;
             case 5: this->setRadarObjectColour( colour({255,0,255}, 100.0f) );
                     break;
@@ -76,12 +76,6 @@
     void WagnisProvince::setTroops(int troops){
         this->troops = troops;
         this->setRadarName(std::to_string(troops));
-        //TEST
-        if(troops == 5){
-            Ogre::ColourValue cv = colour({255,255,255}, 100.0f);
-            this->setRadarObjectColour(cv);
-        }
-        
     }
     //set ID
     void WagnisProvince::setID(int id){



More information about the Orxonox-commit mailing list