name changed to avoid collision with another mod

This commit is contained in:
Alexsandro Percy 2022-01-19 10:12:48 -03:00
parent 7c7bd5b3ca
commit 7914ee6a11
28 changed files with 78 additions and 249 deletions

View File

@ -1,105 +0,0 @@
--global constants
automobiles.vector_up = vector.new(0, 1, 0)
function automobiles.check_road_is_ok(obj, max_acc_factor)
local pos_below = obj:get_pos()
pos_below.y = pos_below.y - 0.1
local node_below = minetest.get_node(pos_below).name
--minetest.chat_send_all(node_below)
local nodedef = minetest.registered_nodes[node_below]
if nodedef.liquidtype == "none" then
local slow_nodes = {
['default:ice '] = 0.01,
['default:cave_ice'] = 0.01,
}
local acc = slow_nodes[node_below]
if acc == nil then acc = max_acc_factor end
return acc
else
return 0
end
end
function automobiles.control(self, dtime, hull_direction, longit_speed, longit_drag, later_drag, accel, max_acc_factor, max_speed, steering_limit, steering_speed)
self._last_time_command = self._last_time_command + dtime
if self._last_time_command > 1 then self._last_time_command = 1 end
local player = minetest.get_player_by_name(self.driver_name)
local retval_accel = accel;
local stop = false
-- player control
if player then
local ctrl = player:get_player_control()
local acc = 0
if longit_speed < roadster.max_speed and ctrl.up then
--get acceleration factor
acc = automobiles.check_road_is_ok(self.object, max_acc_factor)
--minetest.chat_send_all('engineacc: '.. engineacc)
if acc > 1 and acc < max_acc_factor and longit_speed > 0 then
--improper road will reduce speed
acc = -1
end
end
--reversing
if ctrl.sneak and longit_speed <= 1.0 and longit_speed > -1.0 then
acc = -1
end
--break
if ctrl.down then
--total stop
--wheel break
if longit_speed > 0 then
acc = -5
if (longit_speed + acc) < 0 then
acc = longit_speed * -1
end
end
if longit_speed < 0 then
acc = 5
if (longit_speed + acc) > 0 then
acc = longit_speed * -1
end
end
if abs(longit_speed) < 0.2 then
stop = true
end
end
if acc then retval_accel=vector.add(accel,vector.multiply(hull_direction,acc)) end
-- steering
if ctrl.right then
self._steering_angle = math.max(self._steering_angle-steering_speed*dtime,-steering_limit)
elseif ctrl.left then
self._steering_angle = math.min(self._steering_angle+steering_speed*dtime,steering_limit)
else
--center steering
if longit_speed > 0 then
local factor = 1
if self._steering_angle > 0 then factor = -1 end
local correction = (steering_limit*(longit_speed/100)) * factor
local before_correction = self._steering_angle
self._steering_angle = self._steering_angle + correction
if math.sign(before_correction) ~= math.sign(self._steering_angle) then self._steering_angle = 0 end
end
end
local angle_factor = self._steering_angle / 60
if angle_factor < 0 then angle_factor = angle_factor * -1 end
local deacc_on_curve = longit_speed * angle_factor
deacc_on_curve = deacc_on_curve * -1
if deacc_on_curve then retval_accel=vector.add(retval_accel,vector.multiply(hull_direction,deacc_on_curve)) end
end
return retval_accel, stop
end

View File

