Skip to content

Commit

Permalink
DM: getSquareAspect(..) is complete
Browse files Browse the repository at this point in the history
  • Loading branch information
WinterGrascph committed Aug 26, 2016
1 parent d9bb44e commit 9655066
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 58 deletions.
2 changes: 1 addition & 1 deletion engines/dm/dm.cpp
Expand Up @@ -71,7 +71,7 @@ Common::Error DMEngine::run() {
uint16 i = 0; //TODO: testing, please delete me
while (true) {
_displayMan->clearScreen(kColorBlack);
_displayMan->drawDungeon(_dungeonMan->_currMap.partyDir, _dungeonMan->_currMap.partyPosX, _dungeonMan->_currMap.partyPosY + i);
_displayMan->drawDungeon(_dungeonMan->_currMap.partyDir, _dungeonMan->_currMap.partyPosX, _dungeonMan->_currMap.partyPosY);
_displayMan->updateScreen();
_system->delayMillis(2000); //TODO: testing, please set me to 10
if (++i == 100) break;
Expand Down
49 changes: 46 additions & 3 deletions engines/dm/dm.h
Expand Up @@ -8,16 +8,59 @@

namespace DM {

class Console;
class DisplayMan;
class DungeonMan;


enum direction {
kDirNorth = 0,
kDirEast = 1,
kDirSouth = 2,
kDirWest = 3
};

class Console;
class DisplayMan;
class DungeonMan;
int16 ordinalToIndex(int16 val); // @ M01_ORDINAL_TO_INDEX
int16 indexToOrdinal(int16 val); // @ M00_INDEX_TO_ORDINAL
enum ThingType {
kPartyThingType = -1, // @ CM1_THING_TYPE_PARTY, special value
kDoorThingType = 0,
kTeleporterThingType = 1,
kTextstringType = 2,
kSensorThingType = 3,
kGroupThingType = 4,
kWeaponThingType = 5,
kArmourThingType = 6,
kScrollThingType = 7,
kPotionThingType = 8,
kContainerThingType = 9,
kJunkThingType = 10,
kProjectileThingType = 14,
kExplosionThingType = 15,
kThingTypeTotal = 16 // +1 than the last (explosionThingType)
}; // @ C[00..15]_THING_TYPE_...

class Thing {
uint16 data;
public:
static const Thing thingNone;
static const Thing thingEndOfList;

Thing() {}
Thing(uint16 d) { set(d); }

void set(uint16 d) {
data = d;
}

byte getCell() const { return data >> 14; }
ThingType getType() const { return (ThingType)((data >> 10) & 0xF); }
uint16 getIndex() const { return data & 0x1FF; }
uint16 toUint16() const { return data; } // I don't like 'em cast operators
bool operator==(const Thing &rhs) const { return data == rhs.data; }
bool operator!=(const Thing &rhs) const { return data != rhs.data; }
}; // @ THING


enum {
// engine debug channels
Expand Down
81 changes: 69 additions & 12 deletions engines/dm/dungeonman.cpp
Expand Up @@ -12,6 +12,7 @@ int8 dirIntoStepCountEast[4] = {0 /* North */, 1 /* East */, 0 /* West */, -1 /*
int8 dirIntoStepCountNorth[4] = {-1 /* North */, 0 /* East */, 1 /* West */, 0 /* South */};

void turnDirRight(direction &dir) { dir = (direction)((dir + 1) & 3); }
bool isOrientedWestEast(direction dir) { return dir & 1; }


}
Expand Down Expand Up @@ -458,21 +459,24 @@ enum SquareAspectIndice {
kStairsUpAspect = 2,
kDoorStateAspect = 2,
kDoorThingIndexAspect = 3,
kFloorOrnOrdAspect = 4
kFloorOrnOrdAspect = 4,
kFootprintsAspect = 0x8000 // @ MASK0x8000_FOOTPRINTS
};


void DungeonMan::setSquareAspect(uint16 *aspectArray, direction dir, int16 mapX, int16 mapY) {
// TODO: get rid of the GOTOs
void DungeonMan::setSquareAspect(uint16 *aspectArray, direction dir, int16 mapX, int16 mapY) { // complete, except where marked
bool leftOrnAllowed, rightOrnAllowed, frontOrnAllowed;
bool squareIsFakeWall;
bool footPrintsAllowed;

_vm->_displayMan->_championPortraitOrdinal = 0; // BUG0_75, possible fix

memset(aspectArray, 0, 5 * sizeof(uint16));
Thing thing = getSquareFirstThing(mapX, mapY);
Square square = getSquare(mapX, mapY);

memset(aspectArray, 0, 5 * sizeof(int16));
aspectArray[kElemAspect] = square.getType();

_vm->_displayMan->_championPortraitOrdinal = 0; // BUG0_75, possible fix
switch (square.getType()) {
case kWallElemType:
switch (dir) {
Expand All @@ -499,6 +503,7 @@ void DungeonMan::setSquareAspect(uint16 *aspectArray, direction dir, int16 mapX,
}

squareIsFakeWall = false;
T0172010_ClosedFakeWall:
setSquareAspectOrnOrdinals(aspectArray, leftOrnAllowed, frontOrnAllowed, rightOrnAllowed, dir, mapX, mapY, squareIsFakeWall);

while ((thing != Thing::thingEndOfList) && (thing.getType() <= kSensorThingType)) {
Expand All @@ -507,22 +512,74 @@ void DungeonMan::setSquareAspect(uint16 *aspectArray, direction dir, int16 mapX,
if (thing.getType() == kTextstringType) {
if (TextString(getThingData(thing)).isVisible()) {
aspectArray[sideIndex + 1] = _currMapInscriptionWallOrnIndex + 1;

} else {
Sensor sensor(getThingData(thing));
aspectArray[sideIndex + 1] = sensor.getOrnOrdinal();
if (sensor.getType() == kSensorWallChampionPortrait) {
_vm->_displayMan->_championPortraitOrdinal = indexToOrdinal(sensor.getData());
}
_vm->_displayMan->_inscriptionThing = thing; // BUG0_76
}
} else {
Sensor sensor(getThingData(thing));
aspectArray[sideIndex + 1] = sensor.getOrnOrdinal();
if (sensor.getType() == kSensorWallChampionPortrait) {
_vm->_displayMan->_championPortraitOrdinal = indexToOrdinal(sensor.getData());
}
}
}
thing = getNextThing(thing);
}
if (squareIsFakeWall && (_currMap.partyPosX != mapX) && (_currMap.partyPosY != mapY)) {
aspectArray[kFirstGroupOrObjectAspect] = Thing::thingEndOfList.toUint16();
return;
}
break;
case kPitElemType:
if (square.get(kPitOpen))
aspectArray[kPitInvisibleAspect] = square.get(kPitInvisible);
else
aspectArray[kElemAspect] = kCorridorElemType;
footPrintsAllowed = true;
goto T0172030_Pit;
case kFakeWallElemType:
if (!square.get(kFakeWallOpen)) {
aspectArray[kElemAspect] = kWallElemType;
leftOrnAllowed = rightOrnAllowed = frontOrnAllowed = square.get(kFakeWallRandOrnOrFootPAllowed);
squareIsFakeWall = true;
goto T0172010_ClosedFakeWall;
}
aspectArray[kWallElemType] = kCorridorElemType;
footPrintsAllowed = square.get(kFakeWallRandOrnOrFootPAllowed);
// intentional fallthrough
case kCorridorElemType:
aspectArray[kFloorOrnOrdAspect] = getRandomOrnOrdinal(square.get(kCorridorRandOrnAllowed), _currMap.map->randFloorOrnCount, mapX, mapY, 30);
T0172029_Teleporter:
footPrintsAllowed = true;
T0172030_Pit:
while ((thing != Thing::thingEndOfList) && (thing.getType() <= kSensorThingType)) {
if (thing.getType() == kSensorThingType)
aspectArray[kFloorOrnOrdAspect] = Sensor(getThingData(thing)).getOrnOrdinal();
thing = getNextThing(thing);
}
goto T0172049_Footprints;
case kTeleporterElemType:
aspectArray[kTeleporterVisibleAspect] = square.get(kTeleporterOpen) && square.get(kTeleporterVisible);
goto T0172029_Teleporter;
case kStairsElemType:
aspectArray[kElemAspect] = ((square.get(kStairsNorthSouthOrient) >> 3) == isOrientedWestEast(dir)) ? kStairsSideElemType : kStairsFrontElemType;
aspectArray[kStairsUpAspect] = square.get(kStairsUp);
footPrintsAllowed = false;
goto T0172046_Stairs;
case kDoorElemType:
if ((square.get(kDoorNorthSouthOrient) >> 3) == isOrientedWestEast(dir)) {
aspectArray[kElemAspect] = kDoorSideElemType;
} else {
aspectArray[kElemAspect] = kDoorFrontElemType;
aspectArray[kDoorStateAspect] = square.getDoorState();
aspectArray[kDoorThingIndexAspect] = getSquareFirstThing(mapX, mapY).getIndex();
}
footPrintsAllowed = true;
T0172046_Stairs:
while ((thing != Thing::thingEndOfList) && (thing.getType() <= kSensorThingType))
thing = getNextThing(thing);
T0172049_Footprints:
if (footPrintsAllowed) // TODO: I skipped some party query code, must come back later and complete
aspectArray[kFloorOrnOrdAspect] &= kFootprintsAspect;
}
aspectArray[kFirstGroupOrObjectAspect] = thing.toUint16();
}
Expand Down
45 changes: 4 additions & 41 deletions engines/dm/dungeonman.h
Expand Up @@ -10,46 +10,6 @@ class DungeonMan;
struct Map;


int16 ordinalToIndex(int16 val); // @ M01_ORDINAL_TO_INDEX
int16 indexToOrdinal(int16 val); // @ M00_INDEX_TO_ORDINAL
enum ThingType {
kPartyThingType = -1, // @ CM1_THING_TYPE_PARTY, special value
kDoorThingType = 0,
kTeleporterThingType = 1,
kTextstringType = 2,
kSensorThingType = 3,
kGroupThingType = 4,
kWeaponThingType = 5,
kArmourThingType = 6,
kScrollThingType = 7,
kPotionThingType = 8,
kContainerThingType = 9,
kJunkThingType = 10,
kProjectileThingType = 14,
kExplosionThingType = 15,
kThingTypeTotal = 16 // +1 than the last (explosionThingType)
}; // @ C[00..15]_THING_TYPE_...

class Thing {
uint16 data;
public:
static const Thing thingNone;
static const Thing thingEndOfList;

Thing() {}
Thing(uint16 d) { set(d); }

void set(uint16 d) {
data = d;
}

byte getCell() const { return data >> 14; }
ThingType getType() const { return (ThingType)((data >> 10) & 0xF); }
uint16 getIndex() const { return data & 0x1FF; }
uint16 toUint16() const { return data; } // I don't like 'em cast operators
bool operator==(const Thing &rhs) const { return data == rhs.data; }
bool operator!=(const Thing &rhs) const { return data != rhs.data; }
}; // @ THING

struct CreatureInfo {
byte creatureAspectIndex;
Expand Down Expand Up @@ -297,6 +257,7 @@ enum SquareMask {
kWallSouthRandOrnAllowed = 0x2,
kWallEastRandOrnAllowed = 0x4,
kWallNorthRandOrnAllowed = 0x8,
kCorridorRandOrnAllowed = 0x8,
kPitImaginary = 0x1,
kPitInvisible = 0x4,
kPitOpen = 0x8,
Expand Down Expand Up @@ -334,7 +295,9 @@ class Square {
Square(SquareType type) { setType(type); }
Square &set(byte dat) { this->data = dat; return *this; }
Square &set(SquareMask mask) { data |= mask; return *this; }
bool get(SquareMask mask) { return data & mask; }
byte get(SquareMask mask) { return data & mask; }
byte getDoorState() { return data & 0x7; } // @ M36_DOOR_STATE
Square &setDoorState(byte state) { data = ((data & ~0x7) | state); } // @ M37_SET_DOOR_STATE
SquareType getType() { return (SquareType)(data >> 5); } // @ M34_SQUARE_TYPE
Square &setType(SquareType type) { data = (data & 0x1F) | type << 5; return *this; }
byte toByte() { return data; } // I don't like 'em casts
Expand Down
3 changes: 2 additions & 1 deletion engines/dm/gfx.h
Expand Up @@ -166,7 +166,6 @@ class DisplayMan {
void drawDungeon(direction dir, int16 posX, int16 posY); // @ F0128_DUNGEONVIEW_Draw_CPSF
void updateScreen();


int16 _championPortraitOrdinal = 0; // @ G0289_i_DungeonView_ChampionPortraitOrdinal
int16 _currMapAlcoveOrnIndices[kAlcoveOrnCount] = {0}; // @ G0267_ai_CurrentMapAlcoveOrnamentIndices
int16 _currMapFountainOrnIndices[kFountainOrnCount] = {0}; // @ G0268_ai_CurrentMapFountainOrnamentIndices
Expand All @@ -179,6 +178,8 @@ class DisplayMan {
byte _currMapDoorOrnIndices[18] = {0}; // @ G0263_auc_CurrentMapDoorOrnamentIndices

int16 _currMapViAltarIndex = 0; // @ G0266_i_CurrentMapViAltarWallOrnamentIndex

Thing _inscriptionThing = Thing::thingNone; // @ G0290_T_DungeonView_InscriptionThing
};

}
Expand Down

0 comments on commit 9655066

Please sign in to comment.