[Scummvm-git-logs] scummvm master -> c9a87e025c8a113236625bd8b77c626d0854f001

a-yyg 76591232+a-yyg at users.noreply.github.com
Wed Jul 7 03:39:25 UTC 2021


This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
4392e3f8a1 SAGA2: Implement Actor saving
e5c884b2ca SAGA2: Fix bandList null access
c9a87e025c SAGA2: Implement Actor loading partially


Commit: 4392e3f8a16c7e1bee57d3dde59692ae49ce4653
    https://github.com/scummvm/scummvm/commit/4392e3f8a16c7e1bee57d3dde59692ae49ce4653
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-07-07T12:36:51+09:00

Commit Message:
SAGA2: Implement Actor saving

Changed paths:
    engines/saga2/actor.cpp
    engines/saga2/actor.h
    engines/saga2/assign.cpp
    engines/saga2/assign.h
    engines/saga2/loadsave.cpp
    engines/saga2/objects.cpp
    engines/saga2/objects.h
    engines/saga2/rect.cpp
    engines/saga2/rect.h
    engines/saga2/sprite.cpp
    engines/saga2/sprite.h
    engines/saga2/tcoords.h


diff --git a/engines/saga2/actor.cpp b/engines/saga2/actor.cpp
index aa0147f1c1..90c73346eb 100644
--- a/engines/saga2/actor.cpp
+++ b/engines/saga2/actor.cpp
@@ -1357,6 +1357,102 @@ void *Actor::archive(void *buf) {
 	return buf;
 }
 
