first
3
README.md
Normal file → Executable file
@ -1,2 +1,3 @@
|
||||
# automobiles
|
||||
automobiles mod for minetest
|
||||
|
||||
Modpack to add automobiles to minetest
|
||||
|
142
automobiles/automobiles_control.lua
Executable file
@ -0,0 +1,142 @@
|
||||
--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;
|
||||
|
||||
-- player control
|
||||
if player then
|
||||
local ctrl = player:get_player_control()
|
||||
|
||||
local acc = 0
|
||||
if self._engine_running then
|
||||
--running
|
||||
if longit_speed < 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
|
||||
else
|
||||
--slow maneuver
|
||||
if longit_speed < 1.0 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
|
||||
end
|
||||
|
||||
--reversing
|
||||
if ctrl.sneak and longit_speed <= 1.0 and longit_speed > -1.0 then
|
||||
acc = -1
|
||||
end
|
||||
|
||||
--break
|
||||
if ctrl.down then
|
||||
if math.abs(longit_speed) > 0 then
|
||||
acc = -5 / (longit_speed / 2) -- lets set a brake efficience based on speed
|
||||
end
|
||||
|
||||
--total stop
|
||||
--wheel break
|
||||
if longit_speed >= 0.1 then
|
||||
acc = -1
|
||||
end
|
||||
if longit_speed <= -0.1 then
|
||||
acc = 1
|
||||
end
|
||||
|
||||
if math.abs(longit_speed) <= 0.1 then
|
||||
-- do not like it here, but worked better
|
||||
acc = 0
|
||||
--self.object:set_acceleration(zero)
|
||||
self.object:set_velocity(vector.new())
|
||||
end
|
||||
end
|
||||
|
||||
if acc then retval_accel=vector.add(accel,vector.multiply(hull_direction,acc)) end
|
||||
|
||||
if ctrl.aux1 then
|
||||
--[[
|
||||
--sets the engine running - but sets a delay also, cause keypress
|
||||
if self._last_time_command > 0.3 then
|
||||
self._last_time_command = 0
|
||||
if self._engine_running then
|
||||
self._engine_running = false
|
||||
-- sound and animation
|
||||
if self.sound_handle then
|
||||
minetest.sound_stop(self.sound_handle)
|
||||
self.sound_handle = nil
|
||||
end
|
||||
--self.engine:set_animation_frame_speed(0)
|
||||
|
||||
elseif self._engine_running == false and self._energy > 0 then
|
||||
self._engine_running = true
|
||||
-- sound and animation
|
||||
self.sound_handle = minetest.sound_play({name = "engine"},
|
||||
{object = self.object, gain = 2.0, pitch = 1.0, max_hear_distance = 32, loop = true,})
|
||||
--self.engine:set_animation_frame_speed(30)
|
||||
end
|
||||
end]]--
|
||||
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
|
||||
end
|
||||
|
||||
|
64
automobiles/automobiles_custom_physics.lua
Executable file
@ -0,0 +1,64 @@
|
||||
local min = math.min
|
||||
local abs = math.abs
|
||||
|
||||
function automobiles.physics(self)
|
||||
local vel=self.object:get_velocity()
|
||||
-- dumb friction
|
||||
--[[if self.isonground and not self.isinliquid then
|
||||
self.object:set_velocity({x= vel.x> 0.2 and vel.x*mobkit.friction or 0,
|
||||
y=vel.y,
|
||||
z=vel.z > 0.2 and vel.z*mobkit.friction or 0})
|
||||
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
|
41
automobiles/automobiles_fuel_management.lua
Executable file
@ -0,0 +1,41 @@
|
||||
--
|
||||
-- fuel
|
||||
--
|
||||
|
||||
function automobiles.contains(table, val)
|
||||
for k,v in pairs(table) do
|
||||
if k == val then
|
||||
return v
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function automobiles.loadFuel(self, player_name, free, max_fuel)
|
||||
free = free or false
|
||||
|
||||
local player = minetest.get_player_by_name(player_name)
|
||||
local inv = player:get_inventory()
|
||||
|
||||
local itmstck=player:get_wielded_item()
|
||||
local item_name = ""
|
||||
if itmstck then item_name = itmstck:get_name() end
|
||||
|
||||
local fuel = automobiles.contains(automobiles.fuel, item_name)
|
||||
if fuel or free == true then
|
||||
local stack = ItemStack(item_name .. " 1")
|
||||
if self._energy < max_fuel then
|
||||
if free == false then inv:remove_item("main", stack) end
|
||||
if fuel then
|
||||
self._energy = self._energy + fuel
|
||||
end
|
||||
if self._energy > max_fuel then self._energy = max_fuel end
|
||||
automobiles.last_fuel_display = 0
|
||||
if self._energy == max_fuel then minetest.chat_send_player(player_name, "Full tank!") end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
202
automobiles/init.lua
Executable file
@ -0,0 +1,202 @@
|
||||
-- Minetest 5.4.1 : automobiles
|
||||
|
||||
automobiles = {}
|
||||
|
||||
automobiles.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)
|
||||
|
||||
--cars colors
|
||||
automobiles.colors ={
|
||||
black='#2b2b2b',
|
||||
blue='#0063b0',
|
||||
brown='#8c5922',
|
||||
cyan='#07B6BC',
|
||||
dark_green='#567a42',
|
||||
dark_grey='#6d6d6d',
|
||||
green='#4ee34c',
|
||||
grey='#9f9f9f',
|
||||
magenta='#ff0098',
|
||||
orange='#ff8b0e',
|
||||
pink='#ff62c6',
|
||||
red='#dc1818',
|
||||
violet='#a437ff',
|
||||
white='#FFFFFF',
|
||||
yellow='#ffe400',
|
||||
}
|
||||
|
||||
--
|
||||
-- helpers and co.
|
||||
--
|
||||
|
||||
function automobiles.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)
|
||||
return (v1.x*v2.x)+(v1.y*v2.y)+(v1.z*v2.z)
|
||||
end
|
||||
|
||||
function automobiles.sign(n)
|
||||
return n>=0 and 1 or -1
|
||||
end
|
||||
|
||||
function automobiles.minmax(v,m)
|
||||
return math.min(math.abs(v),m)*minekart.sign(v)
|
||||
end
|
||||
|
||||
--painting
|
||||
function automobiles.paint(self, colstr)
|
||||
if colstr then
|
||||
self._color = colstr
|
||||
local l_textures = self.initial_properties.textures
|
||||
for _, texture in ipairs(l_textures) do
|
||||
local indx = texture:find('automobiles_painting.png')
|
||||
if indx then
|
||||
l_textures[_] = "automobiles_painting.png^[multiply:".. colstr
|
||||
end
|
||||
end
|
||||
self.object:set_properties({textures=l_textures})
|
||||
end
|
||||
end
|
||||
|
||||
-- attach player
|
||||
function automobiles.attach_driver(self, player)
|
||||
local name = player:get_player_name()
|
||||
self.driver_name = name
|
||||
|
||||
-- attach the driver
|
||||
player:set_attach(self.driver_seat, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
||||
player:set_eye_offset({x = 0, y = -4, z = 2}, {x = 0, y = 1, z = -30})
|
||||
player:set_eye_offset({x = 0, y = -4, z = 2}, {x = 0, y = 1, z = -30})
|
||||
player_api.player_attached[name] = true
|
||||
-- make the driver sit
|
||||
minetest.after(0.2, function()
|
||||
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})
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function automobiles.dettach_driver(self, player)
|
||||
local name = self.driver_name
|
||||
|
||||
--self._engine_running = false
|
||||
|
||||
-- driver clicked the object => driver gets off the vehicle
|
||||
self.driver_name = nil
|
||||
|
||||
if self._engine_running then
|
||||
self._engine_running = false
|
||||
end
|
||||
-- sound and animation
|
||||
if self.sound_handle then
|
||||
minetest.sound_stop(self.sound_handle)
|
||||
self.sound_handle = nil
|
||||
end
|
||||
|
||||
-- detach the player
|
||||
if player then
|
||||
--automobiles.remove_hud(player)
|
||||
|
||||
player:set_detach()
|
||||
player_api.player_attached[name] = nil
|
||||
player:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})
|
||||
player_api.set_animation(player, "stand")
|
||||
end
|
||||
self.driver = nil
|
||||
end
|
||||
|
||||
-- attach passenger
|
||||
function automobiles.attach_pax(self, player, onside)
|
||||
local onside = onside or false
|
||||
local name = player:get_player_name()
|
||||
|
||||
if onside == true then
|
||||
if self._passenger == nil then
|
||||
self._passenger = name
|
||||
|
||||
-- attach the driver
|
||||
player:set_attach(self.passenger_seat, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
||||
player:set_eye_offset({x = 0, y = -4, z = 2}, {x = 0, y = 3, z = -30})
|
||||
player_api.player_attached[name] = true
|
||||
-- make the driver sit
|
||||
minetest.after(0.2, function()
|
||||
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})
|
||||
end
|
||||
end)
|
||||
end
|
||||
else
|
||||
--randomize the seat
|
||||
--[[local t = {1,2,3,4,5,6,7,8,9,10}
|
||||
for i = 1, #t*2 do
|
||||
local a = math.random(#t)
|
||||
local b = math.random(#t)
|
||||
t[a],t[b] = t[b],t[a]
|
||||
end
|
||||
|
||||
--for i = 1,10,1 do
|
||||
for k,v in ipairs(t) do
|
||||
i = t[k]
|
||||
if self._passengers[i] == nil then
|
||||
--minetest.chat_send_all(self.driver_name)
|
||||
self._passengers[i] = name
|
||||
player:set_attach(self._passengers_base[i], "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
||||
if i > 2 then
|
||||
player:set_eye_offset({x = 0, y = -4, z = 2}, {x = 0, y = 3, z = -30})
|
||||
else
|
||||
player:set_eye_offset({x = 0, y = -4, z = 0}, {x = 0, y = 3, z = -30})
|
||||
end
|
||||
player_api.player_attached[name] = true
|
||||
-- make the driver sit
|
||||
minetest.after(0.2, function()
|
||||
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})
|
||||
end
|
||||
end)
|
||||
break
|
||||
end
|
||||
end]]--
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
function automobiles.dettach_pax(self, player)
|
||||
local name = player:get_player_name() --self._passenger
|
||||
|
||||
-- passenger clicked the object => driver gets off the vehicle
|
||||
if self._passenger == name then
|
||||
self._passenger = nil
|
||||
else
|
||||
--[[for i = 10,1,-1
|
||||
do
|
||||
if self._passengers[i] == name then
|
||||
self._passengers[i] = nil
|
||||
break
|
||||
end
|
||||
end]]--
|
||||
end
|
||||
|
||||
-- detach the player
|
||||
player:set_detach()
|
||||
player_api.player_attached[name] = nil
|
||||
player_api.set_animation(player, "stand")
|
||||
player:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})
|
||||
--remove_physics_override(player, {speed=1,gravity=1,jump=1})
|
||||
end
|
||||
|
||||
|
||||
|
||||
dofile(minetest.get_modpath("automobiles") .. DIR_DELIM .. "automobiles_custom_physics.lua")
|
||||
dofile(minetest.get_modpath("automobiles") .. DIR_DELIM .. "automobiles_control.lua")
|
||||
dofile(minetest.get_modpath("automobiles") .. DIR_DELIM .. "automobiles_fuel_management.lua")
|
||||
|
2
automobiles/mod.conf
Executable file
@ -0,0 +1,2 @@
|
||||
name = automobiles
|
||||
depends=biofuel,mobkit
|
BIN
automobiles/models/automobiles_pivot_mesh.b3d
Executable file
BIN
automobiles/textures/automobiles_alpha.png
Executable file
After Width: | Height: | Size: 4.8 KiB |
BIN
automobiles/textures/automobiles_black.png
Executable file
After Width: | Height: | Size: 382 B |
BIN
automobiles/textures/automobiles_glass.png
Executable file
After Width: | Height: | Size: 4.7 KiB |
BIN
automobiles/textures/automobiles_grey.png
Executable file
After Width: | Height: | Size: 1.1 KiB |
BIN
automobiles/textures/automobiles_metal.png
Executable file
After Width: | Height: | Size: 5.9 KiB |
BIN
automobiles/textures/automobiles_metal2.png
Executable file
After Width: | Height: | Size: 6.4 KiB |
BIN
automobiles/textures/automobiles_painting.png
Executable file
After Width: | Height: | Size: 2.1 KiB |
BIN
automobiles/textures/automobiles_red.png
Executable file
After Width: | Height: | Size: 2.3 KiB |
BIN
automobiles/textures/automobiles_white.png
Executable file
After Width: | Height: | Size: 2.1 KiB |
BIN
automobiles/textures/automobiles_wood.png
Executable file
After Width: | Height: | Size: 5.3 KiB |
BIN
automobiles/textures/automobiles_wood2.png
Executable file
After Width: | Height: | Size: 5.8 KiB |
7
automobiles_roadster/README.md
Executable file
@ -0,0 +1,7 @@
|
||||
Roadster
|
||||
|
||||
This mod adds a roadster automobile to minetest
|
||||
|
||||
|
||||
|
||||
licence see the files
|
20
automobiles_roadster/init.lua
Executable file
@ -0,0 +1,20 @@
|
||||
--
|
||||
-- constants
|
||||
--
|
||||
roadster={}
|
||||
roadster.LONGIT_DRAG_FACTOR = 0.16*0.16
|
||||
roadster.LATER_DRAG_FACTOR = 30.0
|
||||
roadster.gravity = automobiles.gravity
|
||||
roadster.max_speed = 10
|
||||
roadster.max_acc_factor = 8
|
||||
roadster.max_fuel = 10
|
||||
|
||||
dofile(minetest.get_modpath("automobiles") .. DIR_DELIM .. "automobiles_custom_physics.lua")
|
||||
dofile(minetest.get_modpath("automobiles") .. DIR_DELIM .. "automobiles_control.lua")
|
||||
dofile(minetest.get_modpath("automobiles") .. DIR_DELIM .. "automobiles_fuel_management.lua")
|
||||
dofile(minetest.get_modpath("automobiles_roadster") .. DIR_DELIM .. "roadster_utilities.lua")
|
||||
dofile(minetest.get_modpath("automobiles_roadster") .. DIR_DELIM .. "roadster_entities.lua")
|
||||
|
||||
|
||||
|
||||
|
5
automobiles_roadster/mod.conf
Executable file
@ -0,0 +1,5 @@
|
||||
name=automobiles_roadster
|
||||
title=Roadster
|
||||
description=A roadster automobile
|
||||
author=apercy
|
||||
depends=biofuel,automobiles,mobkit
|
BIN
automobiles_roadster/models/automobiles_roadster.b3d
Executable file
BIN
automobiles_roadster/models/automobiles_roadster_front_suspension.b3d
Executable file
BIN
automobiles_roadster/models/automobiles_roadster_rear_suspension.b3d
Executable file
BIN
automobiles_roadster/models/automobiles_roadster_steering.b3d
Executable file
BIN
automobiles_roadster/models/automobiles_roadster_top1.b3d
Executable file
BIN
automobiles_roadster/models/automobiles_roadster_top2.b3d
Executable file
BIN
automobiles_roadster/models/automobiles_roadster_wheel.b3d
Executable file
652
automobiles_roadster/roadster_entities.lua
Executable file
@ -0,0 +1,652 @@
|
||||
--
|
||||
-- entity
|
||||
--
|
||||
|
||||
minetest.register_entity('automobiles_roadster:front_suspension',{
|
||||
initial_properties = {
|
||||
physical = false,
|
||||
collide_with_objects=false,
|
||||
pointable=false,
|
||||
visual = "mesh",
|
||||
mesh = "automobiles_roadster_front_suspension.b3d",
|
||||
textures = {"automobiles_black.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,
|
||||
|
||||
})
|
||||
|
||||
minetest.register_entity('automobiles_roadster:rear_suspension',{
|
||||
initial_properties = {
|
||||
physical = false,
|
||||
collide_with_objects=false,
|
||||
pointable=false,
|
||||
visual = "mesh",
|
||||
mesh = "automobiles_roadster_rear_suspension.b3d",
|
||||
textures = {"automobiles_black.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,
|
||||
|
||||
})
|
||||
|
||||
minetest.register_entity('automobiles_roadster:wheel',{
|
||||
initial_properties = {
|
||||
physical = false,
|
||||
collide_with_objects=false,
|
||||
pointable=false,
|
||||
visual = "mesh",
|
||||
mesh = "automobiles_roadster_wheel.b3d",
|
||||
backface_culling = false,
|
||||
textures = {"automobiles_black.png", "automobiles_wood2.png", "automobiles_roadster_wheel.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,
|
||||
|
||||
})
|
||||
|
||||
minetest.register_entity('automobiles_roadster:top1',{
|
||||
initial_properties = {
|
||||
physical = false,
|
||||
collide_with_objects=false,
|
||||
pointable=false,
|
||||
visual = "mesh",
|
||||
mesh = "automobiles_roadster_top1.b3d",
|
||||
backface_culling = false,
|
||||
textures = {"automobiles_metal.png", "automobiles_black.png", "automobiles_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,
|
||||
|
||||
})
|
||||
|
||||
minetest.register_entity('automobiles_roadster:top2',{
|
||||
initial_properties = {
|
||||
physical = false,
|
||||
collide_with_objects=false,
|
||||
pointable=false,
|
||||
visual = "mesh",
|
||||
mesh = "automobiles_roadster_top2.b3d",
|
||||
backface_culling = false,
|
||||
textures = {"automobiles_metal.png", "automobiles_black.png", "automobiles_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,
|
||||
|
||||
})
|
||||
|
||||
minetest.register_entity('automobiles_roadster:pivot_mesh',{
|
||||
initial_properties = {
|
||||
physical = false,
|
||||
collide_with_objects=false,
|
||||
pointable=false,
|
||||
visual = "mesh",
|
||||
mesh = "automobiles_pivot_mesh.b3d",
|
||||
textures = {"automobiles_black.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,
|
||||
|
||||
})
|
||||
|
||||
minetest.register_entity('automobiles_roadster:steering',{
|
||||
initial_properties = {
|
||||
physical = false,
|
||||
collide_with_objects=false,
|
||||
pointable=false,
|
||||
visual = "mesh",
|
||||
mesh = "automobiles_roadster_steering.b3d",
|
||||
textures = {"automobiles_metal.png", "automobiles_wood2.png", "automobiles_metal.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,
|
||||
|
||||
})
|
||||
|
||||
minetest.register_entity("automobiles_roadster:roadster", {
|
||||
initial_properties = {
|
||||
physical = true,
|
||||
collide_with_objects = true,
|
||||
collisionbox = {-1.1, -0.51, -1.1, 1.1, 2, 1.1},
|
||||
selectionbox = {-1.1, 0.0, -1.1, 1.1, 2, 1.1},
|
||||
stepheight = 0.5,
|
||||
visual = "mesh",
|
||||
mesh = "automobiles_roadster.b3d",
|
||||
textures = {
|
||||
"automobiles_black.png", --bancos
|
||||
"automobiles_painting.png", --pintura
|
||||
"automobiles_black.png", --chassis
|
||||
"automobiles_metal2.png", --carcaça farol
|
||||
"automobiles_black.png", --grade do radiador
|
||||
"automobiles_black.png", --forração interna
|
||||
"automobiles_metal.png", --lente do farol
|
||||
"automobiles_wood.png", --parede de fogo
|
||||
"automobiles_roadster_fuel.png", --combustivel
|
||||
"automobiles_metal2.png", --parabrisa fixo
|
||||
"automobiles_alpha.png", --vidro do parabrisa fixo
|
||||
"automobiles_black.png", --paralamas
|
||||
"automobiles_painting.png", --portas
|
||||
"automobiles_black.png", --portas interno
|
||||
"automobiles_metal2.png", --parabrisa movel
|
||||
"automobiles_alpha.png", --vidro do parabrisa movel
|
||||
"automobiles_metal2.png", --carenagem do radiador
|
||||
"automobiles_wood.png", --assoalho
|
||||
"automobiles_painting.png", --tanque de combustivel
|
||||
},
|
||||
},
|
||||
textures = {},
|
||||
driver_name = nil,
|
||||
sound_handle = nil,
|
||||
owner = "",
|
||||
static_save = true,
|
||||
infotext = "A very nice roadster!",
|
||||
hp = 50,
|
||||
buoyancy = 2,
|
||||
physics = automobiles.physics,
|
||||
lastvelocity = vector.new(),
|
||||
time_total = 0,
|
||||
_passenger = nil,
|
||||
_color = "#2b2b2b",
|
||||
_steering_angle = 0,
|
||||
_engine_running = false,
|
||||
_last_checkpoint = "",
|
||||
_total_laps = -1,
|
||||
_race_id = "",
|
||||
_energy = 1,
|
||||
_last_time_collision_snd = 0,
|
||||
_last_time_drift_snd = 0,
|
||||
_last_time_command = 0,
|
||||
|
||||
get_staticdata = function(self) -- unloaded/unloads ... is now saved
|
||||
return minetest.serialize({
|
||||
stored_owner = self.owner,
|
||||
stored_hp = self.hp,
|
||||
stored_color = self._color,
|
||||
stored_steering = self._steering_angle,
|
||||
stored_energy = self._energy,
|
||||
--race data
|
||||
stored_last_checkpoint = self._last_checkpoint,
|
||||
stored_total_laps = self._total_laps,
|
||||
stored_race_id = self._race_id,
|
||||
})
|
||||
end,
|
||||
|
||||
on_activate = function(self, staticdata, dtime_s)
|
||||
if staticdata ~= "" and staticdata ~= nil then
|
||||
local data = minetest.deserialize(staticdata) or {}
|
||||
self.owner = data.stored_owner
|
||||
self.hp = data.stored_hp
|
||||
self._color = data.stored_color
|
||||
self._steering_angle = data.stored_steering
|
||||
self._energy = data.stored_energy
|
||||
--minetest.debug("loaded: ", self.energy)
|
||||
--race data
|
||||
self._last_checkpoint = data.stored_last_checkpoint
|
||||
self._total_laps = data.stored_total_laps
|
||||
self._race_id = data.stored_race_id
|
||||
end
|
||||
|
||||
self.object:set_animation({x = 1, y = 8}, 0, 0, true)
|
||||
|
||||
automobiles.paint(self, self._color)
|
||||
local pos = self.object:get_pos()
|
||||
|
||||
local top1=minetest.add_entity(self.object:get_pos(),'automobiles_roadster:top1')
|
||||
top1:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
|
||||
self.top1 = top1
|
||||
|
||||
local front_suspension=minetest.add_entity(self.object:get_pos(),'automobiles_roadster:front_suspension')
|
||||
front_suspension:set_attach(self.object,'',{x=0,y=0,z=25.5},{x=0,y=0,z=0})
|
||||
self.front_suspension = front_suspension
|
||||
|
||||
local lf_wheel=minetest.add_entity(pos,'automobiles_roadster:wheel')
|
||||
lf_wheel:set_attach(self.front_suspension,'',{x=-10.8,y=0,z=0},{x=0,y=0,z=0})
|
||||
-- set the animation once and later only change the speed
|
||||
lf_wheel:set_animation({x = 2, y = 13}, 0, 0, true)
|
||||
self.lf_wheel = lf_wheel
|
||||
|
||||
local rf_wheel=minetest.add_entity(pos,'automobiles_roadster:wheel')
|
||||
rf_wheel:set_attach(self.front_suspension,'',{x=10.8,y=0,z=0},{x=0,y=0,z=0})
|
||||
-- set the animation once and later only change the speed
|
||||
rf_wheel:set_animation({x = 2, y = 13}, 0, 0, true)
|
||||
self.rf_wheel = rf_wheel
|
||||
|
||||
local rear_suspension=minetest.add_entity(self.object:get_pos(),'automobiles_roadster:rear_suspension')
|
||||
rear_suspension:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
|
||||
self.rear_suspension = rear_suspension
|
||||
|
||||
local lr_wheel=minetest.add_entity(pos,'automobiles_roadster:wheel')
|
||||
lr_wheel:set_attach(self.rear_suspension,'',{x=-10.8,y=0,z=0},{x=0,y=0,z=0})
|
||||
-- set the animation once and later only change the speed
|
||||
lr_wheel:set_animation({x = 2, y = 13}, 0, 0, true)
|
||||
self.lr_wheel = lr_wheel
|
||||
|
||||
local rr_wheel=minetest.add_entity(pos,'automobiles_roadster:wheel')
|
||||
rr_wheel:set_attach(self.rear_suspension,'',{x=10.8,y=0,z=0},{x=0,y=0,z=0})
|
||||
-- set the animation once and later only change the speed
|
||||
rr_wheel:set_animation({x = 2, y = 13}, 0, 0, true)
|
||||
self.rr_wheel = rr_wheel
|
||||
|
||||
local steering_axis=minetest.add_entity(pos,'automobiles_roadster:pivot_mesh')
|
||||
steering_axis:set_attach(self.object,'',{x=-4.25,y=12,z=15},{x=70,y=0,z=0})
|
||||
self.steering_axis = steering_axis
|
||||
|
||||
local steering=minetest.add_entity(self.steering_axis:get_pos(),'automobiles_roadster:steering')
|
||||
steering:set_attach(self.steering_axis,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
|
||||
self.steering = steering
|
||||
|
||||
local driver_seat=minetest.add_entity(pos,'automobiles_roadster:pivot_mesh')
|
||||
driver_seat:set_attach(self.object,'',{x=-4.25,y=7.5,z=9.5},{x=0,y=0,z=0})
|
||||
self.driver_seat = driver_seat
|
||||
|
||||
local passenger_seat=minetest.add_entity(pos,'automobiles_roadster:pivot_mesh')
|
||||
passenger_seat:set_attach(self.object,'',{x=4.25,y=7.5,z=9.5},{x=0,y=0,z=0})
|
||||
self.passenger_seat = passenger_seat
|
||||
|
||||
self.object:set_armor_groups({immortal=1})
|
||||
|
||||
mobkit.actfunc(self, staticdata, dtime_s)
|
||||
end,
|
||||
|
||||
on_step = function(self, dtime)
|
||||
mobkit.stepfunc(self, dtime)
|
||||
--[[sound play control]]--
|
||||
self._last_time_collision_snd = self._last_time_collision_snd + dtime
|
||||
if self._last_time_collision_snd > 1 then self._last_time_collision_snd = 1 end
|
||||
self._last_time_drift_snd = self._last_time_drift_snd + dtime
|
||||
if self._last_time_drift_snd > 1 then self._last_time_drift_snd = 1 end
|
||||
--[[end sound control]]--
|
||||
|
||||
local rotation = self.object:get_rotation()
|
||||
local yaw = rotation.y
|
||||
local newyaw=yaw
|
||||
local pitch = rotation.x
|
||||
|
||||
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 = automobiles.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))
|
||||
|
||||
local later_speed = automobiles.dot(velocity,nhdir)
|
||||
local later_drag = vector.multiply(nhdir,later_speed*
|
||||
later_speed*roadster.LATER_DRAG_FACTOR*-1*automobiles.sign(later_speed))
|
||||
|
||||
local accel = vector.add(longit_drag,later_drag)
|
||||
|
||||
local player = nil
|
||||
local is_attached = false
|
||||
if self.driver_name then
|
||||
player = minetest.get_player_by_name(self.driver_name)
|
||||
|
||||
if player then
|
||||
local player_attach = player:get_attach()
|
||||
if player_attach then
|
||||
if self.driver_seat then
|
||||
if player_attach == self.driver_seat then is_attached = true end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if is_attached then --and self.driver_name == self.owner then
|
||||
local curr_pos = self.object:get_pos()
|
||||
local impact = automobiles.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
|
||||
self._last_time_collision_snd = 0
|
||||
minetest.sound_play("collision", {
|
||||
to_player = self.driver_name,
|
||||
--pos = curr_pos,
|
||||
--max_hear_distance = 5,
|
||||
gain = 1.0,
|
||||
fade = 0.0,
|
||||
pitch = 1.0,
|
||||
})
|
||||
end
|
||||
--[[if self.damage > 100 then --if acumulated damage is greater than 100, adieu
|
||||
automobiles.destroy(self)
|
||||
end]]--
|
||||
end
|
||||
|
||||
local min_later_speed = 0.9
|
||||
if (later_speed > min_later_speed or later_speed < -min_later_speed) and
|
||||
self._last_time_drift_snd > 0.6 then
|
||||
self._last_time_drift_snd = 0
|
||||
minetest.sound_play("drifting", {
|
||||
to_player = self.driver_name,
|
||||
pos = curr_pos,
|
||||
max_hear_distance = 5,
|
||||
gain = 1.0,
|
||||
fade = 0.0,
|
||||
pitch = 1.0,
|
||||
ephemeral = true,
|
||||
})
|
||||
end
|
||||
|
||||
--control
|
||||
local steering_angle_max = 30
|
||||
local steering_speed = 40
|
||||
accel = 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)
|
||||
else
|
||||
if self.sound_handle ~= nil then
|
||||
minetest.sound_stop(self.sound_handle)
|
||||
self.sound_handle = nil
|
||||
end
|
||||
end
|
||||
|
||||
local angle_factor = self._steering_angle / 10
|
||||
self.lf_wheel:set_animation_frame_speed(longit_speed * (10 + angle_factor))
|
||||
self.rf_wheel:set_animation_frame_speed(longit_speed * (10 - angle_factor))
|
||||
self.lr_wheel:set_animation_frame_speed(longit_speed * (10 - angle_factor))
|
||||
self.rr_wheel:set_animation_frame_speed(longit_speed * (10 + angle_factor))
|
||||
|
||||
--whell turn
|
||||
self.steering:set_attach(self.steering_axis,'',{x=0,y=0,z=0},{x=0,y=0,z=self._steering_angle*2})
|
||||
self.lf_wheel:set_attach(self.front_suspension,'',{x=10.8,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
|
||||
self.rf_wheel:set_attach(self.front_suspension,'',{x=-10.8,y=0,z=0},{x=0,y=-self._steering_angle+angle_factor,z=0})
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
--[[if player and is_attached then
|
||||
player:set_look_horizontal(newyaw)
|
||||
end]]--
|
||||
|
||||
local newpitch = velocity.y * math.rad(6)
|
||||
|
||||
--[[
|
||||
accell correction
|
||||
under some circunstances the acceleration exceeds the max value accepted by set_acceleration and
|
||||
the game crashes with an overflow, so limiting the max acceleration in each axis prevents the crash
|
||||
]]--
|
||||
local max_factor = 25
|
||||
local acc_adjusted = 10
|
||||
if accel.x > max_factor then accel.x = acc_adjusted end
|
||||
if accel.x < -max_factor then accel.x = -acc_adjusted end
|
||||
if accel.z > max_factor then accel.z = acc_adjusted end
|
||||
if accel.z < -max_factor then accel.z = -acc_adjusted end
|
||||
-- end correction
|
||||
accel.y = -automobiles.gravity
|
||||
|
||||
self.object:set_acceleration(accel)
|
||||
|
||||
if newyaw~=yaw or newpitch~=pitch then self.object:set_rotation({x=newpitch,y=newyaw,z=0}) end
|
||||
|
||||
--saves last velocity for collision detection (abrupt stop)
|
||||
self.lastvelocity = self.object:get_velocity()
|
||||
|
||||
-- calculate energy consumption --
|
||||
----------------------------------
|
||||
if self._energy > 0 and self._engine_running and not automobiles.is_creative then
|
||||
local zero_reference = vector.new()
|
||||
local acceleration = automobiles.get_hipotenuse_value(accel, zero_reference)
|
||||
local consumed_power = acceleration/200000
|
||||
self._energy = self._energy - consumed_power;
|
||||
end
|
||||
if self._energy <= 0 and self._engine_running then
|
||||
self._engine_running = false
|
||||
if self.sound_handle then minetest.sound_stop(self.sound_handle) end
|
||||
minetest.chat_send_player(self.driver_name, "Out of fuel")
|
||||
end
|
||||
----------------------------
|
||||
-- end energy consumption --
|
||||
end,
|
||||
|
||||
on_punch = function(self, puncher, ttime, toolcaps, dir, damage)
|
||||
if not puncher or not puncher:is_player() then
|
||||
return
|
||||
end
|
||||
|
||||
local name = puncher:get_player_name()
|
||||
--[[if self.owner and self.owner ~= name and self.owner ~= "" then return end]]--
|
||||
if self.owner == nil then
|
||||
self.owner = name
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
local is_attached = false
|
||||
if puncher:get_attach() == self.object then is_attached = true end
|
||||
|
||||
local itmstck=puncher:get_wielded_item()
|
||||
local item_name = ""
|
||||
if itmstck then item_name = itmstck:get_name() end
|
||||
|
||||
--refuel procedure
|
||||
--[[
|
||||
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)
|
||||
if self._engine_running == false and speed <= 0.1 then
|
||||
if automobiles.loadFuel(self, puncher:get_player_name(), roadster.max_fuel) then return end
|
||||
end
|
||||
-- end refuel
|
||||
|
||||
if is_attached == false then
|
||||
|
||||
-- deal with painting or destroying
|
||||
if itmstck then
|
||||
--race status restart
|
||||
if item_name == "checkpoints:status_restarter" and self._engine_running == false then
|
||||
--restart race current status
|
||||
self._last_checkpoint = ""
|
||||
self._total_laps = -1
|
||||
self._race_id = ""
|
||||
return
|
||||
end
|
||||
|
||||
--painting
|
||||
local split = string.split(item_name, ":")
|
||||
local color, indx, _
|
||||
if split[1] then _,indx = split[1]:find('dye') end
|
||||
if indx then
|
||||
for clr,_ in pairs(automobiles.colors) do
|
||||
local _,x = split[2]:find(clr)
|
||||
if x then color = clr end
|
||||
end
|
||||
else
|
||||
color = false
|
||||
end
|
||||
|
||||
if color then
|
||||
|
||||
--lets paint!!!!
|
||||
--local color = item_name:sub(indx+1)
|
||||
local colstr = automobiles.colors[color]
|
||||
--minetest.chat_send_all(color ..' '.. dump(colstr))
|
||||
if colstr then
|
||||
automobiles.paint(self, colstr)
|
||||
itmstck:set_count(itmstck:get_count()-1)
|
||||
puncher:set_wielded_item(itmstck)
|
||||
end
|
||||
-- end painting
|
||||
|
||||
else -- deal damage
|
||||
|
||||
local is_admin = false
|
||||
is_admin = minetest.check_player_privs(puncher, {server=true})
|
||||
--minetest.chat_send_all('owner '.. self.owner ..' - name '.. name)
|
||||
if not self.driver and (self.owner == name or is_admin == true) and toolcaps and
|
||||
toolcaps.damage_groups and toolcaps.damage_groups.fleshy then
|
||||
self.hp = self.hp - 10
|
||||
minetest.sound_play("collision", {
|
||||
object = self.object,
|
||||
max_hear_distance = 5,
|
||||
gain = 1.0,
|
||||
fade = 0.0,
|
||||
pitch = 1.0,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if self.hp <= 0 then
|
||||
roadster.destroy(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end,
|
||||
|
||||
on_rightclick = function(self, clicker)
|
||||
if not clicker or not clicker:is_player() then
|
||||
return
|
||||
end
|
||||
|
||||
local name = clicker:get_player_name()
|
||||
--[[if self.owner and self.owner ~= name and self.owner ~= "" then return end]]--
|
||||
if self.owner == "" then
|
||||
self.owner = name
|
||||
end
|
||||
|
||||
if name == self.driver_name then
|
||||
--detach all
|
||||
automobiles.dettach_driver(self, clicker)
|
||||
|
||||
local passenger = nil
|
||||
if self._passenger then
|
||||
passenger = minetest.get_player_by_name(self._passenger)
|
||||
if passenger then automobiles.dettach_pax(self, passenger) end
|
||||
end
|
||||
|
||||
self.object:set_acceleration(vector.multiply(automobiles.vector_up, -automobiles.gravity))
|
||||
|
||||
else
|
||||
if name == self.owner then
|
||||
--is the owner, okay, lets attach
|
||||
automobiles.attach_driver(self, clicker)
|
||||
else
|
||||
--minetest.chat_send_all("clicou")
|
||||
--a passenger
|
||||
if self._passenger == nil then
|
||||
--there is no passenger, so lets attach
|
||||
if self.driver_name then
|
||||
automobiles.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)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
--
|
||||
-- items
|
||||
--
|
||||
|
||||
-- roadster
|
||||
minetest.register_craftitem("automobiles_roadster:roadster", {
|
||||
description = "Roadster",
|
||||
inventory_image = "automobiles_roadster.png",
|
||||
liquids_pointable = false,
|
||||
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
if pointed_thing.type ~= "node" then
|
||||
return
|
||||
end
|
||||
|
||||
local pointed_pos = pointed_thing.above
|
||||
--pointed_pos.y=pointed_pos.y+0.2
|
||||
local car = minetest.add_entity(pointed_pos, "automobiles_roadster:roadster")
|
||||
if car and placer then
|
||||
local ent = car:get_luaentity()
|
||||
local owner = placer:get_player_name()
|
||||
if ent then
|
||||
ent.owner = owner
|
||||
car:set_yaw(placer:get_look_horizontal())
|
||||
itemstack:take_item()
|
||||
ent.object:set_acceleration({x=0,y=-automobiles.gravity,z=0})
|
||||
end
|
||||
end
|
||||
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
--
|
||||
-- crafting
|
||||
--
|
||||
--[[
|
||||
if minetest.get_modpath("default") then
|
||||
minetest.register_craft({
|
||||
output = "automobiles_roadster:roadster",
|
||||
recipe = {
|
||||
{"default:obsidian_block", "default:steel_ingot", "default:obsidian_block"},
|
||||
{"default:steel_ingot", "default:mese_block", "default:steel_ingot"},
|
||||
{"default:obsidian_block", "default:steel_ingot", "default:obsidian_block"},
|
||||
}
|
||||
})
|
||||
end]]--
|
36
automobiles_roadster/roadster_utilities.lua
Executable file
@ -0,0 +1,36 @@
|
||||
--dofile(minetest.get_modpath("automobiles_roadster") .. DIR_DELIM .. "roadster_global_definitions.lua")
|
||||
--dofile(minetest.get_modpath("automobiles_roadster") .. DIR_DELIM .. "roadster_hud.lua")
|
||||
|
||||
-- destroy the roadster
|
||||
function roadster.destroy(self, puncher)
|
||||
if self.sound_handle then
|
||||
minetest.sound_stop(self.sound_handle)
|
||||
self.sound_handle = nil
|
||||
end
|
||||
|
||||
if self.driver_name then
|
||||
-- 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})
|
||||
if minetest.global_exists("player_api") then
|
||||
player_api.player_attached[self.driver_name] = nil
|
||||
-- player should stand again
|
||||
player_api.set_animation(puncher, "stand")
|
||||
end
|
||||
self.driver_name = nil
|
||||
end
|
||||
|
||||
local pos = self.object:get_pos()
|
||||
if self.l_wheel then self.l_wheel:remove() end
|
||||
if self.r_wheel then self.r_wheel:remove() end
|
||||
if self.steering_base then self.steering_base:remove() end
|
||||
if self.steering_axis then self.steering_axis:remove() end
|
||||
if self.steering then self.steering:remove() end
|
||||
if self.dir_bar then self.dir_bar:remove() end
|
||||
|
||||
self.object:remove()
|
||||
|
||||
pos.y=pos.y+2
|
||||
|
||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_roadster:roadster')
|
||||
end
|
BIN
automobiles_roadster/screenshot.png
Executable file
After Width: | Height: | Size: 254 KiB |
BIN
automobiles_roadster/textures/automobiles_roadster.png
Executable file
After Width: | Height: | Size: 8.8 KiB |
BIN
automobiles_roadster/textures/automobiles_roadster_fuel.png
Executable file
After Width: | Height: | Size: 2.4 KiB |
BIN
automobiles_roadster/textures/automobiles_roadster_metal2.png
Executable file
After Width: | Height: | Size: 6.4 KiB |
BIN
automobiles_roadster/textures/automobiles_roadster_wheel.png
Executable file
After Width: | Height: | Size: 10 KiB |
198
license.txt
Executable file
@ -0,0 +1,198 @@
|
||||
Copyright (C) 2021 Alexsandro Percy (APercy) and contributors
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
=================================
|
||||
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright © 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and modification follow.
|
||||
TERMS AND CONDITIONS
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that same work.
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
|
||||
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices".
|
||||
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
|
||||
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
|
||||
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
|
||||
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
|
||||
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
|
||||
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
|
||||
|
||||