From cc6c6092c725c15424aa7c47c0ab3a99705a58f1 Mon Sep 17 00:00:00 2001 From: Justin Marshall Date: Wed, 10 Jun 2020 20:13:22 -0700 Subject: [PATCH] Added more scripting functions. --- REDALERT/CONQUER.CPP | 2 +- REDALERT/FUNCTION.H | 2 +- REDALERT/MapScript.cpp | 26 ++++++++++++++++++++++++++ REDALERT/SCENARIO.CPP | 11 ++++++----- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/REDALERT/CONQUER.CPP b/REDALERT/CONQUER.CPP index b6b2d8a..a3e4eb5 100644 --- a/REDALERT/CONQUER.CPP +++ b/REDALERT/CONQUER.CPP @@ -2465,7 +2465,7 @@ Mono_Set_Cursor(0,0); #endif BEnd(BENCH_GAME_FRAME); - Scenario_PlayMapStart(); + Scenario_MapScriptFrame(); Sync_Delay(); return(!GameActive); diff --git a/REDALERT/FUNCTION.H b/REDALERT/FUNCTION.H index bc7caf7..fd89080 100644 --- a/REDALERT/FUNCTION.H +++ b/REDALERT/FUNCTION.H @@ -909,7 +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 Scenario_MapScriptFrame(void); void Set_Scenario_Difficulty(int difficulty); HousesType Select_House(void); void Clear_Scenario(void); diff --git a/REDALERT/MapScript.cpp b/REDALERT/MapScript.cpp index 3461abd..8fc67d4 100644 --- a/REDALERT/MapScript.cpp +++ b/REDALERT/MapScript.cpp @@ -4,6 +4,30 @@ #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)); @@ -63,6 +87,8 @@ bool MapScript::Init(const char* mapName) { 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; } diff --git a/REDALERT/SCENARIO.CPP b/REDALERT/SCENARIO.CPP index 47854f9..2737a1c 100644 --- a/REDALERT/SCENARIO.CPP +++ b/REDALERT/SCENARIO.CPP @@ -420,16 +420,17 @@ bool Start_Scenario(char * name, bool briefing) return(true); } -void Scenario_PlayMapStart(void) { +void Scenario_MapScriptFrame(void) { if (!mapScript) return; - if (!mapScriptPlayStart) + if (mapScriptPlayStart) { + mapScript->CallFunction("map_start"); + mapScriptPlayStart = false; return; + } - mapScript->CallFunction("map_start"); - - mapScriptPlayStart = false; + mapScript->CallFunction("map_frame"); }