swwmgz_m/zscript/hud/swwm_hud_weapons.zsc

295 lines
11 KiB
Text

// Weapons and ammo
extend Class SWWMStatusBar
{
private void TickWeaponInterpolators()
{
// ammo updates
for ( int i=0; i<18; i++ )
{
let a = SWWMAmmo(CPlayer.mo.FindInventory(AmmoSlots[i]));
int amt = 0;
int maxamt = 0;
if ( a )
{
amt = a.Amount;
maxamt = a.MaxAmount;
if ( a.MagAmmoType )
{
let m = MagAmmo(CPlayer.mo.FindInventory(a.MagAmmoType));
if ( m )
{
amt *= m.ClipSize;
amt += m.Amount;
maxamt *= m.ClipSize;
}
}
}
else
{
let a = GetDefaultByType(AmmoSlots[i]);
maxamt = a.MaxAmount;
if ( a.MagAmmoType )
{
let m = GetDefaultByType(a.MagAmmoType);
maxamt *= m.ClipSize;
}
}
if ( (amt > AmmoOldAmounts[i]) && (AmmoOldAmounts[i] != int.min) )
AmmoFlash[i] = gametic+25;
AmmoOldAmounts[i] = amt;
if ( (maxamt > AmmoOldMaxAmounts[i]) && (AmmoOldMaxAmounts[i] != int.min) )
AmmoMaxFlash[i] = gametic+25;
AmmoOldMaxAmounts[i] = maxamt;
}
}
private void TickWeapons()
{
// let weapons update their own interpolators
for ( Inventory i=CPlayer.mo.inv; i; i=i.inv )
{
if ( !(i is 'SWWMWeapon') ) continue;
SWWMWeapon(i).HudTick();
}
}
// hello??? why is this function clearscope???
override void ReceivedWeapon( Weapon weapn )
{
Super.ReceivedWeapon(weapn);
int dummy, slot;
[dummy, slot] = players[consoleplayer].weapons.LocateWeapon(weapn.GetClass());
EventHandler.SendNetworkEvent("swwmweaponreceive",slot,consoleplayer);
}
private void DrawWeapons()
{
Screen.DrawTexture(WeaponTex,false,ss.x-(margin+80),ss.y-(margin+10),DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
double xx = ss.x-(margin+78), yy = ss.y-(margin+8);
for ( int i=1; i<=10; i++,xx+=8 )
{
int ncolor = mhudfontcol[MCR_WHITE];
if ( !CPlayer.HasWeaponsInSlot(i%10) )
{
Screen.DrawText(MiniHUDFont,ncolor,xx,yy,String.Format("%d",(i%10)),DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_ColorOverlay,Color(128,0,0,0));
continue;
}
bool selected = false;
bool dummy;
int slot;
SWWMGesture hasgesture = null;
SWWMItemGesture hasitemgesture = null;
if ( CPlayer.PendingWeapon is 'SWWMGesture' ) hasgesture = SWWMGesture(CPlayer.PendingWeapon);
else if ( CPlayer.ReadyWeapon is 'SWWMGesture' ) hasgesture = SWWMGesture(CPlayer.ReadyWeapon);
if ( CPlayer.PendingWeapon is 'SWWMItemGesture' ) hasitemgesture = SWWMItemGesture(CPlayer.PendingWeapon);
else if ( CPlayer.ReadyWeapon is 'SWWMItemGesture' ) hasitemgesture = SWWMItemGesture(CPlayer.ReadyWeapon);
if ( hasgesture && hasgesture.formerweapon )
{
[dummy, slot] = CPlayer.weapons.LocateWeapon(hasgesture.formerweapon.GetClass());
if ( slot == (i%10) ) selected = true;
}
else if ( hasitemgesture && hasitemgesture.gest.formerweapon )
{
[dummy, slot] = CPlayer.weapons.LocateWeapon(hasitemgesture.gest.formerweapon.GetClass());
if ( slot == (i%10) ) selected = true;
}
else if ( CPlayer.PendingWeapon && (CPlayer.PendingWeapon != WP_NOCHANGE) )
{
[dummy, slot] = CPlayer.weapons.LocateWeapon(CPlayer.PendingWeapon.GetClass());
if ( slot == (i%10) ) selected = true;
}
else if ( (!CPlayer.PendingWeapon || (CPlayer.PendingWeapon == WP_NOCHANGE)) && CPlayer.ReadyWeapon )
{
[dummy, slot] = CPlayer.weapons.LocateWeapon(CPlayer.ReadyWeapon.GetClass());
if ( slot == (i%10) ) selected = true;
}
if ( selected ) ncolor = mhudfontcol[MCR_BRASS];
else
{
bool hasammo = (i==1);
for ( Inventory inv=CPlayer.mo.Inv; inv; inv=inv.Inv )
{
if ( inv is 'Weapon' ) [dummy, slot] = CPlayer.weapons.LocateWeapon(Weapon(inv).GetClass());
else continue;
if ( slot != (i%10) ) continue;
// CheckAmmo can't be called from ui, so we have to improvise
// for SWWM weapons I made a function for this at least
if ( (inv is 'SWWMWeapon') && SWWMWeapon(inv).ReportHUDAmmo() )
hasammo = true;
else if ( !(inv is 'SWWMWeapon') && ((!Weapon(inv).Ammo1 || (Weapon(inv).Ammo1.Amount > 0) || Weapon(inv).bAMMO_OPTIONAL) || (Weapon(inv).Ammo2 && ((Weapon(inv).Ammo2.Amount > 0) || Weapon(inv).bALT_AMMO_OPTIONAL))) )
hasammo = true;
}
if ( !hasammo ) ncolor = mhudfontcol[MCR_RED];
}
Screen.DrawText(MiniHUDFont,ncolor,xx,yy,String.Format("%d",(i%10)),DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
int f = hnd.WeaponFlash[i%10];
if ( f && (gametic < f) )
{
double alph = max((f-(gametic+FracTic))/25.,0.)**1.5;
Screen.DrawText(MiniHUDFont,mhudfontcol[MCR_FLASH],xx,yy,String.Format("%d",(i%10)),DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_Alpha,alph,DTA_LegacyRenderStyle,STYLE_Add);
}
}
xx = ss.x-(margin+54);
yy = ss.y-(margin+14);
bool bDrewAmmo = false;
bool checkowned = !swwm_hudallammo;
Array<SWWMWeapon> OwnedWeapons;
if ( checkowned ) for ( Inventory i=CPlayer.mo.inv; i; i=i.inv )
{
if ( !(i is 'SWWMWeapon') ) continue;
OwnedWeapons.Push(SWWMWeapon(i));
}
String str;
for ( int i=17; i>=0; i-- )
{
let a = AmmoSlots[i];
// check if owned
if ( checkowned )
{
bool owned = false;
foreach ( w:OwnedWeapons )
{
if ( w.UsesAmmo(a) )
owned = true;
}
if ( !owned ) continue;
}
if ( !bDrewAmmo )
{
Screen.DrawTexture(AmmoTex[2],false,xx,yy,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
bDrewAmmo = true;
}
yy -= 6;
Screen.DrawTexture(AmmoTex[1],false,xx,yy,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
xx += 2;
let cur = SWWMAmmo(CPlayer.mo.FindInventory(a));
int amt, amax;
if ( !cur )
{
amt = 0;
amax = GetDefaultByType(a).MaxAmount;
let def = GetDefaultByType(a);
if ( def.MagAmmoType )
{
let mag = MagAmmo(CPlayer.mo.FindInventory(def.MagAmmoType));
if ( mag ) // theoretically can't happen, but still check for it
{
amt = mag.Amount;
amax = amax*mag.ClipSize+mag.MaxAmount;
}
else
{
let defmag = GetDefaultByType(def.MagAmmoType);
amax = amax*defmag.ClipSize+defmag.MaxAmount;
}
}
}
else
{
amt = cur.Amount;
amax = cur.MaxAmount;
if ( cur.MagAmmoType )
{
let mag = MagAmmo(CPlayer.mo.FindInventory(cur.MagAmmoType));
// theoretically this should never be null, but nevertheless...
if ( mag )
{
amt = amt*mag.ClipSize+mag.Amount;
amax = amax*mag.ClipSize+mag.MaxAmount;
}
else
{
let def = GetDefaultByType(cur.MagAmmoType);
amt = amt*def.ClipSize;
amax = amax*def.ClipSize+def.MaxAmount;
}
}
}
bool used = false;
if ( CPlayer.ReadyWeapon && (CPlayer.ReadyWeapon is 'SWWMWeapon') )
used = SWWMWeapon(CPlayer.ReadyWeapon).UsesAmmo(a);
int scol = mhudfontcol[used?MCR_BRASS:MCR_WHITE];
int ncolor = (amt>0)?scol:mhudfontcol[MCR_RED];
int dcnt1 = 2-int(Log10(clamp(amt,1,999)));
int dcnt2 = 2-int(Log10(clamp(amax,1,999)));
for ( int j=0; j<dcnt1; j++ ) Screen.DrawChar(MiniHUDFont,ncolor,xx+20+j*4,yy,0x30,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_ColorOverlay,Color(160,0,0,0));
for ( int j=0; j<dcnt2; j++ ) Screen.DrawChar(MiniHUDFont,scol,xx+38+j*4,yy,0x30,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_ColorOverlay,Color(160,0,0,0));
str = AmmoNames[i];
Screen.DrawText(MiniHUDFont,scol,xx,yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
str = "/";
Screen.DrawText(MiniHUDFont,scol,xx+32,yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_ColorOverlay,Color(80,0,0,0));
str = String.Format("%3d",clamp(amt,0,999));
Screen.DrawText(MiniHUDFont,ncolor,xx+20,yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
str = String.Format("%3d",clamp(amax,0,999));
Screen.DrawText(MiniHUDFont,scol,xx+38,yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
let f = AmmoFlash[i];
if ( f && (gametic < f) )
{
double alph = max((f-(gametic+FracTic))/25.,0.)**1.5;
str = String.Format("%3d",clamp(amt,0,999));
Screen.DrawText(MiniHUDFont,mhudfontcol[MCR_FLASH],xx+20,yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_Alpha,alph,DTA_LegacyRenderStyle,STYLE_Add);
}
f = AmmoMaxFlash[i];
if ( f && (gametic < f) )
{
double alph = max((f-(gametic+FracTic))/25.,0.)**1.5;
str = String.Format("%3d",clamp(amax,0,999));
Screen.DrawText(MiniHUDFont,mhudfontcol[MCR_FLASH],xx+38,yy,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true,DTA_Alpha,alph,DTA_LegacyRenderStyle,STYLE_Add);
}
xx -= 2;
}
if ( bDrewAmmo )
{
yy -= 2;
Screen.DrawTexture(AmmoTex[0],false,xx,yy,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
}
// score
String sstr = String.Format("%09d",int(ScoreInter.GetValue()));
xx = ss.x-(margin+48);
if ( bDrewAmmo ) yy -= 12;
else yy = ss.y-(margin+22);
Screen.DrawTexture(ScoreTex,false,xx,yy,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
xx += 10;
yy += 2;
Screen.DrawText(MiniHUDFont,mhudfontcol[MCR_BRASS],xx,yy,sstr,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
int bx = bDrewAmmo?56:50;
// ammo display
if ( CPlayer.ReadyWeapon is 'SWWMWeapon' ) SWWMWeapon(CPlayer.ReadyWeapon).DrawWeapon(FracTic,ss.x-(margin+bx),ss.y-(margin+12),hs,ss);
else if ( CPlayer.ReadyWeapon )
{
// generic display
double xx = ss.x-(margin+bx+2), yy = ss.y-(margin+22);
String str;
int len;
if ( CPlayer.ReadyWeapon.Ammo2 && (CPlayer.ReadyWeapon.Ammo2 != CPlayer.ReadyWeapon.Ammo1) )
{
str = String.Format("%d",CPlayer.ReadyWeapon.Ammo2.Amount);
len = str.Length();
yy -= 12;
Screen.DrawTexture(GenericAmmoTex[2],false,xx,yy,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
for ( int i=0; i<len; i++ )
{
xx -= 4;
Screen.DrawTexture(GenericAmmoTex[1],false,xx,yy,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
}
Screen.DrawTexture(GenericAmmoTex[0],false,xx-2,yy,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
Screen.DrawText(MiniHUDFont,mhudfontcol[(CPlayer.ReadyWeapon.Ammo2.Amount<=0)?MCR_RED:MCR_BRASS],xx,yy+2,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
yy += 12;
}
xx = ss.x-(margin+bx+2);
if ( CPlayer.ReadyWeapon.Ammo1 )
{
str = String.Format("%d",CPlayer.ReadyWeapon.Ammo1.Amount);
len = str.Length();
Screen.DrawTexture(GenericAmmoTex[2],false,xx,yy,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
for ( int i=0; i<len; i++ )
{
xx -= 4;
Screen.DrawTexture(GenericAmmoTex[1],false,xx,yy,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
}
Screen.DrawTexture(GenericAmmoTex[0],false,xx-2,yy,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
Screen.DrawText(MiniHUDFont,mhudfontcol[(CPlayer.ReadyWeapon.Ammo1.Amount<=0)?MCR_RED:MCR_BRASS],xx,yy+2,str,DTA_VirtualWidthF,ss.x,DTA_VirtualHeightF,ss.y,DTA_KeepRatio,true);
}
}
}
}