Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weapon jettison #80

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
8 changes: 7 additions & 1 deletion src/core/fscontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void FsFlightControl::Initialize(void)
ctlAileron=0.0;

ctlFireWeaponButtonExt=YSFALSE;
ctlJettisonWeaponButtonExt = YSFALSE;
ctlFireGunButtonExt=YSFALSE;
ctlFireAAMButtonExt=YSFALSE;
ctlFireAGMButtonExt=YSFALSE;
Expand All @@ -58,6 +59,7 @@ void FsFlightControl::Initialize(void)
ctlCycleSmokeSelectorButtonExt=YSFALSE;

ctlFireWeaponButton=YSFALSE;
ctlToggleJettisonWeaponButton = YSFALSE;
ctlFireGunButton=YSFALSE;
ctlFireAAMButton=YSFALSE;
ctlFireAGMButton=YSFALSE;
Expand Down Expand Up @@ -464,6 +466,7 @@ YSRESULT FsFlightControl::ProcessButtonFunction(const double &/*cTime*/,FsExiste
case FSBTF_BRAKEHOLD: // Brake On While Holding
case FSBTF_FIREGUN: // Fire Machine Gun
case FSBTF_SMOKE: // Smoke
case FSBTF_TOGGLE_JETTISON_WEAPON:
break;

case FSBTF_TOGGLEALLDOOR:
Expand Down Expand Up @@ -598,6 +601,7 @@ YSRESULT FsFlightControl::ReadControl
// <<

ctlFireWeaponButton=YsOr(ctlAssign.IsButtonPressed(FSBTF_FIREWEAPON,joy),ctlFireWeaponButtonExt);
ctlToggleJettisonWeaponButton = YsOr(ctlAssign.IsButtonPressed(FSBTF_TOGGLE_JETTISON_WEAPON, joy), ctlJettisonWeaponButtonExt);
ctlFireGunButton=YsOr(ctlAssign.IsButtonPressed(FSBTF_FIREGUN,joy),ctlFireGunButtonExt);
ctlFireAAMButton=YsOr(ctlAssign.IsButtonPressed(FSBTF_FIREAAM,joy),ctlFireAAMButtonExt);
ctlFireAGMButton=YsOr(ctlAssign.IsButtonPressed(FSBTF_FIREAGM,joy),ctlFireAGMButtonExt);
Expand All @@ -609,6 +613,7 @@ YSRESULT FsFlightControl::ReadControl
ctlCycleSmokeSelectorButton=YsOr(ctlAssign.IsButtonPressed(FSBTF_CYCLESMOKESELECTOR,joy),ctlCycleSmokeSelectorButtonExt);

ctlFireWeaponButtonExt=YSFALSE;
ctlJettisonWeaponButtonExt = YSFALSE;
ctlFireGunButtonExt=YSFALSE;
ctlFireAAMButtonExt=YSFALSE;
ctlFireAGMButtonExt=YSFALSE;
Expand Down Expand Up @@ -1343,7 +1348,8 @@ static struct FsButtonFunctionString fsButtonFuncStr[]=
{FSBTF_SENSITIVITYUP, "SENSITIVITYUP", "Increase Sensitivity"},
{FSBTF_SENSITIVITYDOWN, "SENSITIVITYDOWN", "Decrease Sensitivity"},

{FSBTF_SWITCHVIEWTARGET, "SWITCHVIEWTARGET", "Switch View Target"}
{FSBTF_SWITCHVIEWTARGET, "SWITCHVIEWTARGET", "Switch View Target"},
{FSBTF_TOGGLE_JETTISON_WEAPON, "JETTISONWEAPON", "Toggle Jettison Selected Weapon"}
};

static struct FsKeyString fsKeyString[]=
Expand Down
5 changes: 4 additions & 1 deletion src/core/fscontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ enum FSBUTTONFUNCTION
FSBTF_PROPBACKWARD, // Decrease rpm

FSBTF_SWITCHVIEWTARGET, // Switch view target
FSBTF_TOGGLE_JETTISON_WEAPON, // Jettison current weapon

FSBTF_NUMBUTTONFUNCTION
FSBTF_NUMBUTTONFUNCTION
};

const char *FsGetAxisFuncLabel(FSAXISFUNCTION fnc);
Expand Down Expand Up @@ -230,6 +231,7 @@ class FsFlightControl

