/*
 * this class represents a zone , a division of the map.
 * it has no correspondence in the DOM.
 * it has 2 members x,y that identify a cell in the map.
 * so when an element moves into that "cell" it is adopted by this zone object.
 * 
 */
var StandardZone = new Class({
    initialize: function(){
        this.x=0;
        this.y=0;
        this.freeZone=true;
        this.type=['-']; // it could be wall, fakewall, hero, bomb, etc ... or it could be [] {'hero','bomb'}
        this.elements=[];
        this.walkable=true;
    },
    addElement: function(el){
        this.elements.push(el);
        this.addType(el.type);
        this.freeZone=false;
    },
    removeElement: function(el){
        util.removeElementFromArray(el,this.elements);
        this.removeType(el.type);
        if(this.elements.length==0)
            this.freeZone=true;
    },
    hasElement: function(el){
        var exists=false;
        for(var i=0;i<this.elements.length;i++){
            if(this.elements[i]==el){
                exists=true;
                break;
            }
        }
        return exists;
    },
    getElements: function(){
        return this.elements;
    },
    hasType: function(_type){
        var typeExists=false;
        for(var i=0;i<this.type.length;i++){
            if(this.type[i]==_type){
                typeExists=true;
                break;
            }
        }
        return typeExists;
    },
    addType: function(_type){
        if(_type==GAMEUNITTYPE.WALL || _type==GAMEUNITTYPE.FAKEWALL || _type==GAMEUNITTYPE.BOMB)
            this.walkable=false;
        if(this.type.length==1 && this.type[0]=='-')
            this.setType(_type);
        else
            this.type[this.type.length]=_type;
    },
    setType: function(_type){
        this.type=[];
        this.type[0]=_type;
    },
    removeType: function(_type){
        util.removeElementFromArray(_type,this.type);
        if(this.type.length==0)
            this.type[0]='-';
        if(this.hasType(GAMEUNITTYPE.WALL) || this.hasType(GAMEUNITTYPE.FAKEWALL) || this.hasType(GAMEUNITTYPE.BOMB))
            this.walkable=false;
        else
            this.walkable=true;
    },
    types: function(){
        var types='';
        for(var i=0;i<this.type.length;i++){
            types=types+', '+this.type[i];
        }
        return types;
    },
    isWalkable: function(){
    	return this.walkable;
    }
    /*
    colorZone: function(){
        var el = new Element('div',{'class': 'colored'});
        el.setStyle('left',this.x+'px');
        el.setStyle('top',this.y+'px');
        el.setStyle('background-color','#ff0000');
        el.injectInside(game.world.HTMLIncarnation);
    }*/
});

