summaryrefslogtreecommitdiffstats
path: root/DTObjectSerializing.c
diff options
context:
space:
mode:
Diffstat (limited to 'DTObjectSerializing.c')
-rw-r--r--DTObjectSerializing.c107
1 files changed, 68 insertions, 39 deletions
diff --git a/DTObjectSerializing.c b/DTObjectSerializing.c
index bd68ddc..8633f8c 100644
--- a/DTObjectSerializing.c
+++ b/DTObjectSerializing.c
@@ -39,8 +39,8 @@ static const Object_Dir = 35;
static const Object_ComDir = 36;
static const Object_Origin = 37;
static const Object_Custom = 38;
-static const Object_Count = 39;
-//_enum(Object_, Status, Name, Owner, Controller, Killer, Category, Position, Speed, Con, OwnMass, Damage, Energy, MagicEnergy, Alive, Breath, ColorDw, Shape, Vertices, SolidMask, Picture, Entrance, Physicals, Action, Components, Contents, PlrViewRange, Visibility, BlitMode, CrewEnabled, ObjectLayer, Locals, Graphics, Effects, ID, ContactDensity, Dir, ComDir, Origin, Custom, Count)
+static const Object_CrewPlayer = 39;
+static const Object_Count = 40;
// DONT KNOW: OnFire, Commands
global func& LocalX(name, object obj)
@@ -62,12 +62,12 @@ global func GetEffectVarCount(object target, int effectNumber) // WARNING: this
var prio = GetEffect(0, target, effectNumber, 2);
var timer = GetEffect(0, target, effectNumber, 3);
var lifeTime = GetEffect(0, target, effectNumber, 6);
-
+
if(!name)
{
return -1;
}
-
+
// determine offset for this effect within GetObjectVal
for(var i = 0; ; ++i)
{
@@ -85,7 +85,7 @@ global func GetEffectVarCount(object target, int effectNumber) // WARNING: this
return 0;
}
}
-
+
}
return GetType(count) == C4V_Int && count;
}
@@ -96,6 +96,7 @@ global func GetObjectSaveData(object obj)
{
obj = obj || this;
var id = GetID(obj);
+ var owner = GetOwner(obj);
var ret = CreateArray(Object_Count);
ret[Object_ID] = id;
ret[Object_Origin] = obj;
@@ -104,7 +105,7 @@ global func GetObjectSaveData(object obj)
{
ret[Object_Name] = GetName(obj);
}
- ret[Object_Owner] = GetOwner(obj);
+ ret[Object_Owner] = owner;
ret[Object_Controller] = GetController(obj);
ret[Object_Killer] = GetKiller(obj);
ret[Object_Category] = GetCategory(obj);
@@ -119,7 +120,7 @@ global func GetObjectSaveData(object obj)
ret[Object_Breath] = GetBreath(obj);
ret[Object_ColorDw] = GetColorDw(obj);
ret[Object_Shape] = [GetObjectVal("Offset", 0, obj, 0), GetObjectVal("Offset", 0, obj, 1), GetObjectVal("Width", 0, obj), GetObjectVal("Height", 0, obj)];
-
+
if(GetObjectVal("OwnVertices", 0, obj))
{
var vertexNum = GetVertexNum(obj);
@@ -130,12 +131,30 @@ global func GetObjectSaveData(object obj)
}
ret[Object_Vertices] = vertices;
}
-
+
+ var crewPlayer = NO_OWNER;
+
+ if(CrewMember(obj))
+ {
+ for(var i = 0; i < GetCrewCount(owner); ++i)
+ {
+ if(GetCrew(owner, i) == obj)
+ {
+ crewPlayer = owner;
+ break;
+ }
+ }
+ }
+
+ ret[Object_CrewPlayer] = crewPlayer;
+
ret[Object_SolidMask] = GetSolidMask(obj);
ret[Object_Picture] = [GetObjectVal("Picture", 0, obj, 0), GetObjectVal("Picture", 0, obj, 1), GetObjectVal("Picture", 0, obj, 2), GetObjectVal("Picture", 0, obj, 3)];
ret[Object_Entrance] = GetEntrance(obj);
- ret[Object_Action] = [GetAction(obj), GetPhase(obj), GetActionTarget(0, obj), GetActionTarget(1, obj), GetObjectVal("ActionData", 0, obj)];
-
+
+ var action = GetAction(obj);
+ ret[Object_Action] = [action, GetPhase(obj), GetActionTarget(0, obj), GetActionTarget(1, obj), GetObjectVal("ActionData", 0, obj)];
+
var defComponents = [], objComponents = [];
for(var i = 0, componentID; componentID = GetComponent(0, i, 0, id); ++i)
{
@@ -153,7 +172,7 @@ global func GetObjectSaveData(object obj)
objComponents[GetLength(objComponents)] = [componentID, cnt];
}
}
-
+
var diffComponents = [];
for(var i = 0; i < GetLength(defComponents); ++i)
{
@@ -168,19 +187,19 @@ global func GetObjectSaveData(object obj)
break;
}
}
-
+
if(cnt != defCnt)
{
diffComponents[GetLength(diffComponents)] = [defID, cnt];
}
}
ArrayAppendArray(diffComponents, objComponents);
-
+
if(GetLength(diffComponents) != 0)
{
ret[Object_Components] = diffComponents;
}
-
+
var contents = [];
for(var content in obj->GetContents())
{
@@ -195,7 +214,7 @@ global func GetObjectSaveData(object obj)
ret[Object_Dir] = GetDir(obj);
ret[Object_ComDir] = GetComDir(obj);
ret[Object_ContactDensity] = GetObjectVal("ContactDensity", 0, obj);
-
+
var locals = [];
for(var f in [0, 1])
{
@@ -206,9 +225,9 @@ global func GetObjectSaveData(object obj)
locals[GetLength(locals)] = [name, LocalX(name, obj)];
}
}
-
+
ret[Object_Locals] = locals;
-
+
var overlays = [[GetGraphics(1, obj, 0), GetGraphics(0, obj, 0), 0, GetGraphics(2, obj, 0), GetGraphics(3, obj, 0), GetGraphics(4, obj, 0), 0, obj->GetObjDrawTransform(0), GetClrModulation(obj, 0)]];
var offset = 0, diffIndex = 0;
while((offset = obj->GetOverlayValueByIndex(diffIndex, offset)) >= 0)
@@ -217,8 +236,12 @@ global func GetObjectSaveData(object obj)
overlays[GetLength(overlays)] = [obj->GetOverlayValueByIndex(0, offset, 4), obj->GetOverlayValueByIndex(0, offset, 3), overlayID, obj->GetOverlayValueByIndex(0, offset, 2), obj->GetOverlayValueByIndex(0, offset, 5), obj->GetOverlayValueByIndex(0, offset, 6), Object(obj->GetOverlayValueByIndex(0, offset, 8)), obj->GetObjDrawTransform(-1, offset), GetClrModulation(obj, overlayID)];
diffIndex = 1;
}
+ if(GetActMapVal("FlipDir", action, id) && GetDir(obj) == DIR_Right)
+ {
+ overlays[0][7][0] *= -1;
+ }
ret[Object_Graphics] = overlays;
-
+
var physicals = []; // TODO: Think about StackTemporary? What about Effects? Maybe pop the whole stack while saving and restore afterwards
for(var physical in ["Energy", "Breath", "Walk", "Jump", "Scale", "Hangle", "Dig", "Swim", "Throw", "Push", "Fight", "Magic", "Float", "CanScale", "CanHangle", "CanDig", "CanConstruct", "CanChop", "CanSwimDig", "CanFly", "CorrosionResist", "BreatheWater"])
{
@@ -232,7 +255,7 @@ global func GetObjectSaveData(object obj)
{
ret[Object_Physicals] = physicals;
}
-
+
var effects = [];
for(var i = 0, index; index = GetEffect("*", obj, i, 0); ++i)
{
@@ -248,9 +271,9 @@ global func GetObjectSaveData(object obj)
{
ret[Object_Effects] = effects;
}
-
+
// TODO: Custom
-
+
return ret;
}
@@ -271,16 +294,22 @@ global func ApplyObjectSaveData(array data, object obj)
}
obj->DoEnergy(data[Object_Energy] - GetObjectVal("Energy", 0, obj), obj, true);
}
-
+
for(var content in data[Object_Contents])
{
var temp = obj->CreateContents(ROCK);
temp->ApplyObjectSaveData(content);
}
-
+
obj->ChangeDef(data[Object_ID]);
-
+
// the following changes should not call Callbacks anymore
+
+ if(data[Object_CrewPlayer] != NO_OWNER)
+ {
+ MakeCrewMember(obj, data[Object_CrewPlayer]);
+ }
+
obj->SetName(data[Object_Name]);
obj->SetController(data[Object_Controller]);
obj->SetKiller(data[Object_Killer]);
@@ -307,7 +336,7 @@ global func ApplyObjectSaveData(array data, object obj)
{
obj->AddVertex();
}
-
+
var i = 0;
for(var vertex in data[Object_Vertices])
{
@@ -318,13 +347,13 @@ global func ApplyObjectSaveData(array data, object obj)
++i;
}
}
-
+
var id = data[Object_ID];
for(var physical in ["Energy", "Breath", "Walk", "Jump", "Scale", "Hangle", "Dig", "Swim", "Throw", "Push", "Fight", "Magic", "Float", "CanScale", "CanHangle", "CanDig", "CanConstruct", "CanChop", "CanSwimDig", "CanFly", "CorrosionResist", "BreatheWater"])
{
obj->SetPhysical(physical, GetPhysical(physical, 0, 0, id), PHYS_Temporary);
}
-
+
if(data[Object_Physicals]) // TODO: Update for StackTemporary and try to represent right mode
{
for(var physical in data[Object_Physicals])
@@ -332,12 +361,12 @@ global func ApplyObjectSaveData(array data, object obj)
obj->SetPhysical(physical[0], physical[1], PHYS_Temporary);
}
}
-
+
for(var localVar in data[Object_Locals])
{
LocalX(localVar[0]) = localVar[1];
}
-
+
if(data[Object_Components])
{
for(var component in data[Object_Components])
@@ -352,19 +381,19 @@ global func ApplyObjectSaveData(array data, object obj)
obj->SetObjectLayer(data[Object_ObjectLayer]);
obj->SetContactDensity(data[Object_ContactDensity]);
obj->SetComDir(data[Object_ComDir]);
-
+
// unfortunately there is no SetAction without triggering CallCallbacks
// SetAction at last, so the important stuff is setup already
obj->SetAction(data[Object_Action][0], data[Object_Action][2], data[Object_Action][3], true);
obj->SetPhase(data[Object_Action][1]);
obj->SetActionData(data[Object_Action][4]);
-
+
obj->SetDir(data[Object_Dir]); // Set Dir after Action because Dirs are enabled per action
-
+
for(var graphic in data[Object_Graphics])
{
SetGraphics(graphic[0], obj, graphic[1], graphic[2], graphic[3], graphic[4], graphic[5], graphic[6]);
-
+
var transform = graphic[7];
if(GetLength(transform) == 6)
{
@@ -375,26 +404,26 @@ global func ApplyObjectSaveData(array data, object obj)
SetObjDrawTransform(1000, 0, 0, 0, 1000, 0, obj, graphic[2]);
obj->SetObjDrawTransform2(transform[0], transform[1], transform[2], transform[3], transform[4], transform[5], transform[6], transform[7], transform[8], graphic[2]);
}
-
+
SetClrModulation(graphic[8], obj, graphic[2]);
}
-
+
if(data[Object_Effects])
{
// WARNING: Can't restore lifetime
for(var effect in data[Object_Effects])
{
var temp = AddEffect("ApplyEffectDummy", obj, effect[1], effect[2], effect[3], effect[4]);
-
+
for(var i = 0; i < GetLength(effect[6]); ++i)
{
EffectVar(i, obj, temp) = effect[6][i];
}
-
+
ChangeEffect(0, obj, temp, effect[0], -1);
}
}
-
+
// TODO: Custom
}
@@ -403,4 +432,4 @@ global func InstantiateObjectSaveData(array data)
var ret = CreateObject(ROCK);
ret->ApplyObjectSaveData(data);
return ret;
-}
+} \ No newline at end of file