@ -1,66 +0,0 @@
local min = math.min
local abs = math.abs
function automobiles.physics(self)
local friction = 0.99
local vel=self.object:get_velocity()
-- dumb friction
if self.isonground and not self.isinliquid then
--minetest.chat_send_all('okay')
self.object:set_velocity({x=vel.x*friction,
y=vel.y,
z=vel.z*friction})
end
-- bounciness
if self.springiness and self.springiness > 0 then
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
end
end
end
if not vector.equals(vel,vnew) then
self.collided = true
else
if self.collided then
vnew = vector.new(self.lastvelocity)
end
self.collided = false
end
self.object:set_velocity(vnew)
end
-- buoyancy
local surface = nil
local surfnodename = nil
local spos = mobkit.get_stand_pos(self)
spos.y = spos.y+0.01
-- get surface height
local snodepos = mobkit.get_node_pos(spos)
local surfnode = mobkit.nodeatpos(spos)
while surfnode and (surfnode.drawtype == 'liquid' or surfnode.drawtype == 'flowingliquid') do
surfnodename = surfnode.name
surface = snodepos.y +0.5
if surface > spos.y+self.height then break end
snodepos.y = snodepos.y+1
surfnode = mobkit.nodeatpos(snodepos)
end
self.isinliquid = surfnodename
if surface then -- standing in liquid
-- self.isinliquid = true
local submergence = min(surface-spos.y,self.height)/self.height
-- local balance = self.buoyancy*self.height
local buoyacc = mobkit.gravity*(self.buoyancy-submergence)
mobkit.set_acceleration(self.object,
{x=-vel.x*self.water_drag,y=buoyacc-vel.y*abs(vel.y)*0.4,z=-vel.z*self.water_drag})
else
self.object:set_acceleration({x=0,y=mobkit.gravity,z=0})
end
end

View File

