Skip to content

Commit

Permalink
Add two new directives to campaign definition files: 'loading' that g…
Browse files Browse the repository at this point in the history
…ives a level

file to read, and 'package' that gives a .wz file in campaign folder to mount. Campaign
definition files can now also be read from 'campaigns' in the user write folder.
  • Loading branch information
perim committed Jan 10, 2013
1 parent 8d5b074 commit 348cdfc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
33 changes: 33 additions & 0 deletions src/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "lib/framework/input.h"
#include "lib/framework/wzconfig.h"
#include "lib/framework/physfs_ext.h"
#include "lib/ivis_opengl/bitimage.h"
#include "lib/ivis_opengl/pieblitfunc.h"
#include "lib/ivis_opengl/piestate.h"
Expand Down Expand Up @@ -71,6 +72,8 @@ struct CAMPAIGN_FILE
QString level;
QString video;
QString captions;
QString package;
QString loading;
};

// ////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -275,10 +278,16 @@ static QList<CAMPAIGN_FILE> readCampaignFiles()
CAMPAIGN_FILE c;
QString filename("campaigns/");
filename += *i;
if (!filename.endsWith(".ini"))
{
continue;
}
WzConfig ini(filename, WzConfig::ReadOnlyAndRequired);
ini.beginGroup("campaign");
c.name = ini.value("name").toString();
c.level = ini.value("level").toString();
c.package = ini.value("package").toString();
c.loading = ini.value("loading").toString();
ini.endGroup();
ini.beginGroup("intro");
c.video = ini.value("video").toString();
Expand Down Expand Up @@ -323,6 +332,30 @@ static void frontEndNewGame(int which)
seq_AddSeqToList(list[which].video.toUtf8().constData(), NULL, list[which].captions.toUtf8().constData(), false);
seq_StartNextFullScreenVideo();
}
if (!list[which].package.isEmpty())
{
QString path;
path += PHYSFS_getWriteDir();
path += PHYSFS_getDirSeparator();
path += "campaigns";
path += PHYSFS_getDirSeparator();
path += list[which].package;
if (!PHYSFS_mount(path.toUtf8().constData(), NULL, PHYSFS_APPEND))
{
debug(LOG_ERROR, "Failed to load campaign mod \"%s\": %s",
path.toUtf8().constData(), PHYSFS_getLastError());
}
}
if (!list[which].loading.isEmpty())
{
debug(LOG_WZ, "Adding campaign mod level \"%s\"", list[which].loading.toUtf8().constData());
if (!loadLevFile(list[which].loading.toUtf8().constData(), mod_campaign, false, NULL))
{
debug(LOG_ERROR, "Failed to load %s", list[which].loading.toUtf8().constData());
return;
}
}
debug(LOG_WZ, "Loading campaign mod -- %s", aLevelName);
changeTitleMode(STARTGAME);
}

Expand Down
10 changes: 6 additions & 4 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static bool InitialiseGlobals(void)
}


static bool loadLevFile(const char* filename, searchPathMode datadir, bool ignoreWrf, char const *realFileName)
bool loadLevFile(const char* filename, searchPathMode datadir, bool ignoreWrf, char const *realFileName)
{
char *pBuffer;
UDWORD size;
Expand All @@ -152,12 +152,12 @@ static bool loadLevFile(const char* filename, searchPathMode datadir, bool ignor

if (!PHYSFS_exists(filename) || !loadFile(filename, &pBuffer, &size))
{
debug(LOG_ERROR, "loadLevFile: File not found: %s\n", filename);
debug(LOG_ERROR, "File not found: %s\n", filename);
return false; // only in NDEBUG case
}
if (!levParse(pBuffer, size, datadir, ignoreWrf, realFileName))
{
debug(LOG_ERROR, "loadLevFile: Parse error in %s\n", filename);
debug(LOG_ERROR, "Parse error in %s\n", filename);
return false;
}
free(pBuffer);
Expand All @@ -166,7 +166,7 @@ static bool loadLevFile(const char* filename, searchPathMode datadir, bool ignor
}


void cleanSearchPath( void )
static void cleanSearchPath()
{
wzSearchPath * curSearchPath = searchPathRegistry, * tmpSearchPath = NULL;

Expand Down Expand Up @@ -271,6 +271,7 @@ bool rebuildSearchPath(searchPathMode mode, bool force, const char *current_map)
#endif // DEBUG
// Remove maps and mods
removeSubdirs( curSearchPath->path, "maps", NULL );
removeSubdirs( curSearchPath->path, "campaigns", NULL );
removeSubdirs( curSearchPath->path, "mods/music", NULL );
removeSubdirs( curSearchPath->path, "mods/global", NULL );
removeSubdirs( curSearchPath->path, "mods/campaign", NULL );
Expand Down Expand Up @@ -326,6 +327,7 @@ bool rebuildSearchPath(searchPathMode mode, bool force, const char *current_map)
// Add global and campaign mods
PHYSFS_addToSearchPath( curSearchPath->path, PHYSFS_APPEND );

addSubdirs( curSearchPath->path, "campaigns", PHYSFS_APPEND, NULL, false );
addSubdirs( curSearchPath->path, "mods/music", PHYSFS_APPEND, NULL, false );
addSubdirs( curSearchPath->path, "mods/global", PHYSFS_APPEND, use_override_mods?override_mods:global_mods, true );
addSubdirs( curSearchPath->path, "mods", PHYSFS_APPEND, use_override_mods?override_mods:global_mods, true );
Expand Down
3 changes: 2 additions & 1 deletion src/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ struct wzSearchPath

enum searchPathMode { mod_clean, mod_campaign, mod_multiplay, mod_override };

void cleanSearchPath( void );
void registerSearchPath( const char path[], unsigned int priority );
bool rebuildSearchPath(searchPathMode mode, bool force, const char *current_map = NULL);

bool buildMapList(void);

bool loadLevFile(const char* filename, searchPathMode datadir, bool ignoreWrf, char const *realFileName);

extern IMAGEFILE *FrontImages;

#endif // __INCLUDED_SRC_INIT_H__

0 comments on commit 348cdfc

Please sign in to comment.