/* Bombay - Decompiled by JODE
 * Visit http://jode.sourceforge.net/
 */
package com.maddox.il2.objects.air;
import java.io.IOException;

import com.maddox.JGP.Point3d;
import com.maddox.il2.ai.Shot;
import com.maddox.il2.ai.World;
import com.maddox.il2.engine.Actor;
import com.maddox.il2.fm.RealFlightModel;
import com.maddox.il2.game.AircraftHotKeys;
import com.maddox.il2.game.HUD;
import com.maddox.rts.NetMsgGuaranted;
import com.maddox.rts.NetMsgInput;
import com.maddox.rts.Property;

public class Bombay extends Scheme1 implements TypeBomber, TypeTransport
{
    public static boolean bChangedPit = false;
    private boolean bSightAutomation = false;
    private boolean bSightBombDump = false;
    private float fSightCurDistance = 0.0F;
    public float fSightCurForwardAngle = 0.0F;
    public float fSightCurSideslip = 0.0F;
    public float fSightCurAltitude = 3000.0F;
    public float fSightCurSpeed = 200.0F;
    public float fSightCurReadyness = 0.0F;
    public float fSightSetForwardAngle = 0.0F;
    /*synthetic*/ static Class class$0;
    
    static {
	Class var_class = class$0;
	if (var_class == null) {
	    Class var_class_0_;
	    try {
		var_class_0_
		    = Class.forName("com.maddox.il2.objects.air.Bombay");
	    } catch (ClassNotFoundException classnotfoundexception) {
		NoClassDefFoundError noclassdeffounderror
		    = new NoClassDefFoundError;
		((UNCONSTRUCTED)noclassdeffounderror)
		    .NoClassDefFoundError(classnotfoundexception.getMessage());
		throw noclassdeffounderror;
	    }
	    var_class = class$0 = var_class_0_;
	}
	Class class1 = var_class;
	Property.set(class1, "originCountry", PaintScheme.countryBritain);
    }
    
    public Bombay() {
	bChangedPit = false;
    }
    
    private final void doHitMeATank(Shot shot, int i) {
	if (this.getEnergyPastArmor(0.2F, shot) > 0.0F) {
	    if (shot.power < 14100.0F) {
		if (FM.AS.astateTankStates[i] == 0) {
		    FM.AS.hitTank(shot.initiator, i, 1);
		    FM.AS.doSetTankState(shot.initiator, i, 1);
		}
		if (FM.AS.astateTankStates[i] > 0
		    && (World.Rnd().nextFloat() < 0.02F
			|| (shot.powerType == 3
			    && World.Rnd().nextFloat() < 0.25F)))
		    FM.AS.hitTank(shot.initiator, i, 2);
	    } else
		FM.AS.hitTank(shot.initiator, i,
			      World.Rnd().nextInt(0, (int) (shot.power
							    / 56000.0F)));
	}
    }
    
    public void update(float f) {
	if (FM instanceof RealFlightModel
	    && ((RealFlightModel) FM).isRealMode()) {
	    float f1 = FM.EI.engines[0].getRPM();
	    if (f1 < 300.0F && f1 > 30.0F)
		((RealFlightModel) FM).producedShakeLevel
		    = (1500.0F - f1) / 3000.0F;
	    float f3 = FM.EI.engines[0].getRPM();
	    if (f3 < 1000.0F && f3 > 301.0F)
		((RealFlightModel) FM).producedShakeLevel
		    = (1500.0F - f3) / 8000.0F;
	    float f5 = FM.EI.engines[0].getRPM();
	    if (f5 > 1001.0F && f5 < 1500.0F)
		((RealFlightModel) FM).producedShakeLevel = 0.07F;
	    float f7 = FM.EI.engines[0].getRPM();
	    if (f7 > 1501.0F && f7 < 2000.0F)
		((RealFlightModel) FM).producedShakeLevel = 0.05F;
	    float f9 = FM.EI.engines[0].getRPM();
	    if (f9 > 2001.0F && f9 < 2500.0F)
		((RealFlightModel) FM).producedShakeLevel = 0.04F;
	    float f11 = FM.EI.engines[0].getRPM();
	    if (f11 > 2501.0F)
		((RealFlightModel) FM).producedShakeLevel = 0.03F;
	}
	if (FM instanceof RealFlightModel
	    && ((RealFlightModel) FM).isRealMode()) {
	    float f2 = FM.EI.engines[1].getRPM();
	    if (f2 < 300.0F && f2 > 30.0F)
		((RealFlightModel) FM).producedShakeLevel
		    = (1500.0F - f2) / 3000.0F;
	    float f4 = FM.EI.engines[1].getRPM();
	    if (f4 < 1000.0F && f4 > 301.0F)
		((RealFlightModel) FM).producedShakeLevel
		    = (1500.0F - f4) / 8000.0F;
	    float f6 = FM.EI.engines[1].getRPM();
	    if (f6 > 1001.0F && f6 < 1500.0F)
		((RealFlightModel) FM).producedShakeLevel = 0.07F;
	    float f8 = FM.EI.engines[1].getRPM();
	    if (f8 > 1501.0F && f8 < 2000.0F)
		((RealFlightModel) FM).producedShakeLevel = 0.05F;
	    float f10 = FM.EI.engines[1].getRPM();
	    if (f10 > 2001.0F && f10 < 2500.0F)
		((RealFlightModel) FM).producedShakeLevel = 0.04F;
	    float f12 = FM.EI.engines[1].getRPM();
	    if (f12 > 2501.0F)
		((RealFlightModel) FM).producedShakeLevel = 0.03F;
	}
	if (FM.getSpeedKMH() > 250.0F && FM.getVertSpeed() > 0.0F
	    && FM.getAltitude() < 5000.0F)
	    FM.producedAF.x += (double) (20.0F * (250.0F - FM.getSpeedKMH()));
	if (FM.isPlayers() && FM.Sq.squareElevators > 0.0F) {
	    if (FM.getSpeedKMH() > 400.0F && FM.getSpeedKMH() < 550.0F) {
		FM.SensPitch = 0.2F;
		FM.producedAM.y
		    -= (double) (500.0F * (400.0F - FM.getSpeedKMH()));
	    }
	    if (FM.getSpeedKMH() >= 550.0F) {
		FM.SensPitch = 0.23F;
		FM.producedAM.y
		    -= (double) (300.0F * (400.0F - FM.getSpeedKMH()));
	    } else
		FM.SensPitch = 0.3F;
	}
	super.update(f);
    }
    