@ -1,8 +1,8 @@
--global constants
automobiles.vector_up = vector.new(0, 1, 0)
automobiles_lib.vector_up = vector.new(0, 1, 0)
function automobiles.check_road_is_ok(obj, max_acc_factor)
function automobiles_lib.check_road_is_ok(obj, max_acc_factor)
local pos_below = obj:get_pos()
pos_below.y = pos_below.y - 0.1
local node_below = minetest.get_node(pos_below).name
@ -21,7 +21,7 @@ function automobiles.check_road_is_ok(obj, max_acc_factor)
end
end
function automobiles.control(self, dtime, hull_direction, longit_speed, longit_drag, later_drag, accel, max_acc_factor, max_speed, steering_limit, steering_speed)
function automobiles_lib.control(self, dtime, hull_direction, longit_speed, longit_drag, later_drag, accel, max_acc_factor, max_speed, steering_limit, steering_speed)
self._last_time_command = self._last_time_command + dtime
if self._last_time_command > 1 then self._last_time_command = 1 end
@ -37,7 +37,7 @@ function automobiles.control(self, dtime, hull_direction, longit_speed, longit_d
if self._energy > 0 then
if longit_speed < roadster.max_speed and ctrl.up then
--get acceleration factor
acc = automobiles.check_road_is_ok(self.object, max_acc_factor)
acc = automobiles_lib.check_road_is_ok(self.object, max_acc_factor)
--minetest.chat_send_all('engineacc: '.. engineacc)
if acc > 1 and acc < max_acc_factor and longit_speed > 0 then
--improper road will reduce speed

View File

@ -1,7 +1,7 @@
local min = math.min
local abs = math.abs
function automobiles.physics(self)
function automobiles_lib.physics(self)
local friction = 0.99
local vel=self.object:get_velocity()
-- dumb friction

View File

@ -2,7 +2,7 @@
-- fuel
--
function automobiles.contains(table, val)
function automobiles_lib.contains(table, val)
for k,v in pairs(table) do
if k == val then
return v
@ -11,7 +11,7 @@ function automobiles.contains(table, val)
return false
end
function automobiles.loadFuel(self, player_name, free, max_fuel)
function automobiles_lib.loadFuel(self, player_name, free, max_fuel)
free = free or false
local player = minetest.get_player_by_name(player_name)
@ -21,7 +21,7 @@ function automobiles.loadFuel(self, player_name, free, max_fuel)
local item_name = ""
if itmstck then item_name = itmstck:get_name() end
local fuel = automobiles.contains(automobiles.fuel, item_name)
local fuel = automobiles_lib.contains(automobiles_lib.fuel, item_name)
if fuel or free == true then
local stack = ItemStack(item_name .. " 1")
if self._energy < max_fuel then
@ -30,7 +30,7 @@ function automobiles.loadFuel(self, player_name, free, max_fuel)
self._energy = self._energy + fuel
end
if self._energy > max_fuel then self._energy = max_fuel end
automobiles.last_fuel_display = 0
automobiles_lib.last_fuel_display = 0
if self._energy == max_fuel then minetest.chat_send_player(player_name, "Full tank!") end
end

View File

@ -1,5 +1,5 @@
--lets assume that the rear axis is at object center, so we will use the distance only for front wheels
function automobiles.ground_get_distances(self, radius, axis_distance)
function automobiles_lib.ground_get_distances(self, radius, axis_distance)
--local mid_axis = (axis_length / 2)/10
local hip = axis_distance
@ -14,35 +14,35 @@ function automobiles.ground_get_distances(self, radius, axis_distance)
local pos = self.object:get_pos()
local r_x, r_z = automobiles.get_xz_from_hipotenuse(pos.x, pos.z, yaw, 0)
local r_x, r_z = automobiles_lib.get_xz_from_hipotenuse(pos.x, pos.z, yaw, 0)
local r_y = pos.y
local rear_axis = {x=r_x, y=r_y, z=r_z}
local rear_obstacle_level = automobiles.get_obstacle(rear_axis)
local rear_obstacle_level = automobiles_lib.get_obstacle(rear_axis)
--minetest.chat_send_all("rear"..dump(rear_obstacle_level))
local f_x, f_z = automobiles.get_xz_from_hipotenuse(pos.x, pos.z, yaw, hip)
local x, f_y = automobiles.get_xz_from_hipotenuse(f_x, r_y, pitch - math.rad(90), hip) --the x is only a mock
local f_x, f_z = automobiles_lib.get_xz_from_hipotenuse(pos.x, pos.z, yaw, hip)
local x, f_y = automobiles_lib.get_xz_from_hipotenuse(f_x, r_y, pitch - math.rad(90), hip) --the x is only a mock
--minetest.chat_send_all("r: "..r_y.." f: "..f_y .." - "..math.deg(pitch))
local front_axis = {x=f_x, y=f_y, z=f_z}
local front_obstacle_level = automobiles.get_obstacle(front_axis)
local front_obstacle_level = automobiles_lib.get_obstacle(front_axis)
--minetest.chat_send_all("front"..dump(front_obstacle_level))
--[[local left_front = {x=0, y=f_y, z=0}
left_front.x, left_front.z = automobiles.get_xz_from_hipotenuse(f_x, f_z, yaw+math.rad(90), mid_axis)
left_front.x, left_front.z = automobiles_lib.get_xz_from_hipotenuse(f_x, f_z, yaw+math.rad(90), mid_axis)
local right_front = {x=0, y=f_y, z=0}
right_front.x, right_front.z = automobiles.get_xz_from_hipotenuse(f_x, f_z, yaw-math.rad(90), mid_axis)]]--
right_front.x, right_front.z = automobiles_lib.get_xz_from_hipotenuse(f_x, f_z, yaw-math.rad(90), mid_axis)]]--
--[[
local rear_obstacle_level = automobiles.get_obstacle(rear_axis, 0.2, 0.25)]]--
local rear_obstacle_level = automobiles_lib.get_obstacle(rear_axis, 0.2, 0.25)]]--
--[[local left_rear = {x=0, y=r_y, z=0}
left_rear.x, left_rear.z = automobiles.get_xz_from_hipotenuse(r_x, r_z, yaw+math.rad(90), mid_axis)
left_rear.x, left_rear.z = automobiles_lib.get_xz_from_hipotenuse(r_x, r_z, yaw+math.rad(90), mid_axis)
local right_rear = {x=0, y=r_y, z=0}
right_rear.x, right_rear.z = automobiles.get_xz_from_hipotenuse(r_x, r_z, yaw-math.rad(90), mid_axis)]]--
right_rear.x, right_rear.z = automobiles_lib.get_xz_from_hipotenuse(r_x, r_z, yaw-math.rad(90), mid_axis)]]--
--lets try to get the pitch
if front_obstacle_level.y ~= nil and rear_obstacle_level.y ~= nil then
@ -62,7 +62,7 @@ function automobiles.ground_get_distances(self, radius, axis_distance)
end
function automobiles.get_xz_from_hipotenuse(orig_x, orig_z, yaw, distance)
function automobiles_lib.get_xz_from_hipotenuse(orig_x, orig_z, yaw, distance)
--cara, o minetest é bizarro, ele considera o eixo no sentido ANTI-HORÁRIO... Então pra equação funcionar, subtrair o angulo de 360 antes
yaw = math.rad(360) - yaw
local z = (math.cos(yaw)*distance) + orig_z
@ -70,14 +70,14 @@ function automobiles.get_xz_from_hipotenuse(orig_x, orig_z, yaw, distance)
return x, z
end
function automobiles.get_obstacle(ref_pos)
function automobiles_lib.get_obstacle(ref_pos)
--lets clone the table
local retval = {x=ref_pos.x, y=ref_pos.y, z=ref_pos.z}
--minetest.chat_send_all("aa y: " .. dump(retval.y))
local i_pos = {x=ref_pos.x, y=ref_pos.y, z=ref_pos.z}
--minetest.chat_send_all("bb y: " .. dump(i_pos.y))
local y = automobiles.eval_interception(i_pos, {x=i_pos.x, y=i_pos.y - 2, z=i_pos.z})
local y = automobiles_lib.eval_interception(i_pos, {x=i_pos.x, y=i_pos.y - 2, z=i_pos.z})
if y then
retval.y = y
end
@ -94,7 +94,7 @@ local function get_nodedef_field(nodename, fieldname)
return minetest.registered_nodes[nodename][fieldname]
end
function automobiles.eval_interception(initial_pos, end_pos)
function automobiles_lib.eval_interception(initial_pos, end_pos)
local ret_y = nil
local cast = minetest.raycast(initial_pos, end_pos, true, false)
local thing = cast:next()
@ -116,7 +116,7 @@ function automobiles.eval_interception(initial_pos, end_pos)
return ret_y
end
function automobiles.get_node_below(pos, dist)
function automobiles_lib.get_node_below(pos, dist)
local node = minetest.get_node(pos)
local pos_below = pos
pos_below.y = pos_below.y - (dist + 0.1)

