Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/UnitAI.js
Show First 20 Lines • Show All 1,226 Lines • ▼ Show 20 Lines | "Order.LeaveFoundation": function(msg) { | ||||
if (!IsOwnedByAllyOfEntity(this.entity, msg.data.target) && !Engine.QueryInterface(SYSTEM_ENTITY, IID_CeasefireManager).IsCeasefireActive() || | if (!IsOwnedByAllyOfEntity(this.entity, msg.data.target) && !Engine.QueryInterface(SYSTEM_ENTITY, IID_CeasefireManager).IsCeasefireActive() || | ||||
this.IsPacking() || this.CanPack() || this.IsTurret()) | this.IsPacking() || this.CanPack() || this.IsTurret()) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return; | return; | ||||
} | } | ||||
// Move a tile outside the building | // Move a tile outside the building | ||||
let range = 4; | let range = 4; | ||||
if (this.CheckTargetRangeExplicit(msg.data.target, range, range)) | if (this.CheckTargetRangeExplicit(msg.data.target, range, -1)) | ||||
{ | { | ||||
// We are already at the target, or can't move at all | // We are already at the target, or can't move at all | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
this.order.data.min = range; | this.order.data.min = range; | ||||
this.SetNextState("WALKINGTOPOINT"); | this.SetNextState("WALKINGTOPOINT"); | ||||
▲ Show 20 Lines • Show All 1,714 Lines • ▼ Show 20 Lines | "Attacked": function(msg) { | ||||
{ | { | ||||
// Never flee, stop what we were doing | // Never flee, stop what we were doing | ||||
this.SetNextState("IDLE"); | this.SetNextState("IDLE"); | ||||
} | } | ||||
}, | }, | ||||
"Order.LeaveFoundation": function(msg) { | "Order.LeaveFoundation": function(msg) { | ||||
// Move a tile outside the building | // Move a tile outside the building | ||||
var range = 4; | let range = 4; | ||||
if (this.CheckTargetRangeExplicit(msg.data.target, range, range)) | if (this.CheckTargetRangeExplicit(msg.data.target, range, -1)) | ||||
{ | { | ||||
this.FinishOrder(); | this.FinishOrder(); | ||||
return; | return; | ||||
} | } | ||||
else | |||||
{ | |||||
this.order.data.min = range; | this.order.data.min = range; | ||||
this.SetNextState("WALKING"); | this.SetNextState("WALKING"); | ||||
} | |||||
}, | }, | ||||
"IDLE": { | "IDLE": { | ||||
// (We need an IDLE state so that FinishOrder works) | // (We need an IDLE state so that FinishOrder works) | ||||
"enter": function() { | "enter": function() { | ||||
// Start feeding immediately | // Start feeding immediately | ||||
this.SetNextState("FEEDING"); | this.SetNextState("FEEDING"); | ||||
▲ Show 20 Lines • Show All 2,795 Lines • ▼ Show 20 Lines | UnitAI.prototype.MoveRandomly = function(distance) | ||||
let halfDelta = randFloat(this.roamAngle / 4, this.roamAngle * 3 / 4); | let halfDelta = randFloat(this.roamAngle / 4, this.roamAngle * 3 / 4); | ||||
// First half rotation to decrease the impression of immediate rotation | // First half rotation to decrease the impression of immediate rotation | ||||
ang += halfDelta; | ang += halfDelta; | ||||
cmpUnitMotion.FaceTowardsPoint(pos.x + 0.5 * Math.sin(ang), pos.z + 0.5 * Math.cos(ang)); | cmpUnitMotion.FaceTowardsPoint(pos.x + 0.5 * Math.sin(ang), pos.z + 0.5 * Math.cos(ang)); | ||||
// Then second half of the rotation | // Then second half of the rotation | ||||
ang += halfDelta; | ang += halfDelta; | ||||
let dist = randFloat(0.5, 1.5) * distance; | let dist = randFloat(0.5, 1.5) * distance; | ||||
cmpUnitMotion.MoveToPointRange(pos.x - 0.5 * Math.sin(ang), pos.z - 0.5 * Math.cos(ang), dist, dist); | cmpUnitMotion.MoveToPointRange(pos.x - 0.5 * Math.sin(ang), pos.z - 0.5 * Math.cos(ang), dist, -1); | ||||
}; | }; | ||||
UnitAI.prototype.SetFacePointAfterMove = function(val) | UnitAI.prototype.SetFacePointAfterMove = function(val) | ||||
{ | { | ||||
var cmpMotion = Engine.QueryInterface(this.entity, IID_UnitMotion); | var cmpMotion = Engine.QueryInterface(this.entity, IID_UnitMotion); | ||||
if (cmpMotion) | if (cmpMotion) | ||||
cmpMotion.SetFacePointAfterMove(val); | cmpMotion.SetFacePointAfterMove(val); | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 82 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator