diff options
Diffstat (limited to 'src/control/Script.h')
-rw-r--r-- | src/control/Script.h | 67 |
1 files changed, 33 insertions, 34 deletions
diff --git a/src/control/Script.h b/src/control/Script.h index 18d148bf..59054be3 100644 --- a/src/control/Script.h +++ b/src/control/Script.h @@ -292,11 +292,43 @@ public: static bool IsDebugOn() { return DbgFlag; }; static void InvertDebugFlag() { DbgFlag = !DbgFlag; } - static int32* GetPointerToScriptVariable(int32 offset) { return (int32*)&ScriptSpace[offset]; } + static int32* GetPointerToScriptVariable(int32 offset) { assert(offset >= 8 && offset < CTheScripts::GetSizeOfVariableSpace()); return (int32*)&ScriptSpace[offset]; } static void ResetCountdownToMakePlayerUnsafe() { CountdownToMakePlayerUnsafe = 0; } static bool IsCountdownToMakePlayerUnsafeOn() { return CountdownToMakePlayerUnsafe != 0; } + static int32 Read4BytesFromScript(uint32* pIp) { + int32 retval = ScriptSpace[*pIp + 3] << 24 | ScriptSpace[*pIp + 2] << 16 | ScriptSpace[*pIp + 1] << 8 | ScriptSpace[*pIp]; + *pIp += 4; + return retval; + } + static int16 Read2BytesFromScript(uint32* pIp) { + int16 retval = ScriptSpace[*pIp + 1] << 8 | ScriptSpace[*pIp]; + *pIp += 2; + return retval; + } + static int8 Read1ByteFromScript(uint32* pIp) { + int8 retval = ScriptSpace[*pIp]; + *pIp += 1; + return retval; + } + static float ReadFloatFromScript(uint32* pIp) { + return Read2BytesFromScript(pIp) / 16.0f; + } + static void ReadTextLabelFromScript(uint32* pIp, char* buf) { + strncpy(buf, (const char*)&CTheScripts::ScriptSpace[*pIp], KEY_LENGTH_IN_SCRIPT); + } + static wchar* GetTextByKeyFromScript(uint32* pIp) { + wchar* text = TheText.Get((const char*)&CTheScripts::ScriptSpace[*pIp]); + *pIp += KEY_LENGTH_IN_SCRIPT; + return text; + } + static int32 GetSizeOfVariableSpace() + { + uint32 tmp = 3; + return Read4BytesFromScript(&tmp); + } + private: static CRunningScript* StartNewScript(uint32); @@ -387,39 +419,6 @@ public: m_anLocalVariables[NUM_LOCAL_VARS + 1] += timeStep; } - static int32 Read4BytesFromScript(uint32* pIp) { - int32 retval = 0; - for (int i = 0; i < 4; i++) { - retval |= CTheScripts::ScriptSpace[(*pIp)++] << (8 * i); - } - return retval; - } - static int16 Read2BytesFromScript(uint32* pIp) { - int16 retval = 0; - for (int i = 0; i < 2; i++) { - retval |= CTheScripts::ScriptSpace[(*pIp)++] << (8 * i); - } - return retval; - } - static int8 Read1ByteFromScript(uint32* pIp) { - int8 retval = 0; - for (int i = 0; i < 1; i++) { - retval |= CTheScripts::ScriptSpace[(*pIp)++] << (8 * i); - } - return retval; - } - static float ReadFloatFromScript(uint32* pIp) { - return Read2BytesFromScript(pIp) / 16.0f; - } - static void ReadTextLabelFromScript(uint32* pIp, char* buf) { - strncpy(buf, (const char*)&CTheScripts::ScriptSpace[*pIp], KEY_LENGTH_IN_SCRIPT); - } - static wchar* GetTextByKeyFromScript(uint32* pIp) { - wchar* text = TheText.Get((const char*)&CTheScripts::ScriptSpace[*pIp]); - *pIp += KEY_LENGTH_IN_SCRIPT; - return text; - } - void Init(); void Process(); |