From 9fbb3cc7b7486aa3d0561a082dabffe81ff413fb Mon Sep 17 00:00:00 2001 From: hispidence Date: Sat, 7 Aug 2021 19:20:17 +0100 Subject: [PATCH] Improve GameScriptLevel. Rename LARA_DRAW_TYPE to LARA_TYPE as it's used in more than just drawing code. Make WEATHER_TYPE a scoped enum (would have done this for LARA_TYPE too but didn't want to pepper casts in other parts of the codebase). Relabel constants in both enums. Add kLaraTypes and kWeatherTypes and add them as tables in GameFlow. Remove Background member - it's not level-specific so GameFlow is a better home for it. Add (incomplete for now) documentation for some GameScriptLevel members - those I tested, at any rate. --- TR5Main/Scripting/GameFlowScript.cpp | 3 + TR5Main/Scripting/GameScriptLevel.cpp | 80 ++++++++++++++++++++++++++- TR5Main/Scripting/GameScriptLevel.h | 46 +++++++++------ 3 files changed, 112 insertions(+), 17 deletions(-) diff --git a/TR5Main/Scripting/GameFlowScript.cpp b/TR5Main/Scripting/GameFlowScript.cpp index 809c8918b..3c4aab248 100644 --- a/TR5Main/Scripting/GameFlowScript.cpp +++ b/TR5Main/Scripting/GameFlowScript.cpp @@ -81,6 +81,9 @@ __(not yet implemented)__ @tparam table table array-style table with TODO EXTRA INFO HERE */ m_lua->set_function("SetSettings", &GameFlow::SetSettings, this); + + MakeReadOnlyTable("WeatherType", kWeatherTypes); + MakeReadOnlyTable("LaraType", kLaraTypes); } GameFlow::~GameFlow() diff --git a/TR5Main/Scripting/GameScriptLevel.cpp b/TR5Main/Scripting/GameScriptLevel.cpp index 8bf9da0a1..3f93f18a7 100644 --- a/TR5Main/Scripting/GameScriptLevel.cpp +++ b/TR5Main/Scripting/GameScriptLevel.cpp @@ -1,27 +1,105 @@ #include "framework.h" #include "GameScriptLevel.h" +#include + +/*** +A container for level metadata - things which aren't present in the compiled +level file itself. + +@classmod Level +@pragma nostrip +*/ void GameScriptLevel::Register(sol::state* state) { state->new_usertype("Level", sol::constructors(), + +/// (string) todo +//@mem name "name", &GameScriptLevel::NameStringKey, + +/// (string) todo +//@mem script "script", &GameScriptLevel::ScriptFileName, + +/// (string) todo +//@mem fileName "fileName", &GameScriptLevel::FileName, + +/// (string) todo +//@mem loadScreen "loadScreen", &GameScriptLevel::LoadScreenFileName, + +/// (string) todo +//@mem ambientTrack "ambientTrack", &GameScriptLevel::AmbientTrack, + +/// (@{SkyLayer}) Primary sky layer +//@mem layer1 "layer1", &GameScriptLevel::Layer1, + +/// (@{SkyLayer}) Secondary sky layer __(not yet implemented)__ +//@mem layer2 "layer2", &GameScriptLevel::Layer2, + +/// (@{Color}) distance fog RGB color (as seen in TR4's Desert Railroad). +// if not provided, distance fog will be black. +// __(not yet implemented)__ +//@mem fog "fog", &GameScriptLevel::Fog, + +/// (bool) if set to true, the horizon and sky layer will be drawn; if set to false; they won't. +//@mem horizon "horizon", &GameScriptLevel::Horizon, + +/// (bool) if true, the horizon graphic will transition smoothly to the sky layer. +// If set to false, there will be a black band between the two. +// __(not yet implemented)__ +//@mem colAddHorizon "colAddHorizon", &GameScriptLevel::ColAddHorizon, + +/// (bool) equivalent to classic TRLE's LIGHTNING setting. +// If true, there will be a flickering lightning in the skylayer, as in the TRC Ireland levels. +// __(thunder sounds not yet implemented)__ +//@mem storm "storm", &GameScriptLevel::Storm, - "background", &GameScriptLevel::Background, + +/// (WeatherType) Must be one of the values WeatherType.NORMAL, WeatherType.RAIN, or WeatherType.SNOW. +// __(not yet implemented)__ +//@mem weather "weather", &GameScriptLevel::Weather, + +/*** (LaraType) Must be one of the LaraType values. +These are: + + NORMAL + YOUNG + BUNHEAD + CATSUIT + DIVESUIT + INVISIBLE + +e.g. `myLevel.laraType = LaraType.DIVESUIT` + + __(not yet fully implemented)__ + @mem laraType*/ "laraType", &GameScriptLevel::LaraType, + +/// (bool) todo +//@mem rumble "rumble", &GameScriptLevel::Rumble, + +/// (bool) todo +//@mem resetHub "resetHub", &GameScriptLevel::ResetHub, + +/// (Mirror) todo +//@mem mirror "mirror", &GameScriptLevel::Mirror, + +/// (table of InventoryObjects) todo +//@mem mirror "objects", &GameScriptLevel::InventoryObjects ); } diff --git a/TR5Main/Scripting/GameScriptLevel.h b/TR5Main/Scripting/GameScriptLevel.h index c20b22c04..4b58bb101 100644 --- a/TR5Main/Scripting/GameScriptLevel.h +++ b/TR5Main/Scripting/GameScriptLevel.h @@ -5,21 +5,36 @@ #include "GameScriptColor.h" #include "GameScriptInventoryObject.h" -enum WEATHER_TYPE +enum class WEATHER_TYPE { - WEATHER_NORMAL, - WEATHER_RAIN, - WEATHER_SNOW + NORMAL, + RAIN, + SNOW }; -enum LARA_DRAW_TYPE +static const std::unordered_map kWeatherTypes{ + {"NORMAL", WEATHER_TYPE::NORMAL}, + {"RAIN", WEATHER_TYPE::RAIN}, + {"SNOW", WEATHER_TYPE::SNOW} +}; + +enum LARA_TYPE { - LARA_NORMAL = 1, - LARA_YOUNG = 2, - LARA_BUNHEAD = 3, - LARA_CATSUIT = 4, - LARA_DIVESUIT = 5, - LARA_INVISIBLE = 7 + NORMAL = 1, + YOUNG = 2, + BUNHEAD = 3, + CATSUIT = 4, + DIVESUIT = 5, + INVISIBLE = 7 +}; + +static const std::unordered_map kLaraTypes{ + {"NORMAL", LARA_TYPE::NORMAL}, + {"YOUNG", LARA_TYPE::YOUNG}, + {"BUNHEAD", LARA_TYPE::BUNHEAD}, + {"CATSUIT", LARA_TYPE::CATSUIT}, + {"DIVESUIT", LARA_TYPE::DIVESUIT}, + {"INVISIBLE", LARA_TYPE::INVISIBLE} }; struct GameScriptLevel @@ -28,7 +43,6 @@ struct GameScriptLevel std::string FileName; std::string ScriptFileName; std::string LoadScreenFileName; - std::string Background; int Name; std::string AmbientTrack; GameScriptSkyLayer Layer1; @@ -36,17 +50,17 @@ struct GameScriptLevel bool Horizon{ false }; bool Sky; bool ColAddHorizon{ false }; - GameScriptColor Fog{ 0,0,0 }; + GameScriptColor Fog{ 0, 0, 0 }; bool Storm{ false }; - WEATHER_TYPE Weather{ WEATHER_NORMAL }; + WEATHER_TYPE Weather{ WEATHER_TYPE::NORMAL }; bool ResetHub{ false }; bool Rumble{ false }; - LARA_DRAW_TYPE LaraType{ LARA_NORMAL }; + LARA_TYPE LaraType{ LARA_TYPE::NORMAL }; GameScriptMirror Mirror; byte UVRotate; int LevelFarView; bool UnlimitedAir{ false }; std::vector InventoryObjects; - + static void Register(sol::state* state); };