+void Actor::write(Common::OutSaveFile *out) {
+	ProtoObj    *holdProto = prototype;
+
+	debugC(3, kDebugSaveload, "Saving actor %d", thisID());
+
+	//  Modify the protoype temporarily so the GameObject::archive()
+	//  will store the index correctly
+	if (prototype != NULL)
+		prototype = &objectProtos[(ActorProto *)prototype - actorProtos];
+
+	GameObject::write(out);
+
+	//  Restore the prototype pointer
+	prototype = holdProto;
+
+	out->writeByte(faction);
+	out->writeByte(colorScheme);
+	out->writeSint32LE(appearanceID);
+	out->writeSByte(attitude);
+	out->writeSByte(mood);
+
+	out->writeByte(disposition);
+	out->writeByte(currentFacing);
+	out->writeSint16LE(tetherLocU);
+	out->writeSint16LE(tetherLocV);
+	out->writeSint16LE(tetherDist);
+	out->writeUint16LE(leftHandObject);
+	out->writeUint16LE(rightHandObject);
+
+	out->write(knowledge, sizeof(knowledge));
+	out->writeUint16LE(schedule);
+	out->write(conversationMemory, sizeof(conversationMemory));
+
+	out->writeByte(currentAnimation);
+	out->writeByte(currentPose);
+	out->writeByte(animationFlags);
+
+	out->writeByte(flags);
+	poseInfo.write(out);
+	out->writeSint16LE(cycleCount);
+	out->writeSint16LE(kludgeCount);
+	out->writeUint32LE(enchantmentFlags);
+	out->writeByte(currentGoal);
+	out->writeByte(deactivationCounter);
+	effectiveStats.write(out);
+	out->writeByte(actionCounter);
+	out->writeUint16LE(effectiveResistance);
+	out->writeUint16LE(effectiveImmunity);
+	out->writeSint16LE(recPointsPerUpdate);
+	out->writeUint16LE(currentRecoveryPoints);
+	out->writeUint16LE(leader != NULL ? leader->thisID() : Nothing);
+	out->writeSint16LE(followers != NULL ? getBandID(followers) : NoBand);
+	out->write(armorObjects, ARMOR_COUNT * 2);
+	out->writeUint16LE(currentTarget != NULL ? currentTarget->thisID() : Nothing);
+	out->write(scriptVar, sizeof(scriptVar));
+
+	if (flags & hasAssignment)
+		writeAssignment(this, out);
+	debugC(4, kDebugSaveload, "... faction = %d", faction);
+	debugC(4, kDebugSaveload, "... colorScheme = %d", colorScheme);
+	debugC(4, kDebugSaveload, "... appearanceID = %d", appearanceID);
+	debugC(4, kDebugSaveload, "... attitude = %d", attitude);
+	debugC(4, kDebugSaveload, "... mood = %d", mood);
+	debugC(4, kDebugSaveload, "... disposition = %d", disposition);
+	debugC(4, kDebugSaveload, "... currentFacing = %d", currentFacing);
+	debugC(4, kDebugSaveload, "... tetherLocU = %d", tetherLocU);
+	debugC(4, kDebugSaveload, "... tetherLocV = %d", tetherLocV);
+	debugC(4, kDebugSaveload, "... tetherDist = %d", tetherDist);
+	debugC(4, kDebugSaveload, "... leftHandObject = %d", leftHandObject);
+	debugC(4, kDebugSaveload, "... rightHandObject = %d", rightHandObject);
+//	debugC(4, kDebugSaveload, "... knowledge = %d", knowledge);
+	debugC(4, kDebugSaveload, "... schedule = %d", schedule);
+//	debugC(4, kDebugSaveload, "... conversationMemory = %d", conversationMemory);
+	debugC(4, kDebugSaveload, "... currentAnimation = %d", currentAnimation);
+	debugC(4, kDebugSaveload, "... currentPose = %d", currentPose);
+	debugC(4, kDebugSaveload, "... animationFlags = %d", animationFlags);
+	debugC(4, kDebugSaveload, "... flags = %d", flags);
+//	debugC(4, kDebugSaveload, "... out = %d", out);
+	debugC(4, kDebugSaveload, "... cycleCount = %d", cycleCount);
+	debugC(4, kDebugSaveload, "... kludgeCount = %d", kludgeCount);
+	debugC(4, kDebugSaveload, "... enchantmentFlags = %d", enchantmentFlags);
+	debugC(4, kDebugSaveload, "... currentGoal = %d", currentGoal);
+	debugC(4, kDebugSaveload, "... deactivationCounter = %d", deactivationCounter);
+//	debugC(4, kDebugSaveload, "... out = %d", out);
+	debugC(4, kDebugSaveload, "... actionCounter = %d", actionCounter);
+	debugC(4, kDebugSaveload, "... effectiveResistance = %d", effectiveResistance);
+	debugC(4, kDebugSaveload, "... effectiveImmunity = %d", effectiveImmunity);
+	debugC(4, kDebugSaveload, "... recPointsPerUpdate = %d", recPointsPerUpdate);
+	debugC(4, kDebugSaveload, "... currentRecoveryPoints = %d", currentRecoveryPoints);
+	debugC(4, kDebugSaveload, "... leaderID = %d", leader != NULL ? leader->thisID() : Nothing);
+	debugC(4, kDebugSaveload, "... followersID = %d", followers != NULL ? getBandID(followers) : NoBand);
+//	debugC(4, kDebugSaveload, "... armorObjects = %d", armorObjects);
+	debugC(4, kDebugSaveload, "... currentTargetID = %d", currentTarget != NULL ? currentTarget->thisID() : Nothing);
+//	debugC(4, kDebugSaveload, "... scriptVar = %d", scriptVar);
+}
+
 //-----------------------------------------------------------------------
 //	Return a newly created actor
 
@@ -3501,6 +3597,27 @@ void saveActors(SaveFileConstructor &saveGame) {
 	free(archiveBuffer);
 }
 
+void saveActors(Common::OutSaveFile *out) {
+	debugC(2, kDebugSaveload, "Saving actors");
+
+	int32   archiveBufSize = 0;
+
+	//  Accumulate size of archive buffer
+
+	//  Add size of actor count
+	archiveBufSize += sizeof(int16);
+
+	for (int i = 0; i < actorCount; i++)
+		archiveBufSize += actorList[i].archiveSize();
+
+	out->write("ACTR", 4);
+	out->writeUint32LE(archiveBufSize);
+	out->writeSint16LE(actorCount);
+
+	for (int i = 0; i < actorCount; ++i)
+		actorList[i].write(out);
+}
+
 //-------------------------------------------------------------------
 //	Load the actor list from a save file
 
diff --git a/engines/saga2/actor.h b/engines/saga2/actor.h
index f648d10907..5150d856e0 100644
--- a/engines/saga2/actor.h
+++ b/engines/saga2/actor.h
@@ -27,6 +27,7 @@
 #ifndef SAGA2_ACTOR_H
 #define SAGA2_ACTOR_H
 
