b2Vec2 Enemy::evade(b2Vec2 pursuer, b2Vec2 pVel, float dist) { b2Vec2 between = pursuer - getPosition(); float distance = between.Length(); float speed = body_->GetLinearVelocity().Length(); int maxTimePrediction = 1000; int timePrediction = 1000; b2Vec2 steer(0, 0); if (speed <= distance / maxTimePrediction) { timePrediction = maxTimePrediction; steer = arrive(pursuer, dist); } else { timePrediction = distance / speed; b2Vec2 newPursuer(pVel); newPursuer *= timePrediction; newPursuer += pursuer; steer = flee(newPursuer, dist); } return steer; }
void AIControl::poll() { if(state==PURSUE) { pursue(vector3df(0,25,0)); } else if (state==FLEE) { flee(vector3df(0,25,0)); } }
/** cherche à éviter une unité */ Vector Vehicule::evade(Vehicule& target) { Vector diff = target.getPosition() - m_position; float distance = diff.norme(); float anticipation_time=0; if(target.getVelocity().norme()>0) anticipation_time = distance / target.getVelocity().norme(); Vector futur_position = target.getPosition() + (target.getVelocity()*anticipation_time/2.f); return flee(futur_position); }
//Return a reaction based on state Enemy::Reaction Enemy::ruminate() { //Update player presence player_ = getPlayer_(); play_ = (player_ != nullptr); //Change states based on behaviour float hpf = (float)getHP() / (float)(startingHP_); //Distance to player, if she's there float between = FLT_MAX; if (play_) between = (getPosition() - player_->getPosition()).Length(); //If the player's dead, hang ten if (!play_) stateOfMind_ = IDLE; //Flee if hurt else if (hpf < ouch_[brainStem_.pain_tolerance]) stateOfMind_ = FLEE; //Otherwise think about what we should do else switch (stateOfMind_) { //If we're running, check if we're healthy enough to stop case FLEE: if (hpf > ouch_[brainStem_.pain_tolerance]) stateOfMind_ = IDLE; //If we're chilling, check if the player is messing with the bull case IDLE: if (play_ && between < 128 && between <= chaseRange_[brainStem_.personal_space] || angry_ == angryMAX_) stateOfMind_ = CHASE; //If we're chasing, make sure we can still see him case CHASE: if (play_ && between > chaseRangeMAX_[brainStem_.perserverance]) stateOfMind_ = IDLE; } //Execute our current mood switch (stateOfMind_) { case IDLE: //std::cout << "idle" << std::endl; return idle(); break; case CHASE: //std::cout << "chase" << std::endl; return chase(); break; case FLEE: //std::cout << "flee" << std::endl; return flee(); break; } return Reaction(); }
void trxVehicle::evade(trxVehicle& target) { float lookAheadTime = (float)position.distance(target.position) / maxSpeed; ofVec3f targetVelocity; targetVelocity.set(target.velocity); targetVelocity *= lookAheadTime; ofVec3f predictedTarget; predictedTarget.set(target.position); predictedTarget -= targetVelocity; flee(predictedTarget); }
Direction AI::decideMovement(D3DXVECTOR3 position) { switch(state) { case S_REGULAR: { regular(position); break; } case S_DEAD: { dead(position); break; } case S_FLEE: { flee(position); break; } } if(getTileClosestAt(position) == destination || !destination) { for(int i = 0; i < 1000000; i++) { destination = tiles->at( rand()%tiles->size() ); if(calcRoute(getTileClosestAt(position),destination)) break; } } if(!route.empty()) { Direction dir = route.front(); route.pop_front(); return dir; } return D_SIZE; }
void Ghost::navigate(Direction directions) { Direction opposite = NONE; if (direction) { switch (direction) { case UP: opposite = DOWN; break; case DOWN: opposite = UP; break; case LEFT: opposite = RIGHT; break; case RIGHT: opposite = LEFT; break; } directions = (Direction)(directions & ~opposite); if (directions == NONE) directions = opposite; } switch (directions) { case UP: direction = UP; return; case DOWN: direction = DOWN; return; case LEFT: direction = LEFT; return; case RIGHT: direction = RIGHT; return; default: break; } switch (mode) { case INACTIVE: break; case CHASE: direction = chase(targetX, targetY, directions); break; case SCATTER: direction = chase(homeX, homeY, directions); break; case AFRAID: direction = flee(directions); break; case HOME: break; } }
void StateCowFleeGetWeapon::update(){ entity->setVelocityX(velocityX); entity->setVelocityY(velocityY); //for the evader's current position. SVector2D vectorCow; vectorCow.x = entity->GetX() + entity->getVelocityX(); vectorCow.y = entity->GetY() + entity->getVelocityY(); SVector2D vectorGun; vectorGun.x = entityGun->GetX(); vectorGun.y = entityGun->GetY(); SVector2D vectorRabbit; vectorRabbit.x = entityRabbit->GetX(); vectorRabbit.y = entityRabbit->GetY(); int entity_x, entity_y; //for toroid entity_x = entity->GetX(); entity_y = entity->GetY(); uint32_t entitiy_w; uint32_t entitiy_h; entity->GetSize(entitiy_w, entitiy_h); /*Toroid*/ if (entity->GetX() < 0 - static_cast<int>(entitiy_w)){ //entity->setVelocityX(-entity->getVelocityX()); entity->setVelocityX(-velocityX); entity_x = w - 1; } if (entity->GetY() < 0 - static_cast<int>(entitiy_h)){ //entity->setVelocityY(-entity->getVelocityY()); entity->setVelocityY(-velocityY); entity_y = h - 1; } /*Toroid*/ if (entity->GetX() > w + static_cast<int>(entitiy_w)){ entity->setVelocityX(velocityX); //entity_x = -static_cast<int>(entitiy_w); //unary operation on unsigned int entity_x = 1; } if (entity->GetY() > h + static_cast<int>(entitiy_h)){ entity->setVelocityY(velocityY); //entity_y = -static_cast<int>(entitiy_h); //unary operation on unsigned int entity_y = 1; } int distance = Vec2DDistanceSq2(vectorGun, vectorCow); const float PanicDistanceSq = 10.0f * 10.0f; int distanceCowRabbit = Vec2DDistanceSq2(vectorCow, vectorRabbit); if (distanceCowRabbit < PanicDistanceSq * 3) { flee(entity, entityRabbit); //printf("flee!"); } else{ seek2(vectorGun); //Seek2 } //Use the distance between cow and gun as collision if (distance < 30){ //set position Weapon/Gun getCaught(); } }
Vector2d ComponentSteering::evade(GameObject* mainPlayer) //no funciona { Vector2d distance = mainPlayer->position - parent->position; Vector2d futurePosition = mainPlayer->position + mainPlayer->velocity * speed; return flee(mainPlayer->position); }
void AIDestroyWizard::update() { if (!characterPtr) { return; } int viewSize = characterPtr->getViewSize(); Character* targetCharacter = searchTargetBFS(Character::Good); if (targetCharacter) { // std::string chantStr = ToolFunction::int2string(characterPtr->getChantCount()); // HudMessageBox::getInstance()->addMessage(chantStr); this->changeOrientationTo(targetCharacter); if (isInAttackArea(targetCharacter)) { //ÒÑÒ÷³ªÇÒħ·¨³ä×ã if (characterPtr->getChantCount() >= 20 && characterPtr->getMP() >= 40) { characterPtr->runSkill( ToolFunction::WStr2UTF8(L"RandomDirectDamage_À×»÷_40_20_100_5_0") ); } else if (characterPtr->getMP() >= 40 && RandomNumber::getInstance()->randomBool(0.8)) { //ħ·¨Öµ³ä×ã if (characterPtr->getChantCount() == 0) { characterPtr->chant(); } else { characterPtr->attack(); } } else { characterPtr->attack(); } } else if (isInMagicArea(4)) { //ÒÑÒ÷³ªÇÒħ·¨³ä×ã if (characterPtr->getChantCount() >= 20 && characterPtr->getMP() >= 40) { characterPtr->runSkill( ToolFunction::WStr2UTF8(L"RandomDirectDamage_À×»÷_40_20_100_5_0") ); } else if (characterPtr->getMP() >= 40 && RandomNumber::getInstance()->randomBool(0.8)) { //ħ·¨Öµ³ä×ã if (characterPtr->getChantCount() == 0) { characterPtr->chant(); } else { //characterPtr->idle(); wander(); } } else { wander(); } } else { if (!flee(targetCharacter)) { wander(); } } } else { characterPtr->idle(); } }
void trxVehicle::fleeTarget(ofVec3f *_target){ flee(*_target); }
kglt::Vec3 Boid::evade(const Vec3& target, const Vec3& target_velocity, const float target_max_speed) const { float T = kglt::Vec3::distance(target, actor_->position()) / target_max_speed; kglt::Vec3 target_location = target + (target_velocity * T); return flee(target_location); }