function Spawner( x , z , player )
{
    this.building = new Building( x , z , player , SPAWNER );
    this.lasttime = Date.now();

    this.entityDamageUpgrade = 0;
    this.entityHPUpgrade = 0;
}



Spawner.prototype.update = function()
{
    this.building.update();
    if ( this.building.isDead() ) return;

    if ( Date.now() > this.lasttime+5000 )
    {
        var enemyPlayer = aiPlayer;
        if ( this.building.player == aiPlayer ) enemyPlayer = player;

        var entity = new Entity( this.building.worldPosition.x , this.building.worldPosition.y , this.building.player , enemyPlayer );
        entity.modelFilename = "models/miner.glb";
        entity.coreHitReward = 3;
        // miners are very strong against the core, but weak to other stuff
        entity.damage = 2+this.entityDamageUpgrade;
        entity.coreDamage = 2+this.entityDamageUpgrade;
        entity.buildingDamage = 2+this.entityDamageUpgrade;
        
        entity.setHP( 10+this.entityHPUpgrade );

        entity.spawn();
        entities.push( entity );
        this.lasttime = Date.now();
    }
}



Spawner.prototype.build = function( scene )
{
    var pthis = this;
    this.model = null;
    loadModel( "models/spawner.glb" , "spawner" , scene , function( model )
    {
        pthis.model = model;
        pthis.model.position.x = pthis.building.worldPosition.x;
        pthis.model.position.z = pthis.building.worldPosition.y;
        pthis.building.healthBar = new HealthBar( scene , pthis.model , 0.4 , 0.03 , -0.7 );
        for ( var i = 0 ; i < pthis.model._children.length ; ++i )
        {
            pthis.model._children[i].name = pthis.building.ID;
        }
    } );
}



Spawner.prototype.remove = function()
{
    this.building.b_modelRemoved = true;
    this.model.dispose();
}