Skip to content

New guard-range sexp - #7606

Open
TheForce172 wants to merge 6 commits into
scp-fs2open:masterfrom
TheForce172:feature/guard-range-by-guarder
Open

New guard-range sexp#7606
TheForce172 wants to merge 6 commits into
scp-fs2open:masterfrom
TheForce172:feature/guard-range-by-guarder

Conversation

@TheForce172

Copy link
Copy Markdown
Member

New guard-range sexp which allows different ranges for different guarders. As requested by Iain baker.

New guard-range sexp which allows different ranges for different guarders
@TheForce172 TheForce172 added feature A totally new sort of functionality Requested by Active Mod A feature request that has been requested by a mod that is actively in development. labels Jul 14, 2026
@MjnMixael

MjnMixael commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Can this not be done as an expansion of the old sexp instead of adding yet another -new sexp? I know there's convention for that but it's not really a user friendly convention.

@TheForce172

TheForce172 commented Jul 14, 2026

Copy link
Copy Markdown
Member Author

Not without changeing the old sexp's behaviour which were not allowed to do as it's been in a stable release.

@Sessile-Nomad

Copy link
Copy Markdown

I suspect I'm the only dev who has used the 'old' set-guard-range Sexp since 26 is so new and I have no issue with adding this to the existing Sexp 🙂

@Sessile-Nomad

Copy link
Copy Markdown

I did a poll to ask if anyone had used the set-guard-range Sexp and it looks like no one has except myself, and most people didn't even know it was 'a thing', so I think we can safely add to it without upsetting anyone.

@Goober5000 Goober5000 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got a review for this which I'll send over Discord.

@TheForce172

Copy link
Copy Markdown
Member Author

Ok, Is clang having a nervous breakdown today or something? This one makes no sense either?

@MjnMixael

MjnMixael commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Ok, Is clang having a nervous breakdown today or something? This one makes no sense either?

The codebase in general prefers nullptr over NULL always. Just replace it and it should pass.

EDIT: Oh I see.. it's saying there's a NULL on that line when there's clearly not. Uh. That's neat.

@Goober5000 Goober5000 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had some time to look at this more closely now. A few more comments inline. Also:

  • The set-guard-range definition in the Operators array still has 2 minimum arguments. It should have 3.
  • Since you've made extensive modifications to the SEXP, you could add your name as a co-author.
  • The warp_shipp = NULL; checks are clang checking unrelated lines that weren't included in the diff. They are from ship_render. Annoying, but just two lines to tweak and the warnings should go away.

Comment thread code/missioneditor/sexp_tree_model.cpp Outdated
case OP_SET_DEBRIS_FIELD:
case OP_NEBULA_TOGGLE_POOF:
case OP_NEBULA_FADE_POOF:
case OP_SET_GUARD_RANGE:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed now that OP_SET_GUARD_RANGE is being modified instead of replaced.

Comment thread code/scripting/api/objs/ship.cpp Outdated
shipp->max_guard_radius = new_max_guard_radius;

return ade_set_args(L, "f", shipp->max_guard_radius);
return ADE_RETURN_NIL;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting MaxGuardRadius should return a value here, not nil. It will have to build the value by iterating through max_guard_ranges.

Comment thread code/ship/ship.h Outdated
float max_guard_radius; // Optional clamp for guard engagement/resume ranges; <= 0 means unused

SCP_vector<guard_range_entry>
max_guard_ranges; // Optional clamp for guard engagement/resume ranges; <= 0 means unused

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The <= 0 means unused comment is drift from the original numeric implementation. It should be updated

Comment thread code/ship/ship.h Outdated

//**************************************************************
void set_guard_range_ship(float range, const ship_registry_entry* ship_entry, ship* shipp);
//**************************************************************

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this indent ought to be fixed

Comment thread code/ai/aicode.cpp Outdated
if (configured > 0.0f) {
return configured;
for (const auto& range_entry : guarder_ship->max_guard_ranges) {
const int regester = ship_registry_get_index(Ships[guarded_objp->instance].ship_name);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at Claude's previous review a bit more closely, it noticed the right symptom but made the wrong recommendation. Since the guard information is only valid for the lifetime of a ship, it is appropriate to use the shipnum index into Ships[] as the stored index. The ship registry index adds complexity and extra processing for no benefit.

Now, doing this will risk leaving a stale guarded shipnum when the ship is destroyed, so the solution to that is to clean it up in ai_ship_destroy. You can check for stale guard thresholds in the "wipe out this ship as a target" loop.

@Sessile-Nomad

Copy link
Copy Markdown

Hi guys. I don't want to sound pushy but do we have an ETA or target date for this? If it's going to be a while I'll need to plan around it.

Also if I were to use the 'old' set-guard-range Sexp in a mission will I need to go back and change it for the new one once it's ready? Cheers 👍

@TheForce172

TheForce172 commented Aug 11, 2026

Copy link
Copy Markdown
Member Author

Sorry for the delay, my life got super busy suddenly out of nowhere and I hadn't had the chance to look at this. Baring any issues the version I just pushed should be ready to go in. I did have to rip out the scripting support as I simply don't have time right now to learn how to rewrite it for how we now do the sexp. If you have used the old sexp you will have to update but it should be obvious where as it should fail on running the sexp as it wont have enough parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature A totally new sort of functionality Requested by Active Mod A feature request that has been requested by a mod that is actively in development.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants