nades do player damage now; added /squad

This commit is contained in:
Ben Russell (300178622) 2012-12-18 16:27:53 +13:00
parent 1ca3ed9c11
commit 712b0c86f9
6 changed files with 70 additions and 19 deletions

View File

@ -136,7 +136,7 @@ Iceball Base Mod:
note, for C->S pid MUST be 0x00 note, for C->S pid MUST be 0x00
0x05 pid team weapon score.s16 kills.s16 deaths.s16 namelen name[namelen]: (S->C) @ 0x05 pid team weapon score.s16 kills.s16 deaths.s16 name.z squad.z: (S->C) @
adds player to server adds player to server
note, this can be used to update a player on the server note, this can be used to update a player on the server

View File

@ -450,19 +450,21 @@ function h_tick_main(sec_current, sec_delta)
plr.set_orient_recv(ya, xa, keys) plr.set_orient_recv(ya, xa, keys)
end end
elseif cid == 0x05 then elseif cid == 0x05 then
-- 0x05 pid team weapon score.s16 kills.s16 deaths.s16 namelen name[namelen]: (S->C) -- 0x05 pid team weapon score.s16 kills.s16 deaths.s16 name.z squad.z: (S->C)
local pid, tidx, wpn, score, kills, deaths, name local pid, tidx, wpn, score, kills, deaths, name, squad
pid, tidx, wpn, score, kills, deaths, name, pkt pid, tidx, wpn, score, kills, deaths, name, squad, pkt
= common.net_unpack("Bbbhhhz", pkt) = common.net_unpack("Bbbhhhzz", pkt)
if players[pid] then if players[pid] then
-- TODO: update wpn/tidx/name -- TODO: update wpn/tidx/name
players[pid].squad = (squad ~= "" and squad) or nil
players[pid].name = name
else else
players[pid] = new_player({ players[pid] = new_player({
name = name, name = name,
--[=[squad = squads[(i-1) % 2][ --[=[squad = squads[(i-1) % 2][
(math.floor((i-1)/2) % 4)+1],]=] (math.floor((i-1)/2) % 4)+1],]=]
squad = nil, squad = (squad ~= "" and squad) or nil,
team = tidx, team = tidx,
weapon = wpn, weapon = wpn,
pid = pid, pid = pid,

View File

@ -68,6 +68,8 @@ MODE_NADE_SPEED = 30.0
MODE_NADE_STEP = 0.1 MODE_NADE_STEP = 0.1
MODE_NADE_ADAMP = 0.5 MODE_NADE_ADAMP = 0.5
MODE_NADE_BDAMP = 1.0 MODE_NADE_BDAMP = 1.0
MODE_NADE_RANGE = 8.0
MODE_NADE_DAMAGE = 500.0
MODE_MINIMAP_RCIRC = false MODE_MINIMAP_RCIRC = false
MODE_ENABLE_MINIMAP = true MODE_ENABLE_MINIMAP = true

View File

@ -247,6 +247,16 @@ function server.hook_tick(sec_current, sec_delta)
local s = nil local s = nil
if string.sub(msg,1,4) == "/me " then if string.sub(msg,1,4) == "/me " then
s = "* "..plr.name.." "..string.sub(msg,5) s = "* "..plr.name.." "..string.sub(msg,5)
elseif string.sub(msg,1,7) == "/squad " then
local s = string.sub(msg,8)
if s ~= "" then
if s == "none" then
plr.squad = nil
else
plr.squad = s
end
plr.update_score()
end
elseif msg == "/kill" then elseif msg == "/kill" then
plr.set_health_damage(0, 0xFF800000, plr.name.." shuffled off this mortal coil", plr) plr.set_health_damage(0, 0xFF800000, plr.name.." shuffled off this mortal coil", plr)
else else
@ -290,11 +300,11 @@ function server.hook_tick(sec_current, sec_delta)
for i=1,players.max do for i=1,players.max do
local plr = players[i] local plr = players[i]
if plr then if plr then
common.net_send(sockfd, common.net_pack("BBBBhhhz", common.net_send(sockfd, common.net_pack("BBBBhhhzz",
0x05, i, 0x05, i,
plr.team, plr.weapon, plr.team, plr.weapon,
plr.score, plr.kills, plr.deaths, plr.score, plr.kills, plr.deaths,
plr.name)) plr.name, plr.squad))
common.net_send(sockfd, common.net_pack("BBfffBB", common.net_send(sockfd, common.net_pack("BBfffBB",
0x10, i, 0x10, i,
plr.x, plr.y, plr.z, plr.x, plr.y, plr.z,
@ -322,11 +332,11 @@ function server.hook_tick(sec_current, sec_delta)
end end
-- relay this player to everyone -- relay this player to everyone
net_broadcast(nil, common.net_pack("BBBBhhhz", net_broadcast(nil, common.net_pack("BBBBhhhzz",
0x05, cli.plrid, 0x05, cli.plrid,
plr.team, plr.weapon, plr.team, plr.weapon,
plr.score, plr.kills, plr.deaths, plr.score, plr.kills, plr.deaths,
plr.name)) plr.name, plr.squad))
net_broadcast(nil, common.net_pack("BBfffBB", net_broadcast(nil, common.net_pack("BBfffBB",
0x10, cli.plrid, 0x10, cli.plrid,
plr.x, plr.y, plr.z, plr.x, plr.y, plr.z,
@ -387,7 +397,8 @@ function server.hook_tick(sec_current, sec_delta)
vx = vx/256, vx = vx/256,
vy = vy/256, vy = vy/256,
vz = vz/256, vz = vz/256,
fuse = fuse/100 fuse = fuse/100,
pid = cli.plrid
}) })
nade_add(n) nade_add(n)
net_broadcast(sockfd, common.net_pack("BhhhhhhH", net_broadcast(sockfd, common.net_pack("BhhhhhhH",

View File

@ -52,6 +52,8 @@ function new_nade(settings)
vy = settings.vy, vy = settings.vy,
vz = settings.vz, vz = settings.vz,
pid = settings.pid,
trem = 0.0, trem = 0.0,
fuse = settings.fuse, fuse = settings.fuse,
dead = false dead = false
@ -102,6 +104,36 @@ function new_nade(settings)
local xlen,ylen,zlen local xlen,ylen,zlen
xlen,ylen,zlen = common.map_get_dims() xlen,ylen,zlen = common.map_get_dims()
local hplr = this.pid and players[this.pid]
local i
for i=1,players.max do
local plr = players[i]
if plr and ((not hplr) or plr == hplr or plr.team ~= hplr.team) then
local dx,dy,dz
dx = plr.x-this.x
dy = (plr.y+0.9)-this.y
dz = plr.z-this.z
local dd = dx*dx+dy*dy+dz*dz
if dd < MODE_NADE_RANGE*MODE_NADE_RANGE then
dd = math.sqrt(dd)
dx = dx/dd
dy = dy/dd
dz = dz/dd
local nd
nd = trace_map_ray_dist(this.x,this.y,this.z, dx,dy,dz, dd)
if not nd then
local dmg = ((MODE_NADE_RANGE-dd)/MODE_NADE_RANGE)
dmg = dmg * dmg
dmg = dmg * MODE_NADE_DAMAGE
plr.grenade_damage(dmg, hplr)
end
end
end
end
if map_block_get(x0,y0,z0) ~= nil then if map_block_get(x0,y0,z0) ~= nil then
if y0 < ylen-2 then if y0 < ylen-2 then
map_block_break(x0,y0,z0) map_block_break(x0,y0,z0)
@ -121,7 +153,7 @@ function new_nade(settings)
end end
end end
-- TODO: hurt players!
end end
function this.tick(sec_current, sec_delta) function this.tick(sec_current, sec_delta)

View File

@ -286,11 +286,11 @@ function new_player(settings)
end end
function this.update_score() function this.update_score()
net_broadcast(nil, common.net_pack("BBBBhhhz", net_broadcast(nil, common.net_pack("BBBBhhhzz",
0x05, this.pid, 0x05, this.pid,
this.team, this.weapon, this.team, this.weapon,
this.score, this.kills, this.deaths, this.score, this.kills, this.deaths,
this.name)) this.name, this.squad))
end end
function this.tent_restock() function this.tent_restock()
@ -405,9 +405,9 @@ function new_player(settings)
function this.grenade_damage(amt, enemy) function this.grenade_damage(amt, enemy)
--print("damage",this.name,part,amt) --print("damage",this.name,part,amt)
local midmsg = " killed " local midmsg = " grenaded "
if this.team == enemy.team then if this.team == enemy.team and this ~= enemy then
midmsg = " teamkilled " error("THIS SHOULD NEVER HAPPEN")
end end
local r,g,b local r,g,b
@ -1350,7 +1350,11 @@ function new_player(settings)
for i=1,players.max do for i=1,players.max do
local plr = players[i] local plr = players[i]
if plr ~= nil then if plr ~= nil then
local s = plr.name.." #"..i..": " local sn = plr.name
if plr.squad then
sn = sn.." ["..plr.squad.."]"
end
local s = sn.." #"..i..": "
..plr.score.." ("..plr.kills.."/"..plr.deaths..")" ..plr.score.." ("..plr.kills.."/"..plr.deaths..")"
if plr.team == 1 then if plr.team == 1 then
font_mini.print(w / 2 + 50, gi * 15 + 150 font_mini.print(w / 2 + 50, gi * 15 + 150
@ -1358,7 +1362,7 @@ function new_player(settings)
, s) , s)
gi = gi + 1 gi = gi + 1
else else
font_mini.print(w / 2 - 50 - (6 * #plr.name), bi * 15 + 150 font_mini.print(w / 2 - 50 - (6 * #s), bi * 15 + 150
, argb_split_to_merged(150, 150, 255, 255) , argb_split_to_merged(150, 150, 255, 255)
, s) , s)
bi = bi + 1 bi = bi + 1