View File

@ -1,15 +1,15 @@
-- Minetest 5.4.1 : automobiles
automobiles = {}
automobiles_lib = {}
automobiles.fuel = {['biofuel:biofuel'] = 1,['biofuel:bottle_fuel'] = 1,
automobiles_lib.fuel = {['biofuel:biofuel'] = 1,['biofuel:bottle_fuel'] = 1,
['biofuel:phial_fuel'] = 0.25, ['biofuel:fuel_can'] = 10}
automobiles.gravity = 9.8
automobiles.is_creative = minetest.settings:get_bool("creative_mode", false)
automobiles_lib.gravity = 9.8
automobiles_lib.is_creative = minetest.settings:get_bool("creative_mode", false)
--cars colors
automobiles.colors ={
automobiles_lib.colors ={
black='#2b2b2b',
blue='#0063b0',
brown='#8c5922',
@ -31,24 +31,24 @@ automobiles.colors ={
-- helpers and co.
--
function automobiles.get_hipotenuse_value(point1, point2)
function automobiles_lib.get_hipotenuse_value(point1, point2)
return math.sqrt((point1.x - point2.x) ^ 2 + (point1.y - point2.y) ^ 2 + (point1.z - point2.z) ^ 2)
end
function automobiles.dot(v1,v2)
function automobiles_lib.dot(v1,v2)
return (v1.x*v2.x)+(v1.y*v2.y)+(v1.z*v2.z)
end
function automobiles.sign(n)
function automobiles_lib.sign(n)
return n>=0 and 1 or -1
end
function automobiles.minmax(v,m)
function automobiles_lib.minmax(v,m)
return math.min(math.abs(v),m)*minekart.sign(v)
end
--painting
function automobiles.paint(self, colstr)
function automobiles_lib.paint(self, colstr)
if colstr then
self._color = colstr
local l_textures = self.initial_properties.textures
@ -63,7 +63,7 @@ function automobiles.paint(self, colstr)
end
-- attach player
function automobiles.attach_driver(self, player)
function automobiles_lib.attach_driver(self, player)
local name = player:get_player_name()
self.driver_name = name
@ -82,7 +82,7 @@ function automobiles.attach_driver(self, player)
end)
end
function automobiles.dettach_driver(self, player)
function automobiles_lib.dettach_driver(self, player)
local name = self.driver_name
--self._engine_running = false
@ -101,7 +101,7 @@ function automobiles.dettach_driver(self, player)
-- detach the player
if player then
--automobiles.remove_hud(player)
--automobiles_lib.remove_hud(player)
player:set_detach()
player_api.player_attached[name] = nil
@ -112,7 +112,7 @@ function automobiles.dettach_driver(self, player)
end
-- attach passenger
function automobiles.attach_pax(self, player, onside)
function automobiles_lib.attach_pax(self, player, onside)
local onside = onside or false
local name = player:get_player_name()
@ -170,7 +170,7 @@ function automobiles.attach_pax(self, player, onside)
end
end
function automobiles.dettach_pax(self, player)
function automobiles_lib.dettach_pax(self, player)
local name = player:get_player_name() --self._passenger
-- passenger clicked the object => driver gets off the vehicle
@ -194,7 +194,7 @@ function automobiles.dettach_pax(self, player)
--remove_physics_override(player, {speed=1,gravity=1,jump=1})
end
function automobiles.get_gauge_angle(value, initial_angle)
function automobiles_lib.get_gauge_angle(value, initial_angle)
initial_angle = initial_angle or 90
local angle = value * 18
angle = angle - initial_angle
@ -202,8 +202,8 @@ function automobiles.get_gauge_angle(value, initial_angle)
return angle
end
dofile(minetest.get_modpath("automobiles") .. DIR_DELIM .. "custom_physics.lua")
dofile(minetest.get_modpath("automobiles") .. DIR_DELIM .. "control.lua")
dofile(minetest.get_modpath("automobiles") .. DIR_DELIM .. "fuel_management.lua")
dofile(minetest.get_modpath("automobiles") .. DIR_DELIM .. "ground_detection.lua")
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "custom_physics.lua")
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "control.lua")
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "fuel_management.lua")
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "ground_detection.lua")

