scummvm/engines/private/funcs.cpp

284 lines
7.3 KiB
C++
Raw Normal View History

2021-01-02 00:58:58 -03:00
#include "common/str.h"
#include "common/debug.h"
#include "common/system.h"
2021-01-02 00:58:58 -03:00
#include "grammar.h"
2021-01-05 21:03:34 -03:00
#include "grammar.tab.h"
2021-01-02 00:58:58 -03:00
#include "private.h"
namespace Private {
2021-01-02 10:22:07 -03:00
void ChgMode(ArgArray args) {
// assert types
debug("ChgMode(%d, %s)", args[0].u.val, args[1].u.str);
2021-01-07 23:32:17 -03:00
g_private->_mode = args[0].u.val;
2021-01-05 21:03:34 -03:00
Common::String *s = new Common::String(args[1].u.str);
2021-01-07 23:32:17 -03:00
g_private->_nextSetting = s;
2021-01-08 22:42:34 -03:00
if (g_private->_mode == 0) {
g_private->_origin->x = 0;
g_private->_origin->y = 0;
2021-01-09 19:11:41 -03:00
// TODO: should clear the screen?
}
2021-01-08 22:42:34 -03:00
else if (g_private->_mode == 1) {
g_private->_origin->x = 63;
g_private->_origin->y = 48;
2021-01-09 16:11:30 -03:00
g_private->drawScreenFrame();
2021-01-08 22:42:34 -03:00
}
else
assert(0);
}
void VSPicture(ArgArray args) {
// assert types
debug("VSPicture(%s)", args[0].u.str);
g_private->_nextVS = new Common::String(args[0].u.str);
2021-01-02 10:22:07 -03:00
}
2021-01-08 22:42:34 -03:00
2021-01-02 10:22:07 -03:00
void Goto(ArgArray args) { // should be goto, but this is a reserved word
2021-01-05 21:03:34 -03:00
// assert types
debug("goto(%s)", args[0].u.str);
2021-01-05 21:03:34 -03:00
Common::String *s = new Common::String(args[0].u.str);
2021-01-07 23:32:17 -03:00
g_private->_nextSetting = s;
2021-01-02 10:22:07 -03:00
}
void Quit(ArgArray args) {
2021-01-09 22:08:41 -03:00
debug("Quit()");
g_private->quitGame();
}
2021-01-09 22:08:41 -03:00
void LoadGame(ArgArray args) {
// assert types
debug("WARNING: RestartGame is not implemented");
}
2021-01-08 22:42:34 -03:00
void RestartGame(ArgArray args) {
// assert types
debug("WARNING: RestartGame is not implemented");
}
void DossierAdd(ArgArray args) {
// assert types
debug("WARNING: DossierAdd is not implemented");
}
2021-01-09 16:11:30 -03:00
void Inventory(ArgArray args) {
// assert types
debug("WARNING: Inventory is not implemented");
}
2021-01-02 10:22:07 -03:00
void SetFlag(ArgArray args) {
2021-01-05 21:03:34 -03:00
// assert types
debug("SetFlag(%s, %d)", args[0].u.sym->name->c_str(), args[1].u.val);
args[0].u.sym->u.val = args[1].u.val;
2021-01-02 10:22:07 -03:00
}
void Exit(ArgArray args) {
// assert types
assert(args[2].type == RECT || args[2].type == NAME);
2021-01-09 16:11:30 -03:00
debug("Exit(%d %d %d)", args[0].type, args[1].type, args[2].type); //, args[0].u.str, args[1].u.sym->name->c_str(), "RECT");
ExitInfo *e = (ExitInfo*) malloc(sizeof(ExitInfo));
2021-01-08 22:42:34 -03:00
if (args[0].type == NUM && args[0].u.val == 0)
e->nextSetting = NULL;
else
e->nextSetting = new Common::String(args[0].u.str);
if (args[1].type == NUM && args[1].u.val == 0)
e->cursor = NULL;
else
e->cursor = args[1].u.sym->name;
2021-01-09 16:11:30 -03:00
if (args[2].type == NAME) {
2021-01-09 19:11:41 -03:00
assert(args[2].u.sym->type == RECT);
args[2].u.rect = args[2].u.sym->u.rect;
2021-01-09 16:11:30 -03:00
}
e->rect = args[2].u.rect;
2021-01-09 16:11:30 -03:00
debug("Rect %d %d %d %d", args[2].u.rect->top, args[2].u.rect->left, args[2].u.rect->bottom, args[2].u.rect->right);
2021-01-07 23:32:17 -03:00
g_private->_exits.push_front(*e);
}
2021-01-04 08:14:40 -03:00
void SetModifiedFlag(ArgArray args) {
2021-01-05 21:03:34 -03:00
// assert types
debug("SetModifiedFlag(%d)", args[0].u.val);
2021-01-07 23:32:17 -03:00
g_private->_modified = (bool) args[0].u.val;
2021-01-04 08:14:40 -03:00
}
2021-01-02 10:22:07 -03:00
void Sound(ArgArray args) {
2021-01-05 21:03:34 -03:00
// assert types
debug("Sound(%s)", args[0].u.str);
if (strcmp("\"\"", args[0].u.str) != 0) {
Common::String *s = new Common::String(args[0].u.str);
g_private->playSound(*s);
//assert(0);
2021-01-02 10:22:07 -03:00
} else {
g_private->stopSound();
2021-01-02 10:22:07 -03:00
}
}
2021-01-09 16:11:30 -03:00
void LoopedSound(ArgArray args) {
// assert types
assert(args.size() == 1);
debug("LoopedSound(%s)", args[0].u.str);
if (strcmp("\"\"", args[0].u.str) != 0) {
Common::String *s = new Common::String(args[0].u.str);
g_private->playSound(*s);
//assert(0);
} else {
g_private->stopSound();
}
}
2021-01-04 08:14:40 -03:00
void Transition(ArgArray args) {
2021-01-05 21:03:34 -03:00
// assert types
debug("Transition(%s, %s)", args[0].u.str, args[1].u.str);
2021-01-09 16:11:30 -03:00
g_private->_nextMovie = new Common::String(args[0].u.str);
2021-01-08 22:42:34 -03:00
g_private->_nextSetting = new Common::String(args[1].u.str);
}
void Movie(ArgArray args) {
// assert types
debug("Movie(%s, %s)", args[0].u.str, args[1].u.str);
if (strcmp(args[0].u.str, "\"\"") != 0)
g_private->_nextMovie = new Common::String(args[0].u.str);
2021-01-07 23:32:17 -03:00
g_private->_nextSetting = new Common::String(args[1].u.str);
2021-01-05 21:03:34 -03:00
}
void CRect(ArgArray args) {
// assert types
int x1, y1, x2, y2;
debug("CRect(%d, %d, %d, %d)", args[0].u.val, args[1].u.val, args[0].u.val, args[1].u.val);
//assert(0);
x1 = args[0].u.val;
y1 = args[1].u.val;
x2 = args[2].u.val;
y2 = args[3].u.val;
Datum *d = new Datum();
Common::Rect *rect = new Common::Rect(x1, y1, x2, y2);
d->type = RECT;
2021-01-05 21:03:34 -03:00
d->u.rect = rect;
push(*d);
2021-01-04 08:14:40 -03:00
}
void Bitmap(ArgArray args) {
assert(args.size() == 1 || args.size() == 3);
int x = 0;
int y = 0;
2021-01-05 21:03:34 -03:00
char *f = args[0].u.str;
if (args.size() == 3) {
x = args[1].u.val;
y = args[2].u.val;
}
debug("Bitmap(%s, %d, %d)", f, x, y);
2021-01-05 21:03:34 -03:00
Common::String *s = new Common::String(args[0].u.str);
2021-01-07 23:32:17 -03:00
g_private->loadImage(*s, x, y);
}
2021-01-09 22:08:41 -03:00
void _Mask(ArgArray args, bool drawn) {
2021-01-08 22:42:34 -03:00
assert(args.size() == 3 || args.size() == 5);
int x = 0;
int y = 0;
char *f = args[0].u.str;
char *e = args[1].u.str;
Common::String *c = args[2].u.sym->name;
2021-01-09 19:11:41 -03:00
2021-01-08 22:42:34 -03:00
if (args.size() == 5) {
x = args[3].u.val;
y = args[4].u.val;
}
debug("Mask(%s, %s, %s, %d, %d)", f, e, c->c_str(), x, y);
const Common::String *s = new Common::String(f);
//if (drawed)
// g_private->loadImage(*s, x, y);
MaskInfo *m = (MaskInfo*) malloc(sizeof(MaskInfo));
m->surf = g_private->loadMask(*s, x, y, drawn);
m->nextSetting = new Common::String(e);
m->cursor = c;
m->point = new Common::Point(x,y);
g_private->_masks.push_front(*m);
}
2021-01-09 22:08:41 -03:00
void Mask(ArgArray args) { _Mask(args, false); }
void MaskDrawn(ArgArray args) { _Mask(args, true); }
2021-01-08 22:42:34 -03:00
void Timer(ArgArray args) {
2021-01-09 16:11:30 -03:00
assert (args.size() == 2 || args.size() == 3);
if (args.size() == 3)
debug("Timer(%d, %s, %s)", args[0].u.val, args[1].u.str, args[2].u.str);
2021-01-09 19:11:41 -03:00
else
2021-01-09 16:11:30 -03:00
debug("Timer(%d, %s)", args[0].u.val, args[1].u.str);
2021-01-09 19:11:41 -03:00
2021-01-05 21:03:34 -03:00
g_system->delayMillis(100 * args[0].u.val);
Common::String *s = new Common::String(args[1].u.str);
g_private->_nextSetting = s;
}
2021-01-09 22:08:41 -03:00
static struct FuncTable {
void (*func)(Private::ArgArray);
const char *name;
} funcTable[] = {
{ Bitmap, "Bitmap"},
{ ChgMode, "ChgMode"},
{ Goto, "goto"},
{ SetFlag, "SetFlag"},
{ Sound, "Sound"},
{ Sound, "SoundEffect"},
{ Sound, "LoopedSound"},
{ Mask, "Mask"},
{ MaskDrawn, "MaskDrawn"},
{ Timer, "Timer"},
{ Transition, "Transition"},
{ Movie, "Movie"},
{ SetModifiedFlag, "SetModifiedFlag"},
{ Exit, "Exit"},
{ Quit, "Quit"},
{ LoadGame, "LoadGame"},
{ DossierAdd, "DossierAdd"},
{ Inventory, "Inventory"},
{ VSPicture, "VSPicture"},
{ CRect, "CRect"},
{ RestartGame, "RestartGame"},
{ 0, 0}
};
NameToPtr _functions;
void initFuncs() {
for (Private::FuncTable *fnc = funcTable; fnc->name; fnc++) {
Common::String *name = new Common::String(fnc->name);
_functions.setVal(*name, (void *)fnc->func);
2021-01-08 22:42:34 -03:00
}
2021-01-09 22:08:41 -03:00
}
2021-01-09 19:11:41 -03:00
2021-01-09 22:08:41 -03:00
void call(char *name, ArgArray args) {
Common::String n(name);
if (!_functions.contains(n)) {
debug("I don't know how to execute %s", name);
2021-01-02 00:58:58 -03:00
assert(0);
2021-01-04 08:14:40 -03:00
}
2021-01-09 22:08:41 -03:00
void (*func)(ArgArray) = (void (*)(ArgArray)) _functions.getVal(n);
func(args);
2021-01-02 00:58:58 -03:00
}
}