Yet more deathmatch stuff.

This commit is contained in:
Mari the Deer 2021-06-04 21:35:17 +02:00
commit da703e3e35
8 changed files with 178 additions and 25 deletions

View file

@ -70,6 +70,13 @@ Class SWWMStatusBar : BaseStatusBar
Color mm_backcolor, mm_cdwallcolor, mm_efwallcolor, mm_fdwallcolor, mm_gridcolor, mm_interlevelcolor, mm_intralevelcolor, mm_lockedcolor, mm_notseencolor, mm_portalcolor, mm_secretsectorcolor, mm_secretwallcolor, mm_specialwallcolor, mm_thingcolor, mm_thingcolor_citem, mm_thingcolor_friend, mm_thingcolor_item, mm_thingcolor_monster, mm_thingcolor_ncmonster, mm_thingcolor_shootable, mm_thingcolor_vipitem, mm_thingcolor_missile, mm_tswallcolor, mm_unexploredsecretcolor, mm_wallcolor, mm_xhaircolor, mm_yourcolor;
bool mm_displaylocks, mm_drawautopage;
// deathmatch stuff
int playercount, rank, lead;
bool tiedscore;
Array<PlayerInfo> sortplayers;
Array<bool> teamactive;
Array<int> teamscore;
// if playing in Japanese, returns an alternate font of the same height
// Tewi -> MPlus
// Miniwi -> k6x8
@ -375,6 +382,34 @@ Class SWWMStatusBar : BaseStatusBar
qsort_itemsense(a,p+1,h);
}
// quicksort (player scores)
private int partition_playerscore( Array<PlayerInfo> a, int l, int h )
{
PlayerInfo pv = a[h];
int i = (l-1);
for ( int j=l; j<=(h-1); j++ )
{
if ( pv.fragcount < a[j].fragcount )
{
i++;
PlayerInfo tmp = a[j];
a[j] = a[i];
a[i] = tmp;
}
}
PlayerInfo tmp = a[h];
a[h] = a[i+1];
a[i+1] = tmp;
return i+1;
}
private void qsort_playerscore( Array<PlayerInfo> a, int l, int h )
{
if ( l >= h ) return;
int p = partition_playerscore(a,l,h);
qsort_playerscore(a,l,p-1);
qsort_playerscore(a,p+1,h);
}
override void Tick()
{
Super.Tick();
@ -465,7 +500,6 @@ Class SWWMStatusBar : BaseStatusBar
if ( !trk.mytarget || trk.mytarget.bDORMANT || trk.mytarget.bINVISIBLE ) continue;
// ignore local player
if ( trk.mytarget == CPlayer.mo ) continue;
if ( trk.myplayer && deathmatch ) continue; // no players in dm
if ( trk.mytarget is 'PlayerGone' ) continue; // ignore "gone" players
int mtime = 35;
if ( thesight && (trk.lasthealth > 0) ) mtime += 105;
@ -587,6 +621,55 @@ Class SWWMStatusBar : BaseStatusBar
// also try with different endianness, just in case
DetachMessageID(0x4e504557); // WEPN
DetachMessageID(0x564e4953); // SINV
// deathmatch stuff
if ( !deathmatch ) return;
if ( teamplay )
{
if ( teamactive.Size() != Teams.Size() ) teamactive.Resize(Teams.Size());
if ( teamscore.Size() != Teams.Size() ) teamscore.Resize(Teams.Size());
for ( int i=0; i<Teams.Size(); i++ )
{
teamactive[i] = false;
teamscore[i] = 0;
}
for ( int i=0; i<MAXPLAYERS; i++ )
{
if ( !playeringame[i] ) continue;
int team = players[i].GetTeam();
if ( team != -1 )
{
teamactive[team] = true;
teamscore[team] += players[i].fragcount;
}
}
return;
}
playercount = 0;
int highscore = int.min;
tiedscore = false;
rank = 1;
for ( int i=0; i<MAXPLAYERS; i++ )
{
if ( !playeringame[i] ) continue;
playercount++;
if ( players[i] == CPlayer ) continue;
if ( players[i].fragcount > CPlayer.fragcount )
rank += 1;
else if ( players[i].fragcount == CPlayer.fragcount )
tiedscore = true;
if ( players[i].fragcount > highscore )
highscore = players[i].fragcount;
}
if ( sortplayers.Size() != playercount ) sortplayers.Resize(playercount);
for ( int i=0, j=0; i<MAXPLAYERS; i++ )
{
if ( !playeringame[i] ) continue;
sortplayers[j++] = players[i];
}
// sort players by score
qsort_playerscore(sortplayers,0,playercount-1);
if ( playercount <= 1 ) highscore = CPlayer.fragcount;
lead = CPlayer.fragcount-highscore;
}
override void Init()
@ -748,7 +831,7 @@ Class SWWMStatusBar : BaseStatusBar
if ( ndc.z >= 1. ) continue;
Vector2 vpos = SWWMUtility.NDCToViewport(projdata,ndc);
tag = targ.mytag;
if ( tag != "" )
if ( (tag != "") && !targ.myplayer )
{
if ( targ.legged && (targ.mutated || swwm_ldspoil) )
{
@ -767,8 +850,15 @@ Class SWWMStatusBar : BaseStatusBar
Vector2 barpos = vpos-(barsiz/2.);
barpos.y -= 16.;
Font fnt = LangFont(swwm_bigtags?mTewiFont:mMiniwiFont);
int col = Font.CR_WHITE;
if ( teamplay )
{
int team = targ.myplayer.GetTeam();
if ( team != -1 ) col = Font.FindFontColor(Teams[team].mName); // this works in practice because team names are the same as their text colors
if ( col == -1 ) col = Font.CR_WHITE;
}
if ( swwm_targettags || targ.myplayer && (tag != "") )
Screen.DrawText(fnt,Font.CR_WHITE,(barpos.x+barsiz.x/2.-(fnt.StringWidth(tag)*hsb.x)/2.)/hsb.x,(barpos.y-fnt.GetHeight()*hsb.y)/hsb.y,tag,DTA_VirtualWidthF,ssb.x,DTA_VirtualHeightF,ssb.y,DTA_KeepRatio,true,DTA_Alpha,alph,DTA_ClipTop,cliptop,DTA_ClipBottom,clipbottom,DTA_ClipLeft,clipleft,DTA_ClipRight,clipright);
Screen.DrawText(fnt,col,(barpos.x+barsiz.x/2.-(fnt.StringWidth(tag)*hsb.x)/2.)/hsb.x,(barpos.y-fnt.GetHeight()*hsb.y)/hsb.y,tag,DTA_VirtualWidthF,ssb.x,DTA_VirtualHeightF,ssb.y,DTA_KeepRatio,true,DTA_Alpha,alph,DTA_ClipTop,cliptop,DTA_ClipBottom,clipbottom,DTA_ClipLeft,clipleft,DTA_ClipRight,clipright);
Screen.DrawTexture(EnemyBTex,false,barpos.x/hsb.x,barpos.y/hsb.y,DTA_VirtualWidthF,ssb.x,DTA_VirtualHeightF,ssb.y,DTA_KeepRatio,true,DTA_Alpha,alph,DTA_ClipTop,cliptop,DTA_ClipBottom,clipbottom,DTA_ClipLeft,clipleft,DTA_ClipRight,clipright);
double ht = clamp(targ.intp.GetValue(),0,targ.maxhealth*10);
double hw = (min(ht,targ.maxhealth)*50.)/targ.maxhealth;
@ -1479,6 +1569,14 @@ Class SWWMStatusBar : BaseStatusBar
}
}
private String OrdinalStr( int val, int gender )
{
String lstr = "SWWM_PLACE"..val.."_GENDER"..gender;
String str = StringTable.Localize("$"..lstr);
if ( str != lstr ) return str;
return StringTable.Localize("$SWWM_PLACE"..val);
}
private void DrawScore()
{
String sstr;
@ -1539,19 +1637,19 @@ Class SWWMStatusBar : BaseStatusBar
yy += fnt.GetHeight();
}
fnt = LangFont(mMiniwiFont);
if ( (level.total_monsters > 0) && am_showmonsters )
if ( (level.total_monsters > 0) && am_showmonsters && !deathmatch )
{
str = String.Format("\cxK \c-%d\cu/\c-%d",level.killed_monsters,level.total_monsters);
Screen.DrawText(fnt,(level.killed_monsters>=level.total_monsters)?Font.CR_GOLD:Font.CR_WHITE,xx-fnt.StringWidth(str),yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
yy += fnt.GetHeight();
}
if ( (level.total_items > 0) && am_showitems )
if ( (level.total_items > 0) && am_showitems && !deathmatch )
{
str = String.Format("\cxI \c-%d\cu/\c-%d",level.found_items,level.total_items);
Screen.DrawText(fnt,(level.found_items>=level.total_items)?Font.CR_GOLD:Font.CR_WHITE,xx-fnt.StringWidth(str),yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
yy += fnt.GetHeight();
}
if ( (level.total_secrets > 0) && am_showsecrets )
if ( (level.total_secrets > 0) && am_showsecrets && !deathmatch )
{
str = String.Format("\cxS \c-%d\cu/\c-%d",level.found_secrets,level.total_secrets);
Screen.DrawText(fnt,(level.found_secrets>=level.total_secrets)?Font.CR_GOLD:Font.CR_WHITE,xx-fnt.StringWidth(str),yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
@ -1574,8 +1672,47 @@ Class SWWMStatusBar : BaseStatusBar
}
yy += 3;
}
if ( deathmatch )
{
yy += 9;
if ( playercount <= 1 ) return;
xx = int(ss.x-(margin+2));
String str;
Font fnt = LangFont(mTewiFont);
if ( teamplay )
{
// draw team scores
for ( int i=0; i<teamscore.Size(); i++ )
{
if ( !teamactive[i] ) continue;
str = String.Format("\cx%s \c-%d",Teams[i].mName,teamscore[i]);
Screen.DrawText(fnt,Font.CR_WHITE,xx-fnt.StringWidth(str),yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
yy += fnt.GetHeight();
}
}
else
{
// draw rank and spread like in UT
if ( tiedscore ) str = String.Format("\cx%s \cg%d\cr/\cg%d\c-",StringTable.Localize("$SWWM_DMRANK"),rank,playercount);
else str = String.Format("\cx%s \cj%d\cu/\cj%d\c-",StringTable.Localize("$SWWM_DMRANK"),rank,playercount);
Screen.DrawText(fnt,Font.CR_WHITE,xx-fnt.StringWidth(str),yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
yy += fnt.GetHeight();
if ( lead > 0 ) str = String.Format("\cx%s \cj+%d\c-",StringTable.Localize("$SWWM_DMSPREAD"),lead);
else str = String.Format("\cx%s \cj%d\c-",StringTable.Localize("$SWWM_DMSPREAD"),lead);
Screen.DrawText(fnt,Font.CR_WHITE,xx-fnt.StringWidth(str),yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
yy += fnt.GetHeight()+3;
// draw top 3 players
for ( int i=0; i<min(3,playercount); i++ )
{
if ( sortplayers[i].fragcount < 0 ) str = String.Format("\cx#%d: \c-%s\c- \cr(\cg%d\cr)\c-",i+1,sortplayers[i].GetUserName(),sortplayers[i].fragcount);
else str = String.Format("\cx%s: \c-%s\c- \cu(\cj%d\cu)\c-",OrdinalStr(i+1,sortplayers[i].GetGender()),sortplayers[i].GetUserName(),sortplayers[i].fragcount);
Screen.DrawText(fnt,Font.CR_WHITE,xx-fnt.StringWidth(str),yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
yy += fnt.GetHeight();
}
}
return;
}
// draw key icons
if ( deathmatch ) return;
Vector2 keypos = (ss.x-(margin+2),yy);
int colc = 0;
double colh = 0;