possibility to attach basement to existing structures

TODO: increased preview size and costs.
issue1247
Maikel de Vries 2014-05-30 15:18:25 +02:00
parent acecebfdd6
commit 09a2033ec0
5 changed files with 56 additions and 26 deletions

View File

@ -5,6 +5,10 @@
@author Clonkonaut
*/
static const CONSTRUCTION_STICK_Left = 1;
static const CONSTRUCTION_STICK_Right = 2;
static const CONSTRUCTION_STICK_Bottom = 4;
local dimension_x, dimension_y, clonk, structure, direction, stick_to, blocked;
local GFX_StructureOverlay = 1;
local GFX_CombineIconOverlay = 2;
@ -35,6 +39,7 @@ func Set(id to_construct, object constructing_clonk)
func AdjustPreview(bool below_surface, bool look_up, bool no_call)
{
var half_y = dimension_y / 2;
blocked = false;
// Do only if not sticking to another object
if (!stick_to)
{
@ -42,7 +47,6 @@ func AdjustPreview(bool below_surface, bool look_up, bool no_call)
var search_dir = 1;
if (look_up) search_dir = -1;
var x = 0, y = 0;
blocked = false;
while (!(!GBackSolid(x,y + half_y) && GBackSolid(x,y + half_y + 1)))
{
y += search_dir;
@ -63,21 +67,14 @@ func AdjustPreview(bool below_surface, bool look_up, bool no_call)
else
SetPosition(GetX(), GetY() + y + dimension_y + 1);
}
// Check for construction site.
if (!below_surface && !CheckConstructionSite(structure, 0, half_y))
blocked = true;
else
// intersection-check with all other construction sites... bah
for (var other_site in FindObjects(Find_ID(ConstructionSite)))
{
// intersection-check with all other construction sites... bah
for(var other_site in FindObjects(Find_ID(ConstructionSite)))
{
if(!(other_site->GetLeftEdge() > GetX()+dimension_x/2 ||
other_site->GetRightEdge() < GetX()-dimension_x/2 ||
other_site->GetTopEdge() > GetY()+half_y ||
other_site->GetBottomEdge() < GetY()-half_y))
{
blocked = true;
}
}
if (!(other_site->GetLeftEdge() > GetX()+dimension_x/2 || other_site->GetRightEdge() < GetX()-dimension_x/2 || other_site->GetTopEdge() < GetY()+half_y || other_site->GetBottomEdge() > GetY()-half_y))
blocked = true;
}
if(!blocked)
@ -97,6 +94,7 @@ func Reposition(int x, int y)
{
x = BoundBy(x, -dimension_x/2, dimension_x/2);
y = BoundBy(y, -dimension_y/2, dimension_y/2);
// Try to combine the structure with other structures.
var found = false;
if (structure->~ConstructionCombineWith())
{
@ -108,11 +106,16 @@ func Reposition(int x, int y)
Find_NoContainer());
if (other)
{
if (other->GetX() < GetX())
x = other->GetX() + other->GetObjWidth()/2 + dimension_x / 2;
else
x = other->GetX() - other->GetObjWidth()/2 - dimension_x / 2;
var stick_dir = structure->~ConstructionCombineDirection();
x = other->GetX();
y = other->GetY();
// Combine to different directions.
if ((stick_dir & CONSTRUCTION_STICK_Left) && other->GetX() >= GetX())
x = other->GetX() - other->GetObjWidth()/2 - dimension_x / 2;
if ((stick_dir & CONSTRUCTION_STICK_Right) && other->GetX() < GetX())
x = other->GetX() + other->GetObjWidth()/2 + dimension_x / 2;
if ((stick_dir & CONSTRUCTION_STICK_Bottom))
y = other->GetY() + other->GetObjHeight()/2 + dimension_y / 2;
stick_to = other;
found = true;
}
@ -127,10 +130,14 @@ func Reposition(int x, int y)
{
stick_to = nil;
SetGraphics(nil, nil, GFX_CombineIconOverlay);
} else if (stick_to) {
}
else if (stick_to)
{
SetGraphics(nil, ConstructionPreviewer_IconCombine, GFX_CombineIconOverlay, GFXOV_MODE_Base);
var dir = 1;
if (stick_to->GetX() < GetX()) dir = -1;
if (structure->~CombineToBottom())
dir = 0;
SetObjDrawTransform(1000, 0, dimension_x/2 * 1000 * dir, 0, 1000, 0, GFX_CombineIconOverlay);
}

View File

@ -40,22 +40,22 @@ public func Set(id def, int dir, object stick)
direction = dir;
stick_to = stick;
var xw = (1-dir*2)*1000;
// Height of construction site needs to exceed 12 pixels for the clonk to be able to add materials.
var xw = (1 - dir * 2) * 1000;
var w, h;
w = def->GetDefWidth();
h = Max(12, def->GetDefHeight());
h = def->GetDefHeight();
// Draw the building with a wired frame and large alpha.
SetGraphics(nil, def, 1, GFXOV_MODE_Base);
SetClrModulation(RGBa(255,255,255,50), 1);
SetObjDrawTransform(xw,0,0,0,1000, -h*500,1);
SetGraphics(nil, def, 2, GFXOV_MODE_Base, nil, GFX_BLIT_Wireframe);
SetObjDrawTransform(xw,0,0,0,1000, -h*500,2);
// Height of construction site needs to exceed 12 pixels for the clonk to be able to add materials.
h = Max(12, h);
SetShape(-w/2, -h, w, h);
// Increase shape for below surface constructions to allow for adding materials.
if (definition->~IsBelowSurfaceConstruction())
SetShape(-w/2, -2*h, w, 2*h);
SetShape(-w/2, -2 * h, w, 2 * h);
SetName(Translate(Format("TxtConstruction",def->GetName())));

View File

@ -25,4 +25,7 @@ public func Damage(int change, int cause, int cause_plr)
return RemoveObject();
}
return _inherited(change, cause, cause_plr);
}
}
// This object is a structure.
public func IsStructure() { return true; }

View File

@ -7,6 +7,7 @@
#include Library_Structure
local parent;
protected func Construction()
{
@ -18,6 +19,8 @@ protected func Construction()
protected func Initialize()
{
var wdt = BoundBy(GetObjWidth(), 8, 120);
if (parent)
wdt = BoundBy(parent->GetObjWidth(), 8, 120);
SetShape(-wdt / 2, -4, wdt, 8);
SetSolidMask(0, 0, wdt, 8, 20 - wdt / 2, 0);
SetObjDrawTransform(1000 * wdt / 40, 0, 0, 0, 1000, 0);
@ -33,6 +36,13 @@ protected func Destruction()
return _inherited(...);
}
// Set the parent if the basement is attached to a structure.
public func CombineWith(object stick_to)
{
parent = stick_to;
return;
}
// Move objects out of the basement.
private func MoveOutOfBasement()
{
@ -64,6 +74,15 @@ private func MoveOutOfBasement()
// 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 ConstructionCombineDirection() { return CONSTRUCTION_STICK_Bottom; }
public func NoConstructionFlip() { return true; }
// Don't stick to itself, so it should not be a structure.
public func IsStructure() { return false; }
/*-- Proplist --*/

View File

@ -124,7 +124,8 @@ func StopEngine()
/* Construction */
// Sticking to other elevators
func ConstructionCombineWith() { return "IsElevator"; }
public func ConstructionCombineWith() { return "IsElevator"; }
public func ConstructionCombineDirection() { return CONSTRUCTION_STICK_Left | CONSTRUCTION_STICK_Right; }
// Called to determine if sticking is possible
func IsElevator(object previewer)