/// Returns the bonus armor for this unit.
u8 getArmorBonusHook(const CUnit *unit) {
  //Default StarCraft behavior
  using scbw::getUpgradeLevel;

  u8 armorUpg = 0;
  if (scbw::isBroodWarMode()) {
    if (unit->id == UnitId::Hero_Torrasque || unit->id == UnitId::ultralisk) {
      if ((Unit::BaseProperty[unit->id] & UnitProperty::Hero)
          || getUpgradeLevel(unit->playerId, UpgradeId::ChitinousPlating)) {
        armorUpg = 2;
      }
    }
  }
  return armorUpg + getUpgradeLevel(unit->playerId, Unit::ArmorUpgrade[unit->id]);
}
Exemplo n.º 2
0
/// Returns the modified sight range of the unit, measured in matrices.
/// StarCraft passes 1 for isForSpellCasting when using Feedback, Mind Control,
/// and Hallucination (but not when launching Nukes).
/// Note: sight ranges cannot exceed 11, unless extended.
u32 getSightRangeHook(const CUnit *unit, bool isForSpellCasting) {
    //Default StarCraft logic
    using scbw::getUpgradeLevel;

    //Check if the unit is a constructing building (exclude remorphing buildings)
    if (unit->status & UnitStatus::GroundedBuilding
            && !(unit->status & UnitStatus::Completed)
            && !unit->isRemorphingBuilding())
        return 4;

    //Check if the unit is blinded (don't bother if this is for spellcasting)
    if (!isForSpellCasting && unit->isBlind)
        return 2;

    //Sight range upgrades
    switch (unit->id) {
    case UnitId::ghost:
        if (getUpgradeLevel(unit->playerId, UpgradeId::OcularImplants))
            return 11;
        break;
    case UnitId::overlord:
        if (getUpgradeLevel(unit->playerId, UpgradeId::Antennae))
            return 11;
        break;
    case UnitId::observer:
        if (getUpgradeLevel(unit->playerId, UpgradeId::SensorArray))
            return 11;
        break;
    case UnitId::scout:
        if (getUpgradeLevel(unit->playerId, UpgradeId::ApialSensors))
            return 11;
        break;
    }

    //Default
    return units_dat::SightRange[unit->id];
}
/// Returns the modified max range for the weapon, which is assumed to be
/// attached to the given unit.
/// This hook affects the behavior of CUnit::getMaxWeaponRange().
/// Note: Weapon ranges are measured in pixels.
///
/// @param  weapon    The weapons.dat ID of the weapon.
/// @param  unit      The unit that owns the weapon. Use this to check upgrades.
u32 getMaxWeaponRangeHook(const CUnit *unit, u8 weaponId) {
  //Default StarCraft behavior
  using scbw::getUpgradeLevel;

  u32 bonusAmount = 0;

  //Give bonus range to units inside Bunkers
  if (unit->status & UnitStatus::InBuilding)
    bonusAmount = 64;

  switch (unit->id) {
    case UnitId::marine:
      if (getUpgradeLevel(unit->playerId, UpgradeId::U_238Shells))
        bonusAmount += 32;
      break;
    case UnitId::hydralisk:
      if (getUpgradeLevel(unit->playerId, UpgradeId::GroovedSpines))
        bonusAmount += 32;
      break;
    case UnitId::dragoon:
      if (getUpgradeLevel(unit->playerId, UpgradeId::SingularityCharge))
        bonusAmount += 64;
      break;
    case UnitId::arbiter: //아비터 사거리업 적용
      if (getUpgradeLevel(unit->playerId, UPGRADE_ARBITER_WPN_RANGE))
        bonusAmount += 64;  //사거리 2 추가
      break;
    case UnitId::fenix_dragoon:
      if (scbw::isBroodWarMode())
        bonusAmount += 64;
      break;
    case UnitId::goliath:
    case UnitId::goliath_turret:
      if (weaponId == WeaponId::HellfireMissilePack
          && getUpgradeLevel(unit->playerId, UpgradeId::CharonBooster))
        bonusAmount += 96;
      break;
    case UnitId::alan_schezar:
    case UnitId::alan_schezar_turret:
      if (weaponId == WeaponId::HellfireMissilePack_AlanSchezar
          && scbw::isBroodWarMode())
        bonusAmount += 96;
      break;
    case UnitId::lurker:  //러커 사거리업 적용
      if (getUpgradeLevel(unit->playerId, UPGRADE_LURKER_RANGE))
        bonusAmount += 96;  //사거리 3 추가
      break;
  }

  return Weapon::MaxRange[weaponId] + bonusAmount;
}
/// Replaces the CUnit::getMaxEnergy() function.
/// Return the amount of maximum energy that a unit can have.
/// Note: 1 energy displayed in-game equals 256 energy.
u16 getUnitMaxEnergyHook(const CUnit* const unit) {
  //Default StarCraft behavior
  using scbw::getUpgradeLevel;
  if (Unit::BaseProperty[unit->id] & UnitProperty::Hero)
    return 64000; //250

  switch (unit->id) {
    case UnitId::science_vessel:
      if (getUpgradeLevel(unit->playerId, UpgradeId::TitanReactor))
        return 64000; //250
      break;
    case UnitId::ghost:
      if (getUpgradeLevel(unit->playerId, UpgradeId::MoebiusReactor))
        return 64000; //250
      break;
    case UnitId::wraith:
      if (getUpgradeLevel(unit->playerId, UpgradeId::ApolloReactor))
        return 64000; //250
      break;
    case UnitId::battlecruiser:
      if (getUpgradeLevel(unit->playerId, UpgradeId::ColossusReactor))
        return 64000; //250
      break;
    case UnitId::queen:
      if (getUpgradeLevel(unit->playerId, UpgradeId::GameteMeiosis))
        return 64000; //250
      break;
    case UnitId::defiler:
      if (getUpgradeLevel(unit->playerId, UpgradeId::MetasynapticNode))
        return 64000; //250
      break;
    case UnitId::high_templar:
      if (getUpgradeLevel(unit->playerId, UpgradeId::KhaydarinAmulet))
        return 64000; //250
      break;
    case UnitId::arbiter:
      if (getUpgradeLevel(unit->playerId, UpgradeId::KhaydarinCore))
        return 64000; //250
      break;
    case UnitId::corsair:
      if (getUpgradeLevel(unit->playerId, UpgradeId::ArgusJewel))
        return 64000; //250
      break;
    case UnitId::medic:
      if (getUpgradeLevel(unit->playerId, UpgradeId::CaduceusReactor))
        return 64000; //250
      break;
    case UnitId::dark_archon:
      if (getUpgradeLevel(unit->playerId, UpgradeId::ArgusTalisman))
        return 64000; //250
      break;
  }

  return 51200; //200
}
/// Returns the modified seek range (AKA target acquisition range) for the unit.
/// Note: Seek ranges are measured in matrices (1 matrix = 32 pixels).
/// This hook affects the behavior of CUnit::getSeekRange().
u8 getSeekRangeHook(const CUnit *unit) {

  using UnitStatus::Cloaked;
  using UnitStatus::RequiresDetection;
  using scbw::getUpgradeLevel;

  const u16 unitId = unit->id;

  //Cloaked ghosts do not voluntarily attack enemy units
  if ((unitId == UnitId::ghost
       || unitId == UnitId::sarah_kerrigan
       || unitId == UnitId::Hero_AlexeiStukov
       || unitId == UnitId::Hero_SamirDuran
       || unitId == UnitId::Hero_InfestedDuran)
      && unit->status & (Cloaked | RequiresDetection)
      && unit->mainOrderId != OrderId::HoldPosition2)
    return 0;

  //홀드 러커
  if (unitId == UnitId::lurker && unit->status & UnitStatus::HoldingPosition)
    return 0;

  u8 bonusAmount = 0;
  switch (unitId) {
    case UnitId::marine:
      if (getUpgradeLevel(unit->playerId, UpgradeId::U_238Shells))
        bonusAmount = 1;
      break;
    case UnitId::hydralisk:
      if (getUpgradeLevel(unit->playerId, UpgradeId::GroovedSpines))
        bonusAmount = 1;
      break;
    case UnitId::dragoon:
      if (getUpgradeLevel(unit->playerId, UpgradeId::SingularityCharge))
        bonusAmount = 2;
      break;
    case UnitId::arbiter: //아비터 사거리업 적용
      if (getUpgradeLevel(unit->playerId, UPGRADE_ARBITER_WPN_RANGE))
        bonusAmount = 2;
      break;
    case UnitId::fenix_dragoon:
      if (scbw::isBroodWarMode())
        bonusAmount = 2;
      break;
    case UnitId::goliath:
    case UnitId::goliath_turret:
      if (getUpgradeLevel(unit->playerId, UpgradeId::CharonBooster))
        bonusAmount = 3;
      break;
    case UnitId::alan_schezar:
    case UnitId::alan_schezar_turret:
      if (scbw::isBroodWarMode())
        bonusAmount = 3;
      break;
    case UnitId::lurker:  //러커 사거리업 적용
      if (getUpgradeLevel(unit->playerId, UPGRADE_LURKER_RANGE))
        bonusAmount = 3;
      break;
  }

  return Unit::SeekRange[unitId] + bonusAmount;
}
	//This hook function is called when creating a new unit.
	void applyUpgradeFlagsToNewUnitHook(CUnit *unit) {
		//Default StarCraft behavior
		using scbw::getUpgradeLevel;

		u8 speedUpgradeLevel = 0, cooldownUpgradeLevel = 0;

		switch (unit->id) {
		case UnitId::vulture:
		case UnitId::jim_raynor_vulture:
			speedUpgradeLevel = getUpgradeLevel(unit->playerId, UpgradeId::IonThrusters);
			break;
		case UnitId::overlord:
			speedUpgradeLevel = getUpgradeLevel(unit->playerId, UpgradeId::PneumatizedCarapace);
			break;
		case UnitId::zergling:
			speedUpgradeLevel = getUpgradeLevel(unit->playerId, UpgradeId::MetabolicBoost);
			cooldownUpgradeLevel = getUpgradeLevel(unit->playerId, UpgradeId::AdrenalGlands);
			break;
		case UnitId::hydralisk:
			speedUpgradeLevel = getUpgradeLevel(unit->playerId, UpgradeId::MuscularAugments);
			break;
		case UnitId::ultralisk:
			speedUpgradeLevel = getUpgradeLevel(unit->playerId, UpgradeId::AnabolicSynthesis);
			break;
		case UnitId::zealot:
			speedUpgradeLevel = getUpgradeLevel(unit->playerId, UpgradeId::LegEnhancements);
			break;
		case UnitId::scout:
			speedUpgradeLevel = getUpgradeLevel(unit->playerId, UpgradeId::GraviticThrusters);
			break;
		case UnitId::shuttle:
			speedUpgradeLevel = getUpgradeLevel(unit->playerId, UpgradeId::GraviticDrive);
			break;
		case UnitId::observer:
			speedUpgradeLevel = getUpgradeLevel(unit->playerId, UpgradeId::GraviticBoosters);
			break;
		case UnitId::Hero_DevouringOne:
			cooldownUpgradeLevel = 1;
			speedUpgradeLevel = 1;
			break;
		case UnitId::Hero_HunterKiller:
		case UnitId::Hero_Yggdrasill:
		case UnitId::Hero_FenixZealot:
		case UnitId::Hero_Mojo:
		case UnitId::Hero_Artanis:
		case UnitId::lurker:
			speedUpgradeLevel = 1;
			break;
		case UnitId::Hero_Torrasque:
			if (scbw::isBroodWarMode())
				speedUpgradeLevel = 1;
			break;
		}

		if (speedUpgradeLevel) {
			unit->status |= UnitStatus::SpeedUpgrade;
			unit->updateSpeed();
		}
		if (cooldownUpgradeLevel) {
			unit->status |= UnitStatus::CooldownUpgrade;
		}
	}