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

stadlero at orxonox.net stadlero at orxonox.net
Wed Nov 28 23:17:41 CET 2018


Author: stadlero
Date: 2018-11-28 23:17:41 +0100 (Wed, 28 Nov 2018)
New Revision: 12130

Modified:
   code/branches/wagnis_HS18/data/levels/Wagnis.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/WagnisGameboard.cc
   code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.cc
   code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.h
Log:
changed gametype from Deathmatch to Wagnis in Wagnis.oxw + some wip in Wagnis.cc

Modified: code/branches/wagnis_HS18/data/levels/Wagnis.oxw
===================================================================
--- code/branches/wagnis_HS18/data/levels/Wagnis.oxw	2018-11-28 11:53:04 UTC (rev 12129)
+++ code/branches/wagnis_HS18/data/levels/Wagnis.oxw	2018-11-28 22:17:41 UTC (rev 12130)
@@ -37,7 +37,7 @@
 </Template> -->
 
 
-<Level plugins="wagnis" gametype="Deathmatch">
+<Level plugins="wagnis" gametype="Wagnis">
   <templates>
     <Template link=lodtemplate_default />
   </templates>

Modified: code/branches/wagnis_HS18/src/modules/wagnis/Wagnis.cc
===================================================================
--- code/branches/wagnis_HS18/src/modules/wagnis/Wagnis.cc	2018-11-28 11:53:04 UTC (rev 12129)
+++ code/branches/wagnis_HS18/src/modules/wagnis/Wagnis.cc	2018-11-28 22:17:41 UTC (rev 12130)
@@ -14,11 +14,16 @@
     RegisterObject(Wagnis);
     this->gameBoard = nullptr;
     this->gameStage = NOT_READY;
+    this->active_player = 1;
 
     int n = 3;
+    this->players.push_back(nullptr);
     for(int i = 1;i <= n;i++){
         WagnisPlayer* p = new WagnisPlayer(context);
         p->gameBoard = this->gameBoard;
+        p->Player_ID = i;
+        p->master = this;
+        //p->finishedStageCallback = &Wagnis::playerFinishedStage;
         this->players.push_back(p);
     }
 }
@@ -28,8 +33,14 @@
 
 //Runs the game
 void Wagnis::start(){
-    //SUPER(Wagnis,start);
-    this->createGame();
+    Deathmatch::start();
+    if(this->gameStage == NOT_READY){
+        this->createGame();
+    }
+
+    //this->gameStage = CHOOSE_PROVINCE_STAGE;
+    //this->players[1]->gameStage = this->gameStage;
+    //this->players[1]->is_active = true;
 }
 
 //Tick
@@ -37,16 +48,67 @@
     SUPER(Wagnis,tick,dt);
 }
 
+
+
+/**
+ * Callback function for Player classes. Needs to be called for the game to go on.
+ * arg: player: pointer to the player which finished his stage.
+ * (used to deactivate player after finishing)
+ * enum GameStage { NOT_READY, CHOOSE_PROVINCE_STAGE, REINFORCEMENT_STAGE, ATTACK_STAGE, MOVE_STAGE };
+ **/
+void Wagnis::playerFinishedStage(WagnisPlayer* player){
+
+    /////////////////TEST////////////
+    orxout()<<"juhuuuuuuuuuuuuuuuuuuu"<<endl;
+    /////////////////TEST////////////
+
+    if(this->active_player != player->Player_ID){
+        orxout()<<"shit happend. This player should not be activ. Wagnis::playerFinishedStage was called from wrong player"<<endl;
+    }
+    switch(this->gameStage){
+        case CHOOSE_PROVINCE_STAGE:{
+            player->is_active = false;
+            if(this->active_player+1 < this->players.size()){
+                this->active_player++;
+                this->players[this->active_player]->gameStage = CHOOSE_PROVINCE_STAGE;
+                this->players[this->active_player]->is_active = true;
+            }else{
+                this->active_player = 1;
+                this->players[this->active_player]->gameStage = REINFORCEMENT_STAGE;
+                this->players[this->active_player]->is_active = true;
+            }
+            break;
+        }
+        case REINFORCEMENT_STAGE:{
+            
+        }
+        case ATTACK_STAGE:{
+            
+        }
+        case MOVE_STAGE:{
+            
+        }
+    }
+}
+
+
+
+
 //Creates and links all needed classes
