Skip to content

Commit ba5f2b5

Browse files
committed
Merge branch 'master' into outlaws
2 parents f325369 + 4549639 commit ba5f2b5

File tree

19 files changed

+238
-20
lines changed

19 files changed

+238
-20
lines changed

TheForceEngine/TFE_DarkForces/Scripting/gs_game.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include "gs_game.h"
2-
#include <TFE_System/system.h>
2+
#include <TFE_DarkForces/hud.h>
3+
#include <TFE_DarkForces/random.h>
34
#include <TFE_DarkForces/time.h>
4-
5+
#include <TFE_System/system.h>
6+
#include <string>
57
#include <angelscript.h>
68

79
using namespace TFE_Jedi;
@@ -15,12 +17,24 @@ namespace TFE_DarkForces
1517
return f32(s_curTick) * c_timeScale;
1618
}
1719

20+
s32 GS_Game::scriptRandom(s32 value)
21+
{
22+
return random(value);
23+
}
24+
25+
void GS_Game::text(string msg)
26+
{
27+
TFE_DarkForces::hud_sendTextMessage(msg.c_str(), 0, false);
28+
}
29+
1830
bool GS_Game::scriptRegister(ScriptAPI api)
1931
{
2032
ScriptClassBegin("Game", "game", api);
2133
{
2234
// Functions
2335
ScriptObjMethod("float getGameTime()", getGameTime);
36+
ScriptObjMethod("int random(int)", scriptRandom);
37+
ScriptObjMethod("void text(string)", text);
2438
}
2539
ScriptClassEnd();
2640
}

TheForceEngine/TFE_DarkForces/Scripting/gs_game.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// in order to properly test elements in isolation without having
77
// to "play" the game as intended.
88
//////////////////////////////////////////////////////////////////////
9+
#include <string>
910
#include <TFE_System/system.h>
1011
#include <TFE_System/types.h>
1112
#include <TFE_ForceScript/scriptInterface.h>
@@ -19,6 +20,8 @@ namespace TFE_DarkForces
1920
bool scriptRegister(ScriptAPI api) override;
2021

2122
f32 getGameTime();
23+
s32 scriptRandom(s32 value);
24+
void text(std::string msg);
2225
};
2326
}
2427

TheForceEngine/TFE_DarkForces/Scripting/gs_level.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,30 @@ namespace TFE_DarkForces
4848
return sector;
4949
}
5050

