bool AbortTask::FillReachable(const AircraftState &state, AlternateVector &approx_waypoints, const GlidePolar &polar, bool only_airfield, bool final_glide, bool safety) { if (IsTaskFull() || approx_waypoints.empty()) return false; const AGeoPoint p_start(state.location, state.altitude); bool found_final_glide = false; reservable_priority_queue<Alternate, AlternateVector, AbortRank> q; q.reserve(32); for (auto v = approx_waypoints.begin(); v != approx_waypoints.end();) { if (only_airfield && !v->waypoint.IsAirport()) { ++v; continue; } UnorderedTaskPoint t(v->waypoint, task_behaviour); GlideResult result = TaskSolution::GlideSolutionRemaining(t, state, polar); /* calculate time_virtual, which is needed by AbortRank */ result.CalcVInvSpeed(polar.GetInvMC()); if (IsReachable(result, final_glide)) { bool intersects = false; const bool is_reachable_final = IsReachable(result, true); if (intersection_test && final_glide && is_reachable_final) intersects = intersection_test->Intersects( AGeoPoint(v->waypoint.location, result.min_height)); if (!intersects) { q.push(Alternate(v->waypoint, result)); // remove it since it's already in the list now approx_waypoints.erase(v); if (is_reachable_final) found_final_glide = true; continue; // skip incrementing v since we just erased it } } ++v; } while (!q.empty() && !IsTaskFull()) { const Alternate top = q.top(); task_points.push_back(AlternateTaskPoint(top.waypoint, task_behaviour, top.solution)); const int i = task_points.size() - 1; if (task_points[i].GetWaypoint().id == active_waypoint) active_task_point = i; q.pop(); } return found_final_glide; }
entity *CACBot::SearchForFlags(bool bUseWPs, float flRange, float flMaxHeight) { /* Flags are scored on the following: - Distance */ float flDist; entity *pNewTargetFlag = NULL; waypoint_s *pWptNearBot = NULL, *pBestWpt = NULL; short sScore, sHighestScore = 0; vec vNewGoal = g_vecZero; if ((WaypointClass.m_iWaypointCount >= 1) && bUseWPs) pWptNearBot = GetNearestWaypoint(200.0f); #ifdef WP_FLOOD if (!pWptNearBot && bUseWPs) pWptNearBot = GetNearestFloodWP(64.0f); #endif loopv(ents) { sScore = 0; entity &e = ents[i]; if(!CanTakeFlag(e)) continue; //vec o = g_vecZero; vec o = vec(e.x, e.y, S(e.x, e.y)->floor + PLAYERHEIGHT + PLAYERABOVEEYE); if(!m_secure(gamemode) && e.attr2 >= 0 && e.attr2 < 2) { flaginfo &f = flaginfos[e.attr2]; // flaginfo &of = flaginfos[team_opposite(i)]; if(f.state == CTFF_DROPPED) { o = f.pos; o.z += PLAYERHEIGHT + PLAYERABOVEEYE; } } if(OUTBORD((int)o.x, (int)o.y)) continue; flDist = GetDistance(o); if (flDist > flRange) continue; // Score on distance float ff = flDist; if (ff > 100.0f) ff = 100.0f; sScore += ((100 - short(ff)) / 2); waypoint_s *pWptNearEnt = NULL; // If this flag entity isn't visible check if there is a nearby waypoint if (!IsReachable(o, flMaxHeight))//(!IsVisible(o)) { if (!pWptNearBot) continue; #ifdef WP_FLOOD if (pWptNearBot->pNode->iFlags & W_FL_FLOOD) pWptNearEnt = GetNearestFloodWP(o, 100.0f); else #endif pWptNearEnt = GetNearestWaypoint(o, 200.f); if (!pWptNearEnt) continue; } // Score on visibility if (pWptNearEnt == NULL) // Ent is visible sScore += 6; else sScore += 3; if(sScore > sHighestScore) { if (pWptNearEnt) pBestWpt = pWptNearEnt; else pBestWpt = NULL; // best flag doesn't need any waypoints vNewGoal = o; pNewTargetFlag = &e; } } if (pNewTargetFlag) { // Need waypoints to reach it? if (pBestWpt) { ResetWaypointVars(); SetCurrentWaypoint(pWptNearBot); SetCurrentGoalWaypoint(pBestWpt); } m_vGoal = vNewGoal; } return pNewTargetFlag; }
bool CACBot::HeadToTargetFlag() { if(m_pTargetFlag) { const vec o = m_vGoal; if(CanTakeFlag(*m_pTargetFlag) && (!UnderWater(m_pMyEnt->o) || !UnderWater(o))) { bool bIsVisible = false; if (m_pCurrentGoalWaypoint) { if ((GetDistance(o) <= 20.0f) && IsReachable(o, 1.0f)) bIsVisible = true; else if (HeadToGoal()) { //debugbeam(m_pMyEnt->o, m_pCurrentWaypoint->pNode->v_origin); //debugbeam(m_pMyEnt->o, // m_pCurrentGoalWaypoint->pNode->v_origin); AddDebugText("Using WPs for flag"); return true; } } else bIsVisible = IsVisible(o); if (bIsVisible) { if (m_pCurrentWaypoint || m_pCurrentGoalWaypoint) { condebug("flag is now visible"); ResetWaypointVars(); } float flHeightDiff = o.z - m_pMyEnt->o.z; bool bToHigh = false; if (Get2DDistance(o) <= 2.0f) { if (flHeightDiff >= 1.5f) { if (flHeightDiff <= JUMP_HEIGHT) { #ifndef RELEASE_BUILD char sz[64]; sprintf(sz, "Flag z diff: %f", o.z-m_pMyEnt->o.z); condebug(sz); #endif // Jump if close to ent and the ent is high m_pMyEnt->jumpnext = true; } else bToHigh = true; } } if (!bToHigh) { AimToVec(o); return true; } } } } return false; }
entity *CACBot::SearchForEnts(bool bUseWPs, float flRange, float flMaxHeight) { /* Entities are scored on the following things: - Visibility - For ammo: Need(ie has this bot much of this type or not) - distance */ float flDist; entity *pNewTargetEnt = NULL; waypoint_s *pWptNearBot = NULL, *pBestWpt = NULL; short sScore, sHighestScore = 0; if ((WaypointClass.m_iWaypointCount >= 1) && bUseWPs) pWptNearBot = GetNearestWaypoint(15.0f); #ifdef WP_FLOOD if (!pWptNearBot && bUseWPs) pWptNearBot = GetNearestFloodWP(5.0f); #endif loopv(ents) { sScore = 0; entity &e = ents[i]; vec o(e.x, e.y, S(e.x, e.y)->floor+player1->eyeheight); if (!ents[i].spawned) continue; if (OUTBORD(e.x, e.y)) continue; bool bInteresting = false; short sAmmo = 0, sMaxAmmo = 0; switch(e.type) { case I_CLIPS: sMaxAmmo = ammostats[m_pMyEnt->secondary].max; bInteresting = (m_pMyEnt->ammo[m_pMyEnt->secondary]<sMaxAmmo); sAmmo = m_pMyEnt->ammo[m_pMyEnt->secondary]; break; case I_AMMO: sMaxAmmo = ammostats[m_pMyEnt->primary].max; bInteresting = (m_pMyEnt->ammo[m_pMyEnt->primary]<sMaxAmmo); sAmmo = m_pMyEnt->ammo[m_pMyEnt->primary]; break; case I_GRENADE: sMaxAmmo = ammostats[GUN_GRENADE].max; bInteresting = (m_pMyEnt->mag[GUN_GRENADE]<sMaxAmmo); sAmmo = -1; break; case I_HEALTH: sMaxAmmo = MAXHEALTH; bInteresting = (m_pMyEnt->health < sMaxAmmo); sAmmo = m_pMyEnt->health; break; case I_HELMET: case I_ARMOUR: sMaxAmmo = MAXARMOUR; bInteresting = (m_pMyEnt->armour < sMaxAmmo); sAmmo = m_pMyEnt->armour; break; case I_AKIMBO: bInteresting = !m_pMyEnt->akimbo; sAmmo = -1; break; }; if (!bInteresting) continue; // Not an interesting item, skip // Score on ammo and need // Akimbo & nade if (sAmmo == -1) { sScore += 75; // Bonus } else { // Calculate current percentage of max ammo float percent = ((float)sAmmo / (float)sMaxAmmo) * 100.0f; if (percent > 100.0f) percent = 100.0f; sScore += ((100 - short(percent))/2); } flDist = GetDistance(o); if (flDist > flRange) continue; // Score on distance float f = flDist; if (f > 100.0f) f = 100.0f; sScore += ((100 - short(f)) / 2); waypoint_s *pWptNearEnt = NULL; // If this entity isn't visible check if there is a nearby waypoint if (!IsReachable(o, flMaxHeight))//(!IsVisible(o)) { if (!pWptNearBot) continue; #ifdef WP_FLOOD if (pWptNearBot->pNode->iFlags & W_FL_FLOOD) pWptNearEnt = GetNearestFloodWP(o, 8.0f); else #endif pWptNearEnt = GetNearestWaypoint(o, 15.0f); if (!pWptNearEnt) continue; } // Score on visibility if (pWptNearEnt == NULL) // Ent is visible sScore += 30; else sScore += 15; if (sScore > sHighestScore) { // Found a valid wp near the bot and the ent,so...lets store it :) if (pWptNearEnt) pBestWpt = pWptNearEnt; else pBestWpt = NULL; // Best ent so far doesn't need any waypoints sHighestScore = sScore; pNewTargetEnt = &ents[i]; } } if (pNewTargetEnt) { // Need waypoints to reach it? if (pBestWpt) { ResetWaypointVars(); SetCurrentWaypoint(pWptNearBot); SetCurrentGoalWaypoint(pBestWpt); } m_vGoal.x = pNewTargetEnt->x; m_vGoal.y = pNewTargetEnt->y; m_vGoal.z = S(pNewTargetEnt->x, pNewTargetEnt->y)->floor+player1->eyeheight; } return pNewTargetEnt; }