-void Wagnis::createGame(){\
-    orxout() << "Game creation started";
+void Wagnis::createGame(){
+    orxout() << "Game creation started" << endl;
 
     if(!findGameBoard()){
-        orxout() << "Error: GameBoard not found";
+        orxout() << "Error: GameBoard not found" << endl;
     }
 
-    this->gameBoard->initializeNeighbors();
-    orxout() << "Game creation finished";
+    //this->gameBoard->initializeNeighbors();
+
+    //for(WagnisPlayer* p: this->players){
+        //this->playerEntered(p);
+    //}
+    
+    orxout() << "Game creation finished" << endl;
 }
 
 //Finds the pointer to the gameBoard
@@ -53,7 +115,7 @@
 bool Wagnis::findGameBoard(){
     for (WagnisGameboard* gb : ObjectList<WagnisGameboard>()){
         this->gameBoard = gb;
-        orxout()<<"Gameboard pointer found and added";
+        orxout()<<"Gameboard pointer found and added"<<endl;
         return true;
     }
     return false;

Modified: code/branches/wagnis_HS18/src/modules/wagnis/Wagnis.h
===================================================================
--- code/branches/wagnis_HS18/src/modules/wagnis/Wagnis.h	2018-11-28 11:53:04 UTC (rev 12129)
+++ code/branches/wagnis_HS18/src/modules/wagnis/Wagnis.h	2018-11-28 22:17:41 UTC (rev 12130)
@@ -37,6 +37,7 @@
         virtual ~Wagnis();
         void start();
         void tick(float);
+        void playerFinishedStage(WagnisPlayer*);
 
 
 
@@ -43,6 +44,7 @@
         WagnisGameboard* gameBoard;
 
         private:
+        int active_player;
         GameStage gameStage;
         std::vector<WagnisPlayer*> players;
         void createGame();

Modified: code/branches/wagnis_HS18/src/modules/wagnis/WagnisGameboard.cc
===================================================================
--- code/branches/wagnis_HS18/src/modules/wagnis/WagnisGameboard.cc	2018-11-28 11:53:04 UTC (rev 12129)
+++ code/branches/wagnis_HS18/src/modules/wagnis/WagnisGameboard.cc	2018-11-28 22:17:41 UTC (rev 12130)
@@ -11,13 +11,10 @@
     
     WagnisGameboard::WagnisGameboard(Context* context) : StaticEntity(context){
         RegisterObject(WagnisGameboard);
+        this->connections_string = "";
     }
+    WagnisGameboard::~WagnisGameboard(){}
 
-    WagnisGameboard::~WagnisGameboard(){
-        for(WagnisProvince* prov:this->provs){
-            prov->destroy();
-        }
-    }
     void WagnisGameboard::XMLPort(Element& xmlelement,XMLPort::Mode mode){
         SUPER(WagnisGameboard, XMLPort, xmlelement, mode);
 
@@ -62,6 +59,7 @@
     //Parses the string and initializes the neigbors vector of all provinces according
     //Syntax: 32=7-8-4  , 2=33+5+7+1+4
     void WagnisGameboard::initializeNeighbors(){
+        
         std::string str = this->connections_string;
         orxout() << "inizializing started" << endl;
         orxout() << "String size:" << endl;
@@ -68,10 +66,9 @@
         orxout() << str.size() << endl;
         unsigned int n = 0;
         while(n < str.size()){
-            orxout() << "test1" << endl;
             int tmp = parse_int(str,n);
-            n = tmp | 0x0000FFFF;
-            int origin_ID = tmp / (2<<16);
+            n = tmp & 0x0000FFFF;
+            int origin_ID = tmp >> 16;
             if(n == str.size() || str[n] != '='){
                 orxout() << "Error while parsing neighbors-string: '=' expected at position: "<< n << endl;
                 orxout() << "Correct syntax: 32=4+2+5+67, 54=8+1+12" << endl;
@@ -80,8 +77,8 @@
             do{
                 n++;
                 tmp = parse_int(str,n);
-                n = tmp | 0x0000FFFF;
-                other_ID = tmp / (2<<16);
+                n = tmp & 0x0000FFFF;
+                other_ID = tmp >> 16;
 
                 for(WagnisProvince* orig:this->provs){
                     if(orig->getID() == origin_ID){
@@ -95,9 +92,9 @@
                     }
                     break;
                 }
-            }while(n < str.size() && str[n] == '+');
+            }while((n < str.size()) && (str[n] == '+'));
             if(n == str.size()) return;
-            while(n < str.size() && str[n] == ' ') n++;
+            while((n < str.size()) && (str[n] == ' ')) n++;
             if(n == str.size()) return;
             if(str[n] != ','){
                 orxout() << "Error while parsing neighbors-string: ',' expected at position: "<< n << endl;

Modified: code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.cc
===================================================================
--- code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.cc	2018-11-28 11:53:04 UTC (rev 12129)
+++ code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.cc	2018-11-28 22:17:41 UTC (rev 12130)
@@ -29,6 +29,17 @@
     void WagnisPlayer::tick(float dt){
         SUPER(WagnisPlayer, tick, dt);
 
+        ///////////TEST//////////////
+        /**
+        if(this->is_active){
+            (master ->* ((orxonox::WagnisPlayer*)this)->orxonox::WagnisPlayer::finishedStageCallback) (this);
+        }
+
+        **/
+        ///////////TEST//////////////
+
+
+
         if(this->is_active)
         {
             for(WagnisProvince* prov:this->gameBoard->provs){
@@ -44,10 +55,10 @@
             }
 
             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 && this->target_province != nullptr && ((gameStage == CHOOSE_PROVINCE_STAGE)||(gameStage == REINFORCEMENT_STAGE)))){
                 
                 this->province_selection_changed = false;
-                switch(gamestage){
+                switch(gameStage){
                     case CHOOSE_PROVINCE_STAGE: 
                     {   
                         if (checkMove(SET_TROOPS_INITIAL))
@@ -106,6 +117,8 @@
                         }
                         break;
                     }
+
+                    default: break;
                 }
             }
         }

Modified: code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.h
===================================================================
--- code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.h	2018-11-28 11:53:04 UTC (rev 12129)
+++ code/branches/wagnis_HS18/src/modules/wagnis/WagnisPlayer.h	2018-11-28 22:17:41 UTC (rev 12130)
@@ -38,7 +38,9 @@
 
 
 
-        GameStage gamestage;
+        //void (Wagnis::*finishedStageCallback) (WagnisPlayer*);
+        Wagnis* master;
+        GameStage gameStage;
         bool province_selection_changed;
         bool is_active;
         int Player_ID;



More information about the Orxonox-commit mailing list