Skip to content

Commit 65d968c

Browse files
committed
Merge branch 't/2.3/mapmod' into 2.3
Refs #2610, closes #2688.
2 parents fe46419 + 68843d0 commit 65d968c

File tree

6 files changed

+49
-9
lines changed

6 files changed

+49
-9
lines changed

src/game.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4505,6 +4505,10 @@ bool gameLoadV(PHYSFS_file* fileHandle, unsigned int version)
45054505
if (version >= VERSION_38)
45064506
{
45074507
setOverrideMods(saveGameData.modList);
4508+
if (saveGameData.sGame.map[0])
4509+
{
4510+
setOverrideMap(saveGameData.sGame.map, saveGameData.sGame.maxPlayers);
4511+
}
45084512
}
45094513

45104514
// All savegames from version 34 or before are little endian so swap them. All

src/init.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ BOOL rebuildSearchPath( searchPathMode mode, BOOL force )
234234
char tmpstr[PATH_MAX] = "\0";
235235

236236
if (mode != current_mode || force ||
237-
(use_override_mods && strcmp(override_mod_list, getModList())))
237+
(use_override_mods && strcmp(override_mod_list, getModList())) || use_override_map)
238238
{
239239
if (mode != mod_clean)
240240
{
@@ -344,7 +344,7 @@ BOOL rebuildSearchPath( searchPathMode mode, BOOL force )
344344
#endif // DEBUG
345345
// Add maps and global and multiplay mods
346346
PHYSFS_addToSearchPath( curSearchPath->path, PHYSFS_APPEND );
347-
addSubdirs( curSearchPath->path, "maps", PHYSFS_APPEND, NULL, false );
347+
addSubdirs( curSearchPath->path, "maps", PHYSFS_APPEND, use_override_map?override_map:NULL, false );
348348
addSubdirs( curSearchPath->path, "mods/music", PHYSFS_APPEND, NULL, false );
349349
addSubdirs( curSearchPath->path, "mods/global", PHYSFS_APPEND, use_override_mods?override_mods:global_mods, true );
350350
addSubdirs( curSearchPath->path, "mods", PHYSFS_APPEND, use_override_mods?override_mods:global_mods, true );
@@ -383,13 +383,13 @@ BOOL rebuildSearchPath( searchPathMode mode, BOOL force )
383383
debug(LOG_ERROR, "Can't switch to unknown mods %i", mode);
384384
return false;
385385
}
386-
if (use_override_mods && mode != mod_clean)
386+
if ((use_override_mods || use_override_map) && mode != mod_clean)
387387
{
388-
if (strcmp(getModList(),override_mod_list))
388+
if (use_override_mods && strcmp(getModList(),override_mod_list))
389389
{
390390
debug(LOG_POPUP, _("The required mod could not be loaded: %s\n\nWarzone will try to load the game without it."), override_mod_list);
391391
}
392-
clearOverrideMods();
392+
clearOverrides();
393393
current_mode = mod_override;
394394
}
395395

@@ -404,7 +404,7 @@ BOOL rebuildSearchPath( searchPathMode mode, BOOL force )
404404
else if (use_override_mods)
405405
{
406406
// override mods are already the same as current mods, so no need to do anything
407-
clearOverrideMods();
407+
clearOverrides();
408408
}
409409
return true;
410410
}

src/levels.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "research.h"
4848
#include "lib/framework/lexer_input.h"
4949
#include "effects.h"
50+
#include "modding.h"
5051

5152
extern int lev_get_lineno(void);
5253
extern char* lev_get_text(void);
@@ -677,6 +678,7 @@ BOOL levLoadData(const char* name, char *pSaveName, GAME_TYPE saveType)
677678
}
678679
}
679680

681+
setOverrideMap(psNewLevel->pName, psNewLevel->players);
680682
if (!rebuildSearchPath(psNewLevel->dataDir, false))
681683
{
682684
return false;

src/main.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ char * multiplay_mods[MAX_MODS] = { NULL };
107107
char * override_mods[MAX_MODS] = { NULL };
108108
char * override_mod_list = NULL;
109109
bool use_override_mods = false;
110+
char * override_map[2] = { NULL };
111+
bool use_override_map = false;
110112

111113
char * loaded_mods[MAX_MODS] = { NULL };
112114
char * mod_list = NULL;
@@ -250,7 +252,29 @@ void setOverrideMods(char * modlist)
250252
override_mod_list = modlist;
251253
use_override_mods = true;
252254
}
253-
void clearOverrideMods(void)
255+
void setOverrideMap(char* map, int maxPlayers)
256+
{
257+
// Transform "Sk-Rush-T2" into "4c-Rush.wz" so it can be matched by the map loader
258+
override_map[0] = (char*)malloc(strlen(map)+1+7);
259+
snprintf(override_map[0], 3, "%d", maxPlayers);
260+
strcat(override_map[0],"c-");
261+
if (strncmp(map, "Sk-", 3) == 0)
262+
{
263+
strcat(override_map[0],map+3);
264+
}
265+
else
266+
{
267+
strcat(override_map[0],map);
268+
}
269+
if (strncmp(override_map[0]+strlen(override_map[0])-3,"-T",2) == 0)
270+
{
271+
override_map[0][strlen(override_map[0])-3] = '\0';
272+
}
273+
strcat(override_map[0],".wz");
274+
override_map[1] = NULL;
275+
use_override_map = true;
276+
}
277+
void clearOverrides(void)
254278
{
255279
int i;
256280
use_override_mods = false;
@@ -260,6 +284,13 @@ void clearOverrideMods(void)
260284
}
261285
override_mods[0] = NULL;
262286
override_mod_list = NULL;
287+
288+
if (override_map[0])
289+
{
290+
free(override_map[0]);
291+
override_map[0] = NULL;
292+
}
293+
use_override_map = false;
263294
}
264295

265296
void addLoadedMod(const char * modname)
@@ -705,7 +736,7 @@ static void startGameLoop(void)
705736
{
706737
SetGameMode(GS_NORMAL);
707738

708-
if (!levLoadData(aLevelName, NULL, 0))
739+
if (!levLoadData(aLevelName, NULL, GTYPE_SCENARIO_START))
709740
{
710741
debug( LOG_FATAL, "Shutting down after failure" );
711742
exit(EXIT_FAILURE);

src/main.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,7 @@ extern char * multiplay_mods[MAX_MODS];
4949
extern char * override_mods[MAX_MODS];
5050
extern char * override_mod_list;
5151
extern bool use_override_mods;
52+
extern char * override_map[2];
53+
extern bool use_override_map;
5254

5355
#endif // __INCLUDED_SRC_MAIN_H__

src/modding.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ void removeSubdirs( const char * basedir, const char * subdir, char * checkList[
2626
void printSearchPath( void );
2727

2828
void setOverrideMods(char * modlist);
29-
void clearOverrideMods(void);
29+
void setOverrideMap(char* map, int maxPlayers);
30+
void clearOverrides(void);
3031

3132
void addLoadedMod(const char * modname);
3233
void clearLoadedMods(void);

0 commit comments

Comments
 (0)