Skip to content

Commit

Permalink
mission goals hook
Browse files Browse the repository at this point in the history
  • Loading branch information
MjnMixael committed Jan 16, 2025
1 parent c9ccace commit 8fb5c64
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
39 changes: 29 additions & 10 deletions code/mission/missiongoals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "parse/parselo.h"
#include "parse/sexp.h"
#include "playerman/player.h"
#include "scripting/global_hooks.h"
#include "tracing/tracing.h"
#include "ui/ui.h"

Expand Down Expand Up @@ -738,28 +739,46 @@ void mission_goal_status_change( int goal_num, int new_status)
send_mission_goal_info_packet( goal_num, new_status, -1 );
}

bool isOverride = false;

if (scripting::hooks::OnMissionObjectivesChanged->isActive()) {
auto paramList = scripting::hook_param_list(scripting::hook_param("Name", 's', Mission_goals[goal_num].name),
scripting::hook_param("Description", 's', Mission_goals[goal_num].message),
scripting::hook_param("Type", 'i', type + 1),
scripting::hook_param("State", 'b', new_status == GOAL_COMPLETE));
if (scripting::hooks::OnMissionObjectivesChanged->isOverride(paramList)) {
isOverride = true; // Override here only prevents displaying the goals and playing the music. Everything
// else still runs.
}
scripting::hooks::OnMissionObjectivesChanged->run(paramList);
}

type = Mission_goals[goal_num].type & GOAL_TYPE_MASK;
Mission_goals[goal_num].satisfied = new_status;
if ( new_status == GOAL_FAILED ) {
// don't display bonus goal failure
if ( type != BONUS_GOAL ) {
if (type != BONUS_GOAL ) {

// only do HUD and music is goals are my teams goals.
// only do HUD and music if goals are my teams goals.
if ( (Game_mode & GM_NORMAL) || ((Net_player != NULL) && (Net_player->p_info.team == Mission_goals[goal_num].team)) ) {
hud_add_objective_messsage(type, new_status);
if ( !( Mission_goals[goal_num].flags & MGF_NO_MUSIC ) ) { // maybe play event music
event_music_primary_goal_failed();
if (!isOverride) {
hud_add_objective_messsage(type, new_status);
if (!(Mission_goals[goal_num].flags & MGF_NO_MUSIC)) { // maybe play event music
event_music_primary_goal_failed();
}
}
}
}
mission_log_add_entry( LOG_GOAL_FAILED, Mission_goals[goal_num].name.c_str(), nullptr, goal_num );
} else if ( new_status == GOAL_COMPLETE ) {
if ( (Game_mode & GM_NORMAL) || ((Net_player != NULL) && (Net_player->p_info.team == Mission_goals[goal_num].team))) {
hud_add_objective_messsage(type, new_status);
// cue for Event Music
if ( !(Mission_goals[goal_num].flags & MGF_NO_MUSIC) ) {
event_music_primary_goals_met();
}
if (!isOverride) {
hud_add_objective_messsage(type, new_status);
// cue for Event Music
if (!(Mission_goals[goal_num].flags & MGF_NO_MUSIC)) {
event_music_primary_goals_met();
}
}
mission_log_add_entry( LOG_GOAL_SATISFIED, Mission_goals[goal_num].name.c_str(), nullptr, goal_num );
}

Expand Down
9 changes: 9 additions & 0 deletions code/scripting/global_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,15 @@ const std::shared_ptr<Hook<>> OnCheat = Hook<>::Factory("On Cheat",
{ "Cheat", "string", "The cheat code the user typed" },
});

const std::shared_ptr<Hook<ShipDeathConditions>> OnMissionObjectivesChanged = Hook<ShipDeathConditions>::Factory(
"On Mission Objectives Changed", "Called when a goal is marked as failed or completed.",
{
{"Name", "string", "The name of the objective."},
{"Description", "string", "The description of the objective."},
{"Type", "number", "The Objective type. 1 for Primary, 2 for secondary, 3 for bonus."},
{"State", "boolean", "True if the goal was completed, false if it was failed."},
});

const std::shared_ptr<Hook<>> OnMissionAboutToEndHook = Hook<>::Factory("On Mission About To End",
"Called when a mission is about to end but has not run any mission-ending logic",
{});
Expand Down
2 changes: 2 additions & 0 deletions code/scripting/global_hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ extern const std::shared_ptr<Hook<>> OnDialogClose;

extern const std::shared_ptr<Hook<>> OnCheat;

extern const std::shared_ptr<OverridableHook<>> OnMissionObjectivesChanged;

extern const std::shared_ptr<Hook<>> OnMissionAboutToEndHook;
extern const std::shared_ptr<OverridableHook<>> OnMissionEndHook;
extern const std::shared_ptr<Hook<>> OnStateAboutToEndHook;
Expand Down

0 comments on commit 8fb5c64

Please sign in to comment.