Add ScriptInterfaceLevel. Move ScriptInterfaceGame and GameScriptLevel to Scripting.

This commit is contained in:
hispidence 2022-01-24 21:11:02 +00:00
parent fe978daa9d
commit 9139a79367
4 changed files with 16 additions and 0 deletions

View file

@ -0,0 +1,68 @@
#pragma once
#include <string>
#include "GameScriptSkyLayer.h"
#include "GameScriptMirror.h"
#include "GameScriptColor.h"
#include "GameScriptInventoryObject.h"
#include <GameScriptFog.h>
enum class WeatherType
{
None,
Rain,
Snow
};
static const std::unordered_map<std::string, WeatherType> kWeatherTypes
{
{"None", WeatherType::None},
{"Rain", WeatherType::Rain},
{"Snow", WeatherType::Snow}
};
enum LaraType
{
Normal = 1,
Young = 2,
Bunhead = 3,
Catsuit = 4,
Divesuit = 5,
Invisible = 7
};
static const std::unordered_map<std::string, LaraType> kLaraTypes
{
{"Normal", LaraType::Normal},
{"Young", LaraType::Young},
{"Bunhead", LaraType::Bunhead},
{"Catsuit", LaraType::Catsuit},
{"Divesuit", LaraType::Divesuit},
{"Invisible", LaraType::Invisible}
};
struct GameScriptLevel
{
std::string NameStringKey;
std::string FileName;
std::string ScriptFileName;
std::string LoadScreenFileName;
std::string AmbientTrack;
GameScriptSkyLayer Layer1;
GameScriptSkyLayer Layer2;
bool Horizon{ false };
bool ColAddHorizon{ false };
GameScriptFog Fog;
bool Storm{ false };
WeatherType Weather{ WeatherType::None };
float WeatherStrength{ 1.0f };
bool Rumble{ false };
LaraType LaraType{ LaraType::Normal };
GameScriptMirror Mirror;
int LevelFarView{ 0 };
bool UnlimitedAir{ false };
std::vector<GameScriptInventoryObject> InventoryObjects;
void SetWeatherStrength(float val);
void SetLevelFarView(byte val);
static void Register(sol::state* state);
};

View file

@ -0,0 +1,37 @@
#pragma once
#include <string>
#include <functional>
#include "room.h"
#include "level.h"
typedef DWORD D3DCOLOR;
using VarMapVal = std::variant< short,
std::reference_wrapper<MESH_INFO>,
std::reference_wrapper<LEVEL_CAMERA_INFO>,
std::reference_wrapper<SINK_INFO>,
std::reference_wrapper<SOUND_SOURCE_INFO>,
std::reference_wrapper<AI_OBJECT>>;
using CallbackDrawString = std::function<void(std::string const&, D3DCOLOR, int, int, int)>;
class ScriptInterfaceGame {
public:
virtual ~ScriptInterfaceGame() = default;
virtual void ProcessDisplayStrings(float dt) = 0;
virtual void InitCallbacks() = 0;
virtual void OnStart() = 0;
virtual void OnLoad() = 0;
virtual void OnControlPhase(float dt) = 0;
virtual void OnSave() = 0;
virtual void OnEnd() = 0;
virtual void SetCallbackDrawString(CallbackDrawString) = 0;
virtual void FreeLevelScripts() = 0;
virtual bool AddName(std::string const& key, VarMapVal val) = 0;
virtual void ExecuteScriptFile(std::string const& luaFileName) = 0;
virtual void ExecuteFunction(std::string const& luaFileName) = 0;
virtual void AssignItemsAndLara() = 0;
};

View file

@ -0,0 +1,16 @@
#pragma once
enum class WeatherType
{
None,
Rain,
Snow
};
class ScriptInterfaceLevel {
public:
virtual ~ScriptInterfaceLevel() = default;
virtual bool GetSkyLayerEnabled(int index) = 0;
virtual short GetSkyLayerSpeed(int index) = 0;
};

View file

