Ticket #1165: entity.js.patch

File entity.js.patch, 2.8 KB (added by gudo, 12 years ago)
  • entity.js

     
    177177       
    178178        return this._template.GarrisonHolder.Max;
    179179    },
     180   
     181    //"Population Bonus" is how much a building raises your population cap.
     182    getPopulationBonus: function()
     183    {
     184        if(!this._template.Cost)
     185            return undefined;
     186        return this._template.Cost.PopulationBonus;
     187    },
    180188
    181189    /**
    182190     * Returns whether this is an animal that is too difficult to hunt.
     
    286294    },
    287295
    288296    hitpoints: function() { return this._entity.hitpoints; },
    289     isHurt: function() { return this.hitpoints < this.maxHitpoints; },
    290     needsHeal: function() { return this.isHurt && this.isHealable; },
    291     needsRepair: function() { return this.isHurt && this.isRepairable; },
     297    isHurt: function() { return this.hitpoints() < this.maxHitpoints(); },
     298    needsHeal: function() { return this.isHurt() && this.isHealable(); },
     299    needsRepair: function() { return this.isHurt() && this.isRepairable(); },
    292300
    293301    /**
    294302     * Returns the current training queue state, of the form
     
    340348    {
    341349        return (this.garrisonMax() - this.garrisoned().length);
    342350    },
     351   
     352    canGarrisonInto: function(target)
     353    {
     354        var allowedClasses = target.garrisonableClasses();
     355        // return false if the target is full or doesn't have any allowed classes
     356        if( target.garrisonSpaceAvaliable() <=0 || allowedClasses == undefined )
     357        return false;
    343358
     359        var hasClasses = this.classes();
     360        for( var i=0; i<hasClasses.length; i++)
     361            {
     362                var hasClass = hasClasses[i];
     363                if( allowedClasses.indexOf(hasClass) >= 0 )
     364                return true;
     365            }//end for units classes
     366        return false;
     367    },
     368
    344369    // TODO: visibility
    345 
     370    attack: function(target)
     371    {
     372        Engine.PostCommand({"type": "attack", "entities": [this.id()], "target": target.id(), "queued": false});
     373        return this;
     374    },
     375   
    346376    move: function(x, z, queued) {
    347377        queued = queued || false;
    348378        Engine.PostCommand({"type": "walk", "entities": [this.id()], "x": x, "z": z, "queued": queued});
     
    389419        });
    390420        return this;
    391421    },
     422   
     423    //ungarrison a specific unit in this building
     424    unload: function(unit)
     425    {
     426        if (!this._template.GarrisonHolder)
     427            return undefined;
     428            Engine.PostCommand({"type": "unload", "garrisonHolder": this.id(), "entity": unit});
     429        var utug = this._entity.garrisoned.indexOf(unit);
     430        this._entity.splice(utug, 1);       // remove the ungarrisoned unit
     431            return this;
     432    },
    392433
     434    unloadAll: function()
     435    {
     436            if (!this._template.GarrisonHolder)
     437            return undefined;
     438        Engine.PostCommand({"type": "unload-all", "garrisonHolder": this.id()});
     439        this._entity.garrisoned = [];   // empty the garrisoned list
     440        return this;
     441    },
     442   
    393443    construct: function(template, x, z, angle) {
    394444        // TODO: verify this unit can construct this, just for internal
    395445        // sanity-checking and error reporting