// Buttn press from external source (script) >>
YSBOOL ctlFireWeaponButtonExt;
YSBOOL ctlJettisonWeaponButtonExt;
YSBOOL ctlFireGunButtonExt;
YSBOOL ctlFireAAMButtonExt;
YSBOOL ctlFireAGMButtonExt;
Expand All @@ -242,6 +244,7 @@ class FsFlightControl
// Buttn press from external source (script) <<

YSBOOL ctlFireWeaponButton;
YSBOOL ctlToggleJettisonWeaponButton;
YSBOOL ctlFireGunButton;
YSBOOL ctlFireAAMButton;
YSBOOL ctlFireAGMButton;
Expand Down
15 changes: 10 additions & 5 deletions src/core/fshud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void FsHeadUpDisplay::SetAreaByCenter(long cx,long cy,long dx,long dy)
hei=dy;
}

void FsHeadUpDisplay::Draw(YSBOOL autoPilot,const class FsCockpitIndicationSet &cockpitIndicationSet)
void FsHeadUpDisplay::Draw(YSBOOL autoPilot,const class FsCockpitIndicationSet &cockpitIndicationSet, YSBOOL shouldJettison)
{
const FsInstrumentIndication &inst=cockpitIndicationSet.inst;

Expand All @@ -56,7 +56,7 @@ void FsHeadUpDisplay::Draw(YSBOOL autoPilot,const class FsCockpitIndicationSet &
}
DrawFuelLeft(inst.fuelRemain[0],inst.fuelCapacity[0]);
DrawG(inst.gForce);
DrawWeapon(cockpitIndicationSet.ammo);
DrawWeapon(cockpitIndicationSet.ammo, shouldJettison);
DrawMach(inst.mach);
DrawElevator(inst.elevator,inst.elevatorTrim,YSFALSE);
DrawAileron(inst.aileron,YSFALSE);
Expand All @@ -75,7 +75,7 @@ void FsHeadUpDisplay::Draw(YSBOOL autoPilot,const class FsCockpitIndicationSet &
DrawBank(inst.bank);
}

void FsHeadUpDisplay::DrawWeapon(const FsAmmunitionIndication &ammo)
void FsHeadUpDisplay::DrawWeapon(const FsAmmunitionIndication &ammo, YSBOOL shouldJettison)
{
int x,y;

Expand All @@ -86,15 +86,20 @@ void FsHeadUpDisplay::DrawWeapon(const FsAmmunitionIndication &ammo)
{
YsColor col;
auto str=a.FormatString();
if(YSTRUE==a.ReadyToFire())
if (shouldJettison && a.selected)
{
str.Append(" - JETTISON!");
col = YsYellow();
}
else if(YSTRUE==a.ReadyToFire())
{
col=hudCol;
}
else
{
col=YsRed();
}
FsDrawString(x,y,str,hudCol);
FsDrawString(x,y,str,col);
y+=FONTPITCH;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/fshud.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class FsHeadUpDisplay
void SetArea(long x1,long y1,long dx,long dy);
void SetAreaByCenter(long cx,long cy,long dx,long dy);

void Draw(YSBOOL autoPilot,const class FsCockpitIndicationSet &cockpitIndicationSet);
void Draw(YSBOOL autoPilot,const class FsCockpitIndicationSet &cockpitIndicationSet, YSBOOL shouldJettison = YSFALSE);
void DrawCrossHair(void);
void DrawHeading(const YsAtt3 &hdg,YSBOOL showHdgBug,const double &hdgBug,YSBOOL selected);
void DrawThrottle(int nEng,const double thr[],const YSBOOL ab[]);
void DrawNozzle(const YsVec3 &vec);
void DrawFuelLeft(double fuel,double maxFuel);
void DrawWeapon(const class FsAmmunitionIndication &ammo);
void DrawWeapon(const class FsAmmunitionIndication &ammo, YSBOOL shouldJettison=YSFALSE);
void DrawG(double g);
void DrawMach(double mach);
void DrawElevator(double elv,double trim,YSBOOL au);
Expand Down
10 changes: 8 additions & 2 deletions src/core/fshud2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1597,16 +1597,22 @@ void FsHud2::DrawAirSpeed(const double &x0,const double &y0,const double &wid,co

void FsHud2::DrawAmmo(
const double &x0,const double &y0,const double &fontWid,const double &fontHei,
const class FsAmmunitionIndication &ammo)
const class FsAmmunitionIndication &ammo, YSBOOL shouldJettison)
{
float x=(float)x0;
float y=(float)(y0+fontHei);

for(auto &a : ammo.ammoArray)
{
auto str=a.FormatString();

YsColor col;
if(YSTRUE==a.ReadyToFire())
if (shouldJettison && a.selected)
{
str.Append(" - JETTISON!");
col = YsYellow();
}
else if(YSTRUE==a.ReadyToFire())
{
col=hudCol;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/fshud2.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class FsHud2

void DrawAmmo(
const double &x0,const double &y0,const double &fontWid,const double &fontHei,
const class FsAmmunitionIndication &ammo);
const class FsAmmunitionIndication &ammo, YSBOOL shouldJettison=YSFALSE);

void DrawVelocityVectorIndicator(const YsVec3 &viewPos,const YsAtt3 &viewAtt,const YsVec3 &vel);

Expand Down
31 changes: 23 additions & 8 deletions src/core/fssimulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3886,13 +3886,22 @@ void FsSimulation::SimMove(const double &dt)
{
airplane->Prop().FireGunIfVirtualTriggerIsPressed(currentTime,dt,this,bulletHolder,airplane);

YSBOOL fired,blockedByBombBay;
YSBOOL fired,blockedByBombBay,jettisoned;
FSWEAPONTYPE woc;
fired=airplane->Prop().ProcessVirtualButtonPress(blockedByBombBay,woc,this,currentTime,bulletHolder,airplane);
if(fired==YSTRUE && airplane==GetPlayerAirplane())
fired=airplane->Prop().ProcessVirtualButtonPress(blockedByBombBay,woc,this,currentTime,bulletHolder,airplane, jettisoned);
if (fired == YSTRUE && jettisoned == YSTRUE && airplane == GetPlayerAirplane())
{
if (woc == FSWEAPON_FLARE)
{
FsSoundSetOneTime(FSSND_ONETIME_ROCKET);
}
else if (woc != FSWEAPON_GUN && woc != FSWEAPON_SMOKE)
{
FsSoundSetOneTime(FSSND_ONETIME_BOMBSAWAY);
}
}
else if(fired==YSTRUE && jettisoned == YSFALSE && airplane==GetPlayerAirplane())
{


switch(woc)
{
case FSWEAPON_AIM9:
Expand Down Expand Up @@ -5718,6 +5727,12 @@ void FsSimulation::SimProcessButtonFunction(FSBUTTONFUNCTION fnc,FSUSERCONTROL u
userInput.ctlFireWeaponButtonExt=YSTRUE;
}
break;
case FSBTF_TOGGLE_JETTISON_WEAPON: // Jettison Selected Weapon
if (FSUSC_SCRIPT == userControl)
{
userInput.ctlJettisonWeaponButtonExt = YSTRUE;
}
break;
case FSBTF_FIREGUN: // Fire Machine Gun
if(FSUSC_SCRIPT==userControl)
{
Expand Down Expand Up @@ -7706,11 +7721,11 @@ void FsSimulation::SimDrawForeground(const ActualViewMode &actualViewMode,const
YSBOOL autoPilot=(NULL!=playerPlane->GetAutopilot() ? YSTRUE : YSFALSE);
if(long(currentTime*2.0)%2==0)
{
hud->Draw(autoPilot,cockpitIndicationSet);
hud->Draw(autoPilot, cockpitIndicationSet, playerPlane->Prop().GetShouldJettisonWeapon());
}
else
{
hud->Draw(YSFALSE,cockpitIndicationSet);
hud->Draw(YSFALSE,cockpitIndicationSet, playerPlane->Prop().GetShouldJettisonWeapon());
}

SimDraw2dVor1(cockpitIndicationSet);
Expand Down Expand Up @@ -8280,7 +8295,7 @@ void FsSimulation::SimDrawHud3d(const YsVec3 &fakeViewPos,const YsAtt3 &instView
loading.Append(FSWEAPON_SMOKE);
loading.Append((int)smokeOil);
}
hud2->DrawAmmo(-0.9,0.9,0.025,0.04,cockpitIndicationSet.ammo);
hud2->DrawAmmo(-0.9,0.9,0.025,0.04,cockpitIndicationSet.ammo, playerPlane->Prop().GetShouldJettisonWeapon());


double ix=1.25;
Expand Down
Loading