Permalink
Browse files

STARTREK: Make Action struct POD again

  • Loading branch information...
Drenn1 authored and sev- committed Jul 4, 2018
1 parent 051ea8c commit 8c71f2db84b06862b4fefbe3e79fb042e7a60666
@@ -29,7 +29,7 @@ namespace StarTrek {

class Room;

enum Acton {
enum Acton { // TODO: rename
ACTION_TICK = 0,

ACTION_WALK = 1, // Actions 1-5 are directly usable on away missions.
@@ -46,20 +46,12 @@ enum Acton {
ACTION_OPTIONS = 13 // Not really an action, but selectable from action menu
};

struct Action : Common::Serializable {
struct Action {
byte type;
byte b1;
byte b2;
byte b3;

Action() {}
Action(int _type, int _b1, int _b2, int _b3)
: type((byte)_type),
b1((byte)_b1),
b2((byte)_b2),
b3((byte)_b3) {}


// ACTION_USE, ACTION_GET, ACTION_LOOK, ACTION_TALK
byte activeObject() { return b1; }
byte passiveObject() { return b2; }
@@ -85,7 +77,7 @@ struct Action : Common::Serializable {
return (type << 24) | (b1 << 16) | (b2 << 8) | (b3 << 0);
}

virtual void saveLoadWithSerializer(Common::Serializer &ser) {
void saveLoadWithSerializer(Common::Serializer &ser) {
ser.syncAsByte(type);
ser.syncAsByte(b1);
ser.syncAsByte(b2);
@@ -189,7 +189,7 @@ void StarTrekEngine::handleAwayMissionEvents() {
updateAwayMissionTimers();
_frameIndex++;
_roomFrameCounter++;
addAction(Action(ACTION_TICK, _roomFrameCounter & 0xff, (_roomFrameCounter >> 8) & 0xff, 0));
addAction(ACTION_TICK, _roomFrameCounter & 0xff, (_roomFrameCounter >> 8) & 0xff, 0);
if (_roomFrameCounter >= 2)
_gfx->incPaletteFadeLevel();
break;
@@ -258,16 +258,16 @@ void StarTrekEngine::handleAwayMissionEvents() {

if (clickedObject == -2)
goto checkAddAction;
if (_room->actionHasCode(Action(ACTION_USE, _awayMission.activeObject, _awayMission.passiveObject, 0)))
if (_room->actionHasCode(ACTION_USE, _awayMission.activeObject, _awayMission.passiveObject, 0))
goto checkAddAction;
if (_awayMission.activeObject == OBJECT_MCCOY) {
if (_room->actionHasCode(Action(ACTION_USE, OBJECT_IMEDKIT, _awayMission.passiveObject, 0)))
if (_room->actionHasCode(ACTION_USE, OBJECT_IMEDKIT, _awayMission.passiveObject, 0))
goto checkAddAction;
if (_room->actionHasCode(Action(ACTION_USE, OBJECT_IMEDKIT, _awayMission.passiveObject, 0)))
if (_room->actionHasCode(ACTION_USE, OBJECT_IMEDKIT, _awayMission.passiveObject, 0))
goto checkAddAction;
}
else if (_awayMission.activeObject == OBJECT_SPOCK) {
if (_room->actionHasCode(Action(ACTION_USE, OBJECT_ISTRICOR, _awayMission.passiveObject, 0)))
if (_room->actionHasCode(ACTION_USE, OBJECT_ISTRICOR, _awayMission.passiveObject, 0))
goto checkAddAction;
}

@@ -277,7 +277,7 @@ void StarTrekEngine::handleAwayMissionEvents() {
if (_awayMission.passiveObject == OBJECT_ICOMM) {
if (walkActiveObjectToHotspot())
break;
addAction(Action(ACTION_USE, OBJECT_ICOMM, 0, 0));
addAction(ACTION_USE, OBJECT_ICOMM, 0, 0);
_sound->playVoc("commun30");
if (_awayMission.activeObject <= OBJECT_REDSHIRT) {
goto checkShowInventory;
@@ -296,7 +296,7 @@ void StarTrekEngine::handleAwayMissionEvents() {
if (!walkActiveObjectToHotspot())
{
if (clickedObject != -2)
addAction(Action(_awayMission.activeAction, _awayMission.activeObject, _awayMission.passiveObject, 0));
addAction(_awayMission.activeAction, _awayMission.activeObject, _awayMission.passiveObject, 0);

checkShowInventory:
if (!(_awayMission.crewDownBitset & (1 << OBJECT_KIRK)))
@@ -325,7 +325,7 @@ void StarTrekEngine::handleAwayMissionEvents() {
break;

if (clickedObject != -2)
addAction(Action(_awayMission.activeAction, _awayMission.activeObject, 0, 0));
addAction(_awayMission.activeAction, _awayMission.activeObject, 0, 0);

if (_awayMission.activeAction == ACTION_LOOK && !(_awayMission.crewDownBitset & (1 << OBJECT_KIRK)))
showInventoryIcons(false);
@@ -358,7 +358,7 @@ void StarTrekEngine::handleAwayMissionEvents() {
if (_awayMission.activeAction == ACTION_USE
&& _awayMission.activeObject == OBJECT_ICOMM && (_awayMission.crewDownBitset & (1 << OBJECT_KIRK)) == 0) {
if (!walkActiveObjectToHotspot()) {
addAction(Action(_awayMission.activeAction, _awayMission.activeObject, 0, 0));
addAction(_awayMission.activeAction, _awayMission.activeObject, 0, 0);
_sound->playVoc("communic");
_awayMission.activeAction = ACTION_WALK;
}
@@ -473,6 +473,11 @@ void StarTrekEngine::addAction(const Action &action) {
_actionQueue.push(action);
}

void StarTrekEngine::addAction(byte type, byte b1, byte b2, byte b3) {
const Action a = {type, b1, b2, b3};
addAction(a);
}

void StarTrekEngine::handleAwayMissionAction() {
Action action = _actionQueue.pop();

@@ -689,7 +694,7 @@ void StarTrekEngine::checkTouchedLoadingZone(int16 x, int16 y) {
uint16 var = _room->readRdfWord(offset);
if (_activeDoorWarpHotspot != var) {
_activeDoorWarpHotspot = var;
addAction(Action(ACTION_TOUCHED_HOTSPOT, var & 0xff, 0, 0));
addAction(ACTION_TOUCHED_HOTSPOT, var & 0xff, 0, 0);
}
return;
}
@@ -707,7 +712,7 @@ void StarTrekEngine::checkTouchedLoadingZone(int16 x, int16 y) {
uint16 var = _room->readRdfWord(offset);
if (_activeWarpHotspot != var) {
_activeWarpHotspot = var;
addAction(Action(ACTION_TOUCHED_WARP, var & 0xff, 0, 0));
addAction(ACTION_TOUCHED_WARP, var & 0xff, 0, 0);
}
return;
}
@@ -191,6 +191,11 @@ bool Room::actionHasCode(const Action &action) {
return false;
}

bool Room::actionHasCode(byte type, byte b1, byte b2, byte b3) {
const Action a = {type, b1, b2, b3};
return actionHasCode(a);
}

bool Room::handleAction(const Action &action) {
const RoomAction *roomActionPtr = _roomActionList;
int n = _numRoomActions;
@@ -207,6 +212,11 @@ bool Room::handleAction(const Action &action) {
return false;
}

bool Room::handleAction(byte type, byte b1, byte b2, byte b3) {
const Action a = {type, b1, b2, b3};
return handleAction(a);
}

bool Room::handleActionWithBitmask(const Action &action) {
const RoomAction *roomActionPtr = _roomActionList;
int n = _numRoomActions;
@@ -224,6 +234,11 @@ bool Room::handleActionWithBitmask(const Action &action) {
return false;
}

bool Room::handleActionWithBitmask(byte type, byte b1, byte b2, byte b3) {
Action a = {type, b1, b2, b3};
return handleActionWithBitmask(a);
}

Common::Point Room::getBeamInPosition(int crewmanIndex) {
int base = RDF_BEAM_IN_POSITIONS + crewmanIndex * 4;
return Common::Point(readRdfWord(base), readRdfWord(base + 2));
@@ -69,12 +69,14 @@ class Room {
// words 0x0e and 0x10 in RDF file are pointers to start and end of event code.
// That code is instead rewritten on a per-room basis.
bool actionHasCode(const Action &action);
bool actionHasCode(byte type, byte b1, byte b2, byte b3);

bool handleAction(const Action &action);
bool handleAction(byte type, byte b1, byte b2, byte b3) { return handleAction(Action(type, b1, b2, b3)); };
bool handleAction(byte type, byte b1, byte b2, byte b3);

// Same as above, but if any byte in the action is -1 (0xff), it matches any value.
bool handleActionWithBitmask(const Action &action);
bool handleActionWithBitmask(byte type, byte b1, byte b2, byte b3) { return handleActionWithBitmask(Action(type, b1, b2, b3)); };
bool handleActionWithBitmask(byte type, byte b1, byte b2, byte b3);

uint16 getFirstHotspot() { return readRdfWord(0x12); }
uint16 getHotspotEnd() { return readRdfWord(0x14); }
Oops, something went wrong.

0 comments on commit 8c71f2d

Please sign in to comment.