diff options
author | Eugene Sandulenko | 2019-07-10 23:02:25 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2019-09-03 17:17:17 +0200 |
commit | e7016e52a9be6b07a4cb3dcca1e8c875078a2bb1 (patch) | |
tree | 1c4e9768cd3f0624d2b468ba2e777a5ca19160ef /engines/hdb | |
parent | 93155c6433ef7dd3c0f9752b161b2b53b3e72115 (diff) | |
download | scummvm-rg350-e7016e52a9be6b07a4cb3dcca1e8c875078a2bb1.tar.gz scummvm-rg350-e7016e52a9be6b07a4cb3dcca1e8c875078a2bb1.tar.bz2 scummvm-rg350-e7016e52a9be6b07a4cb3dcca1e8c875078a2bb1.zip |
HDB: Refarcot entity save/loading into separate methods
Diffstat (limited to 'engines/hdb')
-rw-r--r-- | engines/hdb/ai-init.cpp | 327 | ||||
-rw-r--r-- | engines/hdb/ai.h | 3 | ||||
-rw-r--r-- | engines/hdb/saveload.cpp | 154 |
3 files changed, 167 insertions, 317 deletions
diff --git a/engines/hdb/ai-init.cpp b/engines/hdb/ai-init.cpp index 7b9a823636..66e78f1f97 100644 --- a/engines/hdb/ai-init.cpp +++ b/engines/hdb/ai-init.cpp @@ -1235,7 +1235,7 @@ void AI::restartSystem() { } void AI::save(Common::OutSaveFile *out) { - int i, j; + int i; // Misc Variables out->writeByte(_playerInvisible); @@ -1401,202 +1401,22 @@ void AI::save(Common::OutSaveFile *out) { out->write(_triggerList->operator[](i)->luaFuncUse, 32); } - AIEntity *e, temp; - char funcString[32]; - const char *lookUp; + AIEntity *e; // Save Floats out->writeUint32LE(_floats->size()); for (i = 0; (uint)i < _floats->size(); i++) { e = _floats->operator[](i); - memcpy(&temp, e, sizeof(AIEntity)); - - // Write out 32-char names for the function ptrs we have in the entity struct - lookUp = funcLookUp(e->aiAction); - memset(&funcString, 0, 32); - if (!lookUp && e->aiAction) - error("AI::save: No matching ACTION function for func-string"); - if (lookUp) - strcpy(funcString, lookUp); - out->write(funcString, 32); - - lookUp = funcLookUp(e->aiUse); - memset(&funcString, 0, 32); - if (!lookUp && e->aiUse) - error("AI::save: No matching USE function for func-string"); - if (lookUp) - strcpy(funcString, lookUp); - out->write(funcString, 32); - - lookUp = funcLookUp(e->aiInit); - memset(&funcString, 0, 32); - if (!lookUp && e->aiInit) - error("AI::save: No matching INIT function for func-string"); - if (lookUp) - strcpy(funcString, lookUp); - out->write(funcString, 32); - - lookUp = funcLookUp(e->aiInit2); - memset(&funcString, 0, 32); - if (!lookUp && e->aiInit2) - error("AI::save: No matching INIT2 function for func-string"); - if (lookUp) - strcpy(funcString, lookUp); - out->write(funcString, 32); - - lookUp = funcLookUp((FuncPtr)e->aiDraw); - memset(&funcString, 0, 32); - if (!lookUp && e->aiDraw) - error("AI::save: No matching DRAW function for func-string"); - if (lookUp) - strcpy(funcString, lookUp); - out->write(funcString, 32); - - // Clear out all ptrs in Entity before writing it out - for (j = 0; j < kMaxAnimFrames; j++) - temp.blinkGfx[j] = temp.movedownGfx[j] = temp.moveupGfx[j] = temp.moveleftGfx[j] = - temp.moverightGfx[j] = temp.standdownGfx[j] = temp.standupGfx[j] = temp.standleftGfx[j] = - temp.standrightGfx[j] = temp.special1Gfx[j] = NULL; - - temp.blinkFrames = temp.movedownFrames = temp.moveupFrames = temp.moveleftFrames = - temp.moverightFrames = temp.standdownFrames = temp.standupFrames = temp.standleftFrames = - temp.standrightFrames = temp.special1Frames = 0; - - temp.draw = NULL; - temp.aiDraw = NULL; - temp.aiAction = temp.aiInit = temp.aiUse = NULL; - - // Save AIEntity - out->writeSint32LE((int)temp.type); - out->writeSint32LE((int)temp.state); - out->writeSint32LE((int)temp.dir); - out->write(temp.luaFuncInit, 32); - out->write(temp.luaFuncAction, 32); - out->write(temp.luaFuncUse, 32); - out->writeUint16LE(temp.level); - out->writeUint16LE(temp.value1); - out->writeUint16LE(temp.value2); - out->writeSint32LE((int)temp.dir2); - out->writeUint16LE(temp.x); - out->writeUint16LE(temp.y); - out->writeSint16LE(temp.drawXOff); - out->writeSint16LE(temp.drawYOff); - out->writeUint16LE(temp.onScreen); - out->writeUint16LE(temp.moveSpeed); - out->writeSint16LE(temp.xVel); - out->writeSint16LE(temp.yVel); - out->writeUint16LE(temp.tileX); - out->writeUint16LE(temp.tileY); - out->writeUint16LE(temp.goalX); - out->writeUint16LE(temp.goalY); - out->writeUint16LE(temp.touchpX); - out->writeUint16LE(temp.touchpY); - out->writeUint16LE(temp.touchpTile); - out->writeUint16LE(temp.touchpWait); - out->writeUint16LE(temp.stunnedWait); - out->writeSint16LE(temp.sequence); - out->write(temp.entityName, 32); - out->write(temp.printedName, 32); - out->writeUint16LE(temp.animFrame); - out->writeUint16LE(temp.animDelay); - out->writeUint16LE(temp.animCycle); + + e->save(out); } // Save Ents out->writeUint32LE(_ents->size()); for (i = 0; (uint)i < _ents->size(); i++) { e = _ents->operator[](i); - memcpy(&temp, e, sizeof(AIEntity)); - - // Write out 32-char names for the function ptrs we have in the entity struct - lookUp = funcLookUp(e->aiAction); - memset(&funcString, 0, 32); - if (!lookUp && e->aiAction) - error("AI::save: No matching ACTION function for func-string"); - if (lookUp) - strcpy(funcString, lookUp); - out->write(funcString, 32); - - lookUp = funcLookUp(e->aiUse); - memset(&funcString, 0, 32); - if (!lookUp && e->aiUse) - error("AI::save: No matching USE function for func-string"); - if (lookUp) - strcpy(funcString, lookUp); - out->write(funcString, 32); - - lookUp = funcLookUp(e->aiInit); - memset(&funcString, 0, 32); - if (!lookUp && e->aiInit) - error("AI::save: No matching INIT function for func-string"); - if (lookUp) - strcpy(funcString, lookUp); - out->write(funcString, 32); - - lookUp = funcLookUp(e->aiInit2); - memset(&funcString, 0, 32); - if (!lookUp && e->aiInit2) - error("AI::save: No matching INIT2 function for func-string"); - if (lookUp) - strcpy(funcString, lookUp); - out->write(funcString, 32); - - lookUp = funcLookUp((FuncPtr)e->aiDraw); - memset(&funcString, 0, 32); - if (!lookUp && e->aiDraw) - error("AI::save: No matching DRAW function for func-string"); - if (lookUp) - strcpy(funcString, lookUp); - out->write(funcString, 32); - - // Clear out all ptrs in Entity before writing it out - for (j = 0; j < kMaxAnimFrames; j++) - temp.blinkGfx[j] = temp.movedownGfx[j] = temp.moveupGfx[j] = temp.moveleftGfx[j] = - temp.moverightGfx[j] = temp.standdownGfx[j] = temp.standupGfx[j] = temp.standleftGfx[j] = - temp.standrightGfx[j] = temp.special1Gfx[j] = NULL; - - temp.blinkFrames = temp.movedownFrames = temp.moveupFrames = temp.moveleftFrames = - temp.moverightFrames = temp.standdownFrames = temp.standupFrames = temp.standleftFrames = - temp.standrightFrames = temp.special1Frames = 0; - - temp.draw = NULL; - temp.aiDraw = NULL; - temp.aiAction = temp.aiInit = temp.aiUse = NULL; - - // Save AIEntity - out->writeSint32LE((int)temp.type); - out->writeSint32LE((int)temp.state); - out->writeSint32LE((int)temp.dir); - out->write(temp.luaFuncInit, 32); - out->write(temp.luaFuncAction, 32); - out->write(temp.luaFuncUse, 32); - out->writeUint16LE(temp.level); - out->writeUint16LE(temp.value1); - out->writeUint16LE(temp.value2); - out->writeSint32LE((int)temp.dir2); - out->writeUint16LE(temp.x); - out->writeUint16LE(temp.y); - out->writeSint16LE(temp.drawXOff); - out->writeSint16LE(temp.drawYOff); - out->writeUint16LE(temp.onScreen); - out->writeUint16LE(temp.moveSpeed); - out->writeSint16LE(temp.xVel); - out->writeSint16LE(temp.yVel); - out->writeUint16LE(temp.tileX); - out->writeUint16LE(temp.tileY); - out->writeUint16LE(temp.goalX); - out->writeUint16LE(temp.goalY); - out->writeUint16LE(temp.touchpX); - out->writeUint16LE(temp.touchpY); - out->writeUint16LE(temp.touchpTile); - out->writeUint16LE(temp.touchpWait); - out->writeUint16LE(temp.stunnedWait); - out->writeSint16LE(temp.sequence); - out->write(temp.entityName, 32); - out->write(temp.printedName, 32); - out->writeUint16LE(temp.animFrame); - out->writeUint16LE(temp.animDelay); - out->writeUint16LE(temp.animCycle); + + e->save(out); } } @@ -1818,78 +1638,13 @@ void AI::loadSaveFile(Common::InSaveFile *in) { } AIEntity *e; - char funcString[32]; - FuncPtr init, init2, use, action; - EntFuncPtr draw; // Load Floats uint32 fsize = in->readUint32LE(); for (i = 0; (uint)i < fsize; i++) { e = new AIEntity; - action = init = init2 = use = NULL; - draw = NULL; - - // Read 32-char names for the function ptrs we have in entity struct - in->read(funcString, 32); - if (funcString[0]) - action = funcLookUp(funcString); - - in->read(funcString, 32); - if (funcString[0]) - use = funcLookUp(funcString); - - in->read(funcString, 32); - if (funcString[0]) - init = funcLookUp(funcString); - - in->read(funcString, 32); - if (funcString[0]) - init2 = funcLookUp(funcString); - - in->read(funcString, 32); - if (funcString[0]) - draw = (EntFuncPtr)funcLookUp(funcString); - - // Load AIEntity - e->type = (AIType)in->readSint32LE(); - e->state = (AIState)in->readSint32LE(); - e->dir = (AIDir)in->readSint32LE(); - in->read(e->luaFuncInit, 32); - in->read(e->luaFuncAction, 32); - in->read(e->luaFuncUse, 32); - e->level = in->readUint16LE(); - e->value1 = in->readUint16LE(); - e->value2 = in->readUint16LE(); - e->dir2 = (AIDir)in->readSint32LE(); - e->x = in->readUint16LE(); - e->y = in->readUint16LE(); - e->drawXOff = in->readSint16LE(); - e->drawYOff = in->readSint16LE(); - e->onScreen = in->readUint16LE(); - e->moveSpeed = in->readUint16LE(); - e->xVel = in->readSint16LE(); - e->yVel = in->readSint16LE(); - e->tileX = in->readUint16LE(); - e->tileY = in->readUint16LE(); - e->goalX = in->readUint16LE(); - e->goalY = in->readUint16LE(); - e->touchpX = in->readUint16LE(); - e->touchpY = in->readUint16LE(); - e->touchpTile = in->readUint16LE(); - e->touchpWait = in->readUint16LE(); - e->stunnedWait = in->readUint16LE(); - e->sequence = in->readSint16LE(); - in->read(e->entityName, 32); - in->read(e->printedName, 32); - e->animFrame = in->readUint16LE(); - e->animDelay = in->readUint16LE(); - e->animCycle = in->readUint16LE(); - - e->aiAction = action; - e->aiInit = init; - e->aiInit2 = init2; - e->aiUse = use; - e->aiDraw = draw; + + e->load(in); // Cache All Entity Graphics cacheEntGfx(e, false); @@ -1902,70 +1657,8 @@ void AI::loadSaveFile(Common::InSaveFile *in) { uint32 esize = in->readUint32LE(); for (i = 0; (uint)i < esize; i++) { e = new AIEntity; - action = init = init2 = use = NULL; - draw = NULL; - - // Read 32-char names for the function ptrs we have in entity struct - in->read(funcString, 32); - if (funcString[0]) - action = funcLookUp(funcString); - - in->read(funcString, 32); - if (funcString[0]) - use = funcLookUp(funcString); - - in->read(funcString, 32); - if (funcString[0]) - init = funcLookUp(funcString); - - in->read(funcString, 32); - if (funcString[0]) - init2 = funcLookUp(funcString); - - in->read(funcString, 32); - if (funcString[0]) - draw = (EntFuncPtr)funcLookUp(funcString); - - // Load AIEntity - e->type = (AIType)in->readSint32LE(); - e->state = (AIState)in->readSint32LE(); - e->dir = (AIDir)in->readSint32LE(); - in->read(e->luaFuncInit, 32); - in->read(e->luaFuncAction, 32); - in->read(e->luaFuncUse, 32); - e->level = in->readUint16LE(); - e->value1 = in->readUint16LE(); - e->value2 = in->readUint16LE(); - e->dir2 = (AIDir)in->readSint32LE(); - e->x = in->readUint16LE(); - e->y = in->readUint16LE(); - e->drawXOff = in->readSint16LE(); - e->drawYOff = in->readSint16LE(); - e->onScreen = in->readUint16LE(); - e->moveSpeed = in->readUint16LE(); - e->xVel = in->readSint16LE(); - e->yVel = in->readSint16LE(); - e->tileX = in->readUint16LE(); - e->tileY = in->readUint16LE(); - e->goalX = in->readUint16LE(); - e->goalY = in->readUint16LE(); - e->touchpX = in->readUint16LE(); - e->touchpY = in->readUint16LE(); - e->touchpTile = in->readUint16LE(); - e->touchpWait = in->readUint16LE(); - e->stunnedWait = in->readUint16LE(); - e->sequence = in->readSint16LE(); - in->read(e->entityName, 32); - in->read(e->printedName, 32); - e->animFrame = in->readUint16LE(); - e->animDelay = in->readUint16LE(); - e->animCycle = in->readUint16LE(); - - e->aiAction = action; - e->aiInit = init; - e->aiInit2 = init2; - e->aiUse = use; - e->aiDraw = draw; + + e->load(in); // Cache All Entity Graphics cacheEntGfx(e, false); diff --git a/engines/hdb/ai.h b/engines/hdb/ai.h index 3cb0cc0610..2e213ce430 100644 --- a/engines/hdb/ai.h +++ b/engines/hdb/ai.h @@ -539,6 +539,9 @@ struct AIEntity { moverightGfx[i] = new Tile; } } + + void save(Common::OutSaveFile *out); + void load(Common::InSaveFile *in); }; // Structs for Function Table Lookup for SaveGames diff --git a/engines/hdb/saveload.cpp b/engines/hdb/saveload.cpp index 6bd212b140..9c8186d358 100644 --- a/engines/hdb/saveload.cpp +++ b/engines/hdb/saveload.cpp @@ -187,4 +187,158 @@ void HDBGame::loadSaveFile(Common::InSaveFile *in) { in->read(_inMapName, 32); } +void AIEntity::save(Common::OutSaveFile *out) { + char funcString[32]; + const char *lookUp; + + + // Write out 32-char names for the function ptrs we have in the entity struct + lookUp = g_hdb->_ai->funcLookUp(aiAction); + memset(&funcString, 0, 32); + if (!lookUp && aiAction) + error("AIEntity::save: No matching ACTION function for func-string"); + if (lookUp) + strcpy(funcString, lookUp); + out->write(funcString, 32); + + lookUp = g_hdb->_ai->funcLookUp(aiUse); + memset(&funcString, 0, 32); + if (!lookUp && aiUse) + error("AIEntity::save: No matching USE function for func-string"); + if (lookUp) + strcpy(funcString, lookUp); + out->write(funcString, 32); + + lookUp = g_hdb->_ai->funcLookUp(aiInit); + memset(&funcString, 0, 32); + if (!lookUp && aiInit) + error("AIEntity::save: No matching INIT function for func-string"); + if (lookUp) + strcpy(funcString, lookUp); + out->write(funcString, 32); + + lookUp = g_hdb->_ai->funcLookUp(aiInit2); + memset(&funcString, 0, 32); + if (!lookUp && aiInit2) + error("AIEntity::save: No matching INIT2 function for func-string"); + if (lookUp) + strcpy(funcString, lookUp); + out->write(funcString, 32); + + lookUp = g_hdb->_ai->funcLookUp((FuncPtr)aiDraw); + memset(&funcString, 0, 32); + if (!lookUp && aiDraw) + error("AIEntity::save: No matching DRAW function for func-string"); + if (lookUp) + strcpy(funcString, lookUp); + out->write(funcString, 32); + + // Save AIEntity + out->writeSint32LE((int)type); + out->writeSint32LE((int)state); + out->writeSint32LE((int)dir); + out->write(luaFuncInit, 32); + out->write(luaFuncAction, 32); + out->write(luaFuncUse, 32); + out->writeUint16LE(level); + out->writeUint16LE(value1); + out->writeUint16LE(value2); + out->writeSint32LE((int)dir2); + out->writeUint16LE(x); + out->writeUint16LE(y); + out->writeSint16LE(drawXOff); + out->writeSint16LE(drawYOff); + out->writeUint16LE(onScreen); + out->writeUint16LE(moveSpeed); + out->writeSint16LE(xVel); + out->writeSint16LE(yVel); + out->writeUint16LE(tileX); + out->writeUint16LE(tileY); + out->writeUint16LE(goalX); + out->writeUint16LE(goalY); + out->writeUint16LE(touchpX); + out->writeUint16LE(touchpY); + out->writeUint16LE(touchpTile); + out->writeUint16LE(touchpWait); + out->writeUint16LE(stunnedWait); + out->writeSint16LE(sequence); + out->write(entityName, 32); + out->write(printedName, 32); + out->writeUint16LE(animFrame); + out->writeUint16LE(animDelay); + out->writeUint16LE(animCycle); +} + +void AIEntity::load(Common::InSaveFile *in) { + char funcString[32]; + FuncPtr init, init2, use, action; + EntFuncPtr drawf; + + action = init = init2 = use = NULL; + drawf = NULL; + + // Read 32-char names for the function ptrs we have in entity struct + in->read(funcString, 32); + if (funcString[0]) + action = g_hdb->_ai->funcLookUp(funcString); + + in->read(funcString, 32); + if (funcString[0]) + use = g_hdb->_ai->funcLookUp(funcString); + + in->read(funcString, 32); + if (funcString[0]) + init = g_hdb->_ai->funcLookUp(funcString); + + in->read(funcString, 32); + if (funcString[0]) + init2 = g_hdb->_ai->funcLookUp(funcString); + + in->read(funcString, 32); + if (funcString[0]) + drawf = (EntFuncPtr)g_hdb->_ai->funcLookUp(funcString); + + // Load AIEntity + type = (AIType)in->readSint32LE(); + state = (AIState)in->readSint32LE(); + dir = (AIDir)in->readSint32LE(); + in->read(luaFuncInit, 32); + in->read(luaFuncAction, 32); + in->read(luaFuncUse, 32); + level = in->readUint16LE(); + value1 = in->readUint16LE(); + value2 = in->readUint16LE(); + dir2 = (AIDir)in->readSint32LE(); + x = in->readUint16LE(); + y = in->readUint16LE(); + drawXOff = in->readSint16LE(); + drawYOff = in->readSint16LE(); + onScreen = in->readUint16LE(); + moveSpeed = in->readUint16LE(); + xVel = in->readSint16LE(); + yVel = in->readSint16LE(); + tileX = in->readUint16LE(); + tileY = in->readUint16LE(); + goalX = in->readUint16LE(); + goalY = in->readUint16LE(); + touchpX = in->readUint16LE(); + touchpY = in->readUint16LE(); + touchpTile = in->readUint16LE(); + touchpWait = in->readUint16LE(); + stunnedWait = in->readUint16LE(); + sequence = in->readSint16LE(); + in->read(entityName, 32); + in->read(printedName, 32); + animFrame = in->readUint16LE(); + animDelay = in->readUint16LE(); + animCycle = in->readUint16LE(); + + aiAction = action; + aiInit = init; + aiInit2 = init2; + aiUse = use; + aiDraw = drawf; +} + + } // End of Namespace |