//-------------------------- AddBots -------------------------------------- // // Adds a bot and switches on the default steering behavior //----------------------------------------------------------------------------- void Raven_Game::AddBots(unsigned int NumBotsToAdd) { while (NumBotsToAdd--) { //create a bot. (its position is irrelevant at this point because it will //not be rendered until it is spawned) Raven_Bot* rb = new Raven_Bot(this, Vector2D()); m_lastTeamSpawned = (m_lastTeamSpawned == 1) ? 2 : 1; rb->SetTeamId(m_lastTeamSpawned); //switch the default steering behaviors on rb->GetSteering()->WallAvoidanceOn(); rb->GetSteering()->SeparationOn(); m_Bots.push_back(rb); //register the bot with the entity manager EntityMgr->RegisterEntity(rb); #ifdef LOG_CREATIONAL_STUFF debug_con << "Adding bot with ID " << ttos(rb->ID()) << ""; #endif } }
void Rocket::TestForImpact() { //if the projectile has reached the target position or it hits an entity //or wall it should explode/inflict damage/whatever and then mark itself //as dead //test to see if the line segment connecting the rocket's current position //and previous position intersects with any bots. Raven_Bot* hit = GetClosestIntersectingBot(m_vPosition - m_vVelocity, m_vPosition); //if hit if (hit) { m_bImpacted = true; //send a message to the bot to let it know it's been hit, and who the //shot came from Dispatcher->DispatchMsg(SEND_MSG_IMMEDIATELY, m_iShooterID, hit->ID(), Msg_TakeThatMF, (void*)&m_iDamageInflicted); //test for bots within the blast radius and inflict damage InflictDamageOnBotsWithinBlastRadius(); } //test for impact with a wall double dist; if( FindClosestPointOfIntersectionWithWalls(m_vPosition - m_vVelocity, m_vPosition, dist, m_vImpactPoint, m_pWorld->GetMap()->GetWalls())) { m_bImpacted = true; //test for bots within the blast radius and inflict damage InflictDamageOnBotsWithinBlastRadius(); m_vPosition = m_vImpactPoint; return; } //test to see if rocket has reached target position. If so, test for //all bots in vicinity const double tolerance = 5.0; if (Vec2DDistanceSq(Pos(), m_vTarget) < tolerance*tolerance) { m_bImpacted = true; InflictDamageOnBotsWithinBlastRadius(); } }
//------------------------------ Update --------------------------------------- //----------------------------------------------------------------------------- void Bolt::Update() { if (!m_bImpacted) { m_vVelocity = MaxSpeed() * Heading(); //make sure vehicle does not exceed maximum velocity m_vVelocity.Truncate(m_dMaxSpeed); //update the position m_vPosition += m_vVelocity; //if the projectile has reached the target position or it hits an entity //or wall it should explode/inflict damage/whatever and then mark itself //as dead //test to see if the line segment connecting the bolt's current position //and previous position intersects with any bots. Raven_Bot* hit = GetClosestIntersectingBot(m_vPosition - m_vVelocity, m_vPosition); //if hit if (hit) { m_bImpacted = true; m_bDead = true; //send a message to the bot to let it know it's been hit, and who the //shot came from Dispatcher->DispatchMsg(SEND_MSG_IMMEDIATELY, m_iShooterID, hit->ID(), Msg_TakeThatMF, (void*)&m_iDamageInflicted); } //test for impact with a wall double dist; if( FindClosestPointOfIntersectionWithWalls(m_vPosition - m_vVelocity, m_vPosition, dist, m_vImpactPoint, m_pWorld->GetMap()->GetWalls())) { m_bDead = true; m_bImpacted = true; m_vPosition = m_vImpactPoint; return; } } }
//----------------------------------- TestForImpact --------------------------- void Pellet::TestForImpact() { //a shot gun shell is an instantaneous projectile so it only gets the chance //to update once m_bImpacted = true; //first find the closest wall that this ray intersects with. Then we //can test against all entities within this range. double DistToClosestImpact; FindClosestPointOfIntersectionWithWalls(m_vOrigin, m_vPosition, DistToClosestImpact, m_vImpactPoint, m_pWorld->GetMap()->GetWalls()); //test to see if the ray between the current position of the shell and //the start position intersects with any bots. Raven_Bot* hit = GetClosestIntersectingBot(m_vOrigin, m_vPosition); //if no bots hit just return; if (!hit) return; //determine the impact point with the bot's bounding circle so that the //shell can be rendered properly GetLineSegmentCircleClosestIntersectionPoint(m_vOrigin, m_vImpactPoint, hit->Pos(), hit->BRadius(), m_vImpactPoint); //send a message to the bot to let it know it's been hit, and who the //shot came from Dispatcher->DispatchMsg(SEND_MSG_IMMEDIATELY, m_iShooterID, hit->ID(), Msg_TakeThatMF, (void*)&m_iDamageInflicted); }