aboutsummaryrefslogtreecommitdiff
path: root/engines/wintermute/base/base_game.cpp
diff options
context:
space:
mode:
authorlolbot-iichan2018-08-27 01:03:43 +0300
committerFilippos Karapetis2020-01-11 18:05:39 +0200
commite3595393c85cbffa4fd604527e747bc701a2d5f4 (patch)
tree24ab52ba8316943b28492e45f0c50ca2556f0d1e /engines/wintermute/base/base_game.cpp
parent04d47de5d68cccae617f31b55aebfc4de11252cb (diff)
downloadscummvm-rg350-e3595393c85cbffa4fd604527e747bc701a2d5f4.tar.gz
scummvm-rg350-e3595393c85cbffa4fd604527e747bc701a2d5f4.tar.bz2
scummvm-rg350-e3595393c85cbffa4fd604527e747bc701a2d5f4.zip
WINTERMUTE: Add FoxTail arrays methods
Game.Split(str,sep) is added to split string into array of substrings with separator array.Delete(index) is added to delete an array item by index
Diffstat (limited to 'engines/wintermute/base/base_game.cpp')
-rw-r--r--engines/wintermute/base/base_game.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/engines/wintermute/base/base_game.cpp b/engines/wintermute/base/base_game.cpp
index a0659cac86..16ad1f51a2 100644
--- a/engines/wintermute/base/base_game.cpp
+++ b/engines/wintermute/base/base_game.cpp
@@ -48,6 +48,7 @@
#include "engines/wintermute/base/base_surface_storage.h"
#include "engines/wintermute/base/saveload.h"
#include "engines/wintermute/base/save_thumb_helper.h"
+#include "engines/wintermute/base/scriptables/script_ext_array.h"
#include "engines/wintermute/base/scriptables/script_value.h"
#include "engines/wintermute/base/scriptables/script_engine.h"
#include "engines/wintermute/base/scriptables/script_stack.h"
@@ -3114,6 +3115,44 @@ bool BaseGame::externalCall(ScScript *script, ScStack *stack, ScStack *thisStack
stack->pushBool(val);
}
+#ifdef ENABLE_FOXTAIL
+ //////////////////////////////////////////////////////////////////////////
+ // [FoxTail] Split
+ // Returns array of words of a string, using another as a delimeter
+ // Used to split strings by 1 character delimeter in various scripts
+ // All the delimeters ever used in FoxTail are: " ", "@", "#", "$", "&"
+ // So, this implementation takes 1st char of delimeter string only
+ //////////////////////////////////////////////////////////////////////////
+ else if (strcmp(name, "Split") == 0) {
+ stack->correctParams(2);
+ const char *str = stack->pop()->getString();
+ const char sep = stack->pop()->getString()[0];
+ size_t size = strlen(str) + 1;
+
+ // There is no way to makeSXArray() with exactly 1 given element
+ // That's why we are creating empty Array and SXArray::push() later
+ stack->pushInt(0);
+ BaseScriptable *arr = makeSXArray(_gameRef, stack);
+
+ // Iterating string copy, replacing delimeter with '\0' and pushing matches
+ char *copy = new char[size];
+ strcpy(copy, str);
+ char *begin = copy;
+ for (char *it = copy; it < copy + size; it++) {
+ if (*it == sep || *it == '\0') {
+ *it = '\0';
+ stack->pushString(begin);
+ ((SXArray *)arr)->push(stack->pop());
+ begin = it + 1;
+ }
+ }
+
+ stack->pushNative(arr, false);
+
+ delete[] copy;
+ }
+#endif
+
//////////////////////////////////////////////////////////////////////////
// failure
else {