Skip to content

Commit

Permalink
Refactored various interfaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
klei1984 committed Sep 30, 2023
1 parent 6e3b81b commit 8b8012a
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 76 deletions.
13 changes: 5 additions & 8 deletions src/access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<UnitInfo> unit;

if (grid_x >= 0 && grid_x < ResourceManager_MapSize.x && grid_y >= 0 && grid_y < ResourceManager_MapSize.y) {
Expand Down Expand Up @@ -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)];
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/access.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
101 changes: 48 additions & 53 deletions src/game_manager.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/helpmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/paths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/taskassistmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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> zone = new (std::nothrow) Zone(unit2, this);

zone->Add(&site);
Expand Down
4 changes: 2 additions & 2 deletions src/taskclearzone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/taskmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/tasktransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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> zone = new (std::nothrow) Zone(unit, this);
Expand Down
6 changes: 2 additions & 4 deletions src/unitinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<UnitInfo> explosion =
Expand Down
4 changes: 3 additions & 1 deletion src/units_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5649,7 +5649,7 @@ void UnitsManager_BuildClearing(UnitInfo* unit, bool mode) {

if (unit_type == LANDMINE || unit_type == SEAMINE) {
SmartPointer<UnitInfo> 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);
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 8b8012a

Please sign in to comment.