aboutsummaryrefslogtreecommitdiff
path: root/engines/dm/objectman.cpp
blob: a373e94f1f952f24b78020e37c93056f4e784469 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "objectman.h"
#include "dungeonman.h"


namespace DM {

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

IconIndice ObjectMan::getObjectType(Thing thing) {
	if (thing == Thing::_thingNone)
		return kIconIndiceNone;

	int16 objectInfoIndex = _vm->_dungeonMan->getObjectInfoIndex(thing);
	if (objectInfoIndex != -1) {
		objectInfoIndex = gObjectInfo[objectInfoIndex]._type;
	}
	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;
}

}