[Orxonox-commit 7466] r12072 - in code/branches/wagnis_HS18: data/levels src/modules/wagnis
stadlero at orxonox.net
stadlero at orxonox.net
Sat Nov 3 23:49:55 CET 2018
Author: stadlero
Date: 2018-11-03 23:49:55 +0100 (Sat, 03 Nov 2018)
New Revision: 12072
Modified:
code/branches/wagnis_HS18/data/levels/Wagnis.oxw
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/WagnisGameboard.h
code/branches/wagnis_HS18/src/modules/wagnis/WagnisProvince.cc
Log:
Added connections-string parser in WagnisGameboard which still needs work
Modified: code/branches/wagnis_HS18/data/levels/Wagnis.oxw
===================================================================
--- code/branches/wagnis_HS18/data/levels/Wagnis.oxw 2018-10-31 10:49:41 UTC (rev 12071)
+++ code/branches/wagnis_HS18/data/levels/Wagnis.oxw 2018-11-03 22:49:55 UTC (rev 12072)
@@ -47,8 +47,10 @@
<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" />
-<WagnisGameboard position="0,0,0">
- <Provinces>
+<WagnisGameboard position="0,0,0" connections_string="1=2,2=1-1000,1000=2 ">
+
+ <Provinces>
+
<WagnisProvince ID="1" continent="1" position="0,30,30" rotationrate="<?lua print(math.random() * 50) ?>" rotationaxis="<?lua print((math.random()-1)*5)?>,<?lua print((math.random()-1)*5)?>,<?lua print((math.random()-1)*5)?>">
<attached>
<Model position="0,0,0" mesh="ast1.mesh" scale3D="2,2,2" />
@@ -61,10 +63,12 @@
</attached>
</WagnisProvince>
+ <WagnisProvince ID="1000" continent="1" position="0,40,40" rotationrate="<?lua print(math.random() * 50) ?>" rotationaxis="<?lua print((math.random()-1)*5)?>,<?lua print((math.random()-1)*5)?>,<?lua print((math.random()-1)*5)?>">
+ <attached>
+ <Model position="0,0,0" mesh="ast1.mesh" scale3D="2,2,2" />
+ </attached>
+ </WagnisProvince>
-
-
-
</Provinces>
</WagnisGameboard>
Modified: code/branches/wagnis_HS18/src/modules/wagnis/Wagnis.h
===================================================================
--- code/branches/wagnis_HS18/src/modules/wagnis/Wagnis.h 2018-10-31 10:49:41 UTC (rev 12071)
+++ code/branches/wagnis_HS18/src/modules/wagnis/Wagnis.h 2018-11-03 22:49:55 UTC (rev 12072)
@@ -1,7 +1,21 @@
#include "WagnisGameboard.h"
#include "WagnisProvince.h"
-// todo: klassen zusammenfassen
+/** Die Wagnis Klasse hat die folgenden Aufgaben:
+ * 1. Das Spiel erstellen.
+ * - Gameboard initialisieren
+ * - Provinzen initialisieren
+ * - Provinzen verbinden (Nachbarschaften eintragen)
+ * - Spieler initialisieren
+ * -
+ *
+ * 2. Den Spielablauf steuern
+ * - Für einen Spieler berechnen wie viele Truppen er setzen darf.
+ * - Den Funktion "setTroops(int troops)" beim Spieler aufrufen.
+ * - Die Funktion "playerTurn()" bei jedem Spieler aufrufen.
+ * -
+ *
+ **/
namespace orxonox
{
@@ -10,33 +24,18 @@
public:
// to start the game
- void createGame; // creates and links provinces
-
- void setPlayers; // initialises players
- void chooseProvinces // players can choose their provinces
-
+ void createGame(); // creates and links provinces
- void playerTurn // each players turn
-
- void setTroops; // get and set your reinforcements
- void attack; // attack neighbouring provinces
- void moveTroops; // move troops from one province to another
- // additional checking funtions
- int troopCounter; // counts how many reinforcements player gets
- bool attackChecker; // checks whether an attack move is valid
+ // additional checking funtions
+ int troopCounter(int); // counts how many reinforcements player gets
+ bool attackChecker; // checks whether an attack move is valid
// (provinces linked, enough troops, no own province)
- bool moveChecker; // checks whether a troop movement is valid
+ bool moveChecker; // checks whether a troop movement is valid
// (start and target belong to player, link existing)
- void attackSimulator; // calculates outcome of battle
+ void attackSimulator; // calculates outcome of battle
- private:
-
- int owner_ID;
- int troops;
- int ID;
- int continent;
}
}
\ No newline at end of file
Modified: code/branches/wagnis_HS18/src/modules/wagnis/WagnisGameboard.cc
===================================================================
--- code/branches/wagnis_HS18/src/modules/wagnis/WagnisGameboard.cc 2018-10-31 10:49:41 UTC (rev 12071)
+++ code/branches/wagnis_HS18/src/modules/wagnis/WagnisGameboard.cc 2018-11-03 22:49:55 UTC (rev 12072)
@@ -2,6 +2,7 @@
#include "core/CoreIncludes.h"
#include "BulletDynamics/Dynamics/btRigidBody.h"
#include <vector>
+#include <string>
namespace orxonox
@@ -14,24 +15,34 @@
WagnisGameboard::~WagnisGameboard(){
for(WagnisProvince* prov:this->provs){
- prov->destroy(); //destroys all Provinces
+ prov->destroy();
}
}
-
-
-
- //XML Port
void WagnisGameboard::XMLPort(Element& xmlelement,XMLPort::Mode mode){
SUPER(WagnisGameboard, XMLPort, xmlelement, mode);
XMLPortObject(WagnisGameboard, WagnisProvince, "Provinces", addProvince, getProvince, xmlelement, mode);
+ XMLPortParam(WagnisGameboard, "connections_string", setConnections_string, getConnections_string, xmlelement, mode);
}
- //XML add province
+
+
+
+
+
+
+
+ //XML FUNCTIONS
//Adds a Province to the Gameboard
void WagnisGameboard::addProvince(WagnisProvince* province){
orxout() << "added" << endl;
orxout() << province->getID() << endl;
this->provs.push_back(province);
+
+ if(province->getID() == 1000){
+ orxout() << "You added a province with ID 1000.\nThis is the magic debug number.\nThe function to initialize the neighbors of all provinces will be called:" << endl;
+ orxout() << "-----neighbors-----" << endl << endl;
+ initializeNeighbors(this->connections_string);
+ }
}
//XML get province
WagnisProvince* WagnisGameboard::getProvince(unsigned int index) const{
@@ -38,4 +49,89 @@
if(this->provs.size() <= index) return nullptr;
return this->provs.at(index);
}
+ //XML set connections_string
+ void WagnisGameboard::setConnections_string(const std::string& str){
+ this->connections_string = str;
+ }
+ //XML get connections_string
+ std::string WagnisGameboard::getConnections_string() const{
+ return this -> connections_string;
+ }
+
+
+
+
+
+
+
+ //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){
+ orxout() << "inizializing started" << endl;
+ orxout() << "String size:" << endl;
+ 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);
+ 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;
+ }
+ int other_ID;
+ do{
+ n++;
+ tmp = parse_int(str,n);
+ n = tmp | 0x0000FFFF;
+ other_ID = tmp / (2<<16);
+
+ for(WagnisProvince* orig:this->provs){
+ if(orig->getID() == origin_ID){
+ for(WagnisProvince* other:this->provs){
+ if(other->getID() == other_ID){
+ orig->addNeighbor(other);
+ orxout() << "Added neighbor province "<< other_ID << " to province " << origin_ID << endl;
+ break;
+ }
+ }
+ }
+ break;
+ }
+ }while(n < str.size() && str[n] == '-');
+ if(n == str.size()) return;
+ 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;
+ orxout() << "Correct syntax: 32=4-2-5-67, 54=8-1-12" << endl;
+ }
+ n++;
+ while(n < str.size() && str[n] == ' ') n++;
+ }
+ }
+
+ //Returns the parsed int and the offset encoded in an int. the upper 16bit(incl MSB) is the number
+ //and the lower 16 bits is the new n(after the last digit)
+ int WagnisGameboard::parse_int(std::string str,unsigned int n){
+ if(n >= str.size()){
+ orxout() << "Error while parsing neighbors-string: Internal error at WagnisGameboard::parse_int() "<< endl;
+ }
+ int digit = str[n] - '0';
+ int number = digit;
+ if(digit < 0 || digit > 9){
+ orxout() << "Error while parsing neighbors-string: Digit expected at position: "<< n << endl;
+ orxout() << "Correct syntax: 32=4-2-5-67, 54=8-1-12" << endl;
+ }
+
+ n++;
+ while(n < str.size() && str[n] - '0' >= 0 && str[n] - '0' < 10){
+ digit = str[n] - '0';
+ number = 10 * number;
+ number += digit;
+ n++;
+ }
+ return (number << 16)+n;
+ }
}
\ No newline at end of file
Modified: code/branches/wagnis_HS18/src/modules/wagnis/WagnisGameboard.h
===================================================================
--- code/branches/wagnis_HS18/src/modules/wagnis/WagnisGameboard.h 2018-10-31 10:49:41 UTC (rev 12071)
+++ code/branches/wagnis_HS18/src/modules/wagnis/WagnisGameboard.h 2018-11-03 22:49:55 UTC (rev 12072)
@@ -14,6 +14,7 @@
#include "core/CoreIncludes.h"
#include "core/XMLPort.h"
#include "worldentities/StaticEntity.h"
+#include <string>
#include <vector>
@@ -29,11 +30,17 @@
virtual void XMLPort(Element&,XMLPort::Mode);
void addProvince(WagnisProvince*);
WagnisProvince* getProvince(unsigned int) const;
+ void setConnections_string(const std::string&);
+ std::string getConnections_string() const;
//
+ void initializeNeighbors(std::string);
+
private:
std::vector<WagnisProvince*> provs;
+ std::string connections_string;
+ int parse_int(std::string,unsigned int);
};
}
Modified: code/branches/wagnis_HS18/src/modules/wagnis/WagnisProvince.cc
===================================================================
--- code/branches/wagnis_HS18/src/modules/wagnis/WagnisProvince.cc 2018-10-31 10:49:41 UTC (rev 12071)
+++ code/branches/wagnis_HS18/src/modules/wagnis/WagnisProvince.cc 2018-11-03 22:49:55 UTC (rev 12072)
@@ -71,9 +71,8 @@
return this-> continent;
}
- //Creates a connection between two provinces.
+ //Adds a connection to neighbors.
void WagnisProvince::addNeighbor(WagnisProvince* prov){
neighbors.push_back(prov);
- prov->neighbors.push_back(this);
}
}
More information about the Orxonox-commit
mailing list