    protected void hitBone(String s, Shot shot, Point3d point3d) {
	if (s.startsWith("xx")) {
	    if (s.startsWith("xxammo")) {
		if (World.Rnd().nextFloat() < 0.25F)
		    FM.AS.setJamBullets(0, World.Rnd().nextInt(0, 5));
		this.getEnergyPastArmor(11.4F, shot);
	    } else if (s.startsWith("xxarmor")) {
		if (s.endsWith("a1") || s.endsWith("c1") || s.endsWith("p1"))
		    this.getEnergyPastArmor((12.100000381469727
					     / Math.abs(Aircraft.v1.x)),
					    shot);
		if (s.endsWith("a2") || s.endsWith("c2") || s.endsWith("p2")) {
		    this.getEnergyPastArmor
			(((double) World.Rnd().nextFloat(20.0F, 60.0F)
			  / Math.abs(Aircraft.v1.x)),
			 shot);
		    if (shot.power <= 0.0F) {
			Aircraft.debugprintln
			    (this, "*** Armor Glass: Bullet Stopped..");
			this.doRicochetBack(shot);
		    }
		}
		if (s.endsWith("a3") || s.endsWith("c3") || s.endsWith("p3"))
		    this.getEnergyPastArmor(12.7F, shot);
		if (s.endsWith("a4") || s.endsWith("c4") || s.endsWith("p4"))
		    this.getEnergyPastArmor((12.699999809265137
					     / (Math.abs(Aircraft.v1.x)
						+ 9.999999974752427E-7)),
					    shot);
		if (s.endsWith("a5") || s.endsWith("c5") || s.endsWith("p5"))
		    this.getEnergyPastArmor((12.699999809265137
					     / (Math.abs(Aircraft.v1.z)
						+ 9.999999974752427E-7)),
					    shot);
		if (s.endsWith("a6") || s.endsWith("c6") || s.endsWith("p6"))
		    this.getEnergyPastArmor((4.099999904632568
					     / (Math.abs(Aircraft.v1.x)
						+ 9.999999974752427E-7)),
					    shot);
		if (s.endsWith("a7") || s.endsWith("c7") || s.endsWith("p7"))
		    this.getEnergyPastArmor((9.529999732971191
					     / (Math.abs(Aircraft.v1.x)
						+ 9.999999974752427E-7)),
					    shot);
	    } else {
		if (s.startsWith("xxcontrol")) {
		    int i = s.charAt(9) - 48;
		    switch (i) {
		    case 1:
			if (this.getEnergyPastArmor(3.0F, shot) > 0.0F) {
			    if (World.Rnd().nextFloat() < 0.1F)
				FM.AS.setControlsDamage(shot.initiator, 2);
			    if (World.Rnd().nextFloat() < 0.1F)
				FM.AS.setControlsDamage(shot.initiator, 1);
			}
			break;
		    case 2:
		    case 3:
			if (!(this.getEnergyPastArmor(3.0F, shot) > 0.0F)
			    || !(World.Rnd().nextFloat() < 0.25F))
			    break;
			FM.AS.setControlsDamage(shot.initiator, 0);
		    }
		} else if (s.startsWith("xxeng")) {
		    int j = 0;
		    if (s.startsWith("xxeng2"))
			j = 1;
		    this.debuggunnery("Engine Module[" + j + "]: Hit..");
		    if (s.endsWith("case")) {
			if ((this.getEnergyPastArmor
			     (World.Rnd().nextFloat(0.2F, 0.55F), shot))
			    > 0.0F) {
			    if (World.Rnd().nextFloat()
				< shot.power / 280000.0F) {
				this.debuggunnery
				    ("Engine Module: Engine Crank Case Hit - Engine Stucks..");
				FM.AS.setEngineStuck(shot.initiator, j);
			    }
			    if (World.Rnd().nextFloat()
				< shot.power / 100000.0F) {
				this.debuggunnery
				    ("Engine Module: Engine Crank Case Hit - Engine Damaged..");
				FM.AS.hitEngine(shot.initiator, j, 2);
			    }
			}
			this.getEnergyPastArmor(World.Rnd().nextFloat(0.0F,
								      24.0F),
						shot);
		    }
		    if (s.endsWith("cyls")) {
			if (this.getEnergyPastArmor(0.85F, shot) > 0.0F
			    && (World.Rnd().nextFloat()
				< (FM.EI.engines[j].getCylindersRatio()
				   * 0.66F))) {
			    FM.EI.engines[j].setCyliderKnockOut
				(shot.initiator,
				 World.Rnd().nextInt(1, (int) (shot.power
							       / 32200.0F)));
			    this.debuggunnery("Engine Module: Cylinders Hit, "
					      + FM.EI.engines[j]
						    .getCylindersOperable()
					      + "/"
					      + FM.EI.engines[j].getCylinders()
					      + " Left..");
			    if (World.Rnd().nextFloat()
				< shot.power / 1000000.0F) {
				FM.AS.hitEngine(shot.initiator, j, 2);
				this.debuggunnery
				    ("Engine Module: Cylinders Hit - Engine Fires..");
			    }
			}
			this.getEnergyPastArmor(25.0F, shot);
		    }
		    if (s.endsWith("cyls")
			&& World.Rnd().nextFloat() < 0.01F) {
			if (this.getEnergyPastArmor(0.5F, shot) > 0.0F) {
			    if (World.Rnd().nextFloat(0.0F, 26700.0F)
				< shot.power)
				FM.AS.setEngineSpecificDamage(shot.initiator,
							      j, 4);
			    if (World.Rnd().nextFloat(0.0F, 26700.0F)
				< shot.power)
				FM.AS.setEngineSpecificDamage(shot.initiator,
							      j, 0);
			    if (World.Rnd().nextFloat(0.0F, 26700.0F)
				< shot.power)
				FM.AS.setEngineSpecificDamage(shot.initiator,
							      j, 6);
			    if (World.Rnd().nextFloat(0.0F, 26700.0F)
				< shot.power)
				FM.AS.setEngineSpecificDamage(shot.initiator,
							      j, 1);
			}
			this.getEnergyPastArmor(2.0F, shot);
		    }
		    if (s.endsWith("case")) {
			this.debuggunnery("Engine Module: Magneto " + j
					  + " Destroyed..");
			FM.EI.engines[j].setMagnetoKnockOut(shot.initiator, j);
		    }
		    if (s.endsWith("oil1")) {
			if (World.Rnd().nextFloat() < 0.5F
			    && this.getEnergyPastArmor(0.25F, shot) > 0.0F)
			    this.debuggunnery
				("Engine Module: Oil Radiator Hit..");
			FM.AS.hitOil(shot.initiator, j);
		    }
		    if (s.endsWith("prop")
			&& this.getEnergyPastArmor(0.42F, shot) > 0.0F)
			FM.EI.engines[j]
			    .setKillPropAngleDevice(shot.initiator);
		    if (s.endsWith("supc")
			&& this.getEnergyPastArmor(World.Rnd()
						       .nextFloat(0.2F, 12.0F),
						   shot) > 0.0F) {
			this.debuggunnery("Engine Module: Turbine Disabled..");
			FM.AS.setEngineSpecificDamage(shot.initiator, j, 0);
		    }
		    return;
		}
		if (s.startsWith("xxlock")) {
		    Aircraft.debugprintln(this,
					  "*** Lock Construction: Hit..");
		    if (s.startsWith("xxlockkr1")
			&& ((this.getEnergyPastArmor
			     (6.5F * World.Rnd().nextFloat(1.0F, 3.0F), shot))
			    > 0.0F)) {
			Aircraft.debugprintln(this,
					      "*** Rudder1 Lock Shot Off..");
			this.nextDMGLevels
			    (3, 2,
			     "Rudder1_D" + this.chunkDamageVisible("Rudder1"),
			     shot.initiator);
		    }
		    if (s.startsWith("xxlockkr2")
			&& ((this.getEnergyPastArmor
			     (6.5F * World.Rnd().nextFloat(1.0F, 3.0F), shot))
			    > 0.0F)) {
			Aircraft.debugprintln(this,
					      "*** Rudder2 Lock Shot Off..");
			this.nextDMGLevels
			    (3, 2,
			     "Rudder2_D" + this.chunkDamageVisible("Rudder2"),
			     shot.initiator);
		    }
		    if (s.startsWith("xxlockvl")
			&& ((this.getEnergyPastArmor
			     (5.5F * World.Rnd().nextFloat(1.0F, 1.2F), shot))
			    > 0.0F)) {
			Aircraft.debugprintln(this,
					      "*** VatorL Lock Shot Off..");
			this.nextDMGLevels
			    (3, 2,
			     "VatorL_D" + this.chunkDamageVisible("VatorL"),
			     shot.initiator);
		    }
		    if (s.startsWith("xxlockvr")
			&& ((this.getEnergyPastArmor
			     (5.5F * World.Rnd().nextFloat(1.0F, 1.2F), shot))
			    > 0.0F)) {
			Aircraft.debugprintln(this,
					      "*** VatorR Lock Shot Off..");
			this.nextDMGLevels
			    (3, 2,
			     "VatorR_D" + this.chunkDamageVisible("VatorR"),
			     shot.initiator);
		    }
		    if (s.startsWith("xxlockal")
			&& ((this.getEnergyPastArmor
			     (5.5F * World.Rnd().nextFloat(1.0F, 1.2F), shot))
			    > 0.0F)) {
			Aircraft.debugprintln(this,
					      "*** AroneL Lock Shot Off..");
			this.nextDMGLevels
			    (3, 2,
			     "AroneL_D" + this.chunkDamageVisible("AroneL"),
			     shot.initiator);
		    }
		    if (s.startsWith("xxlockar")
			&& ((this.getEnergyPastArmor
			     (5.5F * World.Rnd().nextFloat(1.0F, 1.2F), shot))
			    > 0.0F)) {
			Aircraft.debugprintln(this,
					      "*** AroneR Lock Shot Off..");
			this.nextDMGLevels
			    (3, 2,
			     "AroneR_D" + this.chunkDamageVisible("AroneR"),
			     shot.initiator);
		    }
		} else if (s.startsWith("xxoil")) {
		    int k = 0;
		    if (s.endsWith("2"))
			k = 1;
		    if (this.getEnergyPastArmor(0.21F, shot) > 0.0F
			&& World.Rnd().nextFloat() < 0.2435F)
			FM.AS.hitOil(shot.initiator, k);
		    Aircraft.debugprintln(this,
					  ("*** Engine (" + k
					   + ") Module: Oil Tank Pierced.."));
		} else if (s.startsWith("xxpnm")) {
		    if (this.getEnergyPastArmor(World.Rnd().nextFloat(0.25F,
								      1.22F),
						shot)
			> 0.0F) {
			this.debuggunnery("Pneumo System: Disabled..");
			FM.AS.setInternalDamage(shot.initiator, 1);
		    }
		} else if (s.startsWith("xxspar")) {
		    if (s.startsWith("xxsparli")
			&& this.chunkDamageVisible("WingLIn") > 2
			&& ((this.getEnergyPastArmor
			     (19.5F * World.Rnd().nextFloat(1.0F, 2.0F), shot))
			    > 0.0F)) {
			this.debuggunnery("*** WingLIn Spars Damaged..");
			this.nextDMGLevels(1, 2, "WingLIn_D2", shot.initiator);
		    }
		    if (s.startsWith("xxsparri")
			&& this.chunkDamageVisible("WingRIn") > 2
			&& ((this.getEnergyPastArmor
			     (19.5F * World.Rnd().nextFloat(1.0F, 2.0F), shot))
			    > 0.0F)) {
			this.debuggunnery("*** WingRIn Spars Damaged..");
			this.nextDMGLevels(1, 2, "WingRIn_D2", shot.initiator);
		    }
		    if (s.startsWith("xxsparlo")
			&& this.chunkDamageVisible("WingLOut") > 2
			&& ((this.getEnergyPastArmor
			     (19.5F * World.Rnd().nextFloat(1.0F, 2.0F), shot))
			    > 0.0F)) {
			this.debuggunnery("*** WingLOut Spars Damaged..");
			this.nextDMGLevels(1, 2, "WingLOut_D2",
					   shot.initiator);
		    }
		    if (s.startsWith("xxsparro")
			&& this.chunkDamageVisible("WingROut") > 2
			&& ((this.getEnergyPastArmor
			     (19.5F * World.Rnd().nextFloat(1.0F, 2.0F), shot))
			    > 0.0F)) {
			this.debuggunnery("*** WingROut Spars Damaged..");
			this.nextDMGLevels(1, 2, "WingROut_D2",
					   shot.initiator);
		    }
		    if (s.startsWith("xxspark1")
			&& this.chunkDamageVisible("Keel1") > 1
			&& ((this.getEnergyPastArmor
			     (9.6F * World.Rnd().nextFloat(1.0F, 2.0F), shot))
			    > 0.0F)) {
			this.debuggunnery("*** Keel1 Spars Damaged..");
			this.nextDMGLevels(1, 2, "Keel1_D2", shot.initiator);
		    }
		    if (s.startsWith("xxspark2")
			&& this.chunkDamageVisible("Keel2") > 1
			&& ((this.getEnergyPastArmor
			     (9.6F * World.Rnd().nextFloat(1.0F, 2.0F), shot))
			    > 0.0F)) {
			this.debuggunnery("*** Keel2 Spars Damaged..");
			this.nextDMGLevels(1, 2, "Keel2_D2", shot.initiator);
		    }
		    if (s.startsWith("xxsparsl")
			&& this.chunkDamageVisible("StabL") > 1
			&& ((this.getEnergyPastArmor
			     (11.2F * World.Rnd().nextFloat(1.0F, 2.0F), shot))
			    > 0.0F)) {
			this.debuggunnery("*** StabL Spars Damaged..");
			this.nextDMGLevels(1, 2, "StabL_D2", shot.initiator);
		    }
		    if (s.startsWith("xxsparsr")
			&& this.chunkDamageVisible("StabR") > 1
			&& ((this.getEnergyPastArmor
			     (11.2F * World.Rnd().nextFloat(1.0F, 2.0F), shot))
			    > 0.0F)) {
			this.debuggunnery("*** StabR Spars Damaged..");
			this.nextDMGLevels(1, 2, "StabR_D2", shot.initiator);
		    }
		} else if (s.startsWith("xxtank")) {
		    int l = s.charAt(6) - 48;
		    switch (l) {
		    case 1:
			doHitMeATank(shot, 0);
			break;
		    case 2:
			doHitMeATank(shot, 1);
			break;
		    case 3:
			doHitMeATank(shot, 2);
			break;
		    case 4:
			doHitMeATank(shot, 3);
			break;
		    case 5:
			doHitMeATank(shot, 1);
			doHitMeATank(shot, 2);
			break;
		    }
		}
	    }
	} else if (s.startsWith("xcf")) {
	    if (this.chunkDamageVisible("CF") < 2)
		this.hitChunk("CF", shot);
	    if (point3d.x > 1.471) {
		if (point3d.z > 0.552 && point3d.x > 2.37) {
		    if (point3d.y > 0.0)
			FM.AS.setCockpitState(shot.initiator,
					      FM.AS.astateCockpitState | 0x4);
		    else
			FM.AS.setCockpitState(shot.initiator,
					      FM.AS.astateCockpitState | 0x10);
		}
		if (point3d.z > 0.0 && point3d.z < 0.539) {
		    if (point3d.y > 0.0)
			FM.AS.setCockpitState(shot.initiator,
					      FM.AS.astateCockpitState | 0x8);
		    else
			FM.AS.setCockpitState(shot.initiator,
					      FM.AS.astateCockpitState | 0x20);
		}
		if (point3d.x < 2.407 && point3d.z > 0.552)
		    FM.AS.setCockpitState(shot.initiator,
					  FM.AS.astateCockpitState | 0x1);
		if (point3d.x > 2.6 && point3d.z > 0.693)
		    FM.AS.setCockpitState(shot.initiator,
					  FM.AS.astateCockpitState | 0x2);
		if (World.Rnd().nextFloat() < 0.12F)
		    FM.AS.setCockpitState(shot.initiator,
					  FM.AS.astateCockpitState | 0x40);
	    }
	} else if (s.startsWith("xtail"))
	    this.hitChunk("Tail1", shot);
	else if (s.startsWith("xkeel1")) {
	    if (this.chunkDamageVisible("Keel1") < 2)
		this.hitChunk("Keel1", shot);
	} else if (s.startsWith("xkeel2")) {
	    if (this.chunkDamageVisible("Keel2") < 2)
		this.hitChunk("Keel2", shot);
	} else if (s.startsWith("xrudder1")) {
	    if (this.chunkDamageVisible("Rudder1") < 2)
		this.hitChunk("Rudder1", shot);
	} else if (s.startsWith("xrudder2")) {
	    if (this.chunkDamageVisible("Rudder2") < 2)
		this.hitChunk("Rudder2", shot);
	} else if (s.startsWith("xstabl")) {
	    if (this.chunkDamageVisible("StabL") < 2)
		this.hitChunk("StabL", shot);
	} else if (s.startsWith("xstabr")) {
	    if (this.chunkDamageVisible("StabR") < 2)
		this.hitChunk("StabR", shot);
	} else if (s.startsWith("xvatorl")) {
	    if (this.chunkDamageVisible("VatorL") < 2)
		this.hitChunk("VatorL", shot);
	} else if (s.startsWith("xvatorr")) {
	    if (this.chunkDamageVisible("VatorR") < 2)
		this.hitChunk("VatorR", shot);
	} else if (s.startsWith("xwinglin")) {
	    if (this.chunkDamageVisible("WingLIn") < 2)
		this.hitChunk("WingLIn", shot);
	} else if (s.startsWith("xwingrin")) {
	    if (this.chunkDamageVisible("WingRIn") < 2)
		this.hitChunk("WingRIn", shot);
	} else if (s.startsWith("xwinglmid")) {
	    if (this.chunkDamageVisible("WingLMid") < 2)
		this.hitChunk("WingLMid", shot);
	} else if (s.startsWith("xwingrmid")) {
	    if (this.chunkDamageVisible("WingRMid") < 2)
		this.hitChunk("WingRMid", shot);
	} else if (s.startsWith("xwinglout")) {
	    if (this.chunkDamageVisible("WingLOut") < 2)
		this.hitChunk("WingLOut", shot);
	} else if (s.startsWith("xwingrout")) {
	    if (this.chunkDamageVisible("WingROut") < 2)
		this.hitChunk("WingROut", shot);
	} else if (s.startsWith("xaronel")) {
	    if (this.chunkDamageVisible("AroneL") < 2)
		this.hitChunk("AroneL", shot);
	} else if (s.startsWith("xaroner")) {
	    if (this.chunkDamageVisible("AroneR") < 2)
		this.hitChunk("AroneR", shot);
	} else if (s.startsWith("xengine1")) {
	    if (this.chunkDamageVisible("Engine1") < 2)
		this.hitChunk("Engine1", shot);
	} else if (s.startsWith("xengine2")) {
	    if (this.chunkDamageVisible("Engine2") < 2)
		this.hitChunk("Engine2", shot);
	} else if (s.startsWith("xgear")) {
	    if (World.Rnd().nextFloat() < 0.1F) {
		this.debuggunnery("*** Gear Hydro Failed..");
		FM.Gears.setHydroOperable(false);
	    }
	} else if (s.startsWith("xturret")) {
	    if (s.startsWith("xturret1b")) {
		FM.AS.setJamBullets(10, 0);
		FM.AS.setJamBullets(10, 1);
	    }
	    if (s.endsWith("2b"))
		FM.AS.setJamBullets(11, 0);
	} else if (s.startsWith("xpilot") || s.startsWith("xhead")) {
	    byte byte0 = 0;
	    int i1;
	    if (s.endsWith("a")) {
		byte0 = (byte) 1;
		i1 = s.charAt(6) - 49;
	    } else if (s.endsWith("b")) {
		byte0 = (byte) 2;
		i1 = s.charAt(6) - 49;
	    } else
		i1 = s.charAt(5) - 49;
	    this.hitFlesh(i1, shot, byte0);
	}
    }
    
