SAGA2: Fix TaskStack construction for full stack

This commit is contained in:
a/ 2021-08-08 15:49:43 +09:00
parent fe098887ce
commit 4cd2a2d433
4 changed files with 33 additions and 5 deletions

View File

@ -2627,7 +2627,7 @@ void Actor::updateState(void) {
disband();
if (curTask == NULL) {
if ((curTask = new TaskStack(this)) != NULL) {
if ((curTask = newTaskStack(this)) != NULL) {
Task *task = new GoAwayFromActorTask(
curTask,
ActorPropertyTarget(
@ -2649,7 +2649,7 @@ void Actor::updateState(void) {
case actorGoalAttackEnemy:
if (curTask == NULL) {
if ((curTask = new TaskStack(this)) != NULL) {
if ((curTask = newTaskStack(this)) != NULL) {
uint8 disp = leader != NULL
? leader->disposition
: disposition;
@ -2687,7 +2687,7 @@ void Actor::updateState(void) {
assert(followers == NULL);
if (curTask == NULL) {
if ((curTask = new TaskStack(this)) != NULL) {
if ((curTask = newTaskStack(this)) != NULL) {
Task *task = new BandAndAvoidEnemiesTask(curTask);
if (task != NULL)
@ -3094,7 +3094,7 @@ TaskStack *Actor::createFollowerTask(Actor *bandMember) {
TaskStack *ts = NULL;
if ((ts = new TaskStack(bandMember)) != NULL) {
if ((ts = newTaskStack(bandMember)) != NULL) {
Task *task = new BandTask(ts);
if (task != NULL)

View File

@ -111,7 +111,7 @@ TaskStack *ActorAssignment::createTask(void) {
Actor *a = getActor();
TaskStack *ts = NULL;
if ((ts = new TaskStack(a)) != NULL) {
if ((ts = newTaskStack(a)) != NULL) {
Task *task = getTask(ts);
if (task != NULL)

View File

@ -120,6 +120,8 @@ public:
// Place a TaskStack from the inactive list into the active
// list.
TaskStack *newTaskStack(Actor *a);
void newTaskStack(TaskStack *p);
void newTaskStack(TaskStack *p, TaskID id);
@ -238,7 +240,28 @@ void TaskStackList::write(Common::MemoryWriteStreamDynamic *out) {
//----------------------------------------------------------------------
// Place a TaskStack into the active list and return its address
TaskStack *TaskStackList::newTaskStack(Actor *a) {
for (int i = 0; i < numTaskStacks; i++)
if (!_list[i]) {
_list[i] = new TaskStack(a);
return _list[i];
}
warning("Too many task stacks in the list, > %d", numTaskStacks);
return nullptr;
}
void TaskStackList::newTaskStack(TaskStack *p) {
for (int i = 0; i < numTaskStacks; i++) {
if (_list[i] == p) {
warning("TaskStack %d (%p) already added", i, (void *)p);
return;
}
}
for (int i = 0; i < numTaskStacks; i++)
if (!_list[i]) {
_list[i] = p;
@ -309,6 +332,10 @@ void resumeActorTasks(void) {
// Call the stackList member function newTaskStack() to get a pointer
// to a new TaskStack
TaskStack *newTaskStack(Actor *a) {
return g_vm->_stackList->newTaskStack(a);
}
void newTaskStack(TaskStack *p) {
return g_vm->_stackList->newTaskStack(p);
}

View File

@ -72,6 +72,7 @@ void pauseActorTasks(void);
void resumeActorTasks(void);
// Allocate a new task stack
TaskStack *newTaskStack(Actor *a);
void newTaskStack(TaskStack *p);
// Dispose of a previously allocated task stack