Skip to content

Conversation

jerethk
Copy link
Contributor

@jerethk jerethk commented Oct 2, 2024

The aim is to give people a simple way to define custom enemy/AI logics in an external JSON file

  • An actor setup method that creates an ActorDispatch logic from custom values
  • A data structure that holds custom logic values (VOC file names, hitpoints, projectile, drop item, attack range, etc.)
  • Code which parses JSON and loads the custom logic data into settings
  • Code which will search for a matching custom logic from a list and then call the setup method if found
  • Amendments have been made to support custom logic use with generators
  • Amendments to the attack function (in Actor.cpp) allowing mortars fired by AI to behave like thermal detonators (fired upwards in an arc)
  • Custom logics will also be loaded from inside mod ZIPs

@jerethk jerethk marked this pull request as draft October 2, 2024 13:29
@jerethk jerethk force-pushed the CUSTOM_LOGIC_PROPOSAL branch 6 times, most recently from 2a76061 to 6b5459c Compare October 8, 2024 12:41
@jerethk jerethk marked this pull request as ready for review October 12, 2024 10:38
@jerethk jerethk force-pushed the CUSTOM_LOGIC_PROPOSAL branch 3 times, most recently from 1f9b981 to 6b5043e Compare October 22, 2024 12:54

for (u32 i = 0; i < jsons.size(); i++)
{
TFE_System::logWrite(LOG_MSG, "LOGICS", "Parsing logic JSON");
Copy link
Owner

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.

Copy link
Contributor Author

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)

Copy link
Owner

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!

@jerethk jerethk force-pushed the CUSTOM_LOGIC_PROPOSAL branch from 6b5043e to 081e15b Compare October 25, 2024 13:33
@jerethk
Copy link
Contributor Author

jerethk commented Oct 25, 2024

I have squashed all my existing commits into a single commit, rebased on master, and fixed up the merge conflicts.

@jerethk jerethk marked this pull request as draft October 26, 2024 10:57
@jerethk jerethk force-pushed the CUSTOM_LOGIC_PROPOSAL branch 4 times, most recently from eca5371 to d1bab6e Compare October 27, 2024 09:31
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
@jerethk jerethk force-pushed the CUSTOM_LOGIC_PROPOSAL branch from d1bab6e to 152c9ce Compare October 27, 2024 11:28
@jerethk jerethk marked this pull request as ready for review October 27, 2024 11:40
@jerethk jerethk requested a review from luciusDXL October 27, 2024 12:03
@jerethk
Copy link
Contributor Author

jerethk commented Oct 27, 2024

@luciusDXL this is ready for another review
I've made the amendments you requested, plus a few other minor tweaks
Also decided to move all the new custom logic stuff out of TFE_Settings and into a new directory & namespace called TFE_ExternalData

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

@luciusDXL luciusDXL merged commit e6f9809 into luciusDXL:master Oct 29, 2024
1 check passed
memset(generator, 0, sizeof(Generator));

generator->type = genType;
generator->logicName = string(logicName);
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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).

Copy link
Contributor

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;
 

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants