From 85227b0d7b19a5fc50f4c2d5281a23541d4c715d Mon Sep 17 00:00:00 2001 From: Alexsandro Percy Date: Thu, 29 Jun 2023 20:04:13 -0300 Subject: [PATCH] flight and entities improvements --- common_entities.lua | 24 +++++++++++++++ init.lua | 1 + lib_planes/entities.lua | 52 ++++++++++++++++++++++++-------- lib_planes/forms.lua | 2 +- lib_planes/utilities.lua | 58 ++++++++++++++++++++---------------- textures/airutils_alpha.png | Bin 0 -> 4819 bytes 6 files changed, 97 insertions(+), 40 deletions(-) create mode 100644 common_entities.lua create mode 100644 textures/airutils_alpha.png diff --git a/common_entities.lua b/common_entities.lua new file mode 100644 index 0000000..4688b60 --- /dev/null +++ b/common_entities.lua @@ -0,0 +1,24 @@ +-- +-- seat pivot +-- +minetest.register_entity('airutils:seat_base',{ +initial_properties = { + physical = false, + collide_with_objects=false, + pointable=false, + visual = "mesh", + mesh = "airutils_seat_base.b3d", + textures = {"airutils_alpha.png",}, + }, + + on_activate = function(self,std) + self.sdata = minetest.deserialize(std) or {} + if self.sdata.remove then self.object:remove() end + end, + + get_staticdata=function(self) + self.sdata.remove=true + return minetest.serialize(self.sdata) + end, + +}) diff --git a/init.lua b/init.lua index fc1cda5..40d1a07 100644 --- a/init.lua +++ b/init.lua @@ -33,6 +33,7 @@ if not minetest.settings:get_bool('airutils.disable_repair') then dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "airutils_repair.lua") end airutils.get_wind = dofile(minetest.get_modpath("airutils") .. DIR_DELIM ..'/wind.lua') +dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "common_entities.lua") dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "airutils_wind.lua") dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "inventory_management.lua") dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "light.lua") diff --git a/lib_planes/entities.lua b/lib_planes/entities.lua index a049f10..d8f4fe6 100644 --- a/lib_planes/entities.lua +++ b/lib_planes/entities.lua @@ -106,6 +106,24 @@ function airutils.on_step(self,dtime,colinfo) self.time_total=self.time_total+self.dtime end +local function ground_pitch(self, longit_speed, curr_pitch) + newpitch = curr_pitch + -- adjust pitch at ground + if math.abs(longit_speed) < self._tail_lift_max_speed then + --minetest.chat_send_all(math.abs(longit_speed)) + local speed_range = self._tail_lift_max_speed - self._tail_lift_min_speed + local percentage = 1-((math.abs(longit_speed) - self._tail_lift_min_speed)/speed_range) + if percentage > 1 then percentage = 1 end + if percentage < 0 then percentage = 0 end + local angle = self._tail_angle * percentage + local calculated_newpitch = math.rad(angle) + if newpitch < calculated_newpitch then newpitch = calculated_newpitch end --ja aproveita o pitch atual se ja estiver cerrto + if newpitch > math.rad(self._tail_angle) then newpitch = math.rad(self._tail_angle) end --não queremos arrastar o cauda no chão + end + + return newpitch +end + function airutils.logic(self) local velocity = self.object:get_velocity() local curr_pos = self.object:get_pos() @@ -256,17 +274,7 @@ function airutils.logic(self) -- adjust pitch at ground if math.abs(longit_speed) > self._tail_lift_min_speed then - if math.abs(longit_speed) < self._tail_lift_max_speed then - --minetest.chat_send_all(math.abs(longit_speed)) - local speed_range = self._tail_lift_max_speed - self._tail_lift_min_speed - percentage = 1-((math.abs(longit_speed) - self._tail_lift_min_speed)/speed_range) - if percentage > 1 then percentage = 1 end - if percentage < 0 then percentage = 0 end - local angle = self._tail_angle * percentage - local calculated_newpitch = math.rad(angle) - if newpitch < calculated_newpitch then newpitch = calculated_newpitch end --ja aproveita o pitch atual se ja estiver cerrto - if newpitch > math.rad(self._tail_angle) then newpitch = math.rad(self._tail_angle) end --não queremos arrastar o cauda no chão - end + newpitch = ground_pitch(self, longit_speed, newpitch) else if math.abs(longit_speed) < self._tail_lift_min_speed then newpitch = math.rad(self._tail_angle) @@ -351,8 +359,26 @@ function airutils.logic(self) end local new_accel = accel - if longit_speed > 1.5 then - new_accel = airutils.getLiftAccel(self, velocity, new_accel, longit_speed, roll, curr_pos, self._lift, 15000) + if longit_speed > self._min_speed*0.66 then + --[[lets do something interesting: + here I'll fake the longit speed effect for takeoff, to force the airplane + to use more runway + ]]-- + local factorized_longit_speed = longit_speed + if is_flying == false and airutils.quadBezier then + local takeoff_speed = self._min_speed * 4 --so first I'll consider the takeoff speed 4x the minimal flight speed + if longit_speed < takeoff_speed and longit_speed > self._min_speed then -- then if the airplane is above the mininam speed and bellow the take off + local scale = (longit_speed*1)/takeoff_speed --get a scale of current longit speed relative to takeoff speed + if scale == nil then scale = 0 end --lets avoid any nil + factorized_longit_speed = airutils.quadBezier(scale, self._min_speed, longit_speed, longit_speed) --here the magic happens using a bezier curve + --minetest.chat_send_all("factor: " .. factorized_longit_speed .. " - longit: " .. longit_speed .. " - scale: " .. scale) + if factorized_longit_speed < 0 then factorized_longit_speed = 0 end --lets avoid negative numbers + if factorized_longit_speed == nil then factorized_longit_speed = longit_speed end --and nil numbers + end + end + + local ceiling = 15000 + new_accel = airutils.getLiftAccel(self, velocity, new_accel, factorized_longit_speed, roll, curr_pos, self._lift, ceiling, self._wing_span) end -- end lift diff --git a/lib_planes/forms.lua b/lib_planes/forms.lua index 912c7ce..7949365 100644 --- a/lib_planes/forms.lua +++ b/lib_planes/forms.lua @@ -30,7 +30,7 @@ function airutils.pilot_formspec(name) if ent._yaw_by_mouse then yaw = "true" end basic_form = basic_form.."button[1,1.0;4,1;turn_on;Start/Stop Engines]" - basic_form = basic_form.."button[1,2.1;4,1;go_out;Go Offboard]" + basic_form = basic_form.."button[1,2.1;4,1;go_out;Go Out!]" basic_form = basic_form.."button[1,3.2;4,1;hud;Show/Hide Gauges]" basic_form = basic_form.."button[1,4.3;4,1;inventory;Show Inventory]" basic_form = basic_form.."checkbox[1,5.7;yaw;Yaw by mouse;"..yaw.."]" diff --git a/lib_planes/utilities.lua b/lib_planes/utilities.lua index f67dfc1..a9034fd 100644 --- a/lib_planes/utilities.lua +++ b/lib_planes/utilities.lua @@ -552,6 +552,10 @@ function airutils.paint_with_mask(self, colstr, target_texture, mask_texture) end function airutils.add_destruction_effects(pos, radius) + local node = airutils.nodeatpos(pos) + local is_liquid = false + if (node.drawtype == 'liquid' or node.drawtype == 'flowingliquid') then is_liquid = true end + minetest.sound_play("airutils_explode", { pos = pos, max_hear_distance = 100, @@ -559,32 +563,34 @@ function airutils.add_destruction_effects(pos, radius) fade = 0.0, pitch = 1.0, }, true) - minetest.add_particle({ - pos = pos, - velocity = vector.new(), - acceleration = vector.new(), - expirationtime = 0.4, - size = radius * 10, - collisiondetection = false, - vertical = false, - texture = "airutils_boom.png", - glow = 15, - }) - minetest.add_particlespawner({ - amount = 32, - time = 0.5, - minpos = vector.subtract(pos, radius / 2), - maxpos = vector.add(pos, radius / 2), - minvel = {x = -10, y = -10, z = -10}, - maxvel = {x = 10, y = 10, z = 10}, - minacc = vector.new(), - maxacc = vector.new(), - minexptime = 1, - maxexptime = 2.5, - minsize = radius * 3, - maxsize = radius * 5, - texture = "airutils_boom.png", - }) + if is_liquid == false then + minetest.add_particle({ + pos = pos, + velocity = vector.new(), + acceleration = vector.new(), + expirationtime = 0.4, + size = radius * 10, + collisiondetection = false, + vertical = false, + texture = "airutils_boom.png", + glow = 15, + }) + minetest.add_particlespawner({ + amount = 32, + time = 0.5, + minpos = vector.subtract(pos, radius / 2), + maxpos = vector.add(pos, radius / 2), + minvel = {x = -10, y = -10, z = -10}, + maxvel = {x = 10, y = 10, z = 10}, + minacc = vector.new(), + maxacc = vector.new(), + minexptime = 1, + maxexptime = 2.5, + minsize = radius * 3, + maxsize = radius * 5, + texture = "airutils_boom.png", + }) + end minetest.add_particlespawner({ amount = 64, time = 1.0, diff --git a/textures/airutils_alpha.png b/textures/airutils_alpha.png new file mode 100644 index 0000000000000000000000000000000000000000..aae5d892f2863267b20ea1c446b59ad1212bc720 GIT binary patch literal 4819 zcmeHKdsGu=77w7}A}oqvm4d_ot|*gC-VX>5144ud@(>UNhRGxb@*){Xz_)-^vB*O~ zEd_kh6%`e=m4{YWKwY&`0j;i}qExG*9Fa;Db-x5uJllUfXZs(?naRw3{O-NK?|yeO z8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