Changeset 12072
- Timestamp:
- Nov 3, 2018, 11:49:55 PM (6 years ago)
- Location:
- code/branches/wagnis_HS18
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/wagnis_HS18/data/levels/Wagnis.oxw
r12067 r12072 48 48 <SpawnPoint position="100, 45, 75" lookat="0, 45, 75" /> 49 49 50 <WagnisGameboard position="0,0,0"> 51 <Provinces> 50 <WagnisGameboard position="0,0,0" connections_string="1=2,2=1-1000,1000=2 "> 51 52 <Provinces> 53 52 54 <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)?>"> 53 55 <attached> … … 62 64 </WagnisProvince> 63 65 64 65 66 66 <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)?>"> 67 <attached> 68 <Model position="0,0,0" mesh="ast1.mesh" scale3D="2,2,2" /> 69 </attached> 70 </WagnisProvince> 67 71 68 72 </Provinces> -
code/branches/wagnis_HS18/src/modules/wagnis/Wagnis.h
r12068 r12072 2 2 #include "WagnisProvince.h" 3 3 4 // todo: klassen zusammenfassen 4 /** Die Wagnis Klasse hat die folgenden Aufgaben: 5 * 1. Das Spiel erstellen. 6 * - Gameboard initialisieren 7 * - Provinzen initialisieren 8 * - Provinzen verbinden (Nachbarschaften eintragen) 9 * - Spieler initialisieren 10 * - 11 * 12 * 2. Den Spielablauf steuern 13 * - Für einen Spieler berechnen wie viele Truppen er setzen darf. 14 * - Den Funktion "setTroops(int troops)" beim Spieler aufrufen. 15 * - Die Funktion "playerTurn()" bei jedem Spieler aufrufen. 16 * - 17 * 18 **/ 5 19 6 20 namespace orxonox … … 11 25 12 26 // to start the game 13 void createGame; // creates and links provinces 27 void createGame(); // creates and links provinces 28 14 29 15 void setPlayers; // initialises players 16 void chooseProvinces // players can choose their provinces 17 18 19 void playerTurn // each players turn 20 21 void setTroops; // get and set your reinforcements 22 void attack; // attack neighbouring provinces 23 void moveTroops; // move troops from one province to another 24 25 // additional checking funtions 26 int troopCounter; // counts how many reinforcements player gets 27 bool attackChecker; // checks whether an attack move is valid 30 // additional checking funtions 31 int troopCounter(int); // counts how many reinforcements player gets 32 bool attackChecker; // checks whether an attack move is valid 28 33 // (provinces linked, enough troops, no own province) 29 34 bool moveChecker; // checks whether a troop movement is valid 30 35 // (start and target belong to player, link existing) 31 36 void attackSimulator; // calculates outcome of battle 32 37 33 38 34 private:35 36 int owner_ID;37 int troops;38 int ID;39 int continent;40 39 } 41 40 -
code/branches/wagnis_HS18/src/modules/wagnis/WagnisGameboard.cc
r12067 r12072 3 3 #include "BulletDynamics/Dynamics/btRigidBody.h" 4 4 #include <vector> 5 #include <string> 5 6 6 7 … … 15 16 WagnisGameboard::~WagnisGameboard(){ 16 17 for(WagnisProvince* prov:this->provs){ 17 prov->destroy(); //destroys all Provinces18 prov->destroy(); 18 19 } 20 } 21 void WagnisGameboard::XMLPort(Element& xmlelement,XMLPort::Mode mode){ 22 SUPER(WagnisGameboard, XMLPort, xmlelement, mode); 23 24 XMLPortObject(WagnisGameboard, WagnisProvince, "Provinces", addProvince, getProvince, xmlelement, mode); 25 XMLPortParam(WagnisGameboard, "connections_string", setConnections_string, getConnections_string, xmlelement, mode); 19 26 } 20 27 21 28 22 29 23 //XML Port24 void WagnisGameboard::XMLPort(Element& xmlelement,XMLPort::Mode mode){25 SUPER(WagnisGameboard, XMLPort, xmlelement, mode);26 30 27 XMLPortObject(WagnisGameboard, WagnisProvince, "Provinces", addProvince, getProvince, xmlelement, mode); 28 } 29 //XML add province 31 32 33 34 //XML FUNCTIONS 30 35 //Adds a Province to the Gameboard 31 36 void WagnisGameboard::addProvince(WagnisProvince* province){ … … 33 38 orxout() << province->getID() << endl; 34 39 this->provs.push_back(province); 40 41 if(province->getID() == 1000){ 42 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; 43 orxout() << "-----neighbors-----" << endl << endl; 44 initializeNeighbors(this->connections_string); 45 } 35 46 } 36 47 //XML get province … … 39 50 return this->provs.at(index); 40 51 } 52 //XML set connections_string 53 void WagnisGameboard::setConnections_string(const std::string& str){ 54 this->connections_string = str; 55 } 56 //XML get connections_string 57 std::string WagnisGameboard::getConnections_string() const{ 58 return this -> connections_string; 59 } 60 61 62 63 64 65 66 67 //Parses the string and initializes the neigbors vector of all provinces according 68 //Syntax: 32=7-8-4 , 2=33-5-7-1-4 69 void WagnisGameboard::initializeNeighbors(std::string str){ 70 orxout() << "inizializing started" << endl; 71 orxout() << "String size:" << endl; 72 orxout() << str.size() << endl; 73 unsigned int n = 0; 74 while(n < str.size()){ 75 orxout() << "test1" << endl; 76 int tmp = parse_int(str,n); 77 n = tmp | 0x0000FFFF; 78 int origin_ID = tmp / (2<<16); 79 if(n == str.size() || str[n] != '='){ 80 orxout() << "Error while parsing neighbors-string: '=' expected at position: "<< n << endl; 81 orxout() << "Correct syntax: 32=4-2-5-67, 54=8-1-12" << endl; 82 } 83 int other_ID; 84 do{ 85 n++; 86 tmp = parse_int(str,n); 87 n = tmp | 0x0000FFFF; 88 other_ID = tmp / (2<<16); 89 90 for(WagnisProvince* orig:this->provs){ 91 if(orig->getID() == origin_ID){ 92 for(WagnisProvince* other:this->provs){ 93 if(other->getID() == other_ID){ 94 orig->addNeighbor(other); 95 orxout() << "Added neighbor province "<< other_ID << " to province " << origin_ID << endl; 96 break; 97 } 98 } 99 } 100 break; 101 } 102 }while(n < str.size() && str[n] == '-'); 103 if(n == str.size()) return; 104 while(n < str.size() && str[n] == ' ') n++; 105 if(n == str.size()) return; 106 if(str[n] != ','){ 107 orxout() << "Error while parsing neighbors-string: ',' expected at position: "<< n << endl; 108 orxout() << "Correct syntax: 32=4-2-5-67, 54=8-1-12" << endl; 109 } 110 n++; 111 while(n < str.size() && str[n] == ' ') n++; 112 } 113 } 114 115 //Returns the parsed int and the offset encoded in an int. the upper 16bit(incl MSB) is the number 116 //and the lower 16 bits is the new n(after the last digit) 117 int WagnisGameboard::parse_int(std::string str,unsigned int n){ 118 if(n >= str.size()){ 119 orxout() << "Error while parsing neighbors-string: Internal error at WagnisGameboard::parse_int() "<< endl; 120 } 121 int digit = str[n] - '0'; 122 int number = digit; 123 if(digit < 0 || digit > 9){ 124 orxout() << "Error while parsing neighbors-string: Digit expected at position: "<< n << endl; 125 orxout() << "Correct syntax: 32=4-2-5-67, 54=8-1-12" << endl; 126 } 127 128 n++; 129 while(n < str.size() && str[n] - '0' >= 0 && str[n] - '0' < 10){ 130 digit = str[n] - '0'; 131 number = 10 * number; 132 number += digit; 133 n++; 134 } 135 return (number << 16)+n; 136 } 41 137 } -
code/branches/wagnis_HS18/src/modules/wagnis/WagnisGameboard.h
r12051 r12072 15 15 #include "core/XMLPort.h" 16 16 #include "worldentities/StaticEntity.h" 17 #include <string> 17 18 #include <vector> 18 19 … … 30 31 void addProvince(WagnisProvince*); 31 32 WagnisProvince* getProvince(unsigned int) const; 33 void setConnections_string(const std::string&); 34 std::string getConnections_string() const; 32 35 // 36 37 void initializeNeighbors(std::string); 33 38 34 39 35 40 private: 36 41 std::vector<WagnisProvince*> provs; 42 std::string connections_string; 43 int parse_int(std::string,unsigned int); 37 44 }; 38 45 } -
code/branches/wagnis_HS18/src/modules/wagnis/WagnisProvince.cc
r12067 r12072 72 72 } 73 73 74 // Creates a connection between two provinces.74 //Adds a connection to neighbors. 75 75 void WagnisProvince::addNeighbor(WagnisProvince* prov){ 76 76 neighbors.push_back(prov); 77 prov->neighbors.push_back(this);78 77 } 79 78 }
Note: See TracChangeset
for help on using the changeset viewer.