From d758c2957d246c1e4ada02dd4b865adfb7859c1b Mon Sep 17 00:00:00 2001 From: Alexsandro Percy Date: Sat, 7 May 2022 09:59:37 -0300 Subject: [PATCH] fix control compression and added damage by overspeed --- control.lua | 11 +---------- init.lua | 28 +++++++++++++++++++++++++++ utilities.lua | 52 +++++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 75 insertions(+), 16 deletions(-) diff --git a/control.lua b/control.lua index 3c083da..cd5e7bc 100755 --- a/control.lua +++ b/control.lua @@ -200,15 +200,6 @@ function pa28.elevator_auto_correction(self, longit_speed, dtime) end end ---obsolete, will be removed -function getAdjustFactor(curr_y, desired_y) - local max_difference = 0.1 - local adjust_factor = 0.5 - local difference = math.abs(curr_y - desired_y) - if difference > max_difference then difference = max_difference end - return (difference * adjust_factor) / max_difference -end - function pa28.autopilot(self, dtime, hull_direction, longit_speed, accel, curr_pos) local retval_accel = accel @@ -230,7 +221,7 @@ function pa28.autopilot(self, dtime, hull_direction, longit_speed, accel, curr_p local engineacc = (self._power_lever * pa28.max_engine_acc) / 100; --self.engine:set_animation_frame_speed(60 + self._power_lever) - local factor = math.abs(climb_rate * 0.1) --getAdjustFactor(curr_pos.y, self._auto_pilot_altitude) + local factor = math.abs(climb_rate * 0.1) --increase power lever if climb_rate > 0.2 then pa28.powerAdjust(self, dtime, factor, -1) diff --git a/init.lua b/init.lua index 1affc63..ac0849e 100755 --- a/init.lua +++ b/init.lua @@ -85,3 +85,31 @@ minetest.register_chatcommand("pa28_manual", { end }) +--[[minetest.register_chatcommand("pa28_up", { + params = "", + description = "Command for test the PA28, putting 100 blocks up - only works with server priv", + privs = {server = true}, + func = function(name, param) + local colorstring = core.colorize('#ff0000', " >>> you are not inside a PA28") + local player = minetest.get_player_by_name(name) + local attached_to = player:get_attach() + + if attached_to ~= nil then + local seat = attached_to:get_attach() + if seat ~= nil then + local entity = seat:get_luaentity() + if entity then + if entity.name == "pa28:pa28" then + local curr_pos = player:get_pos() + curr_pos.y = curr_pos.y + 100 + entity.object:move_to(curr_pos) + else + minetest.chat_send_player(name,colorstring) + end + end + end + else + minetest.chat_send_player(name,colorstring) + end + end +})]]-- diff --git a/utilities.lua b/utilities.lua index 9e07b2a..e57885a 100755 --- a/utilities.lua +++ b/utilities.lua @@ -244,7 +244,7 @@ function pa28.destroy(self) --minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'hidroplane:hidro') end -function pa28.testImpact(self, velocity, position) +function pa28.testDamage(self, velocity, position) if self._last_accell == nil then return end local p = position --self.object:get_pos() local collision = false @@ -283,6 +283,30 @@ function pa28.testImpact(self, velocity, position) end end + --damage by speed + if self._last_speed_damage_time == nil then self._last_speed_damage_time = 0 end + self._last_speed_damage_time = self._last_speed_damage_time + self.dtime + if self._last_speed_damage_time > 2 then self._last_speed_damage_time = 2 end + if self._longit_speed > 14.7 and self._last_speed_damage_time >= 2 then + self._last_speed_damage_time = 0 + minetest.sound_play("pa28_collision", { + --to_player = self.driver_name, + object = self.object, + max_hear_distance = 15, + gain = 1.0, + fade = 0.0, + pitch = 1.0, + }, true) + self.hp_max = self.hp_max - 5 + if self.driver_name then + local player_name = self.driver_name + airutils.setText(self, pa28.plane_text) + end + if self.hp_max < 0 then --if acumulated damage is greater than 50, adieu + pa28.destroy(self) + end + end + if collision then --self.object:set_velocity({x=0,y=0,z=0}) local damage = impact -- / 2 @@ -447,8 +471,9 @@ function pa28.flightstep(self) local passenger = nil if self._passenger then passenger = minetest.get_player_by_name(self._passenger) end + local ctrl = nil if player then - local ctrl = player:get_player_control() + ctrl = player:get_player_control() --------------------- -- change the driver --------------------- @@ -581,7 +606,6 @@ function pa28.flightstep(self) if longit_speed > pa28.min_speed then speed_factor = (velocity.y * math.rad(1)) end local newpitch = math.rad(self._angle_of_attack) + speed_factor - -- adjust pitch at ground if is_flying == false then if newpitch < 0 then newpitch = 0 end @@ -741,13 +765,29 @@ function pa28.flightstep(self) climb_rate = -5 end + --in a command compression during a dive, force the control to recover + local longit_initial_speed = 13.0 + --minetest.chat_send_all(longit_speed) + if longit_speed > longit_initial_speed and climb_rate < 0 and is_flying then + local recover_command = -0.2 + if ctrl then + if not ctrl.up then + self._elevator_angle = recover_command + end + else + self._elevator_angle = recover_command + end + end + --is an stall, force a recover - if longit_speed < (pa28.min_speed / 2) and climb_rate < -3.5 and is_flying then + if longit_speed < (pa28.min_speed / 2) and climb_rate < -3 and is_flying then self._elevator_angle = 0 self._angle_of_attack = -2 newpitch = math.rad(self._angle_of_attack) end + --minetest.chat_send_all("speed: "..longit_speed.." - climb: "..climb_rate.." - angle attack: "..self._angle_of_attack.." - elevator:"..self._elevator_angle) + --minetest.chat_send_all('rate '.. climb_rate) local climb_angle = pa28.get_gauge_angle(climb_rate) self.object:set_bone_position("climber", {x=-1.98,y=2.40,z=10.2}, {x=0,y=0,z=climb_angle-90}) @@ -845,8 +885,8 @@ function pa28.flightstep(self) -- calculate energy consumption -- pa28.consumptionCalc(self, accel) - --test collision - pa28.testImpact(self, self.object:get_velocity(), curr_pos) + --test damage + pa28.testDamage(self, self.object:get_velocity(), curr_pos) --saves last velocity for collision detection (abrupt stop) self._last_vel = self.object:get_velocity()