Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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_Asset/dfKeywords.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ static const char* c_keywords[] =
"M_TRIGGER",
// TFE
"SCRIPTCALL:",
"NAME:"
};

#define KEYWORD_COUNT TFE_ARRAYSIZE(c_keywords)
Expand Down
1 change: 1 addition & 0 deletions TheForceEngine/TFE_Asset/dfKeywords.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ enum KEYWORD
KW_M_TRIGGER, // INF
// TFE ADDED
KW_SCRIPTCALL,
KW_NAME,
KW_COUNT
};

Expand Down
2 changes: 2 additions & 0 deletions TheForceEngine/TFE_DarkForces/Actor/actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,8 @@ namespace TFE_DarkForces
corpse->worldWidth = 0;
corpse->entityFlags |= ETFLAG_CORPSE;
sector_addObject(obj->sector, corpse);

obj_addToRefList(corpse, ObjRefType_Corpse); // scripting
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not stick obj_addToRefList inside sector_addobject so you don't update multiple files?

Copy link
Contributor Author

@jerethk jerethk Apr 9, 2025

Choose a reason for hiding this comment

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

Because there are different types of objects (corpse, spawned item, projectile, etc.) and once you are inside sector_addObject you have no idea what type of object it is.
See the ObjectRefType enum

The idea is that eventually there may be functionality to let you get all objects of a certain category so you can do something with them.
For example make all projectiles stop in mid-air. Make all corpses levitate/vanish. Or whatever.

}
}
actor_kill();
Expand Down
1 change: 1 addition & 0 deletions TheForceEngine/TFE_DarkForces/Actor/bobaFett.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ namespace TFE_DarkForces
corpse->worldHeight = 0;
corpse->entityFlags |= (ETFLAG_CORPSE | ETFLAG_KEEP_CORPSE);
sector_addObject(local(obj)->sector, corpse);
obj_addToRefList(corpse, ObjRefType_Corpse); // scripting

local(physicsActor)->alive = JFALSE;
actor_handleBossDeath(local(physicsActor));
Expand Down
2 changes: 2 additions & 0 deletions TheForceEngine/TFE_DarkForces/Actor/dragon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,8 @@ namespace TFE_DarkForces
corpse->worldHeight = 0;
corpse->entityFlags |= (ETFLAG_CORPSE | ETFLAG_KEEP_CORPSE);
sector_addObject(sector, corpse);

obj_addToRefList(corpse, ObjRefType_Corpse); // scripting
}
local(physicsActor)->alive = JFALSE;
actor_handleBossDeath(local(physicsActor));
Expand Down
2 changes: 2 additions & 0 deletions TheForceEngine/TFE_DarkForces/Actor/mousebot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ namespace TFE_DarkForces
newObj->worldWidth = 0;
newObj->worldHeight = 0;
sector_addObject(local(sector), newObj);

obj_addToRefList(newObj, ObjRefType_Corpse); // scripting
}

// Spawn a battery.
Expand Down
2 changes: 2 additions & 0 deletions TheForceEngine/TFE_DarkForces/Actor/phaseOne.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,8 @@ namespace TFE_DarkForces
corpse->worldHeight = 0;
corpse->entityFlags |= (ETFLAG_CORPSE | ETFLAG_KEEP_CORPSE);
sector_addObject(sector, corpse);

obj_addToRefList(corpse, ObjRefType_Corpse); // scripting
}
local(physicsActor)->alive = JFALSE;
actor_handleBossDeath(local(physicsActor));
Expand Down
2 changes: 2 additions & 0 deletions TheForceEngine/TFE_DarkForces/Actor/phaseThree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,8 @@ namespace TFE_DarkForces
corpse->worldHeight = 0;
corpse->entityFlags |= (ETFLAG_CORPSE | ETFLAG_KEEP_CORPSE);
sector_addObject(sector, corpse);

obj_addToRefList(corpse, ObjRefType_Corpse); // scripting
}
local(physicsActor)->alive = JFALSE;
actor_handleBossDeath(local(physicsActor));
Expand Down
1 change: 1 addition & 0 deletions TheForceEngine/TFE_DarkForces/Actor/phaseTwo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ namespace TFE_DarkForces
corpse->worldHeight = 0;
corpse->entityFlags |= (ETFLAG_CORPSE | ETFLAG_KEEP_CORPSE);
sector_addObject(sector, corpse);
obj_addToRefList(corpse, ObjRefType_Corpse); // scripting

