aboutsummaryrefslogtreecommitdiff
path: root/engines/agi
diff options
context:
space:
mode:
Diffstat (limited to 'engines/agi')
-rw-r--r--engines/agi/agi.cpp2
-rw-r--r--engines/agi/detection.cpp2
-rw-r--r--engines/agi/preagi_winnie.cpp81
-rw-r--r--engines/agi/sound.cpp2
-rw-r--r--engines/agi/sound_2gs.cpp12
-rw-r--r--engines/agi/sound_2gs.h4
-rw-r--r--engines/agi/sound_midi.cpp10
-rw-r--r--engines/agi/sound_pcjr.h4
-rw-r--r--engines/agi/sound_sarien.cpp4
-rw-r--r--engines/agi/text.cpp5
-rw-r--r--engines/agi/wagparser.cpp4
11 files changed, 66 insertions, 64 deletions
diff --git a/engines/agi/agi.cpp b/engines/agi/agi.cpp
index 811a58f45d..0eefbab04d 100644
--- a/engines/agi/agi.cpp
+++ b/engines/agi/agi.cpp
@@ -188,7 +188,7 @@ void AgiEngine::processEvents() {
case Common::KEYCODE_KP5:
if (_predictiveDialogRunning)
key = event.kbd.ascii;
- else
+ else
key = KEY_STATIONARY;
break;
case Common::KEYCODE_PLUS:
diff --git a/engines/agi/detection.cpp b/engines/agi/detection.cpp
index 21ff5deb2c..a0736d0cc3 100644
--- a/engines/agi/detection.cpp
+++ b/engines/agi/detection.cpp
@@ -473,7 +473,7 @@ bool AgiBase::canLoadGameStateCurrently() {
bool AgiBase::canSaveGameStateCurrently() {
if (getGameID() == GID_BC) // Technically in Black Cauldron we may save anytime
return true;
-
+
return (!(getGameType() == GType_PreAGI) && getflag(fMenusWork) && !_noSaveLoadAllowed && _game.inputEnabled);
}
diff --git a/engines/agi/preagi_winnie.cpp b/engines/agi/preagi_winnie.cpp
index 1df31ff72a..af26fe62d0 100644
--- a/engines/agi/preagi_winnie.cpp
+++ b/engines/agi/preagi_winnie.cpp
@@ -86,27 +86,30 @@ void Winnie::parseObjHeader(WTP_OBJ_HDR *objHdr, byte *buffer, int len) {
}
uint32 Winnie::readRoom(int iRoom, uint8 *buffer, WTP_ROOM_HDR &roomHdr) {
- char szFile[256] = {0};
+ Common::String fileName;
if (_vm->getPlatform() == Common::kPlatformPC)
- sprintf(szFile, IDS_WTP_ROOM_DOS, iRoom);
+ fileName = Common::String::format(IDS_WTP_ROOM_DOS, iRoom);
else if (_vm->getPlatform() == Common::kPlatformAmiga)
- sprintf(szFile, IDS_WTP_ROOM_AMIGA, iRoom);
+ fileName = Common::String::format(IDS_WTP_ROOM_AMIGA, iRoom);
else if (_vm->getPlatform() == Common::kPlatformC64)
- sprintf(szFile, IDS_WTP_ROOM_C64, iRoom);
+ fileName = Common::String::format(IDS_WTP_ROOM_C64, iRoom);
else if (_vm->getPlatform() == Common::kPlatformApple2GS)
- sprintf(szFile, IDS_WTP_ROOM_APPLE, iRoom);
+ fileName = Common::String::format(IDS_WTP_ROOM_APPLE, iRoom);
+
Common::File file;
- if (!file.open(szFile)) {
- warning ("Could not open file \'%s\'", szFile);
+ if (!file.open(fileName)) {
+ warning("Could not open file \'%s\'", fileName.c_str());
return 0;
}
+
uint32 filelen = file.size();
- if (_vm->getPlatform() == Common::kPlatformC64) { //Skip the loading address
+ if (_vm->getPlatform() == Common::kPlatformC64) { // Skip the loading address
filelen -= 2;
file.seek(2, SEEK_CUR);
}
- memset(buffer, 0, sizeof(buffer));
+
+ memset(buffer, 0, 4096);
file.read(buffer, filelen);
file.close();
@@ -116,26 +119,30 @@ uint32 Winnie::readRoom(int iRoom, uint8 *buffer, WTP_ROOM_HDR &roomHdr) {
}
uint32 Winnie::readObj(int iObj, uint8 *buffer) {
- char szFile[256] = {0};
+ Common::String fileName;
+
if (_vm->getPlatform() == Common::kPlatformPC)
- sprintf(szFile, IDS_WTP_OBJ_DOS, iObj);
+ fileName = Common::String::format(IDS_WTP_OBJ_DOS, iObj);
else if (_vm->getPlatform() == Common::kPlatformAmiga)
- sprintf(szFile, IDS_WTP_OBJ_AMIGA, iObj);
+ fileName = Common::String::format(IDS_WTP_OBJ_AMIGA, iObj);
else if (_vm->getPlatform() == Common::kPlatformC64)
- sprintf(szFile, IDS_WTP_OBJ_C64, iObj);
+ fileName = Common::String::format(IDS_WTP_OBJ_C64, iObj);
else if (_vm->getPlatform() == Common::kPlatformApple2GS)
- sprintf(szFile, IDS_WTP_OBJ_APPLE, iObj);
+ fileName = Common::String::format(IDS_WTP_OBJ_APPLE, iObj);
+
Common::File file;
- if (!file.open(szFile)) {
- warning ("Could not open file \'%s\'", szFile);
+ if (!file.open(fileName)) {
+ warning ("Could not open file \'%s\'", fileName.c_str());
return 0;
}
+
uint32 filelen = file.size();
- if (_vm->getPlatform() == Common::kPlatformC64) { //Skip the loading address
+ if (_vm->getPlatform() == Common::kPlatformC64) { // Skip the loading address
filelen -= 2;
file.seek(2, SEEK_CUR);
}
- memset(buffer, 0, sizeof(buffer));
+
+ memset(buffer, 0, 2048);
file.read(buffer, filelen);
file.close();
return filelen;
@@ -461,8 +468,6 @@ void Winnie::keyHelp() {
}
void Winnie::inventory() {
- char szMissing[41] = {0};
-
if (_game.iObjHave)
printObjStr(_game.iObjHave, IDI_WTP_OBJ_TAKE);
else {
@@ -470,8 +475,9 @@ void Winnie::inventory() {
_vm->drawStr(IDI_WTP_ROW_MENU, IDI_WTP_COL_MENU, IDA_DEFAULT, IDS_WTP_INVENTORY_0);
}
- sprintf(szMissing, IDS_WTP_INVENTORY_1, _game.nObjMiss);
- _vm->drawStr(IDI_WTP_ROW_OPTION_4, IDI_WTP_COL_MENU, IDA_DEFAULT, szMissing);
+ Common::String missing = Common::String::format(IDS_WTP_INVENTORY_1, _game.nObjMiss);
+
+ _vm->drawStr(IDI_WTP_ROW_OPTION_4, IDI_WTP_COL_MENU, IDA_DEFAULT, missing.c_str());
_vm->_gfx->doUpdate();
_vm->_system->updateScreen(); //TODO: Move to game's main loop
_vm->getSelection(kSelAnyKey);
@@ -1042,16 +1048,15 @@ phase2:
}
void Winnie::drawPic(const char *szName) {
- char szFile[256] = {0};
- Common::File file;
+ Common::String fileName = szName;
- // construct filename
if (_vm->getPlatform() != Common::kPlatformAmiga)
- sprintf(szFile, "%s.pic", szName);
- else
- strcpy(szFile, szName);
- if (!file.open(szFile)) {
- warning ("Could not open file \'%s\'", szFile);
+ fileName += ".pic";
+
+ Common::File file;
+
+ if (!file.open(fileName)) {
+ warning ("Could not open file \'%s\'", fileName.c_str());
return;
}
@@ -1142,12 +1147,11 @@ void Winnie::gameOver() {
}
void Winnie::saveGame() {
- Common::OutSaveFile* outfile;
- char szFile[256] = {0};
int i = 0;
- sprintf(szFile, IDS_WTP_FILE_SAVEGAME);
- if (!(outfile = _vm->getSaveFileMan()->openForSaving(szFile)))
+ Common::OutSaveFile *outfile = _vm->getSaveFileMan()->openForSaving(IDS_WTP_FILE_SAVEGAME);
+
+ if (!outfile)
return;
outfile->writeUint32BE(MKTAG('W','I','N','N')); // header
@@ -1171,19 +1175,18 @@ void Winnie::saveGame() {
outfile->finalize();
if (outfile->err())
- warning("Can't write file '%s'. (Disk full?)", szFile);
+ warning("Can't write file '%s'. (Disk full?)", IDS_WTP_FILE_SAVEGAME);
delete outfile;
}
void Winnie::loadGame() {
- Common::InSaveFile* infile;
- char szFile[256] = {0};
int saveVersion = 0;
int i = 0;
- sprintf(szFile, IDS_WTP_FILE_SAVEGAME);
- if (!(infile = _vm->getSaveFileMan()->openForLoading(szFile)))
+ Common::InSaveFile *infile = _vm->getSaveFileMan()->openForLoading(IDS_WTP_FILE_SAVEGAME);
+
+ if (!infile)
return;
if (infile->readUint32BE() == MKTAG('W','I','N','N')) {
diff --git a/engines/agi/sound.cpp b/engines/agi/sound.cpp
index aa338db0f2..f2d7af32da 100644
--- a/engines/agi/sound.cpp
+++ b/engines/agi/sound.cpp
@@ -144,7 +144,7 @@ void SoundMgr::stopSound() {
// not be any harm doing it, so do it anyway.
if (_endflag != -1)
_vm->setflag(_endflag, true);
-
+
_endflag = -1;
}
diff --git a/engines/agi/sound_2gs.cpp b/engines/agi/sound_2gs.cpp
index 3c8a3dfc8d..38e256aa4b 100644
--- a/engines/agi/sound_2gs.cpp
+++ b/engines/agi/sound_2gs.cpp
@@ -167,12 +167,12 @@ uint SoundGen2GS::generateOutput() {
g->seg++;
}
}
-
+
// TODO: Advance vibrato here. The Apple IIGS uses a LFO with
// triangle wave to modulate the frequency of both oscillators.
// In Apple IIGS the vibrato and the envelope are updated at the
// same time, so the vibrato speed depends on ENVELOPE_COEF.
-
+
// Advance oscillators
int s0 = 0;
int s1 = 0;
@@ -202,12 +202,12 @@ uint SoundGen2GS::generateOutput() {
}
}
}
-
+
// Take envelope and MIDI volume information into account.
// Also amplify.
s0 *= vol * g->vel / 127 * 80 / 256;
s1 *= vol * g->vel / 127 * 80 / 256;
-
+
// Select output channel.
if (g->osc[0].chn)
outl += s0;
@@ -375,7 +375,7 @@ void SoundGen2GS::midiNoteOn(int channel, int note, int velocity) {
IIgsGenerator* g = allocateGenerator();
g->ins = _channels[channel].getInstrument();
const IIgsInstrumentHeader* i = g->ins;
-
+
// Pass information from the MIDI channel to the generator. Take
// velocity into account, although simplistically.
velocity *= 5 / 3;
@@ -385,7 +385,7 @@ void SoundGen2GS::midiNoteOn(int channel, int note, int velocity) {
g->key = note;
g->vel = velocity * _channels[channel].getVolume() / 127;
g->chn = channel;
-
+
// Instruments can define different samples to be used based on
// what the key is. Find the correct samples for our key.
int wa = 0;
diff --git a/engines/agi/sound_2gs.h b/engines/agi/sound_2gs.h
index 1a225300ae..9123e18415 100644
--- a/engines/agi/sound_2gs.h
+++ b/engines/agi/sound_2gs.h
@@ -33,7 +33,7 @@ namespace Agi {
// Apple IIGS to halt the corresponding oscillator immediately. We preprocess
// the sample data by converting it to signed values and the instruments by
// detecting prematurely stopping samples beforehand.
-//
+//
// Note: None of the tested SIERRASTANDARD files have zeroes in them. So in
// practice there is no need to check for them. However, they still do exist
// in the sample resources.
@@ -263,7 +263,7 @@ private:
uint _ticks; ///< MIDI ticks (60Hz)
int16 *_out; ///< Output buffer
uint _outSize; ///< Output buffer size
-
+
static const int kSfxMidiChannel = 15; ///< MIDI channel used for playing sample resources
};
diff --git a/engines/agi/sound_midi.cpp b/engines/agi/sound_midi.cpp
index d2c99171e2..0cbaa4af86 100644
--- a/engines/agi/sound_midi.cpp
+++ b/engines/agi/sound_midi.cpp
@@ -33,7 +33,7 @@
// Timing is not perfect, yet. It plays correct, when I use the
// Gravis-Midiplayer, but the songs are too fast when I use playmidi on
// Linux.
-//
+//
// Original program developed by Jens. Christian Restemeier
//
@@ -114,7 +114,7 @@ void SoundGenMIDI::endOfTrack() {
void SoundGenMIDI::play(int resnum) {
MIDISound *track;
-
+
stop();
_isGM = true;
@@ -153,7 +153,7 @@ unsigned char instr[] = {50, 51, 19};
static void writeDelta(Common::MemoryWriteStreamDynamic *st, int32 delta) {
int32 i;
- i = delta >> 21; if (i > 0) st->writeByte((i & 127) | 128);
+ i = delta >> 21; if (i > 0) st->writeByte((i & 127) | 128);
i = delta >> 14; if (i > 0) st->writeByte((i & 127) | 128);
i = delta >> 7; if (i > 0) st->writeByte((i & 127) | 128);
st->writeByte(delta & 127);
@@ -196,7 +196,7 @@ static uint32 convertSND2MIDI(byte *snddata, byte **data) {
int note;
/* I don't know, what frequency equals midi note 0 ... */
/* This moves the song 4 octaves down: */
- fr = (log10(111860.0 / (double)freq) / ll) - 48;
+ fr = (log10(111860.0 / (double)freq) / ll) - 48;
note = (int)floor(fr + 0.5);
if (note < 0) note = 0;
if (note > 127) note = 127;
@@ -222,7 +222,7 @@ static uint32 convertSND2MIDI(byte *snddata, byte **data) {
st.writeByte(0);
st.writeByte(0);
}
- }
+ }
writeDelta(&st, 0);
st.writeByte(0xff);
st.writeByte(0x2f);
diff --git a/engines/agi/sound_pcjr.h b/engines/agi/sound_pcjr.h
index f50fd0aa82..4317e86516 100644
--- a/engines/agi/sound_pcjr.h
+++ b/engines/agi/sound_pcjr.h
@@ -45,9 +45,9 @@ struct SndGenChan {
uint16 dissolveCount;
byte attenuation;
byte attenuationCopy;
-
+
GenType genType;
-
+
// for the sample mixer
int freqCount;
};
diff --git a/engines/agi/sound_sarien.cpp b/engines/agi/sound_sarien.cpp
index fc9a57791c..9ea8569b81 100644
--- a/engines/agi/sound_sarien.cpp
+++ b/engines/agi/sound_sarien.cpp
@@ -105,7 +105,7 @@ SoundGenSarien::~SoundGenSarien() {
int SoundGenSarien::readBuffer(int16 *buffer, const int numSamples) {
fillAudio(buffer, numSamples / 2);
-
+
return numSamples;
}
@@ -124,7 +124,7 @@ void SoundGenSarien::play(int resnum) {
for (int i = 0; i < NUM_CHANNELS; i++) {
_chn[i].type = type;
_chn[i].flags = AGI_SOUND_LOOP;
-
+
if (_env) {
_chn[i].flags |= AGI_SOUND_ENVELOPE;
_chn[i].adsr = AGI_SOUND_ENV_ATTACK;
diff --git a/engines/agi/text.cpp b/engines/agi/text.cpp
index fedfd29362..82a2340ad6 100644
--- a/engines/agi/text.cpp
+++ b/engines/agi/text.cpp
@@ -504,17 +504,16 @@ int AgiEngine::print(const char *p, int lin, int col, int len) {
*
*/
void AgiEngine::printStatus(const char *message, ...) {
- char x[42];
va_list args;
va_start(args, message);
- vsprintf(x, message, args);
+ Common::String x = Common::String::vformat(message, args);
va_end(args);
debugC(4, kDebugLevelText, "fg=%d, bg=%d", STATUS_FG, STATUS_BG);
- printText(x, 0, 0, _game.lineStatus, 40, STATUS_FG, STATUS_BG);
+ printText(x.c_str(), 0, 0, _game.lineStatus, 40, STATUS_FG, STATUS_BG);
}
static void safeStrcat(Common::String &p, const char *t) {
diff --git a/engines/agi/wagparser.cpp b/engines/agi/wagparser.cpp
index 14159c0147..39f9e0dd92 100644
--- a/engines/agi/wagparser.cpp
+++ b/engines/agi/wagparser.cpp
@@ -112,11 +112,11 @@ WagFileParser::~WagFileParser() {
bool WagFileParser::checkAgiVersionProperty(const WagProperty &version) const {
if (version.getCode() == WagProperty::PC_INTVERSION && // Must be AGI interpreter version property
version.getSize() >= 3 && // Need at least three characters for a version number like "X.Y"
- isdigit(version.getData()[0]) && // And the first character must be a digit
+ isdigit(static_cast<unsigned char>(version.getData()[0])) && // And the first character must be a digit
(version.getData()[1] == ',' || version.getData()[1] == '.')) { // And the second a comma or a period
for (int i = 2; i < version.getSize(); i++) // And the rest must all be digits
- if (!isdigit(version.getData()[i]))
+ if (!isdigit(static_cast<unsigned char>(version.getData()[i])))
return false; // Bail out if found a non-digit after the decimal point
return true;