    protected boolean cutFM(int i, int j, Actor actor) {
	switch (i) {
	case 19:
	    this.killPilot(this, 4);
	    /* fall through */
	default:
	    return super.cutFM(i, j, actor);
	}
    }
    
    public void rareAction(float f, boolean flag) {
	super.rareAction(f, flag);
	for (int i = 1; i < 4; i++) {
	    if (FM.getAltitude() < 3000.0F)
		this.hierMesh().chunkVisible("HMask" + i + "_D0", false);
	    else
		this.hierMesh().chunkVisible
		    ("HMask" + i + "_D0",
		     this.hierMesh().isChunkVisible("Pilot" + i + "_D0"));
	}
    }
    
    protected void nextDMGLevel(String s, int i, Actor actor) {
	super.nextDMGLevel(s, i, actor);
	if (FM.isPlayers())
	    bChangedPit = true;
    }
    
    protected void nextCUTLevel(String s, int i, Actor actor) {
	super.nextCUTLevel(s, i, actor);
	if (FM.isPlayers())
	    bChangedPit = true;
    }
    
    public boolean turretAngles(int i, float[] af) {
	boolean flag = super.turretAngles(i, af);
	float f = -af[0];
	float f1 = af[1];
	switch (i) {
	default:
	    break;
	case 0:
	    if (f < -23.0F) {
		f = -23.0F;
		flag = false;
	    }
	    if (f > 23.0F) {
		f = 23.0F;
		flag = false;
	    }
	    if (f1 < -25.0F) {
		f1 = -25.0F;
		flag = false;
	    }
	    if (f1 > 15.0F) {
		f1 = 15.0F;
		flag = false;
	    }
	    break;
	case 1:
	    if (f1 < 0.0F) {
		f1 = 0.0F;
		flag = false;
	    }
	    if (f1 > 73.0F) {
		f1 = 73.0F;
		flag = false;
	    }
	}
	af[0] = -f;
	af[1] = f1;
	return flag;
    }
    
