Skip to content
Open
Show file tree
Hide file tree
Changes from 11 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
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

}
14 changes: 14 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 @@ -808,6 +809,19 @@ namespace TFE_DarkForces
disableNightVision();
hud_clearMessage();
}

// Don't start the game with a weapon you don't have after overrides.
if (!hasWeapon(s_playerInfo.curWeapon))
{
if (s_playerInfo.itemPistol)
{
s_playerInfo.curWeapon = WPN_PISTOL;
}
else
{
s_playerInfo.curWeapon = WPN_FIST;
}
}
}

void player_createController(JBool clearData)
Expand Down