Skip to content

Commit

Permalink
DM: Add entrance processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Bendegúz Nagy committed Aug 26, 2016
1 parent 11704d0 commit aacecd6
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 12 deletions.
1 change: 1 addition & 0 deletions engines/dm/TODOs/todo.txt
Expand Up @@ -31,4 +31,5 @@ Todo:
Finish stuff:
f380_processCommandQueue
Missing main loop methods
Save file f433_processCommand140_saveGame fails silently

2 changes: 1 addition & 1 deletion engines/dm/detection.cpp
Expand Up @@ -83,7 +83,7 @@ class DMMetaEngine : public AdvancedMetaEngine {
}

virtual const ADGameDescription *fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const { return gameDescriptions; }
virtual bool hasFeature(MetaEngineFeature f) const { return false; }

virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const {
if(desc)
*engine = new DM::DMEngine(syst);
Expand Down
112 changes: 110 additions & 2 deletions engines/dm/dm.cpp
Expand Up @@ -172,6 +172,9 @@ DMEngine::DMEngine(OSystem *syst) : Engine(syst), _console(nullptr) {
_g313_gameTime = 0;
_g353_stringBuildBuffer[0] = '\0';
_g318_waitForInputMaxVerticalBlankCount = 0;
for (uint16 i = 0; i < 10; ++i)
_g562_entranceDoorAnimSteps[i] = nullptr;
_g564_interfaceCredits = nullptr;
debug("DMEngine::DMEngine");


Expand Down Expand Up @@ -202,6 +205,12 @@ DMEngine::~DMEngine() {
DebugMan.clearAllDebugChannels();
}

bool DMEngine::hasFeature(EngineFeature f) const {
return
(f == kSupportsSavingDuringRuntime) ||
(f == kSupportsLoadingDuringRuntime);
}

void DMEngine::f22_delay(uint16 verticalBlank) {
_system->delayMillis(verticalBlank * 20); // Google says most Amiga games had a refreshrate of 50 hz
}
Expand All @@ -221,9 +230,9 @@ void DMEngine::f463_initializeGame() {
_textMan->f54_textInitialize();
_objectMan->loadObjectNames();
_eventMan->initMouse();
//F0441_STARTEND_ProcessEntrance();
f441_processEntrance();
while (f435_loadgame() != k1_LoadgameSuccess) {
warning(false, "TODO: F0441_STARTEND_ProcessEntrance");
f441_processEntrance();
}
//F0396_MENUS_LoadSpellAreaLinesBitmap() is not needed, every bitmap has been loaded

Expand Down Expand Up @@ -423,4 +432,103 @@ int16 DMEngine::M0_indexToOrdinal(int16 val) {
return val + 1;
}


void DMEngine::f441_processEntrance() {
uint16 L1402_ui_AnimationStep;
Box L1405_s_Box;

_eventMan->_g441_primaryMouseInput = g445_PrimaryMouseInput_Entrance;
_eventMan->_g442_secondaryMouseInput = nullptr;
_eventMan->_g443_primaryKeyboardInput = nullptr;
_eventMan->_g444_secondaryKeyboardInput = nullptr;
_g562_entranceDoorAnimSteps[0] = new byte[128 * 161 * 12];
for (L1402_ui_AnimationStep = 1; L1402_ui_AnimationStep < 8; L1402_ui_AnimationStep++) {
_g562_entranceDoorAnimSteps[L1402_ui_AnimationStep] = _g562_entranceDoorAnimSteps[L1402_ui_AnimationStep - 1] + 128 * 161;
}
_g562_entranceDoorAnimSteps[8] = _g562_entranceDoorAnimSteps[7] + 128 * 161;
_g562_entranceDoorAnimSteps[9] = _g562_entranceDoorAnimSteps[8] + 128 * 161 * 2;

_displayMan->f466_loadIntoBitmap(k3_entranceRightDoorGraphicIndice, _g562_entranceDoorAnimSteps[4]);
_displayMan->f466_loadIntoBitmap(k2_entranceLeftDoorGraphicIndice, _g562_entranceDoorAnimSteps[0]);
_g564_interfaceCredits = _displayMan->f489_getNativeBitmapOrGraphic(k5_creditsGraphicIndice);
_displayMan->_g578_useByteBoxCoordinates = false;
L1405_s_Box._x1 = 0;
L1405_s_Box._x2 = 100;
L1405_s_Box._y1 = 0;
L1405_s_Box._y2 = 160;
for (L1402_ui_AnimationStep = 1; L1402_ui_AnimationStep < 4; L1402_ui_AnimationStep++) {
_displayMan->f132_blitToBitmap(_g562_entranceDoorAnimSteps[0], _g562_entranceDoorAnimSteps[L1402_ui_AnimationStep], L1405_s_Box, L1402_ui_AnimationStep << 2, 0, k64_byteWidth, k64_byteWidth, kM1_ColorNoTransparency, 161, 161);
L1405_s_Box._x2 -= 4;
}
L1405_s_Box._x2 = 127;
for (L1402_ui_AnimationStep = 5; L1402_ui_AnimationStep < 8; L1402_ui_AnimationStep++) {
L1405_s_Box._x1 += 4;
_displayMan->f132_blitToBitmap(_g562_entranceDoorAnimSteps[4], _g562_entranceDoorAnimSteps[L1402_ui_AnimationStep], L1405_s_Box, 0, 0, k64_byteWidth, k64_byteWidth, kM1_ColorNoTransparency, 161, 161);
}
do {
f439_drawEntrance();
//_eventMan->f77_hideMouse();
//_eventMan->f77_hideMouse();
_eventMan->f78_showMouse();
_eventMan->f357_discardAllInput();
_g298_newGame = k99_modeWaitingOnEntrance;
do {
_eventMan->processInput();
_eventMan->f380_processCommandQueue();
_displayMan->updateScreen();
} while (_g298_newGame == k99_modeWaitingOnEntrance);
} while (_g298_newGame == k202_CommandEntranceDrawCredits);
//Strangerke: CHECKME: Earlier versions were using G0566_puc_Graphic534_Sound01Switch
warning(false, "MISSING CODE: F0060_SOUND_Play");
f22_delay(20);
_eventMan->f78_showMouse();
if (_g298_newGame) {
warning(false, "MISSING CODE: F0438_STARTEND_OpenEntranceDoors();");
}
delete[] _g562_entranceDoorAnimSteps[0];
for (uint16 i = 0; i < 10; ++i)
_g562_entranceDoorAnimSteps[i] = nullptr;
}


void DMEngine::f439_drawEntrance() {
static Box K0079_s_Box_Entrance_DoorsUpperHalf = {0, 231, 0, 80};
static Box K0152_s_Box_Entrance_DoorsLowerHalf = {0, 231, 81, 160};
static Box G0010_s_Graphic562_Box_Entrance_ClosedDoorLeft = {0, 104, 30, 190};
static Box G0011_s_Graphic562_Box_Entrance_ClosedDoorRight = {105, 231, 30, 190};

uint16 L1397_ui_ColumnIndex;
byte* L1398_apuc_MicroDungeonCurrentMapData[32];
Square L1399_auc_MicroDungeonSquares[25];

_dungeonMan->_g309_partyMapIndex = k255_mapIndexEntrance;
_displayMan->_g297_drawFloorAndCeilingRequested = true;
_dungeonMan->_g273_currMapWidth = 5;
_dungeonMan->_g274_currMapHeight = 5;
_dungeonMan->_g271_currMapData = L1398_apuc_MicroDungeonCurrentMapData;

Map map; // uninitialized, won't be used
_dungeonMan->_g269_currMap = &map;
for (uint16 i = 0; i < 25; ++i)
L1399_auc_MicroDungeonSquares[i] = Square(k0_ElementTypeWall, 0);
for (L1397_ui_ColumnIndex = 0; L1397_ui_ColumnIndex < 5; L1397_ui_ColumnIndex++) {
L1398_apuc_MicroDungeonCurrentMapData[L1397_ui_ColumnIndex] = (byte*)&L1399_auc_MicroDungeonSquares[L1397_ui_ColumnIndex * 5];
L1399_auc_MicroDungeonSquares[L1397_ui_ColumnIndex + 10] = Square(k1_CorridorElemType, 0);
}
L1399_auc_MicroDungeonSquares[7] = Square(k1_CorridorElemType, 0);
warning(false, "MISSING CODE: F0436_STARTEND_FadeToPalette(G0345_aui_BlankBuffer);");

// note, a global variable is used here in the original
_displayMan->f466_loadIntoBitmap(k4_entranceGraphicIndice, _displayMan->_g348_bitmapScreen);
_displayMan->f128_drawDungeon(kDirSouth, 2, 0);
warning(false, "IGNORED CODE: G0324_B_DrawViewportRequested = false;");

_displayMan->_g578_useByteBoxCoordinates = false, _displayMan->f132_blitToBitmap(_displayMan->_g348_bitmapScreen, _g562_entranceDoorAnimSteps[8], K0079_s_Box_Entrance_DoorsUpperHalf, 0, 30, k160_byteWidthScreen, k128_byteWidth, kM1_ColorNoTransparency, 200, 161);
_displayMan->_g578_useByteBoxCoordinates = false, _displayMan->f132_blitToBitmap(_displayMan->_g348_bitmapScreen, _g562_entranceDoorAnimSteps[8], K0152_s_Box_Entrance_DoorsLowerHalf, 0, 111, k160_byteWidthScreen, k128_byteWidth, kM1_ColorNoTransparency, 200, 161);

_displayMan->f21_blitToScreen(_g562_entranceDoorAnimSteps[0], &G0010_s_Graphic562_Box_Entrance_ClosedDoorLeft, k64_byteWidth, kM1_ColorNoTransparency, 161);
_displayMan->f21_blitToScreen(_g562_entranceDoorAnimSteps[4], &G0011_s_Graphic562_Box_Entrance_ClosedDoorRight, k64_byteWidth, kM1_ColorNoTransparency, 161);
warning(false, "MISSING CODE: F0436_STARTEND_FadeToPalette(g20_PalEntrance);");
}

} // End of namespace DM
9 changes: 7 additions & 2 deletions engines/dm/dm.h
Expand Up @@ -193,11 +193,13 @@ class DMEngine : public Engine {
void initArrays();
Common::String getSavefileName(uint16 slot);
void writeSaveGameHeader(Common::OutSaveFile *out, const Common::String &saveName);
void f439_drawEntrance(); // @ F0439_STARTEND_DrawEntrance
public:
explicit DMEngine(OSystem *syst);
~DMEngine();
virtual bool hasFeature(EngineFeature f) const;

void f22_delay(uint16 ms); // @ F0022_MAIN_Delay
void f22_delay(uint16 verticalBlank); // @ F0022_MAIN_Delay
uint16 f30_getScaledProduct(uint16 val, uint16 scale, uint16 vale2); // @ F0030_MAIN_GetScaledProduct
uint16 getRandomNumber(uint32 max) { return _rnd->getRandomNumber(max - 1); }
int16 M1_ordinalToIndex(int16 val); // @ M01_ORDINAL_TO_INDEX
Expand All @@ -206,12 +208,15 @@ class DMEngine : public Engine {
virtual Common::Error run(); // @ main
void f433_processCommand140_saveGame(uint16 slot, const Common::String desc); // @ F0433_STARTEND_ProcessCommand140_SaveGame_CPSCDF
LoadgameResponse f435_loadgame(); // @ F0435_STARTEND_LoadGame_CPSF
void f441_processEntrance(); // @ F0441_STARTEND_ProcessEntrance

private:
int16 _g528_saveFormat; // @ G0528_i_Format
int16 _g527_platform; // @ G0527_i_Platform
uint16 _g526_dungeonId; // @ G0526_ui_DungeonID
Console *_console;
byte *_g562_entranceDoorAnimSteps[10]; // @ G0562_apuc_Bitmap_EntranceDoorAnimationSteps
byte *_g564_interfaceCredits; // @ G0564_puc_Graphic5_InterfaceCredits
public:
Common::RandomSource *_rnd;
DisplayMan *_displayMan;
Expand All @@ -228,7 +233,7 @@ class DMEngine : public Engine {
ProjExpl *_projexpl;


bool _g298_newGame; // @ G0298_B_NewGame
int16 _g298_newGame; // @ G0298_B_NewGame
bool _g523_restartGameRequest; // @ G0523_B_RestartGameRequested

bool _g321_stopWaitingForPlayerInput; // @ G0321_B_StopWaitingForPlayerInput
Expand Down
1 change: 1 addition & 0 deletions engines/dm/eventman.cpp
Expand Up @@ -740,6 +740,7 @@ void EventManager::f380_processCommandQueue() {
if (cmdType == k140_CommandSaveGame) {
if ((_vm->_championMan->_g305_partyChampionCount > 0) && !_vm->_championMan->_g299_candidateChampionOrdinal) {
warning(false, "MISSING CODE: F0433_STARTEND_ProcessCommand140_SaveGame_CPSCDF();");
_vm->f433_processCommand140_saveGame(1, "Nice save:)");
}
return;
}
Expand Down
15 changes: 9 additions & 6 deletions engines/dm/gfx.cpp
Expand Up @@ -772,6 +772,8 @@ void DisplayMan::setUpScreens(uint16 width, uint16 height) {
delete[] _g348_bitmapScreen;
_g348_bitmapScreen = new byte[_screenWidth * _screenHeight];
fillScreen(k0_ColorBlack);

_g74_tmpBitmap = new byte[_screenWidth * _screenHeight];
}

void DisplayMan::f479_loadGraphics() {
Expand Down Expand Up @@ -2248,11 +2250,13 @@ void DisplayMan::f128_drawDungeon(direction dir, int16 posX, int16 posY) {
f126_drawSquareD0R(dir, tmpPosX, tmpPosY);
f127_drawSquareD0C(dir, posX, posY);

_g698_bitmapWallSet_Wall_D3LCR = _g95_bitmapWall_D3LCR_Native;
_g699_bitmapWallSet_Wall_D2LCR = _g96_bitmapWall_D2LCR_Native;
_g700_bitmapWallSet_Wall_D1LCR = _g97_bitmapWall_D1LCR_Native;
_g701_bitmapWallSet_Wall_D0L = _g98_bitmapWall_D0L_Native;
_g702_bitmapWallSet_Wall_D0R = _g99_bitmapWall_D0R_Native;
if (_g76_useFlippedWallAndFootprintsBitmap) {
_g698_bitmapWallSet_Wall_D3LCR = _g95_bitmapWall_D3LCR_Native;
_g699_bitmapWallSet_Wall_D2LCR = _g96_bitmapWall_D2LCR_Native;
_g700_bitmapWallSet_Wall_D1LCR = _g97_bitmapWall_D1LCR_Native;
_g701_bitmapWallSet_Wall_D0L = _g98_bitmapWall_D0L_Native;
_g702_bitmapWallSet_Wall_D0R = _g99_bitmapWall_D0R_Native;
}

f97_drawViewport((_vm->_dungeonMan->_g309_partyMapIndex != k255_mapIndexEntrance) ? 1 : 0);
if (_vm->_dungeonMan->_g309_partyMapIndex != k255_mapIndexEntrance)
Expand Down Expand Up @@ -2320,7 +2324,6 @@ void DisplayMan::f96_loadCurrentMapGraphics() {
f95_loadWallSet(_vm->_dungeonMan->_g269_currMap->_wallSet);

{
_g74_tmpBitmap = new byte[_screenWidth * _screenHeight];
_g578_useByteBoxCoordinates = true;

f99_copyBitmapAndFlipHorizontal(_g95_bitmapWall_D3LCR_Native = _g698_bitmapWallSet_Wall_D3LCR, _g74_tmpBitmap,
Expand Down
4 changes: 4 additions & 0 deletions engines/dm/gfx.h
Expand Up @@ -202,6 +202,10 @@ enum ViewCell {
};

enum GraphicIndice {
k2_entranceLeftDoorGraphicIndice = 2, // @ C002_GRAPHIC_ENTRANCE_LEFT_DOOR
k3_entranceRightDoorGraphicIndice = 3, // @ C003_GRAPHIC_ENTRANCE_RIGHT_DOOR
k4_entranceGraphicIndice = 4, // @ C004_GRAPHIC_ENTRANCE
k5_creditsGraphicIndice = 5, // @ C005_GRAPHIC_CREDITS
k8_StatusBoxDeadChampion = 8, // @ C008_GRAPHIC_STATUS_BOX_DEAD_CHAMPION
k9_MenuSpellAreaBackground = 9, // @ C009_GRAPHIC_MENU_SPELL_AREA_BACKGROUND
k10_MenuActionAreaIndice = 10, // @ C010_GRAPHIC_MENU_ACTION_AREA
Expand Down
1 change: 0 additions & 1 deletion engines/dm/loadsave.cpp
Expand Up @@ -176,5 +176,4 @@ void DMEngine::writeSaveGameHeader(Common::OutSaveFile* out, const Common::Strin
out->writeUint32BE(playTime);
}


}

0 comments on commit aacecd6

Please sign in to comment.