51+
ScriptSector GS_Level::getSectorByName(std::string name)
52+
{
53+
const char* sectorName = name.c_str();
54+
55+
MessageAddress* msgAddr = message_getAddress(sectorName);
56+
if (msgAddr)
57+
{
58+
u32 sectorCount = s_levelState.sectorCount;
59+
for (u32 s = 0; s < sectorCount; s++)
60+
{
61+
RSector* sec = &s_levelState.sectors[s];
62+
if (sec == msgAddr->sector)
63+
{
64+
ScriptSector sector(s);
65+
return sector;
66+
}
67+
}
68+
}
69+
70+
// Could not find the sector
71+
ScriptSector sector(-1);
72+
return sector;
73+
}
74+
5175
ScriptElev GS_Level::getElevator(s32 id)
5276
{
5377
if (id < 0 || id >= allocator_getCount(s_infSerState.infElevators))
@@ -230,6 +254,7 @@ namespace TFE_DarkForces
230254

231255
// Functions
232256
ScriptObjMethod("Sector getSector(int)", getSectorById);
257+
ScriptObjMethod("Sector getSector(string)", getSectorByName);
233258
ScriptObjMethod("Elevator getElevator(int)", getElevator);
234259
ScriptObjMethod("void findConnectedSectors(Sector initSector, uint, array<Sector>&)", findConnectedSectors);
235260

TheForceEngine/TFE_DarkForces/Scripting/gs_level.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ namespace TFE_DarkForces
2525
bool scriptRegister(ScriptAPI api) override;
2626

2727
ScriptSector getSectorById(s32 id);
28+
ScriptSector getSectorByName(std::string name);
2829
ScriptElev getElevator(s32 id);
2930
void findConnectedSectors(ScriptSector initSector, u32 matchProp, CScriptArray& results);
3031
void setGravity(s32 grav);

TheForceEngine/TFE_DarkForces/agent.cpp

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
#include "hud.h"
77
#include "weapon.h"
88
#include <TFE_Game/igame.h>
9+
#include <TFE_DarkForces/mission.h>
910
#include <TFE_FileSystem/fileutil.h>
1011
#include <TFE_FileSystem/paths.h>
12+
#include <TFE_Settings/settings.h>
1113
#include <TFE_System/system.h>
1214
#include <TFE_System/parser.h>
1315
#include <TFE_Jedi/Serialization/serialization.h>
@@ -180,12 +182,23 @@ namespace TFE_DarkForces
180182
void levelEndTaskFunc(MessageType msg)
181183
{
182184
task_begin;
183-
while (1)
185+
186+
// If you are using the auto end mission setting, then just wait a few seconds and end the level.
187+
if (TFE_Settings::getGameSettings()->df_autoEndMission)
184188
{
185-
hud_sendTextMessage(461);
186-
task_yield(582); // ~4 seconds
187-
hud_sendTextMessage(462);
188-
task_yield(4369); // ~30 seconds
189+
task_yield(873); // ~ 6 seconds
190+
mission_setExitLevel(JTRUE);
191+
}
192+
else
193+
{
194+
// Otherwise loop the end level message until the player exits through the escape menu.
195+
while (1)
196+
{
197+
hud_sendTextMessage(461);
198+
task_yield(582); // ~4 seconds
199+
hud_sendTextMessage(462);
200+
task_yield(4369); // ~30 seconds
201+
}
189202
}
190203
task_end;
191204
}
@@ -541,10 +554,19 @@ namespace TFE_DarkForces
541554
}
542555
else
543556
{
544-
// Finally generate a new one.
545-
TFE_System::logWrite(LOG_WARNING, "DarkForcesMain", "Cannot find 'DARKPILO.CFG' at '%s'. Creating a new file for save data.", sourcePath);
546-
newpilo:
547-
createDarkPilotConfig(documentsPath);
557+
// Also check the remaster documents path.
558+
TFE_Paths::appendPath(PATH_REMASTER_DOCS, "DARKPILO.CFG", sourcePath);
559+
if (FileUtil::exists(sourcePath))
560+
{
561+
FileUtil::copyFile(sourcePath, documentsPath);
562+
}
563+
else
564+
{
565+
// Finally generate a new one.
566+
TFE_System::logWrite(LOG_WARNING, "DarkForcesMain", "Cannot find 'DARKPILO.CFG' at '%s'. Creating a new file for save data.", sourcePath);
567+
newpilo:
568+
createDarkPilotConfig(documentsPath);
569+
}
548570
}
549571
}
550572
}

TheForceEngine/TFE_DarkForces/mission.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,11 @@ namespace TFE_DarkForces
518518
s_exitLevel = JTRUE;
519519
}
520520

521+
void mission_setExitLevel(JBool exitLevel)
522+
{
523+
s_exitLevel = exitLevel;
524+
}
525+
521526
void mission_render(s32 rendererIndex, bool forceTextureUpdate)
522527
{
523528
if (task_getCount() > 1 && s_missionMode == MISSION_MODE_MAIN)

TheForceEngine/TFE_DarkForces/mission.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace TFE_DarkForces
2626
void mission_startTaskFunc(MessageType msg);
2727
void mission_setLoadMissionTask(Task* task);
2828
void mission_exitLevel();
29+
void mission_setExitLevel(JBool exitLevel);
2930
void mission_pause(JBool pause);
3031

3132
void setScreenFxLevels(s32 healthFx, s32 shieldFx, s32 flashFx);

TheForceEngine/TFE_FileSystem/paths-posix.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "paths.h"
44
#include "fileutil.h"
55
#include "filestream.h"
6+
#include <TFE_Settings/gameSourceData.h>
67
#include <TFE_System/system.h>
78
#include <TFE_Archive/archive.h>
89
#include <algorithm>
@@ -130,6 +131,34 @@ namespace TFE_Paths
130131
return true;
131132
}
132133