    public void doKillPilot(int i) {
	switch (i) {
	case 2:
	    FM.turret[0].bIsOperable = false;
	    break;
	case 3:
	    FM.turret[1].bIsOperable = false;
	    break;
	}
    }
    
    private static final float toMeters(float f) {
	return 0.3048F * f;
    }
    
    private static final float toMetersPerSecond(float f) {
	return 0.4470401F * f;
    }
    
    public boolean typeBomberToggleAutomation() {
	bSightAutomation = !bSightAutomation;
	bSightBombDump = false;
	HUD.log(AircraftHotKeys.hudLogWeaponId,
		"BombsightAutomation" + (bSightAutomation ? "ON" : "OFF"));
	return bSightAutomation;
    }
    
    public void typeBomberAdjDistanceReset() {
	fSightCurDistance = 0.0F;
	fSightCurForwardAngle = 0.0F;
    }
    
    public void typeBomberAdjDistancePlus() {
	fSightCurForwardAngle++;
	if (fSightCurForwardAngle > 85.0F)
	    fSightCurForwardAngle = 85.0F;
	fSightCurDistance
	    = (toMeters(fSightCurAltitude)
	       * (float) (Math.tan
			  (Math.toRadians((double) fSightCurForwardAngle))));
	HUD.log(AircraftHotKeys.hudLogWeaponId, "BombsightElevation",
		new Object[] { new Integer((int) fSightCurForwardAngle) });
	if (bSightAutomation)
	    typeBomberToggleAutomation();
    }
    
