Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/ai/common-api/entity.js
Show First 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | if (!cost) | ||||
return 0; | return 0; | ||||
let ret = 0; | let ret = 0; | ||||
for (let type in cost) | for (let type in cost) | ||||
ret += cost[type]; | ret += cost[type]; | ||||
return ret; | return ret; | ||||
}, | }, | ||||
"techCostMultiplier": function(type) { | "techCostMultiplier": function(type) { | ||||
return +(this.get("ProductionQueue/TechCostMultiplier/"+type) || 1); | return +(this.get("Researcher/TechCostMultiplier/"+type) || 1); | ||||
}, | }, | ||||
/** | /** | ||||
* Returns { "max": max, "min": min } or undefined if no obstruction. | * Returns { "max": max, "min": min } or undefined if no obstruction. | ||||
* max: radius of the outer circle surrounding this entity's obstruction shape | * max: radius of the outer circle surrounding this entity's obstruction shape | ||||
* min: radius of the inner circle | * min: radius of the inner circle | ||||
*/ | */ | ||||
"obstructionRadius": function() { | "obstructionRadius": function() { | ||||
▲ Show 20 Lines • Show All 204 Lines • ▼ Show 20 Lines | m.Template = m.Class({ | ||||
"buildableEntities": function(civ) { | "buildableEntities": function(civ) { | ||||
let templates = this.get("Builder/Entities/_string"); | let templates = this.get("Builder/Entities/_string"); | ||||
if (!templates) | if (!templates) | ||||
return []; | return []; | ||||
return templates.replace(/\{native\}/g, this.civ()).replace(/\{civ\}/g, civ).split(/\s+/); | return templates.replace(/\{native\}/g, this.civ()).replace(/\{civ\}/g, civ).split(/\s+/); | ||||
}, | }, | ||||
"trainableEntities": function(civ) { | "trainableEntities": function(civ) { | ||||
let templates = this.get("ProductionQueue/Entities/_string"); | const templates = this.get("Trainer/Entities/_string"); | ||||
if (!templates) | if (!templates) | ||||
return undefined; | return undefined; | ||||
return templates.replace(/\{native\}/g, this.civ()).replace(/\{civ\}/g, civ).split(/\s+/); | return templates.replace(/\{native\}/g, this.civ()).replace(/\{civ\}/g, civ).split(/\s+/); | ||||
}, | }, | ||||
"researchableTechs": function(gameState, civ) { | "researchableTechs": function(gameState, civ) { | ||||
let templates = this.get("ProductionQueue/Technologies/_string"); | const templates = this.get("Researcher/Technologies/_string"); | ||||
if (!templates) | if (!templates) | ||||
return undefined; | return undefined; | ||||
let techs = templates.split(/\s+/); | let techs = templates.split(/\s+/); | ||||
for (let i = 0; i < techs.length; ++i) | for (let i = 0; i < techs.length; ++i) | ||||
{ | { | ||||
let tech = techs[i]; | let tech = techs[i]; | ||||
if (tech.indexOf("{civ}") == -1) | if (tech.indexOf("{civ}") == -1) | ||||
continue; | continue; | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | "isHuntable": function() { | ||||
return this.get("ResourceSupply/KillBeforeGather") && | return this.get("ResourceSupply/KillBeforeGather") && | ||||
(!this.get("Health") || !this.get("Attack")); | (!this.get("Health") || !this.get("Attack")); | ||||
}, | }, | ||||
"walkSpeed": function() { return +this.get("UnitMotion/WalkSpeed"); }, | "walkSpeed": function() { return +this.get("UnitMotion/WalkSpeed"); }, | ||||
"trainingCategory": function() { return this.get("TrainingRestrictions/Category"); }, | "trainingCategory": function() { return this.get("TrainingRestrictions/Category"); }, | ||||
"buildTime": function(productionQueue) { | "buildTime": function(researcher) { | ||||
let time = +this.get("Cost/BuildTime"); | let time = +this.get("Cost/BuildTime"); | ||||
if (productionQueue) | if (researcher) | ||||
time *= productionQueue.techCostMultiplier("time"); | time *= researcher.techCostMultiplier("time"); | ||||
return time; | return time; | ||||
}, | }, | ||||
"buildCategory": function() { return this.get("BuildRestrictions/Category"); }, | "buildCategory": function() { return this.get("BuildRestrictions/Category"); }, | ||||
"buildDistance": function() { | "buildDistance": function() { | ||||
let distance = this.get("BuildRestrictions/Distance"); | let distance = this.get("BuildRestrictions/Distance"); | ||||
if (!distance) | if (!distance) | ||||
▲ Show 20 Lines • Show All 468 Lines • ▼ Show 20 Lines | "setRallyPoint": function(target, command) { | ||||
return this; | return this; | ||||
}, | }, | ||||
"unsetRallyPoint": function() { | "unsetRallyPoint": function() { | ||||
Engine.PostCommand(PlayerID, { "type": "unset-rallypoint", "entities": [this.id()] }); | Engine.PostCommand(PlayerID, { "type": "unset-rallypoint", "entities": [this.id()] }); | ||||
return this; | return this; | ||||
}, | }, | ||||
"train": function(civ, type, count, metadata, promotedTypes, pushFront = false) | "train": function(civ, type, count, metadata, pushFront = false) | ||||
{ | { | ||||
let trainable = this.trainableEntities(civ); | let trainable = this.trainableEntities(civ); | ||||
if (!trainable) | if (!trainable) | ||||
{ | { | ||||
error("Called train("+type+", "+count+") on non-training entity "+this); | error("Called train("+type+", "+count+") on non-training entity "+this); | ||||
return this; | return this; | ||||
} | } | ||||
if (trainable.indexOf(type) == -1) | if (trainable.indexOf(type) == -1) | ||||
{ | { | ||||
error("Called train("+type+", "+count+") on entity "+this+" which can't train that"); | error("Called train("+type+", "+count+") on entity "+this+" which can't train that"); | ||||
return this; | return this; | ||||
} | } | ||||
Engine.PostCommand(PlayerID, { | Engine.PostCommand(PlayerID, { | ||||
"type": "train", | "type": "train", | ||||
"entities": [this.id()], | "entities": [this.id()], | ||||
"template": type, | "template": type, | ||||
"count": count, | "count": count, | ||||
"metadata": metadata, | "metadata": metadata, | ||||
"promoted": promotedTypes, | |||||
"pushFront": pushFront | "pushFront": pushFront | ||||
}); | }); | ||||
return this; | return this; | ||||
}, | }, | ||||
"construct": function(template, x, z, angle, metadata) { | "construct": function(template, x, z, angle, metadata) { | ||||
// 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 | ||||
▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator