Fix scenario saving of array-typed visibility. Fix ItemSpawn saving and spawn def re-setting.

liquid_container
Sven Eberhardt 2016-02-07 13:20:50 -05:00
parent ef032c60fa
commit 35fcc0ff51
2 changed files with 26 additions and 10 deletions

View File

@ -28,6 +28,12 @@ public func SetSpawnObject(id def)
{
spawn_id = def;
SetGraphics(nil, spawn_id, GFX_Overlay, GFXOV_MODE_Base);
// Changing the spawn id also resets all collected items to make the spawn available again
for (var plr in GetPlayers())
{
spawn_list[plr] = nil;
UpdateVisibility(plr);
}
return true;
}
@ -55,7 +61,7 @@ public func Construction()
B = PV_Random(200, 255)
};
// Initial visibility for all players
Visibility = [VIS_Select,false,false,false,false];
Visibility = [VIS_Select | VIS_God, false,false,false,false];
for (var plr in GetPlayers()) UpdateVisibility(plr);
// Timer effect
AddEffect("Spawn", this, 1, 2, this);
@ -120,10 +126,14 @@ public func OnTeamSwitch(int plr, int new_team, int old_team)
func SaveScenarioObject(props)
{
if (!inherited(props, ...)) return false;
var fx_spawn = GetEffect("ProcessSpawn", this);
if (!fx_spawn) return true; // effects lost? Just save the unused object then; maybe someone wants to assign it an item later.
// Visibility is handled by us
props->Remove("Visibility");
// Item spawner has its own creation procedure
props->RemoveCreation();
props->Add(SAVEOBJ_Creation, "%i->Create(%i,%d,%d,%i)", GetID() /* to allow overloads */, fx_spawn.spawn_id, GetX(), GetY());
if (spawn_id)
{
props->RemoveCreation();
props->Add(SAVEOBJ_Creation, "%i->Create(%i,%d,%d)", GetID() /* to allow overloads */, spawn_id, GetX(), GetY());
}
if (team) props->AddCall("Team", this, "SetTeam", team);
return true;
}

View File

@ -361,7 +361,7 @@ global func SaveScenarioObject(props)
v = GetName(); if (v != def->GetName()) props->AddCall("Name", this, "SetName", Format("%v", v)); // TODO: Escape quotation marks, backslashes, etc. in name
v = this.MaxEnergy; if (v != def.MaxEnergy) props->AddSet ("MaxEnergy", this, "MaxEnergy", this.MaxEnergy);
v = GetEnergy(); if (v != def.MaxEnergy/1000) props->AddCall("Energy", this, "DoEnergy", v-def.MaxEnergy/1000);
v = this.Visibility; if (v != def.Visibility) props->AddSet ("Visibility", this, "Visibility", GetBitmaskNameByValue(v, "VIS_"));
v = this.Visibility; if (v != def.Visibility) props->AddSet ("Visibility", this, "Visibility", SaveScenarioValue2String(v, "VIS_", true));
v = this.Plane; if (v != def.Plane) props->AddSet ("Plane", this, "Plane", v);
v = GetObjectLayer(); var def_layer=nil; if (Contained()) def_layer = Contained()->GetObjectLayer();
if (v != def_layer) props->AddCall("Layer", this, "SetObjectLayer", v);
@ -409,17 +409,17 @@ global func FxFireSaveScen(object obj, proplist fx, proplist props)
/* Helper functions for value formatting */
// Helper function to turn values of several types into a strings to be written to Objects.c
global func SaveScenarioValue2String(v, bitmask_prefix)
global func SaveScenarioValue2String(v, string constant_prefix, bool allow_bitmask)
{
var rval;
if (bitmask_prefix) return GetConstantNameByValueSafe(v, bitmask_prefix);
if (GetType(v) == C4V_C4Object) return v->MakeScenarioSaveName();
if (GetType(v) == C4V_Array) // save procedure for arrays: recurse into contents (cannot save arrays pointing into itself that way)
{
for (var el in v)
{
if (rval) rval = Format("%s,%s", rval, SaveScenarioValue2String(el));
else rval = SaveScenarioValue2String(el);
if (rval) rval = Format("%s,%s", rval, SaveScenarioValue2String(el, constant_prefix, allow_bitmask));
else rval = SaveScenarioValue2String(el, constant_prefix, allow_bitmask);
constant_prefix = nil; // Only first element is actual bitmask (at least or VIS_, and that's the only user for this case)
}
if (rval) rval = Format("[%s]", rval); else rval = "[]";
return rval;
@ -429,6 +429,12 @@ global func SaveScenarioValue2String(v, bitmask_prefix)
rval = v->~ToString();
if (rval) return rval;
}
// int as constant? (treat nil as 0 in this case)
if (constant_prefix)
if (allow_bitmask)
return GetBitmaskNameByValue(v, constant_prefix);
else
return GetConstantNameByValueSafe(v, constant_prefix);
// Otherwise, rely on the default %v formatting
return Format("%v", v);
}