From 3040a5c89059b2fb939717ce38c8b52c64ec668c Mon Sep 17 00:00:00 2001 From: Niklp <nik@niklp.net> Date: Sat, 5 Oct 2024 11:27:56 +0200 Subject: [PATCH] Try to fix most warnings reported by luacheck --- .luacheckrc | 46 +++++++++++++++++++++++++++ airutils_biofuel.lua | 9 +----- airutils_papi.lua | 15 ++------- airutils_tug.lua | 5 ++- airutils_wind.lua | 20 ++++++------ attach_extern_ent.lua | 16 +++++----- common_entities.lua | 6 ++-- init.lua | 17 ++-------- lib_copter/control.lua | 39 ++++------------------- lib_copter/entities.lua | 12 +++---- lib_planes/control.lua | 24 +++----------- lib_planes/custom_physics.lua | 9 +++--- lib_planes/entities.lua | 53 ++++++++++++++----------------- lib_planes/forms.lua | 19 +++++------- lib_planes/fuel_management.lua | 4 +-- lib_planes/gauges.lua | 14 +++++---- lib_planes/hud.lua | 2 +- lib_planes/init.lua | 8 ----- lib_planes/utilities.lua | 57 +++++++++++++++------------------- light.lua | 2 +- physics_lib.lua | 36 ++++++++++----------- pilot_skin_manager.lua | 4 +-- text.lua | 16 +++++----- texture_management.lua | 4 +-- water_splash.lua | 8 ++--- 25 files changed, 194 insertions(+), 251 deletions(-) create mode 100644 .luacheckrc diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..14d4d8a --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,46 @@ +-- Disable some (non critical) warnings +-- unused = false +unused_args = false +redefined = false + +globals = { + "airutils", +} + +read_globals = { + "DIR_DELIM", + "ItemStack", + "PseudoRandom", + "basic_machines", + "biomass", + "climate_api", + "core", + "creative", + "default", + "dump", + "emote", + "math", + "mcl_formspec", + "mcl_player", + "minetest", + "player_api", + "signs_lib", + "skins", + "string", + "technic", + "vector", + "wardrobe", +} + +-- Per file options +files["airutils_biofuel.lua"] = { + globals = {"basic_machines.grinder_recipes"}, +} + +files["lib_planes/utilities.lua"] = { + globals = {"player_api.player_attached.?", "mcl_player.player_attached.?"} +} + +files["pilot_skin_manager.lua"] = { + globals = {"skins.skin_class.apply_skin_to_player"} +} \ No newline at end of file diff --git a/airutils_biofuel.lua b/airutils_biofuel.lua index f97e699..9505962 100644 --- a/airutils_biofuel.lua +++ b/airutils_biofuel.lua @@ -75,7 +75,7 @@ local ferment_groups = {'flora', 'leaves', 'flower', 'sapling', 'tree', 'wood', local biofueldistiller_formspec = "size[8,9]" .. "list[current_name;src;2,1;1,1;]" .. airutils.get_itemslot_bg(2, 1, 1, 1) .. "list[current_name;dst;5,1;1,1;]" .. airutils.get_itemslot_bg(5, 1, 1, 1) - .. "list[current_player;main;0,5;8,4;]" .. airutils.get_itemslot_bg(0, 5, 8, 4) + .. "list[current_player;main;0,5;8,4;]" .. airutils.get_itemslot_bg(0, 5, 8, 4) .. "listring[current_name;dst]" .. "listring[current_player;main]" .. "listring[current_name;src]" @@ -138,9 +138,6 @@ minetest.register_node( module_name .. ":biofuel_distiller", { return 0 end - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - if listname == "src" then return stack:get_count() elseif listname == "dst" then @@ -154,10 +151,6 @@ minetest.register_node( module_name .. ":biofuel_distiller", { return 0 end - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - local stack = inv:get_stack(from_list, from_index) - if to_list == "src" then return count elseif to_list == "dst" then diff --git a/airutils_papi.lua b/airutils_papi.lua index d589392..c5c548c 100644 --- a/airutils_papi.lua +++ b/airutils_papi.lua @@ -19,7 +19,6 @@ function airutils.PAPIplace(player,pos) end local dir = minetest.dir_to_facedir(player:get_look_dir()) - local pos1 = vector.new(pos) local player_name = player:get_player_name() if check_protection(pos, player_name) then @@ -45,7 +44,7 @@ function airutils.togglePapiSide(pos, node, clicker, itemstack) local dir=node.param2 if node.name == "airutils:papi_right" then core.set_node(pos, {name="airutils:papi", param2=dir}) - meta:set_string("infotext", S("PAPI") .. " - " .. S("left side") .. "\r" .. S("Owned by: @1",player_name)) + meta:set_string("infotext", S("PAPI") .. " - " .. S("left side") .. "\r" .. S("Owned by: @1",player_name)) elseif node.name == "airutils:papi" then core.set_node(pos, {name="airutils:papi_right", param2=dir}) meta:set_string("infotext", S("PAPI") .. " - " .. S("right side") .. "\r" .. S("Owned by: @1",player_name)) @@ -107,11 +106,6 @@ minetest.register_node("airutils:papi",{ return end end - - local itmstck=puncher:get_wielded_item() - local item_name = "" - if itmstck then item_name = itmstck:get_name() end - end, }) @@ -123,7 +117,7 @@ function airutils.remove_papi(pos) local dir=node.param2 if node.name == "airutils:papi_right" then core.set_node(pos, {name="airutils:papi", param2=dir}) - meta:set_string("infotext", "PAPI - left side\rOwned by: "..player_name) + meta:set_string("infotext", "PAPI - left side\rOwned by: "..player_name) end meta:set_string("owner", player_name) @@ -161,11 +155,6 @@ minetest.register_node("airutils:papi_right",{ if player_name ~= meta:get_string("owner") then return end - - local itmstck=puncher:get_wielded_item() - local item_name = "" - if itmstck then item_name = itmstck:get_name() end - end, }) diff --git a/airutils_tug.lua b/airutils_tug.lua index 0b8f8d0..418a477 100644 --- a/airutils_tug.lua +++ b/airutils_tug.lua @@ -50,9 +50,8 @@ minetest.register_tool("airutils:tug", { return end - local is_admin = false - is_admin = minetest.check_player_privs(player, {server=true}) - + local is_admin = minetest.check_player_privs(player, {server=true}) + local pos = player:get_pos() local pname = player:get_player_name() diff --git a/airutils_wind.lua b/airutils_wind.lua index 786807e..da9206d 100644 --- a/airutils_wind.lua +++ b/airutils_wind.lua @@ -47,7 +47,7 @@ airutils.wind_selection_box = { local function get_smooth(angle_initial, reference, last_ref, value) local range = reference-last_ref local retVal = (value*angle_initial)/range - retval = angle_initial - retVal + local retval = angle_initial - retVal if retval < 0 then retval = 0 end return retval end @@ -55,7 +55,7 @@ end minetest.register_entity("airutils:wind_indicator",{ -- common props physical = true, - stepheight = 0.5, + stepheight = 0.5, collide_with_objects = true, collisionbox = {-0.5, 0, -0.5, 0.5, 5.0, 0.5}, visual = "mesh", @@ -113,14 +113,13 @@ minetest.register_entity("airutils:wind_indicator",{ on_punch=function(self, puncher) return end, - + on_rightclick = function(self, clicker) - local wind = airutils.get_wind(pos, 2.0) + local wind = airutils.get_wind(self.object:get_pos(), 2.0) local wind_yaw = minetest.dir_to_yaw(wind) minetest.chat_send_player(clicker:get_player_name(),core.colorize('#00ff00', S(" >>> The wind direction now is @1", math.deg(wind_yaw)))) return end, - }) @@ -141,13 +140,13 @@ minetest.register_node("airutils:wind",{ {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, {-0.1, 0.5, -0.1, 0.1, 2.0, 0.1} } - }, - + }, + node_dig_prediction = "default:dirt", node_placement_prediction = "airutils:wind", - + on_place = function(itemstack, placer, pointed_thing) - + local pos = pointed_thing.above local player_name = placer:get_player_name() @@ -156,7 +155,6 @@ minetest.register_node("airutils:wind",{ if not minetest.is_protected(pos, player_name) and not minetest.is_protected(pos, player_name) then minetest.set_node(pos, {name = "airutils:wind",param2 = 1 }) minetest.add_entity({x=pos.x, y=pos.y, z=pos.z},"airutils:wind_indicator") - local meta = minetest.get_meta(pos) if not (creative and creative.is_enabled_for and creative.is_enabled_for(player_name)) then itemstack:take_item() end @@ -168,7 +166,7 @@ minetest.register_node("airutils:wind",{ return itemstack end, - + on_destruct = function(pos) local meta=minetest.get_meta(pos) if meta then diff --git a/attach_extern_ent.lua b/attach_extern_ent.lua index a84fafe..c29d657 100644 --- a/attach_extern_ent.lua +++ b/attach_extern_ent.lua @@ -29,12 +29,11 @@ function airutils.get_attached_entity(self) if not self._vehicle_custom_data then return nil, nil end if not self._vehicle_custom_data.simple_external_attach_entity then return nil, nil end - local entity_name = self._vehicle_custom_data.simple_external_attach_entity local inv_id = self._vehicle_custom_data.simple_external_attach_invid local pos = self.object:get_pos() local nearby_objects = minetest.get_objects_inside_radius(pos, 32) - for i,obj in ipairs(nearby_objects) do + for i,obj in ipairs(nearby_objects) do local ent = obj:get_luaentity() if ent then if ent._inv_id then @@ -85,12 +84,12 @@ function airutils.simple_external_attach(self, relative_pos, entity_name, radius attach_up = attach_up or false radius = radius or 12 if self.object then - local curr_ent, curr_obj = airutils.get_attached_entity(self) + local curr_ent, _ = airutils.get_attached_entity(self) if curr_ent then return end local pos = self.object:get_pos() local nearby_objects = minetest.get_objects_inside_radius(pos, radius) - for i,obj in ipairs(nearby_objects) do + for i,obj in ipairs(nearby_objects) do if obj == self.object then table.remove(nearby_objects,i) end @@ -98,7 +97,7 @@ function airutils.simple_external_attach(self, relative_pos, entity_name, radius if ent then if ent.name == entity_name then airutils.attach_external_object(self, nearby_objects[i], ent, pos, relative_pos, attach_up) - return + return end end end @@ -109,10 +108,9 @@ end function airutils.restore_external_attach(self) if not self._vehicle_custom_data then return end if not self._vehicle_custom_data.simple_external_attach_invid then return end - + local pos = self.object:get_pos() local dest_pos = vector.new(pos) - local entity_name = self._vehicle_custom_data.simple_external_attach_entity local relative_pos = self._vehicle_custom_data.simple_external_attach_pos local inv_id = self._vehicle_custom_data.simple_external_attach_invid dest_pos = vector.add(dest_pos, relative_pos) @@ -126,7 +124,7 @@ function airutils.restore_external_attach(self) --minetest.chat_send_all(dump(ent.name)) if ent._inv_id then --minetest.chat_send_all(">> "..dump(ent._inv_id).." >> "..dump(inv_id)) - if ent._inv_id == inv_id and (not (ent._inv_id == self._inv_id)) then + if ent._inv_id == inv_id and ent._inv_id ~= self._inv_id then --minetest.chat_send_all("++ "..dump(ent._inv_id).." ++ "..dump(inv_id)) local target_obj = nearby_objects[i] target_obj:set_pos(dest_pos) @@ -173,7 +171,7 @@ minetest.register_chatcommand("remove_hook", { local velocity = rem_ent.object:get_velocity() local move = 0 - if rem_ent._vehicle_custom_data.simple_external_attach_pos then + if rem_ent._vehicle_custom_data.simple_external_attach_pos then move = -1*rem_ent._vehicle_custom_data.simple_external_attach_pos.z/10 end pos.x = pos.x + move * math.sin(direction) diff --git a/common_entities.lua b/common_entities.lua index 4688b60..0f6bb64 100644 --- a/common_entities.lua +++ b/common_entities.lua @@ -10,15 +10,15 @@ initial_properties = { 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 1f66a63..4089876 100644 --- a/init.lua +++ b/init.lua @@ -300,15 +300,6 @@ end -- max_height: the max ceilling for the airplane -- wingspan: for ground effect calculation function airutils.getLiftAccel(self, velocity, accel, longit_speed, roll, curr_pos, in_lift, max_height, wingspan) - local new_velocity = vector.new(velocity) - if not self._min_collective then --ignore if it is an helicopter - --add wind to the lift calcs - local wind = airutils.get_wind(curr_pos, 5) - local accel_wind = vector.subtract(accel, wind) --why? because I need to fake more speed when against the wind to gain lift - local vel_wind = vector.multiply(accel_wind, self.dtime) - new_velocity = vector.add(new_velocity, vel_wind) - end - if longit_speed == nil then longit_speed = 0 end wingspan = wingspan or 10 local lift = in_lift @@ -374,7 +365,7 @@ function airutils.getLiftAccel(self, velocity, accel, longit_speed, roll, curr_p retval = vector.add(retval,lift_acc) ----------------------------------------------------------- -- end lift - + return retval end @@ -439,7 +430,7 @@ function airutils.set_paint(self, puncher, itmstck, texture_name) else --painting with dyes local split = string.split(item_name, ":") - local color, indx, _ + local indx, _ if split[1] then _,indx = split[1]:find('dye') end if indx then --[[for clr,_ in pairs(airutils.colors) do @@ -469,7 +460,7 @@ function airutils._set_name(self) if not airutils._use_signs_api then return end local l_textures = self.object:get_properties().textures --self.initial_properties.textures for _, texture in ipairs(l_textures) do - indx = texture:find('airutils_name_canvas.png') + local indx = texture:find('airutils_name_canvas.png') if indx then l_textures[_] = "airutils_name_canvas.png^"..airutils.convert_text_to_texture(self._ship_name, self._name_color or 0, self._name_hor_aligment or 0.8) end @@ -606,7 +597,6 @@ minetest.register_chatcommand("ground_effect", { description = S("Enables/disables the ground effect (for debug purposes)"), privs = {server=true}, func = function(name, param) - local player = minetest.get_player_by_name(name) if minetest.check_player_privs(name, {server=true}) then if param == "on" or param == "" then airutils.ground_effect_is_disabled = nil @@ -626,7 +616,6 @@ minetest.register_chatcommand("show_lift", { description = S("Enables/disables the lift printing (for debug purposes)"), privs = {server=true}, func = function(name, param) - local player = minetest.get_player_by_name(name) if minetest.check_player_privs(name, {server=true}) then if param == "on" or param == "" then airutils.show_lift = name diff --git a/lib_copter/control.lua b/lib_copter/control.lua index a8ba873..da1eecb 100755 --- a/lib_copter/control.lua +++ b/lib_copter/control.lua @@ -4,33 +4,10 @@ local S = airutils.S dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELIM .. "utilities.lua") -local function floating_auto_correction(self, dtime) - local factor = 1 - local range = 0.03 --above and bellow - - if self._wing_configuration > self._stable_collective + range or - self._wing_configuration < self._stable_collective - range then - return - end - - --minetest.chat_send_player(self.driver_name, "antes: " .. self._air_float) - if self._wing_configuration > self._stable_collective then factor = -1 end - local time_correction = (dtime/airutils.ideal_step) - if time_correction < 1 then time_correction = 1 end - local intensity = 1 - local correction = (intensity*factor) * time_correction - - local new_wing_configuration = self._wing_configuration + correction - - self._wing_configuration = new_wing_configuration - - --minetest.chat_send_all(dump(self._wing_configuration)) -end - local function 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 @@ -40,7 +17,7 @@ local function set_yaw_by_mouse(self, dir) local intensity = self._yaw_intensity / 10 local command = (rot_y - dir) * intensity - if command < -90 then command = -90 + 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) @@ -62,7 +39,7 @@ function airutils.heli_control(self, dtime, hull_direction, longit_speed, longit local retval_accel = accel local stop = false - local ctrl = nil + local ctrl local time_correction = (dtime/airutils.ideal_step) if time_correction < 1 then time_correction = 1 end @@ -78,12 +55,8 @@ function airutils.heli_control(self, dtime, hull_direction, longit_speed, longit if not self._acceleration then self._acceleration = 0 end if not self._lat_acceleration then self._lat_acceleration = 0 end - + if self._engine_running then - --engine acceleration calc - - local factor = 1 - --control lift local collective_up_max = 1.2 local min_angle = self._min_collective @@ -137,7 +110,7 @@ function airutils.heli_control(self, dtime, hull_direction, longit_speed, longit end elseif ctrl.left then yaw_cmd = -1 - if later_speed > -self._max_speed and self._yaw_by_mouse then + if later_speed > -self._max_speed and self._yaw_by_mouse then self._lat_acceleration = self._lat_acceleration + (-acc_fraction) else self._lat_acceleration = 0 @@ -187,7 +160,7 @@ function airutils.heli_control(self, dtime, hull_direction, longit_speed, longit end end end - + return retval_accel, stop end diff --git a/lib_copter/entities.lua b/lib_copter/entities.lua index 36b0037..c7baa4e 100644 --- a/lib_copter/entities.lua +++ b/lib_copter/entities.lua @@ -1,6 +1,6 @@ dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELIM .. "global_definitions.lua") -function engineSoundPlay(self, increment, base) +local function engineSoundPlay(self, increment, base) increment = increment or 0.0 --sound if self.sound_handle then minetest.sound_stop(self.sound_handle) end @@ -17,14 +17,14 @@ end local function engine_set_sound_and_animation(self, is_flying, newpitch, newroll) is_flying = is_flying or false - + if self._engine_running then --engine running if not self.sound_handle then engineSoundPlay(self, 0.0, 0.9) end --self._cmd_snd if self._snd_last_cmd ~= self._cmd_snd then - local increment = 0.0 + local increment self._snd_last_cmd = self._cmd_snd if self._cmd_snd then increment = 0.1 else increment = 0.0 end engineSoundPlay(self, increment, 0.9) @@ -34,7 +34,7 @@ local function engine_set_sound_and_animation(self, is_flying, newpitch, newroll else if is_flying then --autorotation here if self._snd_last_cmd ~= self._cmd_snd then - local increment = 0.0 + local increment self._snd_last_cmd = self._cmd_snd if self._cmd_snd then increment = 0.1 else increment = 0.0 end engineSoundPlay(self, increment, 0.6) @@ -100,7 +100,6 @@ function airutils.logic_heli(self) local rotation = self.object:get_rotation() local yaw = rotation.y local newyaw=yaw - local pitch = rotation.x local roll = rotation.z local hull_direction = airutils.rot_to_dir(rotation) --minetest.yaw_to_dir(yaw) @@ -118,7 +117,6 @@ function airutils.logic_heli(self) local accel = vector.add(longit_drag,later_drag) local stop = false - local node_bellow = airutils.nodeatpos(airutils.pos_shift(curr_pos,{y=-1.3})) local is_flying = true if self.colinfo then is_flying = (not self.colinfo.touching_ground) @@ -290,7 +288,7 @@ function airutils.logic_heli(self) self._last_accell = new_accel self.object:move_to(curr_pos) --airutils.set_acceleration(self.object, new_accel) - local limit = self._climb_speed + --local limit = self._climb_speed --if new_accel.y > limit then new_accel.y = limit end --it isn't a rocket :/ else diff --git a/lib_planes/control.lua b/lib_planes/control.lua index ce9ff4f..0ef58da 100755 --- a/lib_planes/control.lua +++ b/lib_planes/control.lua @@ -11,7 +11,6 @@ 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 - local power_index = self._power_lever if dir == 1 then if self._power_lever < max then @@ -46,7 +45,7 @@ function airutils.control(self, dtime, hull_direction, longit_speed, longit_drag if ctrl.aux1 and self._last_time_command > 0.5 then self._last_time_command = 0 - + end ---------------------------------- -- flap operation @@ -150,8 +149,7 @@ function airutils.control(self, dtime, hull_direction, longit_speed, longit_drag if longit_speed > 0 then if ctrl then - if ctrl.right or ctrl.left then - else + if not (ctrl.right or ctrl.left) then airutils.rudder_auto_correction(self, longit_speed, dtime) end else @@ -178,11 +176,9 @@ function airutils.set_pitch(self, dir, dtime) local multiplier = pitch_factor*(dtime/airutils.ideal_step) if dir == -1 then --minetest.chat_send_all("cabrando") - if self._elevator_angle > 0 then pitch_factor = pitch_factor * 2 end self._elevator_angle = math.max(self._elevator_angle-multiplier,-self._elevator_limit) elseif dir == 1 then --minetest.chat_send_all("picando") - if self._angle_of_attack < 0 then pitch_factor = 1 end --lets reduce the command power to avoid accidents self._elevator_angle = math.min(self._elevator_angle+multiplier,self._elevator_limit) end end @@ -192,11 +188,9 @@ function airutils.set_autopilot_pitch(self, dir, dtime) local multiplier = pitch_factor*(dtime/airutils.ideal_step) if dir == -1 then --minetest.chat_send_all("cabrando") - if self._elevator_angle > 0 then pitch_factor = pitch_factor * 2 end self._elevator_angle = math.max(self._elevator_angle-multiplier,-self._elevator_limit) elseif dir == 1 then --minetest.chat_send_all("picando") - if self._angle_of_attack < 0 then pitch_factor = 1 end --lets reduce the command power to avoid accidents self._elevator_angle = math.min(self._elevator_angle+multiplier,self._elevator_limit) end end @@ -204,7 +198,7 @@ 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 @@ -214,7 +208,7 @@ function airutils.set_yaw_by_mouse(self, dir) local intensity = self._yaw_intensity / 10 local command = (rot_y - dir) * intensity - if command < -90 then command = -90 + 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) @@ -243,22 +237,12 @@ function airutils.rudder_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 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 max_autopilot_power = 85 local max_attack_angle = 1.8 --climb diff --git a/lib_planes/custom_physics.lua b/lib_planes/custom_physics.lua index 34c887e..1c87eb8 100755 --- a/lib_planes/custom_physics.lua +++ b/lib_planes/custom_physics.lua @@ -30,7 +30,6 @@ function airutils.physics(self) end if self.isinliquid then - local accell = {x=0, y=0, z=0} self.water_drag = 0.2 self.isinliquid = true local height = self.height @@ -38,7 +37,7 @@ function airutils.physics(self) -- local balance = self.buoyancy*self.height local buoyacc = airutils.gravity*(self.buoyancy-submergence) --local buoyacc = self._baloon_buoyancy*(self.buoyancy-submergence) - accell = { + local accell = { x=-vel.x*self.water_drag, y=buoyacc-(vel.y*math.abs(vel.y)*0.4), z=-vel.z*self.water_drag @@ -53,7 +52,7 @@ function airutils.physics(self) 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 @@ -71,7 +70,7 @@ function airutils.physics(self) -- 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 @@ -79,7 +78,7 @@ function airutils.physics(self) end end end - + if not vector.equals(new_velocity,vnew) then self.collided = true else diff --git a/lib_planes/entities.lua b/lib_planes/entities.lua index 430af2b..1dd3872 100644 --- a/lib_planes/entities.lua +++ b/lib_planes/entities.lua @@ -76,7 +76,7 @@ function airutils.on_activate(self, staticdata, dtime_s) return end end - + self._climb_rate = 0 self._yaw = 0 self._roll = 0 @@ -99,7 +99,7 @@ function airutils.on_activate(self, staticdata, dtime_s) if self._anim_start_frame then start_frame = self._anim_start_frame end_frame = self._anim_start_frame + self._anim_frames - end + end self.object:set_animation({x = start_frame, y = end_frame}, 0, 0, true) if self.wheels then @@ -135,7 +135,7 @@ function airutils.on_step(self,dtime,colinfo) self.dtime = math.min(dtime,0.2) self.colinfo = colinfo self.height = airutils.get_box_height(self) - + -- physics comes first local vel = self.object:get_velocity() local pos = self.object:get_pos() @@ -154,8 +154,8 @@ function airutils.on_step(self,dtime,colinfo) props.show_on_minimap = false self.object:set_properties(props) end - - if colinfo then + + if colinfo then self.isonground = colinfo.touching_ground else if self.lastvelocity.y==0 and vel.y==0 then @@ -164,7 +164,7 @@ function airutils.on_step(self,dtime,colinfo) self.isonground = false end end - + if self.hp_max <= 0 then airutils.destroy(self) end @@ -174,7 +174,7 @@ function airutils.on_step(self,dtime,colinfo) if self.logic then self:logic() end - + self.lastvelocity = self.object:get_velocity() self.time_total=self.time_total+self.dtime end @@ -205,7 +205,7 @@ local function ground_pitch(self, longit_speed, curr_pitch) 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 @@ -280,7 +280,6 @@ function airutils.logic(self) local rotation = self.object:get_rotation() local yaw = rotation.y local newyaw=yaw - local pitch = rotation.x local roll = rotation.z local newroll=roll newroll = math.floor(newroll/360) @@ -411,11 +410,12 @@ function airutils.logic(self) --is an stall, force a recover if longit_speed < (self._min_speed+0.5) and climb_rate < -1.5 and is_flying then + --[[ if player and self.driver_name then - --minetest.chat_send_player(self.driver_name,core.colorize('#ff0000', " >>> STALL")) + minetest.chat_send_player(self.driver_name,core.colorize('#ff0000', " >>> STALL")) end + ]]-- self._elevator_angle = 0 - actuator_angle = 0 self._angle_of_attack = -1 newpitch = math.rad(self._angle_of_attack) else @@ -439,7 +439,7 @@ function airutils.logic(self) end --limiting the very high climb angle due to strange behavior]]--]]-- if self._inverted_pitch_reaction then self._elevator_angle = -1*actuator_angle end --revert the reversion - + end end @@ -516,7 +516,7 @@ function airutils.logic(self) --end accell --get disconnected players - if not self._autoflymode == true then + if self._autoflymode ~= true then airutils.rescueConnectionFailedPassengers(self) end @@ -557,7 +557,7 @@ function airutils.logic(self) 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 + to use more runway ]]-- local factorized_longit_speed = longit_speed if is_flying == false and airutils.quadBezier then @@ -727,27 +727,26 @@ function airutils.on_punch(self, puncher, ttime, toolcaps, dir, damage) end if self._vehicle_name then airutils.setText(self, self._vehicle_name) end - if (string.find(puncher:get_wielded_item():get_name(), "rayweapon") or + if (string.find(puncher:get_wielded_item():get_name(), "rayweapon") or toolcaps.damage_groups.vehicle) then damage_vehicle(self, toolcaps, ttime, damage) end - local is_admin = false - is_admin = minetest.check_player_privs(puncher, {server=true}) + local is_admin = minetest.check_player_privs(puncher, {server=true}) if self.owner == nil then self.owner = name end if self.owner and self.owner ~= name and self.owner ~= "" then if is_admin == false then return end end - + if is_admin == false and minetest.check_player_privs(puncher, {protection_bypass=false}) then if self.driver_name and self.driver_name ~= name then -- do not allow other players to remove the object while there is a driver return end end - + local is_attached = false local player_attach = puncher:get_attach() if player_attach then @@ -758,7 +757,7 @@ function airutils.on_punch(self, puncher, ttime, toolcaps, dir, damage) is_attached = true end end - + if puncher:get_attach() == self.object then is_attached = true end --if puncher:get_attach() == self.pilot_seat_base then is_attached = true end @@ -831,9 +830,9 @@ local function get_vehicle(self, player) local lua_ent = self.object:get_luaentity() local staticdata = lua_ent:get_staticdata(self) local obj_name = lua_ent.name + local pos = self.object:get_pos() local stack = ItemStack(obj_name) - local max = stack:get_stack_max() local tool = false if stack:get_stack_max() == 1 then tool = true end @@ -863,7 +862,7 @@ local function get_vehicle(self, player) return true end - + return false end @@ -886,8 +885,6 @@ function airutils.on_rightclick(self, clicker) --minetest.chat_send_all(dump(self.driver_name)) - local touching_ground, liquid_below = airutils.check_node_below(self.object, 2.5) - local is_on_ground = self.isinliquid or touching_ground or liquid_below local is_under_water = airutils.check_is_under_water(self.object) --minetest.chat_send_all('name '.. dump(name) .. ' - pilot: ' .. dump(self.driver_name) .. ' - pax: ' .. dump(copilot_name)) @@ -900,7 +897,7 @@ function airutils.on_rightclick(self, clicker) local plane = seat:get_attach() if plane == self.object then is_attached = true end end - + if name == self.driver_name then if is_attached then local itmstck=clicker:get_wielded_item() @@ -946,8 +943,6 @@ function airutils.on_rightclick(self, clicker) if self.owner == name or minetest.check_player_privs(clicker, {protection_bypass=true}) then local itmstck=clicker:get_wielded_item() - local item_name = "" - if itmstck then item_name = itmstck:get_name() end if itmstck then if airutils.set_param_paint(self, clicker, itmstck, 2) == true then @@ -963,10 +958,10 @@ function airutils.on_rightclick(self, clicker) else if is_under_water then return end - --remove the passengers first + --remove the passengers first local max_seats = table.getn(self._seats) for i = max_seats,1,-1 - do + do if self._passengers[i] and self._passengers[i] ~= "" then local passenger = minetest.get_player_by_name(self._passengers[i]) if passenger then airutils.dettach_pax(self, passenger) end diff --git a/lib_planes/forms.lua b/lib_planes/forms.lua index 6080f0b..3c225f5 100644 --- a/lib_planes/forms.lua +++ b/lib_planes/forms.lua @@ -87,7 +87,7 @@ function airutils.pilot_formspec(name) 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 @@ -101,7 +101,7 @@ function airutils.pilot_formspec(name) end if ent._have_manual then - basic_form = basic_form.."button[6,5.2;4,1;manual;" .. S("Manual") .. "]" + basic_form = basic_form.."button[6,5.2;4,1;manual;" .. S("Manual") .. "]" expand_form = true end @@ -168,8 +168,6 @@ function airutils.adf_formspec(name) z = math.floor(ent._adf_destiny.z) end end - else - --return end local basic_form = table.concat({ @@ -280,7 +278,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) airutils.attach_pax(ent, player) end if fields.go_out then - local touching_ground, liquid_below = airutils.check_node_below(plane_obj, 2.5) + 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 @@ -308,21 +306,20 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) if fields.go_out then local touch_point = ent.initial_properties.collisionbox[2]-1.0 -----//// - local is_on_ground = false 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] - is_on_ground = not nodedef or nodedef.walkable or false -- unknown nodes are solid + 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 + --remove the passengers first local max_seats = table.getn(ent._seats) for i = max_seats,1,-1 - do + 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]) @@ -409,8 +406,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) if fields.copilot then --look for a free seat first local is_there_a_free_seat = false - for i = 2,1,-1 - do + for i = 2,1,-1 + do if ent._passengers[i] == nil then is_there_a_free_seat = true break diff --git a/lib_planes/fuel_management.lua b/lib_planes/fuel_management.lua index 402329e..5b6225d 100755 --- a/lib_planes/fuel_management.lua +++ b/lib_planes/fuel_management.lua @@ -25,10 +25,10 @@ function airutils.loadFuel(self, player_name) 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) + --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 diff --git a/lib_planes/gauges.lua b/lib_planes/gauges.lua index f91198c..28e8370 100644 --- a/lib_planes/gauges.lua +++ b/lib_planes/gauges.lua @@ -1,15 +1,16 @@ +--[[ 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" - pointer_img_size = 8 + 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 @@ -33,10 +34,11 @@ local function get_pointer(pointer_angle, gauge_center_x, gauge_center_y, full_p 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 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 @@ -76,7 +78,7 @@ end function airutils.plot_fuel_gauge(self, scale, place_x, place_y) local bg_width_height = 100 - local pointer_img = 8 + 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 @@ -95,7 +97,7 @@ end function airutils.plot_speed_gauge(self, scale, place_x, place_y) local bg_width_height = 100 - local pointer_img = 8 + 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 @@ -114,7 +116,7 @@ end function airutils.plot_power_gauge(self, scale, place_x, place_y) local bg_width_height = 100 - local pointer_img = 8 + 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 diff --git a/lib_planes/hud.lua b/lib_planes/hud.lua index 20b59ad..a06b143 100755 --- a/lib_planes/hud.lua +++ b/lib_planes/hud.lua @@ -73,7 +73,7 @@ function airutils.update_hud(player, climb, speed, power, fuel) 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}, diff --git a/lib_planes/init.lua b/lib_planes/init.lua index 1c4854d..e7ec634 100755 --- a/lib_planes/init.lua +++ b/lib_planes/init.lua @@ -17,11 +17,3 @@ dofile(minetest.get_modpath("airutils") .. DIR_DELIM .. "lib_planes" .. DIR_DELI -- -- items -- - -settings = Settings(minetest.get_worldpath() .. "/settings.conf") -local function fetch_setting(name) - local sname = name - return settings and settings:get(sname) or minetest.settings:get(sname) -end - - diff --git a/lib_planes/utilities.lua b/lib_planes/utilities.lua index 08807cf..37b49f4 100644 --- a/lib_planes/utilities.lua +++ b/lib_planes/utilities.lua @@ -77,7 +77,7 @@ function airutils.attach(self, player, instructor_mode) eye_y = -4 --airutils.seat_create(self, 1) --airutils.seat_create(self, 2) - + if not self.co_pilot_seat_base then self.co_pilot_seat_base = self._passengers_base[2] end @@ -99,7 +99,7 @@ function airutils.attach(self, player, instructor_mode) if airutils.detect_player_api(player) == 2 then eye_y = -4 end - + player:set_eye_offset({x = 0, y = eye_y, z = 2}, {x = 0, y = 1, z = -30}) sit_player(player, name) end @@ -173,8 +173,8 @@ function airutils.check_passenger_is_attached(self, name) if self._passenger == name then is_attached = true end if is_attached == false then local max_occupants = table.getn(self._seats) - for i = max_occupants,1,-1 - do + for i = max_occupants,1,-1 + do if self._passengers[i] == name then is_attached = true break @@ -272,7 +272,7 @@ function airutils.dettach_pax(self, player, is_flying) else local max_seats = table.getn(self._seats) for i = max_seats,1,-1 - do + do if self._passengers[i] == name then self._passengers[i] = "" break @@ -365,10 +365,10 @@ function airutils.destroy(self, by_name, by_automation) self.sound_handle = nil end - --remove the passengers first + --remove the passengers first local max_seats = table.getn(self._seats) for i = max_seats,2,-1 - do + do if self._passengers[i] and self._passengers[i] ~= "" then local passenger = minetest.get_player_by_name(self._passengers[i]) if passenger then airutils.dettach_pax(self, passenger) end @@ -535,7 +535,6 @@ function airutils.testImpact(self, velocity, position) }, true) self.hp_max = self.hp_max - self._damage_by_wind_speed if self.driver_name then - local player_name = self.driver_name airutils.setText(self, self._vehicle_name) end if self.hp_max < 0 then --if acumulated damage is greater than 50, adieu @@ -580,7 +579,7 @@ function airutils.testImpact(self, velocity, position) self._power_lever = 0 self._engine_running = false end - + airutils.setText(self, self._vehicle_name) if self.driver_name then @@ -621,8 +620,8 @@ function airutils.rescueConnectionFailedPassengers(self) if self._disconnection_check_time > 1 then --minetest.chat_send_all(dump(self._passengers)) self._disconnection_check_time = 0 - for i = max_seats,1,-1 - do + for i = max_seats,1,-1 + do if self._passengers[i] and self._passengers[i] ~= "" then local player = minetest.get_player_by_name(self._passengers[i]) if player then --we have a player! @@ -672,11 +671,11 @@ function airutils.checkattachBug(self) local base_value = 1.0 if self._seat_check_interval == nil then self._seat_check_interval = base_value end self._seat_check_interval = self._seat_check_interval + self.dtime - + if self._seat_check_interval >= base_value then self._seat_check_interval = 0 local max_seats = table.getn(self._seats) - for i = max_seats,1,-1 + for i = max_seats,1,-1 do if self._passengers[i] and self._passengers[i] ~= "" then local player = minetest.get_player_by_name(self._passengers[i]) @@ -734,7 +733,7 @@ function airutils.set_param_paint(self, puncher, itmstck, mode) mode = mode or 1 local item_name = "" if itmstck then item_name = itmstck:get_name() end - + if item_name == "automobiles_lib:painter" or item_name == "bike:painter" then self._skin = "" --painting with bike painter @@ -751,7 +750,7 @@ function airutils.set_param_paint(self, puncher, itmstck, mode) else --painting with dyes local split = string.split(item_name, ":") - local color, indx, _ + local indx, _ if split[1] then _,indx = split[1]:find('dye') end if indx then self._skin = "" @@ -784,7 +783,7 @@ end local function _paint(self, l_textures, colstr, paint_list, mask_associations) paint_list = paint_list or self._painting_texture mask_associations = mask_associations or self._mask_painting_associations - + for _, texture in ipairs(l_textures) do for i, texture_name in ipairs(paint_list) do --textures list local indx = texture:find(texture_name) @@ -879,7 +878,7 @@ end function airutils.paint_with_mask(self, colstr, target_texture, mask_texture) if colstr then self._color = colstr - self._det_color = mask_colstr + self._det_color = mask_colstr -- !!! accessing undefined variable mask_colstr local l_textures = self.initial_properties.textures for _, texture in ipairs(l_textures) do local indx = texture:find(target_texture) @@ -904,7 +903,7 @@ function airutils.pid_controller(current_value, setpoint, last_error, d_time, kp local _error = setpoint - current_value local derivative = _error - last_error --local output = kpv*erro + (kpv/Tiv)*I + kpv*Tdv*((erro - erro_passado)/delta_t); - if integrative == nil then integrative = 0 end + if integrative == nil then integrative = 0 end -- !!! accessing undefined variable integrative integrative = integrative + (((_error + last_error)/delta_t)/2); local output = kp*_error + (kp/ti)*integrative + kp * td*((_error - last_error)/delta_t) last_error = _error @@ -927,7 +926,6 @@ function airutils.add_smoke_trail(self, smoke_type) end if self._smoke_spawner == nil then - local radius = 1 self._smoke_spawner = minetest.add_particlespawner({ amount = 3, time = 0, @@ -1017,7 +1015,7 @@ function airutils.add_blast_damage(pos, radius, damage_cal) local obj_pos = obj:get_pos() local dist = math.max(1, vector.distance(pos, obj_pos)) local damage = (damage_cal / dist) * radius - + if obj:is_player() then obj:set_hp(obj:get_hp() - damage) else @@ -1044,7 +1042,7 @@ function airutils.add_blast_damage(pos, radius, damage_cal) }, nil) end for _, item in pairs(entity_drops) do - add_drop(drops, item) + add_drop(drops, item) -- !!! accessing undefined variable add_drop, drops end end @@ -1114,7 +1112,7 @@ function airutils.camera_reposition(player, pitch, roll) --minetest.chat_send_all("2") eye_y = -5 end - + local z, y = airutils.get_xz_from_hipotenuse(0, eye_y, pitch, player_properties.eye_height) new_eye_offset.z = z*7 new_eye_offset.y = y*1.5 @@ -1129,7 +1127,7 @@ function airutils.seats_create(self) local pos = self.object:get_pos() self._passengers_base = {} self._passengers = {} - if self._seats then + if self._seats then local max_seats = table.getn(self._seats) for i=1, max_seats do self._passengers_base[i] = minetest.add_entity(pos,'airutils:seat_base') @@ -1154,7 +1152,7 @@ function airutils.seat_create(self, index) local pos = self.object:get_pos() if not self._passengers_base then self._passengers_base = {} - if self._seats then + if self._seats then local max_seats = table.getn(self._seats) for i=1, max_seats do self._passengers_base[i] = 0 @@ -1162,7 +1160,7 @@ function airutils.seat_create(self, index) end end if self._passengers_base[index] == 0 then - if self._seats then + if self._seats then local max_seats = table.getn(self._seats) for i=1, max_seats do if i == index then @@ -1179,8 +1177,7 @@ end function airutils.seats_update(self) if self.object then - local pos = self.object:get_pos() - if self._passengers_base then + if self._passengers_base then local max_seats = table.getn(self._passengers_base) for i=1, max_seats do if self._passengers_base[i] then @@ -1324,8 +1321,6 @@ function airutils.destroyed_save_static_data(self) end function airutils.destroyed_on_activate(self, staticdata, dtime_s) - local pos = self.object:get_pos() - if staticdata ~= "" and staticdata ~= nil then local data = minetest.deserialize(staticdata) or {} self.owner = data.stored_owner @@ -1354,7 +1349,6 @@ local function check_shared_by_time(self) end function airutils.destroyed_open_inventory(self, clicker) - local message = "" if not clicker or not clicker:is_player() then return end @@ -1386,8 +1380,7 @@ function airutils.destroyed_on_punch(self, puncher, ttime, toolcaps, dir, damage local shared_by_time = check_shared_by_time(self) local pos = self.object:get_pos() - local is_admin = false - is_admin = minetest.check_player_privs(puncher, {server=true}) + local is_admin = minetest.check_player_privs(puncher, {server=true}) if shared_by_time == false then if self.owner and self.owner ~= name and self.owner ~= "" then if is_admin == false then return end diff --git a/light.lua b/light.lua index 7206242..9e92ead 100644 --- a/light.lua +++ b/light.lua @@ -45,7 +45,7 @@ function airutils.swap_node(self, pos) count = count + 1 target_pos.y = target_pos.y + 1 end - + if have_air then minetest.set_node(target_pos, {name='airutils:light'}) airutils.remove_light(self) diff --git a/physics_lib.lua b/physics_lib.lua index 3f58943..e25d201 100755 --- a/physics_lib.lua +++ b/physics_lib.lua @@ -48,7 +48,7 @@ function airutils.get_stand_pos(thing) -- thing can be luaentity or objectref. pos = thing:get_pos() if not thing:get_properties() then return false end colbox = thing:get_properties().collisionbox - else + else return false end return airutils.pos_shift(pos,{y=colbox[2]+0.01}), pos @@ -78,7 +78,7 @@ function airutils.set_acceleration(thing,vec,limit) vec.x=airutils.minmax(vec.x,limit) vec.y=airutils.minmax(vec.y,limit) vec.z=airutils.minmax(vec.z,limit) - + thing:set_acceleration(vec) end @@ -86,7 +86,7 @@ function airutils.actfunc(self, staticdata, dtime_s) self.logic = self.logic or self.brainfunc self.physics = self.physics or airutils.physics - + self.lqueue = {} self.hqueue = {} self.nearby_objects = {} @@ -97,29 +97,29 @@ function airutils.actfunc(self, staticdata, dtime_s) self.water_drag = self.water_drag or 1 local sdata = minetest.deserialize(staticdata) - if sdata then + if sdata then for k,v in pairs(sdata) do self[k] = v end end - + if self.textures==nil then local prop_tex = self.object:get_properties().textures if prop_tex then self.textures=prop_tex end end - + if not self.memory then -- this is the initial activation - self.memory = {} - + self.memory = {} + -- texture variation if #self.textures > 1 then self.texture_no = random(#self.textures) end end - + if self.timeout and ((self.timeout>0 and dtime_s > self.timeout and next(self.memory)==nil) or (self.timeout<0 and dtime_s > abs(self.timeout))) then self.object:remove() end - + -- apply texture if self.textures and self.texture_no then local props = {} @@ -136,7 +136,7 @@ function airutils.actfunc(self, staticdata, dtime_s) end self.armor_groups.immortal = 1 self.object:set_armor_groups(self.armor_groups) - + self.buoyancy = self.buoyancy or 0 self.oxygen = self.oxygen or self.lung_capacity self.lastvelocity = {x=0,y=0,z=0} @@ -147,7 +147,7 @@ function airutils.get_box_height(self) local colbox = self:get_properties().collisionbox local height = 0.1 if colbox then height = colbox[5]-colbox[2] end - + return height > 0 and height or 0.1 end @@ -155,11 +155,11 @@ function airutils.stepfunc(self,dtime,colinfo) self.dtime = min(dtime,0.2) self.colinfo = colinfo self.height = airutils.get_box_height(self) - + -- physics comes first local vel = self.object:get_velocity() - - if colinfo then + + if colinfo then self.isonground = colinfo.touching_ground else if self.lastvelocity.y==0 and vel.y==0 then @@ -168,15 +168,15 @@ function airutils.stepfunc(self,dtime,colinfo) self.isonground = false end end - + self:physics() if self.logic then if self.view_range then self:sensefunc() end self:logic() - execute_queues(self) + execute_queues(self) -- !!! accessing undefined variable execute_queues end - + self.lastvelocity = self.object:get_velocity() self.time_total=self.time_total+self.dtime end diff --git a/pilot_skin_manager.lua b/pilot_skin_manager.lua index 7184cf0..8ebda7a 100644 --- a/pilot_skin_manager.lua +++ b/pilot_skin_manager.lua @@ -3,8 +3,6 @@ local S = airutils.S airutils.pilot_textures = {"pilot_clothes1.png","pilot_clothes2.png","pilot_clothes3.png","pilot_clothes4.png", "pilot_novaskin_girl.png","pilot_novaskin_girl_steampunk.png","pilot_novaskin_girl_2.png","pilot_novaskin_girl_steampunk_2.png"} local skinsdb_mod_path = minetest.get_modpath("skinsdb") -local backup = "airutils:bcp_last_skin" -local curr_skin = "airutils:skin" minetest.register_chatcommand("au_uniform", { func = function(name, param) @@ -99,7 +97,7 @@ function airutils.set_player_skin(player, skin) else --remove texture local old_texture = player_meta:get_string("backup") - if set_skin then + if set_skin then -- !!! accessing undefined variable set_skin if player:get_attribute("set_skin:player_skin") ~= nil and player:get_attribute("set_skin:player_skin") ~= "" then old_texture = player:get_attribute("set_skin:player_skin") end diff --git a/text.lua b/text.lua index f67cfd4..c72cebd 100644 --- a/text.lua +++ b/text.lua @@ -58,20 +58,20 @@ local function clamp_characters(text, max_lenght) local c = "" for i = 1, #new_string, 1 do c = string.sub(new_string,i,i) - if not (c == control_char) then + if c ~= control_char then count = count + 1 end curr_index = i if count == max_lenght then break end end local cutstring = string.sub(new_string,1,curr_index) - + --now reconstruct the string local outputstring = "" local control_order_curr_intex = 0 for i = 1, #cutstring, 1 do c = string.sub(cutstring,i,i) - if not (c == control_char) then + if c ~= control_char then outputstring = outputstring .. (c or "") else control_order_curr_intex = control_order_curr_intex + 1 @@ -92,10 +92,10 @@ local function file_exists(name, return_handle, mode) if (return_handle) then return f end - io.close(f) - return true - else - return false + io.close(f) + return true + else + return false end end @@ -217,7 +217,7 @@ local function make_text_texture(text, default_color, line_width, line_height, c table.insert(texture, (":%d,%d=%s"):format(xpos + ch.off, ypos, ch.tex)) end table.insert( - texture, + texture, (":%d,%d="):format(xpos + word.w, ypos) .. char_tex(font_name, " ") ) xpos = xpos + word.w + cwidth_tab[" "] diff --git a/texture_management.lua b/texture_management.lua index fa668d3..491eae4 100644 --- a/texture_management.lua +++ b/texture_management.lua @@ -48,7 +48,7 @@ local function getTexturesFromItem(itemDef) end --function to remove duplicates and invalid for textlist -function filter_texture_names(list_to_test) +local function filter_texture_names(list_to_test) local hash = {} local result = {} for _,v in ipairs(list_to_test) do @@ -63,7 +63,7 @@ function filter_texture_names(list_to_test) end -- Function to list all loaded textures -function listLoadedTextures() +local function listLoadedTextures() local loadedTextures = {} --nodes diff --git a/water_splash.lua b/water_splash.lua index e8af787..3972b2e 100644 --- a/water_splash.lua +++ b/water_splash.lua @@ -6,7 +6,7 @@ local function calculateVelocity(magnitude, angle) y = 0, -- Se a velocidade não tem componente z z = magnitude * math.sin(angle), } - + return velocity end @@ -30,14 +30,14 @@ end function airutils.add_splash(pos, yaw, x_pos) local direction = yaw - local spl_pos = vector.new(pos) + local spl_pos = vector.new(pos) --water_particle(spl_pos, {x=0,y=0,z=0}) --right local move = x_pos/10 spl_pos.x = spl_pos.x + move * math.cos(direction) spl_pos.z = spl_pos.z + move * math.sin(direction) - + local velocity = calculateVelocity(0.2, yaw) water_particle(spl_pos, velocity) @@ -46,7 +46,7 @@ function airutils.add_splash(pos, yaw, x_pos) spl_pos = vector.new(pos) spl_pos.x = spl_pos.x + move * math.cos(direction) spl_pos.z = spl_pos.z + move * math.sin(direction) - + velocity = calculateVelocity(0.2, yaw - math.rad(180)) water_particle(spl_pos, velocity) end