Skip to content

Commit

Permalink
Merge pull request #6483 from daftmugi/add-campaign-cmdline
Browse files Browse the repository at this point in the history
Add '-campaign' cmdline option to set current campaign
  • Loading branch information
Goober5000 authored Dec 31, 2024
2 parents c3e9099 + 32a71e6 commit ca9edc0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
10 changes: 10 additions & 0 deletions code/cmdline/cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,10 @@ int Cmdline_no_enhanced_sound = 0;

// MOD related
cmdline_parm mod_arg("-mod", "List of folders to overwrite/add-to the default data", AT_STRING, true); // Cmdline_mod -- DTP modsupport
cmdline_parm campaign_arg("-campaign", "Set current campaign", AT_STRING); // Cmdline_campaign

char *Cmdline_mod = NULL; //DTP for mod argument
char *Cmdline_campaign = nullptr; // for campaign argument

// Multiplayer/Network related
cmdline_parm almission_arg("-almission", "Autoload multiplayer mission", AT_STRING); // Cmdline_almission -- DTP for autoload Multi mission
Expand Down Expand Up @@ -1874,6 +1876,14 @@ bool SetCmdlineParams()
Cmdline_mod = modlist;
}

if(campaign_arg.found()) {
Cmdline_campaign = campaign_arg.str();

// strip off blank space if it's there
if ( Cmdline_campaign[strlen(Cmdline_campaign)-1] == ' ' ) {
Cmdline_campaign[strlen(Cmdline_campaign)-1] = '\0';
}
}

if (fps_arg.found())
{
Expand Down
1 change: 1 addition & 0 deletions code/cmdline/cmdline.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ extern int Cmdline_no_enhanced_sound;

// MOD related
extern char *Cmdline_mod; // DTP for mod support
extern char *Cmdline_campaign; // for campaign support
// Multiplayer/Network related
extern char *Cmdline_almission; // DTP for autoload mission (for multi only)
extern int Cmdline_ingamejoin;
Expand Down
39 changes: 36 additions & 3 deletions code/mission/missioncampaign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1557,14 +1557,47 @@ int mission_load_up_campaign(bool fall_back_from_current)
auto pl = Player;

// find best campaign to use:
// 1) last used
// 2) builtin
// 3) anything else
// 1) cmdline
// 2) last used
// 3) builtin
// 4) anything else
// Note that in each step we only fall back when the error is benign, e.g. ignored or missing;
// if there's some other real error with the campaign file, we report it.
// Also note that if we *have* a current campaign, we shouldn't fall back *at all*, lest we repeatedly
// reset what the current campaign is, *unless* we are starting a brand new session or loading a new pilot.

// cmdline...
if ( Cmdline_campaign != nullptr && strlen(Cmdline_campaign) ) {
char* campaign = Cmdline_campaign;

// Clear cmdline value
// * Only set campaign once from cmdline.
// * Prevent subsequent load failures.
// * On success, campaign becomes "last used".
Cmdline_campaign = nullptr;

bool has_last_used_campaign = strlen(pl->current_campaign) > 0;
bool campaign_already_set = has_last_used_campaign
&& (stricmp(campaign, pl->current_campaign) == 0);

if (has_last_used_campaign) {
mprintf(("Current campaign is '%s'\n", pl->current_campaign));
}

if (!campaign_already_set) {
rc = mission_campaign_load(campaign, nullptr, pl);

if (rc == 0) {
// update pilot with the new current campaign (becomes "last used")
strcpy_s(pl->current_campaign, Campaign.filename);
mprintf(("Set current campaign to '%s'\n", campaign));
return rc;
} else {
mprintf(("Failed to set current campaign to '%s'\n", campaign));
}
}
}

// last used...
if ( strlen(pl->current_campaign) ) {
rc = mission_campaign_load(pl->current_campaign, nullptr, pl);
Expand Down

0 comments on commit ca9edc0

Please sign in to comment.