Skip to content

Commit ebb003b

Browse files
committed
allow unlimited campaign description length to be saved
1 parent 490c4fd commit ebb003b

File tree

6 files changed

+16
-26
lines changed

6 files changed

+16
-26
lines changed

code/mission/missioncampaign.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ int mission_campaign_load(const char* filename, const char* full_path, player* p
504504
Error(LOCATION, "Unknown campaign type %s!", type);
505505

506506
if (optional_string("+Description:"))
507-
Campaign.desc = stuff_and_malloc_string(F_MULTITEXT, NULL);
507+
stuff_string(Campaign.description, F_MULTITEXT);
508508

509509
// if the type is multiplayer -- get the number of players
510510
if ( Campaign.type != CAMPAIGN_TYPE_SINGLE) {
@@ -1204,10 +1204,7 @@ void mission_campaign_clear()
12041204
{
12051205
int i;
12061206

1207-
if (Campaign.desc != NULL) {
1208-
vm_free(Campaign.desc);
1209-
Campaign.desc = NULL;
1210-
}
1207+
Campaign.description.clear();
12111208

12121209
// be sure to remove all old malloced strings of Mission_names
12131210
// we must also free any goal stuff that was from a previous campaign

code/mission/missioncampaign.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class campaign
116116
public:
117117
char name[NAME_LENGTH]; // name of the campaign
118118
char filename[CF_MAX_PATHNAME_LENGTH]; // filename the campaign info is in
119-
char *desc; // description of campaign
119+
SCP_string description; // unlimited length description of campaign
120120
int type; // type of campaign
121121
int flags; // flags - Goober5000
122122
int num_missions; // number of missions in the campaign
@@ -139,7 +139,7 @@ class campaign
139139
SCP_map<SCP_string, SCP_string> custom_data; // Custom data for the campaign
140140

141141
campaign()
142-
: desc(nullptr), num_missions(0)
142+
: num_missions(0)
143143
{
144144
name[0] = 0;
145145
filename[0] = 0;

code/missioneditor/campaignsave.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ int Fred_campaign_save::save_campaign_file(const char* pathname)
3131

3232
required_string_fred("$Name:");
3333
parse_comments(0);
34-
fout(" %s", Campaign.name);
34+
fout_ext(" ", "%s", Campaign.name);
3535

3636
Assert((Campaign.type >= 0) && (Campaign.type < MAX_CAMPAIGN_TYPES));
3737
required_string_fred("$Type:");
3838
parse_comments();
3939
fout(" %s", campaign_types[Campaign.type]);
4040

4141
// XSTR
42-
if (Campaign.desc) {
42+
if (!Campaign.description.empty()) {
4343
required_string_fred("+Description:");
4444
parse_comments();
45-
fout_ext("\n", "%s", Campaign.desc);
45+
fout_ext("\n", "%s", Campaign.description.c_str());
4646
fout("\n$end_multi_text");
4747
}
4848

fred2/campaigneditordlg.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void campaign_editor::DoDataExchange(CDataExchange* pDX)
7373
DDX_CBIndex(pDX, IDC_CAMPAIGN_TYPE, m_type);
7474
DDX_Text(pDX, IDC_NUM_PLAYERS, m_num_players);
7575
DDX_Text(pDX, IDC_DESC2, m_desc);
76-
DDV_MaxChars(pDX, m_desc, MISSION_DESC_LENGTH - 1);
76+
//DDV_MaxChars(pDX, m_desc, MISSION_DESC_LENGTH - 1);
7777
DDX_Text(pDX, IDC_MISSION_LOOP_DESC, m_branch_desc);
7878
DDV_MaxChars(pDX, m_branch_desc, MISSION_DESC_LENGTH - 1);
7979
DDX_Text(pDX, IDC_LOOP_BRIEF_ANIM, m_branch_brief_anim);
@@ -251,8 +251,8 @@ void campaign_editor::initialize( bool init_files, bool clear_path )
251251
m_type = Campaign.type;
252252
m_num_players.Format("%d", Campaign.num_players);
253253

254-
if (Campaign.desc) {
255-
convert_multiline_string(m_desc, Campaign.desc);
254+
if (!Campaign.description.empty()) {
255+
convert_multiline_string(m_desc, Campaign.description);
256256
} else {
257257
m_desc = _T("");
258258
}
@@ -303,8 +303,6 @@ void campaign_editor::mission_selected(int num)
303303

304304
void campaign_editor::update()
305305
{
306-
char buf[MISSION_DESC_LENGTH];
307-
308306
// get data from dlog box
309307
UpdateData(TRUE);
310308

@@ -317,15 +315,11 @@ void campaign_editor::update()
317315
Campaign.type = m_type;
318316

319317
// update campaign desc
320-
deconvert_multiline_string(buf, m_desc, MISSION_DESC_LENGTH - 1);
321-
if (Campaign.desc) {
322-
free(Campaign.desc);
323-
}
318+
SCP_string desc_buf;
319+
deconvert_multiline_string(desc_buf, m_desc);
324320

325-
Campaign.desc = NULL;
326-
if (strlen(buf)) {
327-
Campaign.desc = strdup(buf);
328-
}
321+
Campaign.description.clear();
322+
Campaign.description = desc_buf;
329323

330324
// update flags
331325
Campaign.flags = CF_DEFAULT_VALUE;

fred2/campaigntreewnd.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ void campaign_tree_wnd::OnCpgnFileNew()
279279
Campaign.num_missions = 0;
280280
Campaign.num_players = 0;
281281
strcpy_s(Campaign.name, "Unnamed");
282-
Campaign.desc = NULL;
283282
Campaign_tree_viewp->free_links();
284283
Campaign_tree_formp->initialize(true, true);
285284
Campaign_modified = 0;

qtfred/src/mission/dialogs/CampaignEditorDialogModel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ CampaignEditorDialogModel::CampaignEditorDialogModel(CampaignEditorDialog* _pare
100100
initialWeapons(Weapon_info, &initWeps, this),
101101
missionData(getMissions(), &CampaignMissionData::initMissions, this),
102102
campaignName(Campaign.name), //missioncampaign.h globals
103-
campaignDescr(Campaign.desc),
103+
campaignDescr(Campaign.description.c_str()),
104104
campaignTechReset(Campaign.flags & CF_CUSTOM_TECH_DATABASE)
105105
{
106106
Assertion(_numPlayers == 0 || campaignFile.isEmpty(), "The editor should only allow setting a player number when a new campaign is created. Please report.");
@@ -447,7 +447,7 @@ bool CampaignEditorDialogModel::_saveTo(QString file) const {
447447
Campaign.type = campaignTypes.indexOf(campaignType);
448448

449449
if (!modified_desc.isEmpty())
450-
Campaign.desc = vm_strdup(qPrintable(modified_desc));
450+
Campaign.description = modified_desc.toUtf8().constData();
451451

452452
Campaign.num_players = numPlayers;
453453

0 commit comments

Comments
 (0)