Skip to content
Permalink
Browse files

STARTREK: Handle shared messages

Also, start moving message patches inside patchRoomMessage(), and
remove some redundant state variables
  • Loading branch information...
bluegr committed Oct 6, 2019
1 parent 7caf897 commit 95f8cfff1602d92178eea875794f83da548566c5
@@ -151,43 +151,85 @@ void Room::loadRoomMessages() {
void Room::loadRoomMessage(const char *text) {
int messageNum;
bool isTalkMessage;
bool isLookMessage;
bool isLookWithTalkerMessage;

Common::String patchedText = patchRoomMessage(text);
text = patchedText.c_str();

char textType = text[10]; // _ and U: talk message, N: look message, L: look with talker message

if (text[5] != '\\')
error("loadRoomMessage: Invalid message");

isTalkMessage = (textType == '_' || textType == 'U'); // U = Uhura
isLookMessage = (textType == 'N');
isLookWithTalkerMessage = (textType == 'L');

sscanf((const char *)(text + 11), "%3d", &messageNum);
if (text[14] != '#')
error("loadRoomMessage: Invalid message");

if (memcmp(text + 1, _vm->_missionName.c_str(), 3) || text[4] != _vm->_roomIndex + '0') {
// String with a prefix of another mission, separate it
messageNum += COMMON_MESSAGE_OFFSET;
}

if (isTalkMessage)
_talkMessages[messageNum] = Common::String((const char *)text);
_talkMessages[messageNum] = text;
else if (isLookMessage)
_lookMessages[messageNum] = text;
else if (isLookWithTalkerMessage)
_lookWithTalkerMessages[messageNum] = Common::String((const char *)text);
else
_lookMessages[messageNum] = Common::String((const char *)text);
_lookWithTalkerMessages[messageNum] = text;
}

Common::String Room::patchRoomMessage(const char *text) {
Common::String txt = text;

// Fix typos where some messages contain a hyphen instead of an underscore
// (e.g in LOV2)
if (txt[10] == '-')
txt.replace(10, 1, "_");

// Message index missing
if (txt.hasPrefix("#LOV3\\LOV3_#"))
txt = Common::String("#LOV3\\LOV3_000#") + (text + 12);

// Should be TX_LOV2_012, but the audio file is missing
if (txt.hasPrefix("#LOV2\\LOV2_012#"))
txt = Common::String("#LOV1\\LOV1_010#") + (text + 14);

// Original voice clip is someone who's clearly not Kelley saying "he's dead, Jim"
if (txt.hasPrefix("#FEA3\\FEA3_030#"))
txt = Common::String("#LOVA\\LOVA_100#") + (text + 14);

return txt;
}

void Room::loadOtherRoomMessages() {
uint16 startOffset = readRdfWord(14);
uint16 endOffset = readRdfWord(16);
uint16 offset = startOffset;
const char *validPrefixes[] = {
"BRI", "COM", "DEM", "FEA", "GEN", "LOV", "MUD", "SIN", "TRI", "TUG", "VEN"
};

while (offset < endOffset) {
uint16 nextOffset = readRdfWord(offset + 4);
if (nextOffset >= endOffset)
break;

while (offset < nextOffset) {
const char *text = (const char *)_rdfData + offset;

if (text[0] == '#' && text[1] == _vm->_missionName[0] && text[5] == '\\')
loadRoomMessage(text);
if (text[0] == '#' && text[5] == '\\') {
for (uint i = 0; i < ARRAYSIZE(validPrefixes); i++) {
if (!memcmp(text + 1, validPrefixes[i], 3)) {
loadRoomMessage(text);
break;
}
}
}

offset++;
}
@@ -383,11 +425,11 @@ int Room::showMultipleTexts(const TextRef *textIDs, bool fromRDF, bool lookWithT
// TODO: This isn't nice, but it's temporary till we migrate to reading text from RDF files
if (i > 0 && fromRDF) {
if (textIDs[0] == TX_NULL)
text[i] = _lookMessages[textIDs[i]].c_str();
text[i] = _lookMessages.contains(textIDs[i]) ? _lookMessages[textIDs[i]].c_str() : _lookMessages[textIDs[i] - COMMON_MESSAGE_OFFSET].c_str();
else if (lookWithTalker)
text[i] = _lookWithTalkerMessages[textIDs[i]].c_str();
text[i] = _lookWithTalkerMessages.contains(textIDs[i]) ? _lookWithTalkerMessages[textIDs[i]].c_str() : _lookWithTalkerMessages[textIDs[i] - COMMON_MESSAGE_OFFSET].c_str();
else
text[i] = _talkMessages[textIDs[i]].c_str();
text[i] = _talkMessages.contains(textIDs[i]) ? _talkMessages[textIDs[i]].c_str() : _talkMessages[textIDs[i] - COMMON_MESSAGE_OFFSET].c_str();
} else
text[i] = g_gameStrings[textIDs[i]];
}
@@ -61,6 +61,8 @@ const int RDF_ROOM_ENTRY_POSITIONS = 0x2a;
const int RDF_BEAM_IN_POSITIONS = 0xaa;
const int RDF_SPAWN_POSITIONS = 0xba;

#define COMMON_MESSAGE_OFFSET 1000

class Room {
public:
Room(StarTrekEngine *vm, const Common::String &name);
@@ -162,6 +164,7 @@ class Room {
void loadRoomMessages();
void loadOtherRoomMessages();
void loadRoomMessage(const char *text);
Common::String patchRoomMessage(const char *text);

int findFunctionPointer(int action, void (Room::*funcPtr)());

@@ -2996,10 +2999,6 @@ class Room {
struct {
// love0
bool heardSummaryOfVirus; // 0xda
int16 consoleCrewman; // 0xe3
char consoleAnimation[10]; // 0xe5
TextRef consoleSpeaker; // 0xe7
TextRef consoleText; // 0xe9

// love1
TextRef dyingSpeaker; // 0xcf
@@ -3037,10 +3036,13 @@ class Room {
void saveLoadWithSerializer(Common::Serializer &ser) {
// love0
ser.syncAsByte(heardSummaryOfVirus);
ser.syncAsSint16LE(consoleCrewman);
ser.syncBytes((byte *)consoleAnimation, 10);
ser.syncAsSint32LE(consoleSpeaker);
ser.syncAsSint32LE(consoleText);
uint16 tmp = 0;
uint32 tmp2 = 0;
byte tmp3[10];
ser.syncAsSint16LE(tmp); // consoleCrewman
ser.syncBytes((byte *)tmp3, 10); // consoleAnimation
ser.syncAsSint32LE(tmp2); // consoleSpeaker
ser.syncAsSint32LE(tmp2); // consoleText

// love1
ser.syncAsSint32LE(dyingSpeaker);
@@ -334,12 +334,8 @@ void Room::feather3UseMedkitOnTlaoxac() {
}

void Room::feather3UseMedkitOnRedshirt() {
if (_awayMission->redshirtDead) {
// BUGFIX: Original voice clip (TX_FEA3_030) is someone who's clearly not Kelley
// saying "he's dead, Jim". He recorded the line a few other times, so use one of
// those instead.
mccoyScan(DIR_N, TX_LOVA_100);
}
if (_awayMission->redshirtDead)
mccoyScan(DIR_N, 30, true);
}

void Room::feather3UseMedkitAnywhere() {
@@ -174,20 +174,15 @@ void Room::love0UseRedshirtOnConsole() {
}

void Room::love0UseSpockOnConsole() {
_roomVar.love.consoleCrewman = OBJECT_SPOCK;
_roomVar.love.consoleSpeaker = TX_SPEAKER_SPOCK;
_roomVar.love.consoleText = TX_LOV0_005;
strcpy(_roomVar.love.consoleAnimation, "susemn");

walkCrewman(_roomVar.love.consoleCrewman, 0x9a, 0x9a, 2);
walkCrewman(OBJECT_SPOCK, 0x9a, 0x9a, 2);
if (!_awayMission->love.spockAccessedConsole) {
_awayMission->love.spockAccessedConsole = true;
_awayMission->love.missionScore += 4;
}
}

void Room::love0SpockReachedConsole() {
loadActorAnim2(_roomVar.love.consoleCrewman, _roomVar.love.consoleAnimation, -1, -1, 5);
loadActorAnim2(OBJECT_SPOCK, "susemn", -1, -1, 5);
}

void Room::love0SpockAccessedConsole() {
@@ -196,7 +191,7 @@ void Room::love0SpockAccessedConsole() {
love0InteractWithConsole();
else {
showText(TX_SPEAKER_COMPUTER, TX_COMPU188);
showText(_roomVar.love.consoleSpeaker, _roomVar.love.consoleText);
showText(TX_SPEAKER_SPOCK, 5, true);
_roomVar.love.heardSummaryOfVirus = true;
}
}
@@ -293,9 +293,7 @@ void Room::love2UseMTricorderAnywhere() {
if (_awayMission->love.knowAboutVirus)
mccoyScan(DIR_S, 8, false, true);
else
// BUGFIX: should be TX_LOV2_012, but the audio file is missing. Using equivalent
// audio from another room.
mccoyScan(DIR_S, TX_LOV1_010, false);
mccoyScan(DIR_S, 12, false);
}

void Room::love2UseSTricorderAnywhere() {
@@ -29,33 +29,8 @@ namespace StarTrek {

// Mccoy or Ferris say something under effects of laughing gas
void Room::loveaTimer0Expired() {
const TextRef ferrisText[] = {
TX_LOV0_039,
TX_LOV0_048,
TX_LOV0_045,
TX_LOV0_040,
TX_LOV0_042,
TX_LOV0_050,
TX_LOV0_043,
TX_LOV0_041,
TX_LOV0_047,
TX_LOV0_046,
TX_LOV0_039
};

const TextRef mccoyText[] = {
TX_LOV0_011,
TX_LOV0_020,
TX_LOV0_016,
TX_LOV0_012,
TX_LOV0_014,
TX_LOV0_022,
TX_LOV0_015,
TX_LOV0_021,
TX_LOV0_013,
TX_LOV0_019,
TX_LOV0_017
};
const TextRef ferrisText[] = { 39, 48, 45, 40, 42, 50, 43, 41, 47, 46, 39 };
const TextRef mccoyText[] = { 11, 20, 16, 12, 14, 22, 15, 21, 13, 19, 17 };

// BUGFIX: should range from 0-1, not 0-2. Original had "get name errors" when it
// rolled a 2.
@@ -74,16 +49,11 @@ void Room::loveaTimer0Expired() {

randomVal = getRandomWordInRange(0, 10);

showText(speaker, textTable[randomVal]);
showText(speaker, COMMON_MESSAGE_OFFSET + textTable[randomVal], true);

if (!_awayMission->love.releasedRomulanLaughingGas) {
const int spockText[] = {
TX_LOV0_029,
TX_LOV0_033,
TX_LOV0_026,
TX_LOV0_124
};
showText(TX_SPEAKER_SPOCK, spockText[getRandomWordInRange(0, 3)]);
const int spockText[] = { 29, 33, 26, 124 };
showText(TX_SPEAKER_SPOCK, COMMON_MESSAGE_OFFSET + spockText[getRandomWordInRange(0, 3)], true);

// BUG(?): This is in an if statement, meaning the human crewmen stop talking from
// laughing gas if Spock is under laughing gas effects. Might be intentional, to
@@ -94,27 +64,16 @@ void Room::loveaTimer0Expired() {

// Spock says something under effects of laughing gas
void Room::loveaTimer1Expired() {
const int spockText[] = {
TX_LOV0_025,
TX_LOV0_101,
TX_LOV0_102,
TX_LOV0_103,
TX_LOV0_104,
TX_LOV0_105,
TX_LOV0_106,
TX_LOV0_107
};

showText(TX_SPEAKER_SPOCK, spockText[getRandomWordInRange(0, 7)]);

const int spockText[] = { 25, 101, 102, 103, 104, 105, 106, 107 };
showText(TX_SPEAKER_SPOCK, COMMON_MESSAGE_OFFSET + spockText[getRandomWordInRange(0, 7)], true);
_awayMission->timers[1] = getRandomWordInRange(200, 400);
}

void Room::loveaUseMedkitOnSpock() {
if (_awayMission->love.spockCured)
showText(TX_SPEAKER_MCCOY, TX_LOV5_015);
showText(TX_SPEAKER_MCCOY, COMMON_MESSAGE_OFFSET + 15, true);
else
showText(TX_SPEAKER_MCCOY, TX_LOV5_019);
showText(TX_SPEAKER_MCCOY, COMMON_MESSAGE_OFFSET + 19, true);
}

void Room::loveaUseCureSampleOnSpock() {
@@ -128,7 +87,7 @@ void Room::loveaUseCureSampleOnSpock() {

void Room::loveaUseCureOnSpock() {
if (_awayMission->love.spockCured)
showText(TX_SPEAKER_MCCOY, TX_LOV5_015);
showText(TX_SPEAKER_MCCOY, COMMON_MESSAGE_OFFSET + 15, true);
else {
walkCrewman(OBJECT_SPOCK, _roomVar.love.cmnXPosToCureSpock, _roomVar.love.cmnYPosToCureSpock, 99);
walkCrewman(OBJECT_MCCOY, _roomVar.love.cmnXPosToCureSpock, _roomVar.love.cmnYPosToCureSpock + 10, 99);
@@ -142,9 +101,9 @@ void Room::loveaSpockOrMccoyInPositionToUseCure() {
}

void Room::loveaFinishedCuringSpock() {
showText(TX_SPEAKER_MCCOY, TX_LOV5_030);
showText(TX_SPEAKER_SPOCK, TX_LOV5_038);
showText(TX_SPEAKER_MCCOY, TX_LOV5_027);
showText(TX_SPEAKER_MCCOY, COMMON_MESSAGE_OFFSET + 30, true);
showText(TX_SPEAKER_SPOCK, COMMON_MESSAGE_OFFSET + 38, true);
showText(TX_SPEAKER_MCCOY, COMMON_MESSAGE_OFFSET + 27, true);
showText(TX_SPEAKER_SPOCK, TX_LOV5C001);
_awayMission->love.spockCured = true;
}
@@ -195,11 +154,11 @@ void Room::loveaUseMTricorderOnSpock() {
else if (_awayMission->love.spockInfectionCounter < 50)
showText(TX_SPEAKER_MCCOY, TX_LOVA_F08);
else if (_awayMission->love.spockInfectionCounter < 70) // BUGFIX: < 70 instead of == 70
showText(TX_SPEAKER_MCCOY, TX_TUG2_010);
showText(TX_SPEAKER_MCCOY, COMMON_MESSAGE_OFFSET + 10, true); // TX_TUG2_010
else if (_awayMission->love.spockInfectionCounter < 100)
showText(TX_SPEAKER_MCCOY, TX_LOVA_F10);
else
showText(TX_SPEAKER_MCCOY, TX_LOVA_100);
showText(TX_SPEAKER_MCCOY, COMMON_MESSAGE_OFFSET + 100);
}

void Room::loveaUseMTricorderOnHuman() {
@@ -208,7 +167,7 @@ void Room::loveaUseMTricorderOnHuman() {
}

void Room::loveaUseRomulanLaughingGas() {
showDescription(TX_LOV2N005);
showDescription(COMMON_MESSAGE_OFFSET + 2, true);
_awayMission->love.releasedRomulanLaughingGas = true;
loseItem(OBJECT_IRLG);

@@ -217,7 +176,7 @@ void Room::loveaUseRomulanLaughingGas() {
}

void Room::loveaUseHumanLaughingGas() {
showDescription(TX_LOV2N005);
showDescription(COMMON_MESSAGE_OFFSET + 5, true);
showText(TX_SPEAKER_SPOCK, TX_MUD2_040);
_awayMission->love.releasedHumanLaughingGas = true;
loseItem(OBJECT_IN2O);
@@ -228,7 +187,7 @@ void Room::loveaUseHumanLaughingGas() {
}

void Room::loveaUseAmmonia() {
showDescription(TX_LOV2N005);
showDescription(COMMON_MESSAGE_OFFSET + 5, true);
// TODO: redshirt says something in floppy edition only
loseItem(OBJECT_INH3);
}
@@ -203,7 +203,7 @@ void Room::mudd0PickedUpLense() {

void Room::mudd0PickedUpItem() {
_awayMission->disableInput = false; // NOTE: this was never set to true
showDescription(TX_LOV1N007);
showDescription(COMMON_MESSAGE_OFFSET + 7, true); // TX_LOV1N007
}


@@ -605,7 +605,7 @@ void Room::tug2TalkToSpock() {
}

void Room::tug2UseCommunicator() {
showText(TX_SPEAKER_SPOCK, TX_TUG1_011);
showText(TX_SPEAKER_SPOCK, COMMON_MESSAGE_OFFSET + 11, true);
}

void Room::tug2DetermineElasiShooter() {

0 comments on commit 95f8cff

Please sign in to comment.
You can’t perform that action at this time.