#include "Wagnis.h" namespace orxonox{ RegisterClass(Wagnis); //Constructor Wagnis::Wagnis(Context* context) : Deathmatch(context){ RegisterObject(Wagnis); this->gameBoard = nullptr; this->gameStage = NOT_READY; this->active_player = 1; this->initial_reinforcements_left = 5; this->empty_provinces_left = 0; int n = 3; for(int i = 0;i < n;i++){ WagnisPlayer* p = new WagnisPlayer(context); p->Player_ID = i+1; p->master = this; this->players.push_back(p); } } //Destructor Wagnis::~Wagnis(){} //Runs the game void Wagnis::start(){ Deathmatch::start(); if(this->gameStage == NOT_READY){ this->createGame(); for(WagnisPlayer* ptr: this->players){ ptr->gameBoard = this->gameBoard; } } this->gameStage = CHOOSE_PROVINCE_STAGE; this->empty_provinces_left = this->provinceCount(); this->players.at(0)->gameStage = this->gameStage; this->players.at(0)->setActive(true); this->players.at(0)->reinforcements = 0; orxout()<<"Player "<<1<<"\'s turn. Please choose province."<resetProvinceSelection(); if(this->active_player != player->Player_ID){ orxout()<<"shit happend. This player should not be activ. Wagnis::playerFinishedStage was called from wrong player"<gameStage){ case CHOOSE_PROVINCE_STAGE:{ player->setActive(false); this->empty_provinces_left -= 1; if(this->empty_provinces_left > 0){ //Still empty provinces left orxout()<<"DEBUG: Empty provs: "<empty_provinces_left<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->setActive(true); next->reinforcements = 0; orxout()<<"Player "<Player_ID<<"\'s turn. Please choose province."<empty_provinces_left<active_player = 1; WagnisPlayer* next = this->players[this->active_player - 1]; next->gameStage = REINFORCEMENT_STAGE; this->gameStage = REINFORCEMENT_STAGE; next->setActive(true); next->reinforcements = 1; orxout()<<"Player "<Player_ID<<"\'s turn. Reinforcement."<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; player->reinforcements = provincesOfPlayerCounter(player->Player_ID); orxout()<<"Player "<Player_ID<<"\'s turn. Attack."<gameStage = MOVE_STAGE; this->gameStage = MOVE_STAGE; orxout()<<"Player "<Player_ID<<"\'s turn. Move."<setActive(false); if(this->active_player < this->players.size()){ this->active_player++; }else{ this->active_player = 1; } WagnisPlayer* next = this->players[this->active_player - 1]; orxout()<<"Player "<Player_ID<<"\'s turn. Reinforcement."<gameStage = REINFORCEMENT_STAGE; this->gameStage = REINFORCEMENT_STAGE; next->setActive(true); break; } default:{} } } //Creates and links all needed classes void Wagnis::createGame(){ orxout() << "Game creation started" << endl; if(!findGameBoard()){ orxout() << "Error: GameBoard not found" << endl; } this->gameBoard->initializeNeighbors(); orxout() << "Game creation finished" << endl; } //Finds the pointer to the gameBoard bool Wagnis::findGameBoard(){ for (WagnisGameboard* gb : ObjectList()){ this->gameBoard = gb; orxout()<<"Gameboard pointer found and added"<gameBoard->provs){ if(p != nullptr){ if(p->ID < 1000){ n++; } }else{ orxout()<<"Nullpointer found in provinces!!!"<gameBoard->provs){ if(p != nullptr){ if(p->getOwner_ID() == player){ n++; } }else{ orxout()<<"Nullpointer found in provinces!!!"<