public void selectWeaponE() { if (!RangedBattle && attackAngle != Defender.UnitRotation) // No counter in ranged or back attacks { float bestDamage = 0; foreach (TurretSpec turret in Defender.UnitBodySpec.turrets) { float newDamage; GunSpec weapon = turret.gunStat; if (Defender.UnitRotation == GameUnit.OppositeRotationStatus(attackAngle) || // Head on attack turret.turnableIndex() >= 0) // Or the turret is turnable { if (weapon.counter && canTarget(Defender, Attacker, distance, turret, weapon)) { newDamage = estimateRawDamage(Attacker.getArmor( attackAngle, false), weapon, Attacker.UnitBodySpec.getNumbers()); if (newDamage > bestDamage) { bestDamage = newDamage; TurretOfChoiceE = turret; } } } } } }
public static float estimateRawDamage(float armor, GunSpec weapon, int unitCount) { float damage = weapon.absolute; float barrageBonus = 1; if (weapon.Turret.totalBarrage <= unitCount) { barrageBonus = weapon.Turret.totalBarrage; } else { float overBonus = Mathf.Log10(50.0f * (float)weapon.Turret.totalBarrage / (float)unitCount) / 4; if (overBonus > 1) { overBonus = 1; } barrageBonus = (float)unitCount * (1.0f + overBonus); //Debug.Log("Barrage OVER: " + barrageBonus + "In " + weapon.Turret.totalBarrage + " vs " + unitCount); } if (armor < weapon.damage) { damage += weapon.damage - Mathf.Max(0, armor - weapon.pierce); } return(damage * weapon.burstsize * barrageBonus); }
public int GenerateBody(GameObject mainPrefab, GameObject[] subPrefab, int index) { if (mainPrefab != null) { GameObject cannons = this.transform.FindChild("Cannons").gameObject; int gunCount = cannons.transform.childCount; for (int i = 0; i < gunCount; i++) { gun = (GameObject)Instantiate(mainPrefab, new Vector3(0, 0, 0), Quaternion.identity); gun.transform.parent = cannons.transform.GetChild(i).FindChild("Extension").transform; gun.transform.position = gun.transform.parent.transform.position; GunSpec wspec = (GunSpec)gun.GetComponent("GunSpec"); wspec.Turret = this; //gun.transform.localEulerAngles = new Vector3(0,0,0); if (gunStat == null) { gunStat = wspec; } } TurretIndex = index; } index = GenerateGuns(subPrefab, index); return(index); }
public static bool canFire(GameUnit attacker, GunSpec weapon) { // foreach (GameObject turret in attacker.UnitBodySpec.turrets) { // TurretSpec turretSpec = (TurretSpec)turret.GetComponent("TurretSpec"); // GunSpec weapon = turretSpec.gunStat; // if (canTarget(attacker, defender, distance, turretSpec, weapon)) // return true; // } // return false; return(true); }
public ActionResult EditGun(string gName) { gun _gun = TableUtils.queryToObject <gun>("SELECT * FROM shooters.gun where gName= '" + gName + "'"); GunSpec gs = new GunSpec(); gs._gun = _gun; List <gunType> _types = TableUtils.queryToTable <gunType>("SELECT * FROM shooters.gunTypeRel natural join shooters.gunType where gName= '" + gName + "'"); gs._specs = _types; ViewBag.gName = gName; return(View(gs)); }
public static bool canTarget(GameUnit attacker, GameUnit defender, int distance) { foreach (TurretSpec turret in attacker.UnitBodySpec.turrets) { GunSpec weapon = turret.gunStat; if (canTarget(attacker, defender, distance, turret, weapon)) { return(true); } } return(false); }
public int getMaxRange() { int max = 0; foreach (TurretSpec turret in turrets) { GunSpec weapon = turret.gunStat; if (weapon.maxrange > 0) { max = Mathf.Max(max, weapon.maxrange); } } return(max); }
public void selectWeapon() { float bestDamage = 0; foreach (TurretSpec turret in Attacker.UnitBodySpec.turrets) { float newDamage; GunSpec weapon = turret.gunStat; if (canTarget(Attacker, Defender, distance, turret, weapon)) { newDamage = estimateRawDamage(Defender.getArmor( GameUnit.OppositeRotationStatus(attackAngle)), weapon, Defender.UnitBodySpec.getNumbers()); if (newDamage > bestDamage) { bestDamage = newDamage; TurretOfChoice = turret; } } } }
public static bool canTargetDirectRules(GameUnit.UnitTerrainStatus attacker, GameUnit.UnitTerrainStatus defender, TurretSpec turret, GunSpec weapon) { // Homing weapons can target all except submerged, cannot be used while submerged if (weapon.type == GunSpec.GunType.Homing && attacker != GameUnit.UnitTerrainStatus.Deep && defender != GameUnit.UnitTerrainStatus.Deep) { return(true); } switch (attacker) { case GameUnit.UnitTerrainStatus.Air: switch (defender) { case GameUnit.UnitTerrainStatus.Air: // A vs A return(weapon.type == GunSpec.GunType.Direct); case GameUnit.UnitTerrainStatus.Deep: // A vs Sub return(weapon.type == GunSpec.GunType.Drop || weapon.type == GunSpec.GunType.Torpedo); case GameUnit.UnitTerrainStatus.High: // A vs G switch (weapon.type) { case GunSpec.GunType.Direct: return(turret.highDepression); case GunSpec.GunType.Heavy: return(true); case GunSpec.GunType.Drop: return(true); } break; case GameUnit.UnitTerrainStatus.HighFloat: // A vs G switch (weapon.type) { case GunSpec.GunType.Direct: return(turret.highDepression); case GunSpec.GunType.Heavy: return(true); case GunSpec.GunType.Drop: return(true); } break; case GameUnit.UnitTerrainStatus.Land: // A vs G switch (weapon.type) { case GunSpec.GunType.Direct: return(turret.highDepression); case GunSpec.GunType.Heavy: return(true); case GunSpec.GunType.Drop: return(true); } break; case GameUnit.UnitTerrainStatus.Float: // A vs G switch (weapon.type) { case GunSpec.GunType.Direct: return(turret.highDepression); case GunSpec.GunType.Heavy: return(true); case GunSpec.GunType.Drop: return(true); } break; case GameUnit.UnitTerrainStatus.Water: // A vs Sea switch (weapon.type) { case GunSpec.GunType.Direct: return(turret.highDepression); case GunSpec.GunType.Heavy: return(true); case GunSpec.GunType.Drop: return(true); case GunSpec.GunType.Torpedo: return(true); } break; } break; case GameUnit.UnitTerrainStatus.Deep: switch (defender) { case GameUnit.UnitTerrainStatus.Deep: // Sub vs Sub return(weapon.type == GunSpec.GunType.Direct || weapon.type == GunSpec.GunType.Torpedo); case GameUnit.UnitTerrainStatus.Water: // Sub vs Sea switch (weapon.type) { case GunSpec.GunType.Direct: return(turret.highDepression); case GunSpec.GunType.Torpedo: return(true); } break; } break; case GameUnit.UnitTerrainStatus.High: switch (defender) { case GameUnit.UnitTerrainStatus.Air: // G vs A switch (weapon.type) { case GunSpec.GunType.Direct: return(turret.highDepression); } break; case GameUnit.UnitTerrainStatus.High: // GH vs GH switch (weapon.type) { case GunSpec.GunType.Direct: return(true); case GunSpec.GunType.Heavy: return(true); } break; case GameUnit.UnitTerrainStatus.HighFloat: // GH vs GH switch (weapon.type) { case GunSpec.GunType.Direct: return(true); case GunSpec.GunType.Heavy: return(true); } break; case GameUnit.UnitTerrainStatus.Land: // GH vs G switch (weapon.type) { case GunSpec.GunType.Direct: return(true); case GunSpec.GunType.Heavy: return(true); } break; case GameUnit.UnitTerrainStatus.Float: // GH vs G switch (weapon.type) { case GunSpec.GunType.Direct: return(true); case GunSpec.GunType.Heavy: return(true); } break; case GameUnit.UnitTerrainStatus.Water: // G vs Sea switch (weapon.type) { case GunSpec.GunType.Direct: return(true); case GunSpec.GunType.Heavy: return(true); } break; } break; case GameUnit.UnitTerrainStatus.Land: switch (defender) { case GameUnit.UnitTerrainStatus.Air: // G vs A switch (weapon.type) { case GunSpec.GunType.Direct: return(turret.highDepression); } break; case GameUnit.UnitTerrainStatus.High: // G vs GH switch (weapon.type) { case GunSpec.GunType.Direct: return(turret.highDepression); case GunSpec.GunType.Heavy: return(turret.highDepression); } break; case GameUnit.UnitTerrainStatus.HighFloat: // G vs GH switch (weapon.type) { case GunSpec.GunType.Direct: return(turret.highDepression); case GunSpec.GunType.Heavy: return(turret.highDepression); } break; case GameUnit.UnitTerrainStatus.Land: // G vs G switch (weapon.type) { case GunSpec.GunType.Direct: return(true); case GunSpec.GunType.Heavy: return(true); } break; case GameUnit.UnitTerrainStatus.Float: // G vs G switch (weapon.type) { case GunSpec.GunType.Direct: return(true); case GunSpec.GunType.Heavy: return(true); } break; case GameUnit.UnitTerrainStatus.Water: // G vs Sea switch (weapon.type) { case GunSpec.GunType.Direct: return(true); case GunSpec.GunType.Heavy: return(true); } break; } break; case GameUnit.UnitTerrainStatus.Water: switch (defender) { case GameUnit.UnitTerrainStatus.Air: // Sea vs A switch (weapon.type) { case GunSpec.GunType.Direct: return(turret.highDepression); } break; case GameUnit.UnitTerrainStatus.High: // Sea vs GH switch (weapon.type) { case GunSpec.GunType.Direct: return(turret.highDepression); case GunSpec.GunType.Heavy: return(turret.highDepression); } break; case GameUnit.UnitTerrainStatus.HighFloat: // Sea vs GH switch (weapon.type) { case GunSpec.GunType.Direct: return(turret.highDepression); case GunSpec.GunType.Heavy: return(turret.highDepression); } break; case GameUnit.UnitTerrainStatus.Land: // Sea vs G switch (weapon.type) { case GunSpec.GunType.Direct: return(true); case GunSpec.GunType.Heavy: return(true); } break; case GameUnit.UnitTerrainStatus.Float: // Sea vs G switch (weapon.type) { case GunSpec.GunType.Direct: return(true); case GunSpec.GunType.Heavy: return(true); } break; case GameUnit.UnitTerrainStatus.Water: // Sea vs Sea switch (weapon.type) { case GunSpec.GunType.Direct: return(true); case GunSpec.GunType.Heavy: return(true); case GunSpec.GunType.Drop: return(true); case GunSpec.GunType.Torpedo: return(true); } break; case GameUnit.UnitTerrainStatus.Deep: // Sea vs Sea switch (weapon.type) { case GunSpec.GunType.Drop: return(true); case GunSpec.GunType.Torpedo: return(true); } break; } break; } return(false); }
public static bool canTarget(GameUnit attacker, GameUnit defender, int distance, TurretSpec turret, GunSpec weapon) { //DIRECT ATTACKS if (distance <= 1) { if (!weapon.direct) { return(false); } return(canTargetDirectRules(attacker.terrainStatus, defender.terrainStatus, turret, weapon)); } //LONG RANGE ATTTACKS else if (!attacker.HasMoved && weapon.minrange <= distance && weapon.maxrange >= distance) { // Debug.Log ("TESTU"); // Homing weapons can target all except submerged, cannot be used while submerged if (weapon.type == GunSpec.GunType.Homing && attacker.terrainStatus != GameUnit.UnitTerrainStatus.Deep && defender.terrainStatus != GameUnit.UnitTerrainStatus.Deep) { return(true); } else if (attacker.terrainStatus == GameUnit.UnitTerrainStatus.Air || // Attacker is flying attacker.terrainStatus == GameUnit.UnitTerrainStatus.Deep || // Attacker is submerged weapon.type == GunSpec.GunType.Torpedo) // Torpedo weapons //use direct attack rules { return(canTargetDirectRules(attacker.terrainStatus, defender.terrainStatus, turret, weapon)); } else if (turret.highDepression) //Attacker is either grounded or on sea, turret need to have a good angle { switch (weapon.type) { case GunSpec.GunType.Direct: // Can only perform anti air against aerial units return(defender.terrainStatus == GameUnit.UnitTerrainStatus.Air); case GunSpec.GunType.Heavy: // Can only perform attacks against non flying and non submerged units return(defender.terrainStatus != GameUnit.UnitTerrainStatus.Air && defender.terrainStatus != GameUnit.UnitTerrainStatus.Deep); } } } return(false); }