    public void typeBomberAdjDistanceMinus() {
	fSightCurForwardAngle--;
	if (fSightCurForwardAngle < 0.0F)
	    fSightCurForwardAngle = 0.0F;
	fSightCurDistance
	    = (toMeters(fSightCurAltitude)
	       * (float) (Math.tan
			  (Math.toRadians((double) fSightCurForwardAngle))));
	HUD.log(AircraftHotKeys.hudLogWeaponId, "BombsightElevation",
		new Object[] { new Integer((int) fSightCurForwardAngle) });
	if (bSightAutomation)
	    typeBomberToggleAutomation();
    }
    
    public void typeBomberAdjSideslipReset() {
	fSightCurSideslip = 0.0F;
    }
    
    public void typeBomberAdjSideslipPlus() {
	fSightCurSideslip += 0.1F;
	if (fSightCurSideslip > 3.0F)
	    fSightCurSideslip = 3.0F;
	HUD.log(AircraftHotKeys.hudLogWeaponId, "BombsightSlip",
		new Object[] { new Integer((int) (fSightCurSideslip
						  * 10.0F)) });
    }
    
    public void typeBomberAdjSideslipMinus() {
	fSightCurSideslip -= 0.1F;
	if (fSightCurSideslip < -3.0F)
	    fSightCurSideslip = -3.0F;
	HUD.log(AircraftHotKeys.hudLogWeaponId, "BombsightSlip",
		new Object[] { new Integer((int) (fSightCurSideslip
						  * 10.0F)) });
    }
    
