Noch mehr mods
This commit is contained in:
parent
a063db5d3b
commit
cf017b2ca1
527 changed files with 21113 additions and 181 deletions
313
mods/airutils/lib_planes/control.lua
Normal file
313
mods/airutils/lib_planes/control.lua
Normal file
|
@ -0,0 +1,313 @@
|
|||
--global constants
|
||||
airutils.ideal_step = 0.02
|
||||
|
||||
--[[airutils.rudder_limit = 30
|
||||
airutils.elevator_limit = 40]]--
|
||||
|
||||
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELIM .. "utilities.lua")
|
||||
local S = airutils.S
|
||||
|
||||
function airutils.powerAdjust(self,dtime,factor,dir,max_power)
|
||||
local max = max_power or 100
|
||||
local add_factor = factor/2
|
||||
add_factor = add_factor * (dtime/airutils.ideal_step) --adjusting the command speed by dtime
|
||||
|
||||
if dir == 1 then
|
||||
if self._power_lever < max then
|
||||
self._power_lever = self._power_lever + add_factor
|
||||
end
|
||||
if self._power_lever > max then
|
||||
self._power_lever = max
|
||||
end
|
||||
end
|
||||
if dir == -1 then
|
||||
if self._power_lever > 0 then
|
||||
self._power_lever = self._power_lever - add_factor
|
||||
if self._power_lever < 0 then self._power_lever = 0 end
|
||||
end
|
||||
if self._power_lever <= 0 then
|
||||
self._power_lever = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function airutils.control(self, dtime, hull_direction, longit_speed, longit_drag,
|
||||
later_speed, later_drag, accel, player, is_flying)
|
||||
--if self.driver_name == nil then return end
|
||||
local retval_accel = accel
|
||||
|
||||
local stop = false
|
||||
local ctrl = nil
|
||||
|
||||
-- player control
|
||||
if player then
|
||||
ctrl = player:get_player_control()
|
||||
|
||||
if ctrl.aux1 and self._last_time_command > 0.5 then
|
||||
self._last_time_command = 0
|
||||
|
||||
end
|
||||
----------------------------------
|
||||
-- flap operation
|
||||
----------------------------------
|
||||
if ctrl.aux1 and ctrl.sneak and self._last_time_command >= 0.3 and self._wing_angle_extra_flaps then
|
||||
self._last_time_command = 0
|
||||
airutils.flap_operate(self, player)
|
||||
end
|
||||
|
||||
self._acceleration = 0
|
||||
if self._engine_running then
|
||||
--engine acceleration calc
|
||||
local engineacc = (self._power_lever * self._max_engine_acc) / 100;
|
||||
|
||||
local factor = 1
|
||||
|
||||
--increase power lever
|
||||
if ctrl.jump then
|
||||
airutils.powerAdjust(self, dtime, factor, 1)
|
||||
end
|
||||
--decrease power lever
|
||||
if ctrl.sneak then
|
||||
airutils.powerAdjust(self, dtime, factor, -1)
|
||||
if self._power_lever <= 0 and is_flying == false then
|
||||
--break
|
||||
if longit_speed > 0 then
|
||||
engineacc = -1
|
||||
if (longit_speed + engineacc) < 0 then
|
||||
engineacc = longit_speed * -1
|
||||
end
|
||||
end
|
||||
if longit_speed < 0 then
|
||||
engineacc = 1
|
||||
if (longit_speed + engineacc) > 0 then
|
||||
engineacc = longit_speed * -1
|
||||
end
|
||||
end
|
||||
if math.abs(longit_speed) < 0.2 then
|
||||
stop = true
|
||||
end
|
||||
end
|
||||
end
|
||||
--do not exceed
|
||||
local max_speed = self._max_speed
|
||||
if longit_speed > max_speed then
|
||||
engineacc = engineacc - (longit_speed-max_speed)
|
||||
if engineacc < 0 then engineacc = 0 end
|
||||
end
|
||||
self._acceleration = engineacc
|
||||
else
|
||||
local paddleacc = 0
|
||||
if longit_speed < 1.0 then
|
||||
if ctrl.jump then paddleacc = 0.5 end
|
||||
end
|
||||
if longit_speed > -1.0 then
|
||||
if ctrl.sneak then paddleacc = -0.5 end
|
||||
end
|
||||
self._acceleration = paddleacc
|
||||
end
|
||||
|
||||
local hull_acc = vector.multiply(hull_direction,self._acceleration)
|
||||
retval_accel=vector.add(retval_accel,hull_acc)
|
||||
|
||||
--pitch
|
||||
local pitch_cmd = 0
|
||||
if self._yaw_by_mouse == true then
|
||||
airutils.set_pitch_by_mouse(self, player)
|
||||
else
|
||||
if ctrl.up then pitch_cmd = 1 elseif ctrl.down then pitch_cmd = -1 end
|
||||
airutils.set_pitch(self, pitch_cmd, dtime)
|
||||
end
|
||||
|
||||
-- yaw
|
||||
local yaw_cmd = 0
|
||||
if self._yaw_by_mouse == true then
|
||||
local rot_y = math.deg(player:get_look_horizontal())
|
||||
airutils.set_yaw_by_mouse(self, rot_y)
|
||||
else
|
||||
if ctrl.right then yaw_cmd = 1 elseif ctrl.left then yaw_cmd = -1 end
|
||||
airutils.set_yaw(self, yaw_cmd, dtime)
|
||||
end
|
||||
|
||||
--I'm desperate, center all!
|
||||
if ctrl.right and ctrl.left then
|
||||
self._elevator_angle = 0
|
||||
self._rudder_angle = 0
|
||||
end
|
||||
|
||||
if ctrl.up and ctrl.down and self._last_time_command > 0.5 then
|
||||
self._last_time_command = 0
|
||||
local name = player:get_player_name()
|
||||
if self._yaw_by_mouse == true then
|
||||
minetest.chat_send_player(name, core.colorize('#0000ff', S(" >>> Mouse control disabled.")))
|
||||
self._yaw_by_mouse = false
|
||||
else
|
||||
minetest.chat_send_player(name, core.colorize('#0000ff', S(" >>> Mouse control enabled.")))
|
||||
self._yaw_by_mouse = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if longit_speed > 0 then
|
||||
if ctrl then
|
||||
if not (ctrl.right or ctrl.left) then
|
||||
airutils.rudder_auto_correction(self, longit_speed, dtime)
|
||||
end
|
||||
else
|
||||
airutils.rudder_auto_correction(self, longit_speed, dtime)
|
||||
end
|
||||
if airutils.elevator_auto_correction then
|
||||
self._elevator_angle = airutils.elevator_auto_correction(self, longit_speed, self.dtime, self._max_speed, self._elevator_angle, self._elevator_limit, airutils.ideal_step, 100)
|
||||
end
|
||||
end
|
||||
|
||||
return retval_accel, stop
|
||||
end
|
||||
|
||||
function airutils.set_pitch_by_mouse(self, player)
|
||||
local vehicle_rot = self.object:get_rotation()
|
||||
local rot_x = player:get_look_vertical()-vehicle_rot.x
|
||||
self._elevator_angle = -(rot_x * self._elevator_limit)*(self._pitch_intensity*10)
|
||||
if self._elevator_angle > self._elevator_limit then self._elevator_angle = self._elevator_limit end
|
||||
if self._elevator_angle < -self._elevator_limit then self._elevator_angle = -self._elevator_limit end
|
||||
end
|
||||
|
||||
function airutils.set_pitch(self, dir, dtime)
|
||||
local pitch_factor = self._pitch_intensity or 0.6
|
||||
local multiplier = pitch_factor*(dtime/airutils.ideal_step)
|
||||
if dir == -1 then
|
||||
--minetest.chat_send_all("cabrando")
|
||||
self._elevator_angle = math.max(self._elevator_angle-multiplier,-self._elevator_limit)
|
||||
elseif dir == 1 then
|
||||
--minetest.chat_send_all("picando")
|
||||
self._elevator_angle = math.min(self._elevator_angle+multiplier,self._elevator_limit)
|
||||
end
|
||||
end
|
||||
|
||||
function airutils.set_autopilot_pitch(self, dir, dtime)
|
||||
local pitch_factor = 0.05
|
||||
local multiplier = pitch_factor*(dtime/airutils.ideal_step)
|
||||
if dir == -1 then
|
||||
--minetest.chat_send_all("cabrando")
|
||||
self._elevator_angle = math.max(self._elevator_angle-multiplier,-self._elevator_limit)
|
||||
elseif dir == 1 then
|
||||
--minetest.chat_send_all("picando")
|
||||
self._elevator_angle = math.min(self._elevator_angle+multiplier,self._elevator_limit)
|
||||
end
|
||||
end
|
||||
|
||||
function airutils.set_yaw_by_mouse(self, dir)
|
||||
local rotation = self.object:get_rotation()
|
||||
local rot_y = math.deg(rotation.y)
|
||||
|
||||
local total = math.abs(math.floor(rot_y/360))
|
||||
|
||||
if rot_y < 0 then rot_y = rot_y + (360*total) end
|
||||
if rot_y > 360 then rot_y = rot_y - (360*total) end
|
||||
if rot_y >= 270 and dir <= 90 then dir = dir + 360 end
|
||||
if rot_y <= 90 and dir >= 270 then dir = dir - 360 end
|
||||
|
||||
local intensity = self._yaw_intensity / 10
|
||||
local command = (rot_y - dir) * intensity
|
||||
if command < -90 then command = -90
|
||||
elseif command > 90 then command = 90 end
|
||||
--minetest.chat_send_all("rotation y: "..rot_y.." - dir: "..dir.." - command: "..command)
|
||||
|
||||
self._rudder_angle = (-command * self._rudder_limit)/90
|
||||
end
|
||||
|
||||
function airutils.set_yaw(self, dir, dtime)
|
||||
local yaw_factor = self._yaw_intensity or 25
|
||||
if dir == 1 then
|
||||
self._rudder_angle = math.max(self._rudder_angle-(yaw_factor*dtime),-self._rudder_limit)
|
||||
elseif dir == -1 then
|
||||
self._rudder_angle = math.min(self._rudder_angle+(yaw_factor*dtime),self._rudder_limit)
|
||||
end
|
||||
end
|
||||
|
||||
function airutils.rudder_auto_correction(self, longit_speed, dtime)
|
||||
local factor = 1
|
||||
if self._rudder_angle > 0 then factor = -1 end
|
||||
local correction = (self._rudder_limit*(longit_speed/1000)) * factor * (dtime/airutils.ideal_step)
|
||||
local before_correction = self._rudder_angle
|
||||
local new_rudder_angle = self._rudder_angle + correction
|
||||
if math.sign(before_correction) ~= math.sign(new_rudder_angle) then
|
||||
self._rudder_angle = 0
|
||||
else
|
||||
self._rudder_angle = new_rudder_angle
|
||||
end
|
||||
end
|
||||
|
||||
function airutils.autopilot(self, dtime, hull_direction, longit_speed, accel, curr_pos)
|
||||
|
||||
local retval_accel = accel
|
||||
|
||||
if not self._have_auto_pilot then return end
|
||||
|
||||
local min_attack_angle = self._wing_angle_of_attack or 1.0
|
||||
local flap = self._wing_angle_extra_flaps or 2
|
||||
local max_attack_angle = min_attack_angle + flap --1.8
|
||||
|
||||
--climb
|
||||
local velocity = self.object:get_velocity()
|
||||
local climb_rate = velocity.y * 1.5
|
||||
if climb_rate > 5 then climb_rate = 5 end
|
||||
if climb_rate < -5 then
|
||||
climb_rate = -5
|
||||
end
|
||||
|
||||
self._acceleration = 0
|
||||
local climb_rate_min = 0.2
|
||||
local factor = math.abs(climb_rate * 0.1)
|
||||
if self._engine_running then
|
||||
--engine acceleration calc
|
||||
local engineacc = (self._power_lever * self._max_engine_acc) / 100;
|
||||
--self.engine:set_animation_frame_speed(60 + self._power_lever)
|
||||
|
||||
--increase power lever
|
||||
if climb_rate > climb_rate_min then
|
||||
airutils.powerAdjust(self, dtime, factor, -1)
|
||||
end
|
||||
--decrease power lever
|
||||
if climb_rate < 0 then
|
||||
airutils.powerAdjust(self, dtime, factor, 1)
|
||||
end
|
||||
--do not exceed
|
||||
local max_speed = self._max_speed
|
||||
if longit_speed > max_speed then
|
||||
engineacc = 0
|
||||
if engineacc < 0 then engineacc = 0 end
|
||||
end
|
||||
self._acceleration = engineacc
|
||||
end
|
||||
|
||||
local hull_acc = vector.multiply(hull_direction,self._acceleration)
|
||||
retval_accel=vector.add(retval_accel,hull_acc)
|
||||
|
||||
--decrease power lever
|
||||
if climb_rate < 0 then
|
||||
airutils.set_autopilot_pitch(self, -1, dtime)
|
||||
--core.chat_send_all("cabrando: "..dump(climb_rate))
|
||||
elseif climb_rate > climb_rate_min then
|
||||
airutils.set_autopilot_pitch(self, 1, dtime)
|
||||
--core.chat_send_all("picando: "..dump(climb_rate))
|
||||
end
|
||||
|
||||
--pitch
|
||||
--[[if self._angle_of_attack > max_attack_angle then
|
||||
airutils.set_autopilot_pitch(self, -1, dtime)
|
||||
elseif self._angle_of_attack < min_attack_angle then
|
||||
airutils.set_autopilot_pitch(self, 1, dtime)
|
||||
end]]--
|
||||
|
||||
-- yaw
|
||||
airutils.set_yaw(self, 0, dtime)
|
||||
|
||||
if longit_speed > (self._min_speed or 0) then
|
||||
airutils.rudder_auto_correction(self, longit_speed, dtime)
|
||||
if airutils.elevator_auto_correction then
|
||||
--self._elevator_angle = airutils.elevator_auto_correction(self, longit_speed, self.dtime, self._max_speed, self._elevator_angle, self._elevator_limit, airutils.ideal_step, 500)
|
||||
end
|
||||
end
|
||||
|
||||
return retval_accel
|
||||
end
|
114
mods/airutils/lib_planes/custom_physics.lua
Normal file
114
mods/airutils/lib_planes/custom_physics.lua
Normal file
|
@ -0,0 +1,114 @@
|
|||
function airutils.physics(self)
|
||||
local friction = self._ground_friction or 0.99
|
||||
local vel=self.object:get_velocity()
|
||||
local new_velocity = vector.new()
|
||||
|
||||
--buoyancy
|
||||
local surface = nil
|
||||
local surfnodename = nil
|
||||
local spos = airutils.get_stand_pos(self)
|
||||
if not spos then return end
|
||||
spos.y = spos.y+0.01
|
||||
-- get surface height
|
||||
local snodepos = airutils.get_node_pos(spos)
|
||||
local surfnode = airutils.nodeatpos(spos)
|
||||
while surfnode and (surfnode.drawtype == 'liquid' or surfnode.drawtype == 'flowingliquid') do
|
||||
surfnodename = surfnode.name
|
||||
surface = snodepos.y +0.5
|
||||
if surface > spos.y+self.height then break end
|
||||
snodepos.y = snodepos.y+1
|
||||
surfnode = airutils.nodeatpos(snodepos)
|
||||
end
|
||||
|
||||
self.isinliquid = surfnodename
|
||||
if surface then -- standing in liquid
|
||||
self.isinliquid = true
|
||||
end
|
||||
local last_accel = vector.new()
|
||||
if self._last_accel then
|
||||
last_accel = vector.new(self._last_accel)
|
||||
end
|
||||
|
||||
if self.isinliquid then
|
||||
self.water_drag = 0.2
|
||||
self.isinliquid = true
|
||||
local height = self.height
|
||||
local submergence = math.min(surface-spos.y,height)/height
|
||||
-- local balance = self.buoyancy*self.height
|
||||
local buoyacc = airutils.gravity*(self.buoyancy-submergence)
|
||||
--local buoyacc = self._baloon_buoyancy*(self.buoyancy-submergence)
|
||||
local accell = {
|
||||
x=-vel.x*self.water_drag,
|
||||
y=buoyacc-(vel.y*math.abs(vel.y)*0.4),
|
||||
z=-vel.z*self.water_drag
|
||||
}
|
||||
if self.buoyancy >= 1 then self._engine_running = false end
|
||||
if last_accel then
|
||||
accell = vector.add(accell,last_accel)
|
||||
end
|
||||
new_velocity = vector.multiply(accell,self.dtime)
|
||||
--airutils.set_acceleration(self.object,accell)
|
||||
--self.object:move_to(self.object:get_pos())
|
||||
else
|
||||
--airutils.set_acceleration(self.object,{x=0,y=airutils.gravity,z=0})
|
||||
self.isinliquid = false
|
||||
|
||||
if last_accel then
|
||||
last_accel.y = last_accel.y + airutils.gravity --gravity here
|
||||
|
||||
new_velocity = vector.multiply(last_accel,self.dtime)
|
||||
end
|
||||
--self.object:set_acceleration({x=0,y=new_accel.y, z=0})
|
||||
end
|
||||
|
||||
if self.isonground and not self.isinliquid then
|
||||
--dumb friction
|
||||
new_velocity = {x=new_velocity.x*friction,
|
||||
y=new_velocity.y,
|
||||
z=new_velocity.z*friction}
|
||||
|
||||
-- bounciness
|
||||
if self.springiness and self.springiness > 0 and self.buoyancy >= 1 then
|
||||
local vnew = vector.new(new_velocity)
|
||||
|
||||
if not self.collided then -- ugly workaround for inconsistent collisions
|
||||
for _,k in ipairs({'y','z','x'}) do
|
||||
if new_velocity[k]==0 and math.abs(self.lastvelocity[k])> 0.1 then
|
||||
vnew[k]=-self.lastvelocity[k]*self.springiness
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not vector.equals(new_velocity,vnew) then
|
||||
self.collided = true
|
||||
else
|
||||
if self.collided then
|
||||
vnew = vector.new(self.lastvelocity)
|
||||
end
|
||||
self.collided = false
|
||||
end
|
||||
new_velocity = vnew
|
||||
end
|
||||
|
||||
--damage if the friction is below .97
|
||||
if self._last_longit_speed then
|
||||
if friction <= 0.97 and self._last_longit_speed > 0 then
|
||||
self.hp_max = self.hp_max - 0.001
|
||||
airutils.setText(self, self._vehicle_name)
|
||||
end --damage the plane if it have hard friction
|
||||
end
|
||||
|
||||
--self.object:set_velocity(new_velocity)
|
||||
--new_velocity = vector.subtract(new_velocity,vel)
|
||||
|
||||
--fix bug with unexpe3cted moving
|
||||
if not self.driver_name and math.abs(vel.x) < 0.2 and math.abs(vel.z) < 0.2 then
|
||||
self.object:set_velocity({x=0,y=airutils.gravity*self.dtime,z=0})
|
||||
if self.wheels then self.wheels:set_animation_frame_speed(0) end
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self.object:add_velocity(new_velocity)
|
||||
end
|
||||
|
1033
mods/airutils/lib_planes/entities.lua
Normal file
1033
mods/airutils/lib_planes/entities.lua
Normal file
File diff suppressed because it is too large
Load diff
450
mods/airutils/lib_planes/forms.lua
Normal file
450
mods/airutils/lib_planes/forms.lua
Normal file
|
@ -0,0 +1,450 @@
|
|||
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELIM .. "global_definitions.lua")
|
||||
local S = airutils.S
|
||||
--------------
|
||||
-- Manual --
|
||||
--------------
|
||||
|
||||
function airutils.getPlaneFromPlayer(player)
|
||||
local seat = player:get_attach()
|
||||
if seat then
|
||||
local plane = seat:get_attach()
|
||||
return plane
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function airutils.pilot_formspec(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
local plane_obj = airutils.getPlaneFromPlayer(player)
|
||||
if plane_obj == nil then
|
||||
return
|
||||
end
|
||||
local ent = plane_obj:get_luaentity()
|
||||
|
||||
local flap_is_down = "false"
|
||||
local have_flaps = false
|
||||
if ent._wing_angle_extra_flaps then
|
||||
if ent._wing_angle_extra_flaps > 0 then
|
||||
have_flaps = true
|
||||
end
|
||||
end
|
||||
if have_flaps then
|
||||
if ent._flap then flap_is_down = "true" end
|
||||
end
|
||||
|
||||
local light = "false"
|
||||
if ent._have_landing_lights then
|
||||
if ent._land_light then light = "true" end
|
||||
end
|
||||
|
||||
local autopilot = "false"
|
||||
if ent._have_auto_pilot then
|
||||
if ent._autopilot then autopilot = "true" end
|
||||
end
|
||||
|
||||
local yaw = "false"
|
||||
if ent._yaw_by_mouse then yaw = "true" end
|
||||
|
||||
local eng_status = "false"
|
||||
local eng_status_color = "#ff0000"
|
||||
if ent._engine_running then
|
||||
eng_status = "true"
|
||||
eng_status_color = "#00ff00"
|
||||
end
|
||||
|
||||
local ver_pos = 1.0
|
||||
local basic_form = ""
|
||||
--basic_form = basic_form.."button[1,"..ver_pos..";4,1;turn_on;Start/Stop Engines]"
|
||||
basic_form = basic_form.."checkbox[1,"..ver_pos..";turn_on;"..core.colorize(eng_status_color, S("Start/Stop Engines"))..";"..eng_status.."]"
|
||||
ver_pos = ver_pos + 1.1
|
||||
basic_form = basic_form.."button[1,"..ver_pos..";4,1;hud;" .. S("Show/Hide Gauges") .. "]"
|
||||
ver_pos = ver_pos + 1.1
|
||||
basic_form = basic_form.."button[1,"..ver_pos..";4,1;inventory;" .. S("Show Inventory") .. "]"
|
||||
ver_pos = ver_pos + 1.5
|
||||
|
||||
basic_form = basic_form.."checkbox[1,"..ver_pos..";yaw;" .. S("Yaw by mouse") .. ";"..yaw.."]"
|
||||
ver_pos = ver_pos + 0.5
|
||||
|
||||
basic_form = basic_form.."button[1,"..ver_pos..";4,1;go_out;" .. S("Go Out!") .. "]"
|
||||
|
||||
--form second part
|
||||
local expand_form = false
|
||||
ver_pos = 1.2 --restart in second collumn
|
||||
if have_flaps then
|
||||
basic_form = basic_form.."checkbox[6,"..ver_pos..";flap_is_down;" .. S("Flaps down") .. ";"..flap_is_down.."]"
|
||||
ver_pos = ver_pos + 0.5
|
||||
expand_form = true
|
||||
end
|
||||
|
||||
if ent._have_landing_lights then
|
||||
basic_form = basic_form.."checkbox[6,"..ver_pos..";light;" .. S("Landing Light") .. ";"..light.."]"
|
||||
ver_pos = ver_pos + 0.5
|
||||
expand_form = true
|
||||
end
|
||||
|
||||
if ent._have_auto_pilot then
|
||||
basic_form = basic_form.."checkbox[6,"..ver_pos..";turn_auto_pilot_on;" .. S("Autopilot") .. ";"..autopilot.."]"
|
||||
ver_pos = ver_pos + 0.5
|
||||
expand_form = true
|
||||
end
|
||||
|
||||
if ent._have_copilot and name == ent.driver_name then
|
||||
basic_form = basic_form.."button[6,"..ver_pos..";4,1;copilot_form;" .. S("Co-pilot Manager") .. "]"
|
||||
ver_pos = ver_pos + 1.25
|
||||
expand_form = true
|
||||
end
|
||||
|
||||
if ent._have_adf then
|
||||
basic_form = basic_form.."button[6,"..ver_pos..";4,1;adf_form;" .. S("Adf Manager") .. "]"
|
||||
ver_pos = ver_pos + 1.1
|
||||
expand_form = true
|
||||
end
|
||||
|
||||
if ent._have_manual then
|
||||
basic_form = basic_form.."button[6,5.2;4,1;manual;" .. S("Manual") .. "]"
|
||||
expand_form = true
|
||||
end
|
||||
|
||||
local form_width = 6
|
||||
if expand_form then form_width = 11 end
|
||||
local form = table.concat({
|
||||
"formspec_version[3]",
|
||||
"size["..form_width..",7.2]",
|
||||
}, "")
|
||||
|
||||
minetest.show_formspec(name, "lib_planes:pilot_main", form..basic_form)
|
||||
end
|
||||
|
||||
function airutils.manage_copilot_formspec(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
local plane_obj = airutils.getPlaneFromPlayer(player)
|
||||
if plane_obj == nil then
|
||||
return
|
||||
end
|
||||
local ent = plane_obj:get_luaentity()
|
||||
|
||||
local pass_list = ""
|
||||
for k, v in pairs(ent._passengers) do
|
||||
pass_list = pass_list .. v .. ","
|
||||
end
|
||||
|
||||
local basic_form = table.concat({
|
||||
"formspec_version[3]",
|
||||
"size[6,4.5]",
|
||||
}, "")
|
||||
|
||||
basic_form = basic_form.."label[1,1.0;" .. S("Bring a copilot") .. ":]"
|
||||
|
||||
local max_seats = table.getn(ent._seats)
|
||||
if ent._have_copilot and max_seats > 2 then --no need to select if there are only 2 occupants
|
||||
basic_form = basic_form.."dropdown[1,1.5;4,0.6;copilot;"..pass_list..";0;false]"
|
||||
end
|
||||
|
||||
basic_form = basic_form.."button[1,2.5;4,1;pass_control;" .. S("Pass the Control") .. "]"
|
||||
|
||||
minetest.show_formspec(name, "lib_planes:manage_copilot", basic_form)
|
||||
end
|
||||
|
||||
function airutils.adf_formspec(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
local plane_obj = airutils.getPlaneFromPlayer(player)
|
||||
if plane_obj == nil then
|
||||
return
|
||||
end
|
||||
local ent = plane_obj:get_luaentity()
|
||||
|
||||
local adf = "false"
|
||||
if ent._adf then adf = "true" end
|
||||
local x = 0
|
||||
local z = 0
|
||||
if ent._adf_destiny then
|
||||
if ent._adf_destiny.x then
|
||||
if type(ent._adf_destiny.x) ~= nil then
|
||||
x = math.floor(ent._adf_destiny.x)
|
||||
end
|
||||
end
|
||||
if ent._adf_destiny.z then
|
||||
if type(ent._adf_destiny.z) ~= nil then
|
||||
z = math.floor(ent._adf_destiny.z)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local basic_form = table.concat({
|
||||
"formspec_version[3]",
|
||||
"size[6,3.5]",
|
||||
}, "")
|
||||
|
||||
basic_form = basic_form.."checkbox[1.0,1.0;adf;" .. S("Auto Direction Find") .. ";"..adf.."]"
|
||||
basic_form = basic_form.."field[1.0,1.7;1.5,0.6;adf_x;pos x;"..x.."]"
|
||||
basic_form = basic_form.."field[2.8,1.7;1.5,0.6;adf_z;pos z;"..z.."]"
|
||||
basic_form = basic_form.."button[4.5,1.7;0.6,0.6;save_adf;" .. S("OK") .. "]"
|
||||
|
||||
minetest.show_formspec(name, "lib_planes:adf_main", basic_form)
|
||||
end
|
||||
|
||||
function airutils.pax_formspec(name)
|
||||
local basic_form = table.concat({
|
||||
"formspec_version[3]",
|
||||
"size[6,5]",
|
||||
}, "")
|
||||
|
||||
basic_form = basic_form.."button[1,1.0;4,1;new_seat;" .. S("Change Seat") .. "]"
|
||||
basic_form = basic_form.."button[1,2.5;4,1;go_out;" .. S("Go Offboard") .. "]"
|
||||
|
||||
minetest.show_formspec(name, "lib_planes:passenger_main", basic_form)
|
||||
end
|
||||
|
||||
function airutils.go_out_confirmation_formspec(name)
|
||||
local basic_form = table.concat({
|
||||
"formspec_version[3]",
|
||||
"size[7,2.2]",
|
||||
}, "")
|
||||
|
||||
basic_form = basic_form.."label[0.5,0.5;" .. S("Do you really want to go offboard now?") .. "]"
|
||||
basic_form = basic_form.."button[1.3,1.0;2,0.8;no;" .. S("No") .. "]"
|
||||
basic_form = basic_form.."button[3.6,1.0;2,0.8;yes;" .. S("Yes") .. "]"
|
||||
|
||||
minetest.show_formspec(name, "lib_planes:go_out_confirmation_form", basic_form)
|
||||
end
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname == "lib_planes:go_out_confirmation_form" then
|
||||
local name = player:get_player_name()
|
||||
local plane_obj = airutils.getPlaneFromPlayer(player)
|
||||
if plane_obj == nil then
|
||||
minetest.close_formspec(name, "lib_planes:go_out_confirmation_form")
|
||||
return
|
||||
end
|
||||
local ent = plane_obj:get_luaentity()
|
||||
if ent then
|
||||
if fields.yes then
|
||||
airutils.dettach_pax(ent, player, true)
|
||||
end
|
||||
end
|
||||
minetest.close_formspec(name, "lib_planes:go_out_confirmation_form")
|
||||
end
|
||||
if formname == "lib_planes:adf_main" then
|
||||
local name = player:get_player_name()
|
||||
local plane_obj = airutils.getPlaneFromPlayer(player)
|
||||
if plane_obj == nil then
|
||||
minetest.chat_send_player(name, core.colorize('#ff0000', S(" >>> There is something wrong with the plane...")))
|
||||
minetest.close_formspec(name, "lib_planes:adf_main")
|
||||
return
|
||||
end
|
||||
local ent = plane_obj:get_luaentity()
|
||||
if ent then
|
||||
if fields.adf then
|
||||
if ent._adf == true then
|
||||
ent._adf = false
|
||||
minetest.chat_send_player(name, core.colorize('#0000ff', S(" >>> ADF deactivated.")))
|
||||
else
|
||||
ent._adf = true
|
||||
minetest.chat_send_player(name, core.colorize('#00ff00', S(" >>> ADF activated.")))
|
||||
end
|
||||
end
|
||||
if fields.save_adf then
|
||||
if not ent._adf_destiny then ent._adf_destiny = {x=0,z=0} end
|
||||
if ent._adf_destiny then
|
||||
if fields.adf_x and fields.adf_z then
|
||||
if tonumber(fields.adf_x, 10) ~= nil and tonumber(fields.adf_z, 10) ~= nil then
|
||||
ent._adf_destiny.x = tonumber(fields.adf_x, 10)
|
||||
ent._adf_destiny.z = tonumber(fields.adf_z, 10)
|
||||
minetest.chat_send_player(name, core.colorize('#00ff00', S(" >>> Destination written successfully.")))
|
||||
else
|
||||
minetest.chat_send_player(name, core.colorize('#ff0000', S(" >>> There is something wrong with the ADF fields values.")))
|
||||
end
|
||||
else
|
||||
minetest.chat_send_player(name, core.colorize('#ff0000', S(" >>> Both ADF fields must be given to complete the operation.")))
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
minetest.chat_send_player(name, core.colorize('#ff0000', S(" >>> There is something wrong on ADF saving...")))
|
||||
end
|
||||
minetest.close_formspec(name, "lib_planes:adf_main")
|
||||
end
|
||||
if formname == "lib_planes:passenger_main" then
|
||||
local name = player:get_player_name()
|
||||
local plane_obj = airutils.getPlaneFromPlayer(player)
|
||||
if plane_obj == nil then
|
||||
minetest.close_formspec(name, "lib_planes:passenger_main")
|
||||
return
|
||||
end
|
||||
local ent = plane_obj:get_luaentity()
|
||||
if ent then
|
||||
if fields.new_seat then
|
||||
airutils.dettach_pax(ent, player)
|
||||
airutils.attach_pax(ent, player)
|
||||
end
|
||||
if fields.go_out then
|
||||
local touching_ground, _ = airutils.check_node_below(plane_obj, 2.5)
|
||||
if ent.isinliquid or touching_ground then --isn't flying?
|
||||
airutils.dettach_pax(ent, player)
|
||||
else
|
||||
airutils.go_out_confirmation_formspec(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
minetest.close_formspec(name, "lib_planes:passenger_main")
|
||||
end
|
||||
if formname == "lib_planes:pilot_main" then
|
||||
local name = player:get_player_name()
|
||||
local plane_obj = airutils.getPlaneFromPlayer(player)
|
||||
if plane_obj then
|
||||
local ent = plane_obj:get_luaentity()
|
||||
if fields.turn_on then
|
||||
airutils.start_engine(ent)
|
||||
end
|
||||
if fields.hud then
|
||||
if ent._show_hud == true then
|
||||
ent._show_hud = false
|
||||
else
|
||||
ent._show_hud = true
|
||||
end
|
||||
end
|
||||
if fields.go_out then
|
||||
local touch_point = ent.initial_properties.collisionbox[2]-1.0
|
||||
-----////
|
||||
local pos = plane_obj:get_pos()
|
||||
pos.y = pos.y + touch_point
|
||||
local node_below = minetest.get_node(pos).name
|
||||
local nodedef = minetest.registered_nodes[node_below]
|
||||
local is_on_ground = not nodedef or nodedef.walkable or false -- unknown nodes are solid
|
||||
|
||||
if ent.driver_name == name and ent.owner == ent.driver_name then --just the owner can do this
|
||||
--minetest.chat_send_all(dump(noded))
|
||||
if is_on_ground then --or clicker:get_player_control().sneak then
|
||||
--minetest.chat_send_all(dump("is on ground"))
|
||||
--remove the passengers first
|
||||
local max_seats = table.getn(ent._seats)
|
||||
for i = max_seats,1,-1
|
||||
do
|
||||
--minetest.chat_send_all("index: "..i.." - "..dump(ent._passengers[i]))
|
||||
if ent._passengers[i] then
|
||||
local passenger = minetest.get_player_by_name(ent._passengers[i])
|
||||
if passenger then airutils.dettach_pax(ent, passenger) end
|
||||
end
|
||||
end
|
||||
ent._instruction_mode = false
|
||||
else
|
||||
-- not on ground
|
||||
if ent.co_pilot then
|
||||
--give the control to the pax
|
||||
ent._autopilot = false
|
||||
airutils.transfer_control(ent, true)
|
||||
ent._command_is_given = true
|
||||
ent._instruction_mode = true
|
||||
end
|
||||
end
|
||||
end
|
||||
airutils.dettach_pax(ent, player)
|
||||
end
|
||||
if fields.inventory then
|
||||
if ent._trunk_slots then
|
||||
airutils.show_vehicle_trunk_formspec(ent, player, ent._trunk_slots)
|
||||
end
|
||||
end
|
||||
if fields.flap_is_down then
|
||||
if fields.flap_is_down == "true" then
|
||||
ent._flap = true
|
||||
else
|
||||
ent._flap = false
|
||||
end
|
||||
minetest.sound_play("airutils_collision", {
|
||||
object = ent.object,
|
||||
max_hear_distance = 15,
|
||||
gain = 1.0,
|
||||
fade = 0.0,
|
||||
pitch = 0.5,
|
||||
}, true)
|
||||
end
|
||||
if fields.light then
|
||||
if ent._land_light == true then
|
||||
ent._land_light = false
|
||||
else
|
||||
ent._land_light = true
|
||||
end
|
||||
end
|
||||
if fields.yaw then
|
||||
if ent._yaw_by_mouse == true then
|
||||
ent._yaw_by_mouse = false
|
||||
else
|
||||
ent._yaw_by_mouse = true
|
||||
end
|
||||
end
|
||||
if fields.copilot_form then
|
||||
airutils.manage_copilot_formspec(name)
|
||||
end
|
||||
if fields.adf_form then
|
||||
airutils.adf_formspec(name)
|
||||
end
|
||||
if fields.turn_auto_pilot_on then
|
||||
if ent._autopilot == true then
|
||||
ent._autopilot = false
|
||||
core.chat_send_player(ent.driver_name,S(" >>> Autopilot deactivated"))
|
||||
else
|
||||
ent._autopilot = true
|
||||
core.chat_send_player(ent.driver_name,core.colorize('#00ff00', S(" >>> Autopilot activated")))
|
||||
end
|
||||
end
|
||||
if fields.manual then
|
||||
if ent._have_manual then
|
||||
ent._have_manual(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
minetest.close_formspec(name, "lib_planes:pilot_main")
|
||||
end
|
||||
if formname == "lib_planes:manage_copilot" then
|
||||
local name = player:get_player_name()
|
||||
local plane_obj = airutils.getPlaneFromPlayer(player)
|
||||
if plane_obj == nil then
|
||||
minetest.close_formspec(name, "lib_planes:manage_copilot")
|
||||
return
|
||||
end
|
||||
local ent = plane_obj:get_luaentity()
|
||||
|
||||
if fields.copilot then
|
||||
--look for a free seat first
|
||||
local is_there_a_free_seat = false
|
||||
for i = 2,1,-1
|
||||
do
|
||||
if ent._passengers[i] == nil then
|
||||
is_there_a_free_seat = true
|
||||
break
|
||||
end
|
||||
end
|
||||
--then move the current copilot to a free seat
|
||||
if ent.co_pilot and is_there_a_free_seat then
|
||||
local copilot_player_obj = minetest.get_player_by_name(ent.co_pilot)
|
||||
if copilot_player_obj then
|
||||
airutils.dettach_pax(ent, copilot_player_obj)
|
||||
airutils.attach_pax(ent, copilot_player_obj)
|
||||
else
|
||||
ent.co_pilot = nil
|
||||
end
|
||||
end
|
||||
--so bring the new copilot
|
||||
if ent.co_pilot == nil then
|
||||
local new_copilot_player_obj = minetest.get_player_by_name(fields.copilot)
|
||||
if new_copilot_player_obj then
|
||||
airutils.dettach_pax(ent, new_copilot_player_obj)
|
||||
airutils.attach_pax(ent, new_copilot_player_obj, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
if fields.pass_control then
|
||||
if ent._command_is_given == true then
|
||||
--take the control
|
||||
airutils.transfer_control(ent, false)
|
||||
else
|
||||
--trasnfer the control to student
|
||||
airutils.transfer_control(ent, true)
|
||||
end
|
||||
end
|
||||
minetest.close_formspec(name, "lib_planes:manage_copilot")
|
||||
end
|
||||
|
||||
|
||||
end)
|
70
mods/airutils/lib_planes/fuel_management.lua
Normal file
70
mods/airutils/lib_planes/fuel_management.lua
Normal file
|
@ -0,0 +1,70 @@
|
|||
function airutils.contains(table, val)
|
||||
for k,v in pairs(table) do
|
||||
if k == val then
|
||||
return v
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function airutils.loadFuel(self, player_name)
|
||||
local player = minetest.get_player_by_name(player_name)
|
||||
local inv = player:get_inventory()
|
||||
local itmstck=player:get_wielded_item()
|
||||
|
||||
local item_name = ""
|
||||
if itmstck then item_name = itmstck:get_name() end
|
||||
|
||||
local fuel = airutils.contains(airutils.fuel, item_name)
|
||||
if fuel then
|
||||
--local stack = ItemStack(item_name .. " 1")
|
||||
|
||||
if self._energy < self._max_fuel then
|
||||
itmstck:set_count(1)
|
||||
inv:remove_item("main", itmstck)
|
||||
self._energy = self._energy + fuel
|
||||
if self._energy > self._max_fuel then self._energy = self._max_fuel end
|
||||
|
||||
--local energy_indicator_angle = airutils.get_gauge_angle(self._energy)
|
||||
--self.fuel_gauge:set_attach(self.object,'',self._gauge_fuel_position,{x=0,y=0,z=energy_indicator_angle})
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function airutils.consumptionCalc(self, accel)
|
||||
if accel == nil then return end
|
||||
if self._energy > 0 and self._engine_running and accel ~= nil then
|
||||
local divisor = 700000
|
||||
if self._fuel_consumption_divisor then divisor = self._fuel_consumption_divisor end
|
||||
local consumed_power = 0
|
||||
local parent_obj = self.object:get_attach()
|
||||
if not parent_obj then
|
||||
if self._rotor_speed then
|
||||
--is an helicopter
|
||||
consumed_power = 50/divisor --fixed rpm
|
||||
else
|
||||
--is a normal plane
|
||||
consumed_power = self._power_lever/divisor
|
||||
end
|
||||
end
|
||||
--minetest.chat_send_all('consumed: '.. consumed_power)
|
||||
self._energy = self._energy - consumed_power;
|
||||
|
||||
local energy_indicator_angle = airutils.get_gauge_angle(self._energy)
|
||||
if self.fuel_gauge then
|
||||
if self.fuel_gauge:get_luaentity() then
|
||||
self.fuel_gauge:set_attach(self.object,'',self._gauge_fuel_position,{x=0,y=0,z=energy_indicator_angle})
|
||||
end
|
||||
end
|
||||
end
|
||||
if self._energy <= 0 and self._engine_running and accel ~= nil then
|
||||
self._engine_running = false
|
||||
self._autopilot = false
|
||||
if self.sound_handle then minetest.sound_stop(self.sound_handle) end
|
||||
self.object:set_animation_frame_speed(0)
|
||||
end
|
||||
end
|
134
mods/airutils/lib_planes/gauges.lua
Normal file
134
mods/airutils/lib_planes/gauges.lua
Normal file
|
@ -0,0 +1,134 @@
|
|||
--[[
|
||||
local function get_pointer(pointer_angle, gauge_center_x, gauge_center_y, full_pointer)
|
||||
full_pointer = full_pointer or 1
|
||||
local retval = ""
|
||||
local ind_pixel = "airutils_ind_box_2.png"
|
||||
|
||||
local pointer_img_size = 8
|
||||
local pointer_rad = math.rad(pointer_angle)
|
||||
local dim = 2*(pointer_img_size/2)
|
||||
local pos_x = math.sin(pointer_rad) * dim
|
||||
local pos_y = math.cos(pointer_rad) * dim
|
||||
retval = retval..(gauge_center_x+pos_x)..","..(gauge_center_y+pos_y).."="..ind_pixel..":"
|
||||
|
||||
dim = 4*(pointer_img_size/2)
|
||||
pos_x = math.sin(pointer_rad) * dim
|
||||
pos_y = math.cos(pointer_rad) * dim
|
||||
retval = retval..(gauge_center_x+pos_x)..","..(gauge_center_y+pos_y).."="..ind_pixel..":"
|
||||
|
||||
dim = 6*(pointer_img_size/2)
|
||||
pos_x = math.sin(pointer_rad) * dim
|
||||
pos_y = math.cos(pointer_rad) * dim
|
||||
retval = retval..(gauge_center_x+pos_x)..","..(gauge_center_y+pos_y).."="..ind_pixel..":"
|
||||
|
||||
if full_pointer == 1 then
|
||||
dim = 8*(pointer_img_size/2)
|
||||
pos_x = math.sin(pointer_rad) * dim
|
||||
pos_y = math.cos(pointer_rad) * dim
|
||||
retval = retval..(gauge_center_x+pos_x)..","..(gauge_center_y+pos_y).."="..ind_pixel..":"
|
||||
|
||||
dim = 10*(pointer_img_size/2)
|
||||
pos_x = math.sin(pointer_rad) * dim
|
||||
pos_y = math.cos(pointer_rad) * dim
|
||||
retval = retval..(gauge_center_x+pos_x)..","..(gauge_center_y+pos_y).."="..ind_pixel..":"
|
||||
end
|
||||
return retval
|
||||
end
|
||||
]]--
|
||||
|
||||
function airutils.plot_altimeter_gauge(self, scale, place_x, place_y)
|
||||
local bg_width_height = 100
|
||||
local pointer_img = 8
|
||||
local gauge_center = (bg_width_height / 2) - (pointer_img/2)
|
||||
local gauge_center_x = place_x + gauge_center
|
||||
local gauge_center_y = place_y + gauge_center
|
||||
|
||||
|
||||
--altimeter
|
||||
--[[local altitude = (height / 0.32) / 100
|
||||
local hour, minutes = math.modf( altitude )
|
||||
hour = math.fmod (hour, 10)
|
||||
minutes = minutes * 100
|
||||
minutes = (minutes * 100) / 100
|
||||
local minute_angle = (minutes*-360)/100
|
||||
local hour_angle = (hour*-360)/10 + ((minute_angle*36)/360)]]--
|
||||
|
||||
--[[
|
||||
#### `[combine:<w>x<h>:<x1>,<y1>=<file1>:<x2>,<y2>=<file2>:...`
|
||||
|
||||
* `<w>`: width
|
||||
* `<h>`: height
|
||||
* `<x>`: x position
|
||||
* `<y>`: y position
|
||||
* `<file>`: texture to combine
|
||||
|
||||
Creates a texture of size `<w>` times `<h>` and blits the listed files to their
|
||||
specified coordinates.
|
||||
|
||||
]]--
|
||||
|
||||
local altimeter = "^[resize:"..scale.."x"..scale.."^[combine:"..bg_width_height.."x"..bg_width_height..":"
|
||||
..place_x..","..place_y.."=airutils_altimeter_gauge.png:"
|
||||
|
||||
--altimeter = altimeter..get_pointer(minute_angle+180, gauge_center_x, gauge_center_y, 1)
|
||||
--altimeter = altimeter..get_pointer(hour_angle+180, gauge_center_x, gauge_center_y, 0)
|
||||
|
||||
return altimeter
|
||||
end
|
||||
|
||||
function airutils.plot_fuel_gauge(self, scale, place_x, place_y)
|
||||
local bg_width_height = 100
|
||||
local pointer_img = 8
|
||||
local gauge_center = (bg_width_height / 2) - (pointer_img/2)
|
||||
local gauge_center_x = place_x + gauge_center
|
||||
local gauge_center_y = place_y + gauge_center
|
||||
|
||||
--local fuel_percentage = (curr_level*100)/max_level
|
||||
--local fuel_angle = -(fuel_percentage*180)/100
|
||||
--minetest.chat_send_all(dump(fuel_angle))
|
||||
|
||||
local fuel = "^[resize:"..scale.."x"..scale.."^[combine:"..bg_width_height.."x"..bg_width_height..":"
|
||||
..place_x..","..place_y.."=airutils_fuel_gauge.png:"
|
||||
|
||||
--fuel = fuel..get_pointer(fuel_angle-90, gauge_center_x, gauge_center_y, 1)
|
||||
|
||||
return fuel
|
||||
end
|
||||
|
||||
function airutils.plot_speed_gauge(self, scale, place_x, place_y)
|
||||
local bg_width_height = 100
|
||||
local pointer_img = 8
|
||||
local gauge_center = (bg_width_height / 2) - (pointer_img/2)
|
||||
local gauge_center_x = place_x + gauge_center
|
||||
local gauge_center_y = place_y + gauge_center
|
||||
|
||||
--local speed_percentage = (curr_level*100)/max_level
|
||||
--local speed_angle = -(speed_percentage*350)/100
|
||||
--minetest.chat_send_all(dump(fuel_angle))
|
||||
|
||||
local speed = "^[resize:"..scale.."x"..scale.."^[combine:"..bg_width_height.."x"..bg_width_height..":"
|
||||
..place_x..","..place_y.."=airutils_speed_gauge.png:"
|
||||
|
||||
--fuel = fuel..get_pointer(speed_angle-180, gauge_center_x, gauge_center_y, 1)
|
||||
|
||||
return speed
|
||||
end
|
||||
|
||||
function airutils.plot_power_gauge(self, scale, place_x, place_y)
|
||||
local bg_width_height = 100
|
||||
local pointer_img = 8
|
||||
local gauge_center = (bg_width_height / 2) - (pointer_img/2)
|
||||
local gauge_center_x = place_x + gauge_center
|
||||
local gauge_center_y = place_y + gauge_center
|
||||
|
||||
--local speed_percentage = (curr_level*100)/max_level
|
||||
--local speed_angle = -(speed_percentage*350)/100
|
||||
--minetest.chat_send_all(dump(fuel_angle))
|
||||
|
||||
local rpm = "^[resize:"..scale.."x"..scale.."^[combine:"..bg_width_height.."x"..bg_width_height..":"
|
||||
..place_x..","..place_y.."=airutils_rpm_gauge.png:"
|
||||
|
||||
--fuel = fuel..get_pointer(speed_angle-180, gauge_center_x, gauge_center_y, 1)
|
||||
|
||||
return rpm
|
||||
end
|
8
mods/airutils/lib_planes/global_definitions.lua
Normal file
8
mods/airutils/lib_planes/global_definitions.lua
Normal file
|
@ -0,0 +1,8 @@
|
|||
--
|
||||
-- constants
|
||||
--
|
||||
airutils.vector_up = vector.new(0, 1, 0)
|
||||
|
||||
--set min y-pos above which airplanes are seen on radar
|
||||
airutils.radarMinHeight = 30
|
||||
|
328
mods/airutils/lib_planes/hud.lua
Normal file
328
mods/airutils/lib_planes/hud.lua
Normal file
|
@ -0,0 +1,328 @@
|
|||
airutils.hud_list = {}
|
||||
local S = airutils.S
|
||||
|
||||
function airutils.animate_gauge(player, ids, prefix, x, y, angle)
|
||||
local angle_in_rad = math.rad(angle + 180)
|
||||
local dim = 10
|
||||
local pos_x = math.sin(angle_in_rad) * dim
|
||||
local pos_y = math.cos(angle_in_rad) * dim
|
||||
player:hud_change(ids[prefix .. "2"], "offset", {x = pos_x + x, y = pos_y + y})
|
||||
dim = 20
|
||||
pos_x = math.sin(angle_in_rad) * dim
|
||||
pos_y = math.cos(angle_in_rad) * dim
|
||||
player:hud_change(ids[prefix .. "3"], "offset", {x = pos_x + x, y = pos_y + y})
|
||||
dim = 30
|
||||
pos_x = math.sin(angle_in_rad) * dim
|
||||
pos_y = math.cos(angle_in_rad) * dim
|
||||
player:hud_change(ids[prefix .. "4"], "offset", {x = pos_x + x, y = pos_y + y})
|
||||
dim = 40
|
||||
pos_x = math.sin(angle_in_rad) * dim
|
||||
pos_y = math.cos(angle_in_rad) * dim
|
||||
player:hud_change(ids[prefix .. "5"], "offset", {x = pos_x + x, y = pos_y + y})
|
||||
dim = 50
|
||||
pos_x = math.sin(angle_in_rad) * dim
|
||||
pos_y = math.cos(angle_in_rad) * dim
|
||||
player:hud_change(ids[prefix .. "6"], "offset", {x = pos_x + x, y = pos_y + y})
|
||||
dim = 60
|
||||
pos_x = math.sin(angle_in_rad) * dim
|
||||
pos_y = math.cos(angle_in_rad) * dim
|
||||
player:hud_change(ids[prefix .. "7"], "offset", {x = pos_x + x, y = pos_y + y})
|
||||
end
|
||||
|
||||
function airutils.update_hud(player, climb, speed, power, fuel)
|
||||
local player_name = player:get_player_name()
|
||||
|
||||
local screen_pos_y = -150
|
||||
local screen_pos_x = 10
|
||||
|
||||
local clb_gauge_x = screen_pos_x + 75
|
||||
local clb_gauge_y = screen_pos_y + 1
|
||||
local sp_gauge_x = screen_pos_x + 170
|
||||
local sp_gauge_y = clb_gauge_y
|
||||
|
||||
local pwr_gauge_x = screen_pos_x + 330
|
||||
local pwr_gauge_y = clb_gauge_y
|
||||
|
||||
local fu_gauge_x = screen_pos_x + 340
|
||||
local fu_gauge_y = clb_gauge_y
|
||||
|
||||
local ids = airutils.hud_list[player_name]
|
||||
if ids then
|
||||
airutils.animate_gauge(player, ids, "clb_pt_", clb_gauge_x, clb_gauge_y, climb)
|
||||
airutils.animate_gauge(player, ids, "sp_pt_", sp_gauge_x, sp_gauge_y, speed)
|
||||
airutils.animate_gauge(player, ids, "pwr_pt_", pwr_gauge_x, pwr_gauge_y, power)
|
||||
airutils.animate_gauge(player, ids, "fu_pt_", fu_gauge_x, fu_gauge_y, fuel)
|
||||
else
|
||||
ids = {}
|
||||
|
||||
ids["title"] = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = screen_pos_x +140, y = screen_pos_y -100},
|
||||
text = S("Flight Information"),
|
||||
alignment = 0,
|
||||
scale = { x = 100, y = 30},
|
||||
number = 0xFFFFFF,
|
||||
})
|
||||
|
||||
ids["bg"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = screen_pos_x, y = screen_pos_y},
|
||||
text = "airutils_hud_panel.png",
|
||||
scale = { x = 0.5, y = 0.5},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
|
||||
ids["clb_pt_1"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = clb_gauge_x, y = clb_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
|
||||
ids["clb_pt_2"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = clb_gauge_x, y = clb_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["clb_pt_3"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = clb_gauge_x, y = clb_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["clb_pt_4"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = clb_gauge_x, y = clb_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["clb_pt_5"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = clb_gauge_x, y = clb_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["clb_pt_6"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = clb_gauge_x, y = clb_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["clb_pt_7"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = clb_gauge_x, y = clb_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
|
||||
ids["sp_pt_1"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = sp_gauge_x, y = sp_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["sp_pt_2"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = sp_gauge_x, y = sp_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["sp_pt_3"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = sp_gauge_x, y = sp_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["sp_pt_4"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = sp_gauge_x, y = sp_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["sp_pt_5"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = sp_gauge_x, y = sp_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["sp_pt_6"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = sp_gauge_x, y = sp_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["sp_pt_7"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = sp_gauge_x, y = sp_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
|
||||
ids["pwr_pt_1"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = pwr_gauge_x, y = pwr_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
|
||||
ids["pwr_pt_2"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = pwr_gauge_x, y = pwr_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["pwr_pt_3"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = pwr_gauge_x, y = pwr_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["pwr_pt_4"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = pwr_gauge_x, y = pwr_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["pwr_pt_5"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = pwr_gauge_x, y = pwr_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["pwr_pt_6"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = pwr_gauge_x, y = pwr_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["pwr_pt_7"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = pwr_gauge_x, y = pwr_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
|
||||
ids["fu_pt_1"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = fu_gauge_x, y = fu_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
|
||||
ids["fu_pt_2"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = fu_gauge_x, y = fu_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["fu_pt_3"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = fu_gauge_x, y = fu_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["fu_pt_4"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = fu_gauge_x, y = fu_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["fu_pt_5"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = fu_gauge_x, y = fu_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["fu_pt_6"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = fu_gauge_x, y = fu_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["fu_pt_7"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = fu_gauge_x, y = fu_gauge_y},
|
||||
text = "airutils_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
|
||||
airutils.hud_list[player_name] = ids
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function airutils.remove_hud(player)
|
||||
if player then
|
||||
local player_name = player:get_player_name()
|
||||
--minetest.chat_send_all(player_name)
|
||||
local ids = airutils.hud_list[player_name]
|
||||
if ids then
|
||||
--player:hud_remove(ids["altitude"])
|
||||
--player:hud_remove(ids["time"])
|
||||
for key in pairs(ids) do
|
||||
player:hud_remove(ids[key])
|
||||
end
|
||||
end
|
||||
airutils.hud_list[player_name] = nil
|
||||
end
|
||||
|
||||
end
|
19
mods/airutils/lib_planes/init.lua
Normal file
19
mods/airutils/lib_planes/init.lua
Normal file
|
@ -0,0 +1,19 @@
|
|||
|
||||
|
||||
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELIM .. "global_definitions.lua")
|
||||
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELIM .. "control.lua")
|
||||
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELIM .. "fuel_management.lua")
|
||||
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELIM .. "custom_physics.lua")
|
||||
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELIM .. "utilities.lua")
|
||||
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELIM .. "entities.lua")
|
||||
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELIM .. "forms.lua")
|
||||
dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELIM .. "gauges.lua")
|
||||
|
||||
--
|
||||
-- helpers and co.
|
||||
--
|
||||
|
||||
|
||||
--
|
||||
-- items
|
||||
--
|
1406
mods/airutils/lib_planes/utilities.lua
Normal file
1406
mods/airutils/lib_planes/utilities.lua
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue