package Hexel.blocks.rules;
import java.util.ArrayList;
import Hexel.Engine;
import Hexel.Hexel;
import Hexel.blocks.BlockRule;
import Hexel.blocks.SpawnBlockRule;
import Hexel.blocks.types.Block;
import Hexel.blocks.types.BlockEmpty;
import Hexel.blocks.types.BlockTransparent;
import Hexel.chunk.Chunk;
import Hexel.chunk.Chunks;
import Hexel.chunk.HighestBlockChunk;
import Hexel.math.Vector3i;
import Hexel.things.types.Deer;
import Hexel.things.types.Wanderer;
import Hexel.things.types.Zombie;
import Hexel.util.Util;
public class SpawnRules {
public static void addRules(final Engine engine, ArrayList<BlockRule> woodRules, ArrayList<BlockRule> dirtRules){
woodRules.add(new SpawnBlockRule(engine, 100){
@Override
public boolean blockMatches(int x, int y, int z, Block b, Chunk c, HighestBlockChunk hbc, Chunks chunks, int steps) {
return true;
}
@Override
public void spawn(double x, double y, double z, int bx, int by, int bz, int step, Chunk c, Chunks chunks) {
if (engine.thingSimulator.getNumberOfThingsOfType(Wanderer.class) < 10 && Math.random() < .001){
Wanderer wanderer = new Wanderer(x, y, z, engine.getThingBridge());
engine.addThing(wanderer);
}
}
});
dirtRules.add(new SpawnBlockRule(engine, 100){
private Vector3i tmp = new Vector3i();
@Override
public boolean blockMatches(int x, int y, int z, Block b, Chunk c, HighestBlockChunk hbc, Chunks chunks, int steps) {
Block ab = chunks.getBlock(x, y, z+1, tmp, c);
return ab instanceof BlockEmpty;
}
@Override
public void spawn(double x, double y, double z, int bx, int by, int bz, int step, Chunk c, Chunks chunks) {
if (engine.thingSimulator.getNumberOfThingsOfType(Deer.class) < 10){
Deer deer = new Deer(x, y, z, engine.getThingBridge());
engine.addThing(deer);
}
}
});
dirtRules.add(new SpawnBlockRule(engine, 100){
private Vector3i tmp = new Vector3i();
@Override
public boolean blockMatches(int x, int y, int z, Block b, Chunk c, HighestBlockChunk hbc, Chunks chunks, int steps) {
Block ab = chunks.getBlock(x, y, z+1, tmp, c);
return ab instanceof BlockEmpty;
}
@Override
public void spawn(double x, double y, double z, int bx, int by, int bz, int step, Chunk c, Chunks chunks) {
Block ab = chunks.getBlock(bx, by, bz+1, tmp, c);
BlockTransparent abt = (BlockTransparent)ab;
int numberToSpawn = engine.zsp.getNumberToSpawn();
if (numberToSpawn <= 0)
return;
double lightLevel = engine.getAmbientLight() - abt.naturalLightLevel*1.0/BlockTransparent.MAX_LIGHT_LEVEL;
if (lightLevel < .5 && Util.hashToDouble(Util.hash(Hexel.session.seed, step, bx, by, bz)) < .25){
Zombie zombie = new Zombie(x, y, z, engine.getThingBridge());
engine.addThing(zombie);
engine.zsp.spawnZombies(1);
}
}
});
}
}