2017-01-20 14:36:52 +01:00
|
|
|
#pragma once
|
|
|
|
|
2017-01-19 22:23:59 +01:00
|
|
|
namespace Components
|
|
|
|
{
|
|
|
|
class Script : public Component
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Script();
|
2022-05-05 15:03:14 +01:00
|
|
|
|
2022-11-29 14:18:10 +00:00
|
|
|
using scriptNames = std::vector<std::string>;
|
2022-07-18 13:01:29 +02:00
|
|
|
static void AddFunction(const std::string& name, Game::BuiltinFunction func, bool type = false);
|
|
|
|
static void AddMethod(const std::string& name, Game::BuiltinMethod func, bool type = false);
|
2017-01-19 22:23:59 +01:00
|
|
|
|
2022-11-29 14:18:10 +00:00
|
|
|
static void AddFuncMultiple(Game::BuiltinFunction func, bool type, scriptNames);
|
|
|
|
static void AddMethMultiple(Game::BuiltinMethod func, bool type, scriptNames);
|
|
|
|
|
2022-02-01 13:29:27 +01:00
|
|
|
static Game::client_t* GetClient(const Game::gentity_t* gentity);
|
2020-07-23 06:36:35 +03:00
|
|
|
|
2022-11-24 15:30:06 +00:00
|
|
|
// Probably a macro 'originally' but this is fine
|
|
|
|
static Game::gentity_s* Scr_GetPlayerEntity(Game::scr_entref_t entref)
|
|
|
|
{
|
2023-03-03 23:35:30 +00:00
|
|
|
if (entref.classnum)
|
2022-11-24 15:30:06 +00:00
|
|
|
{
|
|
|
|
Game::Scr_ObjectError("not an entity");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(entref.entnum < Game::MAX_GENTITIES);
|
|
|
|
|
|
|
|
auto* ent = &Game::g_entities[entref.entnum];
|
|
|
|
if (ent->client == nullptr)
|
|
|
|
{
|
|
|
|
Game::Scr_ObjectError(Utils::String::VA("entity %i is not a player", entref.entnum));
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ent;
|
|
|
|
}
|
|
|
|
|
2017-01-19 22:23:59 +01:00
|
|
|
private:
|
2022-07-18 13:01:29 +02:00
|
|
|
struct ScriptFunction
|
|
|
|
{
|
|
|
|
Game::BuiltinFunction actionFunc;
|
|
|
|
bool type;
|
2022-11-29 14:18:10 +00:00
|
|
|
scriptNames aliases;
|
2022-07-18 13:01:29 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ScriptMethod
|
|
|
|
{
|
|
|
|
Game::BuiltinMethod actionFunc;
|
|
|
|
bool type;
|
2022-11-29 14:18:10 +00:00
|
|
|
scriptNames aliases;
|
2022-07-18 13:01:29 +02:00
|
|
|
};
|
|
|
|
|
2022-11-29 14:18:10 +00:00
|
|
|
static std::vector<ScriptFunction> CustomScrFunctions;
|
|
|
|
static std::vector<ScriptMethod> CustomScrMethods;
|
2022-07-18 13:01:29 +02:00
|
|
|
|
2022-11-24 15:30:06 +00:00
|
|
|
static std::unordered_map<std::string, int> ScriptMainHandles;
|
|
|
|
static std::unordered_map<std::string, int> ScriptInitHandles;
|
2022-06-25 14:22:13 +02:00
|
|
|
|
|
|
|
static void Scr_LoadGameType_Stub();
|
|
|
|
static void Scr_StartupGameType_Stub();
|
|
|
|
static void GScr_LoadGameTypeScript_Stub();
|
2017-04-29 23:08:41 +02:00
|
|
|
|
2022-04-12 14:34:51 +02:00
|
|
|
static Game::BuiltinFunction BuiltIn_GetFunctionStub(const char** pName, int* type);
|
2022-07-18 13:01:29 +02:00
|
|
|
static Game::BuiltinMethod BuiltIn_GetMethodStub(const char** pName, int* type);
|
2017-05-13 12:09:58 +02:00
|
|
|
|
2021-11-13 13:22:06 +00:00
|
|
|
static unsigned int SetExpFogStub();
|
2017-01-19 22:23:59 +01:00
|
|
|
};
|
|
|
|
}
|