From 8b8012a7082861663fea62d9f229fd5e295473f8 Mon Sep 17 00:00:00 2001 From: klei1984 <53688147+klei1984@users.noreply.github.com> Date: Sat, 30 Sep 2023 18:48:07 +0200 Subject: [PATCH] Refactored various interfaces. --- src/access.cpp | 13 ++---- src/access.hpp | 4 +- src/game_manager.cpp | 101 ++++++++++++++++++++--------------------- src/helpmenu.cpp | 4 +- src/paths.cpp | 2 +- src/taskassistmove.cpp | 2 +- src/taskclearzone.cpp | 4 +- src/taskmove.cpp | 2 +- src/tasktransport.cpp | 2 +- src/unitinfo.cpp | 6 +-- src/units_manager.cpp | 4 +- 11 files changed, 68 insertions(+), 76 deletions(-) diff --git a/src/access.cpp b/src/access.cpp index 79e3bf68..02ca160c 100644 --- a/src/access.cpp +++ b/src/access.cpp @@ -1517,7 +1517,7 @@ void Access_DestroyGroundCovers(int32_t grid_x, int32_t grid_y) { } } -UnitInfo* Access_GetUnit6(uint16_t team, int32_t grid_x, int32_t grid_y, uint32_t flags) { +UnitInfo* Access_GetEnemyUnit(uint16_t team, int32_t grid_x, int32_t grid_y, uint32_t flags) { UnitInfo* unit; unit = nullptr; @@ -1563,7 +1563,7 @@ UnitInfo* Access_GetUnit7(uint16_t team, int32_t grid_x, int32_t grid_y) { return unit; } -UnitInfo* Access_GetUnit4(int32_t grid_x, int32_t grid_y, uint16_t team, uint32_t flags) { +UnitInfo* Access_GetTeamUnit(int32_t grid_x, int32_t grid_y, uint16_t team, uint32_t flags) { SmartPointer unit; if (grid_x >= 0 && grid_x < ResourceManager_MapSize.x && grid_y >= 0 && grid_y < ResourceManager_MapSize.y) { @@ -1756,11 +1756,8 @@ bool Access_IsValidAttackTarget(UnitInfo* attacker, UnitInfo* target) { } UnitInfo* Access_GetAttackTarget(UnitInfo* unit, int32_t grid_x, int32_t grid_y, bool mode) { - UnitInfo* result; - bool normal_unit; - - result = nullptr; - normal_unit = false; + UnitInfo* result{nullptr}; + bool normal_unit{false}; if (grid_x >= 0 && grid_x < ResourceManager_MapSize.x && grid_y >= 0 && grid_y < ResourceManager_MapSize.y) { const auto units = Hash_MapHash[Point(grid_x, grid_y)]; @@ -1950,7 +1947,7 @@ void Access_MultiSelect(UnitInfo* unit, Rect* bounds) { for (int32_t y = selection.uly; y <= selection.lry && !limit_reached; ++y) { for (int32_t x = selection.ulx; x <= selection.lrx && !limit_reached; ++x) { UnitInfo* unit2 = - Access_GetUnit4(x, y, GameManager_PlayerTeam, MOBILE_AIR_UNIT | MOBILE_SEA_UNIT | MOBILE_LAND_UNIT); + Access_GetTeamUnit(x, y, GameManager_PlayerTeam, MOBILE_AIR_UNIT | MOBILE_SEA_UNIT | MOBILE_LAND_UNIT); if (unit2 && (unit2->state == ORDER_STATE_1 || unit2->state == ORDER_STATE_2)) { unit2->ClearUnitList(); diff --git a/src/access.hpp b/src/access.hpp index e291495d..ecddc91b 100644 --- a/src/access.hpp +++ b/src/access.hpp @@ -82,9 +82,9 @@ UnitInfo *Access_GetUnit5(int32_t grid_x, int32_t grid_y); UnitInfo *Access_GetUnit3(int32_t grid_x, int32_t grid_y, uint32_t flags); UnitInfo *Access_GetUnit1(int32_t grid_x, int32_t grid_y); UnitInfo *Access_GetUnit2(int32_t grid_x, int32_t grid_y, uint16_t team); -UnitInfo *Access_GetUnit6(uint16_t team, int32_t grid_x, int32_t grid_y, uint32_t flags); +UnitInfo *Access_GetEnemyUnit(uint16_t team, int32_t grid_x, int32_t grid_y, uint32_t flags); UnitInfo *Access_GetUnit7(uint16_t team, int32_t grid_x, int32_t grid_y); -UnitInfo *Access_GetUnit4(int32_t grid_x, int32_t grid_y, uint16_t team, uint32_t flags); +UnitInfo *Access_GetTeamUnit(int32_t grid_x, int32_t grid_y, uint16_t team, uint32_t flags); uint32_t Access_GetValidAttackTargetTypes(ResourceID unit_type); bool Access_IsValidAttackTargetType(ResourceID attacker, ResourceID target); bool Access_IsValidAttackTarget(ResourceID attacker, ResourceID target, Point point); diff --git a/src/game_manager.cpp b/src/game_manager.cpp index 04d0a868..62c6afce 100644 --- a/src/game_manager.cpp +++ b/src/game_manager.cpp @@ -433,7 +433,7 @@ SmartPointer GameManager_SelectedUnit; SmartPointer GameManager_TempTape; SmartPointer GameManager_UnknownUnit2; SmartPointer GameManager_UnknownUnit3; -SmartPointer GameManager_UnknownUnit4; +SmartPointer GameManager_UnitUnderMouseCursor; Image* GameManager_TurnTimerImageNormal; Image* GameManager_TurnTimerImageScaled; Point GameManager_GridCenter; @@ -4286,29 +4286,25 @@ bool GameManager_IsValidStartingPosition(int32_t grid_x, int32_t grid_y) { } uint8_t GameManager_GetWindowCursor(int32_t grid_x, int32_t grid_y) { - UnitInfo* unit1; - UnitInfo* unit2; + UnitInfo* team_unit = Access_GetTeamUnit(grid_x, grid_y, GameManager_PlayerTeam, SELECTABLE); + UnitInfo* unit_under_cursor = team_unit; - unit1 = Access_GetUnit4(grid_x, grid_y, GameManager_PlayerTeam, SELECTABLE); - - unit2 = unit1; - - if (!unit2) { - unit2 = Access_GetUnit6(GameManager_PlayerTeam, grid_x, grid_y, SELECTABLE); + if (!unit_under_cursor) { + unit_under_cursor = Access_GetEnemyUnit(GameManager_PlayerTeam, grid_x, grid_y, SELECTABLE); } - if (GameManager_UnknownUnit4 != unit2) { + if (GameManager_UnitUnderMouseCursor != unit_under_cursor) { char text[100]; text[0] = '\0'; - if (unit2) { - unit2->GetDisplayName(text); + if (unit_under_cursor) { + unit_under_cursor->GetDisplayName(text); } GameManager_DrawDisplayPanel(MENU_DISPLAY_CONTROL_UNIT_DESCRIPTION, text, 0xA2); - GameManager_UnknownUnit4 = unit2; + GameManager_UnitUnderMouseCursor = unit_under_cursor; } GameManager_MousePosition.x = grid_x; @@ -4318,7 +4314,7 @@ uint8_t GameManager_GetWindowCursor(int32_t grid_x, int32_t grid_y) { UnitsManager_TeamInfo[GameManager_ActiveTurnTeam].team_type != TEAM_TYPE_PLAYER) { uint8_t result; - if (unit1) { + if (team_unit) { result = CURSOR_FRIEND; } else { @@ -4383,15 +4379,15 @@ uint8_t GameManager_GetWindowCursor(int32_t grid_x, int32_t grid_y) { GameManager_SelectedUnit->team != GameManager_PlayerTeam) { uint8_t result; - if (GameManager_SelectedUnit != nullptr && GameManager_SelectedUnit == unit1 && + if (GameManager_SelectedUnit != nullptr && GameManager_SelectedUnit == team_unit && GameManager_SelectedUnit->orders != ORDER_DISABLE) { result = CURSOR_UNIT_NO_GO; - } else if (GameManager_SelectedUnit != nullptr && unit1 && GameManager_SelectedUnit->GetUnitList() && - GameManager_SelectedUnit->GetUnitList() == unit1->GetUnitList()) { + } else if (GameManager_SelectedUnit != nullptr && team_unit && GameManager_SelectedUnit->GetUnitList() && + GameManager_SelectedUnit->GetUnitList() == team_unit->GetUnitList()) { result = CURSOR_UNIT_NO_GO; - } else if (unit1) { + } else if (team_unit) { result = CURSOR_FRIEND; } else { @@ -4404,10 +4400,10 @@ uint8_t GameManager_GetWindowCursor(int32_t grid_x, int32_t grid_y) { if (Access_IsGroupOrderInterrupted(&*GameManager_SelectedUnit)) { uint8_t result; - if (unit1 && unit1->GetUnitList() == GameManager_SelectedUnit->GetUnitList()) { + if (team_unit && team_unit->GetUnitList() == GameManager_SelectedUnit->GetUnitList()) { result = CURSOR_UNIT_NO_GO; - } else if (unit1) { + } else if (team_unit) { result = CURSOR_FRIEND; } else { @@ -4420,17 +4416,17 @@ uint8_t GameManager_GetWindowCursor(int32_t grid_x, int32_t grid_y) { if ((GameManager_SelectedUnit->orders == ORDER_BUILD || GameManager_SelectedUnit->orders == ORDER_AWAIT_TAPE_POSITIONING) && (GameManager_SelectedUnit->flags & MOBILE_LAND_UNIT)) { - return GameManager_GetBuilderUnitCursor(&*GameManager_SelectedUnit, grid_x, grid_y, unit1); + return GameManager_GetBuilderUnitCursor(&*GameManager_SelectedUnit, grid_x, grid_y, team_unit); } if (GameManager_SelectedUnit->orders == ORDER_IDLE) { - return GameManager_GetAirUnitCursor(&*GameManager_SelectedUnit, grid_x, grid_y, unit1); + return GameManager_GetAirUnitCursor(&*GameManager_SelectedUnit, grid_x, grid_y, team_unit); } if (GameManager_SelectedUnit->state == ORDER_STATE_1) { UnitInfo* unit; - unit = Access_GetUnit6(GameManager_PlayerTeam, grid_x, grid_y, SELECTABLE); + unit = Access_GetEnemyUnit(GameManager_PlayerTeam, grid_x, grid_y, SELECTABLE); if (unit && unit->unit_type != CNCT_4W && (!(unit->flags & GROUND_COVER) || unit->unit_type == LANDMINE || unit->unit_type == SEAMINE)) { @@ -4438,7 +4434,7 @@ uint8_t GameManager_GetWindowCursor(int32_t grid_x, int32_t grid_y) { result = GameManager_GetMilitaryCursor(unit, grid_x, grid_y); - if (result != CURSOR_UNIT_NO_GO || !unit1) { + if (result != CURSOR_UNIT_NO_GO || !team_unit) { return result; } } @@ -4447,7 +4443,7 @@ uint8_t GameManager_GetWindowCursor(int32_t grid_x, int32_t grid_y) { if (GameManager_SelectedUnit->targeting_mode) { uint8_t result; - if (GameManager_SelectedUnit == unit1) { + if (GameManager_SelectedUnit == team_unit) { result = CURSOR_FRIEND; } else if (GameManager_SelectedUnit->shots == 0) { @@ -4457,17 +4453,18 @@ uint8_t GameManager_GetWindowCursor(int32_t grid_x, int32_t grid_y) { GameManager_SelectedUnit->GetBaseValues()->GetAttribute(ATTRIB_RANGE))) { result = CURSOR_UNIT_NO_GO; - } else if (unit1 && !Access_IsValidAttackTarget(&*GameManager_SelectedUnit, unit1, Point(grid_x, grid_y))) { + } else if (team_unit && + !Access_IsValidAttackTarget(&*GameManager_SelectedUnit, team_unit, Point(grid_x, grid_y))) { result = CURSOR_UNIT_NO_GO; } else { - unit2 = unit1; + unit_under_cursor = team_unit; - if (!unit2) { - unit2 = Access_GetUnit6(GameManager_PlayerTeam, grid_x, grid_y, SELECTABLE); + if (!unit_under_cursor) { + unit_under_cursor = Access_GetEnemyUnit(GameManager_PlayerTeam, grid_x, grid_y, SELECTABLE); } - Cursor_DrawAttackPowerCursor(&*GameManager_SelectedUnit, unit2, CURSOR_ENEMY); + Cursor_DrawAttackPowerCursor(&*GameManager_SelectedUnit, unit_under_cursor, CURSOR_ENEMY); result = CURSOR_ENEMY; } @@ -4478,7 +4475,7 @@ uint8_t GameManager_GetWindowCursor(int32_t grid_x, int32_t grid_y) { if (GameManager_SelectedUnit->enter_mode) { uint8_t result; - if (GameManager_SelectedUnit == unit1) { + if (GameManager_SelectedUnit == team_unit) { result = CURSOR_FRIEND; } else { @@ -4505,17 +4502,17 @@ uint8_t GameManager_GetWindowCursor(int32_t grid_x, int32_t grid_y) { GameManager_SelectedUnit->state == ORDER_STATE_1) { if (GameManager_SelectedUnit->storage < GameManager_SelectedUnit->GetBaseValues()->GetAttribute(ATTRIB_STORAGE)) { - GameManager_Unit = Access_GetUnit4(grid_x, grid_y, GameManager_PlayerTeam, MOBILE_LAND_UNIT); + GameManager_Unit = Access_GetTeamUnit(grid_x, grid_y, GameManager_PlayerTeam, MOBILE_LAND_UNIT); if (GameManager_Unit && GameManager_Unit->orders != ORDER_CLEAR && GameManager_Unit->orders != ORDER_BUILD && - !Access_GetUnit4(grid_x, grid_y, GameManager_PlayerTeam, MOBILE_AIR_UNIT)) { + !Access_GetTeamUnit(grid_x, grid_y, GameManager_PlayerTeam, MOBILE_AIR_UNIT)) { return CURSOR_LOAD; } } } - if (unit1 && unit1->unit_type != LANDPAD && !(unit1->flags & GROUND_COVER)) { + if (team_unit && team_unit->unit_type != LANDPAD && !(team_unit->flags & GROUND_COVER)) { result = CURSOR_FRIEND; } else if (GameManager_IsShiftKeyPressed) { @@ -4529,7 +4526,7 @@ uint8_t GameManager_GetWindowCursor(int32_t grid_x, int32_t grid_y) { case MOBILE_LAND_UNIT: case MOBILE_SEA_UNIT: case (MOBILE_SEA_UNIT | MOBILE_LAND_UNIT): { - result = GameManager_GetUnitActionCursor(&*GameManager_SelectedUnit, grid_x, grid_y, unit1); + result = GameManager_GetUnitActionCursor(&*GameManager_SelectedUnit, grid_x, grid_y, team_unit); } break; case STATIONARY: { @@ -4539,7 +4536,7 @@ uint8_t GameManager_GetWindowCursor(int32_t grid_x, int32_t grid_y) { switch (GameManager_SelectedUnit->unit_type) { case DEPOT: { GameManager_Unit = - Access_GetUnit4(grid_x, grid_y, GameManager_PlayerTeam, MOBILE_LAND_UNIT); + Access_GetTeamUnit(grid_x, grid_y, GameManager_PlayerTeam, MOBILE_LAND_UNIT); if (GameManager_Unit && Task_IsReadyToTakeOrders(GameManager_Unit) && GameManager_Unit->unit_type != COMMANDO && @@ -4550,7 +4547,7 @@ uint8_t GameManager_GetWindowCursor(int32_t grid_x, int32_t grid_y) { case HANGAR: { GameManager_Unit = - Access_GetUnit4(grid_x, grid_y, GameManager_PlayerTeam, MOBILE_AIR_UNIT); + Access_GetTeamUnit(grid_x, grid_y, GameManager_PlayerTeam, MOBILE_AIR_UNIT); if (GameManager_Unit && Task_IsReadyToTakeOrders(GameManager_Unit)) { return CURSOR_LOAD; @@ -4559,7 +4556,7 @@ uint8_t GameManager_GetWindowCursor(int32_t grid_x, int32_t grid_y) { case DOCK: { GameManager_Unit = - Access_GetUnit4(grid_x, grid_y, GameManager_PlayerTeam, MOBILE_SEA_UNIT); + Access_GetTeamUnit(grid_x, grid_y, GameManager_PlayerTeam, MOBILE_SEA_UNIT); if (GameManager_Unit && !(GameManager_Unit->flags & MOBILE_LAND_UNIT) && Task_IsReadyToTakeOrders(GameManager_Unit)) { @@ -4569,7 +4566,7 @@ uint8_t GameManager_GetWindowCursor(int32_t grid_x, int32_t grid_y) { case BARRACKS: { GameManager_Unit = - Access_GetUnit4(grid_x, grid_y, GameManager_PlayerTeam, MOBILE_LAND_UNIT); + Access_GetTeamUnit(grid_x, grid_y, GameManager_PlayerTeam, MOBILE_LAND_UNIT); if (GameManager_Unit && (GameManager_Unit->unit_type == COMMANDO || GameManager_Unit->unit_type == INFANTRY)) { @@ -4605,7 +4602,7 @@ uint8_t GameManager_GetWindowCursor(int32_t grid_x, int32_t grid_y) { } } - if (unit1) { + if (team_unit) { return CURSOR_FRIEND; } else { return CURSOR_UNIT_NO_GO; @@ -5919,7 +5916,7 @@ int32_t GameManager_GetUnitActionCursor(UnitInfo* unit1, int32_t grid_x, int32_t } else if (unit2) { if (unit1->cursor == CURSOR_ARROW_SW && unit1->storage < unit1->GetBaseValues()->GetAttribute(ATTRIB_STORAGE)) { - GameManager_Unit = Access_GetUnit4(grid_x, grid_y, GameManager_PlayerTeam, MOBILE_LAND_UNIT); + GameManager_Unit = Access_GetTeamUnit(grid_x, grid_y, GameManager_PlayerTeam, MOBILE_LAND_UNIT); if (GameManager_Unit && Task_IsReadyToTakeOrders(GameManager_Unit)) { if (unit1->unit_type == CLNTRANS && @@ -6094,24 +6091,22 @@ int32_t GameManager_GetMilitaryCursor(UnitInfo* unit, int32_t grid_x, int32_t gr } { - UnitInfo* target; - - target = Access_GetAttackTarget(&*GameManager_SelectedUnit, grid_x, grid_y); + UnitInfo* target = Access_GetAttackTarget(GameManager_SelectedUnit.Get(), grid_x, grid_y); if (target) { if (GameManager_SelectedUnit->unit_type == COMMANDO && GameManager_SelectedUnit->targeting_mode == 0) { - if (GameManager_IsUnitNextToPosition(&*GameManager_SelectedUnit, grid_x, grid_y) && + if (GameManager_IsUnitNextToPosition(GameManager_SelectedUnit.Get(), grid_x, grid_y) && GameManager_IsUnitNotInAir(target)) { if (GameManager_SelectedUnit->cursor == CURSOR_ARROW_NW || GameManager_SelectedUnit->cursor == CURSOR_HIDDEN) { - if (GameManager_IsValidDisableTarget(&*GameManager_SelectedUnit, target)) { + if (GameManager_IsValidDisableTarget(GameManager_SelectedUnit.Get(), target)) { return CURSOR_DISABLE; } } if (GameManager_SelectedUnit->cursor == CURSOR_ARROW_W || GameManager_SelectedUnit->cursor == CURSOR_HIDDEN) { - if (GameManager_IsValidStealTarget(&*GameManager_SelectedUnit, target)) { + if (GameManager_IsValidStealTarget(GameManager_SelectedUnit.Get(), target)) { return CURSOR_STEAL; } } @@ -6129,7 +6124,7 @@ int32_t GameManager_GetMilitaryCursor(UnitInfo* unit, int32_t grid_x, int32_t gr { int32_t result; - if (Access_IsWithinAttackRange(&*GameManager_SelectedUnit, grid_x, grid_y, + if (Access_IsWithinAttackRange(GameManager_SelectedUnit.Get(), grid_x, grid_y, GameManager_SelectedUnit->GetBaseValues()->GetAttribute(ATTRIB_RANGE))) { if (GameManager_SelectedUnit->ammo > 0) { result = CURSOR_ENEMY; @@ -6146,7 +6141,7 @@ int32_t GameManager_GetMilitaryCursor(UnitInfo* unit, int32_t grid_x, int32_t gr } if (result != CURSOR_UNIT_NO_GO) { - Cursor_DrawAttackPowerCursor(&*GameManager_SelectedUnit, target, result); + Cursor_DrawAttackPowerCursor(GameManager_SelectedUnit.Get(), target, result); } return result; @@ -6603,8 +6598,8 @@ void GameManager_ProcessInput() { } } else { - UnitInfo* unit = Access_GetUnit4(GameManager_MousePosition.x, GameManager_MousePosition.y, - GameManager_PlayerTeam, SELECTABLE); + UnitInfo* unit = Access_GetTeamUnit(GameManager_MousePosition.x, GameManager_MousePosition.y, + GameManager_PlayerTeam, SELECTABLE); if (GameManager_UnknownFlag3) { if (GameManager_MouseButtons & MOUSE_RELEASE_RIGHT) { @@ -6632,8 +6627,8 @@ void GameManager_ProcessInput() { } } else { - UnitInfo* unit2 = Access_GetUnit6(GameManager_PlayerTeam, GameManager_MousePosition.x, - GameManager_MousePosition.y, SELECTABLE); + UnitInfo* unit2 = Access_GetEnemyUnit(GameManager_PlayerTeam, GameManager_MousePosition.x, + GameManager_MousePosition.y, SELECTABLE); if (GameManager_MouseButtons & MOUSE_RELEASE_RIGHT) { GameManager_ManagePlayerAction(); diff --git a/src/helpmenu.cpp b/src/helpmenu.cpp index ab01b470..93f4f8fd 100644 --- a/src/helpmenu.cpp +++ b/src/helpmenu.cpp @@ -539,10 +539,10 @@ bool HelpMenu_UnitReport(int32_t mouse_x, int32_t mouse_y) { (GameManager_MapWindowDrawBounds.uly + ((Gfx_MapScalingFactor * (mouse_y - window->window.uly)) >> 16)) >> 6; - unit = Access_GetUnit4(mouse_x, mouse_y, GameManager_PlayerTeam, SELECTABLE); + unit = Access_GetTeamUnit(mouse_x, mouse_y, GameManager_PlayerTeam, SELECTABLE); if (!unit) { - unit = Access_GetUnit6(GameManager_PlayerTeam, mouse_x, mouse_y, SELECTABLE); + unit = Access_GetEnemyUnit(GameManager_PlayerTeam, mouse_x, mouse_y, SELECTABLE); } if (!unit) { diff --git a/src/paths.cpp b/src/paths.cpp index 870dface..196dbf11 100644 --- a/src/paths.cpp +++ b/src/paths.cpp @@ -1431,7 +1431,7 @@ void Paths_FinishMove(UnitInfo* unit) { if (!Paths_LoadUnit(unit)) { if (unit->unit_type == AIRTRANS && unit->GetParent()) { if (unit->storage < unit->GetBaseValues()->GetAttribute(ATTRIB_STORAGE)) { - if (unit->GetParent() == Access_GetUnit4(grid_x, grid_y, unit->team, MOBILE_LAND_UNIT)) { + if (unit->GetParent() == Access_GetTeamUnit(grid_x, grid_y, unit->team, MOBILE_LAND_UNIT)) { unit->orders = ORDER_LOAD; unit->state = ORDER_STATE_INIT; diff --git a/src/taskassistmove.cpp b/src/taskassistmove.cpp index c6e18379..40efecff 100644 --- a/src/taskassistmove.cpp +++ b/src/taskassistmove.cpp @@ -68,7 +68,7 @@ void TaskAssistMove::RequestTransport(UnitInfo* unit1, UnitInfo* unit2) { void TaskAssistMove::CompleteTransport(UnitInfo* unit1, UnitInfo* unit2, Point site) { if (GameManager_PlayMode != PLAY_MODE_TURN_BASED || GameManager_ActiveTurnTeam == team) { - if (Access_GetUnit4(site.x, site.y, team, MOBILE_SEA_UNIT | MOBILE_LAND_UNIT)) { + if (Access_GetTeamUnit(site.x, site.y, team, MOBILE_SEA_UNIT | MOBILE_LAND_UNIT)) { SmartPointer zone = new (std::nothrow) Zone(unit2, this); zone->Add(&site); diff --git a/src/taskclearzone.cpp b/src/taskclearzone.cpp index 0b7f4f73..0b98907b 100644 --- a/src/taskclearzone.cpp +++ b/src/taskclearzone.cpp @@ -237,7 +237,7 @@ bool TaskClearZone::ExamineZones() { info_map[site.x][site.y] |= 0x08; } - UnitInfo* unit = Access_GetUnit4(site.x, site.y, team, unit_flags); + UnitInfo* unit = Access_GetTeamUnit(site.x, site.y, team, unit_flags); if (unit && zone->unit != unit) { is_found = true; @@ -325,7 +325,7 @@ bool TaskClearZone::IsNewSite(Point site) { void TaskClearZone::EvaluateSite(ZoneSquare* zone_square, Point site) { if (Task_IsReadyToTakeOrders(zone_square->unit)) { - UnitInfo* unit = Access_GetUnit4(site.x, site.y, team, unit_flags); + UnitInfo* unit = Access_GetTeamUnit(site.x, site.y, team, unit_flags); if (unit) { if (unit->shots > 0 && Task_ShouldReserveShot(unit, site)) { diff --git a/src/taskmove.cpp b/src/taskmove.cpp index fb4b175f..42ac265c 100644 --- a/src/taskmove.cpp +++ b/src/taskmove.cpp @@ -651,7 +651,7 @@ void TaskMove::BlockedPathResultCallback(Task* task, PathRequest* path_request, local_zone->Add(&site); - unit = Access_GetUnit4(site.x, site.y, move->team, unit_flags); + unit = Access_GetTeamUnit(site.x, site.y, move->team, unit_flags); if (unit) { log.Log("Blocked by %s at [%i,%i].", UnitsManager_BaseUnits[unit->unit_type].singular_name, diff --git a/src/tasktransport.cpp b/src/tasktransport.cpp index a415d02a..f7d45005 100644 --- a/src/tasktransport.cpp +++ b/src/tasktransport.cpp @@ -765,7 +765,7 @@ void TaskTransport::UnloadUnit(UnitInfo* unit) { if (destination.x >= 0 && unit_transporter == unit->GetParent()) { UnitInfo* unit_in_the_way = - Access_GetUnit4(destination.x, destination.y, team, MOBILE_SEA_UNIT | MOBILE_LAND_UNIT); + Access_GetTeamUnit(destination.x, destination.y, team, MOBILE_SEA_UNIT | MOBILE_LAND_UNIT); if (unit_in_the_way) { SmartPointer zone = new (std::nothrow) Zone(unit, this); diff --git a/src/unitinfo.cpp b/src/unitinfo.cpp index 5893c87d..6996f7c7 100644 --- a/src/unitinfo.cpp +++ b/src/unitinfo.cpp @@ -1506,9 +1506,7 @@ void UnitInfo::TransferRaw(int32_t amount) { storage += amount; if (complex != nullptr) { - int32_t storage_capacity; - - storage_capacity = GetBaseValues()->GetAttribute(ATTRIB_STORAGE); + const int32_t storage_capacity = GetBaseValues()->GetAttribute(ATTRIB_STORAGE); complex->material += amount; @@ -3097,7 +3095,7 @@ void UnitInfo::Attack(int32_t grid_x, int32_t grid_y) { target->visible_to_team[team] = true; } else { - enemy = Access_GetUnit4(grid_x, grid_y, team, SELECTABLE); + enemy = Access_GetTeamUnit(grid_x, grid_y, team, SELECTABLE); if (!enemy && unit_type != ANTIAIR && unit_type != SP_FLAK && unit_type != FASTBOAT) { SmartPointer explosion = diff --git a/src/units_manager.cpp b/src/units_manager.cpp index 68afb47a..1ce04c71 100644 --- a/src/units_manager.cpp +++ b/src/units_manager.cpp @@ -5649,7 +5649,7 @@ void UnitsManager_BuildClearing(UnitInfo* unit, bool mode) { if (unit_type == LANDMINE || unit_type == SEAMINE) { SmartPointer target_unit( - Access_GetUnit6(unit_team, unit_grid_x, unit_grid_y, (MOBILE_SEA_UNIT | MOBILE_LAND_UNIT))); + Access_GetEnemyUnit(unit_team, unit_grid_x, unit_grid_y, (MOBILE_SEA_UNIT | MOBILE_LAND_UNIT))); if (!target_unit) { target_unit = Access_GetAttackTarget2(unit, unit_grid_x, unit_grid_y); @@ -6194,6 +6194,8 @@ void UnitsManager_Transfer(UnitInfo* unit) { source->storage -= transfer_amount; } else { + SDL_assert(source->GetComplex()); + transfer_amount -= source->storage; source->storage = 0;