Skip to content

Commit

Permalink
DM: Add F0033_OBJECT_GetIconIndex and several getters for object types
Browse files Browse the repository at this point in the history
  • Loading branch information
Bendegúz Nagy committed Aug 26, 2016
1 parent 23c1acf commit 29d832b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
9 changes: 7 additions & 2 deletions engines/dm/dungeonman.h
Expand Up @@ -313,6 +313,8 @@ class Weapon {
Weapon(uint16 *rawDat) : _nextThing(rawDat[0]), _desc(rawDat[1]) {}

WeaponType getType() { return (WeaponType)(_desc & 0x7F); }
bool isLit() { return (_desc >> 15) & 1; }
uint16 getChargeCount() { return (_desc >> 10) & 0xF; }
Thing getNextThing() { return _nextThing; }
}; // @ WEAPON

Expand Down Expand Up @@ -343,6 +345,7 @@ class Scroll {
_attributes = attribs;
}
Thing getNextThing() { return _nextThing; }
uint16 getClosed() { return (_attributes >> 10) & 0x3F; } // ??? dunno why, the original bitfield is 6 bits long
}; // @ SCROLL

enum PotionType {
Expand Down Expand Up @@ -574,11 +577,13 @@ class DungeonMan {

void setCurrentMap(uint16 mapIndex); // @ F0173_DUNGEON_SetCurrentMap

Thing getNextThing(Thing thing); // @ F0159_DUNGEON_GetNextThing(THING P0280_T_Thing)
uint16 *getThingData(Thing thing); // @ unsigned char* F0156_DUNGEON_GetThingData(register THING P0276_T_Thing)
public:
DungeonMan(DMEngine *dmEngine);
~DungeonMan();

Thing getNextThing(Thing thing); // @ F0159_DUNGEON_GetNextThing(THING P0280_T_Thing)
uint16 *getThingData(Thing thing); // @ unsigned char* F0156_DUNGEON_GetThingData(register THING P0276_T_Thing)

// TODO: this does stuff other than load the file!
void loadDungeonFile(); // @ F0434_STARTEND_IsLoadDungeonSuccessful_CPSC
void setCurrentMapAndPartyMap(uint16 mapIndex); // @ F0174_DUNGEON_SetCurrentMapAndPartyMap
Expand Down
50 changes: 48 additions & 2 deletions engines/dm/objectman.cpp
Expand Up @@ -4,7 +4,7 @@

namespace DM {

ObjectMan::ObjectMan(DMEngine *vm): _vm(vm) {}
ObjectMan::ObjectMan(DMEngine *vm) : _vm(vm) {}

IconIndice ObjectMan::getObjectType(Thing thing) {
if (thing == Thing::_thingNone)
Expand All @@ -17,8 +17,54 @@ IconIndice ObjectMan::getObjectType(Thing thing) {
return (IconIndice)objectInfoIndex;
}


byte gChargeCountToTorchType[16] = {0, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3}; // @ G0029_auc_Graphic562_ChargeCountToTorchType

int16 ObjectMan::getIconIndex(Thing thing) {
IconIndice iconIndex = getObjectType(thing);

if ((iconIndex != kIconIndiceNone) &&
((iconIndex < kIconIndiceWeaponDagger) &&(iconIndex >= kIconIndiceJunkCompassNorth)) || // < instead of <= is no error
((iconIndex >= kIconIndicePotionMaPotionMonPotion) && (iconIndex <= kIconIndicePotionWaterFlask)) ||
(iconIndex == kIconIndicePotionEmptyFlask)
) {
uint16 *rawType = _vm->_dungeonMan->getThingData(thing);
switch (iconIndex) {
case kIconIndiceJunkCompassNorth:
iconIndex = (IconIndice)(iconIndex + _vm->_dungeonMan->_currMap._partyDir);
break;
case kIconIndiceWeaponTorchUnlit: {
Weapon weapon(rawType);
if (weapon.isLit()) {
iconIndex = (IconIndice)(iconIndex + gChargeCountToTorchType[weapon.getChargeCount()]);
}
break;
}
case kIconIndiceScrollOpen:
if (Scroll(rawType).getClosed()) {
iconIndex = (IconIndice)(iconIndex + 1);
}
break;
case kIconIndiceJunkWater:
case kIconIndiceJunkIllumuletUnequipped:
case kIconIndiceJunkJewelSymalUnequipped:
if (Junk(rawType).getChargeCount()) {
iconIndex = (IconIndice)(iconIndex + 1);
}
break;
case kIconIndiceWeaponBoltBladeStormEmpty:
case kIconIndiceWeaponFlamittEmpty:
case kIconIndiceWeaponStormringEmpty:
case kIconIndiceWeaponFuryRaBladeEmpty:
case kIconIndiceWeaponEyeOfTimeEmpty:
case kIconIndiceWeaponStaffOfClawsEmpty:
if (Weapon(rawType).getChargeCount()) {
iconIndex = (IconIndice)(iconIndex + 1);
}
break;
}
}

return iconIndex;
}

}
1 change: 1 addition & 0 deletions engines/dm/objectman.h
Expand Up @@ -9,6 +9,7 @@ class ObjectMan {
public:
ObjectMan(DMEngine *vm);
IconIndice getObjectType(Thing thing); // @ F0032_OBJECT_GetType
int16 getIconIndex(Thing thing); // @ F0033_OBJECT_GetIconIndex

};

Expand Down

0 comments on commit 29d832b

Please sign in to comment.