Skip to content

Commit

Permalink
Merge pull request #35 from luigi-budd/main
Browse files Browse the repository at this point in the history
Add pf viewpoint
  • Loading branch information
Jiskster authored Sep 7, 2024
2 parents bf52d3b + b8c15bb commit dde14d6
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 28 deletions.
43 changes: 43 additions & 0 deletions src/Lua/HUD/hud_pfviewpoint.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
local pfviewpoint_hud = function(v, p)
if not PTSR.IsPTSR() then return end
if not (p.spectator) then return end

local me = p.realmo

if not (me and me.valid) then return end

if not (me.pfviewpoint)
v.drawString(160,30,
"Press TOSSFLAG to",
V_SNAPTOTOP|V_20TRANS,
"thin-center"
)
v.drawString(160,38,
"spectate Pizzaface!",
V_SNAPTOTOP|V_20TRANS,
"thin-center"
)

else
local maskdata = PTSR.PFMaskData[PTSR.pizzas[me.pfindex].pizzastyle or 1]

v.drawString(160,30,
"VIEWPOINT:",
V_SNAPTOTOP|V_YELLOWMAP,
"thin-center"
)
v.drawString(160,38,
maskdata.name,
V_SNAPTOTOP|V_ALLOWLOWERCASE,
"thin-center"
)
v.drawString(160,46,
"Press any button to stop",
V_SNAPTOTOP|V_20TRANS,
"thin-center"
)

end
end