134+
// There is no official remaster support on linux
135+
// Lets approximate proton save locations.
136+
bool setRemasterDocsPath(GameID game)
137+
{
138+
if (isPortableInstall())
139+
{
140+
s_paths[PATH_REMASTER_DOCS] = s_paths[PATH_PROGRAM];
141+
return true;
142+
}
143+
string strId = to_string((int)TFE_Settings::c_steamRemasterProductId[game]);
144+
string append = "~/.steam/steam/steamapps/compatdata/" + strId + "/pfx/drive_c/users/steamuser/Saved Games/Nightdive Studios";
145+
146+
if (game == Game_Dark_Forces)
147+
{
148+
append += "/Dark Forces Remaster/";
149+
}
150+
else if (game == Game_Outlaws)
151+
{
152+
append += "/Outlaws Remaster/";
153+
}
154+
else
155+
{
156+
return false;
157+
}
158+
s_paths[PATH_REMASTER_DOCS] = append;
159+
return !s_paths[PATH_REMASTER_DOCS].empty();
160+
}
161+
133162
bool setProgramPath(void)
134163
{
135164
char p[TFE_MAX_PATH];

TheForceEngine/TFE_FileSystem/paths.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,35 @@ namespace TFE_Paths
123123
return false;
124124
}
125125

126+
// This is the path to the Remaster documents folder.
127+
bool setRemasterDocsPath(GameID game)
128+
{
129+
#ifdef _WIN32
130+
char path[TFE_MAX_PATH];
131+
132+
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, 0, path)))
133+
{
134+
// Append product-specific path
135+
if (game == Game_Dark_Forces)
136+
{
137+
PathAppend(path, "Saved Games\\Nightdive Studios\\Dark Forces Remaster");
138+
}
139+
else if (game == Game_Outlaws)
140+
{
141+
PathAppend(path, "Saved Games\\Nightdive Studios\\Outlaws Remaster");
142+
}
143+
else
144+
{
145+
return false;
146+
}
147+
s_paths[PATH_REMASTER_DOCS] = path;
148+
s_paths[PATH_REMASTER_DOCS] += "\\";
149+
}
150+
return !s_paths[PATH_REMASTER_DOCS].empty();
151+
#endif
152+
return false;
153+
}
154+
126155
bool setProgramPath()
127156
{
128157
char path[TFE_MAX_PATH];

TheForceEngine/TFE_FileSystem/paths.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22
#include "fileutil.h"
33
#include <TFE_System/types.h>
4+
#include <TFE_Settings/gameSourceData.h>
45

56
enum TFE_PathType
67
{
@@ -10,6 +11,7 @@ enum TFE_PathType
1011
PATH_SOURCE_DATA, // This is the location of the source data, such as maps, textures, etc.
1112
PATH_EMULATOR, // Path to the dosbox exe (for the editor).
1213
PATH_MOD, // Use this to reference mods.
14+
PATH_REMASTER_DOCS, // Path for Remaster Document Folder.
1315
PATH_COUNT
1416
};
1517

@@ -34,6 +36,7 @@ namespace TFE_Paths
3436
bool setProgramDataPath(const char* append);
3537
bool setUserDocumentsPath(const char* append);
3638
// Platform specific executable path.
39+
bool setRemasterDocsPath(GameID game);
3740
bool setProgramPath();
3841
// find a relative path in a TFE system directory. true if mapping was done.
3942
bool mapSystemPath(char *path);

0 commit comments

Comments
 (0)