code cleaning
parent
56810b1042
commit
659ccbdc76
|
@ -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"}
|
49
init.lua
49
init.lua
|
@ -15,7 +15,8 @@ minetest.register_lbm({ -- this is to remove old brig
|
|||
|
||||
nautilus={}
|
||||
nautilus.gravity = tonumber(minetest.settings:get("movement_gravity")) or 9.8
|
||||
nautilus.fuel = {['biofuel:biofuel'] = {amount=1},['biofuel:bottle_fuel'] = {amount=1},['biofuel:phial_fuel'] = {amount=0.25}, ['biofuel:fuel_can'] = {amount=10}}
|
||||
nautilus.fuel = {['biofuel:biofuel'] = {amount=1},['biofuel:bottle_fuel'] = {amount=1},
|
||||
['biofuel:phial_fuel'] = {amount=0.25}, ['biofuel:fuel_can'] = {amount=10}}
|
||||
nautilus.air = {['vacuum:air_bottle'] = {amount=100,drop="vessels:steel_bottle"},}
|
||||
|
||||
nautilus.have_air = false
|
||||
|
@ -63,8 +64,6 @@ dofile(minetest.get_modpath("nautilus") .. DIR_DELIM .. "nautilus_custom_physics
|
|||
-- helpers and co.
|
||||
--
|
||||
|
||||
local creative_exists = minetest.global_exists("creative")
|
||||
|
||||
function nautilus.get_hipotenuse_value(point1, point2)
|
||||
return math.sqrt((point1.x - point2.x) ^ 2 + (point1.y - point2.y) ^ 2 + (point1.z - point2.z) ^ 2)
|
||||
end
|
||||
|
@ -90,7 +89,7 @@ function nautilus.paint(self, colstr)
|
|||
self.color = colstr
|
||||
local l_textures = self.initial_properties.textures
|
||||
for _, texture in ipairs(l_textures) do
|
||||
local i,indx = texture:find('nautilus_painting.png')
|
||||
local indx = texture:find('nautilus_painting.png')
|
||||
if indx then
|
||||
l_textures[_] = "nautilus_painting.png^[multiply:".. colstr
|
||||
end
|
||||
|
@ -100,7 +99,7 @@ function nautilus.paint(self, colstr)
|
|||
end
|
||||
|
||||
-- destroy the boat
|
||||
function nautilus.destroy(self)
|
||||
function nautilus.destroy(self, puncher)
|
||||
if self.sound_handle then
|
||||
minetest.sound_stop(self.sound_handle)
|
||||
self.sound_handle = nil
|
||||
|
@ -110,7 +109,7 @@ function nautilus.destroy(self)
|
|||
-- detach the driver first (puncher must be driver)
|
||||
puncher:set_detach()
|
||||
puncher:set_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
||||
player_api.player_attached[name] = nil
|
||||
player_api.player_attached[self.driver_name] = nil
|
||||
-- player should stand again
|
||||
player_api.set_animation(puncher, "stand")
|
||||
self.driver_name = nil
|
||||
|
@ -161,7 +160,7 @@ function nautilus.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")
|
||||
end
|
||||
|
@ -201,7 +200,10 @@ minetest.register_entity("nautilus:boat", {
|
|||
selectionbox = {-0.6,0.6,-0.6, 0.6,1,0.6},
|
||||
visual = "mesh",
|
||||
mesh = "nautilus.b3d",
|
||||
textures = {"nautilus_black.png", "nautilus_painting.png", "nautilus_glass.png", "nautilus_metal.png", "nautilus_metal.png", "nautilus_orange.png", "nautilus_painting.png", "nautilus_red.png", "nautilus_painting.png", "nautilus_helice.png", "nautilus_interior.png", "nautilus_panel.png"},
|
||||
textures = {"nautilus_black.png", "nautilus_painting.png", "nautilus_glass.png",
|
||||
"nautilus_metal.png", "nautilus_metal.png", "nautilus_orange.png",
|
||||
"nautilus_painting.png", "nautilus_red.png", "nautilus_painting.png",
|
||||
"nautilus_helice.png", "nautilus_interior.png", "nautilus_panel.png"},
|
||||
},
|
||||
textures = {},
|
||||
driver_name = nil,
|
||||
|
@ -287,16 +289,17 @@ minetest.register_entity("nautilus:boat", {
|
|||
local pitch = rotation.x
|
||||
local newpitch = pitch
|
||||
local roll = rotation.z
|
||||
local newroll=roll
|
||||
|
||||
local hull_direction = minetest.yaw_to_dir(yaw)
|
||||
local nhdir = {x=hull_direction.z,y=0,z=-hull_direction.x} -- lateral unit vector
|
||||
local velocity = self.object:get_velocity()
|
||||
|
||||
local longit_speed = nautilus.dot(velocity,hull_direction)
|
||||
local longit_drag = vector.multiply(hull_direction,longit_speed*longit_speed*LONGIT_DRAG_FACTOR*-1*nautilus.sign(longit_speed))
|
||||
local longit_drag = vector.multiply(hull_direction,longit_speed*
|
||||
longit_speed*LONGIT_DRAG_FACTOR*-1*nautilus.sign(longit_speed))
|
||||
local later_speed = nautilus.dot(velocity,nhdir)
|
||||
local later_drag = vector.multiply(nhdir,later_speed*later_speed*LATER_DRAG_FACTOR*-1*nautilus.sign(later_speed))
|
||||
local later_drag = vector.multiply(nhdir,later_speed*later_speed*
|
||||
LATER_DRAG_FACTOR*-1*nautilus.sign(later_speed))
|
||||
local accel = vector.add(longit_drag,later_drag)
|
||||
|
||||
local vel = self.object:get_velocity()
|
||||
|
@ -318,7 +321,7 @@ minetest.register_entity("nautilus:boat", {
|
|||
local impact = nautilus.get_hipotenuse_value(vel, self.last_vel)
|
||||
if impact > 1 then
|
||||
--self.damage = self.damage + impact --sum the impact value directly to damage meter
|
||||
local curr_pos = self.object:get_pos()
|
||||
--local curr_pos = self.object:get_pos()
|
||||
minetest.sound_play("collision", {
|
||||
to_player = self.driver_name,
|
||||
--pos = curr_pos,
|
||||
|
@ -328,7 +331,7 @@ minetest.register_entity("nautilus:boat", {
|
|||
pitch = 1.0,
|
||||
})
|
||||
--[[if self.damage > 100 then --if acumulated damage is greater than 100, adieu
|
||||
nautilus.destroy(self)
|
||||
nautilus.destroy(self, puncher)
|
||||
end]]--
|
||||
end
|
||||
if (nautilus.have_air==false) then
|
||||
|
@ -363,9 +366,10 @@ minetest.register_entity("nautilus:boat", {
|
|||
end
|
||||
end
|
||||
|
||||
if math.abs(self.rudder_angle)>5 then
|
||||
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 * nautilus.sign(longit_speed)
|
||||
newyaw = yaw + self.dtime*(1 - 1 / (math.abs(longit_speed) + 1)) *
|
||||
self.rudder_angle / 30 * turn_rate * nautilus.sign(longit_speed)
|
||||
end
|
||||
|
||||
-- calculate energy consumption --
|
||||
|
@ -400,11 +404,13 @@ minetest.register_entity("nautilus:boat", {
|
|||
|
||||
local air_indicator_angle = nautilus.get_pointer_angle(self.air, nautilus.MAX_AIR)
|
||||
if self.pointer_air:get_luaentity() then
|
||||
self.pointer_air:set_attach(self.object,'',nautilus.GAUGE_AIR_POSITION,{x=0,y=0,z=air_indicator_angle})
|
||||
self.pointer_air:set_attach(self.object,'',nautilus.GAUGE_AIR_POSITION,
|
||||
{x=0,y=0,z=air_indicator_angle})
|
||||
else
|
||||
--in case it have lost the entity by some conflict
|
||||
self.pointer_air=minetest.add_entity(nautilus.GAUGE_AIR_POSITION,'nautilus:pointer_air')
|
||||
self.pointer_air:set_attach(self.object,'',nautilus.GAUGE_AIR_POSITION,{x=0,y=0,z=air_indicator_angle})
|
||||
self.pointer_air:set_attach(self.object,'',nautilus.GAUGE_AIR_POSITION,
|
||||
{x=0,y=0,z=air_indicator_angle})
|
||||
end
|
||||
|
||||
self.breath_time = self.breath_time + dtime
|
||||
|
@ -447,7 +453,7 @@ minetest.register_entity("nautilus:boat", {
|
|||
local snormal = {x=sdir.z,y=0,z=-sdir.x} -- rightside, dot is negative
|
||||
local prsr = nautilus.dot(snormal,nhdir)
|
||||
local rollfactor = -10
|
||||
newroll = (prsr*math.rad(rollfactor))*later_speed
|
||||
local newroll = (prsr*math.rad(rollfactor))*later_speed
|
||||
--minetest.chat_send_all('newroll: '.. newroll)
|
||||
---------------------------------
|
||||
-- end roll
|
||||
|
@ -491,8 +497,6 @@ minetest.register_entity("nautilus:boat", {
|
|||
-- do not allow other players to remove the object while there is a driver
|
||||
return
|
||||
end
|
||||
|
||||
local touching_ground, liquid_below = nautilus.check_node_below(self.object)
|
||||
|
||||
local is_attached = false
|
||||
if puncher:get_attach() == self.object then
|
||||
|
@ -532,7 +536,8 @@ minetest.register_entity("nautilus:boat", {
|
|||
-- end painting
|
||||
|
||||
else -- deal damage
|
||||
if not self.driver_name and toolcaps and toolcaps.damage_groups and toolcaps.damage_groups.fleshy then
|
||||
if not self.driver_name and toolcaps and toolcaps.damage_groups and
|
||||
toolcaps.damage_groups.fleshy then
|
||||
--mobkit.hurt(self,toolcaps.damage_groups.fleshy - 1)
|
||||
--mobkit.make_sound(self,'hit')
|
||||
self.hp = self.hp - 10
|
||||
|
@ -548,7 +553,7 @@ minetest.register_entity("nautilus:boat", {
|
|||
end
|
||||
|
||||
if self.hp <= 0 then
|
||||
nautilus.destroy(self)
|
||||
nautilus.destroy(self, puncher)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -40,14 +40,13 @@ function nautilus.load_air(self, player_name)
|
|||
local item_name = ""
|
||||
if itmstck then item_name = itmstck:get_name() end
|
||||
|
||||
local stack = nil
|
||||
--minetest.debug("air: ", item_name)
|
||||
local air = nautilus.contains(nautilus.air, item_name)
|
||||
if air then
|
||||
stack = ItemStack(item_name .. " 1")
|
||||
local stack = ItemStack(item_name .. " 1")
|
||||
|
||||
if self.air < nautilus.MAX_AIR then
|
||||
local taken = inv:remove_item("main", stack)
|
||||
inv:remove_item("main", stack)
|
||||
self.air = self.air + air.amount
|
||||
if self.air > nautilus.MAX_AIR then self.air = nautilus.MAX_AIR end
|
||||
|
||||
|
|
|
@ -32,7 +32,9 @@ function nautilus.nautilus_control(self, dtime, hull_direction, longit_speed, ac
|
|||
local ctrl = player:get_player_control()
|
||||
local max_speed_anchor = 0.2
|
||||
if ctrl.aux1 then
|
||||
if nautilus.nautilus_last_time_command > 0.3 and longit_speed < max_speed_anchor and longit_speed > -max_speed_anchor then
|
||||
if nautilus.nautilus_last_time_command > 0.3 and
|
||||
longit_speed < max_speed_anchor and
|
||||
longit_speed > -max_speed_anchor then
|
||||
nautilus.nautilus_last_time_command = 0
|
||||
if self.anchored == false then
|
||||
self.anchored = true
|
||||
|
@ -80,7 +82,7 @@ function nautilus.nautilus_control(self, dtime, hull_direction, longit_speed, ac
|
|||
self.buoyancy = 1.03
|
||||
else
|
||||
--check if its liquid above
|
||||
local pos_up = self.object:get_pos()
|
||||
local pos_up = self.object:get_pos()
|
||||
pos_up.y = pos_up.y + 2
|
||||
local node_up = minetest.get_node(pos_up).name
|
||||
local nodedef = minetest.registered_nodes[node_up]
|
||||
|
|
|
@ -15,9 +15,9 @@ function nautilus.physics(self)
|
|||
local vnew = vector.new(vel)
|
||||
|
||||
if not self.collided then -- ugly workaround for inconsistent collisions
|
||||
for _,k in ipairs({'y','z','x'}) do
|
||||
if vel[k]==0 and abs(self.lastvelocity[k])> 0.1 then
|
||||
vnew[k]=-self.lastvelocity[k]*self.springiness
|
||||
for _,k in ipairs({'y','z','x'}) do
|
||||
if vel[k]==0 and abs(self.lastvelocity[k])> 0.1 then
|
||||
vnew[k]=-self.lastvelocity[k]*self.springiness
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -45,14 +45,13 @@ function nautilus.load_fuel(self, player_name)
|
|||
local item_name = ""
|
||||
if itmstck then item_name = itmstck:get_name() end
|
||||
|
||||
local stack = nil
|
||||
--minetest.debug("fuel: ", item_name)
|
||||
local fuel = nautilus.contains(nautilus.fuel, item_name)
|
||||
if fuel then
|
||||
stack = ItemStack(item_name .. " 1")
|
||||
local stack = ItemStack(item_name .. " 1")
|
||||
|
||||
if self.energy < nautilus.MAX_FUEL then
|
||||
local taken = inv:remove_item("main", stack)
|
||||
inv:remove_item("main", stack)
|
||||
self.energy = self.energy + fuel.amount
|
||||
if self.energy > nautilus.MAX_FUEL then self.energy = nautilus.MAX_FUEL end
|
||||
|
||||
|
|
Loading…
Reference in New Issue