/** * Returns the average damage of the given weapon at the given range. We say "average" here as * some weapons use a clustered system and may only do partial damage, otherwise we return the * maximum damage. If the range specified is less than 0 or greater than the maximum range of the * weapon we return -1. * * @param w The weapon in question. * @param range The range that the weapon will be hitting a target at * @return The average damage of the weapon at that range. */ public static int GetAverageDamageAtRange(ifWeapon w, int range) { if (w.IsCluster()) { boolean Streak = w.IsStreak(); boolean Ultra = w.IsUltra(); boolean Rotary = w.IsRotary(); boolean Ballistic = false; if (w.GetWeaponClass() == ifWeapon.W_BALLISTIC) { Ballistic = true; } if (range > w.GetRangeLong()) { return 0; } else if (range > w.GetRangeMedium()) { if (Streak) { return w.GetDamageLong() * w.ClusterSize(); } else if (Ultra) { // don't even bother with the cluster table, it'll always // return 1 in this case. return w.GetDamageLong(); } else if (Ballistic & !Rotary) { // this covers LB-X cannons in general return GetAverageClusterHits(w, w.ClusterModLong()); } else { return w.GetDamageLong() * GetAverageClusterHits(w, w.ClusterModLong()); } } else if (range > w.GetRangeShort()) { if (Streak) { return w.GetDamageMedium() * w.ClusterSize(); } else if (Ultra) { return w.GetDamageMedium(); } else if (Ballistic & !Rotary) { return GetAverageClusterHits(w, w.ClusterModMedium()); } else { return w.GetDamageMedium() * GetAverageClusterHits(w, w.ClusterModMedium()); } } else { if (Streak) { return w.GetDamageShort() * w.ClusterSize(); } else if (Ultra) { return w.GetDamageShort(); } else if (Ballistic & !Rotary) { return GetAverageClusterHits(w, w.ClusterModShort()); } else { return w.GetDamageShort() * GetAverageClusterHits(w, w.ClusterModShort()); } } } else { if (range > w.GetRangeLong()) { return 0; } else if (range > w.GetRangeMedium()) { return w.GetDamageLong(); } else if (range > w.GetRangeShort()) { return w.GetDamageMedium(); } else { return w.GetDamageShort(); } } }
/** * Returns the to-hit modifier of the weapon at the given range. This is only weapon-specific, it * does not account for target or firer movement, or other modifiers. If the weapon cannot hit at * the given range, we return 12. * * @param w The weapon in question. * @param range The range that the weapon will be hitting a target at. * @return The to-hit modifier for the weapon at the given range. */ public static int GetToHitAtRange(ifWeapon w, int range) { if (range > w.GetRangeLong()) { return 12; } else if (range > w.GetRangeMedium()) { return 4 + w.GetToHitLong(); } else if (range > w.GetRangeShort()) { return 2 + w.GetToHitMedium(); } else { if (range <= w.GetRangeMin() && w.GetRangeMin() > 0) { int min = w.GetRangeMin() - range + 1; return 0 + min + w.GetToHitShort(); } else { return 0 + w.GetToHitShort(); } } }