View File

@ -1,2 +1,2 @@
name = automobiles
name = automobiles_lib
depends=biofuel,mobkit

View File

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

Before

Width:  |  Height:  |  Size: 382 B

After

Width:  |  Height:  |  Size: 382 B

View File

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

View File

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

@ -4,7 +4,7 @@
roadster={}
roadster.LONGIT_DRAG_FACTOR = 0.16*0.16
roadster.LATER_DRAG_FACTOR = 30.0
roadster.gravity = automobiles.gravity
roadster.gravity = automobiles_lib.gravity
roadster.max_speed = 15
roadster.max_acc_factor = 5
roadster.max_fuel = 10
@ -14,10 +14,10 @@ ROADSTER_GAUGE_FUEL_POSITION = {x=0,y=8.04,z=17.84}
roadster.front_wheel_xpos = 10.26
roadster.rear_wheel_xpos = 10.26
dofile(minetest.get_modpath("automobiles") .. DIR_DELIM .. "custom_physics.lua")
dofile(minetest.get_modpath("automobiles") .. DIR_DELIM .. "control.lua")
dofile(minetest.get_modpath("automobiles") .. DIR_DELIM .. "fuel_management.lua")
dofile(minetest.get_modpath("automobiles") .. DIR_DELIM .. "ground_detection.lua")
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "custom_physics.lua")
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "control.lua")
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "fuel_management.lua")
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "ground_detection.lua")
dofile(minetest.get_modpath("automobiles_roadster") .. DIR_DELIM .. "roadster_utilities.lua")
dofile(minetest.get_modpath("automobiles_roadster") .. DIR_DELIM .. "roadster_entities.lua")
dofile(minetest.get_modpath("automobiles_roadster") .. DIR_DELIM .. "roadster_forms.lua")

View File

@ -2,4 +2,4 @@ name=automobiles_roadster
title=Roadster
description=A roadster automobile
author=apercy
depends=biofuel,automobiles,mobkit
depends=biofuel,automobiles_lib,mobkit

View File

