forked from Mirrors/openclonk
waterfall: implement editor interface
parent
a85a3201d9
commit
97f87019b7
|
@ -35,9 +35,9 @@ protected func Initialize()
|
||||||
|
|
||||||
var waterfall;
|
var waterfall;
|
||||||
waterfall = CreateWaterfall(130, 53, 2, "Water");
|
waterfall = CreateWaterfall(130, 53, 2, "Water");
|
||||||
waterfall->SetDirection(4, 0, 3, 6);
|
waterfall->SetDirection(6, 3, 2, 3);
|
||||||
waterfall = CreateWaterfall(144, 50, 8, "Water");
|
waterfall = CreateWaterfall(144, 50, 8, "Water");
|
||||||
waterfall->SetDirection(6, 0, 5, 6);
|
waterfall->SetDirection(9, 3, 3, 3);
|
||||||
CreateLiquidDrain(100, 315, 10);
|
CreateLiquidDrain(100, 315, 10);
|
||||||
CreateLiquidDrain(130, 315, 10);
|
CreateLiquidDrain(130, 315, 10);
|
||||||
CreateLiquidDrain(160, 315, 10);
|
CreateLiquidDrain(160, 315, 10);
|
||||||
|
|
|
@ -2,3 +2,6 @@
|
||||||
id=Waterfall
|
id=Waterfall
|
||||||
Version=8,0
|
Version=8,0
|
||||||
Category=C4D_StaticBack
|
Category=C4D_StaticBack
|
||||||
|
Width=32
|
||||||
|
Height=32
|
||||||
|
Offset=-16,-16
|
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
|
@ -1,82 +1,105 @@
|
||||||
/*--
|
/**
|
||||||
Waterfall
|
Waterfall
|
||||||
Author: Maikel
|
|
||||||
|
|
||||||
Waterfall object, use to place waterfalls in the landscape.
|
Waterfall object, use to place waterfalls in the landscape.
|
||||||
--*/
|
|
||||||
|
|
||||||
|
@author Maikel
|
||||||
|
*/
|
||||||
|
|
||||||
protected func Initialize()
|
|
||||||
{
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*-- Waterfall --*/
|
/*-- Waterfall --*/
|
||||||
|
|
||||||
global func CreateWaterfall(int x, int y, int strength, string mat)
|
global func CreateWaterfall(int x, int y, int strength, string mat)
|
||||||
{
|
{
|
||||||
var fall = CreateObjectAbove(Waterfall, x, y, NO_OWNER);
|
var waterfall = CreateObjectAbove(Waterfall, x, y, NO_OWNER);
|
||||||
if (!mat) mat = "Water";
|
if (!mat)
|
||||||
AddEffect("IntWaterfall", fall, 100, 1, fall, nil, x, y, strength, mat);
|
mat = "Water";
|
||||||
return fall;
|
waterfall->CreateEffect(waterfall.FxWaterfallLiquidSource, 100, 1, x, y, strength, mat);
|
||||||
|
return waterfall;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected func FxIntWaterfallStart(object target, proplist effect, int temporary, int x, int y, int strength, string mat)
|
local FxWaterfallLiquidSource = new Effect
|
||||||
{
|
{
|
||||||
if (temporary)
|
Construction = func(int x, int y, int strength, string mat)
|
||||||
return 1;
|
{
|
||||||
effect.X = x;
|
this.source_position = [x, y];
|
||||||
effect.Y = y;
|
this.source_direction = [x, y];
|
||||||
effect.Strength = strength;
|
this.source_x = x;
|
||||||
effect.Material = mat;
|
this.source_y = y;
|
||||||
// Start sound.
|
this.source_strength = strength;
|
||||||
target->Sound("Environment::Waterfall", false, 5 * effect.Strength, nil, 1);
|
this.source_mat = mat;
|
||||||
return 1;
|
// Start sound.
|
||||||
}
|
Target->Sound("Environment::Waterfall", false, 5 * this.source_strength, nil, 1);
|
||||||
|
return FX_OK;
|
||||||
protected func FxIntWaterfallTimer(object target, proplist effect)
|
},
|
||||||
{
|
Timer = func(int time)
|
||||||
// Insert liquid at location every frame.
|
{
|
||||||
for (var i = 0; i < effect.Strength / 2; i++)
|
// Insert liquid at location every frame.
|
||||||
InsertMaterial(Material(effect.Material), AbsX(effect.X), AbsY(effect.Y), effect.XDir + Random(effect.XVar), effect.YDir + Random(effect.YVar));
|
for (var i = 0; i < this.source_strength / 2; i++)
|
||||||
return 1;
|
Global->InsertMaterial(Material(this.source_mat), this.source_x, this.source_y, this.xdir + RandomX(-this.xvar, this.xvar), this.ydir + RandomX(-this.yvar, this.yvar));
|
||||||
}
|
return FX_OK;
|
||||||
|
},
|
||||||
protected func FxIntWaterfallStop(object target, proplist effect, bool temporary)
|
Destruction = func()
|
||||||
{
|
{
|
||||||
if (temporary)
|
// Stop sound.
|
||||||
return 1;
|
Target->Sound("Environment::Waterfall", false, 5 * this.source_strength, nil, -1);
|
||||||
// Stop sound.
|
return FX_OK;
|
||||||
target->Sound("Environment::Waterfall", false, 5 * effect.Strength, nil, -1);
|
},
|
||||||
return 1;
|
EditorProps =
|
||||||
}
|
{
|
||||||
|
source_strength = { Name = "$EditorSourceStrength$", EditorHelp = "$EditorSourceStrengthHelp$", Type = "int", Min = 2, Max = 100 },
|
||||||
|
source_mat = { Name = "$EditorSourceMaterial$", EditorHelp = "$EditorSourceMaterialHelp$", Type = "enum", Options = [
|
||||||
|
{ Name = "$EditorSourceMaterialWater$", Value = "Water" },
|
||||||
|
{ Name = "$EditorSourceMaterialAcid$", Value = "Acid" },
|
||||||
|
{ Name = "$EditorSourceMaterialLava$", Value = "Lava" },
|
||||||
|
{ Name = "$EditorSourceMaterialDuroLava$", Value = "DuroLava" },
|
||||||
|
{ Name = "$EditorSourceMaterialOil$", Value = "Oil" }
|
||||||
|
] },
|
||||||
|
// TODO: Replace these two properties with an arrow in editor once available.
|
||||||
|
source_position = { Name = "$EditorSourcePosition$", EditorHelp = "$EditorSourcePositionHelp$", Type = "point", Relative = false, Color = 0x008fff, Set = "SetSourcePosition" },
|
||||||
|
source_direction = { Name = "$EditorSourceDirection$", EditorHelp = "$EditorSourceDirectionHelp$", Type = "point", Relative = false, Color = 0x006bbb, Set = "SetSourceDirection" }
|
||||||
|
},
|
||||||
|
SetSourcePosition = func(array pos)
|
||||||
|
{
|
||||||
|
this.source_position = pos;
|
||||||
|
this.source_x = pos[0];
|
||||||
|
this.source_y = pos[1];
|
||||||
|
},
|
||||||
|
SetSourceDirection = func(array dir)
|
||||||
|
{
|
||||||
|
this.source_direction = dir;
|
||||||
|
this.xdir = dir[0] - this.source_x;
|
||||||
|
this.ydir = dir[1] - this.source_y;
|
||||||
|
this.xvar = Abs(this.xdir / 2);
|
||||||
|
this.yvar = Abs(this.ydir / 2);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public func SetStrength(int strength)
|
public func SetStrength(int strength)
|
||||||
{
|
{
|
||||||
var effect = GetEffect("IntWaterfall", this);
|
var fx_waterfall = GetEffect("FxWaterfallLiquidSource", this);
|
||||||
if (effect)
|
if (fx_waterfall)
|
||||||
effect.Strength = BoundBy(strength, 0, 100);
|
fx_waterfall.source_strength = BoundBy(strength, 0, 100);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public func SetMaterial(int material)
|
public func SetMaterial(int material)
|
||||||
{
|
{
|
||||||
var effect = GetEffect("IntWaterfall", this);
|
var fx_waterfall = GetEffect("FxWaterfallLiquidSource", this);
|
||||||
if (effect)
|
if (fx_waterfall)
|
||||||
effect.Material = material;
|
fx_waterfall.source_mat = material;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public func SetDirection(int xdir, int ydir, int xvar, int yvar)
|
public func SetDirection(int xdir, int ydir, int xvar, int yvar)
|
||||||
{
|
{
|
||||||
var effect = GetEffect("IntWaterfall", this);
|
var fx_waterfall = GetEffect("FxWaterfallLiquidSource", this);
|
||||||
if (effect)
|
if (fx_waterfall)
|
||||||
{
|
{
|
||||||
effect.XDir = xdir;
|
fx_waterfall.xdir = xdir;
|
||||||
effect.YDir = ydir;
|
fx_waterfall.ydir = ydir;
|
||||||
effect.XVar = xvar;
|
fx_waterfall.xvar = xvar;
|
||||||
effect.YVar = yvar;
|
fx_waterfall.yvar = yvar;
|
||||||
|
fx_waterfall.source_direction = [fx_waterfall.source_x + xdir, fx_waterfall.source_y + ydir];
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -85,58 +108,100 @@ public func SetSoundLocation(int x, int y)
|
||||||
{
|
{
|
||||||
SetPosition(x, y);
|
SetPosition(x, y);
|
||||||
// Update sound.
|
// Update sound.
|
||||||
var effect = GetEffect("IntWaterfall", this);
|
var fx_waterfall = GetEffect("FxWaterfallLiquidSource", this);
|
||||||
if (effect)
|
if (fx_waterfall)
|
||||||
Sound("Environment::Waterfall", false, 5 * effect.Strength, nil, 1);
|
Sound("Environment::Waterfall", false, 5 * fx_waterfall.source_strength, nil, 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scenario saving
|
|
||||||
func SaveScenarioObject(props)
|
|
||||||
{
|
|
||||||
if (!inherited(props, ...)) return false;
|
|
||||||
var fx_waterfall = GetEffect("IntWaterfall", this), fx_drain = GetEffect("IntLiquidDrain", this);
|
|
||||||
if (!fx_waterfall && !fx_drain) return false; // effects lost? don't save dead object then
|
|
||||||
// Waterfall has its own creation procedure
|
|
||||||
props->RemoveCreation();
|
|
||||||
if (fx_waterfall)
|
|
||||||
{
|
|
||||||
props->Add(SAVEOBJ_Creation, "CreateWaterfall(%d, %d, %d, %v)",fx_waterfall.X, fx_waterfall.Y, fx_waterfall.Strength, fx_waterfall.Material);
|
|
||||||
if (fx_waterfall.X != GetX() || fx_waterfall.Y != GetY()) props->AddCall("Position", this, "SetSoundLocation", GetX(), GetY());
|
|
||||||
if (fx_waterfall.XDir || fx_waterfall.YDir || fx_waterfall.XVar || fx_waterfall.YVar)
|
|
||||||
props->AddCall("Direction", this, "SetDirection", fx_waterfall.XDir, fx_waterfall.YDir, fx_waterfall.XVar, fx_waterfall.YVar);
|
|
||||||
}
|
|
||||||
if (fx_drain) props->Add(SAVEOBJ_Creation, "CreateLiquidDrain(%d, %d, %d)",fx_drain.X, fx_drain.Y, fx_drain.Strength);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*-- Liquid Drain --*/
|
/*-- Liquid Drain --*/
|
||||||
|
|
||||||
global func CreateLiquidDrain(int x, int y, int strength)
|
global func CreateLiquidDrain(int x, int y, int strength)
|
||||||
{
|
{
|
||||||
var drain = CreateObjectAbove(Waterfall, x, y, NO_OWNER);
|
var drain = CreateObjectAbove(Waterfall, x, y, NO_OWNER);
|
||||||
AddEffect("IntLiquidDrain", drain, 100, 1, drain, nil, x, y, strength);
|
drain->CreateEffect(drain.FxWaterfallLiquidDrain, 100, 1, x, y, strength);
|
||||||
return drain;
|
return drain;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected func FxIntLiquidDrainStart(object target, proplist effect, int temporary, int x, int y, int strength)
|
local FxWaterfallLiquidDrain = new Effect
|
||||||
{
|
{
|
||||||
if (temporary)
|
Construction = func(int x, int y, int strength)
|
||||||
return 1;
|
{
|
||||||
effect.X = x;
|
this.drain_position = [x, y];
|
||||||
effect.Y = y;
|
this.drain_x = x;
|
||||||
effect.Strength = strength;
|
this.drain_y = y;
|
||||||
return 1;
|
this.drain_strength = strength;
|
||||||
}
|
return FX_OK;
|
||||||
|
},
|
||||||
|
Timer = func(int time)
|
||||||
|
{
|
||||||
|
Global->ExtractLiquidAmount(this.drain_x, this.drain_y, this.drain_strength / 2);
|
||||||
|
return FX_OK;
|
||||||
|
},
|
||||||
|
EditorProps =
|
||||||
|
{
|
||||||
|
drain_strength = { Name = "$EditorDrainStrength$", EditorHelp = "$EditorDrainStrengthHelp$", Type = "int", Min = 2, Max = 100},
|
||||||
|
drain_position = { Name = "$EditorDrainPosition$", EditorHelp = "$EditorDrainPositionHelp$", Type = "point", Relative = false, Color = 0x00ff8f, Set = "SetDrainPosition" }
|
||||||
|
},
|
||||||
|
SetDrainPosition = func(array pos)
|
||||||
|
{
|
||||||
|
this.drain_position = pos;
|
||||||
|
this.drain_x = pos[0];
|
||||||
|
this.drain_y = pos[1];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
protected func FxIntLiquidDrainTimer(object target, proplist effect)
|
|
||||||
|
/*-- Editor --*/
|
||||||
|
|
||||||
|
public func EditorInitialize()
|
||||||
{
|
{
|
||||||
ExtractLiquidAmount(AbsX(effect.X), AbsY(effect.Y),effect.Strength / 2);
|
// Init waterfall with the source directly above the drain.
|
||||||
return 1;
|
this->CreateEffect(this.FxWaterfallLiquidSource, 100, 1, GetX(), GetY() - 40, 10, "Water");
|
||||||
|
this->CreateEffect(this.FxWaterfallLiquidDrain, 100, 1, GetX(), GetY() + 40, 10);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-- Scenario Saving --*/
|
||||||
|
|
||||||
|
public func SaveScenarioObject(proplist props)
|
||||||
|
{
|
||||||
|
if (!inherited(props, ...))
|
||||||
|
return false;
|
||||||
|
var fx_source = GetEffect("FxWaterfallLiquidSource", this);
|
||||||
|
var fx_drain = GetEffect("FxWaterfallLiquidDrain", this);
|
||||||
|
if (!fx_source && !fx_drain)
|
||||||
|
return false;
|
||||||
|
if (fx_source)
|
||||||
|
{
|
||||||
|
props->AddCall("SourceEffect", this, "AddSourceEffect", fx_source.source_x, fx_source.source_y, fx_source.source_strength, Format("%v", fx_source.source_mat));
|
||||||
|
if (fx_source.source_x != GetX() || fx_source.source_y != GetY())
|
||||||
|
props->AddCall("SoundLocation", this, "SetSoundLocation", GetX(), GetY());
|
||||||
|
if (fx_source.xdir || fx_source.xdir || fx_source.xvar || fx_source.yvar)
|
||||||
|
props->AddCall("Direction", this, "SetDirection", fx_source.xdir, fx_source.ydir, fx_source.xvar, fx_source.yvar);
|
||||||
|
}
|
||||||
|
if (fx_drain)
|
||||||
|
props->AddCall("DrainEffect", this, "AddDrainEffect", fx_drain.drain_x, fx_drain.drain_y, fx_drain.drain_strength);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public func AddSourceEffect(int x, int y, int strength, string mat)
|
||||||
|
{
|
||||||
|
CreateEffect(this.FxWaterfallLiquidSource, 100, 1, x, y, strength, mat);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public func AddDrainEffect(int x, int y, int strength)
|
||||||
|
{
|
||||||
|
CreateEffect(this.FxWaterfallLiquidDrain, 100, 1, x, y, strength);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*-- Properties --*/
|
||||||
|
|
||||||
local Name = "$Name$";
|
local Name = "$Name$";
|
||||||
|
local Description = "$Description$";
|
||||||
|
local Visibility = VIS_Editor;
|
||||||
|
|
|
@ -1 +1,21 @@
|
||||||
Name=Wasserfall
|
Name=Wasserfall
|
||||||
|
Description=Spawns liquid pixels at a regular interval, place at a cliff to create a waterfall. The waterfall sound is played at the position of this object.
|
||||||
|
|
||||||
|
EditorSourceStrength=Source strength
|
||||||
|
EditorSourceStrengthHelp=Amount of pixels the sources creates per 2 frames.
|
||||||
|
EditorSourceMaterial=Source material
|
||||||
|
EditorSourceMaterialHelp=The type of liquid to create.
|
||||||
|
EditorSourceMaterialWater=Water
|
||||||
|
EditorSourceMaterialAcid=Acid
|
||||||
|
EditorSourceMaterialLava=Lava
|
||||||
|
EditorSourceMaterialDuroLava=DuroLava
|
||||||
|
EditorSourceMaterialOil=Oil
|
||||||
|
EditorSourcePosition=Source position
|
||||||
|
EditorSourcePositionHelp=Set the position of the source.
|
||||||
|
EditorSourceDirection=Source direction
|
||||||
|
EditorSourceDirectionHelp=Set the direction of liquid insertion, relative to the source position.
|
||||||
|
|
||||||
|
EditorDrainStrength=Drain strength
|
||||||
|
EditorDrainStrengthHelp=Amount of pixels the drain removes per 2 frames.
|
||||||
|
EditorDrainPosition=Drain position
|
||||||
|
EditorDrainPositionHelp=Set the position of the drain.
|
|
@ -1 +1,21 @@
|
||||||
Name=Waterfall
|
Name=Waterfall
|
||||||
|
Description=Spawns liquid pixels at a regular interval, place at a cliff to create a waterfall. The waterfall sound is played at the position of this object.
|
||||||
|
|
||||||
|
EditorSourceStrength=Source strength
|
||||||
|
EditorSourceStrengthHelp=Amount of pixels the sources creates per 2 frames.
|
||||||
|
EditorSourceMaterial=Source material
|
||||||
|
EditorSourceMaterialHelp=The type of liquid to create.
|
||||||
|
EditorSourceMaterialWater=Water
|
||||||
|
EditorSourceMaterialAcid=Acid
|
||||||
|
EditorSourceMaterialLava=Lava
|
||||||
|
EditorSourceMaterialDuroLava=DuroLava
|
||||||
|
EditorSourceMaterialOil=Oil
|
||||||
|
EditorSourcePosition=Source position
|
||||||
|
EditorSourcePositionHelp=Set the position of the source.
|
||||||
|
EditorSourceDirection=Source direction
|
||||||
|
EditorSourceDirectionHelp=Set the direction of liquid insertion, relative to the source position.
|
||||||
|
|
||||||
|
EditorDrainStrength=Drain strength
|
||||||
|
EditorDrainStrengthHelp=Amount of pixels the drain removes per 2 frames.
|
||||||
|
EditorDrainPosition=Drain position
|
||||||
|
EditorDrainPositionHelp=Set the position of the drain.
|
|
@ -92,9 +92,9 @@ private func InitCaveEntrance()
|
||||||
trunk.MeshTransformation = [-70, 0, 998, 0, 0, 1000, 0, 0, -998, 0, -70, 0];
|
trunk.MeshTransformation = [-70, 0, 998, 0, 0, 1000, 0, 0, -998, 0, -70, 0];
|
||||||
var waterfall;
|
var waterfall;
|
||||||
waterfall = CreateWaterfall(325, 448, 2, "Water");
|
waterfall = CreateWaterfall(325, 448, 2, "Water");
|
||||||
waterfall->SetDirection(2, 0, 3, 6);
|
waterfall->SetDirection(3, 3, 1, 3);
|
||||||
waterfall = CreateWaterfall(338, 450, 8, "Water");
|
waterfall = CreateWaterfall(338, 450, 8, "Water");
|
||||||
waterfall->SetDirection(1, 0, 4, 8);
|
waterfall->SetDirection(3, 4, 2, 4);
|
||||||
CreateLiquidDrain(160, 648, 10);
|
CreateLiquidDrain(160, 648, 10);
|
||||||
CreateLiquidDrain(184, 648, 10);
|
CreateLiquidDrain(184, 648, 10);
|
||||||
CreateLiquidDrain(208, 648, 10);
|
CreateLiquidDrain(208, 648, 10);
|
||||||
|
|
|
@ -144,7 +144,7 @@ private func InitEnvironment(int map_size, int difficulty)
|
||||||
for (var i = 0; i < 16 + 4 * difficulty; i++)
|
for (var i = 0; i < 16 + 4 * difficulty; i++)
|
||||||
{
|
{
|
||||||
var fall = CreateWaterfall(waterfall_x + 2, 0, RandomX(3, 4), "Water");
|
var fall = CreateWaterfall(waterfall_x + 2, 0, RandomX(3, 4), "Water");
|
||||||
fall->SetDirection(RandomX(10, 12), 8, 8, 8);
|
fall->SetDirection(RandomX(14, 16), 12, 4, 4);
|
||||||
fall->SetSoundLocation(LandscapeWidth() / 2, Random(LandscapeHeight()));
|
fall->SetSoundLocation(LandscapeWidth() / 2, Random(LandscapeHeight()));
|
||||||
}
|
}
|
||||||
var trunk = CreateObjectAbove(Trunk, waterfall_x + 2, 20);
|
var trunk = CreateObjectAbove(Trunk, waterfall_x + 2, 20);
|
||||||
|
|
|
@ -156,7 +156,7 @@ private func InitEnvironment(int difficulty)
|
||||||
trunk->MakeInvincible();
|
trunk->MakeInvincible();
|
||||||
|
|
||||||
var waterfall = CreateWaterfall(waterfall_x + 22, waterfall_y - 10, 10, "Water");
|
var waterfall = CreateWaterfall(waterfall_x + 22, waterfall_y - 10, 10, "Water");
|
||||||
waterfall->SetDirection(2, 0, 3, 6);
|
waterfall->SetDirection(3, 3, 2, 3);
|
||||||
waterfall->SetSoundLocation(waterfall_x + 40, waterfall_y + 240);
|
waterfall->SetSoundLocation(waterfall_x + 40, waterfall_y + 240);
|
||||||
|
|
||||||
CreateLiquidDrain(8, 1040, 10);
|
CreateLiquidDrain(8, 1040, 10);
|
||||||
|
|
Loading…
Reference in New Issue