KINGDOM: Move the hardcoded logic to a separate class

This commit is contained in:
Strangerke 2017-07-12 01:58:19 +02:00 committed by Eugene Sandulenko
parent 45cafdc8aa
commit 7153dd6d06
9 changed files with 2387 additions and 2276 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -21,46 +21,47 @@
*/
#include "kingdom/kingdom.h"
#include "kingdom/logic.h"
namespace Kingdom {
void KingdomGame::GPLogic4() {
void Logic::GPLogic4() {
switch(_statPlay) {
case 900:
if (_aTimer > 0) {
playSound(0);
_aTimer = 133;
if (_vm->_aTimer > 0) {
_vm->playSound(0);
_vm->_aTimer = 133;
}
if (_asMode) {
switchMtoA();
if (_vm->_asMode) {
_vm->switchMtoA();
_mapStat = 0;
_oldStatPlay--;
_asMode = false;
_vm->_asMode = false;
}
saveAS();
fadeToBlack2();
_vm->saveAS();
_vm->fadeToBlack2();
if (_health == 10 || _health == 6 || _health == 2) {
showPic(121);
_bTimer = 38;
readMouse();
while (_bTimer && !_mouseButton) {
checkTimers();
refreshSound();
readMouse();
_vm->showPic(121);
_vm->_bTimer = 38;
_vm->readMouse();
while (_vm->_bTimer && !_vm->_mouseButton) {
_vm->checkTimers();
_vm->refreshSound();
_vm->readMouse();
}
if (_aTimer > 0)
setATimer();
if (_vm->_aTimer > 0)
_vm->setATimer();
_userInput = 0;
_vm->_userInput = 0;
GPLogic4_SP901();
} else {
if (_aTimer > 0) {
setATimer();
_aTimer = 133;
if (_vm->_aTimer > 0) {
_vm->setATimer();
_vm->_aTimer = 133;
}
showPic(120);
_vm->showPic(120);
_statPlay = 901;
}
break;
@ -69,48 +70,48 @@ void KingdomGame::GPLogic4() {
break;
case 991:
_currMap = 10;
_userInput = 0;
playSound(0);
_vm->_userInput = 0;
_vm->playSound(0);
if (_health == 10 || _health == 6 || _health == 2)
_health -= 2;
else
_health -= 4;
if (_health == 0) {
playMovie(194);
_noIFScreen = true;
fShowPic(107);
_vm->playMovie(194);
_vm->_noIFScreen = true;
_vm->fShowPic(107);
_currMap = 3;
dsAll();
_pouch = false;
playSound(1);
_vm->playSound(1);
memset(_inventory, -1, 19);
_statPlay = 994;
} else {
_bTimer = 36;
while(_bTimer) {
checkTimers();
refreshSound();
_vm->_bTimer = 36;
while(_vm->_bTimer) {
_vm->checkTimers();
_vm->refreshSound();
}
_loopFlag = true;
_vm->_loopFlag = true;
if (_nodes[29] == 1) {
_nodes[29] = 0;
_nodes[49] = 0;
}
_itemInhibit = false;
_vm->_itemInhibit = false;
_tideCntl = false;
drawPic(179);
_skylarTimer = 0;
_skylarTimerFlag = false;
_vm->drawPic(179);
_vm->_skylarTimer = 0;
_vm->_skylarTimerFlag = false;
enAll();
_mapEx = true;
_vm->_mapEx = true;
_nodeNum = 5;
drawLocation();
playSound(0);
_vm->drawLocation();
_vm->playSound(0);
if (_nodes[5] > 0) {
playMovie(197);
_vm->playMovie(197);
_resurrect = true;
}
inventoryDel(12);
@ -119,79 +120,79 @@ void KingdomGame::GPLogic4() {
break;
case 992:
_currMap = 10;
_userInput = 0;
playSound(0);
_vm->_userInput = 0;
_vm->playSound(0);
if (_health == 10 || _health == 6 || _health == 2)
_health -= 2;
else
_health -= 4;
if (_health == 0) {
playMovie(194);
_noIFScreen = true;
fShowPic(107);
_vm->playMovie(194);
_vm->_noIFScreen = true;
_vm->fShowPic(107);
_currMap = 3;
dsAll();
_pouch = false;
playSound(1);
_vm->playSound(1);
memset(_inventory, -1, 19);
_statPlay = 994;
} else {
_bTimer = 36;
while(_bTimer != 0) {
checkTimers();
refreshSound();
_vm->_bTimer = 36;
while(_vm->_bTimer != 0) {
_vm->checkTimers();
_vm->refreshSound();
}
_loopFlag = true;
_vm->_loopFlag = true;
if (_nodes[29] == 1) {
_nodes[29] = 0;
_nodes[49] = 0;
}
_itemInhibit = false;
_vm->_itemInhibit = false;
_tideCntl = false;
drawPic(179);
_skylarTimer = 0;
_skylarTimerFlag = false;
_vm->drawPic(179);
_vm->_skylarTimer = 0;
_vm->_skylarTimerFlag = false;
enAll();
_mapEx = true;
_vm->_mapEx = true;
_nodeNum = 27;
drawLocation();
_vm->drawLocation();
_resurrect = true;
playSound(0);
playMovie(195);
_vm->playSound(0);
_vm->playMovie(195);
inventoryDel(12);
_statPlay = 270;
}
break;
case 993:
_currMap = 10;
_userInput = 0;
playSound(0);
_vm->_userInput = 0;
_vm->playSound(0);
if (_health == 10 || _health == 6 || _health == 2)
_health -= 2;
else
_health -= 4;
if (_health == 0) {
playMovie(194);
_noIFScreen = true;
fShowPic(107);
_vm->playMovie(194);
_vm->_noIFScreen = true;
_vm->fShowPic(107);
_currMap = 3;
dsAll();
_pouch = false;
playSound(1);
_vm->playSound(1);
memset(_inventory, -1, 19);
_statPlay = 994;
} else {
_bTimer = 36;
while (_bTimer != 0) {
checkTimers();
refreshSound();
_vm->_bTimer = 36;
while (_vm->_bTimer != 0) {
_vm->checkTimers();
_vm->refreshSound();
}
_loopFlag = true;
_vm->_loopFlag = true;
if (_nodes[29] == 1) {
_nodes[29] = 0;
_nodes[49] = 0;
@ -199,73 +200,73 @@ void KingdomGame::GPLogic4() {
if (_nodes[68] == 1)
_nodes[68] = 0;
_itemInhibit = false;
_vm->_itemInhibit = false;
_tideCntl = false;
drawPic(179);
_skylarTimer = 0;
_skylarTimerFlag = false;
_vm->drawPic(179);
_vm->_skylarTimer = 0;
_vm->_skylarTimerFlag = false;
enAll();
_mapEx = true;
_vm->_mapEx = true;
_nodeNum = 52;
drawLocation();
_vm->drawLocation();
_resurrect = true;
playSound(0);
playMovie(196);
_vm->playSound(0);
_vm->playMovie(196);
inventoryDel(12);
_statPlay = 520;
}
break;
case 994:
switch(_userInput) {
switch(_vm->_userInput) {
case 0x190:
initPlay();
_vm->initPlay();
// TODO _QuitFlag = 1;
_quit = true;
_vm->_quit = true;
break;
case 0x191:
// TODO _QuitFlag = 2;
_quit = true;
_vm->_quit = true;
break;
}
break;
}
}
void KingdomGame::GPLogic4_SP901() {
setMouse();
eraseCursor();
fadeToBlack2();
showPic(106);
drawIcon(4, 0, 12 - _healthOld);
void Logic::GPLogic4_SP901() {
_vm->setMouse();
_vm->eraseCursor();
_vm->fadeToBlack2();
_vm->showPic(106);
_vm->drawIcon(4, 0, 12 - _healthOld);
if (_tideCntl)
drawPic(178);
_vm->drawPic(178);
else
drawPic(179);
_vm->drawPic(179);
_iconRedraw = true;
if (_userInput == 0x2F1) {
_asMode = false;
restoreAS();
_vm->_iconRedraw = true;
if (_vm->_userInput == 0x2F1) {
_vm->_asMode = false;
_vm->restoreAS();
_statPlay = _oldStatPlay;
_loopFlag = true;
_vm->_loopFlag = true;
} else {
if (_health == 10 || _health == 6 || _health == 2 || _userInput < 0x400 || _userInput > 0x427) {
_asMode = false;
restoreAS();
if (_health == 10 || _health == 6 || _health == 2 || _vm->_userInput < 0x400 || _vm->_userInput > 0x427) {
_vm->_asMode = false;
_vm->restoreAS();
_statPlay = _oldStatPlay;
} else {
_statPlay = _mapExit[_userInput - 0x400];
_userInput = 0;
_statPlay = _mapExit[_vm->_userInput - 0x400];
_vm->_userInput = 0;
wound();
playMovie(10);
_vm->playMovie(10);
inventoryDel(3);
_tsIconOnly = false;
_vm->_tsIconOnly = false;
enAll();
switchAS();
_mapStat = 0;
}
_userInput = 0;
_loopFlag = true;
_vm->_userInput = 0;
_vm->_loopFlag = true;
}
}

View File

@ -53,6 +53,8 @@ KingdomGame::KingdomGame(OSystem *syst, const ADGameDescription *gameDesc) : Eng
DebugMan.addDebugChannel(kDebugGeneral, "general", "General debug level");
_logic = nullptr;
_asPtr = nullptr;
_quit = false;
_kingartEntries = nullptr;
@ -93,8 +95,6 @@ void KingdomGame::initVariables() {
_iconRedraw = 0;
_healthTmr = 0;
_healthOld = 0;
_health = 0;
_palStepFlag = 0;
_skylarTimerFlag = 0;
_skylarTimer = 0;
@ -107,54 +107,30 @@ void KingdomGame::initVariables() {
_zoom = 0;
_wizard = 0;
_userInput = 0;
_tideCntl = 0;
// _track = 0;
// _statMap = 0;
_statPlay = 0;
_spell3 = 0;
_spell2 = 0;
_spell1 = 0;
_soundNumber = 0;
_robberyNode = 0;
_rtnNode = 0;
_replay = false;
_resurrect = false;
// _quitFlag = 0;
_pouch = false;
_soundNumber = 0;
_pMovie = 0;
// _options = 0;
_oldPouch = false;
_oldHelp = false;
_oldEye = false;
_oldTRS = 0;
_oldTLS = 0;
_oldStatPlay = 0;
_oldNode = 0;
_oldIconsClosed = false;
_fstFwd = false;
_noMusic = false;
_nodeNum = 0;
_nextNode = 0;
_mouseValue = 0;
_mapEx = 0;
_mapStat = 0;
_loopFlag = false;
_lastSound = 0;
_lastObs = 0;
_lastObstacle = 0;
_keyActive = false;
_help = false;
_itemInhibit = false;
// _iconW = 0;
_gameMode = 0;
_fullScreen = false;
_frameStop = 0;
_eye = false;
_daelonCntr = 0;
_sound = 0;
_asMode = false;
for (int i = 0; i < 99; i++)
_nodes[i] = 0;
for (int i = 0; i < 510; i++) {
_rezPointers[i] = nullptr;
_rezSize[i] = 0;
@ -170,12 +146,12 @@ void KingdomGame::initVariables() {
_cursorDef = 0;
_cursorY = 0;
_cursorX = 0;
_currMap = 0;
_asMap = 0;
}
KingdomGame::~KingdomGame() {
delete _console;
delete _logic;
delete _rnd;
}
@ -187,6 +163,9 @@ Common::Error KingdomGame::run() {
initGraphics(320, 200, false);
_console = new Console(this);
_logic = new Logic(this);
_logic->initVariables();
setupPics();
initTools();
titlePage();
@ -196,21 +175,21 @@ Common::Error KingdomGame::run() {
while (!_quit) {
_loopFlag = false;
gameHelp();
_logic->gameHelp();
if (_gameMode == 0) {
if (_statPlay < 250)
GPLogic1();
if (_statPlay > 249 && _statPlay < 500)
GPLogic2();
if (_statPlay > 499 && _statPlay < 900) {
if (_logic->_statPlay < 250)
_logic->GPLogic1();
if (_logic->_statPlay > 249 && _logic->_statPlay < 500)
_logic->GPLogic2();
if (_logic->_statPlay > 499 && _logic->_statPlay < 900) {
if (!isDemo())
GPLogic3();
_logic->GPLogic3();
else
warning("Unexpected GPL3 opcode found in demo: %d", _statPlay);
warning("Unexpected GPL3 opcode found in demo: %d", _logic->_statPlay);
}
if (_statPlay > 899)
GPLogic4();
if (_logic->_statPlay > 899)
_logic->GPLogic4();
}
if (!_loopFlag)
@ -309,21 +288,12 @@ void KingdomGame::titlePage() {
}
void KingdomGame::initPlay() {
memset(_inventory, 0xFF, 19);
for (int i = 0; i < 99; i++)
_nodes[i] = 0;
for (int i = 0; i < 7; i++)
_iconPic[i] = 89 + i;
_frameStop = 0;
_gameMode = 0;
_daelonCntr = 0;
_statPlay = 10;
_spell1 = false;
_spell2 = false;
_spell3 = false;
_itemInhibit = false;
_asMode = false;
_aTimerFlag = false;
@ -334,10 +304,7 @@ void KingdomGame::initPlay() {
_bTimer = 0;
_cTimer = 0;
_skylarTimer = 0;
_tideCntl = false;
_mapEx = false;
_health = 12;
_healthOld = 1;
_healthTmr = 0;
_treeEyeTimer = 0;
_treeHGTimer = 0;
@ -346,15 +313,14 @@ void KingdomGame::initPlay() {
_treeRightPic = 0;
_treeRightSta = 1;
_tsIconOnly = false;
_lastObs = false;
enAll();
_pouch = true;
_noIFScreen = true;
_noMusic = false;
_fstFwd = true;
delete[] _asPtr;
_asPtr = nullptr;
_logic->initPlay();
}
void KingdomGame::initHelp() {
@ -369,150 +335,6 @@ void KingdomGame::fadeToBlack2() {
debug("STUB: FadeToBlack2");
}
void KingdomGame::gameHelp_Sub43C() {
fadeToBlack1();
_currMap = _asMap;
drawRect(4, 17, 228, 161, 0);
restoreAS();
_userInput = 0;
_gameMode = 0;
_iconsClosed = false;
_treeLeftSta = _oldTLS;
_eye = _oldEye;
_help = _oldHelp;
_pouch = _oldPouch;
}
void KingdomGame::gameHelp() {
if (!_gameMode) {
if (_userInput == 0x43C) {
saveAS();
_asMap = _currMap;
_currMap = 0;
fadeToBlack1();
drawRect(4, 17, 228, 161, 0);
drawHelpScreen();
_gameMode = 1;
_oldTLS = _treeLeftSta;
_treeLeftSta = 0;
_iconsClosed = true;
_oldEye = _eye;
_eye = false;
_oldHelp = _help;
_oldPouch = _pouch;
_pouch = false;
_userInput = 0;
}
if (_userInput == 0x44F) {
saveAS();
_asMap = _currMap;
_gameMode = 2;
_oldTLS = _treeLeftSta;
_treeLeftSta = 0;
_iconsClosed = true;
_oldEye = _eye;
_eye = false;
_oldHelp = _help;
_help = false;
_oldPouch = _pouch;
fadeToBlack1();
drawRect(4, 17, 228, 161, 0);
drawInventory();
if (_nodes[68] == 1 || _nodes[29] == 1 || _itemInhibit)
_currMap = 10;
else
_currMap = 11;
_userInput = 0;
}
}
if (_gameMode == 0)
return;
switch(_userInput) {
case 0x240:
fadeToBlack2();
//TODO: Set _quitFlag to 1
break;
case 0x241:
gameHelp_Sub43C();
return;
break;
case 0x242:
if (_noMusic) {
_noMusic = false;
playSound(1);
} else {
_noMusic = true;
playSound(0);
}
drawHelpScreen();
break;
case 0x243: {
fadeToBlack2();
_keyActive = false;
_noIFScreen = true;
playSound(0);
// The demo isn't saving pMovie.
// It's obviously a bug and this behavior wasn't kept in ScummVM
int oldPMovie = _pMovie;
while(!_keyActive) {
playMovie(54);
fadeToBlack2();
}
_pMovie = oldPMovie;
_noIFScreen = false;
showPic(106);
drawHelpScreen();
_iconRedraw = true;
playSound(1);
}
break;
case 0x244:
//TODO: Set _quitFlag to 2
_quit = true;
break;
case 0x245: {
fadeToBlack1();
// The demo isn't saving pMovie.
// It's obviously a bug and this behavior wasn't kept in ScummVM
int oldPMovie = _pMovie;
drawRect(4, 17, 228, 161, 0);
playMovie(205);
fadeToBlack1();
drawRect(4, 17, 228, 161, 0);
playMovie(199);
fadeToBlack1();
drawRect(4, 17, 228, 161, 0);
drawHelpScreen();
_pMovie = oldPMovie;
}
break;
case 0x246:
saveGame();
break;
case 0x43B:
case 0x43C:
case 0x44F:
gameHelp_Sub43C();
return;
}
if (_userInput > 0x427 && _userInput < 0x43A)
fShowPic(130 + _userInput - 0x428);
if (_userInput == 0x260) {
drawInventory();
if (_nodes[68] == 1 || _nodes[29] == 1)
_currMap = 10;
else
_currMap = 11;
_userInput = 0;
}
}
void KingdomGame::loadKingArt() {
loadAResource(0x97);
Common::SeekableReadStream *kingartStream = _rezPointers[0x97];
@ -673,7 +495,7 @@ void KingdomGame::playMovie(int movieNum) {
_treeRightSta = 1;
_iconsClosed = false;
_iconSel = 9;
_treeLeftSta = _replay ? 2 : 0;
_treeLeftSta = _logic->_replay ? 2 : 0;
checkMainScreen();
drawCursor();
_fstFwd = true;
@ -684,22 +506,6 @@ void KingdomGame::playMovie(int movieNum) {
}
}
void KingdomGame::enAll() {
_help = true;
_eye = true;
_replay = true;
_pouch = true;
_fstFwd = true;
}
void KingdomGame::dsAll() {
_help = false;
_eye = false;
_replay = false;
_pouch = false;
_fstFwd = false;
}
void KingdomGame::saveAS() {
byte palette[256 * 3];
delete[] _asPtr;
@ -742,20 +548,10 @@ void KingdomGame::restoreAS() {
_asPtr = nullptr;
}
void KingdomGame::switchAS() {
_asMode = false;
_currMap = _asMap;
_treeLeftSta = _oldTLS;
_treeRightSta = _oldTRS;
_pouch = _oldPouch;
_help = _oldHelp;
_iconsClosed = _oldIconsClosed;
}
void KingdomGame::drawHelpScreen() {
int picNum;
switch(_health) {
switch(_logic->_health) {
case 2:
picNum = 166;
break;
@ -797,74 +593,74 @@ void KingdomGame::drawRect(uint minX, uint minY, uint maxX, uint maxY, int color
void KingdomGame::drawInventory() {
fShowPic(108);
if (_nodes[29] == 1 || _nodes[68] == 1 || _itemInhibit)
if (_logic->_nodes[29] == 1 || _logic->_nodes[68] == 1 || _itemInhibit)
return;
if (_inventory[0] > 0)
if (_logic->_inventory[0] > 0)
drawIcon(136, 102, 180);
if (_inventory[1] > 0)
if (_logic->_inventory[1] > 0)
drawIcon(73, 65, 175);
if (_inventory[2] > 0)
if (_logic->_inventory[2] > 0)
drawIcon(171, 96, 179);
if (_inventory[3] > 0)
if (_logic->_inventory[3] > 0)
drawIcon(120, 34, 174);
if (_inventory[4] > 0)
if (_logic->_inventory[4] > 0)
drawIcon(160, 41, 177);
if (_inventory[5] > 0)
if (_logic->_inventory[5] > 0)
drawIcon(21, 124, 184);
if (_inventory[6] > 0)
if (_logic->_inventory[6] > 0)
drawIcon(201, 42, 178);
if (_inventory[7] > 0)
if (_logic->_inventory[7] > 0)
drawIcon(76, 119, 186);
if (_inventory[8] > 0)
if (_logic->_inventory[8] > 0)
drawIcon(18, 31, 170);
if (_inventory[9] > 0)
if (_logic->_inventory[9] > 0)
drawIcon(57, 88, 185);
if (_inventory[10] > 0)
if (_logic->_inventory[10] > 0)
drawIcon(182, 124, 181);
if (_inventory[11] > 0)
if (_logic->_inventory[11] > 0)
drawIcon(176, 26, 183);
if (_inventory[12] > 0)
if (_logic->_inventory[12] > 0)
drawIcon(54, 23, 171);
if (_inventory[13] > 0)
if (_logic->_inventory[13] > 0)
drawIcon(120, 133, 182);
if (_inventory[14] > 0)
if (_logic->_inventory[14] > 0)
drawIcon(94, 92, 187);
if (_inventory[15] > 0)
if (_logic->_inventory[15] > 0)
drawIcon(135, 67, 176);
if (_inventory[16] > 0)
if (_logic->_inventory[16] > 0)
drawIcon(84, 30, 173);
if (_inventory[17] > 0)
if (_logic->_inventory[17] > 0)
drawIcon(20, 78, 172);
if (_inventory[0] > 0)
drawIcon(158, 117, 134 + _inventory[0]);
if (_logic->_inventory[0] > 0)
drawIcon(158, 117, 134 + _logic->_inventory[0]);
if (_inventory[1] > 0)
drawIcon(94, 67, 134 + _inventory[1]);
if (_logic->_inventory[1] > 0)
drawIcon(94, 67, 134 + _logic->_inventory[1]);
if (_inventory[2] > 0)
drawIcon(193, 105, 134 + _inventory[2]);
if (_logic->_inventory[2] > 0)
drawIcon(193, 105, 134 + _logic->_inventory[2]);
if (_inventory[3] > 0)
drawIcon(131, 39, 134 + _inventory[3]);
if (_logic->_inventory[3] > 0)
drawIcon(131, 39, 134 + _logic->_inventory[3]);
}
Common::String KingdomGame::getSavegameFilename(int slot) {
@ -968,17 +764,9 @@ Common::Error KingdomGame::loadGameState(int slot) {
}
void KingdomGame::synchronize(Common::Serializer &s) {
s.syncAsSint16LE(_statPlay);
s.syncAsSint16LE(_asMap);
s.syncAsSint16LE(_daelonCntr);
s.syncAsSint16LE(_health);
s.syncAsSint16LE(_healthOld);
s.syncAsSint16LE(_lastObstacle);
s.syncAsSint16LE(_nextNode);
s.syncAsSint16LE(_nodeNum);
s.syncAsSint16LE(_pMovie);
s.syncAsSint16LE(_rtnNode);
s.syncAsSint16LE(_robberyNode);
s.syncAsSint16LE(_soundNumber);
s.syncAsSint16LE(_treeEyePic);
s.syncAsSint16LE(_treeEyeSta);
@ -987,32 +775,18 @@ void KingdomGame::synchronize(Common::Serializer &s) {
s.syncAsSint16LE(_oldTLS);
s.syncAsSint16LE(_cTimer);
s.syncAsSint16LE(_skylarTimer);
for (int i = 0; i < 18; i++)
s.syncAsSint16LE(_inventory[i]);
for (int i = 0; i < 99; i++)
s.syncAsSint16LE(_nodes[i]);
s.syncAsByte(_oldEye);
s.syncAsByte(_fstFwd);
s.syncAsByte(_help);
s.syncAsByte(_itemInhibit);
s.syncAsByte(_lastObs);
s.syncAsByte(_lastSound);
s.syncAsByte(_mapEx);
s.syncAsByte(_noMusic);
s.syncAsByte(_oldPouch);
s.syncAsByte(_replay);
s.syncAsByte(_spell1);
s.syncAsByte(_spell2);
s.syncAsByte(_spell3);
s.syncAsByte(_tideCntl);
s.syncAsByte(_wizard);
s.syncAsByte(_tsIconOnly);
s.syncAsByte(_cTimerFlag);
s.syncAsByte(_skylarTimerFlag);
_logic->synchronize(s);
// Present in the original. Looks unused.
// s.syncAsSint16LE(_StatMap);
}
@ -1140,24 +914,24 @@ void KingdomGame::getUserInput() {
if (_quit)
return;
if (_userInput == 2 && _eye)
if (_userInput == 2 && _logic->_eye)
_userInput = _asMode ? 0x43B : 0x43A;
if (_userInput == 1)
_userInput = _mouseValue;
if (_userInput == 0x2F5) {
_statPlay = 600;
_logic->_statPlay = 600;
_loopFlag = true;
}
if (_userInput == 0x42B && _statPlay == 53 && _gameMode == 0) {
_oldStatPlay = _statPlay;
_statPlay = 900;
if (_userInput == 0x42B && _logic->_statPlay == 53 && _gameMode == 0) {
_logic->_oldStatPlay = _logic->_statPlay;
_logic->_statPlay = 900;
_loopFlag = true;
}
if (_userInput == 0x12D && _currMap == 1)
if (_userInput == 0x12D && _logic->_currMap == 1)
// CHECKME: _quitFlag = 2;
_quit = true;
}
@ -1176,13 +950,13 @@ void KingdomGame::drawLocation() {
_aTimer = 0;
_aTimerFlag = false;
int emlValue = _emlTable[_nodeNum];
int emlValue = _emlTable[_logic->_nodeNum];
if (emlValue > 0)
enAll();
_logic->enAll();
if (!_mapEx || !emlValue || _resurrect) {
if (_statPlay != 50)
_resurrect = false;
if (!_mapEx || !emlValue || _logic->_resurrect) {
if (_logic->_statPlay != 50)
_logic->_resurrect = false;
_iconsClosed = false;
} else {
_mapEx = false;
@ -1206,7 +980,7 @@ void KingdomGame::processMap(int mapNum, int zoom) {
if (!_asMode)
switchAtoM();
fShowPic(var6);
_currMap = _zoomTable[mapNum][zoom][1];
_logic->_currMap = _zoomTable[mapNum][zoom][1];
if (zoom > 0)
_treeLeftSta = _zoomTable[mapNum][zoom - 1][0] == 0 ? 0 : 3;
@ -1224,8 +998,8 @@ void KingdomGame::processMapInput(int mapNum) {
case 0x43B:
case 0x443:
switchMtoA();
_mapStat = 0;
_statPlay--;
_logic->_mapStat = 0;
_logic->_statPlay--;
break;
case 0x43F:
if (_treeLeftSta == 3) {
@ -1243,34 +1017,22 @@ void KingdomGame::processMapInput(int mapNum) {
break;
default:
if (_userInput > 0x3FF && _userInput < 0x428) {
_statPlay = _mapExit[_userInput - 0x400];
_logic->_statPlay = _mapExit[_userInput - 0x400];
_mapEx = true;
_loopFlag = true;
switchAS();
_logic->switchAS();
}
if (_userInput > 0x440) {
switchMtoA();
_mapStat = false;
_statPlay--;
_logic->_mapStat = false;
_logic->_statPlay--;
_loopFlag = true;
}
break;
}
}
void KingdomGame::inventoryDel(int item) {
if (_inventory[item] > 0)
_inventory[item]--;
}
void KingdomGame::inventoryAdd(int item) {
if (item >= 4)
_inventory[item] = 1;
else
_inventory[item] = 3;
}
void KingdomGame::drawPic(int reznum) {
eraseCursor();
loadAResource(reznum);
@ -1321,19 +1083,19 @@ void KingdomGame::displayIcon(int reznum) {
void KingdomGame::setATimer() {
_aTimerFlag = true;
_aTimer = 0;
int wrkNodeNum = _nodeNum;
if (_nodes[29] == 1 || _nodes[68] == 1)
int wrkNodeNum = _logic->_nodeNum;
if (_logic->_nodes[29] == 1 || _logic->_nodes[68] == 1)
return;
if (_tsIconOnly)
wrkNodeNum = 79;
if (_nodeNum == 56 && _inventory[8] < 1 && _wizard)
if (_logic->_nodeNum == 56 && _logic->_inventory[8] < 1 && _wizard)
wrkNodeNum = 80;
for (int i = 0; i < 7; i++) {
int idx = _iconActTable[wrkNodeNum][i];
if (_inventory[idx] > 0) {
if (_logic->_inventory[idx] > 0) {
_aTimerFlag = false;
_aTimer = _wizard ? 114 : 133;
playSound(0);
@ -1344,52 +1106,34 @@ void KingdomGame::setATimer() {
}
}
bool KingdomGame::wound() {
bool retval = false;
if (_health == 12 || _health == 8 || _health == 4) {
_health -= 2;
retval = true;
}
return retval;
}
void KingdomGame::refreshSound() {
// No implementation needed in ScummVM
// The only useful check is against _sndReplayTbl, which determines
// which sound should be replayed. But this array contains only false
}
void KingdomGame::increaseHealth() {
if (_health <= 3)
_health = 4;
else if (_health <= 7)
_health = 8;
else
_health = 12;
}
void KingdomGame::checkMainScreen() {
if (_cTimerFlag || _statPlay == 900 || _statPlay == 901)
if (_cTimerFlag || _logic->_statPlay == 900 || _logic->_statPlay == 901)
return;
_cTimerFlag = false;
if (_noIFScreen)
return;
if (_healthOld != _health) {
if (_logic->_healthOld != _logic->_health) {
if (_healthTmr > 0)
_healthTmr--;
else {
if (_health <= _healthOld)
_healthOld--;
if (_logic->_health <= _logic->_healthOld)
_logic->_healthOld--;
else
_healthOld++;
_logic->_healthOld++;
int iconIndex;
if (_healthOld == 0)
if (_logic->_healthOld == 0)
iconIndex = 12 - 1;
else
iconIndex = 12 - _healthOld;
iconIndex = 12 - _logic->_healthOld;
drawIcon(4, 0, iconIndex);
_healthTmr = 1;
@ -1398,7 +1142,7 @@ void KingdomGame::checkMainScreen() {
if (_iconRedraw) {
_iconRedraw = false;
drawIcon(4, 0, 12 - _healthOld);
drawIcon(4, 0, 12 - _logic->_healthOld);
drawIcon(11, 178, _iconPic[0]);
drawIcon(38, 178, _iconPic[1]);
drawIcon(65, 178, _iconPic[2]);
@ -1413,21 +1157,21 @@ void KingdomGame::checkMainScreen() {
_treeHGTimer = 0;
_treeHGUPic = 0;
}
if (_tideCntl)
if (_logic->_tideCntl)
drawPic(178);
}
for (int i = 0; i < 7; i++) {
int wrkNodeNum = _nodeNum;
int wrkNodeNum = _logic->_nodeNum;
if (_tsIconOnly)
wrkNodeNum = 79;
if (_nodeNum == 56 && _inventory[16] < 1 && _wizard)
if (_logic->_nodeNum == 56 && _logic->_inventory[16] < 1 && _wizard)
wrkNodeNum = 80;
if (_nodeNum == 21 && _nodes[21] == 9 && !isDemo())
if (_logic->_nodeNum == 21 && _logic->_nodes[21] == 9 && !isDemo())
wrkNodeNum = 81;
int idx = _iconActTable[wrkNodeNum][i];
if (_inventory[idx] >= 1 && _nodes[29] != 1 && _nodes[68] != 1 && !_itemInhibit && !_iconsClosed) {
if (_logic->_inventory[idx] >= 1 && _logic->_nodes[29] != 1 && _logic->_nodes[68] != 1 && !_itemInhibit && !_iconsClosed) {
if (_iconPic[i] != 12 + idx) {
if (_iconPic[i] == 89 + i)
_iconPic[i] = 96 + i;
@ -1472,7 +1216,7 @@ void KingdomGame::checkMainScreen() {
}
break;
case 2:
if (!_replay) {
if (!_logic->_replay) {
if (_treeLeftPic != 33) {
drawIcon(243, 141, 33);
_treeLeftPic = 33;
@ -1503,7 +1247,7 @@ void KingdomGame::checkMainScreen() {
}
break;
case 1:
if (_help) {
if (_logic->_help) {
if (_treeRightPic != 38) {
drawIcon(290, 143, 38);
_treeRightPic = 38;
@ -1526,7 +1270,7 @@ void KingdomGame::checkMainScreen() {
break;
}
if (_eye) {
if (_logic->_eye) {
if (_treeEyeTimer == 0) {
_treeEyePic = _teaSeq[_treeEyeSta][0];
drawIcon(261, 51, _treeEyePic);
@ -1585,65 +1329,25 @@ void KingdomGame::checkMainScreen() {
_treeHGTimer--;
}
bool KingdomGame::chkDesertObstacles() {
if (!_wizard)
return false;
_nextNode = _nodeNum;
if (_lastObs) {
_lastObs = false;
return false;
}
if (_nodes[29] || _rnd->getRandomNumber(6) == 0) {
if (!_nodes[49] || _robberyNode != _nodeNum) {
if (_lastObstacle != _nodeNum) {
if (_rnd->getRandomNumber(5) == 0) {
_statPlay = 250;
_lastObstacle = _nodeNum;
_lastObs = true;
_loopFlag = true;
return true;
} else {
return false;
}
} else {
return false;
}
} else {
_statPlay = 490;
_loopFlag = true;
return true;
}
} else {
_statPlay = 280;
_robberyNode = _nodeNum;
_lastObstacle = _nodeNum;
_lastObs = true;
_loopFlag = true;
return true;
}
}
void KingdomGame::switchAtoM() {
_asMode = true;
_asMap = _currMap;
_asMap = _logic->_currMap;
saveAS();
_iconSel = 9;
_oldTLS = _treeLeftSta;
_oldTRS = _treeRightSta;
_oldPouch = _pouch;
_oldHelp = _help;
_logic->_oldPouch = _logic->_pouch;
_logic->_oldHelp = _logic->_help;
_oldIconsClosed = _iconsClosed;
_treeLeftSta = 0;
_treeRightSta = 0;
_pouch = false;
_help = false;
_logic->_pouch = false;
_logic->_help = false;
_iconsClosed = true;
}
void KingdomGame::switchMtoA() {
switchAS();
_logic->switchAS();
fadeToBlack1();
drawRect(4, 17, 228, 161, 0);
restoreAS();
@ -1700,7 +1404,7 @@ int KingdomGame::getAKey() {
}
break;
case Common::EVENT_LBUTTONUP: // retval == 2?
if (_eye)
if (_logic->_eye)
retval = !_asMode ? 0x43A : 0x43B;
break;
case Common::EVENT_RBUTTONUP: // retval == 1?
@ -1749,9 +1453,9 @@ void KingdomGame::drawCursor() {
void KingdomGame::cursorType() {
_mouseValue = 0;
if (_currMap != 1 && _statPlay >= 30) {
int var2 = _statPlay == 901 ? 16 : 0;
int var6 = _statPlay == 901 ? 35 : 16;
if (_logic->_currMap != 1 && _logic->_statPlay >= 30) {
int var2 = _logic->_statPlay == 901 ? 16 : 0;
int var6 = _logic->_statPlay == 901 ? 35 : 16;
for (int i = 0; i < var6 + 1; i++) {
if (i == var6) {
int tmpVal = checkMouseMapAS();
@ -1777,7 +1481,7 @@ void KingdomGame::cursorType() {
switch(_mouseValue) {
case 0x18A:
if (_eye)
if (_logic->_eye)
_mouseValue = !_asMode ? 0x43A : 0x43B;
else
_mouseValue = 0;
@ -1789,14 +1493,14 @@ void KingdomGame::cursorType() {
_mouseValue = 0x43F;
else if (_treeLeftSta == 0)
_mouseValue = 0;
else if (_treeLeftSta == 2 && _replay)
else if (_treeLeftSta == 2 && _logic->_replay)
_mouseValue = 0x43E;
else
_mouseValue = 0;
break;
case 0x18D:
if (_treeRightSta == 1)
_mouseValue = _help ? 0x43C : 0;
_mouseValue = _logic->_help ? 0x43C : 0;
if (_treeRightSta == 2)
_mouseValue = 0x440;
break;
@ -1805,15 +1509,15 @@ void KingdomGame::cursorType() {
// No more check in ScummVM, we display the load screen
break;
case 0x407:
if (_statPlay == 182 && _nodes[18] < 9)
if (_logic->_statPlay == 182 && _logic->_nodes[18] < 9)
_mouseValue = 0;
break;
case 0x40D:
if (_nodes[29] == 1)
if (_logic->_nodes[29] == 1)
_mouseValue = 0;
break;
case 0x41F:
if (_nodes[32] == 0)
if (_logic->_nodes[32] == 0)
_mouseValue = 0;
break;
case 0x422:
@ -1822,27 +1526,27 @@ void KingdomGame::cursorType() {
_mouseValue = 0;
break;
case 0x428:
if (_nodeNum == 5 && _gameMode != 2 && _spell1)
if (_logic->_nodeNum == 5 && _gameMode != 2 && _logic->_spell1)
_mouseValue = 0;
break;
case 0x42A:
if (_nodeNum == 5 && _gameMode != 2 && _spell2)
if (_logic->_nodeNum == 5 && _gameMode != 2 && _logic->_spell2)
_mouseValue = 0;
break;
case 0x42B:
if (_nodeNum == 5 && _gameMode != 2 && _spell3)
if (_logic->_nodeNum == 5 && _gameMode != 2 && _logic->_spell3)
_mouseValue = 0;
break;
case 0x445:
if (_statPlay == 161 && _nodes[16] == 0 && _wizard)
if (_logic->_statPlay == 161 && _logic->_nodes[16] == 0 && _wizard)
_mouseValue = 0x450;
break;
case 0x44F:
if (!_pouch)
if (!_logic->_pouch)
_mouseValue = 0;
break;
case 0x457:
if (!_tideCntl)
if (!_logic->_tideCntl)
_mouseValue = 0;
break;
}
@ -1850,13 +1554,13 @@ void KingdomGame::cursorType() {
_iconSelect = 9;
for (int var6 = 0; var6 < 8; var6++) {
if (_mouseValue == 181 + var6) {
int var2 = _nodeNum;
int var2 = _logic->_nodeNum;
if (_tsIconOnly)
var2 = 79;
if (_nodeNum == 56 && _inventory[8] < 1 && _wizard)
if (_logic->_nodeNum == 56 && _logic->_inventory[8] < 1 && _wizard)
var2 = 80;
int indx = _iconActTable[var2][var6];
if (_inventory[indx] != 0 && _nodes[29] != 1 && _nodes[68] != 1 && !_iconsClosed && !_itemInhibit) {
if (_logic->_inventory[indx] != 0 && _logic->_nodes[29] != 1 && _logic->_nodes[68] != 1 && !_iconsClosed && !_itemInhibit) {
_mouseValue = indx + 0x428;
_iconSelect = var6;
break;
@ -1865,9 +1569,9 @@ void KingdomGame::cursorType() {
}
}
if (_currMap == 11) {
if (_logic->_currMap == 11) {
if (_mouseValue > 0x427 && _mouseValue < 0x43A) {
if (_inventory[_mouseValue - 0x428] < 1)
if (_logic->_inventory[_mouseValue - 0x428] < 1)
_mouseValue = 0x241;
}
}
@ -1883,11 +1587,11 @@ void KingdomGame::cursorTypeExit() {
int KingdomGame::checkMouseMapAS() {
for (int i = 0; i < 16; i++) {
if (_cursorX >= _mouseMapAS[_currMap][i]._minX && _cursorX < _mouseMapAS[_currMap][i]._maxX
&& _cursorY >= _mouseMapAS[_currMap][i]._minY && _cursorY < _mouseMapAS[_currMap][i]._maxY)
return _mouseMapAS[_currMap][i]._mouseValue;
if (_cursorX >= _mouseMapAS[_logic->_currMap][i]._minX && _cursorX < _mouseMapAS[_logic->_currMap][i]._maxX
&& _cursorY >= _mouseMapAS[_logic->_currMap][i]._minY && _cursorY < _mouseMapAS[_logic->_currMap][i]._maxY)
return _mouseMapAS[_logic->_currMap][i]._mouseValue;
}
if (_currMap == 11) {
if (_logic->_currMap == 11) {
for (int i = 0; i < 16; i++) {
if (_cursorX >= _mouseMapAS[12][i]._minX && _cursorX < _mouseMapAS[12][i]._maxX
&& _cursorY >= _mouseMapAS[12][i]._minY && _cursorY < _mouseMapAS[12][i]._maxY)

View File

@ -51,6 +51,7 @@
#include "common/serializer.h"
#include "kingdom/console.h"
#include "kingdom/logic.h"
namespace Kingdom {
enum KingdomDebugChannels {
@ -108,14 +109,15 @@ namespace Kingdom {
private:
Console *_console;
Common::RandomSource *_rnd;
Logic *_logic;
KingArtEntry *_kingartEntries;
public:
Common::RandomSource *_rnd;
bool _loopFlag;
int _gameMode;
int _statPlay;
int _oldStatPlay;
bool _fstFwd;
bool _noIFScreen;
bool _sound;
@ -123,9 +125,6 @@ namespace Kingdom {
bool _fullScreen;
int _frameStop;
int _daelonCntr;
bool _spell1;
bool _spell2;
bool _spell3;
bool _itemInhibit;
bool _asMode;
bool _aTimerFlag;
@ -136,10 +135,7 @@ namespace Kingdom {
int _bTimer;
int _cTimer;
int _skylarTimer;
bool _tideCntl;
bool _mapEx;
int _health;
int _healthOld;
int _healthTmr;
int _treeEyeTimer;
int _treeEyePic;
@ -152,37 +148,21 @@ namespace Kingdom {
int _treeRightSta;
int _treeHGSta;
bool _tsIconOnly;
bool _lastObs;
bool _pouch;
bool _noMusic; // TODO: Synchronize this flag with the launcher
byte *_asPtr;
int _asMap;
int _currMap;
int _oldTLS;
int _oldTRS;
int _treeLeftSta;
bool _iconsClosed;
bool _oldIconsClosed;
bool _oldEye;
bool _eye;
bool _oldHelp;
bool _help;
bool _oldPouch;
int _pMovie;
bool _keyActive;
bool _iconRedraw;
bool _replay;
bool _quit;
int _nodeNum;
int _oldNode; // CHECKME: Useless? If so, to be removed
int _nextNode;
int _robberyNode;
bool _cursorDrawn; // CHECKME: Useless
bool _wizard;
int _zoom;
bool _resurrect;
int _lastObstacle;
int _mapStat; // CHECKME: Useless? If so, to be removed
int _mouseValue;
int _cursorDef; // TODO: Could be removed by using the return value of CursorTypeExit()
int _oldCursorDef; // CHECKME: Unused in our implementation?
@ -193,18 +173,14 @@ namespace Kingdom {
int _iconSel;
int _iconSelect;
bool _mouseDebound;
int _rtnNode;
int _soundNumber;
bool _palStepFlag;
Audio::SoundHandle _soundHandle;
int _tickCount;
uint32 _oldTime;
int16 _nodes[99];
Common::SeekableReadStream *_rezPointers[510];
int _rezSize[510];
int _inventory[19];
int _iconPic[7];
uint16 _userInput;
uint16 _mouseButton;
@ -217,15 +193,6 @@ namespace Kingdom {
void initHelp();
void fadeToBlack1();
void fadeToBlack2();
void gameHelp();
void GPLogic1();
void GPLogic1_SubSP10();
void GPLogic1_SubSP121();
void GPLogic2();
void GPLogic2_SubSP361();
void GPLogic3();
void GPLogic4();
void GPLogic4_SP901();
void loadAResource(int reznum);
void releaseAResource(int reznum);
void showPic(int reznum);
@ -236,14 +203,11 @@ namespace Kingdom {
void readMouse();
void initMPlayer();
void playMovie(int movieNum);
void enAll(); // TODO: Rename later as enableAll
void dsAll(); // TODO: Rename later as disableAll
void saveAS(); // TODO: Rename later as saveVideoBackground
void restoreAS(); // TODO: Rename later as restoreVideoBackground
void drawHelpScreen();
void drawRect(uint minX, uint minY, uint maxX, uint maxY, int color);
void drawInventory();
void gameHelp_Sub43C();
void playSound(int idx);
void eraseCursor();
void getUserInput();
@ -251,17 +215,11 @@ namespace Kingdom {
void drawLocation();
void processMap(int mapNum, int zoom);
void processMapInput(int mapNum);
void inventoryDel(int item);
void inventoryAdd(int item);
void drawPic(int reznum);
void displayIcon(int reznum);
void setATimer();
bool wound();
void refreshSound();
void switchAS();
void increaseHealth();
void checkMainScreen();
bool chkDesertObstacles();
void switchAtoM();
void switchMtoA();
void drawIcon(int x, int y, int index);
@ -273,7 +231,6 @@ namespace Kingdom {
int getAKey();
int checkMouseMapAS();
void cursorTypeExit();
void endCredits();
void saveGame();
void restoreGame();
virtual Common::Error loadGameState(int slot);

380
engines/kingdom/logic.cpp Normal file
View File

@ -0,0 +1,380 @@
/* 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 "kingdom/kingdom.h"
#include "kingdom/logic.h"
namespace Kingdom {
Logic::Logic(KingdomGame* vm) : _vm(vm) {
}
void Logic::initVariables() {
_healthOld = 0;
_health = 0;
_tideCntl = 0;
_statPlay = 0;
_spell3 = 0;
_spell2 = 0;
_spell1 = 0;
_robberyNode = 0;
_rtnNode = 0;
_replay = false;
_resurrect = false;
_pouch = false;
_oldPouch = false;
_oldHelp = false;
_oldEye = false;
_oldStatPlay = 0;
_oldNode = 0;
_nodeNum = 0;
_nextNode = 0;
_mapStat = 0;
_lastObs = 0;
_lastObstacle = 0;
_help = false;
_eye = false;
for (int i = 0; i < 99; i++)
_nodes[i] = 0;
_currMap = 0;
}
void Logic::initPlay() {
memset(_inventory, 0xFF, 19);
for (int i = 0; i < 99; i++)
_nodes[i] = 0;
_statPlay = 10;
_spell1 = false;
_spell2 = false;
_spell3 = false;
_tideCntl = false;
_health = 12;
_healthOld = 1;
_lastObs = false;
enAll();
_pouch = true;
}
void Logic::enAll() {
_help = true;
_eye = true;
_replay = true;
_pouch = true;
_fstFwd = true;
}
void Logic::dsAll() {
_help = false;
_eye = false;
_replay = false;
_pouch = false;
_fstFwd = false;
}
void Logic::inventoryDel(int item) {
if (_inventory[item] > 0)
_inventory[item]--;
}
void Logic::inventoryAdd(int item) {
if (item >= 4)
_inventory[item] = 1;
else
_inventory[item] = 3;
}
bool Logic::wound() {
bool retval = false;
if (_health == 12 || _health == 8 || _health == 4) {
_health -= 2;
retval = true;
}
return retval;
}
bool Logic::chkDesertObstacles() {
if (!_vm->_wizard)
return false;
_nextNode = _nodeNum;
if (_lastObs) {
_lastObs = false;
return false;
}
if (_nodes[29] || _vm->_rnd->getRandomNumber(6) == 0) {
if (!_nodes[49] || _robberyNode != _nodeNum) {
if (_lastObstacle != _nodeNum) {
if (_vm->_rnd->getRandomNumber(5) == 0) {
_statPlay = 250;
_lastObstacle = _nodeNum;
_lastObs = true;
_vm->_loopFlag = true;
return true;
} else {
return false;
}
} else {
return false;
}
} else {
_statPlay = 490;
_vm->_loopFlag = true;
return true;
}
} else {
_statPlay = 280;
_robberyNode = _nodeNum;
_lastObstacle = _nodeNum;
_lastObs = true;
_vm->_loopFlag = true;
return true;
}
}
void Logic::increaseHealth() {
if (_health <= 3)
_health = 4;
else if (_health <= 7)
_health = 8;
else
_health = 12;
}
void Logic::endCredits() {
_nodeNum = 0;
_vm->_bTimer = 190;
_vm->readMouse();
while(_vm->_bTimer != 0 && _vm->_mouseButton == 0) {
_vm->checkTimers();
_vm->refreshSound();
_vm->checkMainScreen();
_vm->readMouse();
}
_vm->fadeToBlack1();
_vm->drawRect(4, 17, 228, 161, 0);
_vm->playSound(0);
dsAll();
_vm->_iconsClosed = true;
_vm->playMovie(199);
dsAll();
_vm->playMovie(205);
dsAll();
_vm->fadeToBlack1();
_vm->drawRect(4, 17, 228, 161, 0);
_vm->playMovie(201);
_vm->fShowPic(125);
_currMap = 3;
dsAll();
_pouch = false;
memset(_inventory, 0xFF, 19);
_statPlay = 994;
_vm->_loopFlag = true;
}
void Logic::gameHelp_Sub43C() {
_vm->fadeToBlack1();
_currMap = _vm->_asMap;
_vm->drawRect(4, 17, 228, 161, 0);
_vm->restoreAS();
_vm->_userInput = 0;
_vm->_gameMode = 0;
_vm->_iconsClosed = false;
_vm->_treeLeftSta = _vm->_oldTLS;
_eye = _oldEye;
_help = _oldHelp;
_pouch = _oldPouch;
}
void Logic::gameHelp() {
if (!_vm->_gameMode) {
if (_vm->_userInput == 0x43C) {
_vm->saveAS();
_vm->_asMap = _currMap;
_currMap = 0;
_vm->fadeToBlack1();
_vm->drawRect(4, 17, 228, 161, 0);
_vm->drawHelpScreen();
_vm->_gameMode = 1;
_vm->_oldTLS = _vm->_treeLeftSta;
_vm->_treeLeftSta = 0;
_vm->_iconsClosed = true;
_oldEye = _eye;
_eye = false;
_oldHelp = _help;
_oldPouch = _pouch;
_pouch = false;
_vm->_userInput = 0;
}
if (_vm->_userInput == 0x44F) {
_vm->saveAS();
_vm->_asMap = _currMap;
_vm->_gameMode = 2;
_vm->_oldTLS = _vm->_treeLeftSta;
_vm->_treeLeftSta = 0;
_vm->_iconsClosed = true;
_oldEye = _eye;
_eye = false;
_oldHelp = _help;
_help = false;
_oldPouch = _pouch;
_vm->fadeToBlack1();
_vm->drawRect(4, 17, 228, 161, 0);
_vm->drawInventory();
if (_nodes[68] == 1 || _nodes[29] == 1 || _vm->_itemInhibit)
_currMap = 10;
else
_currMap = 11;
_vm->_userInput = 0;
}
}
if (_vm->_gameMode == 0)
return;
switch(_vm->_userInput) {
case 0x240:
_vm->fadeToBlack2();
//TODO: Set _quitFlag to 1
break;
case 0x241:
gameHelp_Sub43C();
return;
break;
case 0x242:
if (_vm->_noMusic) {
_vm->_noMusic = false;
_vm->playSound(1);
} else {
_vm->_noMusic = true;
_vm->playSound(0);
}
_vm->drawHelpScreen();
break;
case 0x243: {
_vm->fadeToBlack2();
_vm->_keyActive = false;
_vm->_noIFScreen = true;
_vm->playSound(0);
// The demo isn't saving pMovie.
// It's obviously a bug and this behavior wasn't kept in ScummVM
int oldPMovie = _vm->_pMovie;
while(!_vm->_keyActive) {
_vm->playMovie(54);
_vm->fadeToBlack2();
}
_vm->_pMovie = oldPMovie;
_vm->_noIFScreen = false;
_vm->showPic(106);
_vm->drawHelpScreen();
_vm->_iconRedraw = true;
_vm->playSound(1);
}
break;
case 0x244:
//TODO: Set _quitFlag to 2
_vm->_quit = true;
break;
case 0x245: {
_vm->fadeToBlack1();
// The demo isn't saving pMovie.
// It's obviously a bug and this behavior wasn't kept in ScummVM
int oldPMovie = _vm->_pMovie;
_vm->drawRect(4, 17, 228, 161, 0);
_vm->playMovie(205);
_vm->fadeToBlack1();
_vm->drawRect(4, 17, 228, 161, 0);
_vm->playMovie(199);
_vm->fadeToBlack1();
_vm->drawRect(4, 17, 228, 161, 0);
_vm->drawHelpScreen();
_vm->_pMovie = oldPMovie;
}
break;
case 0x246:
_vm->saveGame();
break;
case 0x43B:
case 0x43C:
case 0x44F:
gameHelp_Sub43C();
return;
}
if (_vm->_userInput > 0x427 && _vm->_userInput < 0x43A)
_vm->fShowPic(130 + _vm->_userInput - 0x428);
if (_vm->_userInput == 0x260) {
_vm->drawInventory();
if (_nodes[68] == 1 || _nodes[29] == 1)
_currMap = 10;
else
_currMap = 11;
_vm->_userInput = 0;
}
}
void Logic::switchAS() {
_vm->_asMode = false;
_currMap = _vm->_asMap;
_vm->_treeLeftSta = _vm->_oldTLS;
_vm->_treeRightSta = _vm->_oldTRS;
_pouch = _oldPouch;
_help = _oldHelp;
_vm->_iconsClosed = _vm->_oldIconsClosed;
}
void Logic::synchronize(Common::Serializer &s) {
s.syncAsSint16LE(_statPlay);
s.syncAsSint16LE(_health);
s.syncAsSint16LE(_healthOld);
s.syncAsSint16LE(_lastObstacle);
s.syncAsSint16LE(_nextNode);
s.syncAsSint16LE(_nodeNum);
s.syncAsSint16LE(_rtnNode);
s.syncAsSint16LE(_robberyNode);
for (int i = 0; i < 18; i++)
s.syncAsSint16LE(_inventory[i]);
for (int i = 0; i < 99; i++)
s.syncAsSint16LE(_nodes[i]);
s.syncAsByte(_oldEye);
s.syncAsByte(_fstFwd);
s.syncAsByte(_help);
s.syncAsByte(_lastObs);
s.syncAsByte(_oldPouch);
s.syncAsByte(_replay);
s.syncAsByte(_spell1);
s.syncAsByte(_spell2);
s.syncAsByte(_spell3);
s.syncAsByte(_tideCntl);
}
} // NameSpace

97
engines/kingdom/logic.h Normal file
View File

@ -0,0 +1,97 @@
/* 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.
*
*/
#ifndef KINGDOM_LOGIC_H
#define KINGDOM_LOGIC_H
#include "gui/debugger.h"
namespace Kingdom {
class KingdomGame;
class Logic {
private:
KingdomGame *_vm;
public:
int _statPlay;
int _oldStatPlay;
int _nodeNum;
int _oldNode; // CHECKME: Useless? If so, to be removed
int _nextNode;
int _robberyNode;
int16 _nodes[99];
int _currMap;
bool _oldEye;
bool _eye;
bool _oldHelp;
bool _help;
int _lastObstacle;
bool _lastObs;
int _inventory[19];
bool _replay;
bool _pouch;
bool _oldPouch;
bool _resurrect;
bool _tideCntl;
int _rtnNode;
int _health;
int _healthOld;
bool _fstFwd;
bool _spell1;
bool _spell2;
bool _spell3;
int _mapStat; // CHECKME: Useless? If so, to be removed
void enAll(); // TODO: Rename later as enableAll
void dsAll(); // TODO: Rename later as disableAll
bool wound();
void GPLogic1_SubSP10();
void GPLogic1_SubSP121();
void GPLogic2_SubSP361();
void GPLogic4_SP901();
bool chkDesertObstacles();
void increaseHealth();
void endCredits();
void gameHelp_Sub43C();
public:
explicit Logic(Kingdom::KingdomGame *vm);
virtual ~Logic(void) {}
void GPLogic1();
void GPLogic2();
void GPLogic3();
void GPLogic4();
void gameHelp();
void inventoryDel(int item);
void inventoryAdd(int item);
void initVariables();
void initPlay();
void switchAS();
void synchronize(Common::Serializer &s);
};
}
#endif

View File

@ -7,6 +7,7 @@ MODULE_OBJS = \
GPLogic2.o \
GPLogic3.o \
GPLogic4.o \
logic.o \
console.o \
detection.o