Rank -> Branch, rename and Place() functionality

issue1247
Maikel de Vries 2015-01-06 19:25:52 +01:00
parent 2d741dfb70
commit 6ae4e71e6e
12 changed files with 122 additions and 33 deletions

View File

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 37 KiB

View File

@ -1,13 +1,13 @@
[DefCore]
id=Rank
id=Branch
Version=6,0
Category=C4D_StaticBack
Width=28
Height=10
Offset=-14,-5
Vertices=2
VertexX=0,0
VertexY=0,3
Width=10
Height=28
Offset=-5,-14
Vertices=3
VertexX=0,0,0
VertexY=-12,0,12
VertexCNAT=3,4
Mass=1
StretchGrowth=1

View File

@ -1,4 +1,4 @@
material Rank
material Branch
{
receive_shadows on
technique
@ -14,7 +14,7 @@ material Rank
emissive 0.000000 0.000000 0.000000 1.000000
texture_unit
{
texture rank.png
texture Branch.png
tex_address_mode wrap
filtering trilinear
}

View File

@ -0,0 +1,111 @@
/**
Branch
A single branch from a tree which can be placed attached to ceilings or walls.
@author Maikel, Randrian
*/
protected func Initialize()
{
SetProperty("MeshTransformation", Trans_Mul(Trans_Scale(1000, 1400, 1000), Trans_Rotate(RandomX(0, 359), 0, 1, 0)));
SetR(RandomX(-30, 30));
return;
}
protected func Damage()
{
if (GetDamage() > 15)
{
CastObjects(Wood, 1, 25);
RemoveObject();
}
return;
}
public func Place(int amount, proplist rectangle, proplist settings)
{
// Only allow definition call.
if (this != Branch)
return;
// Default parameters.
if (!settings)
settings = { size = [80, 120] };
if (!settings.size)
settings.size = [80, 120];
var loc_area = nil;
if (rectangle)
loc_area = Loc_InRect(rectangle);
var branches = [];
for (var i = 0; i < amount; i++)
{
var size = RandomX(settings.size[0], settings.size[1]);
var loc = FindLocation(Loc_Or(Loc_Sky(), Loc_Tunnel()), Loc_Wall(CNAT_Left | CNAT_Right | CNAT_Top), loc_area);
if (!loc)
continue;
var branch = CreateObject(Branch);
branch->SetPosition(loc.x, loc.y);
branch->SetCon(size);
if (!Random(3))
branch.Plane = 510;
// Adjust orientation and position with respect to landscape.
branch->AdjustOrientation();
branch->AdjustPosition();
// Retry if the center is add a solid location.
if (branch->GBackSolid())
{
branch->RemoveObject();
i--;
continue;
}
PushBack(branches, branch);
}
return branches;
}
// Adjust the orientation of the branch with respect to material.
public func AdjustOrientation()
{
// Make sure it is not stuck in solid with its center.
var dx = 0;
if (GBackSolid(-2, 0) && !GBackSolid(2, 0))
dx = 3;
if (GBackSolid(2, 0) && !GBackSolid(-2, 0))
dx = -3;
var dy = 0;
if (GBackSolid(0, -2) && !GBackSolid(0, 2))
dy = 3;
if (GBackSolid(0, 2) && !GBackSolid(0, -2))
dy = -3;
SetPosition(GetX() + dx, GetY() + dy);
// Check for increasing radius.
for (var d = 0; d < 15 * GetCon() / 100; d++)
// Check 8 directions.
for (var angle = 0; angle < 360; angle += 45)
if (GBackSolid(-Sin(angle, d), Cos(angle, d)))
return SetR(RandomX(angle - 10, angle + 10));
return;
}
// Adjust position with respect to material.
public func AdjustPosition()
{
var angle = GetR();
// Find distance to material.
var d = 0;
while (!GBackSolid(-Sin(angle, d), Cos(angle, d)) && d < 24 * GetCon() / 100)
d++;
// Adjust position.
var size = 12 * GetCon() / 100;
SetPosition(GetX() - Sin(angle, d - size), GetY() + Cos(angle, d - size));
return;
}
/*-- Properties --*/
local Name = "$Name$";
local BlastIncinerate = 1;
local ContactIncinerate = 3;
local Placement = 4;

View File

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

View File

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

View File

@ -1,22 +0,0 @@
/*-- Rank --*/
private func Initialize()
{
SetProperty("MeshTransformation", Trans_Rotate(RandomX(0,359),0,1,0));
SetR(RandomX(-30,30));
}
func Damage()
{
if (GetDamage() > 15)
{
CastObjects(Wood, 1, 25);
RemoveObject();
}
return;
}
local Name = "$Name$";
local BlastIncinerate = 1;
local ContactIncinerate = 3;
local Placement = 4;

View File

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