    public void typeBomberAdjAltitudeReset() {
	fSightCurAltitude = 3000.0F;
    }
    
    public void typeBomberAdjAltitudePlus() {
	fSightCurAltitude += 50.0F;
	if (fSightCurAltitude > 50000.0F)
	    fSightCurAltitude = 50000.0F;
	HUD.log(AircraftHotKeys.hudLogWeaponId, "BombsightAltitudeft",
		new Object[] { new Integer((int) fSightCurAltitude) });
	fSightCurDistance
	    = (toMeters(fSightCurAltitude)
	       * (float) (Math.tan
			  (Math.toRadians((double) fSightCurForwardAngle))));
    }
    
    public void typeBomberAdjAltitudeMinus() {
	fSightCurAltitude -= 50.0F;
	if (fSightCurAltitude < 1000.0F)
	    fSightCurAltitude = 1000.0F;
	HUD.log(AircraftHotKeys.hudLogWeaponId, "BombsightAltitudeft",
		new Object[] { new Integer((int) fSightCurAltitude) });
	fSightCurDistance
	    = (toMeters(fSightCurAltitude)
	       * (float) (Math.tan
			  (Math.toRadians((double) fSightCurForwardAngle))));
    }
    
    public void typeBomberAdjSpeedReset() {
	fSightCurSpeed = 200.0F;
    }
    
