forked from Mirrors/openclonk
fix scenario saving of basements
parent
6772f2da86
commit
807ba20922
|
@ -3,12 +3,23 @@
|
|||
Basic library for structures, handles:
|
||||
* Damage
|
||||
* Energy bar if rule active
|
||||
* Basements
|
||||
|
||||
@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 (this.HitPoints != nil)
|
||||
AddEnergyBar();
|
||||
|
@ -28,4 +39,17 @@ public func Damage(int change, int cause, int cause_plr)
|
|||
}
|
||||
|
||||
// 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; }
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include Library_Structure
|
||||
|
||||
local parent;
|
||||
local width;
|
||||
|
||||
protected func Construction()
|
||||
{
|
||||
|
@ -37,19 +38,33 @@ protected func Destruction()
|
|||
// Set the width of the basement.
|
||||
public func SetWidth(int wdt)
|
||||
{
|
||||
width = wdt;
|
||||
SetShape(-wdt / 2, -4, wdt, 8);
|
||||
SetSolidMask(0, 0, wdt, 8, 20 - wdt / 2, 0);
|
||||
SetObjDrawTransform(1000 * wdt / 40, 0, 0, 0, 1000, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
public func GetWidth() { return width; }
|
||||
|
||||
// Set the parent if the basement is attached to a structure.
|
||||
public func CombineWith(object stick_to)
|
||||
{
|
||||
parent = stick_to;
|
||||
SetParent(stick_to);
|
||||
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.
|
||||
private func MoveOutOfBasement()
|
||||
{
|
||||
|
@ -76,13 +91,14 @@ private func MoveOutOfBasement()
|
|||
obj->SetPosition(x, y - dif);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Is a construction that is built just below the surface.
|
||||
public func IsBelowSurfaceConstruction() { return true; }
|
||||
|
||||
// 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 NoConstructionFlip() { return true; }
|
||||
|
@ -91,6 +107,20 @@ public func NoConstructionFlip() { return true; }
|
|||
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 --*/
|
||||
|
||||
local Name = "$Name$";
|
||||
|
|
|
@ -22,6 +22,8 @@ private func GetCaseSpeed() { return 20; }
|
|||
private func GetAutoSpeed() { 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()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue