forked from Mirrors/openclonk
correctly place/preview basement for elevator (#1534)
parent
447be6c91d
commit
2d22022a20
|
@ -137,6 +137,14 @@ func Reposition(int x, int y)
|
|||
x = other->GetX() + other->GetObjWidth()/2 + dimension_x / 2;
|
||||
if ((stick_dir & CONSTRUCTION_STICK_Bottom))
|
||||
y = other->GetY() + other->GetObjHeight()/2 + dimension_y / 2;
|
||||
// Add an additional offset if needed, for example a basement can be place
|
||||
// only under a part of the structure.
|
||||
var stick_offset = structure->~ConstructionCombineOffset(other);
|
||||
if (stick_offset)
|
||||
{
|
||||
x += stick_offset[0];
|
||||
y += stick_offset[1];
|
||||
}
|
||||
stick_to = other;
|
||||
found = true;
|
||||
}
|
||||
|
|
|
@ -19,12 +19,16 @@ protected func Construction()
|
|||
|
||||
protected func Initialize()
|
||||
{
|
||||
var wdt = BoundBy(GetObjWidth(), 8, 120);
|
||||
var wdt = GetObjWidth();
|
||||
if (parent)
|
||||
wdt = BoundBy(parent->GetObjWidth(), 8, 120);
|
||||
SetWidth(wdt);
|
||||
{
|
||||
wdt = parent->~GetBasementWidth();
|
||||
if (wdt == nil)
|
||||
wdt = parent->GetObjWidth();
|
||||
}
|
||||
SetWidth(BoundBy(wdt, 8, 120));
|
||||
// Move objects out of the basement.
|
||||
MoveOutOfSolidMask();
|
||||
MoveOutOfSolidMask();
|
||||
return _inherited(...);
|
||||
}
|
||||
|
||||
|
@ -57,7 +61,10 @@ public func CombineWith(object stick_to)
|
|||
public func SetParent(object to_parent)
|
||||
{
|
||||
parent = to_parent;
|
||||
SetWidth(BoundBy(parent->GetObjWidth(), 8, 120));
|
||||
var wdt = parent->~GetBasementWidth();
|
||||
if (wdt == nil)
|
||||
wdt = parent->GetObjWidth();
|
||||
SetWidth(BoundBy(wdt, 8, 120));
|
||||
// Notify the parent.
|
||||
parent->~SetBasement(this);
|
||||
return;
|
||||
|
@ -71,6 +78,11 @@ public func IsBelowSurfaceConstruction() { return true; }
|
|||
// Sticking to other structures, at the bottom of that structure.
|
||||
public func ConstructionCombineWith() { return "IsStructureWithoutBasement"; }
|
||||
public func ConstructionCombineDirection() { return CONSTRUCTION_STICK_Bottom; }
|
||||
public func ConstructionCombineOffset(object other)
|
||||
{
|
||||
// Some structures like the elevator require the basement to have an offset.
|
||||
return other->~GetBasementOffset();
|
||||
}
|
||||
|
||||
public func NoConstructionFlip() { return true; }
|
||||
|
||||
|
@ -85,7 +97,11 @@ public func GetSiteWidth(int direction, object combine_with)
|
|||
{
|
||||
var wdt = GetDefWidth();
|
||||
if (combine_with)
|
||||
wdt = combine_with->GetObjWidth();
|
||||
{
|
||||
wdt = combine_with->~GetBasementWidth();
|
||||
if (wdt == nil)
|
||||
wdt = combine_with->GetObjWidth();
|
||||
}
|
||||
return BoundBy(wdt, 8, 120);
|
||||
}
|
||||
|
||||
|
|
|
@ -251,6 +251,11 @@ public func CombineWith(object other)
|
|||
partner = other;
|
||||
}
|
||||
|
||||
// Special requirements for the basement of the elevator.
|
||||
public func GetBasementWidth() { return 36; }
|
||||
public func GetBasementOffset() { return [11 * (2 * GetDir() - 1), 0]; }
|
||||
|
||||
|
||||
/* Combination */
|
||||
|
||||
// Called by a new elevator next to this one
|
||||
|
|
Loading…
Reference in New Issue