var buildingIDCounter = 0;
function Building( x , z , player , type )
{
    this.ID = buildingIDCounter++;
    this.x = x;
    this.z = z;
    this.player = player;
    this.type = type;

    this.worldPosition = new BABYLON.Vector2( xToWorldCoords( this.x ) , zToWorldCoords( this.z ) );

    this.maxHP = 30;
    this.HP = this.maxHP;
    this.b_alive = true;
    this.deathCounter = 0;
    this.b_modelRemoved = false;

    this.healthBar = null;
}



Building.prototype.update = function()
{
    if ( !this.b_alive )
    {
        ++this.deathCounter;
    }
}



Building.prototype.takeDamage = function( damage )
{
    this.HP -= damage;

    if ( this.healthBar != null )
    {
        this.healthBar.update( this.HP , this.maxHP );
    }

    if ( this.HP <= 0 )
    {
        this.HP = 0;
        this.b_alive = false;
        return true;
    }
    return false;
}



Building.prototype.setHP = function( hp )
{
    this.maxHP = hp;
    this.HP = this.maxHP;
}



Building.prototype.isDead = function()
{
    return !this.b_alive;
}



Building.prototype.isModelRemoved = function()
{
    return this.b_modelRemoved;
}