Skip to content
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

More message filters #5605

Merged
merged 6 commits into from
Oct 18, 2023
Merged

Conversation

naomimyselfandi
Copy link
Contributor

@naomimyselfandi naomimyselfandi commented Sep 16, 2023

This PR introduces a few enhancements to the dynamic message system:

  • Message filters can look at a ship's IFF.
  • A dynamic message can be filtered based on the presence of other ships in the mission, and can do so with a range check. Alongside an IFF filter, this can be used to play different versions of a message when the speaker is "in battle" or not.
  • The tiebreaker system can be further customized, for cases where two messages have filters but the author wants one to beat the other. (Maybe one of your pilots has a special arrival message for HoL ships, and another for enemy bombers. Currently, when this pilot announces HoL bombers, they'll pick one of those two at random. This feature lets you pick one message or the other.)
  • Lastly, as a QoL enhancement, when a message is assigned a mood, it can automatically exclude all other moods. (This could already be done manually, but it gets annoying when you add more moods...)

All of these features are desired for BTA's upcoming release.

@wookieejedi wookieejedi added enhancement A new feature or upgrade of an existing feature to add additional functionality. Requested by Active Mod A feature request that has been requested by a mod that is actively in development. Waiting for Stable Marks a pull request that is to be merged after the next stable release, due to a release cycle labels Sep 17, 2023
Copy link
Member

@BMagnu BMagnu left a comment

Choose a reason for hiding this comment

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

A few small comments and questions, but looking good overall

@@ -403,6 +427,16 @@ void handle_legacy_backup_message(MissionMessage& msg, SCP_string wing_name) {
strcpy(msg.name, backup);
}

int lookup_mood(SCP_string& name) {
Copy link
Member

Choose a reason for hiding this comment

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

We should be sticking to making things like this name parameter const as often as we can

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is somewhere where my C++ is a little lacking. SCP_string const & means "a reference to an SCP_string which we promise not to change" and potentially allows for compiler optimizations, right? What about declaring the function itself const? (To be clear, I'm asking from an educational perspective ^^ )

Copy link
Member

Choose a reason for hiding this comment

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

Yes, basically.
SCP_string const & gives you a reference to a string you cannot change. The compiler will stop you from any things that would change the string, so not only allows it for more optimization, but also is simply a safeguard for you as the developer to not do things you shouldn't.
Declaring the function const in this context is not possible. You could declare the return type const (const int lookup_mood), but declaring the function const (int lookup_mood(...) const {) is only possible if it's a member function of a class (which it isn't, as a global function), and will basically mean "disallow any modification of member variables", which allows you to call the function on an object of that class which is const itself.

msg.mood = 0;
SCP_string buf;
stuff_string(buf, F_NAME);
msg.mood = lookup_mood(buf);
Copy link
Member

Choose a reason for hiding this comment

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

If a mood isn't found, msg.mood will now be set to -1 instead of 0. Which in turn means that erroneous moods for messages caused the messages to be boosted when the mood was actually 0.
While I doubt that that has been taken advantage off in an existing mod, it should probably at least get a comment here acknowledging that change, in case anyone comes looking in the future.

Copy link
Contributor Author

@naomimyselfandi naomimyselfandi Sep 24, 2023

Choose a reason for hiding this comment

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

Would it? Looking at the code on master, I'm not sure that msg.mood is actually initialized on a missing mood. Isn't that UB?
e: following up on Discord

Copy link
Member

Choose a reason for hiding this comment

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

True, turns out I was confusing things, and the default-initialization implicitly causing a zero-initialization is only correct for variables with a static lifetime

if (obj->flags[Object::Object_Flags::Should_be_dead]) {
continue;
}
if ((range >= 0) && (vm_vec_dist(&obj->pos, &Objects[sender->objnum].pos) > range)) {
Copy link
Member

Choose a reason for hiding this comment

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

>= ?
I mean, I guess an uninitialized range is set to -1, but is there ever a case where range == 0 is sensible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the sender itself is ignored (if (sender->objnum == i->objnum) { continue; }), the only way a range of 0 could ever be satisfied is with non-colliding objects in exactly the same position. I don't think it matters in practice, but > 0 is probably clearer, so I'm happy to make that change.

BMagnu
BMagnu previously approved these changes Sep 24, 2023
@TRBlount TRBlount dismissed BMagnu’s stale review October 14, 2023 21:15

Awaiting response to other reviews

@JohnAFernandez JohnAFernandez removed the Waiting for Stable Marks a pull request that is to be merged after the next stable release, due to a release cycle label Oct 16, 2023
@TRBlount TRBlount merged commit a6c1b1b into scp-fs2open:master Oct 18, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature or upgrade of an existing feature to add additional 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.

5 participants