+#include "common/savefile.h"
 #include "saga2/objects.h"
 
 namespace Saga2 {
@@ -193,6 +194,30 @@ struct ActorAttributes {
 		blueMana = stream->readSint16LE();
 		violetMana = stream->readSint16LE();
 	}
+
+	void write(Common::OutSaveFile *out) {
+		out->writeByte(archery);
+		out->writeByte(swordcraft);
+		out->writeByte(shieldcraft);
+		out->writeByte(bludgeon);
+		out->writeByte(throwing);
+		out->writeByte(spellcraft);
+		out->writeByte(stealth);
+		out->writeByte(agility);
+		out->writeByte(brawn);
+		out->writeByte(lockpick);
+		out->writeByte(pilfer);
+		out->writeByte(firstAid);
+		out->writeByte(spotHidden);
+		out->writeSByte(pad);
+		out->writeSint16LE(vitality);
+		out->writeSint16LE(redMana);
+		out->writeSint16LE(orangeMana);
+		out->writeSint16LE(yellowMana);
+		out->writeSint16LE(greenMana);
+		out->writeSint16LE(blueMana);
+		out->writeSint16LE(violetMana);
+	}
 };  // 28 bytes
 
 
@@ -705,6 +730,8 @@ public:
 	//  Reconstruct from archive buffer
 	Actor(void **buf);
 
+	Actor(Common::InSaveFile *in);
+
 	//  Destructor
 	~Actor(void);
 
@@ -714,6 +741,8 @@ public:
 	//  Archive this actor in a buffer
 	void *archive(void *buf);
 
+	void write(Common::OutSaveFile *out);
+
 	static Actor *newActor(
 	    int16   protoNum,
 	    uint16  nameIndex,
diff --git a/engines/saga2/assign.cpp b/engines/saga2/assign.cpp
index aa8579cb20..049c277b25 100644
--- a/engines/saga2/assign.cpp
+++ b/engines/saga2/assign.cpp
@@ -106,6 +106,11 @@ void *ActorAssignment::archive(void *buf) const {
 	return a;
 }
 
+void ActorAssignment::write(Common::OutSaveFile *out) const {
+	out->writeUint16LE(startFrame);
+	out->writeUint16LE(endFrame);
+}
+
 //----------------------------------------------------------------------
 //	Determine if the time limit for this assignment has been exceeded
 
@@ -901,4 +906,14 @@ void *archiveAssignment(Actor *a, void *buf) {
 	return buf;
 }
 
+void writeAssignment(Actor *a, Common::OutSaveFile *out) {
+	ActorAssignment *assign = a->getAssignment();
+
+	if (assign != NULL) {
+		out->writeSint16LE(assign->type());
+
+		assign->write(out);
+	}
+}
+
 }
diff --git a/engines/saga2/assign.h b/engines/saga2/assign.h
index 0f3d65e46c..8815ed5e4e 100644
--- a/engines/saga2/assign.h
+++ b/engines/saga2/assign.h
@@ -78,6 +78,8 @@ public:
 	//  to save it on disk
 	virtual void *archive(void *buf) const;
 
+	virtual void write(Common::OutSaveFile *out) const;
+
 	//  Construct a TaskStack for this assignment
 	TaskStack *createTask(void);
 
@@ -484,6 +486,8 @@ int32 assignmentArchiveSize(Actor *a);
 //  Write the specified actor's assignment to an archive buffer
 void *archiveAssignment(Actor *a, void *buf);
 
+void writeAssignment(Actor *a, Common::OutSaveFile *out);
+
 }
 
 #endif
