diff --git a/MVES/Classes/MapHistory.uc b/MVES/Classes/MapHistory.uc index ca4ae2d..a05b8fe 100644 --- a/MVES/Classes/MapHistory.uc +++ b/MVES/Classes/MapHistory.uc @@ -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); } @@ -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 { @@ -58,6 +58,10 @@ function PopList( int idx ) { Elements[i] = Elements[i + 1]; } + if ( ElementCount < 0 ) + { + ElementCount = 0; + } Elements[ElementCount] = DefaultMapElement; } @@ -67,7 +71,7 @@ function PushList( int idx ) for ( i = ElementCount; i > idx; i -= 1 ) { Elements[i] = Elements[i - 1]; - i -- ; + i--; } ElementCount += 1; } diff --git a/TestMVE/Classes/TestMapHistory.uc b/TestMVE/Classes/TestMapHistory.uc index 2f03942..02a3eab 100644 --- a/TestMVE/Classes/TestMapHistory.uc +++ b/TestMVE/Classes/TestMapHistory.uc @@ -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)