- Timestamp:
- Mar 29, 2010, 4:23:08 PM (15 years ago)
- Location:
- code/branches/ai/src/orxonox
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ai/src/orxonox/controllers/AIController.cc
r5929 r6640 56 56 float maxrand = 100.0f / ACTION_INTERVAL; 57 57 58 // search enemy 59 random = rnd(maxrand); 60 if (random < 15 && (!this->target_)) 61 this->searchNewTarget(); 58 if (this->state_==0) 59 { 62 60 63 // forget enemy64 random = rnd(maxrand);65 if (random < 5 && (this->target_))66 this->forgetTarget();61 // search master 62 random = rnd(maxrand); 63 if (random < 50 && (!this->target_)) 64 this->searchNewMaster(); 67 65 68 // next enemy 69 random = rnd(maxrand); 70 if (random < 10 && (this->target_)) 71 this->searchNewTarget(); 66 //this->state_=1; 72 67 73 // fly somewhere 74 random = rnd(maxrand); 75 if (random < 50 && (!this->bHasTargetPosition_ && !this->target_)) 76 this->searchRandomTargetPosition(); 68 } 77 69 78 // stop flying79 random = rnd(maxrand);80 if (random < 10 && (this->bHasTargetPosition_ && !this->target_))81 this->bHasTargetPosition_ = false;70 if (this->state_==-1) 71 { 72 73 } 82 74 83 // fly somewhere else 84 random = rnd(maxrand); 85 if (random < 30 && (this->bHasTargetPosition_ && !this->target_)) 86 this->searchRandomTargetPosition(); 75 if (this->state_==1) 76 { 77 // search enemy 78 random = rnd(maxrand); 79 if (random < 15 && (!this->target_)) 80 this->searchNewTarget(); 87 81 88 // shoot89 random = rnd(maxrand);90 if (random < 75 && (this->target_ && !this->bShooting_))91 this->bShooting_ = true;82 // forget enemy 83 random = rnd(maxrand); 84 if (random < 5 && (this->target_)) 85 this->forgetTarget(); 92 86 93 // stop shooting 94 random = rnd(maxrand); 95 if (random < 25 && (this->bShooting_)) 96 this->bShooting_ = false; 87 // next enemy 88 random = rnd(maxrand); 89 if (random < 10 && (this->target_)) 90 this->searchNewTarget(); 91 92 // fly somewhere 93 random = rnd(maxrand); 94 if (random < 50 && (!this->bHasTargetPosition_ && !this->target_)) 95 this->searchRandomTargetPosition(); 96 97 // stop flying 98 random = rnd(maxrand); 99 if (random < 10 && (this->bHasTargetPosition_ && !this->target_)) 100 this->bHasTargetPosition_ = false; 101 102 // fly somewhere else 103 random = rnd(maxrand); 104 if (random < 30 && (this->bHasTargetPosition_ && !this->target_)) 105 this->searchRandomTargetPosition(); 106 107 // shoot 108 random = rnd(maxrand); 109 if (random < 75 && (this->target_ && !this->bShooting_)) 110 this->bShooting_ = true; 111 112 // stop shooting 113 random = rnd(maxrand); 114 if (random < 25 && (this->bShooting_)) 115 this->bShooting_ = false; 116 } 97 117 } 98 118 … … 102 122 return; 103 123 104 if (this->target_) 105 this->aimAtTarget(); 124 if (this->state_==1) 125 { 126 if (this->target_) 127 this->aimAtTarget(); 106 128 107 if (this->bHasTargetPosition_)108 this->moveToTargetPosition();129 if (this->bHasTargetPosition_) 130 this->moveToTargetPosition(); 109 131 110 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f)) 111 this->getControllableEntity()->fire(0); 132 if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f)) 133 this->getControllableEntity()->fire(0); 134 } 135 136 if (this->state_==-1) 137 { 138 //this->state_=1; 139 140 141 } 112 142 113 143 SUPER(AIController, tick, dt); -
code/branches/ai/src/orxonox/controllers/ArtificialController.cc
r6601 r6640 44 44 45 45 this->target_ = 0; 46 this->team_ = 0;//new47 this-> isMaster_ = false;//new46 this->team_ = -1;//new 47 this->state_ = 0;//new 48 48 this->bShooting_ = false; 49 49 this->bHasTargetPosition_ = false; … … 88 88 { 89 89 this->moveToPosition(this->targetPosition_); 90 } 91 92 int ArtificialController::getState() 93 { 94 return this->state_; 95 } 96 97 void ArtificialController::searchNewMaster() 98 { 99 if (!this->getControllableEntity()) 100 return; 101 102 this->targetPosition_ = this->getControllableEntity()->getPosition(); 103 this->forgetTarget(); 104 105 //go through all pawns 106 for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it) 107 { 108 //same team? no: continue 109 if (!ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype())) 110 continue; 111 112 //has it an ArtificialController and is it a master? no: continue 113 114 ArtificialController *controller = static_cast<ArtificialController*>(it->getController()); 115 if (controller && controller->getState()!=1) 116 continue; 117 118 //is pawn oneself? && is pawn in range? 119 if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity() /*&& it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) < 1000 */) 120 { 121 //this->target_ = (*it); 122 //this->targetPosition_ = it->getPosition(); 123 this->state_ = -1; 124 125 } 126 }//for 127 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... 90 130 } 91 131 -
code/branches/ai/src/orxonox/controllers/ArtificialController.h
r6601 r6640 59 59 void moveToTargetPosition(); 60 60 61 int getState(); 62 void searchNewMaster(); 63 61 64 void setTargetPosition(const Vector3& target); 62 65 void searchRandomTargetPosition(); … … 77 80 bool bShooting_; 78 81 79 bool isMaster_;//new82 int state_;//new master: 1 slave: -1 free: 0 80 83 int team_;//new 81 84 -
code/branches/ai/src/orxonox/worldentities/pawns/Pawn.h
r6540 r6640 115 115 Vector3 getAimPosition() 116 116 { return this->aimPosition_; } 117 117 118 118 virtual const Vector3& getCarrierPosition(void) 119 119 { return this->getWorldPosition(); };
Note: See TracChangeset
for help on using the changeset viewer.