Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/ai/common-api/entity.js
Show First 20 Lines • Show All 416 Lines • ▼ Show 20 Lines | m.Template = m.Class({ | |||||||||||||||
"promotion": function() { return this.get("Promotion/Entity"); }, | "promotion": function() { return this.get("Promotion/Entity"); }, | |||||||||||||||
"isPackable": function() { return this.get("Pack") != undefined; }, | "isPackable": function() { return this.get("Pack") != undefined; }, | |||||||||||||||
/** | /** | |||||||||||||||
* Returns whether this is an animal that is too difficult to hunt. | * Returns whether this is an animal that is too difficult to hunt. | |||||||||||||||
*/ | */ | |||||||||||||||
"isHuntable": function() { | "isHuntable": function() { | |||||||||||||||
if(!this.get("ResourceSupply/KillBeforeGather")) | if (!this.get("ResourceSupply/KillBeforeGather")) | |||||||||||||||
return false; | return false; | |||||||||||||||
// do not hunt retaliating animals (animals without UnitAI are dead animals) | // Do not hunt retaliating animals (animals without UnitAI are dead animals). | |||||||||||||||
let behaviour = this.get("UnitAI/NaturalBehaviour"); | // Assume entities which can attack, will attack. | |||||||||||||||
return !behaviour || | return !this.get("UnitAI") || !this.get("Attack"); | |||||||||||||||
Stan: Refs: D497 | ||||||||||||||||
behaviour != "violent" && behaviour != "aggressive" && behaviour != "defensive"; | ||||||||||||||||
}, | }, | |||||||||||||||
Done Inline Actions
Maybe ? Stan: Maybe ? | ||||||||||||||||
"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(productionQueue) { | |||||||||||||||
let time = +this.get("Cost/BuildTime"); | let time = +this.get("Cost/BuildTime"); | |||||||||||||||
if (productionQueue) | if (productionQueue) | |||||||||||||||
▲ Show 20 Lines • Show All 320 Lines • ▼ Show 20 Lines | "canAttackTarget": function(target, allowCapture) | |||||||||||||||
for (let type in attackTypes) | for (let type in attackTypes) | |||||||||||||||
{ | { | |||||||||||||||
if (type == "Capture" ? !canCapture : target.isInvulnerable()) | if (type == "Capture" ? !canCapture : target.isInvulnerable()) | |||||||||||||||
continue; | continue; | |||||||||||||||
let restrictedClasses = this.get("Attack/" + type + "/RestrictedClasses/_string"); | let restrictedClasses = this.get("Attack/" + type + "/RestrictedClasses/_string"); | |||||||||||||||
if (!restrictedClasses || !MatchesClassList(target.classes(), restrictedClasses)) | if (!restrictedClasses || !MatchesClassList(target.classes(), restrictedClasses)) | |||||||||||||||
return true; | return true; | |||||||||||||||
}; | }; | |||||||||||||||
Lint: ESLintBear (no-extra-semi) Unnecessary semicolon. Lint: ESLintBear (no-extra-semi): `Unnecessary semicolon.` | ||||||||||||||||
Lint: JSHintBear Unnecessary semicolon. Lint: JSHintBear: `Unnecessary semicolon.` | ||||||||||||||||
return false; | return false; | |||||||||||||||
}, | }, | |||||||||||||||
"move": function(x, z, queued = false) { | "move": function(x, z, queued = false) { | |||||||||||||||
Engine.PostCommand(PlayerID, { "type": "walk", "entities": [this.id()], "x": x, "z": z, "queued": queued }); | Engine.PostCommand(PlayerID, { "type": "walk", "entities": [this.id()], "x": x, "z": z, "queued": queued }); | |||||||||||||||
return this; | return this; | |||||||||||||||
}, | }, | |||||||||||||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | m.Entity = m.Class({ | |||||||||||||||
"attack": function(unitId, allowCapture = true, queued = false) { | "attack": function(unitId, allowCapture = true, queued = false) { | |||||||||||||||
Engine.PostCommand(PlayerID, { "type": "attack", "entities": [this.id()], "target": unitId, "allowCapture": allowCapture, "queued": queued }); | Engine.PostCommand(PlayerID, { "type": "attack", "entities": [this.id()], "target": unitId, "allowCapture": allowCapture, "queued": queued }); | |||||||||||||||
return this; | return this; | |||||||||||||||
}, | }, | |||||||||||||||
// moveApart from a point in the opposite direction with a distance dist | // moveApart from a point in the opposite direction with a distance dist | |||||||||||||||
"moveApart": function(point, dist) { | "moveApart": function(point, dist) { | |||||||||||||||
if (this.position() !== undefined) { | if (this.position() !== undefined) { | |||||||||||||||
Lint: ESLintBear (brace-rules/brace-on-same-line) Opening curly brace appears on the same line as controlling statement. Lint: ESLintBear (brace-rules/brace-on-same-line): `Opening curly brace appears on the same line as controlling statement.` | ||||||||||||||||
let direction = [this.position()[0] - point[0], this.position()[1] - point[1]]; | let direction = [this.position()[0] - point[0], this.position()[1] - point[1]]; | |||||||||||||||
let norm = m.VectorDistance(point, this.position()); | let norm = m.VectorDistance(point, this.position()); | |||||||||||||||
if (norm === 0) | if (norm === 0) | |||||||||||||||
direction = [1, 0]; | direction = [1, 0]; | |||||||||||||||
else | else | |||||||||||||||
{ | { | |||||||||||||||
direction[0] /= norm; | direction[0] /= norm; | |||||||||||||||
direction[1] /= norm; | direction[1] /= norm; | |||||||||||||||
} | } | |||||||||||||||
Engine.PostCommand(PlayerID, { "type": "walk", "entities": [this.id()], "x": this.position()[0] + direction[0]*dist, "z": this.position()[1] + direction[1]*dist, "queued": false }); | Engine.PostCommand(PlayerID, { "type": "walk", "entities": [this.id()], "x": this.position()[0] + direction[0]*dist, "z": this.position()[1] + direction[1]*dist, "queued": false }); | |||||||||||||||
} | } | |||||||||||||||
return this; | return this; | |||||||||||||||
}, | }, | |||||||||||||||
// Flees from a unit in the opposite direction. | // Flees from a unit in the opposite direction. | |||||||||||||||
"flee": function(unitToFleeFrom) { | "flee": function(unitToFleeFrom) { | |||||||||||||||
if (this.position() !== undefined && unitToFleeFrom.position() !== undefined) { | if (this.position() !== undefined && unitToFleeFrom.position() !== undefined) { | |||||||||||||||
Lint: ESLintBear (brace-rules/brace-on-same-line) Opening curly brace appears on the same line as controlling statement. Lint: ESLintBear (brace-rules/brace-on-same-line): `Opening curly brace appears on the same line as controlling statement.` | ||||||||||||||||
let FleeDirection = [this.position()[0] - unitToFleeFrom.position()[0], | let FleeDirection = [this.position()[0] - unitToFleeFrom.position()[0], | |||||||||||||||
this.position()[1] - unitToFleeFrom.position()[1]]; | this.position()[1] - unitToFleeFrom.position()[1]]; | |||||||||||||||
let dist = m.VectorDistance(unitToFleeFrom.position(), this.position()); | let dist = m.VectorDistance(unitToFleeFrom.position(), this.position()); | |||||||||||||||
FleeDirection[0] = 40 * FleeDirection[0]/dist; | FleeDirection[0] = 40 * FleeDirection[0]/dist; | |||||||||||||||
FleeDirection[1] = 40 * FleeDirection[1]/dist; | FleeDirection[1] = 40 * FleeDirection[1]/dist; | |||||||||||||||
Engine.PostCommand(PlayerID, { "type": "walk", "entities": [this.id()], "x": this.position()[0] + FleeDirection[0], "z": this.position()[1] + FleeDirection[1], "queued": false }); | Engine.PostCommand(PlayerID, { "type": "walk", "entities": [this.id()], "x": this.position()[0] + FleeDirection[0], "z": this.position()[1] + FleeDirection[1], "queued": false }); | |||||||||||||||
} | } | |||||||||||||||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | m.Entity = m.Class({ | |||||||||||||||
"removeGuard": function() { | "removeGuard": function() { | |||||||||||||||
Engine.PostCommand(PlayerID, { "type": "remove-guard", "entities": [this.id()] }); | Engine.PostCommand(PlayerID, { "type": "remove-guard", "entities": [this.id()] }); | |||||||||||||||
return this; | return this; | |||||||||||||||
} | } | |||||||||||||||
}); | }); | |||||||||||||||
return m; | return m; | |||||||||||||||
}(API3); | }(API3); | |||||||||||||||
Lint: ESLintBear (no-use-before-define) 'API3' was used before it was defined. Lint: ESLintBear (no-use-before-define): `'API3' was used before it was defined.` |
Wildfire Games · Phabricator
Refs: D497