From 2d22022a2046f00ee4bdb0e8b5a1052f7482a53b Mon Sep 17 00:00:00 2001 From: Maikel de Vries Date: Sat, 30 Jan 2016 12:13:03 +0100 Subject: [PATCH] correctly place/preview basement for elevator (#1534) --- .../ConstructionPreviewer.ocd/Script.c | 8 ++++++ .../Structures.ocd/Basement.ocd/Script.c | 28 +++++++++++++++---- .../Structures.ocd/Elevator.ocd/Script.c | 5 ++++ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/planet/Objects.ocd/Libraries.ocd/Constructor.ocd/ConstructionPreviewer.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/Constructor.ocd/ConstructionPreviewer.ocd/Script.c index 52b8ed929..c13ff82bd 100644 --- a/planet/Objects.ocd/Libraries.ocd/Constructor.ocd/ConstructionPreviewer.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/Constructor.ocd/ConstructionPreviewer.ocd/Script.c @@ -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; } diff --git a/planet/Objects.ocd/Structures.ocd/Basement.ocd/Script.c b/planet/Objects.ocd/Structures.ocd/Basement.ocd/Script.c index b539a14f0..9fd0c6c8e 100644 --- a/planet/Objects.ocd/Structures.ocd/Basement.ocd/Script.c +++ b/planet/Objects.ocd/Structures.ocd/Basement.ocd/Script.c @@ -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); } diff --git a/planet/Objects.ocd/Structures.ocd/Elevator.ocd/Script.c b/planet/Objects.ocd/Structures.ocd/Elevator.ocd/Script.c index 6c98159e2..066360fb7 100644 --- a/planet/Objects.ocd/Structures.ocd/Elevator.ocd/Script.c +++ b/planet/Objects.ocd/Structures.ocd/Elevator.ocd/Script.c @@ -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