forked from Mirrors/openclonk
add vine as new vegetation object
still missing: proper graphics, leave particles which fall offliquid_container
parent
9bb2de333a
commit
66c71b4ab8
|
@ -0,0 +1,11 @@
|
|||
[DefCore]
|
||||
id=Vine
|
||||
Version=6,0
|
||||
Category=C4D_StaticBack
|
||||
Width=10
|
||||
Height=56
|
||||
Offset=-5,-28
|
||||
Vertices=3
|
||||
VertexX=0,0,0
|
||||
VertexY=-27,0,27
|
||||
Mass=4
|
Binary file not shown.
After Width: | Height: | Size: 9.5 KiB |
|
@ -0,0 +1,146 @@
|
|||
/**
|
||||
Vine
|
||||
A single vine which can hang down from ceilings.
|
||||
|
||||
@author Maikel, Randrian
|
||||
*/
|
||||
|
||||
local segments;
|
||||
|
||||
protected func Initialize()
|
||||
{
|
||||
// Create vine segments to climb on.
|
||||
CreateSegments();
|
||||
return;
|
||||
}
|
||||
|
||||
protected func Damage()
|
||||
{
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*-- Ladder Control --*/
|
||||
|
||||
// Creates the segments which control the climbing.
|
||||
private 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(VineSegment, 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]);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Callback by the ladder climb library when the vine is grabbed.
|
||||
public func OnLadderGrab(object clonk, object segment, int segment_index)
|
||||
{
|
||||
segment->Sound("Environment::Vine::Grab?");
|
||||
return;
|
||||
}
|
||||
|
||||
// Callback by the ladder climb library when the vine is climbed.
|
||||
public func OnLadderClimb(object clonk, object segment, int segment_index)
|
||||
{
|
||||
if (clonk->GetComDir() == COMD_Up || clonk->GetComDir() == COMD_Down)
|
||||
if (!Random(20))
|
||||
segment->Sound("Environment::Vine::Grab?", {volume = 35});
|
||||
return;
|
||||
}
|
||||
|
||||
// Callback by the ladder climb library when the vine is released.
|
||||
public func OnLadderReleased(object clonk, object segment, int segment_index)
|
||||
{
|
||||
segment->Sound("Environment::Vine::Grab?", {volume = 50});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*-- Placement --*/
|
||||
|
||||
// Place an amount of branches in the specified area. Settings:
|
||||
// min_dist: the minimal distance between vines (default 32 pixels).
|
||||
public func Place(int amount, proplist area, proplist settings)
|
||||
{
|
||||
// Only allow definition call.
|
||||
if (this != Vine)
|
||||
return;
|
||||
// Default parameters.
|
||||
if (!settings)
|
||||
settings = {};
|
||||
if (!settings.min_dist)
|
||||
settings.min_dist = 32;
|
||||
var loc_area = nil;
|
||||
if (area)
|
||||
loc_area = Loc_InArea(area);
|
||||
var vines = [];
|
||||
var max_tries = Max(200, amount * 20);
|
||||
var nr_created = 0;
|
||||
for (var i = 0; i < max_tries && nr_created < amount; i++)
|
||||
{
|
||||
var loc = FindLocation(Loc_Sky(), Loc_Not(Loc_Liquid()), Loc_Wall(CNAT_Top, Loc_Or(Loc_Material("Granite"), Loc_Material("Rock"), Loc_MaterialVal("Soil", "Material", nil, 1))), loc_area);
|
||||
if (!loc)
|
||||
continue;
|
||||
var vine = CreateObject(Vine);
|
||||
vine->SetPosition(loc.x, loc.y);
|
||||
if (!Random(3))
|
||||
vine.Plane = 510;
|
||||
// Adjust position with respect to landscape.
|
||||
vine->AdjustPosition();
|
||||
// Retry if the center is at a solid location or if another vine is too close.
|
||||
if (vine->GBackSolid() || vine->FindObject(Find_ID(Vine), Find_Distance(settings.min_dist + Random(8)), Find_Exclude(vine)))
|
||||
{
|
||||
vine->RemoveObject();
|
||||
continue;
|
||||
}
|
||||
PushBack(vines, vine);
|
||||
nr_created++;
|
||||
}
|
||||
return vines;
|
||||
}
|
||||
|
||||
// Adjust position with respect to material.
|
||||
public func AdjustPosition()
|
||||
{
|
||||
// Find distance to material.
|
||||
var d = 0;
|
||||
while (!GBackSolid(0, d) && d < 36 * GetCon() / 100)
|
||||
d++;
|
||||
// Adjust position.
|
||||
var size = 12 * GetCon() / 100;
|
||||
SetPosition(GetX(), GetY() + d - size);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*-- Saving --*/
|
||||
|
||||
// Save placed ladder segments in scenarios.
|
||||
public func SaveScenarioObject(props)
|
||||
{
|
||||
if (!inherited(props, ...))
|
||||
return false;
|
||||
props->AddCall("CreateSegments", this, "CreateSegments");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*-- Properties --*/
|
||||
|
||||
local Name = "$Name$";
|
||||
local BlastIncinerate = 1;
|
||||
local ContactIncinerate = 3;
|
||||
local Placement = 4;
|
|
@ -0,0 +1 @@
|
|||
Name=Kletterpflanze
|
|
@ -0,0 +1 @@
|
|||
Name=Vine
|
|
@ -0,0 +1,7 @@
|
|||
[DefCore]
|
||||
id=VineSegment
|
||||
Version=6,0
|
||||
Category=C4D_StaticBack
|
||||
Width=5
|
||||
Height=8
|
||||
Offset=-3,-4
|
|
@ -0,0 +1,80 @@
|
|||
/**
|
||||
Vine Segment
|
||||
|
||||
@author Maikel
|
||||
*/
|
||||
|
||||
#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() + new_master->GetTop());
|
||||
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 vine object is saved.
|
||||
public func SaveScenarioObject() { return false; }
|
||||
|
||||
|
||||
/*-- Properties --*/
|
||||
|
||||
local ActMap = {
|
||||
Attach = {
|
||||
Prototype = Action,
|
||||
Name = "Attach",
|
||||
Procedure = DFA_ATTACH,
|
||||
},
|
||||
};
|
Binary file not shown.
Binary file not shown.
|
@ -5,7 +5,7 @@ Author Work(s)
|
|||
===============================================================================
|
||||
|
||||
ala - Fire/Spark1&2&3, Objects/Weapons/Musket/Click1&2&3, Clonk/Action/Munch2, Clonk/Movement/DivingLoop1&2&3, Animals/Wipf/Snuff3
|
||||
Structures/DoorOpen*, Structures/DoorClose*, Hits/BucketHit*, Objects/Lorry/Dump*, UI/UnCash1&2&3
|
||||
Structures/DoorOpen*, Structures/DoorClose*, Hits/BucketHit*, Objects/Lorry/Dump*, UI/UnCash1&2&3, Environment/Vine/Grab1&2
|
||||
Structures/Repair, Structures/FinishBuilding made from following resources:
|
||||
- JoelAudio: https://www.freesound.org/people/JoelAudio/sounds/135860/ - CC-By 3.0
|
||||
- cmusounddesign: https://www.freesound.org/people/cmusounddesign/sounds/84696 - CC-By 3.0
|
||||
|
|
Loading…
Reference in New Issue