I am trying to introduce a function to a .java class file aircraft mod, that will have the effect of multiplying the speed calculated via the ‘flightmodel (FM) function. The mod is for the computer game ‘il2-1946’
This is how the speed is calculated in the ‘flightmodel class’.
public class FlightModelMain extends FMMath
{
public float getSpeedKMH()
{
return (float)(Vflow.x * 3.6000000000000001D);
}
public float getSpeed()
{
return (float)Vflow.x;
}
public void getSpeed(Vector3d vector3d)
{
vector3d.set(Vair);
}
public float getVertSpeed()
{
return (float)Vair.z;
}
type here
The speed of the actual aircraft in game is calculated the the ‘vector3d’ object in the above code. I have experimented with some Java modifications to try to implement the multiplier effect in game in the aircraft.class as shown below.
The vector 3d calculation is based off of the flight model parameters, but despite trying to push the parameters of flight model as far as possible, I seem to be running into an ‘in-game’ speed limit.
So I basically want to create a code that will take the calculated speed for the aircraft from the flight model, then apply a multiplier to that speed in the class file that the game will then use as the new speed for that aircraft only.
public void applySpeedMultiplier(float multiplier)
{
float currentSpeedKMH = ((FlightModelMain) super.FM).getSpeedKMH();
float newSpeedKMH = currentSpeedKMH * (2.0F); //put as (2.00F) for doubling? (0.5F) half
((FlightModelMainMultiplier) super.FM).setSpeedKMH(newSpeedKMH);
}
public void applySpeedMultiplier(float multiplier) {
Vector3d speedVector = new Vector3d();
flightModel.getSpeed(speedVector);
float currentSpeedKMH = (float) (speedVector.length() * 3.6);
float newSpeedKMH = currentSpeedKMH * multiplier;
flightModel.setSpeedKMH(newSpeedKMH);
}
}
I also made an extension to the ‘FlightModelMain’ containing the speed code, that would allow me to add any extra lines required in the .fm. javapackage
package com.maddox.il2.fm;
import com.maddox.JGP.*;
import com.maddox.il2.ai.*;
import com.maddox.il2.engine.*;
import com.maddox.il2.game.Main;
import com.maddox.il2.game.Mission;
import com.maddox.il2.objects.air.*;
import com.maddox.il2.objects.effects.Explosions;
import com.maddox.il2.objects.sounds.Voice;
import com.maddox.rts.*;
import java.io.*;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.StringTokenizer;
// Referenced classes of package com.maddox.il2.fm:
// FMMath, FlightModel, Controls, EnginesInterface,
// Mass, AircraftState, Squares, Supersonic,
// Arm, Gear, Polares, RealFlightModel,
// Atmosphere, Turret, Motor, Autopilotage
public class FlightModelMainMultiplier extends FlightModelMain
{
public FlightModelMainMultiplier(String arg0) {
super(arg0);
// TODO Auto-generated constructor stub
}
public void setSpeedKMH(float setSpeedKMH) {
Vflow.x = setSpeedKMH / 3.6f;
}
}
However, it does not appear to be having an effect in the game or equally causing the game to crash.
An error that I am finding in Eclipse is ‘Cannot cast from FlightModel to FlightModelMainMultiplier’, despite trying this code instead.
public void applySpeedMultiplier(float multiplier)
{
if (super.FM instanceof FlightModelMainMultiplier) {
float currentSpeedKMH = ((FlightModelMain) super.FM).getSpeedKMH();
float newSpeedKMH = currentSpeedKMH * multiplier;
((FlightModelMainMultiplier) super.FM).setSpeedKMH(newSpeedKMH);
} else if (super.FM instanceof FlightModelMain) {
float currentSpeedKMH = ((FlightModelMain) super.FM).getSpeedKMH();
float newSpeedKMH = currentSpeedKMH * multiplier;
((FlightModelMain) super.FM).setSpeedKMH(newSpeedKMH);
} else {
// Handle the case where super.FM is not an instance of FlightModelMain or FlightModelMainMultiplier
System.out.println("Cannot apply speed multiplier: super.FM is not an instance of FlightModelMain or FlightModelMainMultiplier");
}
}
What is the best way to adjust my code so can implement the speed multiplier function?