Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 2 additions & 26 deletions TheForceEngine/TFE_DarkForces/Scripting/gs_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,34 +429,10 @@ namespace TFE_DarkForces
}
}

// Moved to Player.cpp to avoid circular dependency
bool hasWeapon(s32 weapon)
{
switch (weapon)
{
case WPN_PISTOL:
return s_playerInfo.itemPistol == JTRUE;

case WPN_RIFLE:
return s_playerInfo.itemRifle == JTRUE;

case WPN_REPEATER:
return s_playerInfo.itemAutogun == JTRUE;

case WPN_FUSION:
return s_playerInfo.itemFusion == JTRUE;

case WPN_MORTAR:
return s_playerInfo.itemMortar == JTRUE;

case WPN_CONCUSSION:
return s_playerInfo.itemConcussion == JTRUE;

case WPN_CANNON:
return s_playerInfo.itemCannon == JTRUE;

default:
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ifeldshteyn
Can you please revert this -- you can't directly use player_hasWeapon from player.cpp because the argument it takes is not based on the same data.

The argument here is the WeaponId enum where
FIST = 0
PISTOL = 1
RIFLE = 2
etc.

Whereas player.cpp player_hasWeapon uses the keyboard numbers
FIST = 1
PISTOL = 2
RIFLE = 3
...

There are also a couple of other minor differences -- eg. player_hasWeapon also assesses whether you have detonator and mines ammo.
And the return value is JBool instead of primitive bool

So it is best to just leave the gs_player function as is.

return player_hasWeapon(weapon);
}

void giveWeapon(s32 weapon)
Expand Down
1 change: 1 addition & 0 deletions TheForceEngine/TFE_DarkForces/Scripting/gs_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ namespace TFE_DarkForces
public:
bool scriptRegister(ScriptAPI api) override;
};
bool hasWeapon(s32 weapon);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can now be reverted too, it doesn't have to be exposed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is complete @jerethk

}
15 changes: 15 additions & 0 deletions TheForceEngine/TFE_DarkForces/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
// Internal types need to be included in this case.
#include <TFE_Jedi/InfSystem/infTypesInternal.h>
#include <TFE_Jedi/Renderer/jediRenderer.h>
#include <TFE_DarkForces/Scripting/gs_player.h>
Copy link
Contributor

@jerethk jerethk Sep 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be uncomfortable doing this.
I think referencing scripting functionality from the base-game is a pattern best avoided.
Scripting has a dependency on the base-game; the reverse should not be true.
(what do you think @luciusDXL ?)

What you could do instead is use the existing player_hasWeapon() function in player.cpp
Note that this function (annoyingly) does not use the WeaponId Enum as its parameter, it instead uses weaponIndex which appears to be based on the keyboard hotkeys, i.e. fist = 1, pistol = 2, rifle = 3....
So you will have to translate from WeaponId to weaponIndex -- but AFAICS it is simply a matter of adding 1 to the WeaponId.

So this should work:

if (!player_hasWeapon(s_playerInfo.curWeapon + 1))
{

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, factor out any common functions and use those. Don't call script functions from within the game (unless it is related to scripting).


// TFE
#include <TFE_System/tfeMessage.h>
Expand Down Expand Up @@ -326,6 +327,7 @@ namespace TFE_DarkForces
// TFE
void player_warp(const ConsoleArgList& args);
void player_sector(const ConsoleArgList& args);
JBool player_hasWeapon(s32 weapon);

///////////////////////////////////////////
// API Implentation
Expand Down Expand Up @@ -808,6 +810,19 @@ namespace TFE_DarkForces
disableNightVision();
hud_clearMessage();
}

// Don't start the game with a weapon you don't have after overrides.
if (!player_hasWeapon(s_playerInfo.curWeapon))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will have to be s_playerInfo.curWeapon + 1 to work correctly

But you should double check to be sure.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ifeldshteyn
I think u missed this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ifeldshteyn
I think u missed this

{
if (s_playerInfo.itemPistol)
{
s_playerInfo.curWeapon = WPN_PISTOL;
}
else
{
s_playerInfo.curWeapon = WPN_FIST;
}
}
}

void player_createController(JBool clearData)
Expand Down