stalactite: fix raindrop, allow placing in sky, fix stalagmite, clean up

stable-8
Maikel de Vries 2018-02-05 16:53:07 +01:00
parent 64c08e1510
commit 0f48bb2a86
3 changed files with 43 additions and 46 deletions

View File

@ -4,11 +4,11 @@ Version=8,0
Category=C4D_Object
Width=15
Height=60
Offset=-7, 0
Offset=-7,0
Vertices=2
VertexX=0, 0
VertexY=0, 60
VertexCNAT=4, 8
VertexX=0,0
VertexY=0,60
VertexCNAT=4,8
VertexFriction=300,300
Mass=35
StretchGrowth=1

View File

@ -20,8 +20,6 @@ public func Construction()
transformation = Trans_Rotate(RandomX(-20, 20), 0, 0, 1);
sibling = TransformBone(bone, transformation, 1, Anim_Const(1000), sibling);
}
AddRainDropEffect(nil, RandomX(80, 120), "Water", RandomX(1, 5));
}
private func Hit()
@ -69,14 +67,23 @@ public func Place(int amount, proplist rectangle, proplist settings)
return;
}
// Default parameters.
if (!settings)
settings = {};
var loc_area = nil;
if (rectangle)
loc_area = Loc_InRect(rectangle);
var loc_background;
if (settings.underground == nil)
loc_background = Loc_Or(Loc_Sky(), Loc_Tunnel());
else if (settings.underground)
loc_background = Loc_Tunnel();
else
loc_background = Loc_Sky();
var stalactites = [];
for (var i = 0; i < amount; i++)
{
var loc = FindLocation(Loc_Tunnel(), Loc_Not(Loc_Liquid()), Loc_Wall(CNAT_Top), Loc_Space(40, CNAT_Bottom), loc_area);
var loc = FindLocation(loc_background, Loc_Not(Loc_Liquid()), Loc_Wall(CNAT_Top), Loc_Space(40, CNAT_Bottom), loc_area);
if (!loc)
continue;
var mat = MaterialName(GetMaterial(loc.x, loc.y - 1));
@ -106,7 +113,7 @@ public func Place(int amount, proplist rectangle, proplist settings)
if (ground_y)
{
height = ground_y - loc.y;
con = Min(con, BoundBy(100 * height / 60 / 2, 25, 100));
con = Min(con, BoundBy(100 * height / 120, 25, 100));
}
@ -146,40 +153,26 @@ private func CreateStalactite(int x, int y, string mat, bool stalagmite)
colour = HSL(hue, 100, 200);
stalactite->SetClrModulation(colour);
}
if (!stalagmite && Random(2))
stalactite->DrawWaterSource();
}
if (stalagmite)
{
stalactite->SetR(180);
stalactite.MeshTransformation = Trans_Mul(Trans_Translate(0, 10 * stalactite->GetDefHeight() * stalactite->GetCon(), 0), stalactite.MeshTransformation);
}
else if (mat != "Ice")
{
// Add rain drop effect for stalactites only.
stalactite->AddRainDropEffect(nil, RandomX(80, 120), "Water", RandomX(1, 5), 0, 4);
}
return stalactite;
}
private func DrawWaterSource()
public func OnRainDropCreated(effect fx_drop)
{
var xold = GetX();
var yold = GetY() - 2;
var xnew = xold;
var ynew = xnew;
for (var i = 0; i < RandomX(30, 140); i++)
{
ynew--;
xnew = xold + RandomX(-1, 1);
if (GBackSemiSolid(xnew-GetX(), ynew-GetY()))
DrawMaterialQuad("Water", xold,yold, xold+1,yold, xold+1,yold+1, xold,yold+1);
else
return;
xold = xnew;
yold = ynew;
}
}
public func OnRainDropCreated()
{
if (Random(9)) return;
if (Random(9))
return;
Sound("Liquids::Waterdrop*");
}

View File

@ -88,30 +88,36 @@ Creates a raindrop effect upon the the calling object.
@strength Specifies how many drops are created in a call.
@return The created effect.
*/
global func AddRainDropEffect(int duration, int interval, string material, int strength)
global func AddRainDropEffect(int duration, int interval, string material, int strength, int offset_x, int offset_y)
{
if(!this || GetType(this) != C4V_C4Object) FatalError(Format("AddRainDropEffect needs to be called from object context, not from %v", this));
return this->CreateEffect(FxRainDrop, 1, interval ?? 10, duration, material, strength);
if (!this || GetType(this) != C4V_C4Object)
FatalError(Format("AddRainDropEffect needs to be called from object context, not from %v", this));
return this->CreateEffect(FxRainDrop, 1, interval ?? 10, duration, material, strength, [offset_x, offset_y]);
}
static const FxRainDrop = new Effect {
static const FxRainDrop = new Effect
{
duration = nil,
material = nil,
strength = nil,
offset = [0, 0],
particle_cache = {},
Construction = func(int duration, string material, int strength) {
Construction = func(int duration, string material, int strength, array offset)
{
this.duration = duration;
this.material = material ?? "Water";
this.strength = strength ?? 1;
this.offset = offset ?? [0, 0];
},
Timer = func(int time) {
if (!this.Target || (this.duration != nil && time > this.duration)) return FX_Execute_Kill;
Timer = func(int time)
{
if (!this.Target || (this.duration != nil && time > this.duration))
return FX_Execute_Kill;
if (this.Target->GBackSemiSolid()) return;
if (this.Target->GBackSemiSolid(this.offset[0], this.offset[1]))
return FX_OK;
var con = this.Target->GetCon();
var wdt = this.Target->GetDefWidth() * con / 500;
@ -129,20 +135,18 @@ static const FxRainDrop = new Effect {
if (this.material == "Lava" || this.material == "DuroLava")
particle_name = "RaindropLava";
else
particle_name = "Raindrop";
this.Target->CreateParticle(
particle_name,
PV_Random(-wdt, wdt),
PV_Random(-hgt, hgt),
PV_Random(this.offset[0] - wdt, this.offset[0] + wdt),
PV_Random(this.offset[1] - hgt, this.offset[1] + hgt),
PV_Random(-5, 5),
PV_Random(10, 30),
PV_Random(200, 300),
this.particle_cache.particle,
this.strength
);
);
this.Target->~OnRainDropCreated(this);
return FX_OK;