swwmgz_m/zscript/swwm_handler.zsc
2021-09-14 18:40:22 +02:00

199 lines
6.1 KiB
Text

// Handler responsible for item replacements and whatever else
// most of the code is split up to make it easier to navigate
Class SWWMHandler : EventHandler
{
transient int lastlock;
transient int lastpickuptic[MAXPLAYERS];
SWWMCombatTracker trackers;
SWWMScoreObj scorenums, damnums;
SWWMInterest intpoints;
int trackers_cnt, scorenums_cnt, damnums_cnt, intpoints_cnt;
transient int slotstrictwarn;
// optimization
OnFire fires;
int fires_cnt;
// stuff to reduce worldthingspawned overhead
int bossmap;
int iwantdie;
int indoomvacation;
// for checkreplacement
bool hasdrlamonsters;
int iskdizd;
// profiling data
bool profiling;
int bprofiletics, profiletics; // how many tics to aggregate data for
uint worldtick_ms;
uint worldthingspawned_ms, worldthingdestroyed_ms,
worldthingdied_ms, worldthingdamaged_ms,
worldthingrevived_ms;
uint checkreplacement_ms, checkreplacee_ms;
uint curms;
override void OnRegister()
{
// oneliner RNG must be relative to consoleplayer
SetRandomSeed[DemoLines](Random[DemoLines]()+consoleplayer+MSTime());
// "uninitialize" some vars
iwantdie = -1;
bossmap = -1;
indoomvacation = -1;
// this one can be initialized here easily
for ( int i=0; i<AllActorClasses.Size(); i++ )
{
if ( AllActorClasses[i].GetClassName() != "RLMonster" ) continue;
hasdrlamonsters = true;
break;
}
if ( LevelInfo.MapExists("Z1M1") && (LevelInfo.MapChecksum("Z1M1") ~== "2B7744234ED2C162AD08A3255E979F65") )
iskdizd = true;
}
override void WorldTick()
{
if ( profiling ) curms = MSTime();
LangRefresh();
QueueMaintenance();
if ( !mnotify && (level.maptime >= 5) )
{
mnotify = true;
let ti = ThinkerIterator.Create("SWWMStats",Thinker.STAT_STATIC);
SWWMStats s;
while ( s = SWWMStats(ti.Next()) )
{
if ( !SWWMUtility.IsKnownMap() ) break;
if ( s.myplayer != players[consoleplayer] ) continue;
int clust = level.cluster;
if ( SWWMUtility.IsEviternity() )
{
// we have to do some heavy lifting here because episodes don't match clusters
if ( level.levelnum <= 5 ) clust = 1;
else if ( level.levelnum <= 10 ) clust = 2;
else if ( level.levelnum <= 15 ) clust = 3;
else if ( level.levelnum <= 20 ) clust = 4;
else if ( level.levelnum <= 25 ) clust = 5;
else if ( level.levelnum <= 30 ) clust = 6;
else if ( level.levelnum <= 31 ) clust = 7;
else if ( level.levelnum <= 32 ) clust = 8;
}
int csiz = s.clustervisit.Size();
if ( (csiz > 0) && (s.clustervisit[csiz-1] != clust) )
Console.Printf(StringTable.Localize("$SWWM_NEWMISSION"));
}
}
OnelinerTick();
FlashTick();
ItemCountTrack();
CombatTrack();
OneHundredPercentCheck();
SimpleTracking();
VanillaBossTick();
if ( profiling )
{
worldtick_ms += MSTime()-curms;
Console.Printf("%d...",profiletics);
profiletics--;
if ( profiletics <= 0 )
{
profiling = false;
Console.Printf("Done!");
Console.Printf("SWWMHandler profiling info for "..bprofiletics.." tic(s):\n"
" event | total | avg\n"
"---------------------|--------|--------\n"
" WorldTick | %-6d | %g\n"
" WorldThingSpawned | %-6d | %g\n"
" WorldThingDestroyed | %-6d | %g\n"
" WorldThingDied | %-6d | %g\n"
" WorldThingDamaged | %-6d | %g\n"
" WorldThingRevived | %-6d | %g\n"
" CheckReplacement | %-6d | %g\n"
" CheckReplacee | %-6d | %g",
worldtick_ms,double(worldtick_ms)/bprofiletics,
worldthingspawned_ms,double(worldthingspawned_ms)/bprofiletics,
worldthingdestroyed_ms,double(worldthingdestroyed_ms)/bprofiletics,
worldthingdied_ms,double(worldthingdied_ms)/bprofiletics,
worldthingdamaged_ms,double(worldthingdamaged_ms)/bprofiletics,
worldthingrevived_ms,double(worldthingrevived_ms)/bprofiletics,
checkreplacement_ms,double(checkreplacement_ms)/bprofiletics,
checkreplacee_ms,double(checkreplacee_ms)/bprofiletics);
}
}
}
override void PostUiTick()
{
OnelinerUITick();
FlashUITick();
VanillaBossUITick();
CheatUITick();
MapstartUITick();
}
override void WorldLinePreActivated( WorldEvent e )
{
// oneliner on locked doors
if ( !e.Thing ) return;
int locknum = SWWMUtility.GetLineLock(e.ActivatedLine);
if ( (locknum < 1) || (locknum > 255) ) return;
if ( e.Thing.CheckLocalView() && !e.Thing.CheckKeys(locknum,false,true) )
{
if ( !lastlock || (gametic > lastlock+20) )
{
if ( SWWMUtility.IsValidLockNum(locknum) )
lastlock = AddOneliner("locked",2);
else lastlock = AddOneliner("jammed",2);
}
}
}
override void WorldLineActivated( WorldEvent e )
{
if ( !(e.ActivationType&SPAC_Use) ) return;
if ( !e.Thing || !e.Thing.player ) return;
let w = SWWMWeapon(e.Thing.player.ReadyWeapon);
if ( (!w || !w.wallponch) && (!(e.Thing is 'Demolitionist') || !Demolitionist(e.Thing).hitactivate) ) return;
let s = SWWMStats.Find(e.Thing.player);
if ( s ) s.wponch++;
SWWMUtility.AchievementProgressInc('swwm_progress_slemg',1,e.Thing.player);
}
// stuff for hud
override void RenderUnderlay( RenderEvent e )
{
// armor/health flashes
FlashRender(e);
if ( slotstrictwarn && (gametic < slotstrictwarn) )
{
String str = StringTable.Localize("$SWWM_SETSLOTSTRICT");
double t = (slotstrictwarn-(gametic+e.FracTic))/20.;
double alph = clamp(t,0.,1.);
BrokenLines l = newsmallfont.BreakLines(str,300);
double yy = (200-l.Count()*newsmallfont.GetHeight())/2;
for ( int i=0; i<l.Count(); i++ )
{
double xx = (320-l.StringWidth(i))/2;
Screen.DrawText(newsmallfont,Font.CR_UNTRANSLATED,xx,yy,l.StringAt(i),DTA_Clean,true,DTA_Alpha,alph);
yy += newsmallfont.GetHeight();
}
}
// weapon underlays
if ( players[consoleplayer].ReadyWeapon is 'SWWMWeapon' )
SWWMWeapon(players[consoleplayer].ReadyWeapon).RenderUnderlay(e);
if ( !statusbar || !(statusbar is 'SWWMStatusBar') ) return;
SWWMStatusBar(statusbar).viewpos = e.viewpos;
SWWMStatusBar(statusbar).viewrot = (e.viewangle,e.viewpitch,e.viewroll);
}
// various shaders
override void RenderOverlay( RenderEvent e )
{
CheatOverlay(e);
RenderShaders(e);
DrawDebug(e);
}
}