Пример #1
0
void Unit::SetHeading(Vec2 new_heading) {
    m_vHeading = Vec2Normalize(new_heading);
}
Пример #2
0
	//--------------------------------------------------------------------------------------------------------------
	//获取该矢量的单位化矢量
	Vector2 Vector2::GetNormalizedVec() const
	{
		static Vector2 tmp;
		Vec2Normalize( &tmp, this );
		return tmp;
	}
Пример #3
0
std::shared_ptr<api::Player> ClosestEnemySelector::Select(api::Bot* bot) {
    ClientPtr client = bot->GetClient();

    std::vector<api::PlayerPtr> enemies = client->GetEnemies(); 

    if (enemies.size() == 0) return api::PlayerPtr(nullptr);

    // Distance of closest enemy with multiplier applied
    double closest_calc_dist = std::numeric_limits<double>::max();
    api::PlayerPtr closest = api::PlayerPtr(nullptr);
    // Determines how much the rotation difference will increase distance by
    // TODO: change this to calculate rotation time using client settings
    const double RotationMultiplier = 2.0; 

    Vec2 spawn(((Bot*)bot)->GetConfig().SpawnX, ((Bot*)bot)->GetConfig().SpawnY);
    int center_radius = ((Bot*)bot)->GetConfig().CenterRadius;
    bool center_only = ((Bot*)bot)->GetConfig().CenterOnly;
    Vec2 bot_pos = bot->GetPos();
    bool has_x = (bot->GetMemorySensor().GetBotPlayer()->GetStatus() & 4) != 0;
    Vec2 half_resolution = Vec2(1920, 1080) / 2;
    Vec2 view_min = bot_pos - half_resolution / 16;
    Vec2 view_max = bot_pos + half_resolution / 16;
    bool bot_in_center = InRect(bot_pos, spawn - center_radius, spawn + center_radius);

    for (unsigned int i = 0; i < enemies.size(); i++) {
        api::PlayerPtr& enemy = enemies.at(i);
        int cdx, cdy;
        double cdist;

        Vec2 enemy_pos = enemy->GetPosition() / 16;

        if (enemy_pos.x <= 0 && enemy_pos.y <= 0) continue;
        if (client->IsInSafe(enemy_pos, bot->GetLevel())) continue;

        bool in_center = InRect(enemy_pos, spawn - center_radius, spawn + center_radius);

        if ((center_only || bot_in_center) && !in_center) continue;

        Util::GetDistance(enemy_pos, bot_pos, &cdx, &cdy, &cdist);

        if (cdist < 15 && bot->IsInSafe()) continue;

        unsigned char status = enemy->GetStatus();
        bool stealth = (status & 1) != 0;
        bool cloak = (status & 2) != 0;

        if (!has_x) {
            if (stealth && cloak) continue;
            bool visible = InRect(enemy_pos, view_min, view_max);

            if (stealth && !visible) continue;
        }

        Vec2 to_target = Vec2Normalize(enemy_pos - bot_pos); 
        double dot = bot->GetHeading().Dot(to_target);
        double multiplier = 1.0 + ((1.0 - dot) / RotationMultiplier);
        double calc_dist = cdist * multiplier;

        if (calc_dist < closest_calc_dist) {
            closest_calc_dist = calc_dist;
            closest = enemy;
        }
    }

    return closest;
}
Пример #4
0
	//--------------------------------------------------------------------------------------------------------------
	//单位化该矢量
	void Vector2::Normalize()
	{
		Vec2Normalize( this, this );
	}