    public void typeBomberAdjSpeedPlus() {
	fSightCurSpeed += 10.0F;
	if (fSightCurSpeed > 450.0F)
	    fSightCurSpeed = 450.0F;
	HUD.log(AircraftHotKeys.hudLogWeaponId, "BombsightSpeedMPH",
		new Object[] { new Integer((int) fSightCurSpeed) });
    }
    
    public void typeBomberAdjSpeedMinus() {
	fSightCurSpeed -= 10.0F;
	if (fSightCurSpeed < 100.0F)
	    fSightCurSpeed = 100.0F;
	HUD.log(AircraftHotKeys.hudLogWeaponId, "BombsightSpeedMPH",
		new Object[] { new Integer((int) fSightCurSpeed) });
    }
    
    public void typeBomberUpdate(float f) {
	if ((double) Math.abs(FM.Or.getKren()) > 4.5) {
	    fSightCurReadyness -= 0.0666666F * f;
	    if (fSightCurReadyness < 0.0F)
		fSightCurReadyness = 0.0F;
	}
	if (fSightCurReadyness < 1.0F)
	    fSightCurReadyness += 0.0333333F * f;
	else if (bSightAutomation) {
	    fSightCurDistance -= toMetersPerSecond(fSightCurSpeed) * f;
	    if (fSightCurDistance < 0.0F) {
		fSightCurDistance = 0.0F;
		typeBomberToggleAutomation();
	    }
	    fSightCurForwardAngle
		= (float) (Math.toDegrees
			   (Math.atan
			    ((double) (fSightCurDistance
				       / toMeters(fSightCurAltitude)))));
	    if ((double) fSightCurDistance
		< ((double) toMetersPerSecond(fSightCurSpeed)
		   * Math.sqrt((double) (toMeters(fSightCurAltitude)
					 * 0.2038736F))))
		bSightBombDump = true;
	    if (bSightBombDump) {
		if (FM.isTick(3, 0)) {
		    if (FM.CT.Weapons[3] != null
			&& (FM.CT.Weapons[3][FM.CT.Weapons[3].length - 1]
			    != null)
			&& FM.CT.Weapons[3][FM.CT.Weapons[3].length - 1]
			       .haveBullets()) {
			FM.CT.WeaponControl[3] = true;
			HUD.log(AircraftHotKeys.hudLogWeaponId,
				"BombsightBombdrop");
		    }
		} else
		    FM.CT.WeaponControl[3] = false;
	    }
	}
	double d = ((double) fSightCurSpeed / 3.6
		    * Math.sqrt((double) fSightCurAltitude * 0.203873598));
	d -= (double) (fSightCurAltitude * fSightCurAltitude) * 1.419E-5;
	fSightSetForwardAngle
	    = (float) Math.toDegrees(Math.atan(d
					       / (double) fSightCurAltitude));
    }
    
