Skip to content

Commit

Permalink
SHERLOCK: More replacing numbers with constants
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed May 18, 2015
1 parent 59993fd commit b760c7d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 33 deletions.
28 changes: 15 additions & 13 deletions engines/sherlock/journal.cpp
Expand Up @@ -29,7 +29,7 @@ namespace Sherlock {
#define LINES_PER_PAGE 11

// Positioning of buttons in the journal view
const int JOURNAL_POINTS[9][3] = {
static const int JOURNAL_POINTS[9][3] = {
{ 6, 68, 37 },
{ 69, 131, 100 },
{ 132, 192, 162 },
Expand All @@ -41,7 +41,7 @@ const int JOURNAL_POINTS[9][3] = {
{ 237, 313, 275 }
};

const int SEARCH_POINTS[3][3] = {
static const int SEARCH_POINTS[3][3] = {
{ 51, 123, 86 },
{ 124, 196, 159 },
{ 197, 269, 232 }
Expand Down Expand Up @@ -146,6 +146,8 @@ void Journal::loadJournalFile(bool alreadyLoaded) {

Common::String dirFilename = _directory[journalEntry._converseNum];
bool replyOnly = journalEntry._replyOnly;

// Get the location number from within the filename
Common::String locStr(dirFilename.c_str() + 4, dirFilename.c_str() + 6);
int newLocation = atoi(locStr.c_str());

Expand Down Expand Up @@ -195,11 +197,11 @@ void Journal::loadJournalFile(bool alreadyLoaded) {

// See if title can fit into a single line, or requires splitting on 2 lines
int width = screen.stringWidth(journalString.c_str() + 1);
if (width > 230) {
if (width > JOURNAL_MAX_WIDTH) {
// Scan backwards from end of title to find a space between a word
// where the width is less than the maximum allowed for the line
const char *lineP = journalString.c_str() + journalString.size() - 1;
while (width > 230 || *lineP != ' ')
while (width > JOURNAL_MAX_WIDTH || *lineP != ' ')
width -= screen.charWidth(*lineP--);

// Split the header into two lines, and add a '@' prefix
Expand Down Expand Up @@ -249,7 +251,7 @@ void Journal::loadJournalFile(bool alreadyLoaded) {
byte c = *replyP++;

// Is it a control character?
if (c < 128) {
if (c < SWITCH_SPEAKER) {
// Nope. Set flag for allowing control codes to insert spaces
ctrlSpace = true;
assert(c >= ' ');
Expand Down Expand Up @@ -296,7 +298,7 @@ void Journal::loadJournalFile(bool alreadyLoaded) {
byte v;
do {
v = *strP++;
} while (v && (v < 128) && (v != '.') && (v != '!') && (v != '?'));
} while (v && (v < SWITCH_SPEAKER) && (v != '.') && (v != '!') && (v != '?'));

if (v == '?')
journalString += " asked, \"";
Expand All @@ -312,11 +314,11 @@ void Journal::loadJournalFile(bool alreadyLoaded) {
journalString += c;
do {
journalString += *replyP++;
} while (*replyP && *replyP < 128 && *replyP != '{' && *replyP != '}');
} while (*replyP && *replyP < SWITCH_SPEAKER && *replyP != '{' && *replyP != '}');

commentJustPrinted = false;
}
} else if (c == 128) {
} else if (c == SWITCH_SPEAKER) {
if (!startOfReply) {
if (!commentFlag && !commentJustPrinted)
journalString += "\"\n";
Expand All @@ -343,7 +345,7 @@ void Journal::loadJournalFile(bool alreadyLoaded) {
byte v;
do {
v = *strP++;
} while (v && v < 128 && v != '.' && v != '!' && v != '?');
} while (v && v < SWITCH_SPEAKER && v != '.' && v != '!' && v != '?');

if (v == '?')
journalString += " asked, \"";
Expand Down Expand Up @@ -403,7 +405,7 @@ void Journal::loadJournalFile(bool alreadyLoaded) {

// Put a space in the output for a control character, unless it's
// immediately coming after another control character
if (ctrlSpace && c != 130 && c != 161 && !commentJustPrinted) {
if (ctrlSpace && c != ASSIGN_PORTRAIT_LOCATION && c != CARRIAGE_RETURN && !commentJustPrinted) {
journalString += " ";
ctrlSpace = false;
}
Expand All @@ -429,11 +431,11 @@ void Journal::loadJournalFile(bool alreadyLoaded) {
// Build up chacters until a full line is found
int width = 0;
const char *endP = startP;
while (width < 230 && *endP && *endP != '\n' && (endP - startP) < 79)
while (width < JOURNAL_MAX_WIDTH && *endP && *endP != '\n' && (endP - startP) < (JOURNAL_MAX_CHARS - 1))
width += screen.charWidth(*endP++);

// If word wrapping, move back to end of prior word
if (width >= 230 || (endP - startP) >= 79) {
if (width >= JOURNAL_MAX_WIDTH || (endP - startP) >= (JOURNAL_MAX_CHARS - 1)) {
while (*--endP != ' ')
;
}
Expand Down Expand Up @@ -518,7 +520,7 @@ void Journal::drawInterface() {

drawJournalFrame();

if (_journal.size() == 0) {
if (_journal.empty()) {
_up = _down = 0;
} else {
drawJournal(0, 0);
Expand Down
3 changes: 3 additions & 0 deletions engines/sherlock/journal.h
Expand Up @@ -31,6 +31,9 @@

namespace Sherlock {

#define JOURNAL_MAX_WIDTH 230
#define JOURNAL_MAX_CHARS 80

struct JournalEntry {
int _converseNum;
bool _replyOnly;
Expand Down
2 changes: 1 addition & 1 deletion engines/sherlock/scene.cpp
Expand Up @@ -1364,7 +1364,7 @@ void Scene::doBgAnim() {
_animating = 0;
screen.slamRect(Common::Rect(0, 0, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCENE_HEIGHT));
} else {
if (people[AL]._type != INVALID && ((_goToScene == -1 || _canimShapes.size() == 0))) {
if (people[AL]._type != INVALID && ((_goToScene == -1 || _canimShapes.empty()))) {
if (people[AL]._type == REMOVE) {
screen.slamRect(Common::Rect(
people[AL]._oldPosition.x, people[AL]._oldPosition.y,
Expand Down
40 changes: 21 additions & 19 deletions engines/sherlock/talk.cpp
Expand Up @@ -26,6 +26,8 @@

namespace Sherlock {

#define SPEAKER_REMOVE 0x80

SequenceEntry::SequenceEntry() {
_objNum = 0;
_frameNumber = 0;
Expand Down Expand Up @@ -221,7 +223,7 @@ void Talk::talkTo(const Common::String &filename) {
break;

case TALK_MODE:
if (_speaker < 128)
if (_speaker < SPEAKER_REMOVE)
people.clearTalking();
if (_talkCounter)
return;
Expand Down Expand Up @@ -464,7 +466,7 @@ void Talk::talk(int objNum) {

ui._windowBounds.top = CONTROLS_Y;
ui._infoFlag = true;
_speaker = 128;
_speaker = SPEAKER_REMOVE;
loadTalkFile(scene._bgShapes[objNum]._name);

// Find the first statement with the correct flags
Expand Down Expand Up @@ -769,11 +771,11 @@ int Talk::talkLine(int lineNum, int stateNum, byte color, int lineY, bool slamIt
bool numberFlag = false;

// Get the statement to display as well as optional number prefix
if (idx < 128) {
if (idx < SPEAKER_REMOVE) {
number = Common::String::format("%d.", stateNum + 1);
numberFlag = true;
} else {
idx -= 128;
idx -= SPEAKER_REMOVE;
}
msg = _statements[idx]._statement;

Expand Down Expand Up @@ -1019,7 +1021,7 @@ void Talk::doScript(const Common::String &script) {
// Check if the script begins with a Stealh Mode Active command
if (str[0] == STEALTH_MODE_ACTIVE || _talkStealth) {
_talkStealth = 2;
_speaker |= 128;
_speaker |= SPEAKER_REMOVE;
} else {
pushSequence(_speaker);
ui.clearWindow();
Expand Down Expand Up @@ -1077,11 +1079,11 @@ void Talk::doScript(const Common::String &script) {
// Start of comment, so skip over it
while (*str++ != '}')
;
} else if (c >= 128) {
} else if (c >= SWITCH_SPEAKER) {
// Handle control code
switch (c) {
case SWITCH_SPEAKER:
if (!(_speaker & 128))
if (!(_speaker & SPEAKER_REMOVE))
people.clearTalking();
if (_talkToAbort)
return;
Expand All @@ -1099,7 +1101,7 @@ void Talk::doScript(const Common::String &script) {

case RUN_CANIMATION:
++str;
scene.startCAnim((str[0] - 1) & 127, (str[0] & 128) ? -1 : 1);
scene.startCAnim((str[0] - 1) & 127, (str[0] & 0x80) ? -1 : 1);
if (_talkToAbort)
return;

Expand Down Expand Up @@ -1135,13 +1137,13 @@ void Talk::doScript(const Common::String &script) {
break;

case REMOVE_PORTRAIT:
if (_speaker >= 0 && _speaker < 128)
if (_speaker >= 0 && _speaker < SPEAKER_REMOVE)
people.clearTalking();
pullSequence();
if (_talkToAbort)
return;

_speaker |= 128;
_speaker |= SPEAKER_REMOVE;
break;

case CLEAR_WINDOW:
Expand All @@ -1167,7 +1169,7 @@ void Talk::doScript(const Common::String &script) {
error("Could not find object %s to change", tempString.c_str());

// Should the script be overwritten?
if (str[0] > 128) {
if (str[0] > 0x80) {
// Save the current sequence
_savedSequences.push(SequenceEntry());
SequenceEntry &seqEntry = _savedSequences.top();
Expand Down Expand Up @@ -1216,14 +1218,14 @@ void Talk::doScript(const Common::String &script) {
break;

case BANISH_WINDOW:
if (!(_speaker & 128))
if (!(_speaker & SPEAKER_REMOVE))
people.clearTalking();
pullSequence();

if (_talkToAbort)
return;

_speaker |= 128;
_speaker |= SPEAKER_REMOVE;
ui.banishWindow();
ui._menuMode = TALK_MODE;
noTextYet = true;
Expand Down Expand Up @@ -1367,7 +1369,7 @@ void Talk::doScript(const Common::String &script) {
tempString += str[idx + 1];

// Set comparison state according to if we want to hide or unhide
bool state = (str[0] >= 128);
bool state = (str[0] >= SPEAKER_REMOVE);
str += str[0] & 127;

for (uint idx = 0; idx < scene._bgShapes.size(); ++idx) {
Expand Down Expand Up @@ -1501,10 +1503,10 @@ void Talk::doScript(const Common::String &script) {
width += screen.charWidth(str[idx]);
++idx;
++charCount;
} while (width < 298 && str[idx] && str[idx] != '{' && str[idx] < 128);
} while (width < 298 && str[idx] && str[idx] != '{' && str[idx] < SWITCH_SPEAKER);

if (str[idx] || width >= 298) {
if (str[idx] < 128 && str[idx] != '{') {
if (str[idx] < SWITCH_SPEAKER && str[idx] != '{') {
--idx;
--charCount;
}
Expand Down Expand Up @@ -1544,7 +1546,7 @@ void Talk::doScript(const Common::String &script) {
str += idx;

// If line wrap occurred, then move to after the separating space between the words
if (str[0] < 128 && str[0] != '{')
if (str[0] < SWITCH_SPEAKER && str[0] != '{')
++str;

yp += 9;
Expand Down Expand Up @@ -1574,7 +1576,7 @@ void Talk::doScript(const Common::String &script) {
}

// Open window if it wasn't already open, and text has already been printed
if ((openTalkWindow && wait) || (openTalkWindow && str[0] >= 128 && str[0] != CARRIAGE_RETURN)) {
if ((openTalkWindow && wait) || (openTalkWindow && str[0] >= SWITCH_SPEAKER && str[0] != CARRIAGE_RETURN)) {
if (!ui._windowStyle) {
screen.slamRect(Common::Rect(0, CONTROLS_Y, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT));
} else {
Expand Down Expand Up @@ -1624,7 +1626,7 @@ void Talk::doScript(const Common::String &script) {
}

pullSequence();
if (_speaker >= 0 && _speaker < 128)
if (_speaker >= 0 && _speaker < SPEAKER_REMOVE)
people.clearTalking();
}
}
Expand Down

0 comments on commit b760c7d

Please sign in to comment.