-
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
Conversation
2a76061
to
6b5459c
Compare
1f9b981
to
6b5043e
Compare
|
||
for (u32 i = 0; i < jsons.size(); i++) | ||
{ | ||
TFE_System::logWrite(LOG_MSG, "LOGICS", "Parsing logic JSON"); |
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.
Do we need to write log spam for each logic? It might be better to write at the top of the loop. You can write the number parsed at the end if desired.
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.
Ah, yes, thanks for picking this up, I agree.
(originally put that there when it was only loading a single JSON, rather than many)
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.
Once you move this out of the loop, I will squash and push the changes. :)
Thanks for adding this feature!
6b5043e
to
081e15b
Compare
I have squashed all my existing commits into a single commit, rebased on master, and fixed up the merge conflicts. |
eca5371
to
d1bab6e
Compare
Add generator support Load logics contained inside a mod's ZIP Let externally defined custom logics take precedence over hardcoded logics Prevent LOGIC: PLAYER from being overridden Apply thermal detonator logic (arcing trajectory) to STATE_FIRE1, for logics that do not have melee Use this for mortars as well, because they also have an arcing trajectory
Also add filename to log output when a JSON fails to parse
Their effect is not properly known and therefore I'm not sure if they're optimally named
Use floatToAngle() to convert angular values
& edit CMakeLists
d1bab6e
to
152c9ce
Compare
@luciusDXL this is ready for another review I will be using TFE_ExternalData when I externalise the projectile & weapon data (the next project!!) I think it would be better to have all this related code live together rather than piling it into Settings. Thanks |
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 comment
The 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 comment
The 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 comment
The 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 comment
The 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.
Don't use std::string since the only place you use this member you do ".c_str()" on it anyway.
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 comment
The 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.
The aim is to give people a simple way to define custom enemy/AI logics in an external JSON file
Actor.cpp
) allowing mortars fired by AI to behave like thermal detonators (fired upwards in an arc)