From 85ce25fb0fb15d4b39db62631feba7f82135c31b Mon Sep 17 00:00:00 2001 From: Maikel de Vries Date: Sun, 15 Jan 2017 11:12:35 +0100 Subject: [PATCH] add editor button to place basement under a structure --- .../Structures.ocd/Structure.ocd/Script.c | 22 +++++++++++++++---- .../Structure.ocd/StringTblDE.txt | 2 ++ .../Structure.ocd/StringTblUS.txt | 2 ++ .../Structures.ocd/Basement.ocd/Script.c | 2 ++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Structure.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Structure.ocd/Script.c index dced2d36e..e42463307 100644 --- a/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Structure.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Structure.ocd/Script.c @@ -25,6 +25,9 @@ protected func Construction() lib_structure.repair_materials = []; // Total value of the components - used to calculate the required material for repairing. lib_structure.total_component_value = nil; + // Make a writable copy of the editor action. + if (this.EditorActions == GetID().EditorActions) + MakePropertyWritable("EditorActions"); return _inherited(...); } @@ -96,6 +99,10 @@ private func EjectContentsOnDestruction(int cause, int by_player) public func SetBasement(object to_basement) { lib_structure.basement = to_basement; + if (lib_structure.basement) + this.EditorActions.basement = nil; + else + this.EditorActions.basement = new GetID().EditorActions.basement {}; return; } @@ -110,6 +117,14 @@ public func IsStructureWithoutBasement() return IsStructure() && !(lib_structure && lib_structure.basement); } +public func AddBasement() +{ + var offset = this->~GetBasementOffset() ?? [0, 0]; + var basement = CreateObject(Basement, offset[0], GetBottom() + 4 + offset[1]); + basement->SetParent(this); + return; +} + /*-- SolidMask --*/ @@ -433,10 +448,9 @@ public func Flip() public func Definition(def, ...) { if (!def.EditorProps) def.EditorProps = {}; + if (!def.EditorActions) def.EditorActions = {}; + def.EditorActions.basement = { Name = "$Basement$", EditorHelp = "$BasementHelp$", Command = "AddBasement()" }; if (!def->~NoConstructionFlip()) - { - if (!def.EditorActions) def.EditorActions = {}; - def.EditorActions.flip = { Name="$Flip$", EditorHelp="$FlipHelp$", Command="Flip()" }; - } + def.EditorActions.flip = { Name = "$Flip$", EditorHelp = "$FlipHelp$", Command = "Flip()" }; return _inherited(def, ...); } diff --git a/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Structure.ocd/StringTblDE.txt b/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Structure.ocd/StringTblDE.txt index 969928644..a8a154ee1 100644 --- a/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Structure.ocd/StringTblDE.txt +++ b/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Structure.ocd/StringTblDE.txt @@ -17,3 +17,5 @@ MsgNotFullyConstructed=%s ist noch nicht fertig gebaut.|Im Moment sind keine Int Flip=Umdrehen FlipHelp=Spiegelt das Gebaeude. +Basement=Fundament +BasementHelp=Platziert ein Fundament unter dem Gebäude. \ No newline at end of file diff --git a/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Structure.ocd/StringTblUS.txt b/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Structure.ocd/StringTblUS.txt index 223f6b973..0e3881099 100644 --- a/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Structure.ocd/StringTblUS.txt +++ b/planet/Objects.ocd/Libraries.ocd/Structures.ocd/Structure.ocd/StringTblUS.txt @@ -17,3 +17,5 @@ MsgNotFullyConstructed=%s is not fully constructed yet.|There are no interaction Flip=Flip FlipHelp=Mirrors the structure. +Basement=Basement +BasementHelp=Adds a basement to the structure. \ No newline at end of file diff --git a/planet/Objects.ocd/Structures.ocd/Basement.ocd/Script.c b/planet/Objects.ocd/Structures.ocd/Basement.ocd/Script.c index 368993b3d..d4d832602 100644 --- a/planet/Objects.ocd/Structures.ocd/Basement.ocd/Script.c +++ b/planet/Objects.ocd/Structures.ocd/Basement.ocd/Script.c @@ -36,6 +36,8 @@ func Destruction() { // Cast a single rock. CastObjects(Rock, 1, 15, 0, -5); + // Set basement to nil in parent. + parent->~SetBasement(nil); return _inherited(...); }