Help needed to undrunkify a SPB while allowing it to speed up

Latius

Hybrid Kart Mapper/Porter
I'm trying to do some tweaks to the SPB code so that it gets faster (along with the player) the longer a race takes, but I ended up making a drunken SPB instead:
kart0251.gif


I have no idea where in the code I've made that caused the SPB to be drunk, but this is the code I currently have for it:

Code:
local function deltaSPBThinker(spb)
	if spb.threshold or not (server.dspba_server and server.dspba_server.running) then 
		return
	end
    if spb.extravalue1 == 1 
        if spb.tracer and spb.tracer.player
			local p = spb.tracer.player
			local pmo = spb.tracer
			local wspeed = spb.movefactor
			local xyspeed
			local zspeed
			local defspeed = wspeed
			local range = 160*pmo.scale
			local speedmodstuff = FixedDiv(server.dspba_server.curspeedmod, 100) //This gives a FRACUNIT percentage of what the speed mod is - it starts at 100%, and increases over time
			local cx = 0
			local cy = 0
			
			spb.flags = $ & !MF_NOCLIPTHING
			if not S_SoundPlaying(spb, spb.info.activesound) then S_StartSound(spb, spb.info.activesound) end
			
			local fracmax = 32
			local spark = ((10 - p.kartspeed) + p.kartweight) / 2
			local easiness = ((p.kartspeed + (10 - spark)) << FRACBITS) / 2
			spb.lastlook = #p
			if P_IsObjectOnGround(pmo)
				defspeed = FixedMul(((fracmax+1)<<FRACBITS) - easiness, K_GetKartSpeed(p, false)) / fracmax
				defspeed = FixedMul($, speedmodstuff)
			else
				defspeed = (7 * p.speed) / 8
			end
			
			cx = p.cmomx
			cy = p.cmomy
			
			local dist = P_AproxDistance(P_AproxDistance(spb.x - pmo.x, spb.y - pmo.y), spb.z - pmo.z)

			wspeed = FixedMul(defspeed, FRACUNIT + FixedDiv(dist-range, range))
			if (wspeed < defspeed)
				wspeed = defspeed
			elseif (wspeed > (3*defspeed)/2)
				wspeed = (3*defspeed)/2
			end
			if (wspeed < 20*pmo.scale)
				wspeed = 20*pmo.scale
			end
			if (p.pflags & PF_SLIDING)
				wspeed = p.speed/2
			end
			
			local hang = R_PointToAngle2(spb.x, spb.y, pmo.x, pmo.y)
			local vang = R_PointToAngle2(0, spb.z, dist, pmo.z)

			if (wspeed > spb.cvmem)
				spb.cvmem = $ + ((wspeed - $) / TICRATE)
			else
				spb.cvmem = wspeed
			end
			
			local input = hang - spb.angle
			local invert = (input > ANGLE_180)
			if invert then
				input = InvAngle(input)
			end
			
			xyspeed = FixedMul(spb.cvmem, max(0, (((180<<FRACBITS) - AngleFixed(input)) / 90) - FRACUNIT))
			
			input = FixedAngle(AngleFixed($)/4)
			if invert then
				input = InvAngle(input)
			end
			spb.angle = $ + input
			
			input = vang - spb.movedir
			invert = (input > ANGLE_180)
			if (invert) then
				input = InvAngle(input)
			end
			
			// Slow down when turning; might as well do it for momz, since we do it above too
			zspeed = FixedMul(spb.cvmem, max(0, (((180<<FRACBITS) - AngleFixed(input)) / 90) - FRACUNIT))

			input = FixedAngle(AngleFixed(input)/4)
			if (invert) then
				input = InvAngle(input)
			end
			spb.movedir = $ + input
			
			spb.momx = cx + FixedMul(FixedMul(xyspeed, cos(spb.angle)), cos(spb.movedir))
			spb.momy = cy + FixedMul(FixedMul(xyspeed, sin(spb.angle)), cos(spb.movedir))
			spb.momz = FixedMul(zspeed, sin(spb.movedir))

			if ((R_PointToDist2(0, 0, spb.momx, spb.momy) > (16*p.speed)/15)) and (xyspeed > (K_GetKartSpeed(p, false)/4)) then
				local fast = P_SpawnMobj(spb.x + (P_RandomRange(-24,24) * spb.scale),
					spb.y + (P_RandomRange(-24,24) * spb.scale),
					spb.z + (spb.height/2) + (P_RandomRange(-24,24) * spb.scale),
					MT_FASTLINE)
				fast.angle = R_PointToAngle2(0, 0, spb.momx, spb.momy)
				fast.color = SKINCOLOR_RED
				fast.colorized = true
				K_MatchGenericExtraFlags(fast, spb)
			end
			
		end
	end
end

addHook("MobjThinker", deltaSPBThinker, MT_SPB)

Could anyone help me find where in the code I made a mistake so that I can fix this and finally put the finishing touches on a mod I'm working on?
 

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top