Ejemplo n.º 1
0
int UnitUtil::GetAttackRange(BWAPI::UnitType attacker, BWAPI::UnitType target)
{
    BWAPI::WeaponType weapon = GetWeapon(attacker, target);

    if (weapon == BWAPI::WeaponTypes::None)
    {
        return 0;
    }

    return weapon.maxRange();
}
Ejemplo n.º 2
0
double UnitUtil::CalculateLTD(BWAPI::Unit attacker, BWAPI::Unit target)
{
    BWAPI::WeaponType weapon = GetWeapon(attacker, target);

    if (weapon == BWAPI::WeaponTypes::None)
    {
        return 0;
    }

    return static_cast<double>(weapon.damageAmount()) / weapon.damageCooldown();
}
Ejemplo n.º 3
0
// returns whether or not this unit can attack a given unit at a given time
const bool Unit::canAttackTarget(const Unit & unit, const TimeType & gameTime) const
{
    BWAPI::WeaponType weapon = unit.type().isFlyer() ? type().airWeapon() : type().groundWeapon();

    if (weapon.damageAmount() == 0)
    {
        return false;
    }

    // range of this unit attacking
    PositionType r = range();

    // return whether the target unit is in range
    return (r * r) >= getDistanceSqToUnit(unit, gameTime);
}
Ejemplo n.º 4
0
// returns whether or not this unit can attack a given unit at a given time
bool Unit::canAttackTarget(const Unit & unit, const TimeType & gameTime) const
{
    BWAPI::WeaponType weapon = unit.type().isFlyer() ? type().airWeapon() : type().groundWeapon();

    if (weapon.damageAmount() == 0 || unit.isloaded() )
    {


        return false;
    }


    // range of this unit attacking
    PositionType r = range();

    if(!unit.type().isBuilding())
        return (r * r) >= getDistanceSqToUnit(unit, gameTime);

    const Position &ours=currentPosition(gameTime);
    const Position &his=unit.currentPosition(gameTime);

    PositionType lines[]={his.y()-unit.type().dimensionUp(),
            his.y()+unit.type().dimensionDown(),
            his.x()-unit.type().dimensionLeft(),
            his.x()+unit.type().dimensionRight()};

    PositionType dists[]={lines[0]-ours.y(),lines[1]-ours.y(),lines[2]-ours.x(),lines[3]-ours.x()};

    if(sign(dists[0])==sign(dists[1])){
        if(sign(dists[2])==sign(dists[3])){
            //diagonal
            return (r*r) >=std::min(abs(dists[0]),abs(dists[1]))*
                    std::min(abs(dists[0]),abs(dists[1]))+
                    std::min(abs(dists[2]),abs(dists[3]))*
                    std::min(abs(dists[2]),abs(dists[3]));
        }else{
            //top or bottom
            return r >= std::min(abs(dists[0]),abs(dists[1]));
        }
    }else if(sign(dists[2])==sign(dists[3])){
        //left or right
        return r >= std::min(abs(dists[2]),abs(dists[3]));
    }else{
        std::cerr<<"WARNING: Unit "<<ID()<<" is inside unit "<<unit.ID()<<std::endl;
        return true;
    }

}
Ejemplo n.º 5
0
int UnitUtil::GetAttackRange(BWAPI::Unit attacker, BWAPI::Unit target)
{
    BWAPI::WeaponType weapon = GetWeapon(attacker, target);

    if (weapon == BWAPI::WeaponTypes::None)
    {
        return 0;
    }

    int range = weapon.maxRange();

    if ((attacker->getType() == BWAPI::UnitTypes::Protoss_Dragoon) 
        && (attacker->getPlayer() == BWAPI::Broodwar->self())
        && BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Singularity_Charge))
	{
		range = 6 * 32;
	}

    return range;
}
Ejemplo n.º 6
0
int UnitClass::getTimeToKill(Unit unit)
{
	int health = unit->totalHitPoints();

	BWAPI::WeaponType weapon = getWeapon(unit);

	int weaponDamage = weapon.damageAmount() + (weapon.damageFactor() * getPlayer()->getUpgradeLevel(weapon.upgradeType()));
	if(weaponDamage == 0)
		return 5000;

	int thisNumberOfShots = health / weaponDamage;

	if(weapon.damageType() == BWAPI::DamageTypes::Concussive)
	{
		if(unit->getType().size() == BWAPI::UnitSizeTypes::Large)
			thisNumberOfShots *= 4;
		else if(unit->getType().size() == BWAPI::UnitSizeTypes::Medium)
			thisNumberOfShots += thisNumberOfShots;
	}
	else if(weapon.damageType() == BWAPI::DamageTypes::Explosive)
	{
		if(unit->getType().size() == BWAPI::UnitSizeTypes::Small)
			thisNumberOfShots += thisNumberOfShots;
		else if(unit->getType().size() == BWAPI::UnitSizeTypes::Medium)
			thisNumberOfShots += thisNumberOfShots / 2;
	}

	if((BWAPI::Broodwar->getGroundHeight(getTilePosition()) - BWAPI::Broodwar->getGroundHeight(unit->getTilePosition())) < 0)
		thisNumberOfShots += thisNumberOfShots;

	return thisNumberOfShots * weapon.damageCooldown();
}
Ejemplo n.º 7
0
void WeaponProps::SetType(BWAPI::WeaponType type)
{
	this->type		= type;
	cooldown[0]		= cooldown[1]		= type.damageCooldown();
	maxRange[0]		= maxRange[1]		= type.maxRange() << pixelShift;
}