Skip to content

Commit

Permalink
Support arbitrary map dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
klei1984 committed Jul 9, 2024
1 parent 834fc2d commit 9f8db49
Show file tree
Hide file tree
Showing 25 changed files with 1,251 additions and 840 deletions.
40 changes: 23 additions & 17 deletions src/access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,21 +317,19 @@ void Access_InitUnitStealthStatus(SmartList<UnitInfo>& units) {
}

void Access_InitStealthMaps() {
int32_t heat_map_size;
const uint32_t map_cell_count{static_cast<uint32_t>(ResourceManager_MapSize.x * ResourceManager_MapSize.y)};

Access_InitUnitStealthStatus(UnitsManager_GroundCoverUnits);
Access_InitUnitStealthStatus(UnitsManager_MobileLandSeaUnits);
Access_InitUnitStealthStatus(UnitsManager_MobileAirUnits);
Access_InitUnitStealthStatus(UnitsManager_ParticleUnits);
Access_InitUnitStealthStatus(UnitsManager_StationaryUnits);

heat_map_size = ResourceManager_MapSize.x * ResourceManager_MapSize.y;

for (int32_t team = PLAYER_TEAM_RED; team < PLAYER_TEAM_MAX - 1; ++team) {
if (UnitsManager_TeamInfo[team].team_type != TEAM_TYPE_NONE) {
memset(UnitsManager_TeamInfo[team].heat_map_complete, 0, heat_map_size);
memset(UnitsManager_TeamInfo[team].heat_map_stealth_sea, 0, heat_map_size);
memset(UnitsManager_TeamInfo[team].heat_map_stealth_land, 0, heat_map_size);
memset(UnitsManager_TeamInfo[team].heat_map_complete, 0, map_cell_count);
memset(UnitsManager_TeamInfo[team].heat_map_stealth_sea, 0, map_cell_count);
memset(UnitsManager_TeamInfo[team].heat_map_stealth_land, 0, map_cell_count);
}
}
}
Expand Down Expand Up @@ -557,11 +555,13 @@ uint32_t Access_UpdateMapStatusAddUnit(UnitInfo* unit, int32_t grid_x, int32_t g
}
}

