mirror of
https://github.com/jmarshall23/CnC_Remastered_Collection.git
synced 2026-08-18 17:14:13 +02:00
Initial Lua Script implementation. Credit/Timer now renders.
This commit is contained in:
@@ -2465,6 +2465,8 @@ Mono_Set_Cursor(0,0);
|
||||
#endif
|
||||
BEnd(BENCH_GAME_FRAME);
|
||||
|
||||
Scenario_PlayMapStart();
|
||||
|
||||
Sync_Delay();
|
||||
return(!GameActive);
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ void CreditClass::Graphic_Logic(bool forced)
|
||||
long hours = mins / 60;
|
||||
secs %= 60;
|
||||
mins %= 60;
|
||||
#if (0) //Moved to LOGIC.CPP
|
||||
|
||||
/*
|
||||
** Speak mission timer reminders.
|
||||
*/
|
||||
@@ -143,15 +143,13 @@ void CreditClass::Graphic_Logic(bool forced)
|
||||
Speak(vox);
|
||||
Map.FlasherTimer = 7;
|
||||
}
|
||||
#endif
|
||||
#ifdef WIN32
|
||||
#if (0) //PG
|
||||
|
||||
if (hours) {
|
||||
Fancy_Text_Print(TXT_TIME_FORMAT_HOURS, 200 * RESFACTOR, 0, &MetalScheme, TBLACK, TPF_METAL12|TPF_CENTER|TPF_USE_GRAD_PAL, hours, mins, secs);
|
||||
} else {
|
||||
Fancy_Text_Print(TXT_TIME_FORMAT_NO_HOURS, 200 * RESFACTOR, 0, &MetalScheme, TBLACK, TPF_METAL12|TPF_CENTER|TPF_USE_GRAD_PAL, mins, secs);
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
if (hours) {
|
||||
Fancy_Text_Print("%02d:%02d:%02d", 120 * RESFACTOR, 0, &ColorRemaps[PCOLOR_GREY], TBLACK, TPF_NOSHADOW|TPF_6PT_GRAD|TPF_CENTER|TPF_BRIGHT_COLOR, hours, mins, secs);
|
||||
|
||||
@@ -909,6 +909,7 @@ void Post_Load_Game(int load_net);
|
||||
bool End_Game(void);
|
||||
bool Read_Scenario(char *root);
|
||||
bool Start_Scenario(char *root, bool briefing=true);
|
||||
void Scenario_PlayMapStart(void);
|
||||
void Set_Scenario_Difficulty(int difficulty);
|
||||
HousesType Select_House(void);
|
||||
void Clear_Scenario(void);
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
// MapScript.cpp
|
||||
//
|
||||
|
||||
#include "FUNCTION.H"
|
||||
#include "MapScript.h"
|
||||
|
||||
static int Script_StartMissionTimer(lua_State* L) {
|
||||
int ret = lua_tointeger(L, -1);
|
||||
Scen.MissionTimer = Scen.MissionTimer + (ret * (TICKS_PER_MINUTE / 10));
|
||||
Scen.MissionTimer.Start();
|
||||
Map.Redraw_Tab();
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int Script_StopMissionTimer(lua_State* L) {
|
||||
Scen.MissionTimer.Start();
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int Script_PlayMovie(lua_State* L) {
|
||||
int ret = lua_tointeger(L, -1);
|
||||
Play_Movie((VQType)ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int Script_Speak(lua_State* L) {
|
||||
int ret = lua_tointeger(L, -1);
|
||||
Speak((VoxType)ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int Script_SetBriefingText(lua_State* L) {
|
||||
strcpy(Scen.BriefingText, lua_tostring(L, -1));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
==================
|
||||
MapScript::CallFunction
|
||||
==================
|
||||
*/
|
||||
void MapScript::CallFunction(const char* functionName) {
|
||||
lua_getglobal(L, functionName);
|
||||
lua_pcall(L, 0, 0, 0);
|
||||
} //BriefingText
|
||||
|
||||
/*
|
||||
==================
|
||||
MapScript::Init
|
||||
==================
|
||||
*/
|
||||
bool MapScript::Init(const char* mapName) {
|
||||
char scriptName[256];
|
||||
sprintf(scriptName, "scripts/%s.script", mapName);
|
||||
L = luaL_newstate();
|
||||
if (luaL_loadfile(L, scriptName) || lua_pcall(L, 0, 0, 0)) {
|
||||
L = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
lua_register(L, "Play_Movie", Script_PlayMovie);
|
||||
lua_register(L, "SetBriefingText", Script_SetBriefingText);
|
||||
lua_register(L, "Speak", Script_Speak);
|
||||
lua_register(L, "StartMissionTimer", Script_StartMissionTimer);
|
||||
lua_register(L, "StopMissionTimer", Script_StopMissionTimer);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// MapScript.h
|
||||
//
|
||||
|
||||
// Lua is written in C, so compiler needs to know how to link its libraries
|
||||
extern "C" {
|
||||
# include "lua.h"
|
||||
# include "lauxlib.h"
|
||||
# include "lualib.h"
|
||||
}
|
||||
|
||||
//
|
||||
// MapScript
|
||||
//
|
||||
class MapScript {
|
||||
public:
|
||||
bool Init(const char* mapName);
|
||||
void CallFunction(const char* functionName);
|
||||
private:
|
||||
lua_State* L;
|
||||
};
|
||||
+40
-4
@@ -60,6 +60,7 @@
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
#include "function.h"
|
||||
#include "MapScript.h"
|
||||
#ifdef WIN32
|
||||
#include "tcpip.h"
|
||||
#include "ccdde.h"
|
||||
@@ -110,6 +111,9 @@ bool Is_Mission_Counterstrike (char *file_name);
|
||||
bool Is_Mission_Aftermath (char *file_name);
|
||||
#endif
|
||||
|
||||
MapScript* mapScript = nullptr;
|
||||
bool mapScriptPlayStart = false;
|
||||
|
||||
/***********************************************************************************************
|
||||
* ScenarioClass::ScenarioClass -- Constructor for the scenario control object. *
|
||||
* *
|
||||
@@ -312,12 +316,26 @@ bool ScenarioClass::Set_Global_To(int global, bool value)
|
||||
bool Start_Scenario(char * name, bool briefing)
|
||||
{
|
||||
//BG Theme.Queue_Song(THEME_QUIET);
|
||||
Theme.Stop();
|
||||
Theme.Stop();
|
||||
IsTanyaDead = SaveTanya;
|
||||
if (!Read_Scenario(name)) {
|
||||
return(false);
|
||||
}
|
||||
|
||||
// jmarshall: map scripts
|
||||
if (mapScript) {
|
||||
delete mapScript;
|
||||
}
|
||||
mapScript = new MapScript();
|
||||
if (!mapScript->Init(name)) {
|
||||
delete mapScript;
|
||||
mapScript = nullptr;
|
||||
}
|
||||
else {
|
||||
mapScriptPlayStart = true;
|
||||
}
|
||||
// jmarshall end
|
||||
|
||||
/*
|
||||
** Play the winning movie and then start the next scenario.
|
||||
*/
|
||||
@@ -351,15 +369,21 @@ Theme.Stop();
|
||||
|
||||
// }
|
||||
Theme.Stop();
|
||||
|
||||
if (briefing) {
|
||||
// jmarshall - map scripts
|
||||
if (mapScript) {
|
||||
Hide_Mouse();
|
||||
VisiblePage.Clear();
|
||||
Show_Mouse();
|
||||
mapScript->CallFunction("map_briefing");
|
||||
}
|
||||
else if (briefing) {
|
||||
Hide_Mouse();
|
||||
VisiblePage.Clear();
|
||||
Show_Mouse();
|
||||
Play_Movie(Scen.IntroMovie);
|
||||
Play_Movie(Scen.BriefMovie);
|
||||
}
|
||||
|
||||
// jmarshall end
|
||||
/*
|
||||
** If there's no briefing movie, restate the mission at the beginning.
|
||||
*/
|
||||
@@ -396,6 +420,18 @@ Theme.Stop();
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Scenario_PlayMapStart(void) {
|
||||
if (!mapScript)
|
||||
return;
|
||||
|
||||
if (!mapScriptPlayStart)
|
||||
return;
|
||||
|
||||
mapScript->CallFunction("map_start");
|
||||
|
||||
mapScriptPlayStart = false;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************************************
|
||||
* Set_Scenario_Difficulty -- Sets the difficulty of the scenario. *
|
||||
|
||||
+1
-3
@@ -93,8 +93,6 @@ void TabClass::Draw_It(bool complete)
|
||||
return;
|
||||
}
|
||||
|
||||
// Disable tab drawing for menu, credits buttons etc. ST - 5/27/2019
|
||||
#if (0)
|
||||
/*
|
||||
** Redraw the top bar imagery if flagged to do so or if the entire display needs
|
||||
** to be redrawn.
|
||||
@@ -136,7 +134,7 @@ void TabClass::Draw_It(bool complete)
|
||||
LogicPage->Unlock();
|
||||
}
|
||||
Credits.Graphic_Logic(complete || IsToRedraw);
|
||||
#endif
|
||||
|
||||
IsToRedraw = false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user