Changeset View
Standalone View
binaries/data/mods/public/simulation/ai/common-api/entity.js
Show First 20 Lines • Show All 395 Lines • ▼ Show 20 Lines | "resourceDropsiteTypes": function() { | ||||
return types ? types.split(/\s+/) : []; | return types ? types.split(/\s+/) : []; | ||||
}, | }, | ||||
"garrisonableClasses": function() { return this.get("GarrisonHolder/List/_string"); }, | "garrisonableClasses": function() { return this.get("GarrisonHolder/List/_string"); }, | ||||
"garrisonMax": function() { return this.get("GarrisonHolder/Max"); }, | "garrisonMax": function() { return this.get("GarrisonHolder/Max"); }, | ||||
"garrisonSize": function() { return this.get("Garrisonable/Size"); }, | |||||
"garrisonEjectHealth": function() { return +this.get("GarrisonHolder/EjectHealth"); }, | "garrisonEjectHealth": function() { return +this.get("GarrisonHolder/EjectHealth"); }, | ||||
"getDefaultArrow": function() { return +this.get("BuildingAI/DefaultArrowCount"); }, | "getDefaultArrow": function() { return +this.get("BuildingAI/DefaultArrowCount"); }, | ||||
"getArrowMultiplier": function() { return +this.get("BuildingAI/GarrisonArrowMultiplier"); }, | "getArrowMultiplier": function() { return +this.get("BuildingAI/GarrisonArrowMultiplier"); }, | ||||
"getGarrisonArrowClasses": function() { | "getGarrisonArrowClasses": function() { | ||||
if (!this.get("BuildingAI")) | if (!this.get("BuildingAI")) | ||||
▲ Show 20 Lines • Show All 281 Lines • ▼ Show 20 Lines | "currentGatherRate": function() { | ||||
// returns the gather rate for the current target if applicable. | // returns the gather rate for the current target if applicable. | ||||
if (!this.get("ResourceGatherer")) | if (!this.get("ResourceGatherer")) | ||||
return undefined; | return undefined; | ||||
if (this.unitAIOrderData().length && | if (this.unitAIOrderData().length && | ||||
(this.unitAIState().split(".")[1] == "GATHER" || this.unitAIState().split(".")[1] == "RETURNRESOURCE")) | (this.unitAIState().split(".")[1] == "GATHER" || this.unitAIState().split(".")[1] == "RETURNRESOURCE")) | ||||
{ | { | ||||
let res; | let res; | ||||
// this is an abuse of "_ai" but it works. | // this is an abuse of "_ai" but it works. | ||||
Freagarach: Got that (below) from here. | |||||
if (this.unitAIState().split(".")[1] == "GATHER" && this.unitAIOrderData()[0].target !== undefined) | if (this.unitAIState().split(".")[1] == "GATHER" && this.unitAIOrderData()[0].target !== undefined) | ||||
res = this._ai._entities.get(this.unitAIOrderData()[0].target); | res = this._ai._entities.get(this.unitAIOrderData()[0].target); | ||||
else if (this.unitAIOrderData()[1] !== undefined && this.unitAIOrderData()[1].target !== undefined) | else if (this.unitAIOrderData()[1] !== undefined && this.unitAIOrderData()[1].target !== undefined) | ||||
res = this._ai._entities.get(this.unitAIOrderData()[1].target); | res = this._ai._entities.get(this.unitAIOrderData()[1].target); | ||||
if (!res) | if (!res) | ||||
return 0; | return 0; | ||||
let type = res.resourceSupplyType(); | let type = res.resourceSupplyType(); | ||||
if (!type) | if (!type) | ||||
return 0; | return 0; | ||||
if (type.generic == "treasure") | if (type.generic == "treasure") | ||||
return 1000; | return 1000; | ||||
let tstring = type.generic + "." + type.specific; | let tstring = type.generic + "." + type.specific; | ||||
let rate = +this.get("ResourceGatherer/BaseSpeed"); | let rate = +this.get("ResourceGatherer/BaseSpeed"); | ||||
rate *= +this.get("ResourceGatherer/Rates/" +tstring); | rate *= +this.get("ResourceGatherer/Rates/" +tstring); | ||||
if (rate) | if (rate) | ||||
return rate; | return rate; | ||||
return 0; | return 0; | ||||
} | } | ||||
return undefined; | return undefined; | ||||
}, | }, | ||||
"garrisoned": function() { return this._entity.garrisoned; }, | "garrisoned": function() { return this._entity.garrisoned; }, | ||||
"canGarrisonInside": function() { return this._entity.garrisoned.length < this.garrisonMax(); }, | |||||
"garrisonedSlots": function() { | |||||
let count = 0; | |||||
if (this._entity.garrisoned) | |||||
for (let ent of this._entity.garrisoned) | |||||
count += +this._ai._entities.get(ent).garrisonSize(); | |||||
return count; | |||||
Done Inline Actions@Angen, please help yet again. I can't get this to work. ent.garrisonSlots() does not exist, but I created it above,,, Freagarach: @Angen, please help yet again. I can't get this to work. `ent.garrisonSlots()` does not exist… | |||||
Done Inline ActionsgarrisonSlots is template function, not entity function Silier: garrisonSlots is template function, not entity function | |||||
Done Inline ActionsBut even if I make it an entity function it whines about it being not a function :( Freagarach: But even if I make it an entity function it whines about it being not a function :(
I tried… | |||||
Done Inline ActionsI think .garrisoned returns only ids of entities not entities themselves Silier: I think .garrisoned returns only ids of entities not entities themselves | |||||
Done Inline ActionsAh, so from the IDs it cannot 'calculate' the data? I thought on the basis of an ID it could get the information needed! Freagarach: Ah, so from the IDs it cannot 'calculate' the data? I thought on the basis of an ID it could… | |||||
Done Inline ActionsI got it working, thanks again! Your help is truly appreciated. Freagarach: I got it working, thanks again! Your help is truly appreciated.
Not sure whether the way I do… | |||||
}, | |||||
"canGarrisonInside": function() { return this.garrisonedSlots() < this.garrisonMax(); }, | |||||
Done Inline ActionsNewlines ? Stan: Newlines ? | |||||
/** | /** | ||||
* returns true if the entity can attack (including capture) the given class. | * returns true if the entity can attack (including capture) the given class. | ||||
*/ | */ | ||||
"canAttackClass": function(aClass) | "canAttackClass": function(aClass) | ||||
{ | { | ||||
if (!this.get("Attack")) | if (!this.get("Attack")) | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 214 Lines • Show Last 20 Lines |
Got that (below) from here.