diff --git a/engines/saga2/loadsave.cpp b/engines/saga2/loadsave.cpp
index 34033a7031..2336882e00 100644
--- a/engines/saga2/loadsave.cpp
+++ b/engines/saga2/loadsave.cpp
@@ -148,9 +148,9 @@ Common::Error saveGameState(int16 saveNo, char *saveName) {
 	saveTimer(out);
 	saveCalender(out);
 	saveWorlds(out);
+	saveActors(out);
 
 #if 0
-	saveActors(saveGame);
 	saveObjects(saveGame);
 	saveBands(saveGame);
 	savePlayerActors(saveGame);
diff --git a/engines/saga2/objects.cpp b/engines/saga2/objects.cpp
index c9c248214c..26a00ad564 100644
--- a/engines/saga2/objects.cpp
+++ b/engines/saga2/objects.cpp
@@ -300,6 +300,42 @@ void *GameObject::archive(void *buf) {
 	return &a[1];
 }
 
+void GameObject::write(Common::OutSaveFile *out) {
+	debugC(2, kDebugSaveload, "Saving object %d", thisID());
+
+	int16 pInd = prototype != nullptr ? prototype - objectProtos : -1;
+	out->writeSint16LE(pInd);
+	_data.location.write(out);
+	out->writeUint16LE(_data.nameIndex);
+	out->writeUint16LE(_data.parentID);
+	out->writeUint16LE(_data.siblingID);
+	out->writeUint16LE(_data.childID);
+	out->writeUint16LE(_data.script);
+	out->writeUint16LE(_data.objectFlags);
+	out->writeByte(_data.hitPoints);
+	out->writeByte(_data.bParam);
+	out->writeUint16LE(_data.massCount);
+	out->writeByte(_data.missileFacing);
+	out->writeSint16LE(_data.currentTAG);
+	out->writeByte(_data.sightCtr);
+
+	debugC(4, kDebugSaveload, "... protoIndex = %d", pInd);
+	debugC(4, kDebugSaveload, "... _data.location = (%d, %d, %d)",
+	       _data.location.u, _data.location.v, _data.location.z);
+	debugC(4, kDebugSaveload, "... _data.nameIndex = %d", _data.nameIndex);
+	debugC(4, kDebugSaveload, "... _data.parentID = %d", _data.parentID);
+	debugC(4, kDebugSaveload, "... _data.siblingID = %d", _data.siblingID);
+	debugC(4, kDebugSaveload, "... _data.childID = %d", _data.childID);
+	debugC(4, kDebugSaveload, "... _data.script = %d", _data.script);
+	debugC(4, kDebugSaveload, "... _data.objectFlags = %d", _data.objectFlags);
+	debugC(4, kDebugSaveload, "... _data.hitPoints = %d", _data.hitPoints);
+	debugC(4, kDebugSaveload, "... _data.bParam = %d", _data.bParam);
+	debugC(4, kDebugSaveload, "... _data.massCount = %d", _data.massCount);
+	debugC(4, kDebugSaveload, "... _data.missileFacing = %d", _data.missileFacing);
+	debugC(4, kDebugSaveload, "... _data.currentTAG = %d", _data.currentTAG);
+	debugC(4, kDebugSaveload, "... _data.sightCtr = %d", _data.sightCtr);
+}
+
 //  Same as above but use object addresses instead of ID's
 
 bool isObject(GameObject *obj) {
diff --git a/engines/saga2/objects.h b/engines/saga2/objects.h
index 7f4d3b24aa..b98d914c2e 100644
--- a/engines/saga2/objects.h
+++ b/engines/saga2/objects.h
@@ -116,7 +116,9 @@ struct ObjectData {
 
 void     initActors(void);
 void     saveActors(SaveFileConstructor &);
+void     saveActors(Common::OutSaveFile *out);
 void     loadActors(SaveFileReader &);
+void     loadActors(Common::InSaveFile *in);
 void     cleanupActors(void);
 class GameObject {
 
@@ -193,6 +195,8 @@ public:
 	//  Archive the object in a buffer
 	void *archive(void *buf);
 
+	void write(Common::OutSaveFile *out);
+
 	//  returns the address of the object based on the ID, and this
 	//  includes accounting for actors.
 	static GameObject *objectAddress(ObjectID id);
diff --git a/engines/saga2/rect.cpp b/engines/saga2/rect.cpp
index efb4b6f139..ba5e0e3df9 100644
--- a/engines/saga2/rect.cpp
+++ b/engines/saga2/rect.cpp
@@ -24,6 +24,7 @@
  *   (c) 1993-1996 The Wyrmkeep Entertainment Co.
  */
 
+#include "common/savefile.h"
 #include "saga2/saga2.h"
 #include "saga2/rect.h"
 
@@ -34,6 +35,11 @@ void Point16::load(Common::SeekableReadStream *stream) {
 	y = stream->readSint16LE();
 }
 
+void Point16::write(Common::OutSaveFile *out) {
+	out->writeSint16LE(x);
+	out->writeSint16LE(y);
+}
+
 Rect16 bound(const Rect16 a, const Rect16 b) {
 	int16               x1, x2, y1, y2;
 
diff --git a/engines/saga2/rect.h b/engines/saga2/rect.h
index 4d1191d22e..98c8ddd827 100644
--- a/engines/saga2/rect.h
+++ b/engines/saga2/rect.h
@@ -55,6 +55,7 @@ public:
 	}
 
 	void load(Common::SeekableReadStream *stream);
+	void write(Common::OutSaveFile *out);
 
 	// Point16 operators
 	friend Point16 operator+ (Point16 a, Point16 b) {
diff --git a/engines/saga2/sprite.cpp b/engines/saga2/sprite.cpp
index b0dec910d9..1497504f6d 100644
--- a/engines/saga2/sprite.cpp
+++ b/engines/saga2/sprite.cpp
@@ -610,6 +610,18 @@ ActorPose::ActorPose(Common::SeekableReadStream *stream) {
 	rightObjectOffset.load(stream);
 }
 
+void ActorPose::write(Common::OutSaveFile *out) {
+	out->writeUint16LE(flags);
+
+	out->writeByte(actorFrameIndex);
+	out->writeByte(actorFrameBank);
+	out->writeByte(leftObjectIndex);
+	out->writeByte(rightObjectIndex);
+
+	leftObjectOffset.write(out);
+	rightObjectOffset.write(out);
+}
+
 ColorScheme::ColorScheme(Common::SeekableReadStream *stream) {
 	for (int i = 0; i < 11; ++i)
 		bank[i] = stream->readByte();
diff --git a/engines/saga2/sprite.h b/engines/saga2/sprite.h
index f782d1be50..8a1d93fd33 100644
--- a/engines/saga2/sprite.h
+++ b/engines/saga2/sprite.h
@@ -133,6 +133,8 @@ struct ActorPose {
 
 	ActorPose();
 	ActorPose(Common::SeekableReadStream *stream);
+
+	void write(Common::OutSaveFile *out);
 };
 
 //  A choreographed sequence of frames
diff --git a/engines/saga2/tcoords.h b/engines/saga2/tcoords.h
index 668fea8a7e..767d948b39 100644
--- a/engines/saga2/tcoords.h
+++ b/engines/saga2/tcoords.h
@@ -27,6 +27,8 @@
 #ifndef SAGA2_TCOORDS_H
 #define SAGA2_TCOORDS_H
 
+#include "common/savefile.h"
+
 namespace Saga2 {
 
 enum facingDirections {
@@ -142,6 +144,12 @@ struct TilePoint {
 		z = p.z;
 	}
 
+	void write(Common::OutSaveFile *out) {
+		out->writeSint16LE(u);
+		out->writeSint16LE(v);
+		out->writeSint16LE(z);
+	}
+
 		// TilePoint operators
 	friend TilePoint operator+ (TilePoint a, TilePoint b)
 		{ return TilePoint( (int16) (a.u + b.u), (int16) (a.v + b.v), (int16) (a.z + b.z) ); }


Commit: e5c884b2ca39b48a02f5f3c3723ee137fe7ea880
    https://github.com/scummvm/scummvm/commit/e5c884b2ca39b48a02f5f3c3723ee137fe7ea880
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-07-07T12:36:51+09:00

Commit Message:
SAGA2: Fix bandList null access

Changed paths:
    engines/saga2/band.cpp


diff --git a/engines/saga2/band.cpp b/engines/saga2/band.cpp
index 3421754784..b4b6376bbd 100644
--- a/engines/saga2/band.cpp
+++ b/engines/saga2/band.cpp
@@ -257,6 +257,9 @@ BandID getBandID(Band *b) {
 //	Return a pointer to a Band given a BandID
 
 Band *getBandAddress(BandID id) {
+	if (g_vm->_bandList == nullptr)
+		return nullptr;
+
 	return g_vm->_bandList->getBandAddress(id);
 }
 


Commit: c9a87e025c8a113236625bd8b77c626d0854f001
    https://github.com/scummvm/scummvm/commit/c9a87e025c8a113236625bd8b77c626d0854f001
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-07-07T12:36:51+09:00

Commit Message:
SAGA2: Implement Actor loading partially

Changed paths:
    engines/saga2/actor.cpp
    engines/saga2/loadsave.cpp
    engines/saga2/objects.cpp
    engines/saga2/objects.h
    engines/saga2/sprite.cpp
    engines/saga2/sprite.h
    engines/saga2/tcoords.h


diff --git a/engines/saga2/actor.cpp b/engines/saga2/actor.cpp
index 90c73346eb..1a8ab09253 100644
--- a/engines/saga2/actor.cpp
+++ b/engines/saga2/actor.cpp
@@ -1266,6 +1266,90 @@ Actor::Actor(void **buf) : GameObject(buf) {
 	*buf = bufferPtr;
 }
 
+Actor::Actor(Common::InSaveFile *in) : GameObject(in) {
+	//  Fixup the prototype pointer to point to an actor prototype
+	prototype   =   prototype != nullptr
+	                ? (ProtoObj *)&actorProtos[prototype - objectProtos]
+	                :   nullptr;
+
+	faction = in->readByte();
+	colorScheme = in->readByte();
+	appearanceID = in->readSint32LE();
+	attitude = in->readSByte();
+	mood = in->readSByte();
+
+	disposition = in->readByte();
+	currentFacing = in->readByte();
+	tetherLocU = in->readSint16LE();
+	tetherLocV = in->readSint16LE();
+	tetherDist = in->readSint16LE();
+	leftHandObject = in->readUint16LE();
+	rightHandObject = in->readUint16LE();
+
+	for (int i = 0; i < ARRAYSIZE(knowledge); ++i)
+		knowledge[i] = in->readUint16LE();
+
+	schedule = in->readUint16LE();
+
+	for (int i = 0; i < ARRAYSIZE(conversationMemory); ++i)
+		conversationMemory[i] = in->readByte();
+
+	currentAnimation = in->readByte();
+	currentPose = in->readByte();
+	animationFlags = in->readByte();
+
+	flags = in->readByte();
+	poseInfo.load(in);
+	cycleCount = in->readSint16LE();
+	kludgeCount = in->readSint16LE();
+	enchantmentFlags = in->readUint32LE();
+	currentGoal = in->readByte();
+	deactivationCounter = in->readByte();
+	effectiveStats.load(in);
+	actionCounter = in->readByte();
+	effectiveResistance = in->readUint16LE();
+	effectiveImmunity = in->readUint16LE();
+	recPointsPerUpdate = in->readSint16LE();
+	currentRecoveryPoints = in->readUint16LE();
+
+	int leaderID = in->readUint16LE();
+
+	leader = leaderID != Nothing
+	         ? (Actor *)GameObject::objectAddress(leaderID)
+	         :   nullptr;
+
+	int followersID = in->readSint16LE();
+
+	followers = followersID != NoBand
+	            ?   getBandAddress(followersID)
+	            :   nullptr;
+
+	for (int i = 0; i < ARRAYSIZE(armorObjects); ++i)
+		armorObjects[i] = in->readUint16LE();
+
+	int currentTargetID = in->readUint16LE();
+
+	currentTarget = currentTargetID != Nothing
+	                ?   GameObject::objectAddress(currentTargetID)
+	                :   nullptr;
+
+	for (int i = 0; i < ARRAYSIZE(scriptVar); ++i)
+		scriptVar[i] = in->readSint16LE();
+
+	warning("STUB: Actor::Actor(Common::InSaveFile *): unfinished");
+#if 0
+	if (flags & hasAssignment) {
+		bufferPtr = constructAssignment(this, bufferPtr);
+	} else {
+		_assignment = nullptr;
+	}
+#endif
+
+	appearance = nullptr;
+	moveTask = nullptr;
+	curTask = nullptr;
+}
+
 //-----------------------------------------------------------------------
 //	Destructor
 
@@ -1362,6 +1446,7 @@ void Actor::write(Common::OutSaveFile *out) {
 
 	debugC(3, kDebugSaveload, "Saving actor %d", thisID());
 
+	warning("STUB: Actor::write: Pointer arithmetic");
 	//  Modify the protoype temporarily so the GameObject::archive()
 	//  will store the index correctly
 	if (prototype != NULL)
@@ -1407,14 +1492,24 @@ void Actor::write(Common::OutSaveFile *out) {
 	out->writeUint16LE(effectiveImmunity);
 	out->writeSint16LE(recPointsPerUpdate);
 	out->writeUint16LE(currentRecoveryPoints);
-	out->writeUint16LE(leader != NULL ? leader->thisID() : Nothing);
-	out->writeSint16LE(followers != NULL ? getBandID(followers) : NoBand);
+
+	int leaderID = (leader != NULL) ? leader->thisID() : Nothing;
+
+	out->writeUint16LE(leaderID);
+
+	int followersID = (followers != NULL) ? getBandID(followers) : NoBand;
+
+	out->writeSint16LE(followersID);
 	out->write(armorObjects, ARMOR_COUNT * 2);
-	out->writeUint16LE(currentTarget != NULL ? currentTarget->thisID() : Nothing);
+
+	int currentTargetID = currentTarget != NULL ? currentTarget->thisID() : Nothing;
+
+	out->writeUint16LE(currentTargetID);
 	out->write(scriptVar, sizeof(scriptVar));
 
 	if (flags & hasAssignment)
 		writeAssignment(this, out);
+	
 	debugC(4, kDebugSaveload, "... faction = %d", faction);
 	debugC(4, kDebugSaveload, "... colorScheme = %d", colorScheme);
 	debugC(4, kDebugSaveload, "... appearanceID = %d", appearanceID);
@@ -3614,6 +3709,8 @@ void saveActors(Common::OutSaveFile *out) {
 	out->writeUint32LE(archiveBufSize);
 	out->writeSint16LE(actorCount);
 
+	debugC(3, kDebugSaveload, "... actorCount = %d", actorCount);
+
 	for (int i = 0; i < actorCount; ++i)
 		actorList[i].write(out);
 }
@@ -3656,6 +3753,26 @@ void loadActors(SaveFileReader &saveGame) {
 	free(archiveBuffer);
 }
 
+void loadActors(Common::InSaveFile *in) {
+	debugC(2, kDebugSaveload, "Loading actors");
+
+	//  Read in the actor count
+	actorCount = in->readSint16LE();
+
+	debugC(3, kDebugSaveload, "... actorCount = %d", actorCount);
+
+	//  Allocate the actor array
+	actorListSize = actorCount * sizeof(Actor);
+	actorList = new Actor[actorCount]();
+	if (actorList == NULL)
+		error("Unable to load Actors");
+
+	for (int i = 0; i < actorCount; i++)
+		//  Initilize actors with archive data
+		new (&actorList[i]) Actor(in);
+
+}
+
 //-------------------------------------------------------------------
 //	Cleanup the actor list
 
diff --git a/engines/saga2/loadsave.cpp b/engines/saga2/loadsave.cpp
index 2336882e00..a97f893d88 100644
--- a/engines/saga2/loadsave.cpp
+++ b/engines/saga2/loadsave.cpp
@@ -256,12 +256,12 @@ void loadSavedGameState(int16 saveNo) {
 			loadWorlds(in);
 			loadFlags |= loadWorldsFlag;
 			break;
-#if 0
 
 		case MKTAG('A', 'C', 'T', 'R'):
-			loadActors(saveGame);
+			loadActors(in);
 			loadFlags |= loadActorsFlag;
 			break;
+#if 0
 
 		case MKTAG('O', 'B', 'J', 'S'):
 			loadObjects(saveGame);
diff --git a/engines/saga2/objects.cpp b/engines/saga2/objects.cpp
index 26a00ad564..88cefe08b8 100644
--- a/engines/saga2/objects.cpp
+++ b/engines/saga2/objects.cpp
@@ -266,6 +266,32 @@ GameObject::GameObject(void **buf) {
 	*buf = &a[1];
 }
 
+GameObject::GameObject(Common::InSaveFile *in) {
+	int16 pInd = in->readSint16LE();
+	//  Convert the protoype index into an object proto pointer
+	prototype = pInd != -1
+	            ?   &objectProtos[pInd]
+	            :   nullptr;
+
+	_data.projectDummy = 0;
+	_data.location.load(in);
+	_data.nameIndex = in->readUint16LE();
+	_data.parentID = in->readUint16LE();
+	_data.siblingID = in->readUint16LE();
+	_data.childID = in->readUint16LE();
+	_data.script = in->readUint16LE();
+	_data.objectFlags = in->readUint16LE();
+	_data.hitPoints = in->readByte();
+	_data.bParam = in->readByte();
+	_data.massCount = in->readUint16LE();
+	_data.missileFacing = in->readByte();
+	_data.currentTAG.val = in->readSint16LE();
+	_data.sightCtr = in->readByte();
+	memset(&_data.reserved, 0, sizeof(_data.reserved));
+
+	_data.obj = this;
+}
+
 //-----------------------------------------------------------------------
 //	Return the number of bytes need to archive this object in an archive
 //	buffer.
@@ -303,6 +329,7 @@ void *GameObject::archive(void *buf) {
 void GameObject::write(Common::OutSaveFile *out) {
 	debugC(2, kDebugSaveload, "Saving object %d", thisID());
 
+	warning("STUB: GameObject::write: Pointer arithmetic");
 	int16 pInd = prototype != nullptr ? prototype - objectProtos : -1;
 	out->writeSint16LE(pInd);
 	_data.location.write(out);
@@ -332,7 +359,7 @@ void GameObject::write(Common::OutSaveFile *out) {
 	debugC(4, kDebugSaveload, "... _data.bParam = %d", _data.bParam);
 	debugC(4, kDebugSaveload, "... _data.massCount = %d", _data.massCount);
 	debugC(4, kDebugSaveload, "... _data.missileFacing = %d", _data.missileFacing);
-	debugC(4, kDebugSaveload, "... _data.currentTAG = %d", _data.currentTAG);
+	debugC(4, kDebugSaveload, "... _data.currentTAG.val = %d", _data.currentTAG.val);
 	debugC(4, kDebugSaveload, "... _data.sightCtr = %d", _data.sightCtr);
 }
 
diff --git a/engines/saga2/objects.h b/engines/saga2/objects.h
index b98d914c2e..c2977152a0 100644
--- a/engines/saga2/objects.h
+++ b/engines/saga2/objects.h
@@ -188,6 +188,8 @@ public:
 	//  Constructor -- reconstruct from archive buffer
 	GameObject(void **buf);
 
+	GameObject(Common::InSaveFile *in);
+
 	//  Return the number of bytes needed to archive this object in
 	//  a buffer
 	int32 archiveSize(void);
diff --git a/engines/saga2/sprite.cpp b/engines/saga2/sprite.cpp
index 1497504f6d..f0f39044fe 100644
--- a/engines/saga2/sprite.cpp
+++ b/engines/saga2/sprite.cpp
@@ -599,6 +599,10 @@ ActorPose::ActorPose() {
 
 
 ActorPose::ActorPose(Common::SeekableReadStream *stream) {
+	load(stream);
+}
+
+void ActorPose::load(Common::SeekableReadStream *stream) {
 	flags = stream->readUint16LE();
 
 	actorFrameIndex = stream->readByte();
@@ -622,6 +626,7 @@ void ActorPose::write(Common::OutSaveFile *out) {
 	rightObjectOffset.write(out);
 }
 
+
 ColorScheme::ColorScheme(Common::SeekableReadStream *stream) {
 	for (int i = 0; i < 11; ++i)
 		bank[i] = stream->readByte();
diff --git a/engines/saga2/sprite.h b/engines/saga2/sprite.h
index 8a1d93fd33..589701f55e 100644
--- a/engines/saga2/sprite.h
+++ b/engines/saga2/sprite.h
@@ -133,6 +133,7 @@ struct ActorPose {
 
 	ActorPose();
 	ActorPose(Common::SeekableReadStream *stream);
+	void load(Common::SeekableReadStream *stream);
 
 	void write(Common::OutSaveFile *out);
 };
diff --git a/engines/saga2/tcoords.h b/engines/saga2/tcoords.h
index 767d948b39..445ded0e0f 100644
--- a/engines/saga2/tcoords.h
+++ b/engines/saga2/tcoords.h
@@ -144,6 +144,12 @@ struct TilePoint {
 		z = p.z;
 	}
 
+	void load(Common::SeekableReadStream *stream) {
+		u = stream->readSint16LE();
+		v = stream->readSint16LE();
+		z = stream->readSint16LE();
+	}
+
 	void write(Common::OutSaveFile *out) {
 		out->writeSint16LE(u);
 		out->writeSint16LE(v);




More information about the Scummvm-git-logs mailing list