Skip to content

Commit

Permalink
Fixes indexing of various Overlapper related loops.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsons26 authored and OmniBlade committed Nov 11, 2022
1 parent 837c554 commit c1fbbef
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 30 deletions.
2 changes: 1 addition & 1 deletion redalert/cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ void CellClass::Wall_Update(void)
** Build the icon number according to walls located in the adjacent
** cells.
*/
for (unsigned i = 0; i < 4; i++) {
for (unsigned i = 0; i < (sizeof(_offsets) / sizeof(_offsets[0]) - 1); i++) {
CellClass* adjcell = newcell->Adjacent_Cell(_offsets[i]);
if (adjcell && adjcell->Overlay == newcell->Overlay) {
icon |= 1 << i;
Expand Down
2 changes: 1 addition & 1 deletion redalert/radar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ void RadarClass::Draw_It(bool forced)
*=========================================================================*/
void RadarClass::Render_Terrain(CELL cell, int x, int y, int size)
{
TerrainClass* list[4] = {0, 0, 0, 0};
TerrainClass* list[ARRAY_SIZE(Map[(CELL)0].Overlapper) + 1] = {};
int listidx = 0;
int lp, lp2;

Expand Down
16 changes: 9 additions & 7 deletions tiberiandawn/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,7 @@ bool BaseClass::Is_Built(int index)
*=============================================================================================*/
BuildingClass* BaseClass::Get_Building(int index)
{
BuildingClass* bldg;
ObjectClass* obj[4];
ObjectClass* obj[1 + ARRAY_SIZE(Map[(CELL)0].Overlapper)];

/*
** Check the location on the map where this building should be; if it's
Expand All @@ -386,12 +385,15 @@ BuildingClass* BaseClass::Get_Building(int index)
CELL cell = Coord_Cell(Nodes[index].Coord);

obj[0] = Map[cell].Cell_Building();
obj[1] = Map[cell].Overlapper[0];
obj[2] = Map[cell].Overlapper[1];
obj[3] = Map[cell].Overlapper[2];
int count = 1;
for (int xindex = 0; xindex < ARRAY_SIZE(Map[cell].Overlapper); xindex++) {
if (Map[cell].Overlapper[xindex] != NULL) {
obj[count++] = Map[cell].Overlapper[xindex];
}
}

bldg = NULL;
for (int i = 0; i < 4; i++) {
BuildingClass* bldg = NULL;
for (int i = 0; i < count; i++) {
if (obj[i] && obj[i]->Coord == Nodes[index].Coord && obj[i]->What_Am_I() == RTTI_BUILDING
&& ((BuildingClass*)obj[i])->Class->Type == Nodes[index].Type) {

Expand Down
2 changes: 1 addition & 1 deletion tiberiandawn/cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,7 @@ void CellClass::Wall_Update(void)
** Build the icon number according to walls located in the adjacent
** cells.
*/
for (unsigned i = 0; i < 4; i++) {
for (unsigned i = 0; i < (sizeof(_offsets) / sizeof(_offsets[0]) - 1); i++) {
CellClass* adjcell = newcell->Adjacent_Cell(_offsets[i]);
if (adjcell && adjcell->Overlay == newcell->Overlay) {
icon |= 1 << i;
Expand Down
26 changes: 10 additions & 16 deletions tiberiandawn/iomap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@
*=============================================================================================*/
bool CellClass::Should_Save(void) const
{
void* _null_array[ARRAY_SIZE(Overlapper)] = {};

return ((Smudge != SMUDGE_NONE) || (TType != TEMPLATE_NONE) || (Overlay != OVERLAY_NONE) || IsMapped || IsVisible
|| IsMappedByPlayerMask || IsVisibleByPlayerMask || IsTrigger || Flag.Composite || OccupierPtr
|| Overlapper[0] || Overlapper[1] || Overlapper[2]);
|| memcmp(Overlapper, _null_array, sizeof(Overlapper)) != 0);
}

/***********************************************************************************************
Expand Down Expand Up @@ -221,7 +223,7 @@ void CellClass::Decode_Pointers(void)
{
char bad[128];

if (OccupierPtr) {
if (OccupierPtr != NULL) {
OccupierPtr = As_Object(TARGET_SAFE_CAST(OccupierPtr), false);
Check_Ptr((void*)OccupierPtr, __FILE__, __LINE__);

Expand All @@ -238,25 +240,17 @@ void CellClass::Decode_Pointers(void)
}
}

if (Overlapper[0]) {
Overlapper[0] = As_Object(TARGET_SAFE_CAST(Overlapper[0]), false);
Check_Ptr((void*)Overlapper[0], __FILE__, __LINE__);
}

if (Overlapper[1]) {
Overlapper[1] = As_Object(TARGET_SAFE_CAST(Overlapper[1]), false);
Check_Ptr((void*)Overlapper[1], __FILE__, __LINE__);
}

if (Overlapper[2]) {
Overlapper[2] = As_Object(TARGET_SAFE_CAST(Overlapper[2]), false);
Check_Ptr((void*)Overlapper[2], __FILE__, __LINE__);
for (int index = 0; index < ARRAY_SIZE(Overlapper); index++) {
if (Overlapper[index] != NULL) {
Overlapper[index] = As_Object(TARGET_SAFE_CAST(Overlapper[index]), false);
Check_Ptr((void*)Overlapper[index], __FILE__, __LINE__);
}
}

/*
** Check for bad overlappers that were saved. ST - 10/3/2019 11:50AM
*/
for (int i = 0; i <= 2; i++) {
for (int i = 0; i < ARRAY_SIZE(Overlapper); i++) {
if (Overlapper[i]) {
ObjectClass* optr = Overlapper[i];
if (optr->IsActive == false) {
Expand Down
4 changes: 2 additions & 2 deletions tiberiandawn/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1695,7 +1695,7 @@ int MapClass::Validate(void)
/*.....................................................................
Validate Overlappers
.....................................................................*/
for (i = 0; i < 3; i++) {
for (i = 0; i < ARRAY_SIZE((*this)[cell].CellClass::Overlapper); i++) {
obj = (*this)[cell].Overlapper[i];
if (obj) {

Expand Down Expand Up @@ -1762,7 +1762,7 @@ void MapClass::Clean(void)
/*.....................................................................
Validate Overlappers
.....................................................................*/
for (i = 0; i < 3; i++) {
for (i = 0; i < ARRAY_SIZE((*this)[cell].Overlapper); i++) {
obj = (*this)[cell].Overlapper[i];
if (obj) {

Expand Down
4 changes: 2 additions & 2 deletions tiberiandawn/radar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ void RadarClass::Draw_It(bool forced)
*=========================================================================*/
void RadarClass::Render_Terrain(CELL cell, int x, int y, int size)
{
TerrainClass* list[4];
TerrainClass* list[ARRAY_SIZE(Map[(CELL)0].Overlapper) + 1] = {};
int listidx = 0;
int lp, lp2;

Expand All @@ -513,7 +513,7 @@ void RadarClass::Render_Terrain(CELL cell, int x, int y, int size)
** Now loop through all the occupiers and add them to the list if they
** are terrain type.
*/
for (lp = 0; lp < 3; lp++) {
for (lp = 0; lp < ARRAY_SIZE(Map[cell].Overlapper); lp++) {
obj = Map[cell].Overlapper[lp];
if (obj && obj->IsActive && obj->What_Am_I() == RTTI_TERRAIN)
list[listidx++] = (TerrainClass*)obj;
Expand Down

0 comments on commit c1fbbef

Please sign in to comment.