summaryrefslogtreecommitdiffstats
path: root/TemplePushing.c4s/Misc.c4d/SpawnPointSpawner.c4d/Script.c
blob: 380ee860379a8ceaaf5ca261e9bbd6a262fd4650 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*-- Spawn Point Spawner --*/

#strict 2

local locations, definitions, spawnInterval;
local sumProbability;
local gamma;

public func CreateSpawnPoints()
{
	for (var pos in locations)
	{
		var spawnpoint = CreateObject(SNPT, pos[0], pos[1], NO_OWNER);
		if (gamma) spawnpoint->SetGamma(gamma[0], gamma[1], gamma[2]);
		spawnpoint->Enable(this);
	}
}

// [[x1, y1], [x2, y2], ...]
public func SetLocations(array locations)
{
	LocalN("locations") = locations;
}

// [[FLNT, 50], [SFLN, 20], ...]
public func SetDefinitions(array definitions)
{
	LocalN("definitions") = definitions;

	sumProbability = 0;
	for (var def in definitions)
	{
		sumProbability += def[1];
	}
}

public func SetSpawnpointGamma(int color1, int color2, int color3)
{
	gamma = [color1, color2, color3];
}

public func GetSpawnInterval() { return spawnInterval; }

public func SetSpawnInterval(int spawnInterval)
{
	LocalN("spawnInterval") = spawnInterval;
}

public func GetRandomDefinition()
{
	var rnd = Random(sumProbability);
	for (var def in definitions)
	{
		rnd -= def[1];
		if (rnd < 0) return def[0];
	}
}