Skip to content

Commit

Permalink
Fix element count cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
peterekepeter committed Mar 14, 2024
1 parent 794f3dd commit df2908a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 7 additions & 3 deletions MVES/Classes/MapHistory.uc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function NewMapPlayed(MV_Result r, int MapCostAddPerLoad)

for ( i = 0 ; i < ElementCount ; i += 1 )
{
while ( --Elements[i].Acc <= 0 )
while ( --Elements[i].Acc <= 0 && i < ElementCount )
{
PopList(i);
}
Expand All @@ -36,7 +36,7 @@ function NewMapPlayed(MV_Result r, int MapCostAddPerLoad)
if ( i < ElementCount && Elements[i].Map == r.Map )
{
// update existing
Elements[i].Acc += MapCostAddPerLoad + 1;
Elements[i].Acc += MapCostAddPerLoad;
}
else
{
Expand All @@ -58,6 +58,10 @@ function PopList( int idx )
{
Elements[i] = Elements[i + 1];
}
if ( ElementCount < 0 )
{
ElementCount = 0;
}
Elements[ElementCount] = DefaultMapElement;
}

Expand All @@ -67,7 +71,7 @@ function PushList( int idx )
for ( i = ElementCount; i > idx; i -= 1 )
{
Elements[i] = Elements[i - 1];
i -- ;
i--;
}
ElementCount += 1;
}
Expand Down
9 changes: 9 additions & 0 deletions TestMVE/Classes/TestMapHistory.uc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ function TestMain()
AssertNotExcluded("DM-Deck16][", "can still be played");
MapPlayed("DM-Deck16][");
AssertExcluded("DM-Deck16][", "cannot be played anymore");

Describe("Does not fail when CostAdd is 0");
CostAdd = 0;
MaxCost = 3;
MapPlayed("DM-Deck16][");
MapPlayed("DM-Fractal");
AssertNotExcluded("DM-Deck16][", "both maps can still be played");
AssertNotExcluded("DM-Fractal", "both maps can still be played");

}

function MapPlayed(optional string map, optional string game, optional string rule)
Expand Down

0 comments on commit df2908a

Please sign in to comment.