if (++UnitsManager_TeamInfo[team].heat_map_complete[map_offset] == 1) {
++UnitsManager_TeamInfo[team].heat_map_complete[map_offset];

if (UnitsManager_TeamInfo[team].heat_map_complete[map_offset] == 1) {
Ai_SetInfoMapPoint(Point(grid_x, grid_y), team);

if (team == GameManager_PlayerTeam) {
ResourceManager_Minimap[map_offset] = ResourceManager_MinimapFov[map_offset];
ResourceManager_MinimapFov[map_offset] = ResourceManager_Minimap[map_offset];
}

const auto units = Hash_MapHash[Point(grid_x, grid_y)];
Expand Down Expand Up @@ -598,12 +598,18 @@ void Access_UpdateMapStatusRemoveUnit(UnitInfo* unit, int32_t grid_x, int32_t gr
--UnitsManager_TeamInfo[team].heat_map_stealth_land[map_offset];
}

if (!--UnitsManager_TeamInfo[team].heat_map_complete[map_offset]) {
--UnitsManager_TeamInfo[team].heat_map_complete[map_offset];

SDL_assert(UnitsManager_TeamInfo[team].heat_map_complete[map_offset] >= 0);
SDL_assert(UnitsManager_TeamInfo[team].heat_map_stealth_land[map_offset] >= 0);
SDL_assert(UnitsManager_TeamInfo[team].heat_map_stealth_sea[map_offset] >= 0);

if (0 == UnitsManager_TeamInfo[team].heat_map_complete[map_offset]) {
Ai_UpdateMineMap(Point(grid_x, grid_y), team);

if (team == GameManager_PlayerTeam) {
ResourceManager_Minimap[map_offset] =
ResourceManager_ColorIndexTable12[ResourceManager_MinimapFov[map_offset]];
ResourceManager_MinimapFov[map_offset] =
ResourceManager_ColorIndexTable12[ResourceManager_Minimap[map_offset]];
}

const auto units = Hash_MapHash[Point(grid_x, grid_y)];
Expand All @@ -628,7 +634,7 @@ void Access_UpdateMapStatusRemoveUnit(UnitInfo* unit, int32_t grid_x, int32_t gr
}

void Access_DrawUnit(UnitInfo* unit) {
int32_t map_offset;
const int32_t map_offset{ResourceManager_MapSize.x * unit->grid_y + unit->grid_x};

if (GameManager_AllVisible) {
for (int32_t team = PLAYER_TEAM_RED; team < PLAYER_TEAM_MAX - 1; ++team) {
Expand All @@ -638,8 +644,6 @@ void Access_DrawUnit(UnitInfo* unit) {
}
}

map_offset = ResourceManager_MapSize.x * unit->grid_y + unit->grid_x;

for (int32_t team = PLAYER_TEAM_RED; team < PLAYER_TEAM_MAX - 1; ++team) {
if (UnitsManager_TeamInfo[team].team_type != TEAM_TYPE_NONE) {
if (UnitsManager_TeamInfo[team].heat_map_stealth_sea[map_offset] && UnitsManager_IsUnitUnderWater(unit)) {
Expand Down Expand Up @@ -833,12 +837,14 @@ void Access_UpdateVisibilityStatus(bool all_visible) {
}

void Access_UpdateMinimapFogOfWar(uint16_t team, bool all_visible, bool ignore_team_heat_map) {
memcpy(ResourceManager_Minimap, ResourceManager_MinimapFov, 112 * 112);
const uint32_t map_cell_count{static_cast<uint32_t>(ResourceManager_MapSize.x * ResourceManager_MapSize.y)};

memcpy(ResourceManager_MinimapFov, ResourceManager_Minimap, map_cell_count);

if (!all_visible) {
for (int32_t i = 0; i < 112 * 112; ++i) {
for (uint32_t i = 0; i < map_cell_count; ++i) {
if (UnitsManager_TeamInfo[team].heat_map_complete[i] == 0 || ignore_team_heat_map) {
ResourceManager_Minimap[i] = ResourceManager_ColorIndexTable12[ResourceManager_Minimap[i]];
ResourceManager_MinimapFov[i] = ResourceManager_ColorIndexTable12[ResourceManager_MinimapFov[i]];
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/ctinfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct ScreenLocation {
};

struct CTInfo {
CTInfo() { Reset(); }
CTInfo() : heat_map_complete(nullptr), heat_map_stealth_sea(nullptr), heat_map_stealth_land(nullptr) { Reset(); }

void Reset() noexcept {
for (auto& marker : markers) {
Expand Down Expand Up @@ -66,8 +66,11 @@ struct CTInfo {

team_units = nullptr;
selected_unit = nullptr;

zoom_level = 0;

camera_position = {0, 0};

display_button_range = 0;
display_button_scan = 0;
display_button_status = 0;
Expand All @@ -79,6 +82,7 @@ struct CTInfo {
display_button_minimap_tnt = 0;
display_button_grid = 0;
display_button_survey = 0;

stats_factories_built = 0;
stats_mines_built = 0;
stats_buildings_built = 0;
Expand All @@ -93,8 +97,13 @@ struct CTInfo {
casualty = 0;
}

delete[] heat_map_complete;
heat_map_complete = nullptr;

delete[] heat_map_stealth_sea;
heat_map_stealth_sea = nullptr;

delete[] heat_map_stealth_land;
heat_map_stealth_land = nullptr;
}

Expand Down
29 changes: 23 additions & 6 deletions src/drawloadbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,35 @@ DrawLoadBar::DrawLoadBar(const char* text) : Window(DIALGPIC, GameManager_GetDia
DrawLoadBar::~DrawLoadBar() { delete loadbar; }

void DrawLoadBar::SetValue(int16_t value) {
int16_t length;

loadbar->SetValue(value);
loadbar->RefreshScreen();

length = 112 * value / 75;
if (value <= 80) {
int32_t length = ResourceManager_MapSize.y * value / 75;

if (length > ResourceManager_MapSize.y) {
length = ResourceManager_MapSize.y;
}

const int32_t window_width{window.window.lrx - window.window.ulx + 1 - 76};
const int32_t window_height{window.window.lry - window.window.uly + 1 - 99};

if (ResourceManager_MapSize.x == window_width && ResourceManager_MapSize.y == window_height) {
buf_to_buf(ResourceManager_MinimapFov, ResourceManager_MapSize.x, length, ResourceManager_MapSize.x,
&window.buffer[window.width * 21 + 37], window.width);

} else {
int32_t output_length = window_height * value / 75;

if (output_length > window_height) {
output_length = window_height;
}

if (length > 112) {
length = 112;
cscale(ResourceManager_MinimapFov, ResourceManager_MapSize.x, length, ResourceManager_MapSize.x,
&window.buffer[window.width * 21 + 37], window_width, output_length, window.width);
}
}

buf_to_buf(ResourceManager_Minimap, 112, length, 112, &window.buffer[window.width * 21 + 37], window.width);
win_draw_rect(window.id, &window.window);
process_bk();
}
Loading

0 comments on commit 9f8db49

Please sign in to comment.