-
Notifications
You must be signed in to change notification settings - Fork 77
Custom logic proposal #451
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 all commits
e85e2e6
aaa9a3b
fa8c617
994dc5f
7d612a9
cceed6d
152c9ce
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 |
---|---|---|
|
@@ -17,6 +17,8 @@ | |
#include <TFE_FileSystem/paths.h> | ||
#include <TFE_FileSystem/filestream.h> | ||
#include <TFE_Jedi/Serialization/serialization.h> | ||
#include <TFE_DarkForces/logic.h> | ||
#include <TFE_Settings/settings.h> | ||
|
||
using namespace TFE_Jedi; | ||
|
||
|
@@ -38,6 +40,8 @@ namespace TFE_DarkForces | |
Tick wanderTime; | ||
Wax* wax; | ||
JBool active; | ||
|
||
string logicName; // JK: added to store a custom logic name | ||
}; | ||
|
||
void generatorTaskFunc(MessageType msg) | ||
|
@@ -104,13 +108,28 @@ namespace TFE_DarkForces | |
|
||
assert(gen->entities && allocator_validate(gen->entities)); | ||
|
||
TFE_Settings_Game* gameSettings = TFE_Settings::getGameSettings(); | ||
|
||
fixed16_16 dy = TFE_Jedi::abs(s_playerObject->posWS.y - spawn->posWS.y); | ||
fixed16_16 dist = dy + distApprox(spawn->posWS.x, spawn->posWS.z, s_playerObject->posWS.x, s_playerObject->posWS.z); | ||
if (dist >= gen->minDist && dist <= gen->maxDist && !actor_canSeeObject(spawn, s_playerObject)) | ||
{ | ||
sprite_setData(spawn, gen->wax); | ||
obj_setEnemyLogic(spawn, gen->type); | ||
|
||
// Search the externally defined logics for a match | ||
TFE_ExternalData::CustomActorLogic* customLogic; | ||
customLogic = tryFindCustomActorLogic(gen->logicName.c_str()); | ||
if (customLogic && gameSettings->df_jsonAiLogics) | ||
{ | ||
obj_setCustomActorLogic(spawn, customLogic); | ||
} | ||
else if (gen->type != -1) | ||
{ | ||
obj_setEnemyLogic(spawn, gen->type); | ||
} | ||
|
||
Logic** head = (Logic**)allocator_getHead_noIterUpdate((Allocator*)spawn->logic); | ||
if (!head) { break; } // JK: This is to prevent a crash happening when an invalid logic is set to a generator | ||
ActorDispatch* actorLogic = *((ActorDispatch**)head); | ||
|
||
actorLogic->flags &= ~1; | ||
|
@@ -211,12 +230,13 @@ namespace TFE_DarkForces | |
return JFALSE; | ||
} | ||
|
||
Logic* obj_createGenerator(SecObject* obj, LogicSetupFunc* setupFunc, KEYWORD genType) | ||
Logic* obj_createGenerator(SecObject* obj, LogicSetupFunc* setupFunc, KEYWORD genType, const char* logicName) | ||
{ | ||
Generator* generator = (Generator*)level_alloc(sizeof(Generator)); | ||
memset(generator, 0, sizeof(Generator)); | ||
|
||
generator->type = genType; | ||
generator->logicName = string(logicName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This crashes with gcc-14/15; changing it to "generator->logicName = logicName" fixes it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mlauss2 thanks for picking this up - are you able to raise a fix? const char* will implicitly cast to string? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should change this member from "string logicName" to "char logicName[16]" and do "strncpy(generator->logicName, logicName, 15);" (or whatever the max length of a logic name is). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add something like this on top of this patchset, it survived a few hours of playtesting. index e5b9878b..83b47218 100644
--- a/TheForceEngine/TFE_DarkForces/generator.cpp
+++ b/TheForceEngine/TFE_DarkForces/generator.cpp
@@ -40,8 +40,7 @@ namespace TFE_DarkForces
Tick wanderTime;
Wax* wax;
JBool active;
-
- string logicName; // JK: added to store a custom logic name
+ char logicName[32]; // JK: added to store a custom logic name
};
void generatorTaskFunc(MessageType msg)
@@ -118,7 +117,7 @@ namespace TFE_DarkForces
// Search the externally defined logics for a match
TFE_ExternalData::CustomActorLogic* customLogic;
- customLogic = tryFindCustomActorLogic(gen->logicName.c_str());
+ customLogic = tryFindCustomActorLogic(gen->logicName);
if (customLogic && gameSettings->df_jsonAiLogics)
{
obj_setCustomActorLogic(spawn, customLogic);
@@ -236,7 +235,8 @@ namespace TFE_DarkForces
memset(generator, 0, sizeof(Generator));
generator->type = genType;
- generator->logicName = string(logicName);
+ memset(generator->logicName, 0, 32);
+ strncpy(generator->logicName, logicName, 31);
generator->active = 1;
generator->delay = 0;
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mlauss2 thanks for that recommendation -- I've got a couple other PRs waiting review, I'll look at this as soon as those have gone through. |
||
generator->active = 1; | ||
generator->delay = 0; | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.