Changeset 6695 for code/branches/ai/src/orxonox/controllers
- Timestamp:
- Apr 12, 2010, 4:18:12 PM (15 years ago)
- Location:
- code/branches/ai/src/orxonox/controllers
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ai/src/orxonox/controllers/AIController.cc
r6683 r6695 50 50 { 51 51 if (this->state_ == MASTER) freeAllSlaves(); 52 if (this->state_ == SLAVE) unregisterSlave(); 53 this->slaves.clear(); 52 54 } 53 55 … … 60 62 { 61 63 64 //this->state_ = MASTER; 62 65 // search master 63 random = rnd(maxrand);64 if (random < 50&& (!this->target_))66 //random = rnd(maxrand); 67 //if (random < 101 && (!this->target_)) 65 68 this->searchNewMaster(); 66 67 68 69 69 70 } … … 78 79 // command slaves 79 80 this->commandSlaves(); 81 80 82 // search enemy 81 83 random = rnd(maxrand); … … 130 132 this->aimAtTarget(); 131 133 132 /*if (this->bHasTargetPosition_)134 if (this->bHasTargetPosition_) 133 135 this->moveToTargetPosition(); 134 */ 136 135 137 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f)) 136 138 this->getControllableEntity()->fire(0); 137 139 } 138 140 139 if (this->state_ ==SLAVE)141 if (this->state_ == SLAVE) 140 142 { 141 143 -
code/branches/ai/src/orxonox/controllers/ArtificialController.cc
r6683 r6695 44 44 45 45 this->target_ = 0; 46 this->myMaster_ = 0; 47 //this->slaveNumber_ = -1; 46 48 this->team_ = -1;//new 47 49 this->state_ = FREE;//new … … 95 97 } 96 98 99 void ArtificialController::unregisterSlave() { 100 if(myMaster_) 101 { 102 myMaster_->slaves.remove(this); 103 } 104 } 105 97 106 void ArtificialController::searchNewMaster() 98 107 { 108 99 109 if (!this->getControllableEntity()) 100 110 return; … … 106 116 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 107 117 { 108 //same team? no: continue 118 119 //same team? 109 120 if (!ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype())) 110 121 continue; 111 122 112 //has it an ArtificialController and is it a master? no: continue 123 //has it an ArtificialController and is it a master? 124 if (!it->getController()) 125 continue; 113 126 114 127 ArtificialController *controller = static_cast<ArtificialController*>(it->getController()); 115 if ( controller &&controller->getState() != MASTER)128 if (!controller || controller->getState() != MASTER) 116 129 continue; 117 130 118 131 //is pawn oneself? && is pawn in range? 119 if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity() /*&& it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) < 1000 */)132 if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity()) //&& it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) < 1000 120 133 { 121 //this->target_ = (*it);122 //this->targetPosition_ = it->getPosition();123 134 this->state_ = SLAVE; 124 135 this->myMaster_ = controller; 136 controller->slaves.push_back(this); 137 break; 125 138 } 126 139 }//for 127 140 128 141 //hasn't encountered any masters in range? -> become a master 129 if (state_!=SLAVE) state_=MASTER; // keep in mind: what happens when two masters encounter eache other? -> has to be evaluated in the for loop of within master mode in AIcontroller... 142 if (state_!=SLAVE) state_ = MASTER; // keep in mind: what happens when two masters encounter eache other? -> has to be evaluated in the for loop within master mode in AIcontroller... 143 130 144 } 131 145 132 146 void ArtificialController::commandSlaves() { 133 147 148 for(std::list<ArtificialController*>::iterator it = slaves.begin(); it != slaves.end(); it++) 149 { 150 (*it)->setTargetPosition(this->getControllableEntity()->getPosition()); 151 } 152 /* 134 153 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 135 154 { 155 156 if (!it->getController()) 157 continue; 158 136 159 ArtificialController *controller = static_cast<ArtificialController*>(it->getController()); 137 if ( controller && controller->getState() != MASTER)138 continue; 139 160 if (!controller || controller->getState() != SLAVE) 161 continue; 162 //controller->setTargetPosition(this->getControllableEntity()->getPosition()); 140 163 controller->targetPosition_ = this->getControllableEntity()->getPosition(); 141 } 142 164 controller->bHasTargetPosition_ = true; 165 } 166 */ 143 167 } 144 168 145 169 void ArtificialController::freeAllSlaves() 146 170 { 171 147 172 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 148 173 { 149 174 ArtificialController *controller = static_cast<ArtificialController*>(it->getController()); 150 if (controller && controller->getState() != MASTER)175 if (controller && controller->getState() != SLAVE) 151 176 continue; 152 177 -
code/branches/ai/src/orxonox/controllers/ArtificialController.h
r6683 r6695 61 61 enum State {SLAVE, MASTER, FREE}; 62 62 int getState(); 63 std::list<ArtificialController*> slaves; 64 void unregisterSlave(); 63 65 void searchNewMaster(); 64 66 void commandSlaves(); 65 67 void freeAllSlaves(); 68 69 ArtificialController *myMaster_; 66 70 67 71 void setTargetPosition(const Vector3& target);
Note: See TracChangeset
for help on using the changeset viewer.