diff --git a/src/taskreload.cpp b/src/taskreload.cpp index 3630df46..d444733c 100644 --- a/src/taskreload.cpp +++ b/src/taskreload.cpp @@ -22,6 +22,7 @@ #include "taskreload.hpp" #include "access.hpp" +#include "ailog.hpp" #include "task_manager.hpp" #include "units_manager.hpp" @@ -32,7 +33,7 @@ TaskReload::~TaskReload() {} int TaskReload::GetMemoryUse() const { return 4; } char* TaskReload::WriteStatusLog(char* buffer) const { - strcpy(buffer, "Reload unit with ammunition"); + strcpy(buffer, "Reload unit with ammunition."); return buffer; } @@ -140,6 +141,9 @@ void TaskReload::CreateUnit() { } void TaskReload::IssueOrder() { + AiLog log("Reloading %s from %s.", UnitsManager_BaseUnits[target_unit->unit_type].singular_name, + UnitsManager_BaseUnits[operator_unit->unit_type].singular_name); + operator_unit->SetParent(&*target_unit); UnitsManager_SetNewOrder(&*operator_unit, ORDER_RELOAD, ORDER_STATE_0); } diff --git a/src/taskrepair.cpp b/src/taskrepair.cpp index 70f9fab5..295c9288 100644 --- a/src/taskrepair.cpp +++ b/src/taskrepair.cpp @@ -22,6 +22,7 @@ #include "taskrepair.hpp" #include "access.hpp" +#include "ailog.hpp" #include "aiplayer.hpp" #include "game_manager.hpp" #include "pathrequest.hpp" @@ -43,6 +44,8 @@ void TaskRepair::ChooseUnitToRepair() { if (target_unit != nullptr) { operator_unit = nullptr; + AiLog log("Choose unit to repair %s.", UnitsManager_BaseUnits[target_unit->unit_type].singular_name); + unit = SelectRepairShop(); SelectOperator(); @@ -65,6 +68,8 @@ void TaskRepair::ChooseUnitToRepair() { } if (operator_unit != nullptr) { + log.Log("Found %s.", UnitsManager_BaseUnits[operator_unit->unit_type].singular_name); + operator_unit->AddTask(this); } } @@ -75,6 +80,9 @@ void TaskRepair::DoRepairs() { !(operator_unit->flags & (MOBILE_AIR_UNIT || MOBILE_SEA_UNIT || MOBILE_LAND_UNIT))) { if (GameManager_PlayMode != PLAY_MODE_UNKNOWN && (GameManager_PlayMode != PLAY_MODE_TURN_BASED || team == GameManager_ActiveTurnTeam)) { + AiLog log("Repair/reload %s: perform repair.", + UnitsManager_BaseUnits[target_unit->unit_type].singular_name); + if (operator_unit->flags & STATIONARY) { Cargo materials; Cargo capacity; @@ -85,6 +93,9 @@ void TaskRepair::DoRepairs() { if (Task_IsReadyToTakeOrders(&*operator_unit)) { IssueOrder(); } + + } else { + log.Log("%s has no material.", UnitsManager_BaseUnits[operator_unit->unit_type].singular_name); } } else if (operator_unit->storage > 0) { @@ -139,6 +150,8 @@ void TaskRepair::RemoveMovementTasks() { } void TaskRepair::RendezvousResultCallback(Task* task, UnitInfo* unit, char result) { + AiLog log("Repair: rendezvous result."); + if (result == 2) { dynamic_cast(task)->RemoveMovementTasks(); @@ -236,6 +249,8 @@ Rect* TaskRepair::GetBounds(Rect* bounds) { unsigned char TaskRepair::GetType() const { return TaskType_TaskRepair; } void TaskRepair::Begin() { + AiLog log("Begin repair/reload/upgrade unit."); + target_unit->AddTask(this); CreateUnit(); ChooseUnitToRepair(); @@ -254,6 +269,8 @@ bool TaskRepair::Execute(UnitInfo& unit) { bool result; if (target_unit == unit && target_unit->GetTask() == this) { + AiLog log("Repair/reload %s move unit.", UnitsManager_BaseUnits[target_unit->unit_type].singular_name); + if (IsInPerfectCondition()) { SmartPointer task; @@ -295,6 +312,9 @@ bool TaskRepair::Execute(UnitInfo& unit) { } else { if (target_unit->state == ORDER_STATE_3) { if (GameManager_PlayMode != PLAY_MODE_TURN_BASED || team == GameManager_ActiveTurnTeam) { + log.Log("%s is inside %s.", UnitsManager_BaseUnits[target_unit->unit_type].singular_name, + UnitsManager_BaseUnits[operator_unit->unit_type].singular_name); + DoRepairs(); } @@ -304,6 +324,8 @@ bool TaskRepair::Execute(UnitInfo& unit) { if ((operator_unit->flags & STATIONARY) || operator_unit->storage > 0 || operator_unit->GetTask() != this) { if (Task_IsAdjacent(&*operator_unit, target_unit->grid_x, target_unit->grid_y)) { + log.Log("Adjacent to %s.", UnitsManager_BaseUnits[operator_unit->unit_type].singular_name); + if (GameManager_PlayMode != PLAY_MODE_UNKNOWN && (GameManager_PlayMode != PLAY_MODE_TURN_BASED || team == GameManager_ActiveTurnTeam)) { if (operator_unit->flags & STATIONARY) { @@ -318,6 +340,8 @@ bool TaskRepair::Execute(UnitInfo& unit) { // only enter repair shop if there is free capacity in it, // and raw materials are available in the complex if (materials.raw > 0 && stored_units < storable_units) { + log.Log("Sending Board order."); + target_unit->target_grid_x = operator_unit->grid_x; target_unit->target_grid_y = operator_unit->grid_y; @@ -392,6 +416,9 @@ void TaskRepair::RemoveSelf() { } void TaskRepair::RemoveUnit(UnitInfo& unit) { + AiLog log("Repair %s: remove %s.", UnitsManager_BaseUnits[target_unit->unit_type].singular_name, + UnitsManager_BaseUnits[unit.unit_type].singular_name); + if (target_unit == unit) { SmartPointer task(this); @@ -476,6 +503,8 @@ void TaskRepair::CreateUnit() { } void TaskRepair::IssueOrder() { + AiLog log("Sending repair order."); + operator_unit->SetParent(&*target_unit); if (target_unit->hits < target_unit->GetBaseValues()->GetAttribute(ATTRIB_HITS)) { diff --git a/src/taskupgrade.cpp b/src/taskupgrade.cpp index 721014f7..c1158563 100644 --- a/src/taskupgrade.cpp +++ b/src/taskupgrade.cpp @@ -21,6 +21,7 @@ #include "taskupgrade.hpp" +#include "ailog.hpp" #include "aiplayer.hpp" #include "units_manager.hpp" @@ -31,7 +32,7 @@ TaskUpgrade::~TaskUpgrade() {} int TaskUpgrade::GetMemoryUse() const { return 4; } char* TaskUpgrade::WriteStatusLog(char* buffer) const { - strcpy(buffer, "Upgrade unit"); + strcpy(buffer, "Upgrade unit."); return buffer; } @@ -82,6 +83,8 @@ void TaskUpgrade::CreateUnit() { } void TaskUpgrade::IssueOrder() { + AiLog log("Upgrading %s.", UnitsManager_BaseUnits[target_unit->unit_type].singular_name); + operator_unit->SetParent(&*target_unit); if (AiPlayer_Teams[team].ShouldUpgradeUnit(&*target_unit)) {