Added and fixed some functions in entity.js from RootBot. Fixes #1165.
This was SVN commit r11121.
This commit is contained in:
parent
b87803b8b9
commit
23f122988a
@ -178,6 +178,15 @@ var EntityTemplate = Class({
|
|||||||
return this._template.GarrisonHolder.Max;
|
return this._template.GarrisonHolder.Max;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
//"Population Bonus" is how much a building raises your population cap.
|
||||||
|
getPopulationBonus: function()
|
||||||
|
{
|
||||||
|
if(!this._template.Cost)
|
||||||
|
return undefined;
|
||||||
|
|
||||||
|
return this._template.Cost.PopulationBonus;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether this is an animal that is too difficult to hunt.
|
* Returns whether this is an animal that is too difficult to hunt.
|
||||||
* (Currently this just includes skittish animals, which are probably
|
* (Currently this just includes skittish animals, which are probably
|
||||||
@ -286,9 +295,9 @@ var Entity = Class({
|
|||||||
},
|
},
|
||||||
|
|
||||||
hitpoints: function() { return this._entity.hitpoints; },
|
hitpoints: function() { return this._entity.hitpoints; },
|
||||||
isHurt: function() { return this.hitpoints < this.maxHitpoints; },
|
isHurt: function() { return this.hitpoints() < this.maxHitpoints(); },
|
||||||
needsHeal: function() { return this.isHurt && this.isHealable; },
|
needsHeal: function() { return this.isHurt() && this.isHealable(); },
|
||||||
needsRepair: function() { return this.isHurt && this.isRepairable; },
|
needsRepair: function() { return this.isHurt() && this.isRepairable(); },
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current training queue state, of the form
|
* Returns the current training queue state, of the form
|
||||||
@ -341,8 +350,33 @@ var Entity = Class({
|
|||||||
return (this.garrisonMax() - this.garrisoned().length);
|
return (this.garrisonMax() - this.garrisoned().length);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
canGarrisonInto: function(target)
|
||||||
|
{
|
||||||
|
var allowedClasses = target.garrisonableClasses();
|
||||||
|
// return false if the target is full or doesn't have any allowed classes
|
||||||
|
if( target.garrisonSpaceAvaliable() <=0 || allowedClasses == undefined )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Check that this unit is a member of at least one of the allowed garrison classes
|
||||||
|
var hasClasses = this.classes();
|
||||||
|
for( var i = 0; i < hasClasses.length; i++)
|
||||||
|
{
|
||||||
|
var hasClass = hasClasses[i];
|
||||||
|
if( allowedClasses.indexOf(hasClass) >= 0 )
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
// TODO: visibility
|
// TODO: visibility
|
||||||
|
|
||||||
|
attack: function(target)
|
||||||
|
{
|
||||||
|
Engine.PostCommand({"type": "attack", "entities": [this.id()], "target": target.id(), "queued": false});
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
|
||||||
move: function(x, z, queued) {
|
move: function(x, z, queued) {
|
||||||
queued = queued || false;
|
queued = queued || false;
|
||||||
Engine.PostCommand({"type": "walk", "entities": [this.id()], "x": x, "z": z, "queued": queued});
|
Engine.PostCommand({"type": "walk", "entities": [this.id()], "x": x, "z": z, "queued": queued});
|
||||||
@ -390,6 +424,23 @@ var Entity = Class({
|
|||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
//ungarrison a specific unit in this building
|
||||||
|
unload: function(unit)
|
||||||
|
{
|
||||||
|
if (!this._template.GarrisonHolder)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Engine.PostCommand({"type": "unload", "garrisonHolder": this.id(), "entity": unit.id()});
|
||||||
|
},
|
||||||
|
|
||||||
|
unloadAll: function()
|
||||||
|
{
|
||||||
|
if (!this._template.GarrisonHolder)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Engine.PostCommand({"type": "unload-all", "garrisonHolder": this.id()});
|
||||||
|
},
|
||||||
|
|
||||||
construct: function(template, x, z, angle) {
|
construct: function(template, x, z, angle) {
|
||||||
// TODO: verify this unit can construct this, just for internal
|
// TODO: verify this unit can construct this, just for internal
|
||||||
// sanity-checking and error reporting
|
// sanity-checking and error reporting
|
||||||
|
Loading…
Reference in New Issue
Block a user