Skip to content

Commit

Permalink
DM: Move two global arrays to DMEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
Strangerke authored and Bendegúz Nagy committed Aug 26, 2016
1 parent 3f19bcd commit 57ca9af
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 19 deletions.
4 changes: 2 additions & 2 deletions engines/dm/champion.cpp
Expand Up @@ -561,8 +561,8 @@ void ChampionMan::addCandidateChampionToParty(uint16 championPortraitIndex) {
int16 mapY = _vm->_dungeonMan->_currMap._partyPosY;

uint16 championObjectsCell = returnOppositeDir((direction)(dunMan._currMap._partyDir));
mapX += gDirIntoStepCountEast[dunMan._currMap._partyDir];
mapY += gDirIntoStepCountNorth[dunMan._currMap._partyDir];
mapX += _vm->_dirIntoStepCountEast[dunMan._currMap._partyDir];
mapY += _vm->_dirIntoStepCountNorth[dunMan._currMap._partyDir];
thing = dunMan.getSquareFirstThing(mapX, mapY);
AL_0_slotIndex_Red = kChampionSlotBackpackLine_1_1;
uint16 slotIndex_Green;
Expand Down
3 changes: 0 additions & 3 deletions engines/dm/dm.cpp
Expand Up @@ -52,9 +52,6 @@

namespace DM {

int8 gDirIntoStepCountEast[4] = {0 /* North */, 1 /* East */, 0 /* West */, -1 /* South */}; // @ G0233_ai_Graphic559_DirectionToStepEastCount
int8 gDirIntoStepCountNorth[4] = {-1 /* North */, 0 /* East */, 1 /* West */, 0 /* South */}; // @ G0234_ai_Graphic559_DirectionToStepNorthCount

void turnDirRight(direction &dir) { dir = (direction)((dir + 1) & 3); }
void turnDirLeft(direction &dir) { dir = (direction)((dir - 1) & 3); }
direction returnOppositeDir(direction dir) { return (direction)((dir + 2) & 3); }
Expand Down
10 changes: 6 additions & 4 deletions engines/dm/dm.h
Expand Up @@ -55,10 +55,6 @@ enum direction {
kDirWest = 3
};

// TODO: refactor direction into a class
extern int8 gDirIntoStepCountEast[4];
extern int8 gDirIntoStepCountNorth[4];

void turnDirRight(direction &dir);
void turnDirLeft(direction &dir);
direction returnOppositeDir(direction dir);
Expand Down Expand Up @@ -128,6 +124,8 @@ class DMEngine : public Engine {
void processNewPartyMap(uint16 mapIndex); // @ F0003_MAIN_ProcessNewPartyMap_CPSE
void initializeGame(); // @ F0463_START_InitializeGame_CPSADEF
void gameloop(); // @ F0002_MAIN_GameLoop_CPSDF
void initArrays();

public:
explicit DMEngine(OSystem *syst);
~DMEngine();
Expand Down Expand Up @@ -160,6 +158,10 @@ class DMEngine : public Engine {
bool _pressingMouth; // @ G0333_B_PressingMouth
bool _stopPressingMouth; // @ G0334_B_StopPressingMouth
bool _highlightBoxInversionRequested; // @ G0340_B_HighlightBoxInversionRequested

// TODO: refactor direction into a class
int8 _dirIntoStepCountEast[4];
int8 _dirIntoStepCountNorth[4];
};

class Console : public GUI::Debugger {
Expand Down
55 changes: 55 additions & 0 deletions engines/dm/dmglobals.cpp
@@ -0,0 +1,55 @@
/* 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.
*
*/

/*
* Based on the Reverse Engineering work of Christophe Fontanel,
* maintainer of the Dungeon Master Encyclopaedia (http://dmweb.free.fr/)
*/

#include "dm/dm.h"
#include "gfx.h"
#include "dungeonman.h"
#include "eventman.h"
#include "menus.h"
#include "champion.h"
#include "loadsave.h"
#include "objectman.h"
#include "inventory.h"
#include "text.h"
#include "movesens.h"

namespace DM {

void DMEngine::initArrays() {
// G0233_ai_Graphic559_DirectionToStepEastCount
_dirIntoStepCountEast[0] = 0; // North
_dirIntoStepCountEast[1] = 1; // East
_dirIntoStepCountEast[2] = 0; // West
_dirIntoStepCountEast[3] = -1; // South

// G0234_ai_Graphic559_DirectionToStepNorthCount
_dirIntoStepCountNorth[0] = -1; // North
_dirIntoStepCountNorth[1] = 0; // East
_dirIntoStepCountNorth[2] = 1; // West
_dirIntoStepCountNorth[3] = 0; // South
}
} // End of namespace DM
8 changes: 4 additions & 4 deletions engines/dm/dungeonman.cpp
Expand Up @@ -360,11 +360,11 @@ CreatureInfo gCreatureInfo[kCreatureTypeCount] = { // @ G0243_as_Graphic559_Crea
{26, 0, 0x38AA, 0x0000, 12, 22, 255, 180, 210, 0, 130, 0x6369, 0xFF37, 0x0FBF, 0x0564, 0xFB52, 5}};

void DungeonMan::mapCoordsAfterRelMovement(direction dir, int16 stepsForward, int16 stepsRight, int16 &posX, int16 &posY) {
posX += gDirIntoStepCountEast[dir] * stepsForward;
posY += gDirIntoStepCountNorth[dir] * stepsForward;
posX += _vm->_dirIntoStepCountEast[dir] * stepsForward;
posY += _vm->_dirIntoStepCountNorth[dir] * stepsForward;
turnDirRight(dir);
posX += gDirIntoStepCountEast[dir] * stepsRight;
posY += gDirIntoStepCountNorth[dir] * stepsRight;
posX += _vm->_dirIntoStepCountEast[dir] * stepsRight;
posY += _vm->_dirIntoStepCountNorth[dir] * stepsRight;
}

DungeonMan::DungeonMan(DMEngine *dmEngine) : _vm(dmEngine), _rawDunFileData(NULL), _maps(NULL), _rawMapData(NULL) {
Expand Down
12 changes: 6 additions & 6 deletions engines/dm/eventman.cpp
Expand Up @@ -508,8 +508,8 @@ void EventManager::commandSetLeader(ChampionIndex champIndex) {
void EventManager::commandProcessType80ClickInDungeonViewTouchFrontWall() {
DungeonMan &dunMan = *_vm->_dungeonMan;
CurrMapData &currMap = dunMan._currMap;
int16 mapX = currMap._partyPosX + gDirIntoStepCountEast[currMap._partyDir];
int16 mapY = currMap._partyPosY + gDirIntoStepCountNorth[currMap._partyDir];
int16 mapX = currMap._partyPosX + _vm->_dirIntoStepCountEast[currMap._partyDir];
int16 mapY = currMap._partyPosY + _vm->_dirIntoStepCountNorth[currMap._partyDir];
if ((mapX >= 0) && (mapX < currMap._width) && (mapY >= 0) && (mapY < currMap._height)) {
_vm->_stopWaitingForPlayerInput = _vm->_movsens->sensorIsTriggeredByClickOnWall(mapX, mapY, returnOppositeDir(currMap._partyDir));
}
Expand All @@ -525,8 +525,8 @@ void EventManager::commandProcessType80ClickInDungeonView(int16 posX, int16 posY
return;

if (champMan._leaderEmptyHanded) {
int16 mapX = currMap._partyPosX + gDirIntoStepCountEast[currMap._partyDir];
int16 mapY = currMap._partyPosY + gDirIntoStepCountNorth[currMap._partyDir];
int16 mapX = currMap._partyPosX + _vm->_dirIntoStepCountEast[currMap._partyDir];
int16 mapY = currMap._partyPosY + _vm->_dirIntoStepCountNorth[currMap._partyDir];

if (Door(dunMan.getSquareFirstThingData(mapX, mapY)).hasButton() &&
dunMan._dungeonViewClickableBoxes[kViewCellDoorButtonOrWallOrn].isPointInside(Common::Point(posX, posY - 33))) {
Expand Down Expand Up @@ -627,8 +627,8 @@ void EventManager::commandProcessCommands160To162ClickInResurrectReincarnatePane
}

champMan._candidateChampionOrdinal = _vm->indexToOrdinal(kChampionNone);
int16 mapX = currMap._partyPosX + gDirIntoStepCountEast[currMap._partyDir];
int16 mapY = currMap._partyPosY + gDirIntoStepCountNorth[currMap._partyDir];
int16 mapX = currMap._partyPosX + _vm->_dirIntoStepCountEast[currMap._partyDir];
int16 mapY = currMap._partyPosY + _vm->_dirIntoStepCountNorth[currMap._partyDir];

for (uint16 slotIndex = kChampionSlotReadyHand; slotIndex < kChampionSlotChest_1; slotIndex++) {
Thing thing = champ->getSlot((ChampionSlot)slotIndex);
Expand Down
1 change: 1 addition & 0 deletions engines/dm/module.mk
Expand Up @@ -32,6 +32,7 @@ MODULE_OBJS := \
champion.o \
detection.o \
dm.o \
dmglobals.o \
dungeonman.o \
eventman.o \
gfx.o \
Expand Down

0 comments on commit 57ca9af

Please sign in to comment.