// Create Plasma pickup
SecObject* item = item_create(ITEM_PLASMA);
Expand Down
1 change: 1 addition & 0 deletions TheForceEngine/TFE_DarkForces/Actor/scenery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace TFE_DarkForces
newObj->worldWidth = obj->worldWidth;

sector_addObject(obj->sector, newObj);
obj_addToRefList(newObj, ObjRefType_Corpse); // scripting
actor_kill();
return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions TheForceEngine/TFE_DarkForces/Actor/sewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ namespace TFE_DarkForces
corpse->entityFlags |= ETFLAG_CORPSE;
corpse->worldWidth = 0;
sector_addObject(sector, corpse);

obj_addToRefList(corpse, ObjRefType_Corpse); // scripting
}
actor_kill();
return 0;
Expand Down
62 changes: 62 additions & 0 deletions TheForceEngine/TFE_DarkForces/Scripting/gs_level.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include <cstring>
#include "gs_level.h"
#include "scriptTexture.h"
#include "scriptElev.h"
#include "scriptWall.h"
#include "scriptSector.h"
#include "scriptObject.h"
#include <TFE_DarkForces/player.h>
#include <TFE_DarkForces/projectile.h>
#include <TFE_System/system.h>
Expand Down Expand Up @@ -159,16 +161,73 @@ namespace TFE_DarkForces
setProjectileGravityAccel(FIXED(pGrav));
}

ScriptObject GS_Level::getObjectById(s32 id)
{
if (id < 0 || id >= s_objectRefList.size())
{
TFE_System::logWrite(LOG_ERROR, "Level Script", "Runtime error, invalid objectID %d.", id);
id = -1;
}

ScriptObject object(id);
return object;
}

ScriptObject GS_Level::getObjectByName(std::string name)
{
const char* cname = name.c_str();
if (!cname || name.empty() || s_objectRefList.empty())
{
ScriptObject object(-1);
return object;
}

s32 objectId = -1;
for (s32 i = 0; i < s_objectRefList.size(); i++)
{
if (strcasecmp(cname, s_objectRefList[i].name) == 0)
{
objectId = i;
break;
}
}

ScriptObject object(objectId);
return object;
}

// Objects will be contained in the results array
void GS_Level::getAllObjectsByName(std::string name, CScriptArray& results)
{
const char* cname = name.c_str();
if (!cname || name.empty() || s_objectRefList.empty())
{
return;
}

results.Resize(0);
for (s32 i = 0; i < s_objectRefList.size(); i++)
{
if (strcasecmp(cname, s_objectRefList[i].name) == 0)
{
ScriptObject sObject(i);
results.InsertLast(&sObject);
}
}
}

bool GS_Level::scriptRegister(ScriptAPI api)
{
ScriptElev scriptElev;
ScriptTexture scriptTex;
ScriptSector scriptSector;
ScriptWall scriptWall;
ScriptObject scriptObject;
scriptElev.registerType();
scriptTex.registerType();
scriptWall.registerType();
scriptSector.registerType();
scriptObject.registerType();

ScriptClassBegin("Level", "level", api);
{
Expand Down Expand Up @@ -229,6 +288,9 @@ namespace TFE_DarkForces
ScriptObjMethod("Sector getSector(int)", getSectorById);
ScriptObjMethod("Elevator getElevator(int)", getElevator);
ScriptObjMethod("void findConnectedSectors(Sector initSector, uint, array<Sector>&)", findConnectedSectors);
ScriptObjMethod("Object getObject(int)", getObjectById);
ScriptObjFunc("Object getObject(string)", getObjectByName);
ScriptObjFunc("int getObjectsByName(string, array<Object>&)", getAllObjectsByName);

ScriptPropertySet("void set_gravity(int)", setGravity);
ScriptPropertySet("void set_projectileGravity(int)", setProjectileGravity);
Expand Down
4 changes: 4 additions & 0 deletions TheForceEngine/TFE_DarkForces/Scripting/gs_level.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace TFE_DarkForces
{
class ScriptSector;
class ScriptElev;
class ScriptObject;

class GS_Level : public ScriptAPIClass
{
Expand All @@ -26,6 +27,9 @@ namespace TFE_DarkForces

ScriptSector getSectorById(s32 id);
ScriptElev getElevator(s32 id);
ScriptObject getObjectById(s32 id);
static ScriptObject getObjectByName(std::string name);
static void getAllObjectsByName(std::string name, CScriptArray& result);
void findConnectedSectors(ScriptSector initSector, u32 matchProp, CScriptArray& results);
void setGravity(s32 grav);
void setProjectileGravity(s32 grav);
Expand Down
Loading