Changeset 9459 for code/branches/Racingbot/src/modules/gametypes
- Timestamp:
- Nov 19, 2012, 4:19:27 PM (12 years ago)
- Location:
- code/branches/Racingbot/src/modules/gametypes
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/Racingbot/src/modules/gametypes/SpaceRaceBot.cc
r9432 r9459 1 1 /* 2 * SpaceRAceBot.cc 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 3 4 * 4 * Created on: 05.11.2012 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Created on: Oct 8, 2012 5 23 * Author: purgham 6 24 */ -
code/branches/Racingbot/src/modules/gametypes/SpaceRaceBot.h
r9432 r9459 1 1 /* 2 * SpaceRaceBot.h 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 3 4 * 4 * Created on: 05.11.2012 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Created on: Oct 8, 2012 5 23 * Author: purgham 6 24 */ -
code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.cc
r9451 r9459 23 23 * Author: purgham 24 24 */ 25 /** 26 * Conventions: 27 * -first Checkpoint has index 0 28 * 29 */ 25 26 /** 27 * Conventions: 28 * -first Checkpoint has index 0 29 * -staticCheckPoint= static Point (see def over = constructor) 30 */ 31 32 33 /*TODO: 34 * tICK KORRIGIEREN 35 * 36 * 37 */ 30 38 #include <gametypes/SpaceRaceController.h> 31 39 #include "core/CoreIncludes.h" … … 33 41 #include "gametypes/SpaceRaceManager.h" 34 42 35 36 37 38 43 namespace orxonox 39 44 { 40 45 CreateFactory(SpaceRaceController); 41 46 47 const int AdjustDistance = 500; 42 48 /* 43 49 * Idea: Find static Point (checkpoints the spaceship has to reach) … … 46 52 ArtificialController(creator) 47 53 { 48 RegisterObject(SpaceRaceController) ;49 std::vector<RaceCheckPoint*> checkpoints;54 RegisterObject(SpaceRaceController) 55 ; std::vector<RaceCheckPoint*> checkpoints; 50 56 for (ObjectList<SpaceRaceManager>::iterator it = ObjectList<SpaceRaceManager>::begin(); it!= ObjectList<SpaceRaceManager>::end(); ++it) 51 57 { 52 58 checkpoints = it->getAllCheckpoints(); 53 nextRaceCheckpoint_=it->findCheckpoint( 1);59 nextRaceCheckpoint_=it->findCheckpoint(0); 54 60 } 55 61 … … 59 65 // initialisation of currentRaceCheckpoint_ 60 66 currentRaceCheckpoint_ = NULL; 61 // find first Checkpoint 62 for (int i=0; true; i++){ 63 if(checkpoints_[i]->getCheckpointIndex()==0){ 64 nextRaceCheckpoint_=checkpoints_[i]; 65 break; 66 } 67 } 68 69 } 70 71 int SpaceRaceController::distanceSpaceshipToCheckPoint(RaceCheckPoint* CheckPoint) 72 { 73 if (this->getControllableEntity() != NULL) 74 { 75 return (CheckPoint->getPosition()- this->getControllableEntity()->getPosition()).length(); 76 } 77 return -1; 78 } 79 80 RaceCheckPoint* SpaceRaceController::nextPointFind(RaceCheckPoint* raceCheckpoint) 81 { 82 int distances[] ={ -1, -1, -1}; 83 int temp_i = 0; 84 for (std::set<int>::iterator it =raceCheckpoint->getNextCheckpoints().begin(); it!= raceCheckpoint->getNextCheckpoints().end(); ++it) 85 { 86 distances[temp_i] = recCalculateDistance(raceCheckpoint, this->getControllableEntity()->getPosition()); 87 temp_i++; 88 } 89 if (distances[0] > distances[1] && distances[1] != -1) 90 { 91 if (distances[2] < distances[1] && distances[2] != -1) 92 { 93 return checkpoints_[*raceCheckpoint->getNextCheckpoints().end()]; // return [2] 94 } 95 else 96 { 97 std::set<int>::iterator temp = raceCheckpoint->getNextCheckpoints().begin(); 98 return checkpoints_[*(++temp)]; 99 } 100 } 101 else 102 { 103 if (distances[2] < distances[0] && distances[2] != -1) 104 { 105 return checkpoints_[*raceCheckpoint->getNextCheckpoints().end()]; // return [2] 106 } 107 else 108 { 109 return checkpoints_[*raceCheckpoint->getNextCheckpoints().begin()]; // return [2] 110 } 111 } 112 } 113 114 RaceCheckPoint* SpaceRaceController::adjustNextPoint() 115 { 116 if (currentRaceCheckpoint_ == NULL) // no Adjust possible 117 118 { 119 return nextRaceCheckpoint_; 120 } 121 if ((currentRaceCheckpoint_->getNextCheckpoints()).size() == 1) // no Adjust possible 122 123 { 124 return nextRaceCheckpoint_; 125 } 126 127 //Adjust possible 128 129 return nextPointFind(currentRaceCheckpoint_); 130 } 131 132 int SpaceRaceController::recCalculateDistance(RaceCheckPoint* currentCheckPoint, Vector3 currentPosition) 133 { 134 orxout()<< "rec Aufruf" << endl; 135 // if ( staticCheckPoint was reached) 136 if (std::find(staticRacePoints_.begin(), staticRacePoints_.end(),currentCheckPoint) != staticRacePoints_.end()) 137 { 138 return (currentCheckPoint->getPosition() - currentPosition).length(); 139 } 140 else 141 { 142 int minimum = std::numeric_limits<int>::max(); 143 int temp=0; 144 for (std::set<int>::iterator it = currentCheckPoint->getNextCheckpoints().begin(); it!= currentCheckPoint->getNextCheckpoints().end(); ++it) 145 { //temp++; 146 WorldEntity* ttt= dynamic_cast<WorldEntity*> (currentCheckPoint); 147 OrxAssert(!(ttt==NULL), "WorldEntity null"); 148 OrxAssert(!(ttt->getNode()==NULL), "Node of WorldEntity is null"); 149 150 //orxout()<< temp <<endl; 151 //if(temp==1){orxout()<<currentCheckPoint << " == null? => "<<(currentCheckPoint==NULL)<<currentPosition<<endl;} 152 Vector3 t=(currentPosition- ttt->getPosition()); //TODO: Find Crash Reason. Why can't currentCheck access node. 153 int tt=static_cast<int>(t.length()); 154 //OrxAssert(!currentCheckPoint.empty(), "currentCheckPoint == null"); 155 //OrxAssert(!(it == currentCheckPoint->getNextCheckpoints().end()), "it is null"); 156 minimum= std::min(minimum, tt+ recCalculateDistance(checkpoints_[(*it)], currentCheckPoint->getPosition())); 157 // minimum of distanz from 'currentPosition' to the next static Checkpoint 158 }//Error tritt manchmal auf 159 return minimum; 160 } 161 } 162 163 /* 67 /* 68 // find first Checkpoint 69 for (int i=0; true; i++){ 70 if(checkpoints_[i]->getCheckpointIndex()==0){ 71 nextRaceCheckpoint_=checkpoints_[i]; 72 break; 73 } 74 }*/ 75 76 virtualCheckPointIndex=-1; 77 } 78 79 80 //------------------------------ 81 // functions for initialisation 82 83 void SpaceRaceController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 84 { 85 SUPER(SpaceRaceController, XMLPort, xmlelement, mode); 86 XMLPortParam(ArtificialController, "accuracy", setAccuracy, getAccuracy, xmlelement, mode).defaultValues(100.0f); 87 XMLPortObject(ArtificialController, WorldEntity, "waypoints", addWaypoint, getWaypoint, xmlelement, mode); 88 89 } 90 91 /* 92 * called from constructor 'SpaceRaceController' 164 93 * returns a vector of static Point (checkpoints the spaceship has to reach) 165 94 */ … … 190 119 191 120 /* 192 * 193 * return how many ways go from the given checkpoint to the last one121 * called from 'findStaticCheckpoints' 122 * return how many ways go from the given Checkpoint to the last Checkpoint (of the Game) 194 123 */ 195 124 int SpaceRaceController::rekSimulationCheckpointsReached(RaceCheckPoint* currentCheckpoint, std::vector<RaceCheckPoint*>* checkpoints, std::map<RaceCheckPoint*, int>* zaehler) … … 203 132 { 204 133 int numberOfWays = 0; // counts number of ways from this Point to the last point 205 for (std::set<int>::iterator it = 134 for (std::set<int>::iterator it =lastPositionSpaceship=this->getControllableEntity()->getPosition(); 206 135 currentCheckpoint->getNextCheckpoints().begin(); it 207 136 != currentCheckpoint->getNextCheckpoints().end(); ++it) … … 214 143 } 215 144 145 146 147 //------------------------------------- 148 // functions for dynamic Way-search 149 150 int SpaceRaceController::distanceSpaceshipToCheckPoint(RaceCheckPoint* CheckPoint) 151 { 152 if (this->getControllableEntity() != NULL) 153 { 154 return (CheckPoint->getPosition()- this->getControllableEntity()->getPosition()).length(); 155 } 156 return -1; 157 } 158 159 /* 160 * called by: 'tick' or 'adjustNextPoint' 161 * returns the next Checkpoint which the shortest way contains 162 */ 163 RaceCheckPoint* SpaceRaceController::nextPointFind(RaceCheckPoint* raceCheckpoint) 164 { 165 int distances[] = { -1, -1, -1}; 166 int temp_i = 0; 167 for (std::set<int>::iterator it =raceCheckpoint->getNextCheckpoints().begin(); it!= raceCheckpoint->getNextCheckpoints().end(); ++it) 168 { 169 distances[temp_i] = recCalculateDistance(findCheckpoint(*it), this->getControllableEntity()->getPosition()); 170 temp_i++; 171 } 172 if (distances[0] > distances[1] && distances[1] != -1) 173 { 174 if (distances[2] < distances[1] && distances[2] != -1) 175 { 176 return findCheckpoint(*raceCheckpoint->getNextCheckpoints().end()); // return checkpoint with ID of raceCheckpoint->getNextCheckpoints() [2] 177 } 178 else 179 { 180 std::set<int>::iterator temp = raceCheckpoint->getNextCheckpoints().begin(); 181 return findCheckpoint(*(++temp)); // return [1] 182 } 183 } 184 else 185 { 186 if (distances[2] < distances[0] && distances[2] != -1) 187 { 188 return findCheckpoint(*raceCheckpoint->getNextCheckpoints().end()); // return [2] 189 } 190 else 191 { 192 return findCheckpoint(*raceCheckpoint->getNextCheckpoints().begin()); // return [0] 193 } 194 } 195 } 196 197 /* 198 * called from 'nextPointFind' 199 * returns the distance between "currentPosition" and the next static checkpoint that can be reached from "currentCheckPoint" 200 */ 201 int SpaceRaceController::recCalculateDistance(RaceCheckPoint* currentCheckPoint, Vector3 currentPosition) 202 { 203 // find: looks if the currentCheckPoint is a staticCheckPoint (staticCheckPoint is the same as: static Point) 204 if (std::find(staticRacePoints_.begin(), staticRacePoints_.end(), currentCheckPoint) != staticRacePoints_.end()) 205 { 206 return (currentCheckPoint->getPosition() - currentPosition).length(); 207 } 208 else 209 { 210 int minimum = std::numeric_limits<int>::max(); 211 for (std::set<int>::iterator it = currentCheckPoint->getNextCheckpoints().begin(); it!= currentCheckPoint->getNextCheckpoints().end(); ++it) 212 { 213 int dist_currentCheckPoint_currentPosition = static_cast<int> ((currentPosition- currentCheckPoint->getPosition()).length()); 214 215 minimum= std::min(minimum, dist_currentCheckPoint_currentPosition + recCalculateDistance(findCheckpoint(*it), currentCheckPoint->getPosition())); 216 // minimum of distanz from 'currentPosition' to the next static Checkpoint 217 } 218 return minimum; 219 } 220 } 221 222 /*called by 'tick' 223 *adjust chosen way of the Spaceship every "AdjustDistance" because spaceship could be displaced through an other one 224 */ 225 RaceCheckPoint* SpaceRaceController::adjustNextPoint() 226 { 227 if (currentRaceCheckpoint_ == NULL) // no Adjust possible 228 229 { 230 return nextRaceCheckpoint_; 231 } 232 if ((currentRaceCheckpoint_->getNextCheckpoints()).size() == 1) // no Adjust possible 233 234 { 235 return nextRaceCheckpoint_; 236 } 237 238 //Adjust possible 239 240 return nextPointFind(currentRaceCheckpoint_); 241 } 242 243 RaceCheckPoint* SpaceRaceController::findCheckpoint(int index) const 244 { 245 for (size_t i = 0; i < this->checkpoints_.size(); ++i) 246 if (this->checkpoints_[i]->getCheckpointIndex() == index) 247 return this->checkpoints_[i]; 248 return NULL; 249 } 250 251 bool SpaceRaceController::addVirtualCheckPoint(int positionInNextCheckPoint, RaceCheckPoint* previousCheckpoint, int indexFollowingCheckPoint , Vector3 virtualCheckPointPosition ){ 252 253 RaceCheckPoint* newTempRaceCheckPoint = new RaceCheckPoint(this); 254 newTempRaceCheckPoint->setPosition(virtualCheckPointPosition); 255 newTempRaceCheckPoint->setCheckpointIndex(virtualCheckPointIndex); 256 newTempRaceCheckPoint->setLast(false); 257 newTempRaceCheckPoint->setNextCheckpointsAsVector3(Vector3(indexFollowingCheckPoint,-1,-1)); 258 259 Vector3 temp = previousCheckpoint->getNextCheckpointsAsVector3(); 260 checkpoints_.insert(checkpoints_.end(), newTempRaceCheckPoint); 261 switch(positionInNextCheckPoint){ 262 case 0: temp.x=virtualCheckPointIndex; break; 263 case 1: temp.y=virtualCheckPointIndex; break; 264 case 2: temp.z=virtualCheckPointIndex; break; 265 } 266 virtualCheckPointIndex--; 267 } 268 269 270 216 271 SpaceRaceController::~SpaceRaceController() 217 272 { 218 // TODO Auto-generated destructor stub 219 } 220 221 void SpaceRaceController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 222 { 223 SUPER(SpaceRaceController, XMLPort, xmlelement, mode); 224 XMLPortParam(ArtificialController, "accuracy", setAccuracy, getAccuracy, xmlelement, mode).defaultValues( 225 100.0f); 226 XMLPortObject(ArtificialController, WorldEntity, "waypoints", addWaypoint, getWaypoint, xmlelement, mode) 227 ; 228 229 } 273 for (int i =-1; i>virtualCheckPointIndex ; i--){ 274 delete findCheckpoint(i); 275 } 276 } 277 230 278 void SpaceRaceController::tick(float dt) 231 279 { 232 if (this->getControllableEntity() == NULL || this->getControllableEntity()->getPlayer() == NULL ){orxout()<<this->getControllableEntity()<< " in tick"<<endl; return;} 280 if (this->getControllableEntity() == NULL || this->getControllableEntity()->getPlayer() == NULL ) 281 { orxout()<<this->getControllableEntity()<< " in tick"<<endl; return;} 282 //FOR virtual Checkpoints 283 if(nextRaceCheckpoint_->getCheckpointIndex() < 0){ 284 if( distanceSpaceshipToCheckPoint(nextRaceCheckpoint_) < 30){ 285 currentRaceCheckpoint_=nextRaceCheckpoint_; 286 nextRaceCheckpoint_ = nextPointFind(nextRaceCheckpoint_); 287 lastPositionSpaceship=this->getControllableEntity()->getPosition(); 288 } 289 } 290 233 291 if (nextRaceCheckpoint_->playerWasHere(this->getControllableEntity()->getPlayer())) 234 292 {//Checkpoint erreicht … … 236 294 OrxAssert(nextRaceCheckpoint_, "next race checkpoint undefined"); 237 295 nextRaceCheckpoint_ = nextPointFind(nextRaceCheckpoint_); 238 } 239 else if (std::abs(lastDistance - distanceSpaceshipToCheckPoint(nextRaceCheckpoint_)) < 500) 296 lastPositionSpaceship=this->getControllableEntity()->getPosition(); 297 } 298 else if ((lastPositionSpaceship-this->getControllableEntity()->getPosition()).length()> AdjustDistance) 240 299 { 241 300 nextRaceCheckpoint_ = adjustNextPoint(); 301 lastPositionSpaceship=this->getControllableEntity()->getPosition(); 302 } 303 //korrigieren! 304 else if((lastPositionSpaceship-this->getControllableEntity()->getPosition()).length()<5){\ 305 this->moveToPosition(Vector3(rnd()*100,rnd()*100,rnd()*100)); 306 this->spin(); 242 307 } 243 308 this->moveToPosition(nextRaceCheckpoint_->getPosition()); 309 310 244 311 } 245 312 -
code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.h
r9441 r9459 43 43 RaceCheckPoint* currentRaceCheckpoint_; // last checkPoint (already reached) 44 44 std::vector<RaceCheckPoint*> checkpoints_; 45 int lastDistance; 45 Vector3 lastPositionSpaceship; 46 int virtualCheckPointIndex; 46 47 47 48 int recCalculateDistance(RaceCheckPoint*, Vector3 currentPosition); … … 52 53 std::vector<RaceCheckPoint*> staticCheckpoints(); 53 54 int rekSimulationCheckpointsReached(RaceCheckPoint* , std::vector<RaceCheckPoint*>* checkpoints, std::map< RaceCheckPoint*, int>*); 55 // same as SpaceRaceManager, but needed to add virtuell Checkpoints ( Checkpoints which don't exist but needed to avoid collisions with big Objects) 56 RaceCheckPoint* findCheckpoint(int index) const; 57 bool addVirtualCheckPoint(int , RaceCheckPoint* , int , Vector3 ); 54 58 55 59 public: -
code/branches/Racingbot/src/modules/gametypes/SpaceRaceManager.cc
r9436 r9459 166 166 // adjust the radarvisibility 167 167 gametype->newCheckpointReached(newCheckpoint, player); 168 this->updateRadarVisibility(oldCheckpoint, newCheckpoint); 168 if(player->isHumanPlayer()) 169 this->updateRadarVisibility(oldCheckpoint, newCheckpoint); 169 170 } 170 171 }
Note: See TracChangeset
for help on using the changeset viewer.