@ -39,7 +39,7 @@ minetest.register_craftitem("automobiles_roadster:roadster", {
ent.owner = owner
car:set_yaw(placer:get_look_horizontal())
itemstack:take_item()
ent.object:set_acceleration({x=0,y=-automobiles.gravity,z=0})
ent.object:set_acceleration({x=0,y=-automobiles_lib.gravity,z=0})
end
end

View File

@ -220,7 +220,7 @@ minetest.register_entity("automobiles_roadster:roadster", {
infotext = "A very nice roadster!",
hp = 50,
buoyancy = 2,
physics = automobiles.physics,
physics = automobiles_lib.physics,
lastvelocity = vector.new(),
time_total = 0,
_passenger = nil,
@ -274,7 +274,7 @@ minetest.register_entity("automobiles_roadster:roadster", {
self.object:set_animation({x = 1, y = 8}, 0, 0, true)
automobiles.paint(self, self._color)
automobiles_lib.paint(self, self._color)
local pos = self.object:get_pos()
local top1=minetest.add_entity(self.object:get_pos(),'automobiles_roadster:top1')
@ -361,14 +361,14 @@ minetest.register_entity("automobiles_roadster:roadster", {
local nhdir = {x=hull_direction.z,y=0,z=-hull_direction.x} -- lateral unit vector
local velocity = self.object:get_velocity()
local longit_speed = automobiles.dot(velocity,hull_direction)
local longit_speed = automobiles_lib.dot(velocity,hull_direction)
local fuel_weight_factor = (5 - self._energy)/5000
local longit_drag = vector.multiply(hull_direction,(longit_speed*longit_speed) *
(roadster.LONGIT_DRAG_FACTOR - fuel_weight_factor) * -1 * automobiles.sign(longit_speed))
(roadster.LONGIT_DRAG_FACTOR - fuel_weight_factor) * -1 * automobiles_lib.sign(longit_speed))
local later_speed = automobiles.dot(velocity,nhdir)
local later_speed = automobiles_lib.dot(velocity,nhdir)
local later_drag = vector.multiply(nhdir,later_speed*
later_speed*roadster.LATER_DRAG_FACTOR*-1*automobiles.sign(later_speed))
later_speed*roadster.LATER_DRAG_FACTOR*-1*automobiles_lib.sign(later_speed))
local accel = vector.add(longit_drag,later_drag)
@ -411,7 +411,7 @@ minetest.register_entity("automobiles_roadster:roadster", {
local curr_pos = self.object:get_pos()
if is_attached then --and self.driver_name == self.owner then
local impact = automobiles.get_hipotenuse_value(velocity, self.lastvelocity)
local impact = automobiles_lib.get_hipotenuse_value(velocity, self.lastvelocity)
if impact > 1 then
--self.damage = self.damage + impact --sum the impact value directly to damage meter
if self._last_time_collision_snd > 0.3 then
@ -426,7 +426,7 @@ minetest.register_entity("automobiles_roadster:roadster", {
})
end
--[[if self.damage > 100 then --if acumulated damage is greater than 100, adieu
automobiles.destroy(self)
automobiles_lib.destroy(self)
end]]--
end
@ -448,7 +448,7 @@ minetest.register_entity("automobiles_roadster:roadster", {
--control
local steering_angle_max = 30
local steering_speed = 40
accel, stop = automobiles.control(self, dtime, hull_direction, longit_speed, longit_drag, later_drag, accel, roadster.max_acc_factor, roadster.max_speed, steering_angle_max, steering_speed)
accel, stop = automobiles_lib.control(self, dtime, hull_direction, longit_speed, longit_drag, later_drag, accel, roadster.max_acc_factor, roadster.max_speed, steering_angle_max, steering_speed)
else
if self.sound_handle ~= nil then
minetest.sound_stop(self.sound_handle)
@ -470,10 +470,10 @@ minetest.register_entity("automobiles_roadster:roadster", {
if math.abs(self._steering_angle)>5 then
local turn_rate = math.rad(40)
newyaw = yaw + dtime*(1 - 1 / (math.abs(longit_speed) + 1)) *
self._steering_angle / 30 * turn_rate * automobiles.sign(longit_speed)
self._steering_angle / 30 * turn_rate * automobiles_lib.sign(longit_speed)
end
automobiles.ground_get_distances(self, 0.5, 2.422)
automobiles_lib.ground_get_distances(self, 0.5, 2.422)
--[[if player and is_attached then
player:set_look_horizontal(newyaw)
@ -498,7 +498,7 @@ minetest.register_entity("automobiles_roadster:roadster", {
----------------------------------
if self._energy > 0 then
local zero_reference = vector.new()
local acceleration = automobiles.get_hipotenuse_value(accel, zero_reference)
local acceleration = automobiles_lib.get_hipotenuse_value(accel, zero_reference)
--minetest.chat_send_all(acceleration)
local consumed_power = acceleration/40000
self._energy = self._energy - consumed_power;
@ -511,12 +511,12 @@ minetest.register_entity("automobiles_roadster:roadster", {
roadster.engine_set_sound_and_animation(self, longit_speed)
end
local energy_indicator_angle = automobiles.get_gauge_angle(self._energy)
local energy_indicator_angle = automobiles_lib.get_gauge_angle(self._energy)
self.fuel_gauge:set_attach(self.object,'',ROADSTER_GAUGE_FUEL_POSITION,{x=0,y=0,z=energy_indicator_angle})
----------------------------
-- end energy consumption --
accel.y = -automobiles.gravity
accel.y = -automobiles_lib.gravity
if stop ~= true then
self.object:set_pos(curr_pos)
@ -565,9 +565,9 @@ minetest.register_entity("automobiles_roadster:roadster", {
refuel works it car is stopped and engine is off
]]--
local velocity = self.object:get_velocity()
local speed = automobiles.get_hipotenuse_value(vector.new(), velocity)
local speed = automobiles_lib.get_hipotenuse_value(vector.new(), velocity)
if math.abs(speed) <= 0.1 then
if automobiles.loadFuel(self, puncher:get_player_name(), false, roadster.max_fuel) then return end
if automobiles_lib.loadFuel(self, puncher:get_player_name(), false, roadster.max_fuel) then return end
end
-- end refuel
@ -589,7 +589,7 @@ minetest.register_entity("automobiles_roadster:roadster", {
local color, indx, _
if split[1] then _,indx = split[1]:find('dye') end
if indx then
for clr,_ in pairs(automobiles.colors) do
for clr,_ in pairs(automobiles_lib.colors) do
local _,x = split[2]:find(clr)
if x then color = clr end
end
@ -601,10 +601,10 @@ minetest.register_entity("automobiles_roadster:roadster", {
--lets paint!!!!
--local color = item_name:sub(indx+1)
local colstr = automobiles.colors[color]
local colstr = automobiles_lib.colors[color]
--minetest.chat_send_all(color ..' '.. dump(colstr))
if colstr then
automobiles.paint(self, colstr)
automobiles_lib.paint(self, colstr)
itmstck:set_count(itmstck:get_count()-1)
puncher:set_wielded_item(itmstck)
end
@ -653,7 +653,7 @@ minetest.register_entity("automobiles_roadster:roadster", {
else
if name == self.owner then
--is the owner, okay, lets attach
automobiles.attach_driver(self, clicker)
automobiles_lib.attach_driver(self, clicker)
-- sound
self.sound_handle = minetest.sound_play({name = "roadster_engine"},
{object = self.object, gain = 0.5, pitch = 0.6, max_hear_distance = 10, loop = true,})
@ -663,13 +663,13 @@ minetest.register_entity("automobiles_roadster:roadster", {
if self._passenger == nil then
--there is no passenger, so lets attach
if self.driver_name then
automobiles.attach_pax(self, clicker, true)
automobiles_lib.attach_pax(self, clicker, true)
end
else
--there is a passeger
if self._passenger == name then
--if you are the psenger, so deattach
automobiles.dettach_pax(self, clicker)
automobiles_lib.dettach_pax(self, clicker)
end
end
end

View File

@ -40,10 +40,10 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if ent._passenger then --any pax?
local pax_obj = minetest.get_player_by_name(ent._passenger)
automobiles.dettach_pax(ent, pax_obj)
automobiles_lib.dettach_pax(ent, pax_obj)
end
automobiles.dettach_driver(ent, player)
automobiles_lib.dettach_driver(ent, player)
end
minetest.close_formspec(name, "roadster:driver_main")
end

View File

@ -1,4 +1,4 @@
name=automobiles
name=automobiles_pck
title=Automobiles
description=Collection of automobiles
author = apercy