2019-09-19 22:42:45 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Copyright (C) 2010-2019 EDuke32 developers and contributors
|
|
|
|
Copyright (C) 2019 Nuke.YKT
|
|
|
|
|
|
|
|
This file is part of NBlood.
|
|
|
|
|
|
|
|
NBlood is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License version 2
|
|
|
|
as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
2019-09-21 18:59:54 +00:00
|
|
|
#include "ns.h" // Must come before everything else!
|
|
|
|
|
2019-09-19 22:42:45 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "blood.h"
|
|
|
|
#include "inifile.h"
|
2020-10-04 16:31:48 +00:00
|
|
|
#include "razemenu.h"
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2019-09-22 06:39:22 +00:00
|
|
|
BEGIN_BLD_NS
|
|
|
|
|
2019-09-19 22:42:45 +00:00
|
|
|
GAMEOPTIONS gGameOptions;
|
|
|
|
|
|
|
|
GAMEOPTIONS gSingleGameOptions = {
|
2020-11-22 15:47:08 +00:00
|
|
|
0, 2, 0, 0, 0, 0, 0, 0, 2, 3600, 1800, 1800, 7200
|
2019-09-19 22:42:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int gSkill = 2;
|
2021-05-02 07:08:57 +00:00
|
|
|
MapRecord* gNextLevel;
|
2019-09-19 22:42:45 +00:00
|
|
|
|
|
|
|
char BloodIniFile[BMAX_PATH] = "BLOOD.INI";
|
|
|
|
bool bINIOverride = false;
|
|
|
|
IniFile *BloodINI;
|
|
|
|
|
|
|
|
|
|
|
|
void levelInitINI(const char *pzIni)
|
|
|
|
{
|
2019-12-07 09:31:27 +00:00
|
|
|
if (!fileSystem.FileExists(pzIni))
|
2020-10-11 10:22:36 +00:00
|
|
|
I_Error("Initialization: %s does not exist", pzIni);
|
2019-09-19 22:42:45 +00:00
|
|
|
BloodINI = new IniFile(pzIni);
|
2020-09-08 16:48:18 +00:00
|
|
|
strncpy(BloodIniFile, pzIni, BMAX_PATH);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CheckSectionAbend(const char *pzSection)
|
|
|
|
{
|
|
|
|
if (!pzSection || !BloodINI->SectionExists(pzSection))
|
2020-10-11 10:22:36 +00:00
|
|
|
I_Error("Section [%s] expected in BLOOD.INI", pzSection);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CheckKeyAbend(const char *pzSection, const char *pzKey)
|
|
|
|
{
|
2020-10-11 10:38:17 +00:00
|
|
|
assert(pzSection != NULL);
|
2019-09-19 22:42:45 +00:00
|
|
|
|
|
|
|
if (!pzKey || !BloodINI->KeyExists(pzSection, pzKey))
|
2020-10-11 10:22:36 +00:00
|
|
|
I_Error("Key %s expected in section [%s] of BLOOD.INI", pzKey, pzSection);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-02 07:08:57 +00:00
|
|
|
|
|
|
|
void levelLoadMapInfo(IniFile* pIni, MapRecord* pLevelInfo, const char* pzSection, int epinum, int mapnum, int* nextmap, int* nextsecret)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
|
|
|
char buffer[16];
|
2019-12-10 23:57:53 +00:00
|
|
|
pLevelInfo->SetName(pIni->GetKeyString(pzSection, "Title", pLevelInfo->labelName));
|
2021-05-01 20:52:28 +00:00
|
|
|
pLevelInfo->Author = pIni->GetKeyString(pzSection, "Author", "");
|
2021-05-03 21:00:24 +00:00
|
|
|
pLevelInfo->music = pIni->GetKeyString(pzSection, "Song", ""); if (pLevelInfo->music.IsNotEmpty()) DefaultExtension(pLevelInfo->music, ".mid");
|
2019-12-10 23:57:53 +00:00
|
|
|
pLevelInfo->cdSongId = pIni->GetKeyInt(pzSection, "Track", -1);
|
2021-05-02 07:08:57 +00:00
|
|
|
*nextmap = pIni->GetKeyInt(pzSection, "EndingA", 0);
|
|
|
|
*nextsecret = pIni->GetKeyInt(pzSection, "EndingB", 0);
|
2019-12-10 23:57:53 +00:00
|
|
|
pLevelInfo->fog = pIni->GetKeyInt(pzSection, "Fog", -0);
|
|
|
|
pLevelInfo->weather = pIni->GetKeyInt(pzSection, "Weather", -0);
|
2019-09-19 22:42:45 +00:00
|
|
|
for (int i = 0; i < kMaxMessages; i++)
|
|
|
|
{
|
2021-05-01 22:58:54 +00:00
|
|
|
sprintf(buffer, "Message%d", i + 1);
|
|
|
|
auto msg = pIni->GetKeyString(pzSection, buffer, "");
|
|
|
|
pLevelInfo->AddMessage(i, msg);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-15 10:34:42 +00:00
|
|
|
static const char* DefFile(void)
|
|
|
|
{
|
2021-04-05 22:56:34 +00:00
|
|
|
int found = -1;
|
|
|
|
if (userConfig.DefaultCon.IsEmpty() || userConfig.DefaultCon.CompareNoCase("blood.ini") == 0)
|
|
|
|
{
|
|
|
|
int numlumps = fileSystem.GetNumEntries();
|
|
|
|
for (int i = numlumps - 1; i >= 0; i--)
|
|
|
|
{
|
2021-04-11 22:01:29 +00:00
|
|
|
int fileno = fileSystem.GetFileContainer(i);
|
2021-08-24 16:39:54 +00:00
|
|
|
if (fileno != -1 && fileno <= fileSystem.GetMaxIwadNum()) continue;
|
2021-04-05 22:56:34 +00:00
|
|
|
FString fn = fileSystem.GetFileFullName(i, false);
|
|
|
|
FString ext = fn.Right(4);
|
|
|
|
if (ext.CompareNoCase(".ini") == 0)
|
|
|
|
{
|
|
|
|
if (fileSystem.CheckNumForFullName(fn) != i) continue;
|
2021-07-13 10:34:35 +00:00
|
|
|
if (found == -1)
|
|
|
|
{
|
|
|
|
IniFile inif(fn);
|
|
|
|
for (int j = 1; j <= 6; j++)
|
|
|
|
{
|
|
|
|
FStringf key("Episode%d", j);
|
2021-07-16 13:01:07 +00:00
|
|
|
if (inif.SectionExists(key))
|
2021-07-13 10:34:35 +00:00
|
|
|
{
|
|
|
|
found = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-05 22:56:34 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
found = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found >= 0) return fileSystem.GetFileFullName(found);
|
2020-07-15 10:34:42 +00:00
|
|
|
// The command line parser stores this in the CON field.
|
|
|
|
return userConfig.DefaultCon.IsNotEmpty() ? userConfig.DefaultCon.GetChars() : "blood.ini";
|
|
|
|
}
|
|
|
|
|
2021-04-28 18:16:13 +00:00
|
|
|
static FString cleanPath(const char* pth)
|
|
|
|
{
|
|
|
|
FString path = pth;
|
|
|
|
FixPathSeperator(path);
|
2021-07-25 15:27:52 +00:00
|
|
|
if (fileSystem.FileExists(path)) return path;
|
2021-04-28 18:16:13 +00:00
|
|
|
if (path.Len() > 3 && path[1] == ':' && isalpha(path[0]) && path[2] == '/')
|
|
|
|
{
|
2021-07-25 15:27:52 +00:00
|
|
|
path = path.Mid(3);
|
|
|
|
if (fileSystem.FileExists(path)) return path;
|
|
|
|
}
|
|
|
|
// optionally strip the first path component to account for poor logic of the DOS EXE.
|
|
|
|
auto pos = path.IndexOf("/");
|
|
|
|
if (pos >= 0)
|
|
|
|
{
|
|
|
|
auto npath = path.Mid(pos + 1);
|
|
|
|
if (fileSystem.FileExists(npath)) return npath;
|
2021-04-28 18:16:13 +00:00
|
|
|
}
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2019-09-19 22:42:45 +00:00
|
|
|
void levelLoadDefaults(void)
|
|
|
|
{
|
|
|
|
char buffer[64];
|
|
|
|
char buffer2[16];
|
2021-04-28 18:16:13 +00:00
|
|
|
|
|
|
|
int cutALevel = 0;
|
|
|
|
|
2020-07-15 10:34:42 +00:00
|
|
|
levelInitINI(DefFile());
|
2019-09-19 22:42:45 +00:00
|
|
|
int i;
|
2021-05-01 22:35:56 +00:00
|
|
|
for (i = 1; i <= kMaxEpisodes; i++)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2021-05-01 22:35:56 +00:00
|
|
|
sprintf(buffer, "Episode%d", i);
|
2019-09-19 22:42:45 +00:00
|
|
|
if (!BloodINI->SectionExists(buffer))
|
|
|
|
break;
|
2021-05-01 22:35:56 +00:00
|
|
|
auto cluster = MustFindCluster(i);
|
|
|
|
auto volume = MustFindVolume(i);
|
|
|
|
CutsceneDef &csB = cluster->outro;
|
2021-10-19 19:09:49 +00:00
|
|
|
FString ep_str = BloodINI->GetKeyString(buffer, "Title", buffer);
|
|
|
|
ep_str.StripRight();
|
|
|
|
cluster->name = volume->name = FStringTable::MakeMacro(ep_str);
|
2021-05-01 22:35:56 +00:00
|
|
|
if (i > 1) volume->flags |= VF_SHAREWARELOCK;
|
2021-07-11 12:30:59 +00:00
|
|
|
if (BloodINI->GetKeyInt(buffer, "BloodBathOnly", 0)) volume->flags |= VF_HIDEFROMSP;
|
2019-09-19 22:42:45 +00:00
|
|
|
|
2021-04-28 18:16:13 +00:00
|
|
|
csB.video = cleanPath(BloodINI->GetKeyString(buffer, "CutSceneB", ""));
|
2021-05-02 16:10:59 +00:00
|
|
|
int soundint = BloodINI->GetKeyInt(buffer, "CutWavB", -1);
|
|
|
|
if (soundint > 0) csB.soundID = soundint + 0x40000000;
|
|
|
|
else csB.soundName = cleanPath(BloodINI->GetKeyString(buffer, "CutWavB", ""));
|
2021-04-28 18:16:13 +00:00
|
|
|
|
|
|
|
//pEpisodeInfo->bloodbath = BloodINI->GetKeyInt(buffer, "BloodBathOnly", 0);
|
2021-05-02 07:08:57 +00:00
|
|
|
cutALevel = BloodINI->GetKeyInt(buffer, "CutSceneALevel", 0);
|
|
|
|
if (cutALevel < 1) cutALevel = 1;
|
2021-04-28 18:16:13 +00:00
|
|
|
|
2021-05-02 07:08:57 +00:00
|
|
|
int nextmaps[kMaxLevels]{}, nextsecrets[kMaxLevels]{};
|
|
|
|
for (int j = 1; j <= kMaxLevels; j++)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2021-05-01 22:35:56 +00:00
|
|
|
sprintf(buffer2, "Map%d", j);
|
2019-09-19 22:42:45 +00:00
|
|
|
if (!BloodINI->KeyExists(buffer, buffer2))
|
|
|
|
break;
|
2020-08-03 18:11:30 +00:00
|
|
|
auto pLevelInfo = AllocateMap();
|
2019-09-19 22:42:45 +00:00
|
|
|
const char *pMap = BloodINI->GetKeyString(buffer, buffer2, NULL);
|
|
|
|
CheckSectionAbend(pMap);
|
2021-05-02 07:08:57 +00:00
|
|
|
SetLevelNum(pLevelInfo, makelevelnum(i, j));
|
2021-05-01 22:35:56 +00:00
|
|
|
pLevelInfo->cluster = i;
|
2019-12-10 23:57:53 +00:00
|
|
|
pLevelInfo->labelName = pMap;
|
2021-05-01 22:58:54 +00:00
|
|
|
if (j == 1) volume->startmap = pLevelInfo->labelName;
|
2019-12-10 23:57:53 +00:00
|
|
|
pLevelInfo->fileName.Format("%s.map", pMap);
|
2021-05-02 07:08:57 +00:00
|
|
|
levelLoadMapInfo(BloodINI, pLevelInfo, pMap, i, j, &nextmaps[j - 1], &nextsecrets[j - 1]);
|
2021-04-28 18:16:13 +00:00
|
|
|
if (j == cutALevel)
|
|
|
|
{
|
|
|
|
CutsceneDef& csA = pLevelInfo->intro;
|
|
|
|
csA.video = cleanPath(BloodINI->GetKeyString(buffer, "CutSceneA", ""));
|
2021-05-02 16:10:59 +00:00
|
|
|
int soundint = BloodINI->GetKeyInt(buffer, "CutWavA", -1);
|
|
|
|
if (soundint > 0) csA.soundID = soundint + 0x40000000;
|
|
|
|
else csA.soundName = cleanPath(BloodINI->GetKeyString(buffer, "CutWavA", ""));
|
2021-04-28 18:16:13 +00:00
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
2021-05-02 07:08:57 +00:00
|
|
|
// Now resolve the level links
|
|
|
|
for (int j = 1; j <= kMaxLevels; j++)
|
|
|
|
{
|
|
|
|
auto map = FindMapByIndexOnly(i, j);
|
|
|
|
if (map)
|
|
|
|
{
|
|
|
|
if (nextmaps[j - 1] > 0)
|
|
|
|
{
|
|
|
|
auto nmap = FindMapByIndexOnly(i, nextmaps[j - 1]);
|
|
|
|
if (nmap) map->NextMap = nmap->labelName;
|
|
|
|
else map->NextMap = "-";
|
|
|
|
}
|
2021-05-03 21:00:24 +00:00
|
|
|
else map->NextMap = "-";
|
2021-05-02 07:08:57 +00:00
|
|
|
if (nextsecrets[j - 1] > 0)
|
|
|
|
{
|
|
|
|
auto nmap = FindMapByIndexOnly(i, nextsecrets[j - 1]);
|
|
|
|
if (nmap) map->NextSecret = nmap->labelName;
|
|
|
|
else map->NextSecret = "-";
|
|
|
|
}
|
2021-05-03 21:00:24 +00:00
|
|
|
else map->NextSecret = "-";
|
2021-05-02 07:08:57 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-28 18:16:13 +00:00
|
|
|
void levelEndLevel(int secret)
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2020-09-04 18:46:44 +00:00
|
|
|
gGameOptions.uGameFlags |= GF_AdvanceLevel;
|
2021-05-02 07:08:57 +00:00
|
|
|
if (!secret) gNextLevel = FindNextMap(currentLevel);
|
|
|
|
else gNextLevel = FindNextSecretMap(currentLevel);
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
2020-08-16 11:26:57 +00:00
|
|
|
void levelTryPlayMusic()
|
2019-09-19 22:42:45 +00:00
|
|
|
{
|
2019-12-25 00:10:13 +00:00
|
|
|
FString buffer;
|
2020-08-16 10:35:46 +00:00
|
|
|
if (mus_redbook && currentLevel->cdSongId > 0)
|
|
|
|
buffer.Format("blood%02i.ogg", currentLevel->cdSongId);
|
2019-09-19 22:42:45 +00:00
|
|
|
else
|
2019-12-07 17:28:30 +00:00
|
|
|
{
|
2020-08-16 10:35:46 +00:00
|
|
|
buffer = currentLevel->music;
|
2021-05-11 23:58:42 +00:00
|
|
|
if (Mus_Play(buffer, true)) return;
|
2021-05-03 21:00:24 +00:00
|
|
|
if (buffer.IsNotEmpty()) DefaultExtension(buffer, ".mid");
|
2019-12-07 17:28:30 +00:00
|
|
|
}
|
2021-05-11 23:58:42 +00:00
|
|
|
if (!Mus_Play(buffer, true))
|
2020-08-16 10:35:46 +00:00
|
|
|
{
|
2021-05-11 23:58:42 +00:00
|
|
|
Mus_Play("", true);
|
2020-08-16 10:35:46 +00:00
|
|
|
}
|
2019-09-19 22:42:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-22 06:39:22 +00:00
|
|
|
END_BLD_NS
|