swwmgz_m/zscript/menu/swwm_inter_coop.zsc

249 lines
9.4 KiB
Text

// Cooperative stats
Class SWWMStatScreen_Coop : SWWMStatScreen
{
override void initStats()
{
CurState = StatCount;
acceleratestage = 0;
ng_state = 1;
cnt_pause = GameTicRate;
for ( int i=0; i<MAXPLAYERS; i++ )
{
playerready[i] = false;
cnt_kills[i] = cnt_items[i] = cnt_secret[i] = cnt_frags[i] = 0;
if ( !playeringame[i] ) continue;
dofrags += fragSum(i);
}
dofrags = !!dofrags;
}
override void updateStats()
{
int fsum;
bool stillticking;
bool autoskip = autoSkip();
if ( (acceleratestage || autoskip) && (ng_state != 10) )
{
acceleratestage = 0;
for ( int i=0; i<MAXPLAYERS; i++ )
{
if ( !playeringame[i] ) continue;
cnt_kills[i] = Plrs[i].skills;
cnt_items[i] = Plrs[i].sitems;
cnt_secret[i] = Plrs[i].ssecret;
if ( dofrags ) cnt_frags[i] = fragSum(i);
}
PlaySound("menu/buyinv");
ng_state = 10;
}
if ( ng_state == 2 )
{
if ( !(bcnt&2) ) PlaySound("menu/demoscroll");
stillticking = false;
for ( int i=0; i<MAXPLAYERS; i++ )
{
if ( !playeringame[i] ) continue;
cnt_kills[i] += max((Plrs[i].skills-cnt_kills[i])/10,2);
if ( cnt_kills[i] > Plrs[i].skills ) cnt_kills[i] = Plrs[i].skills;
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_items[i] += max((Plrs[i].sitems-cnt_items[i])/10,2);
if ( cnt_items[i] > Plrs[i].sitems ) cnt_items[i] = Plrs[i].sitems;
else stillticking = true;
}
if ( !stillticking )
{
PlaySound("menu/buyinv");
ng_state++;
}
}
else if ( ng_state == 6 )
{
if ( !(bcnt&2) ) PlaySound("menu/demoscroll");
stillticking = false;
for ( int i=0; i<MAXPLAYERS; i++ )
{
if ( !playeringame[i] ) continue;
cnt_secret[i] += max((Plrs[i].ssecret-cnt_secret[i])/10,2);
if ( cnt_secret[i] > Plrs[i].ssecret ) cnt_secret[i] = Plrs[i].ssecret;
else stillticking = true;
}
if ( !stillticking )
{
PlaySound("menu/buyinv");
ng_state += 1+2*!dofrags;
}
}
else if ( ng_state == 8 )
{
if ( !(bcnt&2) ) PlaySound("menu/demoscroll");
stillticking = false;
for ( int i=0; i<MAXPLAYERS; i++ )
{
if ( !playeringame[i] ) continue;
fsum = fragSum(i);
cnt_frags[i] += max((fsum-cnt_frags[i])/10,1);
if ( cnt_frags[i] >= fsum ) cnt_frags[i] = fsum;
else stillticking = true;
}
if ( !stillticking )
{
PlaySound("menu/buyinv");
ng_state++;
}
}
else if ( ng_state == 10 )
{
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) || autoskip )
{
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 itemsstr = StringTable.Localize((gameinfo.gametype&GAME_Raven)?"$SCORE_BONUS":"$SCORE_ITEMS");
String secretstr = StringTable.Localize("$SCORE_SECRET");
String killsstr = StringTable.Localize("$SCORE_KILLS");
String missedstr = StringTable.Localize("$SCORE_MISSED");
String totalstr = StringTable.Localize("$SCORE_TOTAL");
int namelen = max(max(mSmallFont.StringWidth(namestr),mSmallFont.StringWidth("XXXXXXXXXX")),max(mSmallFont.StringWidth(missedstr),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++;
}
int misseditems = wbs.maxitems;
int missedsecret = wbs.maxsecret;
int missedkills = wbs.maxkills;
String itemstotal = String.Format("%d",misseditems);
String secrettotal = String.Format("%d",missedsecret);
String killstotal = String.Format("%d",missedkills);
int itemslen = max(mSmallFont.StringWidth("100%"),max(mSmallFont.StringWidth(itemstotal),mSmallFont.StringWidth(itemsstr)));
int secretlen = max(mSmallFont.StringWidth("100%"),max(mSmallFont.StringWidth(secrettotal),mSmallFont.StringWidth(secretstr)));
int killslen = max(mSmallFont.StringWidth("100%"),max(mSmallFont.StringWidth(killstotal),mSmallFont.StringWidth(killsstr)));
int pad = 2;
int spc = 12;
int hspc = 6;
int lspc = 2;
int rwidth = mSmallFont.GetCharWidth(checkmark)+4;
int linew = pad+rwidth+namelen+spc+itemslen+spc+secretlen+spc+killslen+pad;
int boxwidth = pad+linew+pad;
int lineh = mSmallFont.GetHeight();
int boxheight = pad+lineh+hspc+(lineh+lspc)*nplayers+hspc+lineh+lspc+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,itemsstr,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
xx += itemslen+spc;
Screen.DrawText(mSmallFont,Font.CR_GREEN,xx,yy,secretstr,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
xx += secretlen+spc;
Screen.DrawText(mSmallFont,Font.CR_GREEN,xx,yy,killsstr,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
yy += lineh+hspc;
String str;
for ( int i=0; i<MAXPLAYERS; i++ )
{
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 >= 4 )
{
str = String.Format("%3d\cu%%\c-",GetPct(cnt_items[i],wbs.maxitems));
Screen.DrawText(mSmallFont,(!wbs.maxitems||(cnt_items[i]>=wbs.maxitems))?Font.CR_GOLD:Font.CR_WHITE,xx+itemslen-mSmallFont.StringWidth(str),yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
misseditems -= cnt_items[i];
}
xx += itemslen+spc;
if ( ng_state >= 6 )
{
str = String.Format("%3d\cu%%\c-",GetPct(cnt_secret[i],wbs.maxsecret));
Screen.DrawText(mSmallFont,(!wbs.maxsecret||(cnt_secret[i]>=wbs.maxsecret))?Font.CR_GOLD:Font.CR_WHITE,xx+secretlen-mSmallFont.StringWidth(str),yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
missedsecret -= cnt_secret[i];
}
xx += secretlen+spc;
str = String.Format("%3d\cu%%\c-",GetPct(cnt_kills[i],wbs.maxkills));
Screen.DrawText(mSmallFont,(!wbs.maxkills||(cnt_kills[i]>=wbs.maxkills))?Font.CR_GOLD:Font.CR_WHITE,xx+killslen-mSmallFont.StringWidth(str),yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
missedkills -= cnt_kills[i];
yy += lineh+lspc;
}
xx = int((ss.x-boxwidth)/2+pad+pad+rwidth);
yy += hspc;
Screen.DrawText(mSmallFont,Font.CR_GREEN,xx,yy,missedstr,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
xx += namelen+spc;
if ( ng_state >= 4 )
{
str = String.Format("%3d\cu%%\c-",GetPct(misseditems,wbs.maxitems,true));
Screen.DrawText(mSmallFont,(wbs.maxitems&&(misseditems>0))?Font.CR_WHITE:Font.CR_GOLD,xx+itemslen-mSmallFont.StringWidth(str),yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
}
xx += itemslen+spc;
if ( ng_state >= 6 )
{
str = String.Format("%3d\cu%%\c-",GetPct(missedsecret,wbs.maxsecret,true));
Screen.DrawText(mSmallFont,(wbs.maxsecret&&(missedsecret>0))?Font.CR_WHITE:Font.CR_GOLD,xx+secretlen-mSmallFont.StringWidth(str),yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
}
xx += secretlen+spc;
str = String.Format("%3d\cu%%\c-",GetPct(missedkills,wbs.maxkills,true));
Screen.DrawText(mSmallFont,(wbs.maxkills&&(missedkills>0))?Font.CR_WHITE:Font.CR_GOLD,xx+killslen-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);
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",wbs.maxitems);
Screen.DrawText(mSmallFont,Font.CR_WHITE,xx+itemslen-mSmallFont.StringWidth(str),yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
}
xx += itemslen+spc;
if ( ng_state >= 6 )
{
str = String.Format("%d",wbs.maxsecret);
Screen.DrawText(mSmallFont,Font.CR_WHITE,xx+secretlen-mSmallFont.StringWidth(str),yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
}
xx += secretlen+spc;
str = String.Format("%d",wbs.maxkills);
Screen.DrawText(mSmallFont,Font.CR_WHITE,xx+killslen-mSmallFont.StringWidth(str),yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
}
}