fix scenario saving of basements

stable-6.1
Maikel de Vries 2015-04-07 18:53:06 +02:00
parent 6772f2da86
commit 807ba20922
3 changed files with 60 additions and 4 deletions

View File

@ -3,12 +3,23 @@
Basic library for structures, handles: Basic library for structures, handles:
* Damage * Damage
* Energy bar if rule active * Energy bar if rule active
* Basements
@author Maikel @author Maikel
*/ */
func Initialize() // All structure related local variables are stored in a single proplist.
// This reduces the chances of clashing local variables. See Initialize
// for which variables are being used.
local lib_structure;
protected func Initialize()
{ {
// Initialize the single proplist for the structure library.
if (lib_structure == nil)
lib_structure = {};
lib_structure.basement = nil;
// Add energy bars if the rule is active.
if (FindObject(Find_ID(Rule_StructureHPBars))) if (FindObject(Find_ID(Rule_StructureHPBars)))
if (this.HitPoints != nil) if (this.HitPoints != nil)
AddEnergyBar(); AddEnergyBar();
@ -28,4 +39,17 @@ public func Damage(int change, int cause, int cause_plr)
} }
// This object is a structure. // This object is a structure.
public func IsStructure() { return true; } public func IsStructure() { return true; }
/*-- Basement Handling --*/
public func SetBasement(object to_basement)
{
lib_structure.basement = to_basement;
return;
}
public func GetBasement() { return lib_structure.basement; }
public func IsStructureWithoutBasement() { return IsStructure() && !lib_structure.basement; }

View File

@ -8,6 +8,7 @@
#include Library_Structure #include Library_Structure
local parent; local parent;
local width;
protected func Construction() protected func Construction()
{ {
@ -37,19 +38,33 @@ protected func Destruction()
// Set the width of the basement. // Set the width of the basement.
public func SetWidth(int wdt) public func SetWidth(int wdt)
{ {
width = wdt;
SetShape(-wdt / 2, -4, wdt, 8); SetShape(-wdt / 2, -4, wdt, 8);
SetSolidMask(0, 0, wdt, 8, 20 - wdt / 2, 0); SetSolidMask(0, 0, wdt, 8, 20 - wdt / 2, 0);
SetObjDrawTransform(1000 * wdt / 40, 0, 0, 0, 1000, 0); SetObjDrawTransform(1000 * wdt / 40, 0, 0, 0, 1000, 0);
return; return;
} }
public func GetWidth() { return width; }
// Set the parent if the basement is attached to a structure. // Set the parent if the basement is attached to a structure.
public func CombineWith(object stick_to) public func CombineWith(object stick_to)
{ {
parent = stick_to; SetParent(stick_to);
return; return;
} }
public func SetParent(object to_parent)
{
parent = to_parent;
SetWidth(BoundBy(parent->GetObjWidth(), 8, 120));
// Notify the parent.
parent->~SetBasement(this);
return;
}
public func GetParent() { return parent; }
// Move objects out of the basement. // Move objects out of the basement.
private func MoveOutOfBasement() private func MoveOutOfBasement()
{ {
@ -76,13 +91,14 @@ private func MoveOutOfBasement()
obj->SetPosition(x, y - dif); obj->SetPosition(x, y - dif);
} }
} }
return;
} }
// Is a construction that is built just below the surface. // Is a construction that is built just below the surface.
public func IsBelowSurfaceConstruction() { return true; } public func IsBelowSurfaceConstruction() { return true; }
// Sticking to other structures, at the bottom of that structure. // Sticking to other structures, at the bottom of that structure.
public func ConstructionCombineWith() { return "IsStructure"; } public func ConstructionCombineWith() { return "IsStructureWithoutBasement"; }
public func ConstructionCombineDirection() { return CONSTRUCTION_STICK_Bottom; } public func ConstructionCombineDirection() { return CONSTRUCTION_STICK_Bottom; }
public func NoConstructionFlip() { return true; } public func NoConstructionFlip() { return true; }
@ -91,6 +107,20 @@ public func NoConstructionFlip() { return true; }
public func IsStructure() { return false; } public func IsStructure() { return false; }
/*-- Saving --*/
public func SaveScenarioObject(proplist props)
{
if (!inherited(props, ...))
return false;
if (parent)
props->AddCall("BasementParent", this, "SetParent", parent);
else if (width)
props->AddCall("BasementWidth", this, "SetWidth", width);
return true;
}
/*-- Proplist --*/ /*-- Proplist --*/
local Name = "$Name$"; local Name = "$Name$";

View File

@ -22,6 +22,8 @@ private func GetCaseSpeed() { return 20; }
private func GetAutoSpeed() { return GetCaseSpeed() * 2; } private func GetAutoSpeed() { return GetCaseSpeed() * 2; }
private func GetDrillSpeed() { return GetCaseSpeed() / 2; } private func GetDrillSpeed() { return GetCaseSpeed() / 2; }
// Case is not a structure, but uses the library.
public func IsStructure() { return false; }
protected func Initialize() protected func Initialize()
{ {