swwmgz_m/zscript/menu/swwm_inter_dm.zsc

181 lines
6 KiB
Text

// Deathmatch stats
Class SWWMStatScreen_DM : SWWMStatScreen
{
override void initStats()
{
CurState = StatCount;
acceleratestage = 0;
for( int i=0; i<MAXPLAYERS; i++ )
{
playerready[i] = false;
cnt_frags[i] = cnt_deaths[i] = player_deaths[i] = 0;
}
total_frags = 0;
total_deaths = 0;
ng_state = 1;
cnt_pause = GameTicRate;
for ( int i=0; i<MAXPLAYERS; i++ )
{
if ( !playeringame[i] ) continue;
for ( int j=0; j<MAXPLAYERS; j++ )
{
if ( !playeringame[j] ) continue;
player_deaths[i] += Plrs[j].frags[i];
}
total_deaths += player_deaths[i];
total_frags += Plrs[i].fragcount;
}
}
override void updateStats()
{
bool stillticking;
bool doautoskip = autoSkip();
if ( (acceleratestage || doautoskip) && (ng_state != 6) )
{
acceleratestage = 0;
for ( int i=0; i<MAXPLAYERS; i++ )
{
if ( !playeringame[i] ) continue;
cnt_frags[i] = Plrs[i].fragcount;
cnt_deaths[i] = player_deaths[i];
}
PlaySound("menu/buyinv");
ng_state = 6;
}
if ( ng_state == 2 )
{
if ( !(bcnt&2) ) PlaySound("menu/demoscroll");
stillticking = false;
for ( int i=0; i<MAXPLAYERS; i++ )
{
if ( !playeringame[i] ) continue;
cnt_frags[i] += max((Plrs[i].fragcount-cnt_frags[i])/10,2);
if ( cnt_frags[i] > Plrs[i].fragcount ) cnt_frags[i] = Plrs[i].fragcount;
else stillticking = true;
}
if ( !stillticking )
{
PlaySound("menu/buyinv");
ng_state++;
}
}
else if ( ng_state == 4 )
{
if ( !(bcnt&2) ) PlaySound("menu/demoscroll");
stillticking = false;
for ( int i=0; i<MAXPLAYERS; i++ )
{
if ( !playeringame[i] ) continue;
cnt_deaths[i] += max((player_deaths[i]-cnt_deaths[i])/10,2);
if ( cnt_deaths[i] > player_deaths[i] ) cnt_deaths[i] = player_deaths[i];
else stillticking = true;
}
if ( !stillticking )
{
PlaySound("menu/buyinv");
ng_state++;
}
}
else if ( ng_state == 6 )
{
int i;
for ( i=0; i<MAXPLAYERS; i++ )
{
// If the player is in the game and not ready, stop checking
if ( playeringame[i] && !players[i].Bot && !playerready[i] )
break;
}
// All players are ready; proceed.
if ( ((i == MAXPLAYERS) && acceleratestage) || doautoskip )
{
PlaySound("misc/w_pkup");
initShowNextLoc();
}
}
else if ( ng_state&1 )
{
if ( !--cnt_pause )
{
ng_state++;
cnt_pause = GameTicRate;
}
}
}
override void drawStats( void )
{
drawLF();
int checkmark = 0x2714; // "✔"
String namestr = StringTable.Localize("$SCORE_NAME");
String deathsstr = StringTable.Localize("$SCORE_DEATHS");
String fragsstr = StringTable.Localize("$SCORE_FRAGS");
String totalstr = StringTable.Localize("$SCORE_TOTAL");
int namelen = max(max(mSmallFont.StringWidth(namestr),mSmallFont.StringWidth("XXXXXXXXXX")),mSmallFont.StringWidth(totalstr));
int nplayers = 0;
for ( int i=0; i<MAXPLAYERS; i++ )
{
if ( !playeringame[i] ) continue;
namelen = max(namelen,mSmallFont.StringWidth(players[i].GetUserName()));
nplayers++;
}
String deathstotal = String.Format("%d",total_deaths);
String fragstotal = String.Format("%d",total_frags);
int deathslen = max(mSmallFont.StringWidth(deathstotal),mSmallFont.StringWidth(deathsstr));
int fragslen = max(mSmallFont.StringWidth(fragstotal),mSmallFont.StringWidth(fragsstr));
int pad = 2;
int spc = 12;
int hspc = 6;
int lspc = 2;
int rwidth = mSmallFont.GetCharWidth(checkmark)+4;
int linew = pad+rwidth+namelen+spc+deathslen+spc+fragslen+pad;
int boxwidth = pad+linew+pad;
int lineh = mSmallFont.GetHeight();
int boxheight = pad+lineh+hspc+(lineh+lspc)*nplayers+hspc+lineh+pad;
Screen.Dim("Black",.8,int((ss.x-boxwidth)*hs)/2,int((ss.y-boxheight)*hs)/2,int(boxwidth*hs),int(boxheight*hs));
// header
int xx = int((ss.x-boxwidth)/2+pad+pad+rwidth);
int yy = int((ss.y-boxheight)/2+pad);
Screen.DrawText(mSmallFont,Font.CR_GREEN,xx,yy,namestr,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
xx += namelen+spc;
Screen.DrawText(mSmallFont,Font.CR_GREEN,xx,yy,deathsstr,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
xx += deathslen+spc;
Screen.DrawText(mSmallFont,Font.CR_GREEN,xx,yy,fragsstr,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
yy += lineh+hspc;
String str;
Array<Int> sorted;
GetSortedPlayers(sorted,teamplay);
foreach ( i:sorted )
{
if ( !playeringame[i] ) continue;
xx = int((ss.x-boxwidth)/2+pad);
Screen.Dim(players[i].GetDisplayColor(),.4,int(xx*hs),int(yy*hs),int(linew*hs),int(lineh*hs));
xx += pad;
if ( playerready[i] || players[i].Bot ) Screen.DrawChar(mSmallFont,Font.CR_GREEN,xx,yy,checkmark,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
xx += rwidth;
Screen.DrawText(mSmallFont,GetRowColor(players[i],i==me),xx,yy,players[i].GetUserName(),DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
xx += namelen+spc;
if ( ng_state >= 2 )
{
str = String.Format("%d",cnt_deaths[i]);
Screen.DrawText(mSmallFont,Font.CR_WHITE,xx+deathslen-mSmallFont.StringWidth(str),yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
}
xx += deathslen+spc;
str = String.Format("%d",cnt_frags[i]);
Screen.DrawText(mSmallFont,Font.CR_WHITE,xx+fragslen-mSmallFont.StringWidth(str),yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
yy += lineh+lspc;
}
xx = int((ss.x-boxwidth)/2+pad+pad+rwidth);
yy += hspc;
Screen.DrawText(mSmallFont,Font.CR_GREEN,xx,yy,totalstr,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
xx += namelen+spc;
if ( ng_state >= 4 )
{
str = String.Format("%d",total_deaths);
Screen.DrawText(mSmallFont,Font.CR_WHITE,xx+deathslen-mSmallFont.StringWidth(str),yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
}
xx += deathslen+spc;
str = String.Format("%d",total_frags);
Screen.DrawText(mSmallFont,Font.CR_WHITE,xx+fragslen-mSmallFont.StringWidth(str),yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
}
}