@ -0,0 +1,172 @@
#include "frameworkandsol.h"
#include "GameScriptLevel.h"
#include "ScriptAssert.h"
/***
Stores level metadata.
These are things things which aren't present in the compiled level file itself.
@pregameclass Level
@pragma nostrip
*/
/*** Make a new Level object.
@function Level.new
@return a Level object
*/
void GameScriptLevel::Register(sol::state* state)
{
state->new_usertype<GameScriptLevel>("Level",
sol::constructors<GameScriptLevel()>(),
/// (string) string key for the level's (localised) name.
// Corresponds to an entry in strings.lua.
//@mem nameKey
"nameKey", &GameScriptLevel::NameStringKey,
/// (string) Level-specific Lua script file.
// Path of the Lua file holding the level's logic script, relative to the location of the tombengine executable
//@mem scriptFile
"scriptFile", &GameScriptLevel::ScriptFileName,
/// (string) Compiled file path.
// This path is relative to the location of the TombEngine executable.
//@mem levelFile
"levelFile", &GameScriptLevel::FileName,
/// (string) Load screen image.
// Path of the level's load screen file (.png or .jpg), relative to the location of the tombengine executable
//@mem loadScreenFile
"loadScreenFile", &GameScriptLevel::LoadScreenFileName,
/// (string) initial ambient sound track to play.
// This is the filename of the track __without__ the .wav extension.
//@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,
/// (@{Fog}) omni fog RGB color and distance.
// As seen in TR4's Desert Railroad.
// If not provided, distance fog will be black.
//
// __(not yet implemented)__
//@mem fog
"fog", &GameScriptLevel::Fog,
/// (bool) Draw sky layer? (default: false)
//@mem horizon
"horizon", &GameScriptLevel::Horizon,
/// (bool) Enable smooth transition from horizon graphic to sky layer.
// If set to false, there will be a black band between the two.
//
// __(not yet implemented)__
//@mem colAddHorizon
"colAddHorizon", &GameScriptLevel::ColAddHorizon,
/// (bool) Enable flickering lightning in the sky.
// Equivalent to classic TRLE's LIGHTNING setting. As in the TRC Ireland levels.
//
//@mem storm
"storm", &GameScriptLevel::Storm,
/// (WeatherType) Choose weather effect.
// Must be one of the values `WeatherType.None`, `WeatherType.Rain`, or `WeatherType.Snow`.
//
//@mem weather
"weather", &GameScriptLevel::Weather,
/// (float) Choose weather strength.
// Must be value between `0.1` and `1.0`.
//
//@mem weatherStrength
"weatherStrength", sol::property(&GameScriptLevel::SetWeatherStrength),
/*** (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) Enable occasional screen shake effect.
// As seen in TRC's Sinking Submarine.
//@mem rumble
"rumble", &GameScriptLevel::Rumble,
/// (@{Mirror}) Location and size of the level's mirror, if present.
//
// __(not yet implemented)__
//@mem mirror
"mirror", &GameScriptLevel::Mirror,
/*** (byte) The maximum draw distance for level.
Given in sectors (blocks).
Must be in the range [1, 127], and equal to or less than the value passed to SetGameFarView.
This is equivalent to TRNG's LevelFarView variable.
__(not yet implemented)__
@mem farView
*/
"farView", sol::property(&GameScriptLevel::SetLevelFarView),
/*** (bool) Enable unlimited oxygen supply when in water.
__(not yet implemented)__
@mem unlimitedAir
*/
"unlimitedAir", &GameScriptLevel::UnlimitedAir,
/// (table of @{InventoryObject}s) table of inventory object overrides
//@mem objects
"objects", &GameScriptLevel::InventoryObjects
);
}
void GameScriptLevel::SetWeatherStrength(float val)
{
bool cond = val <= 1.0f && val >= 0.0f;
std::string msg{ "weatherStrength value must be in the range [0.1, 1.0]." };
if (!ScriptAssert(cond, msg))
{
ScriptWarn("Setting weatherStrength view to 1.");
WeatherStrength = 1.0f;
}
else
{
WeatherStrength = val;
}
}
void GameScriptLevel::SetLevelFarView(byte val)
{
bool cond = val <= 127 && val >= 1;
std::string msg{ "levelFarView value must be in the range [1, 127]." };
if (!ScriptAssert(cond, msg))
{
ScriptWarn("Setting levelFarView view to 32.");
LevelFarView = 32;
}
else
{
LevelFarView = val;
}
}