Changeset 6683 for code/branches/ai/src/orxonox/controllers
- Timestamp:
- Apr 12, 2010, 1:24:24 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
r6640 r6683 49 49 AIController::~AIController() 50 50 { 51 if (this->state_ == MASTER) freeAllSlaves(); 51 52 } 52 53 … … 56 57 float maxrand = 100.0f / ACTION_INTERVAL; 57 58 58 if (this->state_ ==0)59 if (this->state_ == FREE)//FREE 59 60 { 60 61 … … 64 65 this->searchNewMaster(); 65 66 66 //this->state_=1; 67 67 68 68 69 } 69 70 70 if (this->state_ ==-1)71 if (this->state_ == SLAVE)//SLAVE 71 72 { 72 73 // this->bShooting_ = true; 73 74 } 74 75 75 if (this->state_ ==1)76 if (this->state_ == MASTER)//MASTER 76 77 { 78 // command slaves 79 this->commandSlaves(); 77 80 // search enemy 78 81 random = rnd(maxrand); … … 106 109 107 110 // shoot 108 random = rnd(maxrand);111 /*random = rnd(maxrand); 109 112 if (random < 75 && (this->target_ && !this->bShooting_)) 110 113 this->bShooting_ = true; 111 114 */ 112 115 // stop shooting 113 116 random = rnd(maxrand); … … 122 125 return; 123 126 124 if (this->state_ ==1)127 if (this->state_ == MASTER) 125 128 { 126 129 if (this->target_) 127 130 this->aimAtTarget(); 128 131 129 if (this->bHasTargetPosition_)132 /*if (this->bHasTargetPosition_) 130 133 this->moveToTargetPosition(); 131 134 */ 132 135 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f)) 133 136 this->getControllableEntity()->fire(0); 134 137 } 135 138 136 if (this->state_== -1)139 if (this->state_==SLAVE) 137 140 { 138 //this->state_=1;139 141 142 if (this->bHasTargetPosition_) 143 this->moveToTargetPosition(); 144 145 //this->getControllableEntity()->fire(0); 140 146 141 147 } -
code/branches/ai/src/orxonox/controllers/ArtificialController.cc
r6640 r6683 45 45 this->target_ = 0; 46 46 this->team_ = -1;//new 47 this->state_ = 0;//new47 this->state_ = FREE;//new 48 48 this->bShooting_ = false; 49 49 this->bHasTargetPosition_ = false; … … 113 113 114 114 ArtificialController *controller = static_cast<ArtificialController*>(it->getController()); 115 if (controller && controller->getState() !=1)115 if (controller && controller->getState() != MASTER) 116 116 continue; 117 117 … … 121 121 //this->target_ = (*it); 122 122 //this->targetPosition_ = it->getPosition(); 123 this->state_ = -1;123 this->state_ = SLAVE; 124 124 125 125 } … … 127 127 128 128 //hasn't encountered any masters in range? -> become a master 129 if (state_!=-1) state_=1; // 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... 130 } 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... 130 } 131 132 void ArtificialController::commandSlaves() { 133 134 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 135 { 136 ArtificialController *controller = static_cast<ArtificialController*>(it->getController()); 137 if (controller && controller->getState() != MASTER) 138 continue; 139 140 controller->targetPosition_ = this->getControllableEntity()->getPosition(); 141 } 142 143 } 144 145 void ArtificialController::freeAllSlaves() 146 { 147 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 148 { 149 ArtificialController *controller = static_cast<ArtificialController*>(it->getController()); 150 if (controller && controller->getState() != MASTER) 151 continue; 152 153 controller->state_ = FREE; 154 } 155 156 } 157 131 158 132 159 void ArtificialController::setTargetPosition(const Vector3& target) -
code/branches/ai/src/orxonox/controllers/ArtificialController.h
r6640 r6683 59 59 void moveToTargetPosition(); 60 60 61 enum State {SLAVE, MASTER, FREE}; 61 62 int getState(); 62 63 void searchNewMaster(); 64 void commandSlaves(); 65 void freeAllSlaves(); 63 66 64 67 void setTargetPosition(const Vector3& target); … … 80 83 bool bShooting_; 81 84 82 int state_;//new master: 1 slave: -1 free: 0 85 86 State state_;//new master: 1 slave: -1 free: 0 83 87 int team_;//new 84 88
Note: See TracChangeset
for help on using the changeset viewer.