aboutsummaryrefslogtreecommitdiff
path: root/engines/wintermute/base/base_game.cpp
diff options
context:
space:
mode:
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 {