Added a simple static ladder to be used by scenario designers.

This thing is a lot faster than the rope ladder.
alut-include-path
Clonkonaut 2017-05-02 22:57:01 +02:00
parent 649c61cd2a
commit 861b0bc08e
10 changed files with 205 additions and 0 deletions

View File

@ -0,0 +1,11 @@
[DefCore]
id=MetalLadder
Version=8,0
Category=C4D_StaticBack
Width=5
Height=80
Offset=-3,-40
Vertices=3
VertexX=0,0,0
VertexY=0,-27,27
Mass=4

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -0,0 +1,8 @@
[DefCore]
id=MetalLadderSegment
Version=8,0
Category=C4D_StaticBack
Width=5
Height=8
Offset=-3,-4
HideInCreator=true

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

View File

@ -0,0 +1,100 @@
/**
Ladder Segment
*/
#include Library_Ladder
local index;
// Called from the ladder object to set a master and the segment index.
public func SetMaster(object new_master, int new_index, ...)
{
// First perform setting the master in the library function.
_inherited(new_master, new_index, ...);
// Then set index and attach to master object.
index = new_index;
AddVertex(0, new_master->GetY() - GetY());
SetAction("Attach", master);
return;
}
// Returns whether the ladder can be climbed.
public func CanNotBeClimbed(bool is_climbing)
{
var test_height = 10;
if (is_climbing)
test_height = 8;
if (GBackSolid(1, test_height) && GBackSolid(-1, test_height))
return true;
return false;
}
// Returns the segment (start x, start y, end x, end y, angle) on which the clonk can climb.
// The coordinate value must be specified with a precision of a 1000.
public func GetLadderData()
{
return [
GetX(1000),
GetY(1000) + 4000,
GetX(1000),
GetY(1000) - 4000,
0
];
}
public func OnLadderGrab(object clonk)
{
if (master)
master->OnLadderGrab(clonk, this, index);
return;
}
public func OnLadderClimb(object clonk)
{
if (master)
master->OnLadderClimb(clonk, this, index);
return;
}
public func OnLadderReleased(object clonk)
{
if (master)
master->OnLadderReleased(clonk, this, index);
return;
}
// Main ladder object is saved.
public func SaveScenarioObject() { return false; }
/*-- Graphics --*/
public func SetPreviousLadder(object ladder)
{
_inherited(ladder);
if (!this->GetNextLadder())
SetGraphics("Top");
else
SetGraphics(nil);
}
public func SetNextLadder(object ladder)
{
_inherited(ladder);
if (!this->GetPreviousLadder())
SetGraphics("Bottom");
else
SetGraphics(nil);
}
/*-- Properties --*/
local ActMap = {
Attach = {
Prototype = Action,
Name = "Attach",
FacetBase = 1,
Procedure = DFA_ATTACH,
},
};

View File

@ -0,0 +1,84 @@
/**
Simple, static ladder
Cannot be built ingame and must be placed by designers. Use the SetLength() function to make it as long as you wish.
@authors: Clonkonaut
*/
local segments;
func Initialize()
{
// Create ladder segments to climb on.
CreateSegments();
}
public func SetLength(int segment_count)
{
if (GetLength(segments) == segment_count) return;
if (segment_count < 2) return;
for (var segment in segments)
segment->RemoveObject();
var new_height = segment_count * 8;
SetShape(-3, new_height / -2, 5, new_height);
CreateSegments();
}
/*-- Ladder Control --*/
// Creates the segments which control the climbing.
func CreateSegments()
{
segments = [];
var nr_segments = (GetBottom() - GetTop()) / 8;
for (var index = 0; index < nr_segments; index++)
{
var y = GetTop() + index * 8;
var segment = CreateObject(MetalLadderSegment, 0, y+4);
segment->SetMaster(this, index);
// Store the segments.
PushBack(segments, segment);
// Set next and previous segment for climbing control.
if (index > 0)
{
segments[index - 1]->SetPreviousLadder(segment);
segment->SetNextLadder(segments[index - 1]);
}
}
}
public func OnLadderGrab(object clonk, object segment, int segment_index)
{
segment->Sound("Clonk::Action::Grab");
}
public func OnLadderClimb(object clonk, object segment, int segment_index)
{
if (clonk->GetComDir() == COMD_Up || clonk->GetComDir() == COMD_Down)
if (!Random(20))
segment->Sound("Clonk::Movement::Rustle?", {volume = 35});
}
public func OnLadderReleased(object clonk, object segment, int segment_index)
{
segment->Sound("Clonk::Action::UnGrab", {volume = 50});
}
/*-- Saving --*/
// Save placed ladder segments in scenarios.
public func SaveScenarioObject(props)
{
if (!inherited(props, ...))
return false;
props->AddCall("Length", this, "SetLength", GetLength(segments));
return true;
}
/*-- Properties --*/
local Name = "$Name$";

View File

@ -0,0 +1 @@
Name=Leiter

View File

@ -0,0 +1 @@
Name=Ladder