+if core.global_exists("areas") then
+ hangglider.flak = true
+ -- chat command definition essentially copied from areas mod.
+ minetest.register_chatcommand("area_flak",{
+ params = "<ID>",
+ description = "Toggle airspace restrictions for area <ID>",
+ func = function(name, param)
+ local id = tonumber(param)
+ if not id then
+ return false, "Invalid usage, see /help area_flak."
+ end
+
+ if not areas:isAreaOwner(id, name) then
+ return false, "Area "..id.." does not exist"
+ .." or is not owned by you."
+ end
+ local open = not areas.areas[id].flak
+ -- Save false as nil to avoid inflating the DB.
+ areas.areas[id].flak = open or nil
+ areas:save()
+ return true, ("Area's airspace %s."):format(open and "closed" or "opened")
+ end
+ })
+end
+
+if core.global_exists("minetestd") and minetestd.services.physicsctl.enabled then
+minetestd.physicsctl.register_physics_effect("hangglider",
+ function(player) -- check
+ return hangglider.use[player:get_player_name()]
+ end,
+ function(phys, player) -- blend
+ local vel_y = player:get_player_velocity().y
+ if debug then player:hud_change(hangglider.debug[pname].id, "text", vel_y..', '..player:get_physics_override().gravity..', '..tostring(hangglider.airbreak[pname])) end
+ phys.gravity = phys.gravity*((vel_y + 3)/20)
+ if vel_y < 0 and vel_y > -3 then
+ phys.speed = (math.abs(vel_y/2) + 0.75)
+ elseif vel_y <= -3 then --Cap our gliding movement speed.
+ phys.speed = 2.25
+ end
+ phys.jump = 0
+ end,
+ 7 -- effect order
+)
+end
+
+hangglider.can_fly = function (pname, pos)
+ -- Checks if the player will get shot down at the position
+ if wardzones then
+ local zone = wardzones.getZone(pos)
+ if zone then
+ return (minetest.check_player_privs(pname, {protection_bypass=true}) or wardzones.checkPlayerZoneAccess(pname, zone) or not zone["data"]["no_fly"])
+ end
+ end
+ if areas and minetest.is_protected(vector.round(pos), pname) then
+ if hangglider.flak then
+ for id, area in pairs(areas:getAreasAtPos(pos)) do
+ if area.flak then
+ return false
+ end
+ end
+ end
+ end
+ return true
+end
+
+hangglider.shot_sound = function (pos)
+ minetest.sound_play("hangglider_flak_shot", {
+ pos = pos,
+ max_hear_distance = 30,
+ gain = 10.0,
+ })
+end
+
+local function set_fast(name, value)
+ local privs = minetest.get_player_privs(name)
+ privs.fast = value
+ minetest.set_player_privs(name, privs)
+end
+
+local physics_attrs = {"jump", "speed", "gravity"}
+local function apply_physics_override(player, overrides)
+ if player_monoids then
+ for _, attr in pairs(physics_attrs) do
+ if overrides[attr] then
+ player_monoids[attr]:add_change(player, overrides[attr], "hangglider:glider")
+ end
+ end
+ else
+ player:set_physics_override(overrides)
+ end
+ if minetest.settings:get_bool("hangglider_no_fast") then
+ set_fast(player:get_player_name(), nil)
+ end
+end
+
+local function remove_physics_override(player, overrides)
+ for _, attr in pairs(physics_attrs) do
+ if overrides[attr] then
+ if core.global_exists("player_monoids") then
+ player_monoids[attr]:del_change(player, "hangglider:glider")
+ else
+ player:set_physics_override({[attr] = 1})
+ end
+ end
+ end
+ set_fast(player:get_player_name(), true)
+end
+
+local step_v