Ticket #1165: entity.js.patch
File entity.js.patch, 2.8 KB (added by , 12 years ago) |
---|
-
entity.js
177 177 178 178 return this._template.GarrisonHolder.Max; 179 179 }, 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 }, 180 188 181 189 /** 182 190 * Returns whether this is an animal that is too difficult to hunt. … … 286 294 }, 287 295 288 296 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(); }, 292 300 293 301 /** 294 302 * Returns the current training queue state, of the form … … 340 348 { 341 349 return (this.garrisonMax() - this.garrisoned().length); 342 350 }, 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; 343 358 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 344 369 // 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 346 376 move: function(x, z, queued) { 347 377 queued = queued || false; 348 378 Engine.PostCommand({"type": "walk", "entities": [this.id()], "x": x, "z": z, "queued": queued}); … … 389 419 }); 390 420 return this; 391 421 }, 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 }, 392 433 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 393 443 construct: function(template, x, z, angle) { 394 444 // TODO: verify this unit can construct this, just for internal 395 445 // sanity-checking and error reporting