forked from Mirrors/openclonk
added very simple framework for the creation of purely visual environment objects + not-implemented-zicadas
parent
e843fbab50
commit
15e29fcfd8
|
@ -22,7 +22,9 @@ protected func Initialize()
|
|||
for (var i = 0; i < 2; i++)
|
||||
PlaceVegetation(SproutBerryBush, bush->GetX() - 200, bush->GetY() - 200, 400, 400, 100000);
|
||||
PlaceGrass(100);
|
||||
|
||||
|
||||
CreateEnvironmentObjects("Temperate");
|
||||
|
||||
// Set time of day to evening and create some clouds and celestials.
|
||||
Cloud->Place(10);
|
||||
Cloud->SetPrecipitation("Water", 15);
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
[DefCore]
|
||||
id=Environment
|
||||
Version=4,10,0,0
|
||||
Category=C4D_StaticBack
|
||||
Width=1
|
||||
Height=1
|
||||
Offset=-1,-1
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 91 B |
|
@ -0,0 +1,108 @@
|
|||
/**
|
||||
VisualEnvironment
|
||||
Cares about the placement of purely visual objects.
|
||||
The placement uses categories and thus is forward-compatible.
|
||||
*/
|
||||
|
||||
// this proplist defines the selectable environment objects
|
||||
// "ID" might be nil or a valid id
|
||||
// "includes" specifies what objects are created when the selected object is created (no specific order)
|
||||
// any entry of "Environment_Attributes" might be nil or false instead of a proplist
|
||||
// nil will log a warning on creating that object and false will silently ignore it
|
||||
// thus something like Environment_Attributes["Foobar"] = false; will work to disable certain features
|
||||
static const Environment_Attributes =
|
||||
{
|
||||
All = {
|
||||
ID = nil,
|
||||
includes = ["Temperate", "Desert"],
|
||||
},
|
||||
|
||||
Temperate = {
|
||||
ID = nil,
|
||||
includes = ["Zicadas", "Frogs", "BackgroundBirds"],
|
||||
},
|
||||
|
||||
Desert = {
|
||||
ID = nil,
|
||||
includes = ["Zicadas"],
|
||||
},
|
||||
|
||||
Zicadas = {
|
||||
ID = Environment_Zicadas,
|
||||
},
|
||||
|
||||
Frogs = {
|
||||
ID = nil /* not yet implemented: Environment_Frogs */,
|
||||
},
|
||||
|
||||
BackgroundBirds = {
|
||||
ID = nil /* not yet implemented: Environment_BackgroundBirds */,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
|
||||
// provides a simple interface for creation of environment objects and decoration with standard values
|
||||
// the objects are placed on a best-effort-basis. That means f.e. objects that rely on water will not be placed when there is no water in the landscape.
|
||||
global func CreateEnvironmentObjects(
|
||||
what /* array of strings or single string: what objects will be created, standard: "All" */
|
||||
, proplist area /* area where objects will be created, format {x = ??, y = ??, w = ??, h = ??}, standard: whole landscape */
|
||||
, int amount_percentage /* what percentage of the standard amount will be created, standard: 100 */
|
||||
)
|
||||
{
|
||||
/*
|
||||
// half desert, half temperate - but birds everywhere
|
||||
CreateEnvironmentObjects(["Desert", "BackgroundBirds"], Rectangle(0, 0, LandscapeWidth()/2, LandscapeHeight()));
|
||||
CreateEnvironmentObjects("Temperate", Rectangle(LandscapeWidth()/2, 0, LandscapeWidth()/2, LandscapeHeight()));
|
||||
*/
|
||||
what = what ?? "All";
|
||||
area = area ?? Rectangle(0, 0, LandscapeWidth(), LandscapeHeight());
|
||||
amount_percentage = amount_percentage ?? 100;
|
||||
|
||||
// might be a string to allow CreateEnvironmentObjects("All")
|
||||
if(GetType(what) != C4V_Array)
|
||||
what = [what];
|
||||
|
||||
// iteratively find all the objects that are included in the selection
|
||||
while(true)
|
||||
{
|
||||
var changed = false;
|
||||
var to_add = [];
|
||||
|
||||
// go through every object in the list
|
||||
for(var obj in what)
|
||||
{
|
||||
var p = Environment_Attributes[obj];
|
||||
if(p == nil) {Log("Warning: Environment object %s does not exist!", obj);}
|
||||
else if(p == false) continue; // disabled by the scenario designer
|
||||
|
||||
// add all objects included to the temporary list if existing
|
||||
if(!p["includes"]) continue;
|
||||
to_add = Concatenate(to_add, p["includes"]);
|
||||
}
|
||||
|
||||
// add every unique item from the temporary list to the object list
|
||||
for(var obj in to_add)
|
||||
{
|
||||
if(IsValueInArray(what, obj)) continue;
|
||||
|
||||
if(!!Environment_Attributes[obj]["includes"])
|
||||
changed = true; // found changes, need further checking
|
||||
|
||||
PushBack(what, obj);
|
||||
}
|
||||
|
||||
if(!changed)
|
||||
break;
|
||||
}
|
||||
|
||||
// now create all the selected objects
|
||||
for(var obj in what)
|
||||
{
|
||||
var p, p_id;
|
||||
if(!(p = Environment_Attributes[obj])) continue;
|
||||
if(!(p_id = p["ID"])) continue;
|
||||
|
||||
p_id->Place(amount_percentage, area);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
[DefCore]
|
||||
id=Environment_Zicadas
|
||||
Version=4,10,0,0
|
||||
Category=C4D_StaticBack
|
||||
Width=1
|
||||
Height=1
|
||||
Offset=-1,-1
|
Binary file not shown.
After Width: | Height: | Size: 91 B |
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
Zicadas
|
||||
Zicada sounds.
|
||||
*/
|
||||
|
||||
local Name = "$Name$";
|
||||
local Description = "$Description$";
|
||||
|
||||
func Place(int amount_percentage, proplist area)
|
||||
{
|
||||
area = area ?? Rectangle(0, 0, LandscapeWidth(), LandscapeHeight());
|
||||
amount_percentage = amount_percentage ?? 100;
|
||||
|
||||
// calculate amount that has to be placed
|
||||
var amount = LandscapeWidth() / 100;
|
||||
amount = (amount_percentage * amount) / 100;
|
||||
if(!amount) return;
|
||||
|
||||
while(--amount)
|
||||
{
|
||||
// search for zicada spot position
|
||||
// ..
|
||||
// place zicada spot
|
||||
// ..
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
Name=Zikaden
|
||||
Description=Zikadengeräusche.
|
|
@ -0,0 +1,2 @@
|
|||
Name=Zicadas
|
||||
Description=Zicada sounds.
|
|
@ -0,0 +1,27 @@
|
|||
/*--
|
||||
Proplists.c
|
||||
|
||||
General helper functions that create or work with proplists.
|
||||
--*/
|
||||
|
||||
// creates a proplists with the properties x, y, w, h that represents a rectangle
|
||||
// satisfies that the resulting rectangle's x|y point is in the top-left corner and the width and height are positive
|
||||
global func Rectangle(int x2, int y2, int w2, int h2)
|
||||
{
|
||||
/*
|
||||
// creates a rectangle representing the landscape
|
||||
var rect = Rectangle(0, 0, LandscapeWidth(), LandscapeHeight());
|
||||
*/
|
||||
// normalize
|
||||
if(w2 < 0)
|
||||
{
|
||||
x2 += w2;
|
||||
w2 = -w2;
|
||||
}
|
||||
if(h2 < 0)
|
||||
{
|
||||
y2 += h2;
|
||||
h2 = - h2;
|
||||
}
|
||||
return {x = x2, y = y2, w = w2, h = h2};
|
||||
}
|
Loading…
Reference in New Issue