Beispiel #1
0
Unit* TargetingAgent::findTarget(BaseAgent* agent)
{
	//Check if the agent targets ground and/or air
	bool targetsGround = false;
	if (agent->getUnitType().groundWeapon().targetsGround()) targetsGround = true;
	if (agent->getUnitType().airWeapon().targetsGround()) targetsGround = true;

	bool targetsAir = false;
	if (agent->getUnitType().groundWeapon().targetsAir()) targetsAir = true;
	if (agent->getUnitType().airWeapon().targetsAir()) targetsAir = true;

	//Check max range
	int range = agent->getUnitType().seekRange();
	if (agent->getUnit()->isSieged()) range = agent->getUnit()->getType().groundWeapon().maxRange();

	//Iterate through enemies to select a target
	int bestTargetScore = -1;
	Unit* target = NULL;
	for(set<Unit*>::const_iterator i=Broodwar->enemy()->getUnits().begin();i!=Broodwar->enemy()->getUnits().end();i++)
	{
		UnitType t = (*i)->getType();

		bool canAttack = false;
		if (!t.isFlyer() && targetsGround) canAttack = true;
		if ((t.isFlyer() || (*i)->isLifted()) && targetsAir) canAttack = true;
		if ((t.hasPermanentCloak() || (*i)->isBurrowed()) && !(*i)->isDetected()) canAttack = false;

		if (canAttack)
		{
			int d = (int)agent->getUnit()->getDistance((*i));
			if (d <= range)
			{
				int cScore = (int)((double)t.destroyScore() * getTargetModifier(agent->getUnit()->getType(), t));
				
				if (cScore > bestTargetScore)
				{
					bestTargetScore = cScore;
					target = (*i);
				}
			}
		}
	}

	return target;
}
Beispiel #2
0
Unit* TargetingAgent::findTarget(BaseAgent* agent)
{
    //Check if the agent targets ground and/or air
    bool targetsGround = false;
    if (agent->getUnitType().groundWeapon().targetsGround()) targetsGround = true;
    if (agent->getUnitType().airWeapon().targetsGround()) targetsGround = true;

    bool targetsAir = false;
    if (agent->getUnitType().groundWeapon().targetsAir()) targetsAir = true;
    if (agent->getUnitType().airWeapon().targetsAir()) targetsAir = true;

    //Check max range
    int range = agent->getUnitType().seekRange();
    if (agent->getUnitType().sightRange() > range)
    {
        range = agent->getUnitType().sightRange();
    }
    range *= 1.5;

    if (agent->getUnit()->isSieged())
    {
        range = Broodwar->self()->groundWeaponMaxRange(agent->getUnit()->getType());
    }

    //Iterate through enemies to select a target
    int bestTargetScore = -10000;
    Unit* target = NULL;
    for(set<Unit*>::const_iterator i=Broodwar->enemy()->getUnits().begin(); i!=Broodwar->enemy()->getUnits().end(); i++)
    {
        UnitType t = (*i)->getType();

        bool canAttack = false;
        if (!t.isFlyer() && targetsGround) canAttack = true;
        if ((t.isFlyer() || (*i)->isLifted()) && targetsAir) canAttack = true;
        if ((*i)->isCloaked() && !(*i)->isDetected())
        {
            canAttack = false;
            handleCloakedUnit((*i));
        }
        if ((*i)->isBurrowed() && !(*i)->isDetected())
        {
            canAttack = false;
            handleCloakedUnit((*i));
        }

        if (canAttack)
        {
            int d = (int)agent->getUnit()->getDistance((*i));
            if (d <= range)
            {
                double mod = getTargetModifier(agent->getUnit()->getType(), t);
                int cScore = (int)((double)t.destroyScore() * mod);
                if ((*i)->getHitPoints() < (*i)->getInitialHitPoints())
                {
                    //Prioritize damaged targets
                    cScore++;
                }

                if (cScore > bestTargetScore)
                {
                    bestTargetScore = cScore;
                    target = (*i);
                }
            }
        }
    }

    return target;
}