mirror of
https://github.com/jmarshall23/CnC_Remastered_Collection.git
synced 2026-08-12 08:00:55 +02:00
Merge remote-tracking branch 'jmarshall23/master' into jm-linux
This commit is contained in:
@@ -1,94 +0,0 @@
|
||||
// MapScript.cpp
|
||||
//
|
||||
|
||||
#include "FUNCTION.H"
|
||||
#include "MapScript.h"
|
||||
|
||||
static int Script_GiveMoney(lua_State* L) {
|
||||
int cashToGive = lua_tointeger(L, -1);
|
||||
PlayerPtr->Refund_Money(cashToGive);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int Script_NumBuildingTypeForPlayer(lua_State* L) {
|
||||
int houseType = lua_tointeger(L, 1);
|
||||
int structType = lua_tointeger(L, 2);
|
||||
int result = 0;
|
||||
for (int b_index = 0; b_index < Buildings.Count(); b_index++) {
|
||||
BuildingClass* building = Buildings.Ptr(b_index);
|
||||
|
||||
if (building->Owner() == houseType) {
|
||||
if (building->Class->Type == structType) {
|
||||
result++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lua_pushnumber(L, result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
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);
|
||||
lua_register(L, "NumBuildingTypeForPlayer", Script_NumBuildingTypeForPlayer);
|
||||
lua_register(L, "GiveMoney", Script_GiveMoney);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
################################################################################
|
||||
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
|
||||
################################################################################
|
||||
|
||||
/.vs
|
||||
/out
|
||||
@@ -101,7 +101,6 @@ set(src_win32lib
|
||||
./REDALERT/WIN32LIB/_DIPTABL.CPP
|
||||
)
|
||||
|
||||
#Red Alert files
|
||||
set(src_REDALERT
|
||||
./REDALERT/2KEYFRAM.CPP
|
||||
./REDALERT/AADATA.CPP
|
||||
@@ -708,12 +707,7 @@ set(src_external
|
||||
add_definitions(-DCHEAT_KEYS -DIMGUI_IMPL_OPENGL_LOADER_GLEW -DSCENARIO_EDITOR -DWINDOWS_IGNORE_PACKING_MISMATCH -DTRUE_FALSE_DEFINED -DWIN32 -DWINDOWS -DENGLISH -D_USRDLL -DREDALERT_EXPORTS)
|
||||
|
||||
if (MSVC)
|
||||
add_compile_options(/permissive+ /Zc:forScope- /Zp1)
|
||||
set_target_properties(RedAlert PROPERTIES OUTPUT_NAME "RedAlert" LINK_FLAGS "/PDB:\"RedAlert.pdb\" /SUBSYSTEM:WINDOWS" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/.." )
|
||||
target_include_directories(RedAlert PRIVATE ./external/;./redalert/win32lib;./external/lua/;./external/imgui;./external/dxsdk/Include;./external/ffmpeg-win32/include;./external/sdl2/include;./win32lib;./external/openal/include)
|
||||
target_link_libraries(RedAlert "opengl32.lib" "winmm.lib" "Ws2_32.lib" "${CMAKE_SOURCE_DIR}/external/sdl2/lib/x86/SDL2.lib" "${CMAKE_SOURCE_DIR}/external/openal/out/build/x86-Release/OpenAL32.lib")
|
||||
endif(MSVC)
|
||||
add_executable(REDALERT ${src_win32lib} ${src_REDALERT} ${src_external})
|
||||
|
||||
|
||||
|
||||
set_target_properties(REDALERT PROPERTIES OUTPUT_NAME "REDALERT" LINK_FLAGS "/PDB:\"REDALERT.pdb\" /SUBSYSTEM:WINDOWS")
|
||||
target_include_directories(REDALERT PRIVATE ./external/;./REDALERT/win32lib;./external/lua/;./external/imgui;./external/dxsdk/Include;./external/ffmpeg-win32/include;./external/sdl2/include;./win32lib;./external/openal/include)
|
||||
target_link_libraries(REDALERT "opengl32.lib" "winmm.lib" "Ws2_32.lib" "${CMAKE_SOURCE_DIR}/external/dxsdk/Lib/x86/d3dx9.lib" "${CMAKE_SOURCE_DIR}/external/sdl2/lib/x86/SDL2.lib" "${CMAKE_SOURCE_DIR}/external/openal/out/build/x86-Release/OpenAL32.lib")
|
||||
@@ -11,6 +11,18 @@
|
||||
"ctestCommandArgs": "",
|
||||
"inheritEnvironments": [ "msvc_x86" ],
|
||||
"variables": []
|
||||
},
|
||||
{
|
||||
"name": "x86-Release",
|
||||
"generator": "Ninja",
|
||||
"configurationType": "RelWithDebInfo",
|
||||
"buildRoot": "${projectDir}\\out\\build\\${name}",
|
||||
"installRoot": "${projectDir}\\out\\install\\${name}",
|
||||
"cmakeCommandArgs": "",
|
||||
"buildCommandArgs": "",
|
||||
"ctestCommandArgs": "",
|
||||
"inheritEnvironments": [ "msvc_x86" ],
|
||||
"variables": []
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,305 @@
|
||||
// CONSOLE.CPP
|
||||
//
|
||||
|
||||
#include "imgui.h"
|
||||
#include "FUNCTION.H"
|
||||
|
||||
char console_text[16384];
|
||||
int console_text_len = 0;
|
||||
char command_text[512];
|
||||
|
||||
#define MAX_ARGS 80
|
||||
|
||||
static int cmd_argc;
|
||||
static char* cmd_argv[MAX_ARGS];
|
||||
static char* cmd_null_string = "";
|
||||
static char* cmd_args = NULL;
|
||||
|
||||
char com_token[1024];
|
||||
int com_argc;
|
||||
char** com_argv;
|
||||
|
||||
typedef struct cmd_function_s
|
||||
{
|
||||
struct cmd_function_s* next;
|
||||
char* name;
|
||||
xcommand_t function;
|
||||
} cmd_function_t;
|
||||
|
||||
static bool executeConsoleCommand = false;
|
||||
|
||||
static cmd_function_t* cmd_functions; // possible commands to execute
|
||||
|
||||
/*
|
||||
============
|
||||
Cmd_AddCommand
|
||||
============
|
||||
*/
|
||||
void Cmd_AddCommand(char* cmd_name, xcommand_t function)
|
||||
{
|
||||
cmd_function_t* cmd;
|
||||
|
||||
// fail if the command already exists
|
||||
for (cmd = cmd_functions; cmd; cmd = cmd->next)
|
||||
{
|
||||
if (!strcmp(cmd_name, cmd->name))
|
||||
{
|
||||
Console_Printf("Cmd_AddCommand: %s already defined\n", cmd_name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
cmd = (cmd_function_t *)malloc(sizeof(cmd_function_t));
|
||||
cmd->name = cmd_name;
|
||||
cmd->function = function;
|
||||
cmd->next = cmd_functions;
|
||||
cmd_functions = cmd;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
==============
|
||||
Cmd_Argc
|
||||
==============
|
||||
*/
|
||||
int Cmd_Argc() {
|
||||
return cmd_argc;
|
||||
}
|
||||
|
||||
/*
|
||||
==============
|
||||
Cmd_Argv
|
||||
==============
|
||||
*/
|
||||
char* Cmd_Argv(int index) {
|
||||
return cmd_argv[index];
|
||||
}
|
||||
|
||||
/*
|
||||
==============
|
||||
COM_Parse
|
||||
|
||||
Parse a token out of a string
|
||||
==============
|
||||
*/
|
||||
char* COM_Parse(char* data)
|
||||
{
|
||||
int c;
|
||||
int len;
|
||||
|
||||
len = 0;
|
||||
com_token[0] = 0;
|
||||
|
||||
if (!data)
|
||||
return NULL;
|
||||
|
||||
// skip whitespace
|
||||
skipwhite:
|
||||
while ((c = *data) <= ' ')
|
||||
{
|
||||
if (c == 0)
|
||||
return NULL; // end of file;
|
||||
data++;
|
||||
}
|
||||
|
||||
// skip // comments
|
||||
if (c == '/' && data[1] == '/')
|
||||
{
|
||||
while (*data && *data != '\n')
|
||||
data++;
|
||||
goto skipwhite;
|
||||
}
|
||||
|
||||
|
||||
// handle quoted strings specially
|
||||
if (c == '\"')
|
||||
{
|
||||
data++;
|
||||
while (1)
|
||||
{
|
||||
c = *data++;
|
||||
if (c == '\"' || !c)
|
||||
{
|
||||
com_token[len] = 0;
|
||||
return data;
|
||||
}
|
||||
com_token[len] = c;
|
||||
len++;
|
||||
}
|
||||
}
|
||||
|
||||
// parse single characters
|
||||
if (c == '{' || c == '}' || c == ')' || c == '(' || c == '\'' || c == ':')
|
||||
{
|
||||
com_token[len] = c;
|
||||
len++;
|
||||
com_token[len] = 0;
|
||||
return data + 1;
|
||||
}
|
||||
|
||||
// parse a regular word
|
||||
do
|
||||
{
|
||||
com_token[len] = c;
|
||||
data++;
|
||||
len++;
|
||||
c = *data;
|
||||
if (c == '{' || c == '}' || c == ')' || c == '(' || c == '\'' || c == ':')
|
||||
break;
|
||||
} while (c > 32);
|
||||
|
||||
com_token[len] = 0;
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
============
|
||||
Cmd_TokenizeString
|
||||
|
||||
Parses the given string into command line tokens.
|
||||
============
|
||||
*/
|
||||
void Cmd_TokenizeString(char* text)
|
||||
{
|
||||
int i;
|
||||
|
||||
// clear the args from the last string
|
||||
for (i = 0; i < cmd_argc; i++)
|
||||
free(cmd_argv[i]);
|
||||
|
||||
cmd_argc = 0;
|
||||
cmd_args = NULL;
|
||||
|
||||
while (1)
|
||||
{
|
||||
// skip whitespace up to a /n
|
||||
while (*text && *text <= ' ' && *text != '\n')
|
||||
{
|
||||
text++;
|
||||
}
|
||||
|
||||
if (*text == '\n')
|
||||
{ // a newline seperates commands in the buffer
|
||||
text++;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!*text)
|
||||
return;
|
||||
|
||||
if (cmd_argc == 1)
|
||||
cmd_args = text;
|
||||
|
||||
text = COM_Parse(text);
|
||||
if (!text)
|
||||
return;
|
||||
|
||||
if (cmd_argc < MAX_ARGS)
|
||||
{
|
||||
cmd_argv[cmd_argc] = (char *)malloc(strlen(com_token) + 1);
|
||||
strcpy(cmd_argv[cmd_argc], com_token);
|
||||
cmd_argc++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
====================
|
||||
Console_Init
|
||||
====================
|
||||
*/
|
||||
void Console_Init(void) {
|
||||
memset(command_text, 0, sizeof(command_text));
|
||||
memset(console_text, 0, sizeof(console_text));
|
||||
console_text_len = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
====================
|
||||
Console_Render
|
||||
====================
|
||||
*/
|
||||
void Console_Printf(const char* fmt, ...) {
|
||||
va_list argptr;
|
||||
char msg[4096];
|
||||
|
||||
va_start(argptr, fmt);
|
||||
vsprintf(msg, fmt, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
int len = strlen(msg);
|
||||
strcpy(&console_text[console_text_len], msg);
|
||||
|
||||
OutputDebugStringA(msg);
|
||||
console_text_len += len;
|
||||
}
|
||||
|
||||
/*
|
||||
====================
|
||||
ExecuteConsoleCommand
|
||||
====================
|
||||
*/
|
||||
void ExecuteConsoleCommand(void) {
|
||||
cmd_function_t* cmd;
|
||||
|
||||
if (strlen(command_text) <= 0)
|
||||
return;
|
||||
|
||||
Console_Printf("%s\n", command_text);
|
||||
Cmd_TokenizeString(command_text);
|
||||
|
||||
memset(command_text, 0, sizeof(command_text));
|
||||
|
||||
for (cmd = cmd_functions; cmd; cmd = cmd->next)
|
||||
{
|
||||
if (!strcmp(Cmd_Argv(0), cmd->name))
|
||||
{
|
||||
cmd->function();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Console_Printf("Unknown command %s\n", Cmd_Argv(0));
|
||||
}
|
||||
|
||||
/*
|
||||
====================
|
||||
Console_Render
|
||||
====================
|
||||
*/
|
||||
void Console_Render(void) {
|
||||
bool ScreenActive;
|
||||
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
style.FramePadding = ImVec2(0, 0);
|
||||
ImGui::SetNextWindowSize(ImVec2(420, 270));
|
||||
ImGui::SetNextWindowPos(ImVec2(0, 0));
|
||||
ImGui::Begin("Developer Console", &ScreenActive, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoScrollbar);
|
||||
ImVec2 textres(420, 180);
|
||||
ImGui::PushID("ConsoleTxt");
|
||||
ImGui::InputTextMultiline("", &console_text[0], sizeof(console_text), textres, ImGuiInputTextFlags_ReadOnly);
|
||||
ImGui::PopID();
|
||||
ImGui::Text("Commands");
|
||||
ImGui::PushID("CmdTxt");
|
||||
ImGui::InputText("", &command_text[0], sizeof(command_text));
|
||||
ImGui::PopID();
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Execute")) {
|
||||
executeConsoleCommand = true;
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
Console_Tick
|
||||
=================
|
||||
*/
|
||||
void Console_Tick(void) {
|
||||
if (executeConsoleCommand) {
|
||||
ExecuteConsoleCommand();
|
||||
executeConsoleCommand = false;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user