Files
kam-mobile/vendor/kam_remake/src/units/tasks/KM_UnitTaskGoHome.pas
T
admin_d 7063d1b1c9
Sync changed files to Google Drive / sync (push) Successful in 1h45m13s
sync: restore source from Google Drive
2026-09-12 16:50:30 +05:00

69 lines
1.2 KiB
ObjectPascal

unit KM_UnitTaskGoHome;
{$I KaM_Remake.inc}
interface
uses
Classes, SysUtils,
KM_Defaults, KM_Units;
type
TKMTaskGoHome = class(TKMUnitTask)
public
constructor Create(aUnit: TKMUnit);
function Execute: TKMTaskResult; override;
function CouldBeCancelled: Boolean; override;
end;
implementation
{ TTaskGoHome }
constructor TKMTaskGoHome.Create(aUnit: TKMUnit);
begin
inherited;
fType := uttGoHome;
aUnit.Thought := thHome;
end;
function TKMTaskGoHome.CouldBeCancelled: Boolean;
begin
Result := (fPhase - 1) //phase was increased at the end of execution
<= 0; //Allow cancel task only at walking phases
end;
function TKMTaskGoHome.Execute: TKMTaskResult;
begin
Result := trTaskContinues;
if fUnit.Home.IsDestroyed then
begin
Result := trTaskDone;
Exit;
end;
with fUnit do
case fPhase of
0: begin
Thought := thHome;
SetActionWalkToSpot(Home.PointBelowEntrance);
end;
1: SetActionGoIn(uaWalk, gdGoInside, Home);
2: begin
Thought := thNone; //Only stop thinking once we are right inside
Home.SetState(hstIdle);
SetActionStay(5, uaWalk);
end;
else Result := trTaskDone;
end;
Inc(fPhase);
end;
end.