scummvm/engines/cge/snail.cpp

1136 lines
26 KiB
C++
Raw Normal View History

/* 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.
*
*/
/*
* This code is based on original Soltys source code
* Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon
*/
2011-06-13 11:57:24 +02:00
#include "cge/general.h"
#include "cge/sound.h"
#include "cge/snail.h"
#include "cge/vga13h.h"
#include "cge/bitmaps.h"
#include "cge/text.h"
#include "cge/mouse.h"
#include "cge/cge_main.h"
#include <stdio.h>
#include <stdlib.h>
#include "cge/keybd.h"
2011-06-10 22:57:09 +02:00
namespace CGE {
static void _enable() {
warning("STUB: _enable");
}
static void _disable() {
warning("STUB: _disable");
}
2011-06-13 11:57:24 +02:00
int MaxCave = 0;
2011-06-13 11:57:24 +02:00
SCB Scb = { NULL, 0, NULL };
bool Flag[4];
bool Dark = false;
bool Game = false;
int Now = 1;
int Lev = -1;
extern Sprite *_pocLight;
//-------------------------------------------------------------------------
2011-06-13 11:57:24 +02:00
// SPRITE * Pocket[POCKET_NX]={ NULL, NULL, NULL, NULL,
// NULL, NULL, NULL, NULL, };
2011-06-13 11:57:24 +02:00
// int PocPtr = 0;
//-------------------------------------------------------------------------
extern Sprite *_pocket[];
2011-06-13 11:57:24 +02:00
extern int PocPtr;
static void SNGame(Sprite *spr, int num) {
2011-06-13 11:57:24 +02:00
switch (num) {
case 1 : {
#define STAGES 8
#define DRESSED 3
static Sprite *dup[3] = { NULL, NULL, NULL };
2011-06-13 11:57:24 +02:00
int buref = 0;
int Stage = 0;
2011-06-29 16:13:17 +02:00
for (dup[0] = Vga->ShowQ->First(); dup[0]; dup[0] = dup[0]->_next) {
buref = dup[0]->_ref;
2011-06-13 11:57:24 +02:00
if (buref / 1000 == 16 && buref % 100 == 6) {
Stage = (buref / 100) % 10;
break;
}
}
2011-06-13 11:57:24 +02:00
if (dup[1] == NULL) {
dup[1] = Vga->ShowQ->Locate(16003); // pan
dup[2] = Vga->ShowQ->Locate(16004); // pani
}
2011-06-13 11:57:24 +02:00
if (Game) { // continue game
2011-06-29 16:13:17 +02:00
int i = new_random(3), hand = (dup[0]->_shpCnt == 6);
Stage++;
2011-06-13 13:07:45 +02:00
if (hand && Stage > DRESSED)
2011-06-13 11:57:24 +02:00
++hand;
if (i >= 0 || (dup[i] == spr && new_random(3) == 0)) {
2011-06-13 11:57:24 +02:00
SNPOST(SNSEQ, -1, 3, dup[0]); // yes
SNPOST(SNSEQ, -1, 3, dup[1]); // yes
SNPOST(SNSEQ, -1, 3, dup[2]); // yes
SNPOST(SNTNEXT, -1, 0, dup[0]); // reset Take
SNPOST(SNTNEXT, -1, 0, dup[1]); // reset Take
SNPOST(SNTNEXT, -1, 0, dup[2]); // reset Take
SNPOST(SNNNEXT, -1, 0, dup[0]); // reset Near
SNPOST(SNPAUSE, -1, 72, NULL); // little rest
SNPOST(SNSAY, 1, 16009, NULL); // hura
SNPOST(SNSAY, buref, 16010, NULL); // siadaj
SNPOST(SNSAY, 1, 16011, NULL); // postoj<6F>
if (hand) {
SNPOST(SNSEND, 16060 + hand, 16, NULL); // dawaj r<>k<EFBFBD>
SNPOST(SNSEQ, buref, 4, NULL); // zdejmowanie
SNPOST(SNSEQ, 16060 + hand, 1, NULL); // ruch
SNPOST(SNSOUND, 16060 + hand, 16002, NULL); // szelest
SNPOST(SNWAIT, 16060 + hand, 3, NULL); // podniesie
SNPOST(SNSWAP, buref, buref + 100, NULL); // rozdziana
SNPOST(SNSEQ, 16016, Stage, NULL); // ro<72>nie kupa
SNPOST(SNSEND, 16060 + hand, -1, NULL); // chowaj r<>k<EFBFBD>
SNPOST(SNWAIT, 16060 + hand, -1, NULL); // r<>ka zamar<61>a
} else {
SNPOST(SNSEQ, buref, 4, NULL); // zdejmowanie
SNPOST(SNSOUND, 16060 + hand, 16002, NULL); // szelest
SNPOST(SNWAIT, buref, -1, NULL); // zdejmie
SNPOST(SNSWAP, buref, buref + 100, NULL); // rozdziana
SNPOST(SNSEQ, 16016, Stage, NULL); // ro<72>nie kupa
}
//SNPOST(SNSEQ, buref+100, 0, NULL); // reset
SNPOST(SNPAUSE, -1, 72, NULL); // chwilk<6C>...
SNPOST(SNSEQ, -1, 0, dup[1]); // odstaw Go
SNPOST(SNSETXY, -1, 203 + SCR_WID * 49, dup[1]);
SNPOST(SNSETZ, -1, 7, dup[1]);
SNPOST(SNSEQ, -1, 0, dup[2]); // odstaw J<>
SNPOST(SNSETXY, -1, 182 + SCR_WID * 62, dup[2]);
SNPOST(SNSETZ, -1, 9, dup[2]);
Game = 0;
return;
} else {
SNPOST(SNSEQ, -1, 2, dup[0]); // no
SNPOST(SNSEQ, -1, 2, dup[1]); // no
SNPOST(SNSEQ, -1, 2, dup[2]); // no
SNPOST(SNPAUSE, -1, 72, NULL); // 1 sec
2011-06-13 13:07:45 +02:00
}
}
2011-06-13 11:57:24 +02:00
SNPOST(SNWALK, 198, 134, NULL); // na miejsce
SNPOST(SNWAIT, 1, -1, NULL); // stoi
SNPOST(SNCOVER, 1, 16101, NULL); // ch<63>op do bicia
SNPOST(SNSEQ, 16101, 1, NULL); // wystaw
SNPOST(SNWAIT, 16101, 5, NULL); // czekaj
SNPOST(SNPAUSE, 16101, 24, NULL); // czekaj chwil<69>
SNPOST(SNSEQ, 16040, 1, NULL); // plask
SNPOST(SNSOUND, 16101, 16001, NULL); // plask!
SNPOST(SNPAUSE, 16101, 24, NULL); // czekaj chwil<69>
SNPOST(SNSEQ, 16040, 0, NULL); // schowaj plask
SNPOST(SNWAIT, 16101, -1, NULL); // stoi
SNPOST(SNUNCOVER, 1, 16101, NULL); // SDS
2011-06-13 13:07:45 +02:00
if (! Game) {
2011-06-13 11:57:24 +02:00
SNPOST(SNSAY, buref, 16008, NULL); // zgadnij!
Game = true;
}
2011-06-13 11:57:24 +02:00
#undef STEPS
#undef DRESSED
}
break;
//--------------------------------------------------------------------
case 2 : {
static Sprite *k = NULL, * k1, * k2, * k3;
2011-06-13 11:57:24 +02:00
static int count = 0;
if (k == NULL) {
k = Vga->ShowQ->Locate(20700);
k1 = Vga->ShowQ->Locate(20701);
k2 = Vga->ShowQ->Locate(20702);
k3 = Vga->ShowQ->Locate(20703);
}
2011-06-13 11:57:24 +02:00
if (! Game) { // init
SNPOST(SNGAME, 20002, 2, NULL);
Game = true;
} else { // cont
k1->Step(new_random(6));
k2->Step(new_random(6));
k3->Step(new_random(6));
///--------------------
if (spr->_ref == 1 && KEYBOARD::Key[ALT]) {
2011-06-13 11:57:24 +02:00
k1->Step(5);
k2->Step(5);
k3->Step(5);
}
///--------------------
SNPOST(SNSETZ, 20700, 0, NULL);
2011-06-29 16:13:17 +02:00
bool hit = (k1->_seqPtr + k2->_seqPtr + k3->_seqPtr == 15);
2011-06-13 11:57:24 +02:00
if (hit) {
if (spr->_ref == 1) {
2011-06-13 11:57:24 +02:00
SNPOST(SNSAY, 1, 20003, NULL); // hura!
SNPOST(SNSEQ, 20011, 2, NULL); // kamera won
SNPOST(SNSEND, 20701, -1, NULL); // k1 won
SNPOST(SNSEND, 20702, -1, NULL); // k2 won
SNPOST(SNSEND, 20703, -1, NULL); // k3 won
SNPOST(SNSEND, 20700, -1, NULL); // tv won
SNPOST(SNKEEP, 20007, 0, NULL); // do kieszeni
SNPOST(SNSEND, 20006, 20, NULL); // bilon
SNPOST(SNSOUND, 20006, 20002, NULL); // bilon!
2011-06-13 13:07:45 +02:00
SNPOST(SNSAY, 20002, 20004, NULL);
2011-06-13 11:57:24 +02:00
SNPOST(SNSEND, 20010, 20, NULL); // papier
SNPOST(SNSOUND, 20010, 20003, NULL); // papier!
SNPOST(SNSAY, 20001, 20005, NULL);
Game = false;
return;
2011-06-13 13:07:45 +02:00
} else
2011-06-13 11:57:24 +02:00
k3->Step(new_random(5));
}
if (count < 100) {
switch (count) {
case 15 :
SNPOST(SNSAY, 20003, 20021, NULL);
break;
case 30 :
case 45 :
case 60 :
case 75 :
SNPOST(SNSAY, 20003, 20022, NULL);
break;
}
++ count;
}
switch (spr->_ref) {
2011-06-13 11:57:24 +02:00
case 1 :
SNPOST(SNSAY, 20001, 20011, NULL); // zapro
SNPOST(SNSEQ, 20001, 1, NULL); // rzu<7A>
SNPOST(SNWAIT, 20001, 1, NULL); // czekaj
SNPOST(SNSETZ, 20700, 2, NULL); // skryj k
SNPOST(SNHIDE, 20007, 1, NULL); // skryj k
SNPOST(SNWAIT, 20001, 16, NULL); // czekaj
SNPOST(SNSEQ, 20007, 1, NULL); // lec<65>
SNPOST(SNHIDE, 20007, 0, NULL); // poka<6B>
SNPOST(SNSOUND, 20007, 20001, NULL); // grzech
SNPOST(SNWAIT, 20007, -1, NULL); // koniec
SNPOST(SNGAME, 20001, 2, NULL); // again!
break;
2011-06-13 13:07:45 +02:00
case 20001:
2011-06-13 11:57:24 +02:00
SNPOST(SNSAY, 20002, 20012, NULL); // zapro
SNPOST(SNSEQ, 20002, 1, NULL); // rzu<7A>
SNPOST(SNWAIT, 20002, 3, NULL); // czekaj
SNPOST(SNSETZ, 20700, 2, NULL); // skryj k
SNPOST(SNHIDE, 20007, 1, NULL); // skryj k
SNPOST(SNWAIT, 20002, 10, NULL); // czekaj
SNPOST(SNSEQ, 20007, 2, NULL); // lec<65>
SNPOST(SNHIDE, 20007, 0, NULL); // poka<6B>
SNPOST(SNSOUND, 20007, 20001, NULL); // grzech
SNPOST(SNWAIT, 20007, -1, NULL); // koniec
SNPOST(SNGAME, 20002, 2, NULL); // again!
2011-06-13 13:07:45 +02:00
break;
case 20002:
2011-06-13 11:57:24 +02:00
SNPOST(SNSAY, 20002, 20010, NULL); // zapro
SNPOST(SNWALK, 20005, -1, NULL); // do stol
SNPOST(SNWAIT, 1, -1, NULL); // stoi
SNPOST(SNCOVER, 1, 20101, NULL); // grasol
SNPOST(SNSEQ, 20101, 1, NULL); // rzu<7A>
SNPOST(SNWAIT, 20101, 5, NULL); // czekaj
SNPOST(SNSETZ, 20700, 2, NULL); // skryj k
SNPOST(SNHIDE, 20007, 1, NULL); // skryj k
SNPOST(SNWAIT, 20101, 15, NULL); // czekaj
SNPOST(SNSEQ, 20007, 1, NULL); // lec<65>
SNPOST(SNHIDE, 20007, 0, NULL); // poka<6B>
SNPOST(SNSOUND, 20007, 20001, NULL); // grzech
SNPOST(SNWAIT, 20101, -1, NULL); // koniec
SNPOST(SNUNCOVER, 1, 20101, NULL); // SDS
SNPOST(SNGAME, 1, 2, NULL); // again!
break;
}
}
2011-06-13 11:57:24 +02:00
}
break;
}
}
void ExpandSprite(Sprite *spr) {
2011-06-13 13:07:45 +02:00
if (spr)
Vga->ShowQ->Insert(Vga->SpareQ->Remove(spr));
}
void ContractSprite(Sprite *spr) {
2011-06-13 13:07:45 +02:00
if (spr)
Vga->SpareQ->Append(Vga->ShowQ->Remove(spr));
}
int FindPocket(Sprite *spr) {
for (int i = 0; i < POCKET_NX; i++)
if (_pocket[i] == spr)
2011-06-13 11:57:24 +02:00
return i;
return -1;
}
2011-06-13 11:57:24 +02:00
void SelectPocket(int n) {
2011-06-29 16:13:17 +02:00
if (n < 0 || (_pocLight->_seqPtr && PocPtr == n)) {
_pocLight->Step(0);
2011-06-13 11:57:24 +02:00
n = FindPocket(NULL);
2011-06-13 13:07:45 +02:00
if (n >= 0)
2011-06-13 11:57:24 +02:00
PocPtr = n;
} else {
if (_pocket[n] != NULL) {
2011-06-13 11:57:24 +02:00
PocPtr = n;
_pocLight->Step(1);
2011-06-13 11:57:24 +02:00
}
}
_pocLight->Goto(POCKET_X + PocPtr * POCKET_DX + POCKET_SX, POCKET_Y + POCKET_SY);
}
2011-06-13 11:57:24 +02:00
void PocFul(void) {
2011-07-01 08:37:40 +02:00
Hero->park();
2011-06-13 11:57:24 +02:00
SNPOST(SNWAIT, -1, -1, Hero);
SNPOST(SNSEQ, -1, POC_FUL, Hero);
SNPOST(SNSOUND, -1, 2, Hero);
SNPOST(SNWAIT, -1, -1, Hero);
SNPOST(SNSAY, 1, POC_FUL_TEXT, Hero);
}
void Hide1(Sprite *spr) {
2011-06-13 11:57:24 +02:00
SNPOST_(SNGHOST, -1, 0, spr->Ghost());
}
2011-06-29 16:13:17 +02:00
void SNGhost(Bitmap *bmp) {
2011-06-13 11:57:24 +02:00
// TODO : Get x and y from M but not using segment / offset
2011-06-29 16:13:17 +02:00
//bmp->Hide(FP_OFF(bmp->_m), FP_SEG(bmp->_m));
bmp->_m = NULL;
2011-06-13 11:57:24 +02:00
delete bmp;
warning("STUB: SNGhost");
}
void FeedSnail(Sprite *spr, SNLIST snq) {
2011-06-13 13:07:45 +02:00
if (spr)
2011-06-13 11:57:24 +02:00
if (spr->Active()) {
uint8 ptr = (snq == TAKE) ? spr->TakePtr : spr->NearPtr;
if (ptr != NO_PTR) {
SNAIL::COM *comtab = spr->SnList(snq);
SNAIL::COM *c = comtab + ptr;
if (FindPocket(NULL) < 0) { // no empty pockets?
SNAIL::COM *p;
for (p = c; p->Com != SNNEXT; p++) { // find KEEP command
2011-06-13 11:57:24 +02:00
if (p->Com == SNKEEP) {
PocFul();
return;
}
2011-06-13 13:07:45 +02:00
if (p->Ptr)
2011-06-13 11:57:24 +02:00
break;
}
}
while (true) {
if (c->Com == SNTALK) {
if ((Snail->TalkEnable = (c->Val != 0)) == false)
2011-06-13 11:57:24 +02:00
KillText();
}
if (c->Com == SNNEXT) {
Sprite *s = (c->Ref < 0) ? spr : Locate(c->Ref);
2011-06-13 11:57:24 +02:00
if (s) {
uint8 *idx = (snq == TAKE) ? &s->TakePtr : &s->NearPtr;
if (*idx != NO_PTR) {
int v;
switch (c->Val) {
case -1 :
v = c - comtab + 1;
break;
case -2 :
v = c - comtab;
break;
case -3 :
v = -1;
break;
default :
v = c->Val;
break;
}
2011-06-13 13:07:45 +02:00
if (v >= 0)
2011-06-13 11:57:24 +02:00
*idx = v;
}
}
2011-06-13 13:07:45 +02:00
if (s == spr)
2011-06-13 11:57:24 +02:00
break;
}
if (c->Com == SNIF) {
Sprite *s = (c->Ref < 0) ? spr : Locate(c->Ref);
2011-06-13 11:57:24 +02:00
if (s) { // sprite extsts
2011-06-13 13:07:45 +02:00
if (! s->SeqTest(-1))
2011-06-13 11:57:24 +02:00
c = comtab + c->Val; // not parked
2011-06-13 13:07:45 +02:00
else
2011-06-13 11:57:24 +02:00
++c;
2011-06-13 13:07:45 +02:00
} else
2011-06-13 11:57:24 +02:00
++c;
} else {
SNPOST(c->Com, c->Ref, c->Val, spr);
2011-06-13 13:07:45 +02:00
if (c->Ptr)
2011-06-13 11:57:24 +02:00
break;
2011-06-13 13:07:45 +02:00
else
2011-06-13 11:57:24 +02:00
++c;
}
}
}
}
}
2011-06-13 13:07:45 +02:00
const char *SNAIL::ComTxt[] = {
"LABEL", "PAUSE", "WAIT", "LEVEL", "HIDE",
"SAY", "INF", "TIME", "CAVE", "KILL",
"RSEQ", "SEQ", "SEND", "SWAP", "KEEP",
"GIVE", "IF", "GAME", "SETX0", "SETY0",
2011-06-13 11:57:24 +02:00
"SLAVE", "SETXY", "RELX", "RELY", "RELZ",
"SETX", "SETY", "SETZ", "TRANS", "PORT",
"NEXT", "NNEXT", "TNEXT", "RNNEXT", "RTNEXT",
2011-06-13 13:07:45 +02:00
"RMNEAR", "RMTAKE", "FLAG", "SETREF", "BACKPT",
"FLASH", "LIGHT", "SETHB", "SETVB", "WALK",
"REACH", "COVER", "UNCOVER", "CLEAR", "TALK",
2011-06-13 11:57:24 +02:00
"MOUSE", "SOUND", "COUNT", NULL
};
SNAIL::SNAIL(CGEEngine *vm, bool turbo)
2011-06-13 11:57:24 +02:00
: Turbo(turbo), Busy(false), TextDelay(false),
_timerExpiry(0), TalkEnable(true),
Head(0), Tail(0), SNList(farnew(COM, 256)), _vm(vm) {
}
2011-06-13 11:57:24 +02:00
SNAIL::~SNAIL(void) {
2011-06-13 13:07:45 +02:00
if (SNList)
2011-06-13 11:57:24 +02:00
free(SNList);
}
2011-06-13 11:57:24 +02:00
void SNAIL::AddCom(SNCOM com, int ref, int val, void *ptr) {
_disable();
COM *snc = &SNList[Head++];
2011-06-13 11:57:24 +02:00
snc->Com = com;
snc->Ref = ref;
snc->Val = val;
snc->Ptr = ptr;
if (com == SNCLEAR) {
Tail = Head;
KillText();
_timerExpiry = 0;
2011-06-13 11:57:24 +02:00
}
_enable();
}
2011-06-13 11:57:24 +02:00
void SNAIL::InsCom(SNCOM com, int ref, int val, void *ptr) {
COM *snc;
_disable();
if (Busy) {
SNList[(Tail - 1) & 0xFF] = SNList[Tail];
snc = &SNList[Tail];
2011-06-13 13:07:45 +02:00
} else
2011-06-13 11:57:24 +02:00
snc = &SNList[(Tail - 1) & 0xFF];
--Tail;
snc->Com = com;
snc->Ref = ref;
snc->Val = val;
snc->Ptr = ptr;
if (com == SNCLEAR) {
Tail = Head;
KillText();
_timerExpiry = 0;
2011-06-13 11:57:24 +02:00
}
_enable();
}
static void SNNNext(Sprite *sprel, int p) {
2011-06-13 13:07:45 +02:00
if (sprel)
if (sprel->NearPtr != NO_PTR)
2011-06-13 11:57:24 +02:00
sprel->NearPtr = p;
}
static void SNTNext(Sprite *sprel, int p) {
2011-06-13 13:07:45 +02:00
if (sprel)
if (sprel->TakePtr != NO_PTR)
2011-06-13 11:57:24 +02:00
sprel->TakePtr = p;
}
static void SNRNNext(Sprite *sprel, int p) {
2011-06-13 13:07:45 +02:00
if (sprel)
if (sprel->NearPtr != NO_PTR)
2011-06-13 11:57:24 +02:00
sprel->NearPtr += p;
}
static void SNRTNext(Sprite *sprel, int p) {
2011-06-13 13:07:45 +02:00
if (sprel)
if (sprel->TakePtr != NO_PTR)
2011-06-13 11:57:24 +02:00
sprel->TakePtr += p;
}
static void SNZTrim(Sprite *spr) {
2011-06-13 13:07:45 +02:00
if (spr)
2011-06-13 11:57:24 +02:00
if (spr->Active()) {
bool en = _heart->_enable;
Sprite *s;
_heart->_enable = false;
2011-06-29 16:13:17 +02:00
s = (spr->_flags._shad) ? spr->_prev : NULL;
Vga->ShowQ->Insert(Vga->ShowQ->Remove(spr));
2011-06-13 11:57:24 +02:00
if (s) {
2011-06-29 16:13:17 +02:00
s->_z = spr->_z;
Vga->ShowQ->Insert(Vga->ShowQ->Remove(s), spr);
2011-06-13 11:57:24 +02:00
}
_heart->_enable = en;
2011-06-13 11:57:24 +02:00
}
}
static void SNHide(Sprite *spr, int val) {
2011-06-13 11:57:24 +02:00
if (spr) {
2011-06-29 16:13:17 +02:00
spr->_flags._hide = (val >= 0) ? (val != 0) : (!spr->_flags._hide);
if (spr->_flags._shad)
spr->_prev->_flags._hide = spr->_flags._hide;
2011-06-13 11:57:24 +02:00
}
}
static void SNRmNear(Sprite *spr) {
2011-06-13 13:07:45 +02:00
if (spr)
2011-06-13 11:57:24 +02:00
spr->NearPtr = NO_PTR;
}
static void SNRmTake(Sprite *spr) {
2011-06-13 13:07:45 +02:00
if (spr)
2011-06-13 11:57:24 +02:00
spr->TakePtr = NO_PTR;
}
void SNSeq(Sprite *spr, int val) {
2011-06-13 11:57:24 +02:00
if (spr) {
2011-06-13 13:07:45 +02:00
if (spr == Hero && val == 0)
2011-07-01 08:37:40 +02:00
Hero->park();
2011-06-13 13:07:45 +02:00
else
2011-06-13 11:57:24 +02:00
spr->Step(val);
}
}
void SNRSeq(Sprite *spr, int val) {
2011-06-13 13:07:45 +02:00
if (spr)
2011-06-29 16:13:17 +02:00
SNSeq(spr, spr->_seqPtr + val);
}
void SNSend(Sprite *spr, int val) {
2011-06-13 11:57:24 +02:00
if (spr) {
int was = spr->_cave;
2011-06-13 11:57:24 +02:00
bool was1 = (was == 0 || was == Now);
bool val1 = (val == 0 || val == Now);
spr->_cave = val;
2011-06-13 11:57:24 +02:00
if (val1 != was1) {
if (was1) {
2011-06-29 16:13:17 +02:00
if (spr->_flags._kept) {
2011-06-13 11:57:24 +02:00
int n = FindPocket(spr);
2011-06-13 13:07:45 +02:00
if (n >= 0)
_pocket[n] = NULL;
2011-06-13 11:57:24 +02:00
}
Hide1(spr);
ContractSprite(spr);
2011-06-29 16:13:17 +02:00
spr->_flags._slav = false;
2011-06-13 11:57:24 +02:00
} else {
if (spr->_ref % 1000 == 0)
2011-06-30 08:30:23 +02:00
Bitmap::_pal = VGA::SysPal;
2011-06-29 16:13:17 +02:00
if (spr->_flags._back)
2011-06-13 11:57:24 +02:00
spr->BackShow(true);
2011-06-13 13:07:45 +02:00
else
2011-06-13 11:57:24 +02:00
ExpandSprite(spr);
2011-06-30 08:30:23 +02:00
Bitmap::_pal = NULL;
2011-06-13 11:57:24 +02:00
}
}
}
}
void SNSwap(Sprite *spr, int xref) {
Sprite *xspr = Locate(xref);
2011-06-13 11:57:24 +02:00
if (spr && xspr) {
int was = spr->_cave;
int xwas = xspr->_cave;
2011-06-13 11:57:24 +02:00
bool was1 = (was == 0 || was == Now);
bool xwas1 = (xwas == 0 || xwas == Now);
Swap(spr->_cave, xspr->_cave);
2011-06-29 16:13:17 +02:00
Swap(spr->_x, xspr->_x);
Swap(spr->_y, xspr->_y);
Swap(spr->_z, xspr->_z);
if (spr->_flags._kept) {
2011-06-13 11:57:24 +02:00
int n = FindPocket(spr);
2011-06-13 13:07:45 +02:00
if (n >= 0)
_pocket[n] = xspr;
2011-06-29 16:13:17 +02:00
xspr->_flags._kept = true;
xspr->_flags._port = false;
2011-06-13 11:57:24 +02:00
}
if (xwas1 != was1) {
if (was1) {
Hide1(spr);
ContractSprite(spr);
2011-06-13 13:07:45 +02:00
} else
2011-06-13 11:57:24 +02:00
ExpandSprite(spr);
if (xwas1) {
Hide1(xspr);
ContractSprite(xspr);
2011-06-13 13:07:45 +02:00
} else
2011-06-13 11:57:24 +02:00
ExpandSprite(xspr);
}
}
}
void SNCover(Sprite *spr, int xref) {
Sprite *xspr = Locate(xref);
2011-06-13 11:57:24 +02:00
if (spr && xspr) {
2011-06-29 16:13:17 +02:00
spr->_flags._hide = true;
xspr->_z = spr->_z;
xspr->_cave = spr->_cave;
2011-06-29 16:13:17 +02:00
xspr->Goto(spr->_x, spr->_y);
2011-06-13 11:57:24 +02:00
ExpandSprite(xspr);
2011-06-29 16:13:17 +02:00
if ((xspr->_flags._shad = spr->_flags._shad) == 1) {
Vga->ShowQ->Insert(Vga->ShowQ->Remove(spr->_prev), xspr);
spr->_flags._shad = false;
2011-06-13 11:57:24 +02:00
}
FeedSnail(xspr, NEAR);
}
}
void SNUncover(Sprite *spr, Sprite *xspr) {
2011-06-13 11:57:24 +02:00
if (spr && xspr) {
2011-06-29 16:13:17 +02:00
spr->_flags._hide = false;
spr->_cave = xspr->_cave;
2011-06-29 16:13:17 +02:00
spr->Goto(xspr->_x, xspr->_y);
if ((spr->_flags._shad = xspr->_flags._shad) == 1) {
Vga->ShowQ->Insert(Vga->ShowQ->Remove(xspr->_prev), spr);
xspr->_flags._shad = false;
2011-06-13 11:57:24 +02:00
}
2011-06-29 16:13:17 +02:00
spr->_z = xspr->_z;
2011-06-13 11:57:24 +02:00
SNSend(xspr, -1);
2011-06-29 16:13:17 +02:00
if (spr->_time == 0)
++spr->_time;
}
}
2011-06-13 11:57:24 +02:00
void SNSetX0(int cav, int x0) {
2011-06-29 16:13:17 +02:00
HeroXY[cav - 1]._x = x0;
}
2011-06-13 11:57:24 +02:00
void SNSetY0(int cav, int y0) {
2011-06-29 16:13:17 +02:00
HeroXY[cav - 1]._y = y0;
}
void SNSetXY(Sprite *spr, uint16 xy) {
2011-06-13 11:57:24 +02:00
if (spr)
spr->Goto(xy % SCR_WID, xy / SCR_WID);
}
void SNRelX(Sprite *spr, int x) {
2011-06-13 11:57:24 +02:00
if (spr && Hero)
2011-06-29 16:13:17 +02:00
spr->Goto(Hero->_x + x, spr->_y);
}
void SNRelY(Sprite *spr, int y) {
2011-06-13 11:57:24 +02:00
if (spr && Hero)
2011-06-29 16:13:17 +02:00
spr->Goto(spr->_x, Hero->_y + y);
}
void SNRelZ(Sprite *spr, int z) {
2011-06-13 11:57:24 +02:00
if (spr && Hero) {
2011-06-29 16:13:17 +02:00
spr->_z = Hero->_z + z;
2011-06-13 11:57:24 +02:00
SNZTrim(spr);
}
}
void SNSetX(Sprite *spr, int x) {
2011-06-13 11:57:24 +02:00
if (spr)
2011-06-29 16:13:17 +02:00
spr->Goto(x, spr->_y);
}
void SNSetY(Sprite *spr, int y) {
2011-06-13 11:57:24 +02:00
if (spr)
2011-06-29 16:13:17 +02:00
spr->Goto(spr->_x, y);
}
void SNSetZ(Sprite *spr, int z) {
2011-06-13 11:57:24 +02:00
if (spr) {
2011-06-29 16:13:17 +02:00
spr->_z = z;
2011-06-13 11:57:24 +02:00
//SNPOST_(SNZTRIM, -1, 0, spr);
SNZTrim(spr);
}
}
void SNSlave(Sprite *spr, int ref) {
Sprite *slv = Locate(ref);
2011-06-13 11:57:24 +02:00
if (spr && slv) {
if (spr->Active()) {
SNSend(slv, spr->_cave);
2011-06-29 16:13:17 +02:00
slv->_flags._slav = true;
slv->_z = spr->_z;
Vga->ShowQ->Insert(Vga->ShowQ->Remove(slv), spr->_next);
2011-06-13 11:57:24 +02:00
}
}
}
void SNTrans(Sprite *spr, int trans) {
2011-06-13 11:57:24 +02:00
if (spr)
2011-06-29 16:13:17 +02:00
spr->_flags._tran = (trans < 0) ? !spr->_flags._tran : (trans != 0);
}
void SNPort(Sprite *spr, int port) {
2011-06-13 11:57:24 +02:00
if (spr)
2011-06-29 16:13:17 +02:00
spr->_flags._port = (port < 0) ? !spr->_flags._port : (port != 0);
}
void SNKill(Sprite *spr) {
2011-06-13 11:57:24 +02:00
if (spr) {
2011-06-29 16:13:17 +02:00
if (spr->_flags._kept) {
2011-06-13 11:57:24 +02:00
int n = FindPocket(spr);
2011-06-13 13:07:45 +02:00
if (n >= 0)
_pocket[n] = NULL;
2011-06-13 11:57:24 +02:00
}
2011-06-29 16:13:17 +02:00
Sprite *nx = spr->_next;
2011-06-13 11:57:24 +02:00
Hide1(spr);
Vga->ShowQ->Remove(spr);
2011-06-13 11:57:24 +02:00
MOUSE::ClrEvt(spr);
2011-06-29 16:13:17 +02:00
if (spr->_flags._kill)
2011-06-13 11:57:24 +02:00
delete spr;
else {
spr->_cave = -1;
Vga->SpareQ->Append(spr);
2011-06-13 11:57:24 +02:00
}
2011-06-29 16:13:17 +02:00
if (nx) {
if (nx->_flags._slav)
2011-06-13 11:57:24 +02:00
SNKill(nx);
2011-06-29 16:13:17 +02:00
}
}
}
static void SNSound(Sprite *spr, int wav, int cnt) {
2011-06-13 11:57:24 +02:00
if (SNDDrvInfo.DDEV) {
2011-06-13 13:07:45 +02:00
if (wav == -1)
2011-06-13 11:57:24 +02:00
Sound.Stop();
else
2011-06-29 16:13:17 +02:00
Sound.Play(Fx[wav], (spr) ? ((spr->_x + spr->_w / 2) / (SCR_WID / 16)) : 8, cnt);
2011-06-13 11:57:24 +02:00
}
}
void SNKeep(Sprite *spr, int stp) {
2011-06-13 11:57:24 +02:00
SelectPocket(-1);
2011-06-29 16:13:17 +02:00
if (spr && ! spr->_flags._kept && _pocket[PocPtr] == NULL) {
2011-06-13 11:57:24 +02:00
SNSound(spr, 3, 1);
_pocket[PocPtr] = spr;
spr->_cave = 0;
2011-06-29 16:13:17 +02:00
spr->_flags._kept = true;
spr->Goto(POCKET_X + POCKET_DX * PocPtr + POCKET_DX / 2 - spr->_w / 2,
POCKET_Y + POCKET_DY / 2 - spr->_h / 2);
2011-06-13 13:07:45 +02:00
if (stp >= 0)
2011-06-13 11:57:24 +02:00
spr->Step(stp);
}
SelectPocket(-1);
}
void SNGive(Sprite *spr, int stp) {
2011-06-13 11:57:24 +02:00
if (spr) {
int p = FindPocket(spr);
if (p >= 0) {
_pocket[p] = NULL;
spr->_cave = Now;
2011-06-29 16:13:17 +02:00
spr->_flags._kept = false;
2011-06-13 13:07:45 +02:00
if (stp >= 0)
2011-06-13 11:57:24 +02:00
spr->Step(stp);
}
}
2011-06-13 11:57:24 +02:00
SelectPocket(-1);
}
static void SNBackPt(Sprite *spr, int stp) {
2011-06-13 11:57:24 +02:00
if (spr) {
2011-06-13 13:07:45 +02:00
if (stp >= 0)
2011-06-13 11:57:24 +02:00
spr->Step(stp);
spr->BackShow(true);
}
}
static void SNLevel(Sprite *spr, int lev) {
2011-06-13 11:57:24 +02:00
#ifdef DEMO
static int maxcav[] = { CAVE_MAX };
#else
static int maxcav[] = { 1, 8, 16, 23, 24 };
#endif
while (Lev < lev) {
++Lev;
spr = Vga->SpareQ->Locate(100 + Lev);
2011-06-13 11:57:24 +02:00
if (spr) {
spr->BackShow(true);
spr->_cave = 0;
2011-06-13 11:57:24 +02:00
}
}
2011-06-13 11:57:24 +02:00
MaxCave = maxcav[Lev];
2011-06-13 13:07:45 +02:00
if (spr)
2011-06-29 16:13:17 +02:00
spr->_flags._hide = false;
}
2011-06-13 11:57:24 +02:00
static void SNFlag(int fn, bool v) {
Flag[fn] = v;
}
static void SNSetRef(Sprite *spr, int nr) {
2011-06-13 11:57:24 +02:00
if (spr)
spr->_ref = nr;
}
2011-06-13 11:57:24 +02:00
void SNFlash(bool on) {
if (on) {
2011-07-01 08:37:40 +02:00
Dac *pal = farnew(Dac, PAL_CNT);
2011-06-13 11:57:24 +02:00
if (pal) {
memcpy(pal, VGA::SysPal, PAL_SIZ);
for (int i = 0; i < PAL_CNT; i++) {
2011-06-13 11:57:24 +02:00
register int c;
2011-07-01 08:37:40 +02:00
c = pal[i]._r << 1;
pal[i]._r = (c < 64) ? c : 63;
c = pal[i]._g << 1;
pal[i]._g = (c < 64) ? c : 63;
c = pal[i]._b << 1;
pal[i]._b = (c < 64) ? c : 63;
2011-06-13 11:57:24 +02:00
}
Vga->SetColors(pal, 64);
2011-06-13 11:57:24 +02:00
}
2011-06-13 13:07:45 +02:00
} else
Vga->SetColors(VGA::SysPal, 64);
2011-06-13 11:57:24 +02:00
Dark = false;
}
2011-06-13 11:57:24 +02:00
static void SNLight(bool in) {
2011-06-13 13:07:45 +02:00
if (in)
Vga->Sunrise(VGA::SysPal);
2011-06-13 11:57:24 +02:00
else
Vga->Sunset();
2011-06-13 11:57:24 +02:00
Dark = ! in;
}
2011-06-13 11:57:24 +02:00
static void SNBarrier(int cav, int bar, bool horz) {
((uint8 *)(Barriers + ((cav > 0) ? cav : Now)))[horz] = bar;
}
static void SNWalk(Sprite *spr, int x, int y) {
2011-06-13 11:57:24 +02:00
if (Hero) {
2011-06-13 13:07:45 +02:00
if (spr && y < 0)
2011-07-01 08:37:40 +02:00
Hero->findWay(spr);
2011-06-13 13:07:45 +02:00
else
2011-07-01 08:37:40 +02:00
Hero->findWay(XZ(x, y));
2011-06-13 11:57:24 +02:00
}
}
static void SNReach(Sprite *spr, int mode) {
2011-06-13 13:07:45 +02:00
if (Hero)
2011-07-01 08:37:40 +02:00
Hero->reach(spr, mode);
}
2011-06-13 11:57:24 +02:00
static void SNMouse(bool on) {
if (on)
2011-06-20 23:40:22 +02:00
Mouse->On();
2011-06-13 11:57:24 +02:00
else
2011-06-20 23:40:22 +02:00
Mouse->Off();
}
2011-06-13 11:57:24 +02:00
void SNAIL::RunCom(void) {
static int count = 1;
if (! Busy) {
Busy = true;
uint8 tmphea = Head;
while (Tail != tmphea) {
COM *snc = &SNList[Tail];
if (! Turbo) { // only for the slower one
if (_timerExpiry && (_timerExpiry > g_system->getMillis()))
2011-06-13 11:57:24 +02:00
break;
else {
if (TextDelay) {
KillText();
TextDelay = false;
}
}
2011-06-13 13:07:45 +02:00
if (Talk && snc->Com != SNPAUSE)
2011-06-13 11:57:24 +02:00
break;
}
Sprite *sprel = ((snc->Ref >= 0) ? Locate(snc->Ref) : ((Sprite *) snc->Ptr));
2011-06-13 11:57:24 +02:00
switch (snc->Com) {
case SNLABEL :
break;
case SNPAUSE :
_timerExpiry = g_system->getMillis() + snc->Val * SNAIL_FRAME_DELAY;
2011-06-13 13:07:45 +02:00
if (Talk)
2011-06-13 11:57:24 +02:00
TextDelay = true;
break;
case SNWAIT :
if (sprel) {
if (sprel->SeqTest(snc->Val) &&
2011-07-01 08:37:40 +02:00
(snc->Val >= 0 || sprel != Hero || Hero->_tracePtr < 0)) {
_timerExpiry = g_system->getMillis() + sprel->_time * SNAIL_FRAME_DELAY;
2011-06-13 13:07:45 +02:00
} else
2011-06-13 11:57:24 +02:00
goto xit;
}
break;
case SNLEVEL :
SNLevel(sprel, snc->Val);
break;
case SNHIDE :
SNHide(sprel, snc->Val);
break;
case SNSAY :
if (sprel && TalkEnable) {
if (sprel == Hero && sprel->SeqTest(-1))
sprel->Step(HTALK);
Text->Say(Text->getText(snc->Val), sprel);
2011-06-20 23:40:22 +02:00
Sys->FunDel = HEROFUN0;
2011-06-13 11:57:24 +02:00
}
break;
case SNINF :
if (TalkEnable) {
2011-07-01 08:37:40 +02:00
_vm->inf(Text->getText(snc->Val));
2011-06-20 23:40:22 +02:00
Sys->FunDel = HEROFUN0;
2011-06-13 11:57:24 +02:00
}
break;
case SNTIME :
if (sprel && TalkEnable) {
if (sprel == Hero && sprel->SeqTest(-1))
sprel->Step(HTALK);
SayTime(sprel);
}
break;
case SNCAVE :
// SwitchCave(snc->Val);
warning("Problematic call of SwitchCave in SNAIL::RunCom");
2011-06-13 11:57:24 +02:00
break;
case SNKILL :
SNKill(sprel);
break;
case SNSEQ :
SNSeq(sprel, snc->Val);
break;
case SNRSEQ :
SNRSeq(sprel, snc->Val);
break;
case SNSEND :
SNSend(sprel, snc->Val);
break;
case SNSWAP :
SNSwap(sprel, snc->Val);
break;
case SNCOVER :
SNCover(sprel, snc->Val);
break;
case SNUNCOVER :
SNUncover(sprel, (snc->Val >= 0) ? Locate(snc->Val) : ((Sprite *) snc->Ptr));
2011-06-13 11:57:24 +02:00
break;
case SNKEEP :
SNKeep(sprel, snc->Val);
break;
case SNGIVE :
SNGive(sprel, snc->Val);
break;
case SNGAME :
SNGame(sprel, snc->Val);
break;
case SNSETX0 :
SNSetX0(snc->Ref, snc->Val);
break;
case SNSETY0 :
SNSetY0(snc->Ref, snc->Val);
break;
2011-06-13 11:57:24 +02:00
case SNSETXY :
SNSetXY(sprel, snc->Val);
break;
2011-06-13 11:57:24 +02:00
case SNRELX :
SNRelX(sprel, snc->Val);
break;
2011-06-13 11:57:24 +02:00
case SNRELY :
SNRelY(sprel, snc->Val);
break;
2011-06-13 11:57:24 +02:00
case SNRELZ :
SNRelZ(sprel, snc->Val);
break;
2011-06-13 11:57:24 +02:00
case SNSETX :
SNSetX(sprel, snc->Val);
break;
case SNSETY :
SNSetY(sprel, snc->Val);
break;
case SNSETZ :
SNSetZ(sprel, snc->Val);
break;
case SNSLAVE :
SNSlave(sprel, snc->Val);
break;
case SNTRANS :
SNTrans(sprel, snc->Val);
break;
case SNPORT :
SNPort(sprel, snc->Val);
break;
case SNNEXT :
break;
case SNIF :
break;
case SNTALK :
break;
case SNMOUSE :
SNMouse(snc->Val != 0);
break;
case SNNNEXT :
SNNNext(sprel, snc->Val);
break;
case SNTNEXT :
SNTNext(sprel, snc->Val);
break;
case SNRNNEXT :
SNRNNext(sprel, snc->Val);
break;
case SNRTNEXT :
SNRTNext(sprel, snc->Val);
break;
case SNRMNEAR :
SNRmNear(sprel);
break;
case SNRMTAKE :
SNRmTake(sprel);
break;
case SNFLAG :
SNFlag(snc->Ref & 3, snc->Val != 0);
break;
case SNSETREF :
SNSetRef(sprel, snc->Val);
break;
case SNBACKPT :
SNBackPt(sprel, snc->Val);
break;
case SNFLASH :
SNFlash(snc->Val != 0);
break;
case SNLIGHT :
SNLight(snc->Val != 0);
break;
case SNSETHB :
SNBarrier(snc->Ref, snc->Val, true);
break;
case SNSETVB :
SNBarrier(snc->Ref, snc->Val, false);
break;
case SNWALK :
SNWalk(sprel, snc->Ref, snc->Val);
break;
case SNREACH :
SNReach(sprel, snc->Val);
break;
case SNSOUND :
SNSound(sprel, snc->Val, count);
count = 1;
break;
case SNCOUNT :
count = snc->Val;
break;
case SNEXEC :
// TODO: Handle correctly the execution of function pointer coming from Message send SNPOST
// ((void(*)(int)) (snc->Ptr))(snc->Val); break;
warning("STUB: SNEXEC code");
case SNSTEP :
sprel->Step();
break;
case SNZTRIM :
SNZTrim(sprel);
break;
case SNGHOST :
2011-06-29 16:13:17 +02:00
SNGhost((Bitmap *) snc->Ptr);
2011-06-13 11:57:24 +02:00
break;
default :
warning("Unhandled snc->Com in SNMouse(bool)");
break;
2011-06-13 11:57:24 +02:00
}
2011-06-29 16:13:17 +02:00
Tail++;
2011-06-13 13:07:45 +02:00
if (!Turbo)
2011-06-13 11:57:24 +02:00
break;
}
xit:
Busy = false;
}
}
2011-06-13 11:57:24 +02:00
bool SNAIL::Idle(void) {
return (Head == Tail);
}
2011-06-10 22:57:09 +02:00
} // End of namespace CGE