Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion TheForceEngine/TFE_DarkForces/Scripting/gs_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,9 @@ namespace TFE_DarkForces
scriptElev.registerType();
scriptTex.registerType();
scriptWall.registerType();
scriptSector.registerType();
scriptObject.registerType();
scriptSector.registerType();
scriptObject.registerFunctions();

ScriptClassBegin("Level", "level", api);
{
Expand Down
10 changes: 10 additions & 0 deletions TheForceEngine/TFE_DarkForces/Scripting/gs_player.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "gs_player.h"
#include "scriptSector.h"
#include "assert.h"
#include <TFE_DarkForces/mission.h>
#include <TFE_DarkForces/pickup.h>
#include <TFE_DarkForces/weapon.h>
#include <TFE_Jedi/Collision/collision.h>
#include <TFE_Jedi/Level/levelData.h>
#include <TFE_FrontEndUI/frontEndUi.h>
#include <TFE_System/system.h>
#include <angelscript.h>
Expand Down Expand Up @@ -49,6 +51,13 @@ namespace TFE_DarkForces
s_reviveTick = s_curTick + 436;
}

ScriptSector getPlayerSector()
{
RSector* sec = s_playerObject->sector;
ScriptSector sector(sec->index);
return sector;
}

vec3_float getPlayerPosition()
{
return
Expand Down Expand Up @@ -652,6 +661,7 @@ namespace TFE_DarkForces
ScriptObjFunc("void setCamera()", setCamera);

// Position and velocity
ScriptPropertyGetFunc("Sector get_sector()", getPlayerSector);
ScriptPropertyGetFunc("float3 get_position()", getPlayerPosition);
ScriptPropertySetFunc("void set_position(float3)", setPlayerPosition);
ScriptPropertyGetFunc("float get_yaw()", getPlayerYaw);
Expand Down
11 changes: 11 additions & 0 deletions TheForceEngine/TFE_DarkForces/Scripting/scriptObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,16 @@ namespace TFE_DarkForces
ScriptEnumStr(PROJ_HOMING_MISSILE);
ScriptEnumStr(PROJ_PROBE_PROJ);
ScriptEnum("PROJ_BOBAFETT_BALL", PROJ_BOBAFET_BALL);
}

// Function registration has been separated from Type registration
// The ScriptObject type needs to be registered before registering ScriptSector functions
// ScriptObject functions need to be registered after registering ScriptSector
void ScriptObject::registerFunctions()
{
s32 res = 0;
asIScriptEngine* engine = (asIScriptEngine*)TFE_ForceScript::getEngine();
s_typeName = "Object";

// Checks
ScriptObjFunc("bool isValid()", isScriptObjectValid);
Expand All @@ -616,6 +626,7 @@ namespace TFE_DarkForces

// Getters
ScriptObjFunc("Sector getSector()", getSector);
ScriptPropertyGetFunc("Sector get_sector()", getSector);
ScriptPropertyGetFunc("float3 get_position()", getPosition);
ScriptPropertyGetFunc("float get_yaw()", getYaw);
ScriptPropertyGetFunc("float get_radius()", getWorldWidth);
Expand Down
1 change: 1 addition & 0 deletions TheForceEngine/TFE_DarkForces/Scripting/scriptObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace TFE_DarkForces
ScriptObject() : m_id(-1) {};
ScriptObject(s32 id) : m_id(id) {};
void registerType();
void registerFunctions();

public:
s32 m_id;
Expand Down
23 changes: 23 additions & 0 deletions TheForceEngine/TFE_DarkForces/Scripting/scriptSector.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include "scriptSector.h"
#include "scriptWall.h"
#include "scriptTexture.h"
#include "scriptObject.h"
#include <TFE_ForceScript/ScriptAPI-Shared/scriptMath.h>
#include <TFE_ForceScript/Angelscript/add_on/scriptarray/scriptarray.h>
#include <TFE_Jedi/Level/levelData.h>
#include <TFE_Jedi/Level/rwall.h>
#include <TFE_Jedi/Level/rsector.h>
#include <TFE_Jedi/Level/robjData.h>
#include <TFE_Jedi/InfSystem/message.h>
#include <angelscript.h>

Expand Down Expand Up @@ -197,6 +200,25 @@ namespace TFE_DarkForces
sendMessageToSector(messageType, evt, 0, sSector);
}

void getSectorObjects(CScriptArray& results, ScriptSector* sSector)
{
results.Resize(0);
if (!isScriptSectorValid(sSector)) { return; }

RSector* sector = &s_levelState.sectors[sSector->m_id];
SecObject** objList = sector->objectList;
for (s32 i = 0, idx = 0; i < sector->objectCount && idx < sector->objectCapacity; idx++)
{
SecObject* obj = objList[idx];
if (obj)
{
s32 objIndex = obj_getRefIndex(obj);
ScriptObject sObj(objIndex);
results.InsertLast(&sObj);
}
}
}

void ScriptSector::registerType()
{
s32 res = 0;
Expand All @@ -213,6 +235,7 @@ namespace TFE_DarkForces
ScriptObjFunc("void setFlag(int, uint)", setSectorFlag);
ScriptObjFunc("float2 getCenterXZ()", getCenterXZ);
ScriptObjFunc("Wall getWall(int)", getWall);
ScriptObjFunc("void getObjects(array<Object>&)", getSectorObjects);

ScriptObjFunc("void sendMessage(int)", sendMessageToSector1);
ScriptObjFunc("void sendMessage(int, uint)", sendMessageToSector2);
Expand Down