Move PlaceBatches into System.ocg

master
Nicolas Hake 2018-07-23 10:15:14 +02:00
parent 05ca450111
commit 30aa6abb55
6 changed files with 41 additions and 108 deletions

View File

@ -16,8 +16,8 @@ func Initialize()
LargeCaveMushroom->Place(15, Shape->Rectangle(100, 0, 600, 300));
// Create earth materials
// Create them in big clusters so the whole object arrangement looks a bit less uniform and more interesting
PlaceBatches([Firestone], 5, 100, 10);
PlaceBatches([Rock, Loam, Loam], 10, 200, 10);
PlaceObjectBatches([Firestone], 5, 100, 10);
PlaceObjectBatches([Rock, Loam, Loam], 10, 200, 10);
// Misc vegetation
SproutBerryBush->Place(5, Shape->Rectangle(100, 0, 600, 300));
Mushroom->Place(5, Shape->Rectangle(100,0,600,300));
@ -71,34 +71,6 @@ private func InitBase(int owner)
return true;
}
private func PlaceBatches(array item_ids, int n_per_batch, int batch_radius, int n_batches)
{
// place a number (n_batches) of batches of objects of types item_ids. Each batch has n_per_batch objects.
// fewer batches and/or objects may be placed if no space is found
var n_item_ids=GetLength(item_ids), n_created=0;
for (var i=0; i<n_batches; ++i)
{
var loc = FindLocation(Loc_Material("Earth"));
if (loc)
{
for (var j=0; j<n_per_batch; ++j)
{
var loc2 = FindLocation(Loc_InRect(loc.x-batch_radius,loc.y-batch_radius,batch_radius*2,batch_radius*2), Loc_Material("Earth"));
if (loc2)
{
var obj = CreateObjectAbove(item_ids[Random(n_item_ids)], loc2.x, loc2.y);
if (obj)
{
obj->SetPosition(loc2.x,loc2.y);
++n_created;
}
}
}
}
}
return n_created;
}
func OnGoalsFulfilled()
{
GainScenarioAchievement("Done");

View File

@ -47,9 +47,9 @@ protected func Initialize()
goal->SetFinishpoint(LandscapeWidth()/2, LandscapeHeight()*5/100);
// Create earth materials
// Create them in big clusters so the whole object arrangement looks a bit less uniform and more interesting
PlaceBatches([Firestone], 5, 100, 15);
PlaceBatches([Dynamite, Dynamite, Dynamite, DynamiteBox], 3, 50, 6);
PlaceBatches([Rock, Loam, Loam], 10, 200, 10);
PlaceObjectBatches([Firestone], 5, 100, 15);
PlaceObjectBatches([Dynamite, Dynamite, Dynamite, DynamiteBox], 3, 50, 6);
PlaceObjectBatches([Rock, Loam, Loam], 10, 200, 10);
// Some dead trees.
Tree_Coniferous_Burned->Place(4);
Tree_Coniferous2_Burned->Place(2);
@ -78,23 +78,6 @@ func InitializePlayer(int plr)
return true;
}
private func PlaceBatches(array item_ids, int n_per_batch, int batch_radius, int n_batches)
{
// place a number (n_batches) of batches of objects of types item_ids. Each batch has n_per_batch objects.
// fewer batches and/or objects may be placed if no space is found
var loc,loc2,n_item_ids=GetLength(item_ids), n_created=0, obj;
for (var i=0; i<n_batches; ++i)
if (loc = FindLocation(Loc_Material("Earth")))
for (var j=0; j<n_per_batch; ++j)
if (loc2 = FindLocation(Loc_InRect(loc.x-batch_radius,loc.y-batch_radius,batch_radius*2,batch_radius*2), Loc_Material("Earth")))
if (obj=CreateObjectAbove(item_ids[Random(n_item_ids)],loc2.x,loc2.y))
{
obj->SetPosition(loc2.x,loc2.y);
++n_created;
}
return n_created;
}
// Gamecall from parkour goal, on respawning.
protected func OnPlayerRespawn(int plr, object cp)
{

View File

@ -19,9 +19,9 @@ protected func Initialize()
goal->SetFinishpoint(w/2, h*5/100);
// Create earth materials
// Create them in big clusters so the whole object arrangement looks a bit less uniform and more interesting
PlaceBatches([Firestone], 5, 100, 15);
PlaceBatches([Dynamite, Dynamite, Dynamite, DynamiteBox], 3, 50, 6);
PlaceBatches([Rock, Loam, Loam], 10, 200, 10);
PlaceObjectBatches([Firestone], 5, 100, 15);
PlaceObjectBatches([Dynamite, Dynamite, Dynamite, DynamiteBox], 3, 50, 6);
PlaceObjectBatches([Rock, Loam, Loam], 10, 200, 10);
// Some dead trees.
Tree_Coniferous_Burned->Place(4);
Tree_Coniferous2_Burned->Place(2);
@ -96,23 +96,6 @@ func InitializePlayer(int plr)
return true;
}
private func PlaceBatches(array item_ids, int n_per_batch, int batch_radius, int n_batches)
{
// place a number (n_batches) of batches of objects of types item_ids. Each batch has n_per_batch objects.
// fewer batches and/or objects may be placed if no space is found
var loc,loc2,n_item_ids=GetLength(item_ids), n_created=0, obj;
for (var i=0; i<n_batches; ++i)
if (loc = FindLocation(Loc_Material("Earth")))
for (var j=0; j<n_per_batch; ++j)
if (loc2 = FindLocation(Loc_InRect(loc.x-batch_radius,loc.y-batch_radius,batch_radius*2,batch_radius*2), Loc_Material("Earth")))
if (obj=CreateObjectAbove(item_ids[Random(n_item_ids)],loc2.x,loc2.y))
{
obj->SetPosition(loc2.x,loc2.y);
++n_created;
}
return n_created;
}
// Gamecall from parkour goal, on respawning.
protected func OnPlayerRespawn(int plr, object cp)
{

View File

@ -87,6 +87,35 @@ global func PlaceObjects(id id, int amount, string mat_str, int x, int y, int wd
return j;
}
global func PlaceObjectBatches(array item_ids, int n_per_batch, int batch_radius, int n_batches, string in_material)
{
// place a number (n_batches) of batches of objects of types item_ids. Each batch has n_per_batch objects.
// fewer batches and/or objects may be placed if no space is found
in_material = in_material ?? "Earth";
var n_item_ids=GetLength(item_ids), n_created=0;
for (var i=0; i<n_batches; ++i)
{
var loc = FindLocation(Loc_Material(in_material));
if (loc)
{
for (var j=0; j<n_per_batch; ++j)
{
var loc2 = FindLocation(Loc_InRect(loc.x-batch_radius,loc.y-batch_radius,batch_radius*2,batch_radius*2), Loc_Material(in_material));
if (loc2)
{
var obj = CreateObjectAbove(item_ids[Random(n_item_ids)], loc2.x, loc2.y);
if (obj)
{
obj->SetPosition(loc2.x,loc2.y);
++n_created;
}
}
}
}
}
return n_created;
}
// documented in /docs/sdk/script/fn
global func CastObjects(id def, int am, int lev, int x, int y, int angs, int angw)
{

View File

@ -97,8 +97,8 @@ private func InitVegetation(int map_size)
LargeCaveMushroom->Place(15, Shape->Rectangle(LandscapeWidth() / 4, 172 * 6, LandscapeWidth() / 2, 60 * 6));
// Create earth materials
// Create them in big clusters so the whole object arrangement looks a bit less uniform and more interesting.
PlaceBatches([Firestone], 3, 100, 5);
PlaceBatches([Rock, Loam, Loam], 10, 200, 10);
PlaceObjectBatches([Firestone], 3, 100, 5);
PlaceObjectBatches([Rock, Loam, Loam], 10, 200, 10);
// Misc vegetation
SproutBerryBush->Place(5, Shape->Rectangle(0, LandscapeHeight() / 4, LandscapeWidth(), LandscapeHeight() * 3 / 4));
Mushroom->Place(5, Shape->Rectangle(0, LandscapeHeight() / 4, LandscapeWidth(), LandscapeHeight() * 3 / 4));
@ -158,20 +158,3 @@ global func FxKeepAreaClearTimer(object q, proplist fx, int time)
obj->RemoveObject();
return FX_OK;
}
private func PlaceBatches(array item_ids, int n_per_batch, int batch_radius, int n_batches)
{
// place a number (n_batches) of batches of objects of types item_ids. Each batch has n_per_batch objects.
// fewer batches and/or objects may be placed if no space is found
var loc,loc2,n_item_ids=GetLength(item_ids), n_created=0, obj;
for (var i=0; i<n_batches; ++i)
if (loc = FindLocation(Loc_Material("Earth")))
for (var j=0; j<n_per_batch; ++j)
if (loc2 = FindLocation(Loc_InRect(loc.x-batch_radius,loc.y-batch_radius,batch_radius*2,batch_radius*2), Loc_Material("Earth")))
if (obj=CreateObjectAbove(item_ids[Random(n_item_ids)],loc2.x,loc2.y))
{
obj->SetPosition(loc2.x,loc2.y);
++n_created;
}
return n_created;
}

View File

@ -185,8 +185,8 @@ private func InitVegetation(int map_size)
Mushroom->Place(14, Shape->Rectangle(0, 0, wdt, 3 * hgt / 8));
// Create earth materials in big clusters so the whole object arrangement looks a bit less uniform and more interesting.
PlaceBatches([Firestone], 3, 100, 5);
PlaceBatches([Rock, Loam, Loam], 10, 200, 10);
PlaceObjectBatches([Firestone], 3, 100, 5);
PlaceObjectBatches([Rock, Loam, Loam], 10, 200, 10);
// Place some underwater vegetation in the flooded caves.
var place_rect = Shape->Rectangle(50, hgt / 2, wdt - 100, hgt / 2);
@ -211,23 +211,6 @@ private func InitAnimals(int map_size, int difficulty)
/*-- Some helper functions --*/
private func PlaceBatches(array item_ids, int n_per_batch, int batch_radius, int n_batches)
{
// place a number (n_batches) of batches of objects of types item_ids. Each batch has n_per_batch objects.
// fewer batches and/or objects may be placed if no space is found
var loc, loc2, n_item_ids = GetLength(item_ids), n_created = 0, obj;
for (var i = 0; i < n_batches; ++i)
if (loc = FindLocation(Loc_Material("Earth")))
for (var j = 0; j < n_per_batch; ++j)
if (loc2 = FindLocation(Loc_InRect(loc.x - batch_radius,loc.y - batch_radius, batch_radius * 2, batch_radius * 2), Loc_Material("Earth")))
if (obj = CreateObjectAbove(item_ids[Random(n_item_ids)], loc2.x, loc2.y))
{
obj->SetPosition(loc2.x, loc2.y);
++n_created;
}
return n_created;
}
global func TestGemCount()
{
var pos;