bug fix and code cleaning
This commit is contained in:
parent
2c4b8cdd24
commit
f809130ed7
25
.luacheckrc
Normal file
25
.luacheckrc
Normal file
@ -0,0 +1,25 @@
|
||||
unused_args = false
|
||||
allow_defined_top = true
|
||||
|
||||
globals = {
|
||||
"minetest",
|
||||
"mobkit",
|
||||
"core",
|
||||
"player_api",
|
||||
"player_monoids",
|
||||
"math.sign",
|
||||
}
|
||||
|
||||
read_globals = {
|
||||
string = {fields = {"split"}},
|
||||
table = {fields = {"copy", "getn"}},
|
||||
|
||||
-- Builtin
|
||||
"vector", "ItemStack",
|
||||
"dump", "DIR_DELIM", "VoxelArea", "Settings",
|
||||
|
||||
-- MTG
|
||||
"default", "sfinv", "creative",
|
||||
}
|
||||
|
||||
ignore = {"611"}
|
7
init.lua
7
init.lua
@ -1,5 +1,6 @@
|
||||
trike={}
|
||||
trike.fuel = {['biofuel:biofuel'] = 1,['biofuel:bottle_fuel'] = 1,['biofuel:phial_fuel'] = 0.25, ['biofuel:fuel_can'] = 10}
|
||||
trike.fuel = {['biofuel:biofuel'] = 1,['biofuel:bottle_fuel'] = 1,
|
||||
['biofuel:phial_fuel'] = 0.25, ['biofuel:fuel_can'] = 10}
|
||||
trike.gravity = tonumber(minetest.settings:get("movement_gravity")) or 9.8
|
||||
|
||||
trike.colors ={
|
||||
@ -32,8 +33,6 @@ dofile(minetest.get_modpath("trike") .. DIR_DELIM .. "trike_entities.lua")
|
||||
-- helpers and co.
|
||||
--
|
||||
|
||||
local creative_exists = minetest.global_exists("creative")
|
||||
|
||||
--
|
||||
-- items
|
||||
--
|
||||
@ -68,7 +67,7 @@ minetest.register_chatcommand("trike_eject", {
|
||||
if parent ~= nil then
|
||||
local entity = parent:get_luaentity()
|
||||
if entity.driver_name == name and entity.name == "trike:trike" then
|
||||
motorboat.dettach(entity, player)
|
||||
trike.dettach(entity, player)
|
||||
else
|
||||
minetest.chat_send_player(name,colorstring)
|
||||
end
|
||||
|
@ -2,6 +2,7 @@
|
||||
trike.trike_last_time_command = 0
|
||||
trike.vector_up = vector.new(0, 1, 0)
|
||||
trike.max_engine_acc = 4.5
|
||||
trike.ideal_step = 0.02
|
||||
|
||||
dofile(minetest.get_modpath("trike") .. DIR_DELIM .. "trike_utilities.lua")
|
||||
|
||||
@ -16,7 +17,8 @@ function trike.check_node_below(obj)
|
||||
return touching_ground, liquid_below
|
||||
end
|
||||
|
||||
function trike.control(self, dtime, hull_direction, longit_speed, longit_drag, later_speed, later_drag, accel, player, is_flying)
|
||||
function trike.control(self, dtime, hull_direction, longit_speed,
|
||||
longit_drag, later_speed, later_drag, accel, player, is_flying)
|
||||
trike.trike_last_time_command = trike.trike_last_time_command + self.dtime
|
||||
if trike.trike_last_time_command > 1 then trike.trike_last_time_command = 1 end
|
||||
if self.driver_name == nil then return end
|
||||
@ -44,22 +46,26 @@ function trike.control(self, dtime, hull_direction, longit_speed, longit_drag, l
|
||||
self._engine_running = true
|
||||
-- sound and animation
|
||||
self.sound_handle = minetest.sound_play({name = "engine"},
|
||||
{object = self.object, gain = 2.0, pitch = 0.5 + ((self._power_lever/100)/2),max_hear_distance = 32, loop = true,})
|
||||
{object = self.object, gain = 2.0,
|
||||
pitch = 0.5 + ((self._power_lever/100)/2),max_hear_distance = 32,
|
||||
loop = true,})
|
||||
self.engine:set_animation_frame_speed(60)
|
||||
end
|
||||
end
|
||||
|
||||
self._acceleration = 0
|
||||
if self._engine_running then
|
||||
local engineacc = 0
|
||||
--engine acceleration calc
|
||||
engineacc = (self._power_lever * trike.max_engine_acc) / 100;
|
||||
local engineacc = (self._power_lever * trike.max_engine_acc) / 100;
|
||||
self.engine:set_animation_frame_speed(60 + self._power_lever)
|
||||
|
||||
local add_factor = 1
|
||||
add_factor = add_factor * (dtime/trike.ideal_step) --adjusting the command speed by dtime
|
||||
|
||||
--increase power lever
|
||||
if ctrl.jump then
|
||||
if self._power_lever < 100 then
|
||||
self._power_lever = self._power_lever + 1
|
||||
self._power_lever = self._power_lever + add_factor
|
||||
end
|
||||
if self._power_lever > 100 then
|
||||
self._power_lever = 100
|
||||
@ -68,13 +74,15 @@ function trike.control(self, dtime, hull_direction, longit_speed, longit_drag, l
|
||||
--sound
|
||||
minetest.sound_stop(self.sound_handle)
|
||||
self.sound_handle = minetest.sound_play({name = "engine"},
|
||||
{object = self.object, gain = 2.0, pitch = 0.5 + ((self._power_lever/100)/2),max_hear_distance = 32, loop = true,})
|
||||
{object = self.object, gain = 2.0,
|
||||
pitch = 0.5 + ((self._power_lever/100)/2),max_hear_distance = 32,
|
||||
loop = true,})
|
||||
end
|
||||
end
|
||||
--decrease power lever
|
||||
if ctrl.sneak then
|
||||
if self._power_lever > 0 then
|
||||
self._power_lever = self._power_lever - 1
|
||||
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 and is_flying == false then
|
||||
@ -92,7 +100,9 @@ function trike.control(self, dtime, hull_direction, longit_speed, longit_drag, l
|
||||
--sound
|
||||
minetest.sound_stop(self.sound_handle)
|
||||
self.sound_handle = minetest.sound_play({name = "engine"},
|
||||
{object = self.object, gain = 2.0, pitch = 0.5 + ((self._power_lever/100)/2),max_hear_distance = 32, loop = true,})
|
||||
{object = self.object, gain = 2.0,
|
||||
pitch = 0.5 + ((self._power_lever/100)/2),
|
||||
max_hear_distance = 32, loop = true,})
|
||||
end
|
||||
end
|
||||
--do not exceed
|
||||
|
@ -1,6 +1,4 @@
|
||||
local min = math.min
|
||||
local abs = math.abs
|
||||
local deg = math.deg
|
||||
|
||||
function trike.physics(self)
|
||||
local friction = 0.99
|
||||
|
@ -152,7 +152,6 @@ minetest.register_entity("trike:trike", {
|
||||
_passenger = nil,
|
||||
_color = "#0063b0",
|
||||
_rudder_angle = 0,
|
||||
_angle_of_attack = 0,
|
||||
_acceleration = 0,
|
||||
_engine_running = false,
|
||||
_angle_of_attack = 2,
|
||||
@ -253,8 +252,6 @@ minetest.register_entity("trike:trike", {
|
||||
return
|
||||
end
|
||||
|
||||
local touching_ground, liquid_below = trike.check_node_below(self.object)
|
||||
|
||||
local is_attached = false
|
||||
if puncher:get_attach() == self.object then is_attached = true end
|
||||
|
||||
@ -274,7 +271,7 @@ minetest.register_entity("trike:trike", {
|
||||
local inv = puncher:get_inventory()
|
||||
if inv:contains_item("main", inventory_item) then
|
||||
local stack = ItemStack(inventory_item .. " 1")
|
||||
local taken = inv:remove_item("main", stack)
|
||||
inv:remove_item("main", stack)
|
||||
self.hp_max = self.hp_max + 10
|
||||
if self.hp_max > 50 then self.hp_max = 50 end
|
||||
trike.setText(self)
|
||||
@ -301,7 +298,8 @@ minetest.register_entity("trike:trike", {
|
||||
-- end painting
|
||||
|
||||
else -- deal damage
|
||||
if not self.driver and toolcaps and toolcaps.damage_groups and toolcaps.damage_groups.fleshy and item_name ~= trike.fuel then
|
||||
if not self.driver and toolcaps and toolcaps.damage_groups and
|
||||
toolcaps.damage_groups.fleshy and item_name ~= trike.fuel then
|
||||
--mobkit.hurt(self,toolcaps.damage_groups.fleshy - 1)
|
||||
--mobkit.make_sound(self,'hit')
|
||||
self.hp_max = self.hp_max - 10
|
||||
@ -346,7 +344,7 @@ minetest.register_entity("trike:trike", {
|
||||
if name == self.driver_name then
|
||||
-- eject passenger if the plane is on ground
|
||||
local touching_ground, liquid_below = trike.check_node_below(self.object)
|
||||
if self.isinliquid or touching_ground then --isn't flying?
|
||||
if self.isinliquid or touching_ground or liquid_below then --isn't flying?
|
||||
if self._passenger then
|
||||
local passenger = minetest.get_player_by_name(self._passenger)
|
||||
if passenger then trike.dettach_pax(self, passenger) end
|
||||
|
@ -15,13 +15,12 @@ function trike.loadFuel(self, player_name)
|
||||
local item_name = ""
|
||||
if itmstck then item_name = itmstck:get_name() end
|
||||
|
||||
local stack = nil
|
||||
local fuel = trike.contains(trike.fuel, item_name)
|
||||
if fuel then
|
||||
stack = ItemStack(item_name .. " 1")
|
||||
local stack = ItemStack(item_name .. " 1")
|
||||
|
||||
if self._energy < 10 then
|
||||
local taken = inv:remove_item("main", stack)
|
||||
inv:remove_item("main", stack)
|
||||
self._energy = self._energy + fuel
|
||||
if self._energy > 10 then self._energy = 10 end
|
||||
|
||||
@ -38,8 +37,6 @@ end
|
||||
function trike.consumptionCalc(self, accel)
|
||||
if accel == nil then return end
|
||||
if self._energy > 0 and self._engine_running and accel ~= nil then
|
||||
local zero_reference = vector.new()
|
||||
local acceleration = trike.get_hipotenuse_value(accel, zero_reference)
|
||||
local consumed_power = self._power_lever/700000
|
||||
--minetest.chat_send_all('consumed: '.. consumed_power)
|
||||
self._energy = self._energy - consumed_power;
|
||||
@ -47,10 +44,6 @@ function trike.consumptionCalc(self, accel)
|
||||
local energy_indicator_angle = trike.get_gauge_angle(self._energy)
|
||||
if self.fuel_gauge:get_luaentity() then
|
||||
self.fuel_gauge:set_attach(self.object,'',TRIKE_GAUGE_FUEL_POSITION,{x=0,y=0,z=energy_indicator_angle})
|
||||
else
|
||||
--in case it have lost the entity by some conflict
|
||||
--self.fuel_gauge=minetest.add_entity(TRIKE_GAUGE_POINTER_POSITION,'trike:pointer')
|
||||
--self.fuel_gauge:set_attach(self.object,'',TRIKE_GAUGE_FUEL_POSITION,{x=0,y=0,z=energy_indicator_angle})
|
||||
end
|
||||
end
|
||||
if self._energy <= 0 and self._engine_running and accel ~= nil then
|
||||
|
@ -6,7 +6,6 @@ LATER_DRAG_FACTOR = 2.0
|
||||
|
||||
deg = math.deg
|
||||
abs = math.abs
|
||||
min = math.min
|
||||
|
||||
TRIKE_GAUGE_FUEL_POSITION = {x=1.5,y=6.2,z=15.2}
|
||||
TRIKE_GAUGE_POWER_POSITION = {x=1.5,y=7.7,z=15.2}
|
||||
|
@ -16,31 +16,6 @@ function trike.minmax(v,m)
|
||||
return math.min(math.abs(v),m)*trike.sign(v)
|
||||
end
|
||||
|
||||
local physics_attrs = {"jump", "speed", "gravity"}
|
||||
local function apply_physics_override(player, overrides)
|
||||
if player_monoids then
|
||||
for _, attr in pairs(physics_attrs) do
|
||||
if overrides[attr] then
|
||||
player_monoids[attr]:add_change(player, overrides[attr], "hangglider:glider")
|
||||
end
|
||||
end
|
||||
else
|
||||
player:set_physics_override(overrides)
|
||||
end
|
||||
end
|
||||
|
||||
local function remove_physics_override(player, overrides)
|
||||
for _, attr in pairs(physics_attrs) do
|
||||
if overrides[attr] then
|
||||
if core.global_exists("player_monoids") then
|
||||
player_monoids[attr]:del_change(player, "hangglider:glider")
|
||||
else
|
||||
player:set_physics_override({[attr] = 1})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--lift
|
||||
local function pitchroll2pitchyaw(aoa,roll)
|
||||
if roll == 0.0 then return aoa,0 end
|
||||
@ -65,13 +40,13 @@ function trike.getLiftAccel(self, velocity, accel, longit_speed, roll, curr_pos)
|
||||
--local acc = 0.8
|
||||
local daoa = deg(angle_of_attack)
|
||||
|
||||
--local curr_pos = self.object:get_pos()
|
||||
local curr_percent_height = (100 - ((curr_pos.y * 100) / max_height))/100 --to decrease the lift coefficient at hight altitudes
|
||||
--to decrease the lift coefficient at hight altitudes
|
||||
local curr_percent_height = (100 - ((curr_pos.y * 100) / max_height))/100
|
||||
|
||||
local rotation=self.object:get_rotation()
|
||||
local vrot = mobkit.dir_to_rot(velocity,rotation)
|
||||
|
||||
hpitch,hyaw = pitchroll2pitchyaw(angle_of_attack,roll)
|
||||
local hpitch,hyaw = pitchroll2pitchyaw(angle_of_attack,roll)
|
||||
|
||||
local hrot = {x=vrot.x+hpitch,y=vrot.y-hyaw,z=roll}
|
||||
local hdir = mobkit.rot_to_dir(hrot) --(hrot)
|
||||
@ -111,7 +86,7 @@ function trike.attach(self, player)
|
||||
player_api.player_attached[name] = true
|
||||
-- make the driver sit
|
||||
minetest.after(0.2, function()
|
||||
local player = minetest.get_player_by_name(name)
|
||||
player = minetest.get_player_by_name(name)
|
||||
if player then
|
||||
player_api.set_animation(player, "sit")
|
||||
--apply_physics_override(player, {speed=0,gravity=0,jump=0})
|
||||
@ -130,7 +105,7 @@ function trike.attach_pax(self, player)
|
||||
player_api.player_attached[name] = true
|
||||
-- make the driver sit
|
||||
minetest.after(0.2, function()
|
||||
local player = minetest.get_player_by_name(name)
|
||||
player = minetest.get_player_by_name(name)
|
||||
if player then
|
||||
player_api.set_animation(player, "sit")
|
||||
--apply_physics_override(player, {speed=0,gravity=0,jump=0})
|
||||
@ -196,7 +171,7 @@ function trike.paint(self, object, colstr, search_string)
|
||||
local entity = object:get_luaentity()
|
||||
local l_textures = entity.initial_properties.textures
|
||||
for _, texture in ipairs(l_textures) do
|
||||
local i,indx = texture:find(search_string)
|
||||
local indx = texture:find(search_string)
|
||||
if indx then
|
||||
l_textures[_] = search_string .."^[multiply:".. colstr
|
||||
end
|
||||
@ -284,7 +259,7 @@ function trike.setText(self)
|
||||
end
|
||||
|
||||
function trike.testImpact(self, velocity)
|
||||
collision = false
|
||||
local collision = false
|
||||
if self._last_vel == nil then return end
|
||||
local impact = abs(trike.get_hipotenuse_value(velocity, self._last_vel))
|
||||
if impact > 2 then
|
||||
@ -308,7 +283,6 @@ function trike.testImpact(self, velocity)
|
||||
if collision then
|
||||
local damage = impact / 2
|
||||
self.hp_max = self.hp_max - damage --subtract the impact value directly to hp meter
|
||||
local curr_pos = self.object:get_pos()
|
||||
|
||||
if self.driver_name then
|
||||
minetest.sound_play("collision", {
|
||||
@ -387,9 +361,7 @@ function trike.flightstep(self)
|
||||
local yaw = rotation.y
|
||||
local newyaw=yaw
|
||||
local pitch = rotation.x
|
||||
local newpitch = pitch
|
||||
local roll = rotation.z
|
||||
local newroll=roll
|
||||
|
||||
local velocity = self.object:get_velocity()
|
||||
self.object:set_velocity(velocity) --hack to avoid glitches
|
||||
@ -398,7 +370,8 @@ function trike.flightstep(self)
|
||||
|
||||
local longit_speed = vector.dot(velocity,hull_direction)
|
||||
self._longit_speed = longit_speed
|
||||
local longit_drag = vector.multiply(hull_direction,longit_speed*longit_speed*LONGIT_DRAG_FACTOR*-1*trike.sign(longit_speed))
|
||||
local longit_drag = vector.multiply(hull_direction,longit_speed*longit_speed*LONGIT_DRAG_FACTOR*
|
||||
-1*trike.sign(longit_speed))
|
||||
local later_speed = trike.dot(velocity,nhdir)
|
||||
--minetest.chat_send_all('later_speed: '.. later_speed)
|
||||
local later_drag = vector.multiply(nhdir,later_speed*later_speed*LATER_DRAG_FACTOR*-1*trike.sign(later_speed))
|
||||
@ -407,8 +380,6 @@ function trike.flightstep(self)
|
||||
|
||||
local player = nil
|
||||
if self.driver_name then player = minetest.get_player_by_name(self.driver_name) end
|
||||
local passenger = nil
|
||||
if self._passenger then passenger = minetest.get_player_by_name(self._passenger) end
|
||||
|
||||
local curr_pos = self.object:get_pos()
|
||||
self.object:set_pos(curr_pos)
|
||||
@ -421,7 +392,8 @@ function trike.flightstep(self)
|
||||
|
||||
if is_attached then
|
||||
--control
|
||||
accel, stop = trike.control(self, self.dtime, hull_direction, longit_speed, longit_drag, later_speed, later_drag, accel, player, is_flying) or vel
|
||||
accel, stop = trike.control(self, self.dtime, hull_direction,
|
||||
longit_speed, longit_drag, later_speed, later_drag, accel, player, is_flying)
|
||||
else
|
||||
-- for some engine error the player can be detached from the machine, so lets set him attached again
|
||||
trike.checkattachBug(self)
|
||||
@ -431,7 +403,8 @@ function trike.flightstep(self)
|
||||
-- new yaw
|
||||
if math.abs(self._rudder_angle)>5 then
|
||||
local turn_rate = math.rad(24)
|
||||
newyaw = yaw + self.dtime*(1 - 1 / (math.abs(longit_speed) + 1)) * self._rudder_angle / 30 * turn_rate * trike.sign(longit_speed)
|
||||
newyaw = yaw + self.dtime*(1 - 1 / (math.abs(longit_speed) + 1)) *
|
||||
self._rudder_angle / 30 * turn_rate * trike.sign(longit_speed)
|
||||
end
|
||||
|
||||
-- calculate energy consumption --
|
||||
@ -443,13 +416,13 @@ function trike.flightstep(self)
|
||||
local snormal = {x=sdir.z,y=0,z=-sdir.x} -- rightside, dot is negative
|
||||
local prsr = trike.dot(snormal,nhdir)
|
||||
local rollfactor = -20
|
||||
newroll = (prsr*math.rad(rollfactor))*(later_speed)
|
||||
local newroll = (prsr*math.rad(rollfactor))*(later_speed)
|
||||
--minetest.chat_send_all('newroll: '.. newroll)
|
||||
---------------------------------
|
||||
-- end roll
|
||||
|
||||
-- pitch
|
||||
newpitch = self._angle_of_attack/200 --(velocity.y * math.rad(6))
|
||||
local newpitch = self._angle_of_attack/200 --(velocity.y * math.rad(6))
|
||||
|
||||
-- adjust pitch by velocity
|
||||
if is_flying == false then --isn't flying?
|
||||
|
Loading…
x
Reference in New Issue
Block a user