TacoServer/Classic/scripts/autoexec/MapRepetitionChecker.cs

119 lines
3 KiB
C#
Raw Normal View History

// Map Repetition Checker Script
//
// To help decrease the chances of a repeated map in the map rotation by correcting repeated maps thru script
2019-02-20 17:59:45 -05:00
//
// Runs at the beginning of every map change
2019-12-12 23:32:45 -05:00
// Keeps track of maps played (Last [$MRC::PastMapsDepth] Maps)
// If any are repeating it picks a new map
//
// $EvoCachedNextMission = "RoundTheMountain";
// $EvoCachedNextMission = "Arrakis";
// $EvoCachedNextMission = "RoundTheMountainLT";
// $EvoCachedNextMission = "ArenaDomeDM";
2019-12-12 23:32:45 -05:00
// How many previous maps you want to compare TheNextCached Map to
$MRC::PastMapsDepth = 6;
2019-12-12 23:32:45 -05:00
for(%x = 1; %x <= $MRC::PastMapsDepth; %x++)
{
$MRC::PrevMap[%x] = "";
//echo("PM" @ %x @ ": " @ $MRC::PrevMap[%x]);
}
//Ran in MissionTypeOptions.cs
2019-02-17 18:58:19 -05:00
function MapRepetitionChecker( %game )
{
//Debug
2019-12-13 00:23:14 -05:00
//%MapRepetitionCheckerDebug = true;
2019-12-12 23:32:45 -05:00
if(isEventPending($MapRepetitionSchedule))
cancel($MapRepetitionSchedule);
//Make sure GetRandomMaps.cs is present
if(!$GetRandomMapsLoaded)
return;
2019-12-04 00:23:29 -05:00
if($EvoCachedNextMission $= "")
return;
if(!$Host::TournamentMode && $Host::EnableMapRepetitionChecker)
{
2019-12-12 23:32:45 -05:00
//Do work
for(%x = 1; %x <= $MRC::PastMapsDepth; %x++)
{
if( $MRC::PrevMap[%x] !$= "" && $MRC::PrevMap[%x] $= $EvoCachedNextMission || $CurrentMission $= $EvoCachedNextMission )
2019-12-12 23:32:45 -05:00
MapRepetitionCheckerFindRandom();
}
//Set vars
2019-12-12 23:32:45 -05:00
for(%x = $MRC::PastMapsDepth; %x >= 1; %x = %x - 1)
{
if(%x > 1)
{
if($MRC::PrevMap[%x - 1] !$= "")
$MRC::PrevMap[%x] = $MRC::PrevMap[%x - 1];
}
else if(%x $= 1)
$MRC::PrevMap[%x] = $CurrentMission;
}
//Debug
if(%MapRepetitionCheckerDebug)
2019-12-12 23:32:45 -05:00
{
for(%x = 1; %x <= $MRC::PastMapsDepth; %x++)
{
if( $MRC::PrevMap[%x] !$= "" )
echo("PM" @ %x @ ": " @ $MRC::PrevMap[%x]);
}
2019-02-18 01:58:56 -05:00
}
}
}
function MapRepetitionCheckerFindRandom(%redone)
{
2019-12-12 23:32:45 -05:00
//Make sure GetRandomMaps.cs is present
if(!$GetRandomMapsLoaded)
2019-02-26 22:33:46 -05:00
return;
//Backup
if(%redone $="")
$SetNextMissionRestore = $EvoCachedNextMission;
2019-02-17 18:58:19 -05:00
2019-03-26 23:10:06 -04:00
//Do work
//getRandomMap() is in GetRandomMaps.cs
$EvoCachedNextMission = getRandomMap();
//Make sure new map still complies
2019-12-12 23:32:45 -05:00
%redo = 0;
for(%x = 1; %x <= $MRC::PastMapsDepth; %x++)
{
if($MRC::PrevMap[%x] !$= "" && $MRC::PrevMap[%x] $= $EvoCachedNextMission)
%redo = 1;
}
2019-12-26 17:05:06 -05:00
//Make sure its within maplimits
%newmaplimits = $Host::MapPlayerLimits[$EvoCachedNextMission, $CurrentMissionType];
%min = getWord(%newmaplimits,0);
%max = getWord(%newmaplimits,1);
if((%min > $AllPlayerCount || $AllPlayerCount > %max) && $AllPlayerCount > 2 )
2019-12-26 17:05:06 -05:00
%redo = 1;
if( %redo && %redone < 3 )
{
%redone++;
MapRepetitionCheckerFindRandom(%redone);
}
2019-02-18 02:38:08 -05:00
else
2019-02-20 17:59:45 -05:00
{
2019-03-27 15:07:40 -04:00
error(formatTimeString("HH:nn:ss") SPC "Map Repetition Corrected from" SPC $SetNextMissionRestore SPC "to" SPC $EvoCachedNextMission @ "." );
//Admin Message Only
for(%idx = 0; %idx < ClientGroup.getCount(); %idx++)
{
%cl = ClientGroup.getObject(%idx);
if(%cl.isAdmin)
messageClient(%cl, 'MsgMapRepCorrection', '\crMap Repetition Corrected: Next mission set from %1 to %2.', $SetNextMissionRestore, $EvoCachedNextMission);
}
2019-02-20 17:59:45 -05:00
}
}