-
Notifications
You must be signed in to change notification settings - Fork 77
Introduce ScriptObject class for object scripting #520
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
Changes from 2 commits
9e84c97
eb05219
e714c0a
75010fb
652d6a5
a35d4ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,6 +234,7 @@ enum KEYWORD | |
KW_M_TRIGGER, // INF | ||
// TFE ADDED | ||
KW_SCRIPTCALL, | ||
KW_NAME, | ||
KW_COUNT | ||
}; | ||
|
||
|
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> | ||
|
@@ -159,16 +161,77 @@ 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 || strcmp(cname, "") == 0 || 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. Return value is the number of objects in the result. | ||
int GS_Level::getAllObjectsByName(std::string name, CScriptArray& results) | ||
|
||
{ | ||
const char* cname = name.c_str(); | ||
if (!cname || strcmp(cname, "") == 0 || s_objectRefList.empty()) | ||
{ | ||
return 0; | ||
} | ||
|
||
int count = 0; | ||
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); | ||
count++; | ||
} | ||
} | ||
|
||
return count; | ||
} | ||
|
||
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); | ||
{ | ||
|
@@ -229,6 +292,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); | ||
|
There was a problem hiding this comment.
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?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.