1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "parallaction/exec.h"
#include "parallaction/input.h"
#include "parallaction/parallaction.h"
#include "parallaction/sound.h"
#include "common/textconsole.h"
namespace Parallaction {
#define INST_ON 1
#define INST_OFF 2
#define INST_X 3
#define INST_Y 4
#define INST_Z 5
#define INST_F 6
#define INST_LOOP 7
#define INST_ENDLOOP 8
#define INST_SHOW 9
#define INST_INC 10
#define INST_DEC 11
#define INST_SET 12
#define INST_PUT 13
#define INST_CALL 14
#define INST_WAIT 15
#define INST_START 16
#define INST_SOUND 17
#define INST_MOVE 18
#define INST_ENDSCRIPT 19
#define SetOpcodeTable(x) table = &x;
typedef Common::Functor1Mem<CommandContext&, void, CommandExec_ns> OpcodeV1;
#define COMMAND_OPCODE(op) table->push_back(new OpcodeV1(this, &CommandExec_ns::cmdOp_##op))
#define DECLARE_COMMAND_OPCODE(op) void CommandExec_ns::cmdOp_##op(CommandContext& ctxt)
typedef Common::Functor1Mem<ProgramContext&, void, ProgramExec_ns> OpcodeV2;
#define INSTRUCTION_OPCODE(op) table->push_back(new OpcodeV2(this, &ProgramExec_ns::instOp_##op))
#define DECLARE_INSTRUCTION_OPCODE(op) void ProgramExec_ns::instOp_##op(ProgramContext& ctxt)
extern const char *_instructionNamesRes_ns[];
DECLARE_INSTRUCTION_OPCODE(on) {
InstructionPtr inst = ctxt._inst;
inst->_a->_flags |= kFlagsActive;
inst->_a->_flags &= ~kFlagsRemove;
}
DECLARE_INSTRUCTION_OPCODE(off) {
ctxt._inst->_a->_flags |= kFlagsRemove;
}
DECLARE_INSTRUCTION_OPCODE(loop) {
InstructionPtr inst = ctxt._inst;
ctxt._program->_loopCounter = inst->_opB.getValue();
ctxt._program->_loopStart = ctxt._ip;
}
DECLARE_INSTRUCTION_OPCODE(endloop) {
if (--ctxt._program->_loopCounter > 0) {
ctxt._ip = ctxt._program->_loopStart;
}
}
DECLARE_INSTRUCTION_OPCODE(inc) {
InstructionPtr inst = ctxt._inst;
int16 _si = inst->_opB.getValue();
if (inst->_flags & kInstMod) { // mod
int16 _bx = (_si > 0 ? _si : -_si);
if (ctxt._modCounter % _bx != 0) return;
_si = (_si > 0 ? 1 : -1);
}
int16 lvalue = inst->_opA.getValue();
if (inst->_index == INST_INC) {
lvalue += _si;
} else {
lvalue -= _si;
}
inst->_opA.setValue(lvalue);
}
DECLARE_INSTRUCTION_OPCODE(set) {
ctxt._inst->_opA.setValue(ctxt._inst->_opB.getValue());
}
DECLARE_INSTRUCTION_OPCODE(put) {
InstructionPtr inst = ctxt._inst;
Common::Rect r;
inst->_a->getFrameRect(r);
Graphics::Surface v18;
v18.init(r.width(), r.height(), r.width(), inst->_a->getFrameData(), Graphics::PixelFormat::createFormatCLUT8());
int16 x = inst->_opA.getValue();
int16 y = inst->_opB.getValue();
bool mask = (inst->_flags & kInstMaskedPut) == kInstMaskedPut;
_vm->_gfx->patchBackground(v18, x, y, mask);
}
DECLARE_INSTRUCTION_OPCODE(show) {
ctxt._suspend = true;
}
DECLARE_INSTRUCTION_OPCODE(invalid) {
error("Can't execute invalid opcode %i", ctxt._inst->_index);
}
DECLARE_INSTRUCTION_OPCODE(call) {
_vm->callFunction(ctxt._inst->_immediate, 0);
}
DECLARE_INSTRUCTION_OPCODE(wait) {
if (g_engineFlags & kEngineWalking) {
ctxt._ip--;
ctxt._suspend = true;
}
}
DECLARE_INSTRUCTION_OPCODE(start) {
ctxt._inst->_a->_flags |= (kFlagsActing | kFlagsActive);
}
DECLARE_INSTRUCTION_OPCODE(sound) {
_vm->_activeZone = ctxt._inst->_z;
}
DECLARE_INSTRUCTION_OPCODE(move) {
InstructionPtr inst = ctxt._inst;
int16 x = inst->_opA.getValue();
int16 y = inst->_opB.getValue();
_vm->scheduleWalk(x, y, false);
}
DECLARE_INSTRUCTION_OPCODE(endscript) {
if ((ctxt._anim->_flags & kFlagsLooping) == 0) {
ctxt._anim->_flags &= ~kFlagsActing;
_vm->_cmdExec->run(ctxt._anim->_commands, ctxt._anim);
ctxt._program->_status = kProgramDone;
}
ctxt._ip = 0;
ctxt._suspend = true;
}
DECLARE_COMMAND_OPCODE(invalid) {
error("Can't execute invalid command '%i'", ctxt._cmd->_id);
}
DECLARE_COMMAND_OPCODE(set) {
if (ctxt._cmd->_flags & kFlagsGlobal) {
ctxt._cmd->_flags &= ~kFlagsGlobal;
g_globalFlags |= ctxt._cmd->_flags;
} else {
_vm->setLocationFlags(ctxt._cmd->_flags);
}
}
DECLARE_COMMAND_OPCODE(clear) {
if (ctxt._cmd->_flags & kFlagsGlobal) {
ctxt._cmd->_flags &= ~kFlagsGlobal;
g_globalFlags &= ~ctxt._cmd->_flags;
} else {
_vm->clearLocationFlags(ctxt._cmd->_flags);
}
}
DECLARE_COMMAND_OPCODE(start) {
ctxt._cmd->_zone->_flags |= kFlagsActing;
}
DECLARE_COMMAND_OPCODE(speak) {
if (ACTIONTYPE(ctxt._cmd->_zone) == kZoneSpeak) {
_vm->enterDialogueMode(ctxt._cmd->_zone);
} else {
_vm->_activeZone = ctxt._cmd->_zone;
}
}
DECLARE_COMMAND_OPCODE(get) {
ctxt._cmd->_zone->_flags &= ~kFlagsFixed;
_vm->runZone(ctxt._cmd->_zone);
}
DECLARE_COMMAND_OPCODE(location) {
_vm->scheduleLocationSwitch(ctxt._cmd->_string.c_str());
}
DECLARE_COMMAND_OPCODE(open) {
_vm->updateDoor(ctxt._cmd->_zone, false);
}
DECLARE_COMMAND_OPCODE(close) {
_vm->updateDoor(ctxt._cmd->_zone, true);
}
DECLARE_COMMAND_OPCODE(on) {
_vm->showZone(ctxt._cmd->_zone, true);
}
DECLARE_COMMAND_OPCODE(off) {
_vm->showZone(ctxt._cmd->_zone, false);
}
DECLARE_COMMAND_OPCODE(call) {
_vm->callFunction(ctxt._cmd->_callable, &ctxt._z);
}
DECLARE_COMMAND_OPCODE(toggle) {
if (ctxt._cmd->_flags & kFlagsGlobal) {
ctxt._cmd->_flags &= ~kFlagsGlobal;
g_globalFlags ^= ctxt._cmd->_flags;
} else {
_vm->toggleLocationFlags(ctxt._cmd->_flags);
}
}
DECLARE_COMMAND_OPCODE(drop){
_vm->dropItem( ctxt._cmd->_object );
}
DECLARE_COMMAND_OPCODE(quit) {
_vm->quitGame();
}
DECLARE_COMMAND_OPCODE(move) {
_vm->scheduleWalk(ctxt._cmd->_move.x, ctxt._cmd->_move.y, false);
}
DECLARE_COMMAND_OPCODE(stop) {
ctxt._cmd->_zone->_flags &= ~kFlagsActing;
}
CommandExec_ns::CommandExec_ns(Parallaction_ns* vm) : CommandExec(vm), _vm(vm) {
CommandOpcodeSet *table = 0;
SetOpcodeTable(_opcodes);
COMMAND_OPCODE(invalid);
COMMAND_OPCODE(set);
COMMAND_OPCODE(clear);
COMMAND_OPCODE(start);
COMMAND_OPCODE(speak);
COMMAND_OPCODE(get);
COMMAND_OPCODE(location);
COMMAND_OPCODE(open);
COMMAND_OPCODE(close);
COMMAND_OPCODE(on);
COMMAND_OPCODE(off);
COMMAND_OPCODE(call);
COMMAND_OPCODE(toggle);
COMMAND_OPCODE(drop);
COMMAND_OPCODE(quit);
COMMAND_OPCODE(move);
COMMAND_OPCODE(stop);
}
ProgramExec_ns::ProgramExec_ns(Parallaction_ns *vm) : _vm(vm) {
_instructionNames = _instructionNamesRes_ns;
ProgramOpcodeSet *table = 0;
SetOpcodeTable(_opcodes);
INSTRUCTION_OPCODE(invalid);
INSTRUCTION_OPCODE(on);
INSTRUCTION_OPCODE(off);
INSTRUCTION_OPCODE(set); // x
INSTRUCTION_OPCODE(set); // y
INSTRUCTION_OPCODE(set); // z
INSTRUCTION_OPCODE(set); // f
INSTRUCTION_OPCODE(loop);
INSTRUCTION_OPCODE(endloop);
INSTRUCTION_OPCODE(show);
INSTRUCTION_OPCODE(inc);
INSTRUCTION_OPCODE(inc); // dec
INSTRUCTION_OPCODE(set);
INSTRUCTION_OPCODE(put);
INSTRUCTION_OPCODE(call);
INSTRUCTION_OPCODE(wait);
INSTRUCTION_OPCODE(start);
INSTRUCTION_OPCODE(sound);
INSTRUCTION_OPCODE(move);
INSTRUCTION_OPCODE(endscript);
}
} // namespace Parallaction
|