29 #include "saga2/target.h" 30 #include "saga2/patrol.h" 34 const int kDefaultEvalRate = 10;
36 const size_t kMaxTaskSize = 48;
46 kGoAwayFromObjectTask,
48 kHuntToBeNearLocationTask,
49 kHuntToBeNearObjectTask,
51 kHuntToBeNearActorTask,
55 kBandAndAvoidEnemiesTask,
56 kFollowPatrolRouteTask,
68 void updateActorTasks();
70 void pauseActorTasks();
71 void resumeActorTasks();
74 TaskStack *newTaskStack(Actor *a);
75 void newTaskStack(TaskStack *p);
78 void deleteTaskStack(TaskStack *p);
81 TaskStackID getTaskStackID(TaskStack *ts);
84 TaskStack *getTaskStackAddress(TaskStackID
id);
87 void initTaskStacks();
93 void cleanupTaskStacks();
96 void newTask(Task *t);
97 void newTask(Task *t, TaskID
id);
100 void deleteTask(Task *p);
103 TaskID getTaskID(Task *t);
106 Task *getTaskAddress(TaskID
id);
128 TaskStackID _stackID;
150 virtual void fixup();
154 virtual int32 archiveSize()
const;
159 virtual int16 getType()
const = 0;
161 virtual void abortTask() = 0;
162 virtual TaskResult evaluate() = 0;
163 virtual TaskResult update() = 0;
166 virtual bool operator == (
const Task &t)
const = 0;
167 bool operator != (
const Task &t)
const {
168 return !operator == (t);
185 debugC(2, kDebugTasks,
" - WanderTask");
186 _type =
"WanderTask";
194 int32 archiveSize()
const;
199 int16 getType()
const;
202 TaskResult evaluate();
206 bool operator == (
const Task &t)
const;
210 virtual TaskResult handleWander();
213 TaskResult handlePaused() {
241 TaskID _gotoTetherID;
257 _gotoTetherID(NoTask) {
258 debugC(2, kDebugTasks,
" - TetheredWanderTask");
259 _type =
"TetheredWanderTask";
269 int32 archiveSize()
const;
274 int16 getType()
const;
279 bool operator == (
const Task &t)
const;
282 TaskResult handleWander();
300 _prevRunState(
false) {
301 debugC(2, kDebugTasks,
" - GotoTask");
312 int32 archiveSize()
const;
317 TaskResult evaluate();
322 virtual TilePoint intermediateDest() = 0;
323 virtual bool lineOfSight() = 0;
324 virtual bool run() = 0;
340 uint8 runDist = maxuint8) :
343 _runThreshold(runDist) {
344 debugC(2, kDebugTasks,
" - GotoLocationTask");
345 _type =
"GotoLocationTask";
352 int32 archiveSize()
const;
357 int16 getType()
const;
360 bool operator == (
const Task &t)
const;
366 void changeTarget(
const TilePoint &newTarget) {
367 _targetLoc = newTarget;
400 debugC(2, kDebugTasks,
" - GotoRegionTask");
401 _type =
"GotoRegionTask";
408 int32 archiveSize()
const;
413 int16 getType()
const;
416 bool operator == (
const Task &t)
const;
453 _lastTestedLoc(Nowhere),
455 _flags(trackFlag ? kTrack : 0),
456 _lastKnownLoc(Nowhere) {
457 debugC(2, kDebugTasks,
" - GotoObjectTargetTask");
458 _type =
"GotoObjectTargetTask";
465 int32 archiveSize()
const;
477 bool tracking()
const {
478 return (_flags & kTrack) != 0;
480 bool isInSight()
const {
481 return (_flags & kInSight) != 0;
499 bool trackFlag =
false) :
502 debugC(2, kDebugTasks,
" - GotoObjectTask");
503 _type =
"GotoObjectTask";
510 int32 archiveSize()
const;
515 int16 getType()
const;
518 bool operator == (
const Task &t)
const;
541 debugC(2, kDebugTasks,
" - GotoActorTask");
542 _type =
"GotoActorTask";
548 int32 archiveSize()
const;
553 int16 getType()
const;
556 bool operator == (
const Task &t)
const;
558 const Actor *getTarget()
const {
588 debugC(2, kDebugTasks,
" - GoAwayFromTask1");
589 _type =
"GoAwayFromTask";
596 _flags(runFlag ? kRun : 0) {
597 debugC(2, kDebugTasks,
" - GoAwayFromTask2");
598 _type =
"GoAwayFromTask";
608 int32 archiveSize()
const;
613 TaskResult evaluate();
617 virtual TilePoint getRepulsionVector() = 0;
632 debugC(2, kDebugTasks,
" - GoAwayFromObjectTask");
633 _type =
"GoAwayFromObjectTask";
640 int32 archiveSize()
const;
645 int16 getType()
const;
648 bool operator == (
const Task &t)
const;
659 TargetPlaceHolder _targetMem;
670 int32 archiveSize()
const;
675 int16 getType()
const;
678 bool operator == (
const Task &t)
const;
699 kHuntWander = (1 << 0),
706 debugC(2, kDebugTasks,
" - HuntTask");
717 int32 archiveSize()
const;
722 TaskResult evaluate();
726 void removeWanderTask();
727 void removeGotoTask();
730 virtual void evaluateTarget() = 0;
732 virtual bool targetHasChanged(
GotoTask *gotoTarget) = 0;
734 virtual TilePoint currentTargetLoc() = 0;
736 virtual bool atTarget() = 0;
737 virtual void atTargetabortTask() = 0;
738 virtual TaskResult atTargetEvaluate() = 0;
739 virtual TaskResult atTargetUpdate() = 0;
747 TargetPlaceHolder _targetMem;
760 int32 archiveSize()
const;
765 bool targetHasChanged(
GotoTask *gotoTarget);
769 const Target *getTarget()
const {
770 return (
const Target *)_targetMem;
781 uint8 _targetEvaluateCtr;
785 kTargetEvaluateRate = 64
794 _targetEvaluateCtr(0) {
795 debugC(2, kDebugTasks,
" - HuntToBeNearLocationTask");
796 _type =
"HuntToBeNearLocationTask";
803 int32 archiveSize()
const;
808 int16 getType()
const;
811 bool operator == (
const Task &t)
const;
814 void evaluateTarget();
818 void atTargetabortTask();
819 TaskResult atTargetEvaluate();
820 TaskResult atTargetUpdate();
822 uint16 getRange()
const {
834 TargetPlaceHolder _targetMem;
847 int32 archiveSize()
const;
852 bool targetHasChanged(
GotoTask *gotoTarget);
868 uint8 _targetEvaluateCtr;
871 kTargetEvaluateRate = 64
883 _targetEvaluateCtr(0) {
884 debugC(2, kDebugTasks,
" - HuntToBeNearObjectTask");
885 _type =
"HuntToBeNearObjectTask";
892 int32 archiveSize()
const;
897 int16 getType()
const;
900 bool operator == (
const Task &t)
const;
903 void evaluateTarget();
907 void atTargetabortTask();
908 TaskResult atTargetEvaluate();
909 TaskResult atTargetUpdate();
911 uint16 getRange()
const {
923 uint8 _targetEvaluateCtr;
926 kTargetEvaluateRate = 64
936 _targetEvaluateCtr(0),
938 debugC(2, kDebugTasks,
" - HuntToPossessTask");
939 _type =
"HuntToPossessTask";
946 int32 archiveSize()
const;
951 int16 getType()
const;
954 bool operator == (
const Task &t)
const;
957 void evaluateTarget();
960 void atTargetabortTask();
961 TaskResult atTargetEvaluate();
962 TaskResult atTargetUpdate();
972 TargetPlaceHolder _targetMem;
980 Actor *_currentTarget;
993 int32 archiveSize()
const;
998 bool targetHasChanged(
GotoTask *gotoTarget);
1006 bool tracking()
const {
1007 return (_flags & kTrack) != 0;
1020 uint8 _targetEvaluateCtr;
1023 kTargetEvaluateRate = 16
1038 bool trackFlag =
false) :
1042 _range(MAX<uint16>(r, 16)),
1043 _targetEvaluateCtr(0) {
1044 debugC(2, kDebugTasks,
" - HuntToBeNearActorTask");
1045 _type =
"HuntToBeNearActorTask";
1055 int32 archiveSize()
const;
1060 int16 getType()
const;
1063 bool operator == (
const Task &t)
const;
1066 void evaluateTarget();
1070 void atTargetabortTask();
1071 TaskResult atTargetEvaluate();
1072 TaskResult atTargetUpdate();
1074 uint16 getRange()
const {
1086 uint8 _targetEvaluateCtr;
1087 uint8 _specialAttackCtr;
1090 kTargetEvaluateRate = 16
1094 kCurrentWeaponBonus = 1
1100 kEvalWeapon = (1 << 0)
1109 bool trackFlag =
false);
1115 int32 archiveSize()
const;
1120 int16 getType()
const;
1123 bool operator == (
const Task &t)
const;
1126 TaskResult update();
1129 void evaluateTarget();
1132 void atTargetabortTask();
1133 TaskResult atTargetEvaluate();
1134 TaskResult atTargetUpdate();
1137 void evaluateWeapon();
1143 inline int16 closenessScore(int16 dist) {
1160 bool trackFlag =
false) :
1163 debugC(2, kDebugTasks,
" - HuntToGiveTask");
1164 _type =
"HuntToGiveTask";
1171 int32 archiveSize()
const;
1176 int16 getType()
const;
1179 bool operator == (
const Task &t)
const;
1182 void evaluateTarget();
1185 void atTargetabortTask();
1186 TaskResult atTargetEvaluate();
1187 TaskResult atTargetUpdate();
1201 uint8 _targetEvaluateCtr;
1204 kTargetEvaluateRate = 2
1215 int16 &repulsorStrength) = 0;
1219 int16 &repulsorStrength) = 0;
1235 int16 &repulsorStrength);
1239 int16 &repulsorStrength);
1249 Actor *_actorArray[6];
1252 bool _iteratingThruEnemies;
1257 for (
int i = 0; i < 6; i++)
1262 bool firstEnemyRepulsor(
1264 int16 &repulsorStrength);
1266 bool nextEnemyRepulsor(
1268 int16 &repulsorStrength);
1273 int16 &repulsorStrength);
1277 int16 &repulsorStrength);
1286 _currentTarget(Nowhere),
1287 _targetEvaluateCtr(0) {
1288 debugC(2, kDebugTasks,
" - BandTask");
1299 int32 archiveSize()
const;
1304 int16 getType()
const;
1307 bool operator == (
const Task &t)
const;
1310 void evaluateTarget();
1312 bool targetHasChanged(
GotoTask *gotoTarget);
1318 void atTargetabortTask();
1319 TaskResult atTargetEvaluate();
1320 TaskResult atTargetUpdate();
1322 virtual int16 getRunThreshold();
1370 int16 getType()
const;
1373 bool operator == (
const Task &t)
const;
1376 int16 getRunThreshold();
1386 TaskID _gotoWayPointID;
1389 int16 _lastWayPointNum;
1401 int16 stopAt = -1) :
1403 _gotoWayPoint(NULL),
1404 _gotoWayPointID(NoTask),
1406 _lastWayPointNum(stopAt), _counter(0) {
1407 debugC(2, kDebugTasks,
" - FollowPatrolRouteTask");
1408 _type =
"FollowPatrolRouteTask";
1409 followPatrolRoute();
1419 int32 archiveSize()
const;
1424 int16 getType()
const;
1427 TaskResult evaluate();
1428 TaskResult update();
1431 bool operator == (
const Task &t)
const;
1434 TaskResult handleFollowPatrolRoute();
1437 TaskResult handlePaused();
1443 void followPatrolRoute() {
1458 debugC(2, kDebugTasks,
" - AttendTask");
1459 _type =
"AttendTask";
1466 int32 archiveSize()
const;
1471 int16 getType()
const;
1474 TaskResult evaluate();
1475 TaskResult update();
1478 bool operator == (
const Task &t)
const;
1489 class DefendTask :
public Task {
1503 int32 archiveSize()
const;
1506 int16 getType()
const;
1509 TaskResult evaluate();
1510 TaskResult update();
1513 bool operator == (
const Task &t)
const;
1520 class ParryTask :
public Task {
1527 kMotionStarted = (1 << 0),
1528 kBlockStarted = (1 << 1)
1542 int32 archiveSize()
const;
1545 int16 getType()
const;
1548 TaskResult evaluate();
1549 TaskResult update();
1552 bool operator == (
const Task &t)
const;
1565 TaskID _stackBottomID;
1580 _stackBottomID(NoTask),
1582 _evalCount(kDefaultEvalRate),
1583 _evalRate(kDefaultEvalRate) {
1591 _actor->_curTask =
nullptr;
1592 deleteTaskStack(
this);
1597 int32 archiveSize() {
1598 return sizeof(ObjectID)
1599 +
sizeof(_stackBottomID)
1600 +
sizeof(_evalCount)
1601 +
sizeof(_evalRate);
1609 void setTask(
Task *t);
1612 const Task *getTask() {
1613 return _stackBottomID != NoTask
1614 ? getTaskAddress(_stackBottomID)
1625 TaskResult evaluate();
1627 TaskResult update();
Definition: savefile.h:54
Definition: memstream.h:194
Definition: tcoords.h:127
Definition: objects.h:118
void void void void void debugC(int level, uint32 debugChannels, MSVC_PRINTF const char *s,...) GCC_PRINTF(3