    public void typeBomberReplicateToNet(NetMsgGuaranted netmsgguaranted)
	throws IOException {
	netmsgguaranted.writeByte((bSightAutomation ? 1 : 0) | (bSightBombDump
								? 2 : 0));
	netmsgguaranted.writeFloat(fSightCurDistance);
	netmsgguaranted.writeByte((int) fSightCurForwardAngle);
	netmsgguaranted.writeByte((int) ((fSightCurSideslip + 3.0F)
					 * 33.33333F));
	netmsgguaranted.writeFloat(fSightCurAltitude);
	netmsgguaranted.writeByte((int) (fSightCurSpeed / 2.5F));
	netmsgguaranted.writeByte((int) (fSightCurReadyness * 200.0F));
    }
    
    public void typeBomberReplicateFromNet(NetMsgInput netmsginput)
	throws IOException {
	int i = netmsginput.readUnsignedByte();
	bSightAutomation = (i & 0x1) != 0;
	bSightBombDump = (i & 0x2) != 0;
	fSightCurDistance = netmsginput.readFloat();
	fSightCurForwardAngle = (float) netmsginput.readUnsignedByte();
	fSightCurSideslip
	    = -3.0F + (float) netmsginput.readUnsignedByte() / 33.33333F;
	fSightCurAltitude = netmsginput.readFloat();
	fSightCurSpeed = (float) netmsginput.readUnsignedByte() * 2.5F;
	fSightCurReadyness = (float) netmsginput.readUnsignedByte() / 200.0F;
    }
    
    protected void moveRudder(float f) {
	this.hierMesh().chunkSetAngles("Rudder1_D0", 0.0F, -30.0F * f, 0.0F);
	this.hierMesh().chunkSetAngles("Rudder2_D0", 0.0F, -30.0F * f, 0.0F);
    }
}
