From c15847a10a0f46373215ee05258fba5e30a29466 Mon Sep 17 00:00:00 2001 From: Marisa Kirisame Date: Sat, 15 Sep 2018 14:14:34 +0200 Subject: [PATCH] One half of "swinger" recoil system added. --- zscript/biorifle.zsc | 8 +++- zscript/chainsaw.zsc | 15 +++++- zscript/enforcer.zsc | 2 + zscript/impacthammer.zsc | 3 ++ zscript/pulsegun.zsc | 2 + zscript/shockrifle.zsc | 16 ++++++- zscript/utcommon.zsc | 100 +++++++++++++++++++++++++++++++++++++++ 7 files changed, 141 insertions(+), 5 deletions(-) diff --git a/zscript/biorifle.zsc b/zscript/biorifle.zsc index 9bf3e6e..00f4286 100644 --- a/zscript/biorifle.zsc +++ b/zscript/biorifle.zsc @@ -662,8 +662,13 @@ Class BioRifle : UTWeapon { p = Spawn("BioGlob",origin); p.A_SetScale(1.0+invoker.charge*0.8); + UTMainHandler.DoSwing(self,(FRandom[GES](-0.6,-1.3),FRandom[GES](-0.9,-0.2)),1+invoker.charge*0.3,-0.1,3,SWING_Spring2,3); + } + else + { + p = Spawn("BioGel",origin); + UTMainHandler.DoSwing(self,(FRandom[GES](-0.6,-1.3),FRandom[GES](-0.9,-0.2)),2,-0.5,2,SWING_Spring2,2); } - else p = Spawn("BioGel",origin); p.angle = angle; p.pitch = BulletSlope(); p.vel = (cos(p.angle)*cos(p.pitch),sin(p.angle)*cos(p.pitch),-sin(p.pitch))*p.speed; @@ -692,6 +697,7 @@ Class BioRifle : UTWeapon { Weapon weap = Weapon(invoker); if ( !weap ) return; + UTMainHandler.DoSwing(self,(FRandom[GES](-1,1),FRandom[GES](-1,1)),0.02*invoker.charge,0,5,SWING_Spring2); if ( invoker.charge >= 5.1 ) return; if ( weap.Ammo1.Amount <= 0 ) return; if ( !weap.DepleteAmmo(weap.bAltFire,true,1) ) return; diff --git a/zscript/chainsaw.zsc b/zscript/chainsaw.zsc index ba1d06d..93a3e20 100644 --- a/zscript/chainsaw.zsc +++ b/zscript/chainsaw.zsc @@ -46,6 +46,7 @@ Class UTChainsaw : UTWeapon action void A_SawHit() { A_QuakeEx(2,2,2,2,0,1,"",QF_RELATIVE,rollIntensity:0.15); + UTMainHandler.DoSwing(self,(FRandom[Chainsaw](-1,1),FRandom[Chainsaw](-1,1)),0.6,-0.2,2,SWING_Spring); invoker.sawcnt += 1./TICRATE; if ( invoker.sawcnt < 0.15 ) return; invoker.sawcnt = 0; @@ -86,6 +87,7 @@ Class UTChainsaw : UTWeapon action void A_SawSwipe( bool initial = false ) { A_QuakeEx(2,2,2,3,0,1,"",QF_RELATIVE,rollIntensity:0.15); + UTMainHandler.DoSwing(self,(FRandom[Chainsaw](-1,1),FRandom[Chainsaw](-1,1)),0.6,-0.2,2,SWING_Spring); if ( initial ) invoker.FireEffect(); A_AlertMonsters(); Vector3 x, y, z; @@ -136,6 +138,7 @@ Class UTChainsaw : UTWeapon A_AlertMonsters(); if ( bAlt ) A_QuakeEx(1,1,1,3,0,1,"",QF_RELATIVE,rollIntensity:0.4); else A_QuakeEx(0,0,0,2,0,1,"",QF_RELATIVE,rollIntensity:0.2); + UTMainHandler.DoSwing(self,(FRandom[Chainsaw](-1,1),FRandom[Chainsaw](-1,1)),0.25,-0.1,2,SWING_Spring); if ( bAlt || Random[Chainsaw](0,2) ) return; Vector3 x, y, z; [x, y, z] = Matrix4.GetAxes(pitch,angle,roll); @@ -232,9 +235,17 @@ Class UTChainsaw : UTWeapon CSWJ FEDCBA 1 A_Vibrate(); Goto Idle; AltFire: - CSWA A 0 A_PlaySound("chainsaw/fire",CHAN_6); + CSWA A 0 + { + A_PlaySound("chainsaw/fire",CHAN_6); + UTMainHandler.DoSwing(self,(FRandom[Chainsaw](-0.8,-1.2),FRandom[Chainsaw](-0.4,-0.7)),0,1,5,SWING_Spring2,6); + } CSWA ABCDE 2 A_Vibrate(true); - CSWA F 2 A_Overlay(PSP_WEAPON+1,"AltFireSwipes"); + CSWA F 2 + { + A_Overlay(PSP_WEAPON+1,"AltFireSwipes"); + UTMainHandler.DoSwing(self,(FRandom[Chainsaw](0.8,1.2),FRandom[Chainsaw](0,0)),0,2,6,SWING_Spring2); + } CSWA GHIJ 2; CSWA K 2 A_Vibrate(true); CSWA K 0 A_PlaySound("chainsaw/idle",CHAN_6,looping:true); diff --git a/zscript/enforcer.zsc b/zscript/enforcer.zsc index 3d9836f..1c0b826 100644 --- a/zscript/enforcer.zsc +++ b/zscript/enforcer.zsc @@ -291,6 +291,7 @@ Class Enforcer : UTWeapon else A_Overlay(-3,"LeftMuzzleFlash"); A_OverlayFlags(-3,PSPF_RENDERSTYLE|PSPF_FORCESTYLE,true); A_OverlayRenderstyle(-3,STYLE_Add); + UTMainHandler.DoSwing(self,(FRandom[Enforcer](0.5,0.2),FRandom[Enforcer](-0.3,0.2)),2,0,1,SWING_Spring2); } else { @@ -298,6 +299,7 @@ Class Enforcer : UTWeapon else A_Overlay(-2,"MuzzleFlash"); A_OverlayFlags(-2,PSPF_RENDERSTYLE|PSPF_FORCESTYLE,true); A_OverlayRenderstyle(-2,STYLE_Add); + UTMainHandler.DoSwing(self,(FRandom[Enforcer](-0.2,-0.5),FRandom[Enforcer](-0.3,0.2)),2,0,1,SWING_Spring2); } Vector3 x, y, z, x2, y2, z2; [x, y, z] = Matrix4.GetAxes(pitch,angle,roll); diff --git a/zscript/impacthammer.zsc b/zscript/impacthammer.zsc index 1456c83..86cf0cc 100644 --- a/zscript/impacthammer.zsc +++ b/zscript/impacthammer.zsc @@ -59,6 +59,7 @@ Class ImpactHammer : UTWeapon A_AlertMonsters(); } A_QuakeEx(clamp(int(invoker.chargesize*3),0,3),clamp(int(invoker.chargesize*3),0,3),clamp(int(invoker.chargesize*3),0,3),amt+1,0,96,"",QF_RELATIVE,rollIntensity:clamp(invoker.chargesize*0.3,0,0.3)); + UTMainHandler.DoSwing(self,(FRandom[Impact](-1,1),FRandom[Impact](-1,1)),invoker.chargesize*0.1,0,1,SWING_Spring); } action void A_FireBlast() { @@ -66,6 +67,7 @@ Class ImpactHammer : UTWeapon if ( !weap ) return; A_PlaySound("impact/release",CHAN_WEAPON); invoker.FireEffect(); + UTMainHandler.DoSwing(self,(FRandom[Impact](-0.3,-1.5),FRandom[Impact](-1.2,-0.4)),3,-0.8,3,SWING_Spring2,3); A_AlertMonsters(); Vector3 x, y, z; [x, y, z] = Matrix4.GetAxes(pitch,angle,roll); @@ -127,6 +129,7 @@ Class ImpactHammer : UTWeapon if ( !weap ) return; A_PlaySound("impact/fire",CHAN_WEAPON); invoker.FireEffect(); + UTMainHandler.DoSwing(self,(FRandom[Impact](-0.3,-1.5),FRandom[Impact](-1.2,-0.4)),2,-0.6,2,SWING_Spring2,1); A_AlertMonsters(); A_QuakeEx(2,2,2,6,0,1,"",QF_RELATIVE|QF_SCALEDOWN,rollIntensity:0.1); Vector3 x, y, z; diff --git a/zscript/pulsegun.zsc b/zscript/pulsegun.zsc index 133cc7d..ddfa695 100644 --- a/zscript/pulsegun.zsc +++ b/zscript/pulsegun.zsc @@ -559,6 +559,7 @@ Class PulseGun : UTWeapon if ( !CVar.GetCVar('flak_pulsereload').GetBool() && (invoker.clipcount <= 0) ) invoker.clipcount = (weap.Ammo1.Amount>0)?Min(50,weap.Ammo1.Amount):50; invoker.FireEffect(); UTMainHandler.DoFlash(self,Color(32,128,255,128),1); + UTMainHandler.DoSwing(self,(FRandom[Pulse](-1,-1),FRandom[Pulse](-1,1)),0.1,-0.02,3,SWING_Spring2); A_AlertMonsters(); Vector3 x, y, z; [x, y, z] = Matrix4.GetAxes(pitch,angle,roll); @@ -619,6 +620,7 @@ Class PulseGun : UTWeapon if ( !CVar.GetCVar('flak_pulsereload').GetBool() && (invoker.clipcount <=0) ) invoker.clipcount = (weap.Ammo1.Amount>0)?Min(50,weap.Ammo1.Amount):50; invoker.FireEffect(); UTMainHandler.DoFlash(self,Color(32,128,255,128),1); + UTMainHandler.DoSwing(self,(FRandom[Pulse](-1,-1),FRandom[Pulse](-1,1)),0.3,-0.1,2,SWING_Spring3); A_AlertMonsters(); A_QuakeEx(1,1,1,2,0,1,"",QF_RELATIVE|QF_SCALEDOWN,rollIntensity:0.05); A_Overlay(-2,"MuzzleFlash"); diff --git a/zscript/shockrifle.zsc b/zscript/shockrifle.zsc index 7ae735e..9128c09 100644 --- a/zscript/shockrifle.zsc +++ b/zscript/shockrifle.zsc @@ -334,7 +334,11 @@ Class ShockBeam : Actor ExplodeMissile(null,t.Results.HitActor); if ( t.Results.HitActor is 'ShockHitbox' ) { - if ( target ) target.TakeInventory('ShockAmmo',2); + if ( target ) + { + target.TakeInventory('ShockAmmo',2); + UTMainHandler.DoSwing(target,(FRandom[ASMD](-0.1,-0.6),FRandom[ASMD](-0.1,0.5)),5,-1,3,SWING_Spring2,2); + } let b = t.Results.HitActor.target; UTMainHandler.DoBlast(b,250,70000); b.ExplodeMissile(null,self); @@ -557,7 +561,11 @@ Class SuperShockBeam : Actor ExplodeMissile(null,t.Results.HitActor); if ( t.Results.HitActor is 'ShockHitbox' ) { - if ( target ) target.TakeInventory('EnhancedShockAmmo',1); + if ( target ) + { + target.TakeInventory('EnhancedShockAmmo',1); + UTMainHandler.DoSwing(target,(FRandom[ASMD](-0.1,-0.6),FRandom[ASMD](-0.1,0.5)),10,-2,3,SWING_Spring2,2); + } let b = t.Results.HitActor.target; UTMainHandler.DoBlast(b,400,70000); b.ExplodeMissile(null,self); @@ -996,6 +1004,7 @@ Class ShockRifle : UTWeapon A_PlaySound("shock/fire",CHAN_WEAPON); invoker.FireEffect(); UTMainHandler.DoFlash(self,Color(128,128,0,255),1); + UTMainHandler.DoSwing(self,(FRandom[ASMD](-0.1,-0.6),FRandom[ASMD](-0.1,0.5)),2,-0.3,3,SWING_Spring3); A_AlertMonsters(); A_QuakeEx(2,2,2,4,0,1,"",QF_RELATIVE|QF_SCALEDOWN,rollIntensity:0.1); Vector3 x, y, z; @@ -1033,6 +1042,7 @@ Class ShockRifle : UTWeapon A_PlaySound("shock/altfire",CHAN_WEAPON); invoker.FireEffect(); UTMainHandler.DoFlash(self,Color(128,128,0,255),1); + UTMainHandler.DoSwing(self,(FRandom[ASMD](-0.1,-0.6),FRandom[ASMD](-0.1,0.5)),3,-0.4,3,SWING_Spring3); A_AlertMonsters(); A_QuakeEx(2,2,2,8,0,1,"",QF_RELATIVE|QF_SCALEDOWN,rollIntensity:0.1); Vector3 x, y, z; @@ -1177,6 +1187,7 @@ Class EnhancedShockRifle : UTWeapon A_PlaySound("shock/fire",CHAN_WEAPON); invoker.FireEffect(); UTMainHandler.DoFlash(self,Color(128,255,128,0),1); + UTMainHandler.DoSwing(self,(FRandom[ASMD](-0.1,-0.6),FRandom[ASMD](-0.1,0.5)),4,-0.6,3,SWING_Spring3); A_AlertMonsters(); A_QuakeEx(3,3,3,4,0,1,"",QF_RELATIVE|QF_SCALEDOWN,rollIntensity:0.15); Vector3 x, y, z; @@ -1214,6 +1225,7 @@ Class EnhancedShockRifle : UTWeapon A_PlaySound("shock/altfire",CHAN_WEAPON); invoker.FireEffect(); UTMainHandler.DoFlash(self,Color(128,255,128,0),1); + UTMainHandler.DoSwing(self,(FRandom[ASMD](-0.1,-0.6),FRandom[ASMD](-0.1,0.5)),6,-0.8,3,SWING_Spring3); A_AlertMonsters(); A_QuakeEx(3,3,3,4,0,1,"",QF_RELATIVE|QF_SCALEDOWN,rollIntensity:0.15); Vector3 x, y, z; diff --git a/zscript/utcommon.zsc b/zscript/utcommon.zsc index 1d0dd83..53b6254 100644 --- a/zscript/utcommon.zsc +++ b/zscript/utcommon.zsc @@ -1156,6 +1156,90 @@ Class ShredCorpseHitbox : Actor } } +Enum ESwingMode +{ + SWING_Straight, // constant increment + SWING_Spring, // bounces back after a delay + SWING_Spring2, // ... returning at half speed + SWING_Spring3, // ... returning at third speed +}; + +Class Swinger : Thinker +{ + Actor target; + Vector2 dir; + double inc; + int steps, mode, delay; + double str, tstr; + int cnt, cstate; + + Enum ESwingerState + { + STATE_Initial, + STATE_Wait, + STATE_Return, + STATE_ReturnSlow, + STATE_ReturnSlower, + }; + + override void Tick() + { + if ( !target ) cstate = -1; + switch ( cstate ) + { + case STATE_Initial: + target.A_SetAngle(target.angle+dir.x*str,SPF_INTERPOLATE); + target.A_SetPitch(target.pitch+dir.y*str,SPF_INTERPOLATE); + str += inc; + if ( ++cnt >= steps ) + { + cnt = 0; + str = tstr/steps; + cstate = (mode==SWING_Straight)?(-1):(delay>0)?STATE_Wait:(mode==SWING_Spring3)?STATE_ReturnSlower:(mode==SWING_Spring2)?STATE_ReturnSlow:STATE_Return; + } + else tstr += str; + break; + case STATE_Wait: + if ( ++cnt >= delay ) + { + cnt = 0; + cstate = (mode==SWING_Spring3)?STATE_ReturnSlower:(mode==SWING_Spring2)?STATE_ReturnSlow:STATE_Return; + } + break; + case STATE_Return: + target.A_SetAngle(target.angle-dir.x*str,SPF_INTERPOLATE); + target.A_SetPitch(target.pitch-dir.y*str,SPF_INTERPOLATE); + if ( ++cnt >= steps ) + { + cnt = 0; + cstate = -1; + } + break; + case STATE_ReturnSlow: + target.A_SetAngle(target.angle-dir.x*str/2.,SPF_INTERPOLATE); + target.A_SetPitch(target.pitch-dir.y*str/2.,SPF_INTERPOLATE); + if ( ++cnt >= steps*2 ) + { + cnt = 0; + cstate = -1; + } + break; + case STATE_ReturnSlower: + target.A_SetAngle(target.angle-dir.x*str/3.,SPF_INTERPOLATE); + target.A_SetPitch(target.pitch-dir.y*str/3.,SPF_INTERPOLATE); + if ( ++cnt >= steps*3 ) + { + cnt = 0; + cstate = -1; + } + break; + default: + Destroy(); + return; + } + } +} + Class GenericFlash : HUDMessageBase { Color col; @@ -1555,4 +1639,20 @@ Class UTMainHandler : StaticEventHandler if ( !Victim ) return; Victim.vel += HitDirection*(MomentumTransfer/(Thinker.TICRATE*Victim.Mass)); } + + static void DoSwing( Actor target, Vector2 dir, double initial, double inc, int steps, int mode = 0, int delay = 0 ) + { + let s = new("Swinger"); + s.ChangeStatNum(Thinker.STAT_USER); + s.target = target; + s.dir = dir; + s.inc = inc; + s.steps = steps; + s.mode = mode; + s.delay = delay; + s.cnt = 0; + s.cstate = 0; + s.str = initial; + s.tstr = initial; + } }