customhud.SetupItem("PTSR_pfviewpoint", ptsr_hudmodname, pfviewpoint_hud, "game", 0)
12 changes: 11 additions & 1 deletion src/Lua/HUD/name_tags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ hud.add( function(v, player, camera)
if (not PTSR.IsPTSR()) then return end
if PTSR.gameover then return end

if (player.awayviewmobj and player.spectator)
return
end

for _, tmo in pairs(PTSR.w2s_mobjs) do
if not tmo or not tmo.valid then continue end
if tmo.player and player == tmo.player then continue end
Expand All @@ -94,7 +98,13 @@ hud.add( function(v, player, camera)
or tmo.type == MT_PT_JUGGERNAUTCROWN) then
continue
end


--WAIT!!!!! check if we're spectating this pf first before doing anything else!
if (tmo.type == MT_PIZZA_ENEMY)
and (tmo == player.awayviewmobj)
continue
end

--if not tmo.player and not mobjinfo[tmo.type].npc_name then continue end

--how far away is the other mobj?
Expand Down
75 changes: 75 additions & 0 deletions src/Lua/Hooks/PlayerThinks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ addHook("PlayerThink", function(player)

player.ptsr.rank_scaleTime = FU
end

end)

--leaderboard stuff -luigi budd
Expand Down Expand Up @@ -308,6 +309,7 @@ addHook('ThinkFrame', function()
local p1 = a
local p2 = b

--ALWAYS promote a P rank than an S with higher score
if ranktonum[a.ptsr.rank] ~= ranktonum[b.ptsr.rank]
if ranktonum[a.ptsr.rank] > ranktonum[b.ptsr.rank]
return true
Expand Down Expand Up @@ -347,4 +349,77 @@ addHook("PostThinkFrame", function()
end
end
end
end)

--PF Viewpoint (spectate pizzafaces)
addHook("PlayerThink",function(p)
if not (p.spectator) then return end

local me = p.realmo

if (PTSR.gameover)
me.pfviewpoint = false
me.pfindex = 0
p.awayviewmobj = nil
return
end

--SURE
if (p.cmd.buttons & BT_TOSSFLAG)
if not (p.lastbuttons & BT_TOSSFLAG)
if me.pfindex == nil
me.pfindex = 1
else
me.pfindex = $+1
end
if me.pfindex > #PTSR.pizzas
me.pfviewpoint = false
me.pfindex = 0
p.awayviewmobj = nil
return
end
me.pfviewpoint = true
end
end

if me.pfviewpoint
local mypizza = PTSR.pizzas[me.pfindex]
local target = mypizza.pizza_target
local cameraman = mypizza.cameraman

--pressed something?
if (p.cmd.buttons &~BT_TOSSFLAG) ~= 0
or (p.cmd.forwardmove or p.cmd.sidemove)
--...orrr if the pf doesnt have a cameraman
or not (cameraman and cameraman.valid)
--stop spectating!
me.pfviewpoint = false
me.pfindex = 0
p.awayviewmobj = nil
return
end

p.awayviewmobj = cameraman
p.awayviewtics = TICRATE

if (target and target.valid)
local dist = R_PointToDist2(
target.x,
target.y,
mypizza.x,
mypizza.y
)

if dist ~= 0
p.awayviewaiming = R_PointToAngle2(0,
mypizza.z,
dist,
mypizza.pizza_target.z
)
else
p.awayviewaiming = 0
end
end
end

end)
1 change: 1 addition & 0 deletions src/Lua/Init/initmap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ local function InitMap()
PTSR.aipf = nil
PTSR.difficulty = FRACUNIT
PTSR.pizzaface_speed_multi = FRACUNIT
PTSR.pizzas = {}

PTSR.vote_maplist = {}

Expand Down
34 changes: 19 additions & 15 deletions src/Lua/Libraries/sglib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,28 @@ rawset(_G, "R_FOV", function(num)
return fovvars.value
end)

// This version of the function was prototyped in Lua by Nev3r ... a HUGE thank you goes out to them!
-- This version of the function was prototyped in Lua by Nev3r ... a HUGE thank you goes out to them!
-- if only it was exposed
local baseFov = 90*FRACUNIT
local BASEVIDWIDTH = 320
local BASEVIDHEIGHT = 200
rawset(_G, "SG_ObjectTracking", function(v, p, c, point, reverse, allowspectator)
//local cameraNum = c.pnum - 1
--local cameraNum = c.pnum - 1
local viewx, viewy, viewz, viewangle, aimingangle, viewroll = SG_GetViewVars(v, p, c, allowspectator)

// Initialize defaults
-- Initialize defaults
local result = {
x = 0,
y = 0,
scale = FRACUNIT,
onScreen = false
}

// Take the view's properties as necessary.
if (viewx == nil and viewy == nil and (p.spectator and not allowspectator))
return result
end

-- Take the view's properties as necessary.
local viewpointAngle, viewpointAiming, viewpointRoll
if reverse then
viewpointAngle = viewangle + ANGLE_180
Expand All @@ -65,60 +69,60 @@ rawset(_G, "SG_ObjectTracking", function(v, p, c, point, reverse, allowspectator
end
end

// Calculate screen size adjustments.
-- Calculate screen size adjustments.
local screenWidth = v.width()/v.dupx()
local screenHeight = v.height()/v.dupy()

-- what's the difference between this and r_splitscreen?
-- future G: seems to alternate between view count and view number depending on where you are in the codebase
-- may i interest the Krew in stplyrnum? :^)
if splitscreen then
// Half-height screens (this isn't kart's splitscreen!)
-- Half-height screens (this isn't kart's splitscreen!)
screenHeight = $ >> 1
end

local screenHalfW = (screenWidth >> 1) << FRACBITS
local screenHalfH = (screenHeight >> 1) << FRACBITS

// Calculate FOV adjustments.
-- Calculate FOV adjustments.
local fovDiff = R_FOV() - baseFov
local fov = ((baseFov - fovDiff) / 2) - (p.fovadd / 2)
local fovTangent = tan(FixedAngle(fov))

if splitscreen == 1 then
// Splitscreen FOV is adjusted to maintain expected vertical view
-- Splitscreen FOV is adjusted to maintain expected vertical view
fovTangent = 10*fovTangent/17
end

local fg = (screenWidth >> 1) * fovTangent

// Determine viewpoint factors.
-- Determine viewpoint factors.

local h = R_PointToDist2(point.x, point.y, viewx, viewy)
local da = viewpointAngle - R_PointToAngle2(viewx, viewy, point.x, point.y)
local dp = viewpointAiming - R_PointToAngle2(0, 0, h, viewz)

if reverse then da = -da end

// Set results relative to top left!
-- Set results relative to top left!
result.x = FixedMul(tan(da), fg)
result.y = FixedMul((tan(viewpointAiming) - FixedDiv((point.z - viewz), 1 + FixedMul(cos(da), h))), fg)

result.angle = da
result.pitch = dp
result.fov = fg

// Rotate for screen roll...
-- Rotate for screen roll...
if viewpointRoll then
local tempx = result.x
result.x = FixedMul(cos(viewpointRoll), tempx) - FixedMul(sin(viewpointRoll), result.y)
result.y = FixedMul(sin(viewpointRoll), tempx) + FixedMul(cos(viewpointRoll), result.y)
end

// Flipped screen?
-- Flipped screen?
if encoremode then result.x = -result.x end

// Center results.
-- Center results.
result.x = $ + screenHalfW
result.y = $ + screenHalfH

Expand All @@ -145,7 +149,7 @@ rawset(_G, "SG_ObjectTracking", function(v, p, c, point, reverse, allowspectator

result.onScreen = not ((abs(da) > ANG60) or (abs(viewpointAiming - R_PointToAngle2(0, 0, h, (viewz - point.z))) > ANGLE_45))

// Cheap dirty hacks for some split-screen related cases
-- Cheap dirty hacks for some split-screen related cases
if result.x < 0 or result.x > (screenWidth << FRACBITS) then
result.onScreen = false
end
Expand All @@ -154,7 +158,7 @@ rawset(_G, "SG_ObjectTracking", function(v, p, c, point, reverse, allowspectator
result.onScreen = false
end

// adjust to non-green-resolution screen coordinates
-- adjust to non-green-resolution screen coordinates
result.x = $ - ((v.width()/v.dupx()) - BASEVIDWIDTH)<<(FRACBITS-(splitscreen and 2 or 1))
result.y = $ - ((v.height()/v.dupy()) - BASEVIDHEIGHT)<<(FRACBITS-(splitscreen and 2 or 1))
return result
Expand Down
4 changes: 4 additions & 0 deletions src/Lua/main_game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ rawset(_G, "PTSR", { -- variables
gamemode = 1,

nextgamemode = 1,

pizzas = {},
})

PTSR.isOvertime = function()
Expand Down Expand Up @@ -279,6 +281,8 @@ addHook("NetVars", function(net)
"difficulty",

"pizzaface_speed_multi",

"pizzas",
}

for i,v in ipairs(sync_list) do
Expand Down
Loading

0 comments on commit dde14d6

Please sign in to comment.