Skip to content

Commit

Permalink
Potentially fixed defect 209.
Browse files Browse the repository at this point in the history
  • Loading branch information
klei1984 committed Nov 7, 2023
1 parent 0c4b15f commit eb2add0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
23 changes: 18 additions & 5 deletions src/taskmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,14 @@ bool TaskMove::Execute(UnitInfo& unit) {
void TaskMove::RemoveSelf() {
if (passenger) {
passenger->RemoveTask(this);
}

AiLog log("Move (RemoveSelf): Remove %s at [%i,%i].", UnitsManager_BaseUnits[passenger->unit_type].singular_name,
passenger->grid_x + 1, passenger->grid_y + 1);
AiLog log("Move (RemoveSelf): Remove %s at [%i,%i].",
UnitsManager_BaseUnits[passenger->unit_type].singular_name, passenger->grid_x + 1,
passenger->grid_y + 1);

passenger = nullptr;
}

passenger = nullptr;
zone = nullptr;
parent = nullptr;

Expand All @@ -335,7 +337,18 @@ void TaskMove::RemoveSelf() {

void TaskMove::RemoveUnit(UnitInfo& unit) {
if (passenger == &unit) {
AiLog log("Move: Remove %s.", UnitsManager_BaseUnits[unit.unit_type].singular_name);
for (auto it = passenger->delayed_tasks.Begin(), it_end = passenger->delayed_tasks.End(); it != it_end; ++it) {
if ((*it).GetType() == TaskType_TaskTransport) {
TaskTransport* transport = dynamic_cast<TaskTransport*>(it->Get());

if (transport->IsClient(this)) {
transport->RemoveUnit(unit);
}
}
}

AiLog log("Move (RemoveUnit): Remove %s at [%i,%i].", UnitsManager_BaseUnits[unit.unit_type].singular_name,
unit.grid_x + 1, unit.grid_y + 1);

Finished(TASKMOVE_RESULT_CANCELLED);
}
Expand Down
15 changes: 14 additions & 1 deletion src/tasktransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,19 @@ bool TaskTransport::ChooseNewTask() {
return result;
}

bool TaskTransport::IsClient(TaskMove* move) {
bool result{false};

for (auto it = move_tasks.Begin(), it_end = move_tasks.End(); it != it_end; ++it) {
if (it->Get() == move) {
result = true;
break;
}
}

return result;
}

void TaskTransport::AddClient(TaskMove* move) {
AiLog log("Transport: Add Client %s.", UnitsManager_BaseUnits[move->GetPassenger()->unit_type].singular_name);

Expand Down Expand Up @@ -321,7 +334,7 @@ void TaskTransport::MoveFinishedCallback2(Task* task, UnitInfo* unit, char resul
AiLog log("Transport: dump client %s.",
transport->task_move->GetPassenger()
? UnitsManager_BaseUnits[transport->task_move->GetPassenger()->unit_type].singular_name
: "null unit.");
: "null unit");

SmartPointer<Task> dump =
new (std::nothrow) TaskDump(transport, &*transport->task_move, &*transport->unit_transporter);
Expand Down
1 change: 1 addition & 0 deletions src/tasktransport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class TaskTransport : public Task {

ResourceID GetTransporterType() const;
bool WillTransportNewClient(TaskMove* task);
bool IsClient(TaskMove* move);
void AddClient(TaskMove* move);
};

Expand Down

0 comments on commit eb2add0

Please sign in to comment.