diff --git a/pkg/base/client_start.lua b/pkg/base/client_start.lua index e7d7081..52a0ad7 100644 --- a/pkg/base/client_start.lua +++ b/pkg/base/client_start.lua @@ -450,8 +450,8 @@ function h_tick_main(sec_current, sec_delta) else players[pid] = new_player({ name = name, - --[=[squad = squads[math.fmod(i-1,2)][ - math.fmod(math.floor((i-1)/2),4)+1],]=] + --[=[squad = squads[(i-1) % 2][ + (math.floor((i-1)/2) % 4)+1],]=] squad = nil, team = tidx, weapon = wpn, @@ -655,10 +655,10 @@ function h_tick_init(sec_current, sec_delta) for i=1,players.max do players[i] = new_player({ name = (players.current == i and user_config.name) or name_generate(), - --[=[squad = squads[math.fmod(i-1,2)][ - math.fmod(math.floor((i-1)/2),4)+1],]=] + --[=[squad = squads[(i-1) % 2][ + (math.floor((i-1)/2) % 4)+1],]=] squad = nil, - team = math.fmod(i-1,2), -- 0 == blue, 1 == green + team = (i-1) % 2, -- 0 == blue, 1 == green weapon = WPN_RIFLE, }) end diff --git a/pkg/base/lib_bits.lua b/pkg/base/lib_bits.lua index 4d029f9..229ba4d 100644 --- a/pkg/base/lib_bits.lua +++ b/pkg/base/lib_bits.lua @@ -17,7 +17,7 @@ function bit_unsign(a,m) m = math.pow(2,m) - local v = math.fmod(a,m) + local v = (a % m) if v < 0 then v = v + m end @@ -28,7 +28,7 @@ function bit_xor(a,b) local shift = 1 local v = 0 while a > 0 and b > 0 do - if (math.fmod(a,2) ~= 0) ~= (math.fmod(b,2) ~= 0) then + if ((a % 2) ~= 0) ~= ((b % 2) ~= 0) then v = v + shift end shift = shift * 2 @@ -42,7 +42,7 @@ function bit_or(a,b) local shift = 1 local v = 0 while a > 0 and b > 0 do - if (math.fmod(a,2) ~= 0) or (math.fmod(b,2) ~= 0) then + if ((a % 2) ~= 0) or ((b % 2) ~= 0) then v = v + shift end shift = shift * 2 @@ -56,7 +56,7 @@ function bit_and(a,b) local shift = 1 local v = 0 while a > 0 and b > 0 do - if (math.fmod(a,2) ~= 0) and (math.fmod(b,2) ~= 0) then + if ((a % 2) ~= 0) and ((b % 2) ~= 0) then v = v + shift end shift = shift * 2 diff --git a/pkg/base/lib_map.lua b/pkg/base/lib_map.lua index af7722c..d07498d 100644 --- a/pkg/base/lib_map.lua +++ b/pkg/base/lib_map.lua @@ -190,17 +190,17 @@ function map_hashcoord3(x,y,z) xlen,ylen,zlen = common.map_get_dims() return - math.fmod(math.fmod(y,ylen)+ylen,ylen) - +ylen*(math.fmod(math.fmod(x,xlen)+xlen,xlen) - +xlen*math.fmod(math.fmod(z,zlen)+zlen,zlen)) + (y % ylen) + +ylen*(x % xlen) + +xlen*(z % zlen) end function map_hashcoord2(x,z) local xlen,ylen,zlen xlen,ylen,zlen = common.map_get_dims() - return math.fmod(math.fmod(x,xlen)+xlen,xlen) - +xlen*math.fmod(math.fmod(z,zlen)+zlen,zlen) + return (x % xlen) + +xlen*(z % zlen) end function map_chkdisbrk(x,y,z) diff --git a/pkg/base/lib_vector.lua b/pkg/base/lib_vector.lua index df3e628..d0423ab 100644 --- a/pkg/base/lib_vector.lua +++ b/pkg/base/lib_vector.lua @@ -15,6 +15,25 @@ along with Ice Lua Components. If not, see . ]] +function trace_gap(x,y,z) + local xlen,ylen,zlen + xlen,ylen,zlen = common.map_get_dims() + + local l = common.map_pillar_get(math.floor(x), math.floor(z)) + i = 1 + local h1,h2 + h1 = nil + while true do + h2 = l[i+1] + if h2 == ylen-1 then h2 = ylen end + if y < l[i+1] or l[i] == 0 then return h1, h2 end + i = i + l[i]*4 + if y < l[i+3] then return h1, h2 end + h1 = l[i+3] + h2 = l[i+1] + end +end + function box_is_clear(x1,y1,z1,x2,y2,z2,canwrap) local x,z,i @@ -216,9 +235,9 @@ function trace_map_box(x1,y1,z1, x2,y2,z2, bx1,by1,bz1, bx2,by2,bz2, canwrap) -- sub deltas local sx, sy, sz - sx = math.fmod(x1, 1.0) - 0.001 - sy = math.fmod(y1, 1.0) - 0.001 - sz = math.fmod(z1, 1.0) - 0.001 + sx = (x1 % 1.0) - 0.001 + sy = (y1 % 1.0) - 0.001 + sz = (z1 % 1.0) - 0.001 if gx >= 0 then sx = 1-sx end if gy >= 0 then sy = 1-sy end if gz >= 0 then sz = 1-sz end diff --git a/pkg/base/main_server.lua b/pkg/base/main_server.lua index c776f29..216a793 100644 --- a/pkg/base/main_server.lua +++ b/pkg/base/main_server.lua @@ -28,12 +28,12 @@ function slot_add(sockfd, tidx, wpn, name) if not players[i] then if tidx < 0 or tidx > 1 then -- TODO: actually balance this properly! - tidx = math.fmod(i-1,2) + tidx = (i-1) % 2 end players[i] = new_player({ name = name, - --[[squad = squads[math.fmod(i-1,2)][ - math.fmod(math.floor((i-1)/2),4)+1],]] + --[[squad = squads[(i-1) % 2][ + (math.floor((i-1)/2) % 4)+1],]] squad = nil, team = tidx, -- 0 == blue, 1 == green weapon = WPN_RIFLE, @@ -406,23 +406,6 @@ map_fname = map_fname or MAP_DEFAULT map_loaded = common.map_load(map_fname, "auto") common.map_set(map_loaded) --- spam with players ---[=[ -players.local_multi = math.floor(math.random()*32)+1 - -for i=1,players.max do - players[i] = new_player({ - name = name_generate(), - --[[squad = squads[math.fmod(i-1,2)][ - math.fmod(math.floor((i-1)/2),4)+1],]] - squad = nil, - team = math.fmod(i-1,2), -- 0 == blue, 1 == green - weapon = WPN_RIFLE, - }) - print("player", i, players[i].name) -end -]=] - intent[#intent+1] = new_intel({team = 0, iid = #intent+1}) intent[#intent+1] = new_tent({team = 0, iid = #intent+1}) intent[#intent+1] = new_intel({team = 1, iid = #intent+1}) diff --git a/pkg/base/obj_intent.lua b/pkg/base/obj_intent.lua index ec48224..87f59c2 100644 --- a/pkg/base/obj_intent.lua +++ b/pkg/base/obj_intent.lua @@ -275,7 +275,7 @@ function new_tent(settings) plr.tent_restock() end - if plr.has_intel then + if plr.has_intel and plr.team == this.team then plr.intel_capture(sec_current) end end diff --git a/pkg/base/obj_player.lua b/pkg/base/obj_player.lua index 3d9393d..e95269d 100644 --- a/pkg/base/obj_player.lua +++ b/pkg/base/obj_player.lua @@ -748,9 +748,11 @@ function new_player(settings) end if this.crouching or MODE_AUTOCLIMB then by2 = by2 - 1 + if MODE_AUTOCLIMB then + by2 = by2 - 0.01 + end end - - + if this.alive then tx1,ty1,tz1 = trace_map_box( ox, oy, oz, @@ -761,37 +763,68 @@ function new_player(settings) else tx1,ty1,tz1 = nx,ny,nz end - - if this.alive and MODE_AUTOCLIMB then + + if this.alive and MODE_AUTOCLIMB and not this.crouching then + by2 = by2 + 1.01 + end + + if this.alive and MODE_AUTOCLIMB and not this.crouching then local jerky = ty1 - if not this.crouching then - ty1 = ty1 - 1 - by2 = by2 + 1 - end - tx1,ty1,tz1 = trace_map_box( - tx1,ty1,tz1, - nx, ny, nz, - -0.4, by1, -0.4, - 0.4, by2, 0.4, - false) - if ty1-jerky < -0.8 and not box_is_clear( - nx-0.4, ny-0.3-0.5, nz-0.4, - nx+0.4, ny-0.3, nz+0.4) then - this.crouching = true - ty1 = ty1 + 1 - end - if math.abs(jerky-ty1) > 0.2 then - this.jerkoffs = this.jerkoffs + jerky - ty1 + + local h1a,h1b,h1c,h1d + local h2a,h2b,h2c,h2d + local h1,h2,_ + _,h2 = trace_gap(tx1,ty1+1.0,tz1) + h1a,h2a = trace_gap(tx1-0.39,ty1+1.0,tz1-0.39) + h1b,h2b = trace_gap(tx1+0.39,ty1+1.0,tz1-0.39) + h1c,h2c = trace_gap(tx1-0.39,ty1+1.0,tz1+0.39) + h1d,h2d = trace_gap(tx1+0.39,ty1+1.0,tz1+0.39) + + if (not h1a) or (h1b and h1a < h1b) then h1a = h1b end + if (not h1a) or (h1c and h1a < h1c) then h1a = h1c end + if (not h1a) or (h1d and h1a < h1d) then h1a = h1d end + if (not h2a) or (h2b and h2a > h2b) then h2a = h2b end + if (not h2a) or (h2c and h2a > h2c) then h2a = h2c end + if (not h2a) or (h2d and h2a > h2d) then h2a = h2d end + + h1 = h1a + h2 = h2a + + local dh1 = (h1 and -(h1 - ty1)) + local dh2 = (h2 and (h2 - ty1)) + + if dh2 and dh2 < by2 and dh2 > 0 then + --print("old", ty1, dh2, by2, h1, h2) + + if (dh1 and dh1 < -by1) then + -- crouch + this.crouching = true + ty1 = ty1 + 1 + else + -- climb + ty1 = h2 - by2 + local jdiff = jerky - ty1 + if math.abs(jdiff) > 0.1 then + this.jerkoffs = this.jerkoffs + jdiff + end + end + + --print("new", ty1, this.vy) + --if this.vy > 0 then this.vy = 0 end end end this.x, this.y, this.z = tx1, ty1, tz1 - - this.grounded = (MODE_AIRJUMP and this.grounded) or not box_is_clear( + + local fgrounded = not box_is_clear( tx1-0.39, ty1+by2, tz1-0.39, tx1+0.39, ty1+by2+0.1, tz1+0.39) - if this.alive and this.vy > 0 and this.grounded then + --print(fgrounded, tx1,ty1,tz1,by2) + + this.grounded = (MODE_AIRJUMP and this.grounded) or fgrounded + + if this.alive and this.vy > 0 and fgrounded then this.vy = 0 end