aboutsummaryrefslogtreecommitdiff
path: root/engines/startrek
diff options
context:
space:
mode:
Diffstat (limited to 'engines/startrek')
-rw-r--r--engines/startrek/actors.cpp30
-rw-r--r--engines/startrek/object.h6
-rw-r--r--engines/startrek/room.cpp10
-rw-r--r--engines/startrek/saveload.cpp12
-rw-r--r--engines/startrek/startrek.cpp2
5 files changed, 32 insertions, 28 deletions
diff --git a/engines/startrek/actors.cpp b/engines/startrek/actors.cpp
index 239818e1ee..876499c14b 100644
--- a/engines/startrek/actors.cpp
+++ b/engines/startrek/actors.cpp
@@ -32,10 +32,10 @@ void StarTrekEngine::initActors() {
for (int i = 0; i < MAX_BAN_FILES; i++)
_banFiles[i].reset();
- strcpy(_kirkActor->animationString, "kstnd");
- strcpy(_spockActor->animationString, "sstnd");
- strcpy(_mccoyActor->animationString, "mstnd");
- strcpy(_redshirtActor->animationString, "rstnd");
+ _kirkActor->animationString = "kstnd";
+ _spockActor->animationString = "sstnd";
+ _mccoyActor->animationString = "mstnd";
+ _redshirtActor->animationString = "rstnd";
}
int StarTrekEngine::loadActorAnim(int actorIndex, const Common::String &animName, int16 x, int16 y, Fixed8 scale) {
@@ -91,7 +91,7 @@ bool StarTrekEngine::actorWalkToPosition(int actorIndex, const Common::String &a
actor->spriteDrawn = true;
actor->animType = 1;
actor->frameToStartNextAnim = _frameIndex + 1;
- strcpy(actor->animationString2, animFile.c_str());
+ actor->animationString2 = animFile;
actor->dest.x = destX;
actor->dest.y = destY;
@@ -111,7 +111,7 @@ bool StarTrekEngine::actorWalkToPosition(int actorIndex, const Common::String &a
if (actor->iwSrcPosition == -1 || actor->iwDestPosition == -1) {
// No path exists; face south by default.
- strcat(actor->animationString2, "S");
+ actor->animationString2 += "S";
actor->direction = 'S';
updateActorPositionWhileWalking(actor, srcX, srcY);
@@ -152,7 +152,7 @@ void StarTrekEngine::updateActorAnimations() {
actor->animFrame = nextAnimFrame;
if (actor->animFrame >= actor->numAnimFrames) {
- if (actor->animationString[0] == '\0')
+ if (actor->animationString.empty())
removeActorFromScreen(i);
else
initStandAnim(i);
@@ -222,7 +222,7 @@ void StarTrekEngine::updateActorAnimations() {
initStandAnim(i);
} else { // actor->iwSrcPosition != -1
if (actor->iwSrcPosition == actor->iwDestPosition) {
- actor->animationString2[strlen(actor->animationString2) - 1] = '\0';
+ actor->animationString2.deleteLastChar();
actor->iwDestPosition = -1;
actor->iwSrcPosition = -1;
chooseActorDirectionForWalking(actor, actor->pos.x, actor->pos.y, actor->dest.x, actor->dest.y);
@@ -230,7 +230,7 @@ void StarTrekEngine::updateActorAnimations() {
int index = _iwFile->_iwEntries[actor->iwSrcPosition][actor->iwDestPosition];
actor->iwSrcPosition = index;
Common::Point dest = _iwFile->_keyPositions[actor->iwSrcPosition];
- actor->animationString2[strlen(actor->animationString2) - 1] = '\0';
+ actor->animationString2.deleteLastChar();
chooseActorDirectionForWalking(actor, actor->pos.x, actor->pos.y, dest.x, dest.y);
}
}
@@ -512,9 +512,9 @@ void StarTrekEngine::initStandAnim(int actorIndex) {
Common::String animName;
if (actor->direction != 0)
- animName = Common::String(actor->animationString) + (char)actor->direction;
+ animName = actor->animationString + (char)actor->direction;
else // Default to facing south
- animName = Common::String(actor->animationString) + 's';
+ animName = actor->animationString + 's';
Fixed8 scale = getActorScaleAtPosition(actor->pos.y);
loadActorAnim(actorIndex, animName, actor->pos.x, actor->pos.y, scale);
@@ -523,7 +523,7 @@ void StarTrekEngine::initStandAnim(int actorIndex) {
void StarTrekEngine::updateActorPositionWhileWalking(Actor *actor, int16 x, int16 y) {
actor->scale = getActorScaleAtPosition(y);
- Common::String animName = Common::String::format("%s%02d", actor->animationString2, actor->field92 & 7);
+ Common::String animName = Common::String::format("%s%02d", actor->animationString2.c_str(), actor->field92 & 7);
actor->sprite.setBitmap(loadAnimationFrame(animName, actor->scale));
memset(actor->bitmapFilename, 0, 10);
@@ -557,8 +557,7 @@ void StarTrekEngine::chooseActorDirectionForWalking(Actor *actor, int16 srcX, in
d = 'W';
// Append direction to animation string
- actor->animationString2[strlen(actor->animationString2) + 1] = '\0';
- actor->animationString2[strlen(actor->animationString2)] = d;
+ actor->animationString2 += d;
actor->direction = d;
actor->field90 = absDistX;
@@ -579,8 +578,7 @@ void StarTrekEngine::chooseActorDirectionForWalking(Actor *actor, int16 srcX, in
d = 'N';
// Append direction to animation string
- actor->animationString2[strlen(actor->animationString2) + 1] = '\0';
- actor->animationString2[strlen(actor->animationString2)] = d;
+ actor->animationString2 += d;
actor->direction = d;
actor->field90 = absDistY;
diff --git a/engines/startrek/object.h b/engines/startrek/object.h
index 9c2bf0d610..19d9b4b314 100644
--- a/engines/startrek/object.h
+++ b/engines/startrek/object.h
@@ -97,7 +97,7 @@ struct Actor {
bool triggerActionWhenAnimFinished;
uint16 finishedAnimActionParam;
- char animationString2[8];
+ Common::String animationString2;
uint16 field70;
uint16 field72;
uint16 field74;
@@ -124,7 +124,7 @@ struct Actor {
uint16 field94;
uint16 field96;
- char animationString[10];
+ Common::String animationString;
// These might be part of "animationString"?
uint16 fielda2;
@@ -174,8 +174,6 @@ public:
fielda6(0) {
memset(animFilename, 0, sizeof(animFilename));
memset(bitmapFilename, 0, sizeof(bitmapFilename));
- memset(animationString2, 0, sizeof(animationString2));
- memset(animationString, 0, sizeof(animationString));
}
};
diff --git a/engines/startrek/room.cpp b/engines/startrek/room.cpp
index dcb873e5ac..667b3b4496 100644
--- a/engines/startrek/room.cpp
+++ b/engines/startrek/room.cpp
@@ -259,7 +259,7 @@ void Room::loadActorStandAnim(int actorIndex) {
_vm->removeActorFromScreen(actorIndex);
else {
Actor *actor = &_vm->_actorList[actorIndex];
- if (actor->animationString[0] == '\0')
+ if (actor->animationString.empty())
_vm->removeActorFromScreen(actorIndex);
else
_vm->initStandAnim(actorIndex);
@@ -447,10 +447,10 @@ void Room::endMission(int16 score, int16 arg1, int16 arg2) {
_vm->loadActorAnimWithRoomScaling(i, anim, actor->sprite.pos.x, actor->sprite.pos.y);
}
- _vm->_kirkActor->animationString[0] = '\0';
- _vm->_spockActor->animationString[0] = '\0';
- _vm->_mccoyActor->animationString[0] = '\0';
- _vm->_redshirtActor->animationString[0] = '\0';
+ _vm->_kirkActor->animationString.clear();
+ _vm->_spockActor->animationString.clear();
+ _vm->_mccoyActor->animationString.clear();
+ _vm->_redshirtActor->animationString.clear();
playSoundEffectIndex(8);
diff --git a/engines/startrek/saveload.cpp b/engines/startrek/saveload.cpp
index 52bb7cbb47..7966537fd5 100644
--- a/engines/startrek/saveload.cpp
+++ b/engines/startrek/saveload.cpp
@@ -237,6 +237,8 @@ bool StarTrekEngine::saveOrLoadGameData(Common::SeekableReadStream *in, Common::
ser.syncAsUint32LE(_roomFrameCounter);
ser.syncAsUint32LE(_frameIndex); // FIXME: redundant
+ byte filler = 0;
+
// Serialize the "actor" class
for (int i = 0; i < NUM_ACTORS; i++) {
Actor *a = &_actorList[i];
@@ -258,7 +260,10 @@ bool StarTrekEngine::saveOrLoadGameData(Common::SeekableReadStream *in, Common::
ser.syncAsUint16LE(a->field62);
ser.syncAsUint16LE(a->triggerActionWhenAnimFinished);
ser.syncAsUint16LE(a->finishedAnimActionParam);
- ser.syncBytes((byte *)a->animationString2, 8);
+ ser.syncString(a->animationString2);
+ filler = 0;
+ for (uint i = 0; i < 8 - a->animationString2.size() - 1; ++i)
+ ser.syncAsByte(filler); // make sure that exactly 8 bytes are synced
ser.syncAsUint16LE(a->field70);
ser.syncAsUint16LE(a->field72);
ser.syncAsUint16LE(a->field74);
@@ -276,7 +281,10 @@ bool StarTrekEngine::saveOrLoadGameData(Common::SeekableReadStream *in, Common::
ser.syncAsByte(a->direction);
ser.syncAsUint16LE(a->field94);
ser.syncAsUint16LE(a->field96);
- ser.syncBytes((byte *)a->animationString, 10);
+ ser.syncString(a->animationString);
+ filler = 0;
+ for (uint i = 0; i < 10 - a->animationString.size() - 1; ++i)
+ ser.syncAsByte(filler); // make sure that exactly 10 bytes are synced
ser.syncAsUint16LE(a->fielda2);
ser.syncAsUint16LE(a->fielda4);
ser.syncAsUint16LE(a->fielda6);
diff --git a/engines/startrek/startrek.cpp b/engines/startrek/startrek.cpp
index 55aea6fc04..d347055efb 100644
--- a/engines/startrek/startrek.cpp
+++ b/engines/startrek/startrek.cpp
@@ -268,7 +268,7 @@ void StarTrekEngine::runTransportSequence(const Common::String &name) {
int x = crewmanTransportPositions[i][0];
int y = crewmanTransportPositions[i][1];
loadActorAnim(i, filename, x, y, 1.0);
- _actorList[i].animationString[0] = '\0';
+ _actorList[i].animationString.clear();
}
if (_missionToLoad.equalsIgnoreCase("feather") && name[4] == 'b') {