improved catrelle

This commit is contained in:
Alexsandro Percy 2023-09-12 11:39:25 -03:00
parent 3cadbc5487
commit 870389bc44
6 changed files with 10 additions and 280 deletions

View File

@ -17,6 +17,7 @@ dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "custom_physics.l
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_lib") .. DIR_DELIM .. "entities.lua")
dofile(minetest.get_modpath("automobiles_buggy") .. DIR_DELIM .. "buggy_forms.lua")
dofile(minetest.get_modpath("automobiles_buggy") .. DIR_DELIM .. "buggy_utilities.lua")
dofile(minetest.get_modpath("automobiles_buggy") .. DIR_DELIM .. "buggy_entities.lua")

View File

@ -35,7 +35,7 @@ minetest.register_craftitem("automobiles_catrelle:catrelle", {
itemstack:take_item()
ent.object:set_acceleration({x=0,y=-automobiles_lib.gravity,z=0})
automobiles_lib.setText(ent, "Catrelle")
automobiles_lib.create_inventory(ent, catrelle.trunk_slots, owner)
automobiles_lib.create_inventory(ent, ent._trunk_slots, owner)
end
end

View File

@ -278,6 +278,9 @@ minetest.register_entity("automobiles_catrelle:catrelle", {
_intensity = 4,
_car_gravity = -automobiles_lib.gravity,
_is_flying = 0,
_trunk_slots = 32,
_engine_sound = "automobiles_engine",
_max_fuel = 10,
get_staticdata = function(self) -- unloaded/unloads ... is now saved
return minetest.serialize({
@ -403,7 +406,7 @@ minetest.register_entity("automobiles_catrelle:catrelle", {
local inv = minetest.get_inventory({type = "detached", name = self._inv_id})
-- if the game was closed the inventories have to be made anew, instead of just reattached
if not inv then
automobiles_lib.create_inventory(self, catrelle.trunk_slots)
automobiles_lib.create_inventory(self, self._trunk_slots)
else
self.inv = inv
end
@ -630,7 +633,7 @@ minetest.register_entity("automobiles_catrelle:catrelle", {
self._last_engine_sound_update = self._last_engine_sound_update + dtime
if self._last_engine_sound_update > 0.300 then
self._last_engine_sound_update = 0
catrelle.engine_set_sound_and_animation(self, longit_speed)
automobiles_lib.engine_set_sound_and_animation(self, longit_speed)
end
end
@ -674,121 +677,8 @@ minetest.register_entity("automobiles_catrelle:catrelle", {
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.driver_seat 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_lib.get_hipotenuse_value(vector.new(), velocity)
if math.abs(speed) <= 0.1 then
if automobiles_lib.loadFuel(self, puncher:get_player_name(), false, catrelle.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
if automobiles_lib.set_paint(self, puncher, itmstck) == false then
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
catrelle.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
catrelle.driver_formspec(name)
else
if name == self.owner then
if clicker:get_player_control().aux1 == true then
automobiles_lib.show_vehicle_trunk_formspec(self, clicker, catrelle.trunk_slots)
else
--is the owner, okay, lets attach
automobiles_lib.attach_driver(self, clicker)
-- sound
self.sound_handle = minetest.sound_play({name = catrelle.engine_sound},
{object = self.object, gain = 1.5, pitch = 1, max_hear_distance = 30, loop = true,})
end
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_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_lib.dettach_pax(self, clicker)
end
end
end
end
end,
on_punch = automobiles_lib.on_punch,
on_rightclick = automobiles_lib.on_rightclick,
})

View File

@ -1,83 +0,0 @@
--------------
-- Manual --
--------------
function catrelle.getCarFromPlayer(player)
local seat = player:get_attach()
if seat then
local car = seat:get_attach()
return car
end
return nil
end
function catrelle.driver_formspec(name)
local player = minetest.get_player_by_name(name)
local vehicle_obj = catrelle.getCarFromPlayer(player)
if vehicle_obj == nil then
return
end
local ent = vehicle_obj:get_luaentity()
local yaw = "false"
if ent._yaw_by_mouse then yaw = "true" end
local flight = "false"
if ent._is_flying == 1 then flight = "true" end
local basic_form = table.concat({
"formspec_version[3]",
"size[6,7]",
}, "")
basic_form = basic_form.."button[1,1.0;4,1;go_out;Go Offboard]"
basic_form = basic_form.."button[1,2.5;4,1;lights;Lights]"
if ent._catrelle_type == 1 then basic_form = basic_form.."checkbox[1,4.0;flight;Flight Mode;"..flight.."]" end
basic_form = basic_form.."checkbox[1,5.5;yaw;Direction by mouse;"..yaw.."]"
minetest.show_formspec(name, "catrelle:driver_main", basic_form)
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname == "catrelle:driver_main" then
local name = player:get_player_name()
local car_obj = catrelle.getCarFromPlayer(player)
if car_obj then
local ent = car_obj:get_luaentity()
if ent then
if fields.go_out then
if ent._passenger then --any pax?
local pax_obj = minetest.get_player_by_name(ent._passenger)
automobiles_lib.dettach_pax(ent, pax_obj)
end
ent._is_flying = 0
automobiles_lib.dettach_driver(ent, player)
end
if fields.lights then
if ent._show_lights == true then
ent._show_lights = false
else
ent._show_lights = true
end
end
if fields.yaw then
if ent._yaw_by_mouse == true then
ent._yaw_by_mouse = false
else
ent._yaw_by_mouse = true
end
end
if fields.flight then
if ent._is_flying == 1 then
ent._is_flying = 0
else
ent._is_flying = 1
end
catrelle.turn_flight_mode(ent)
end
end
end
minetest.close_formspec(name, "catrelle:driver_main")
end
end)

View File

@ -7,10 +7,7 @@ catrelle.LATER_DRAG_FACTOR = 8.0
catrelle.gravity = automobiles_lib.gravity
catrelle.max_speed = 14
catrelle.max_acc_factor = 5
catrelle.max_fuel = 10
catrelle.trunk_slots = 32
catrelle.ideal_step = 0.2
catrelle.engine_sound = "automobiles_engine"
catrelle_GAUGE_FUEL_POSITION = {x=-4.47,y=8.50,z=20.5}
@ -21,9 +18,8 @@ dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "custom_physics.l
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_lib") .. DIR_DELIM .. "control.lua")
dofile(minetest.get_modpath("automobiles_catrelle") .. DIR_DELIM .. "utilities.lua")
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "entities.lua")
dofile(minetest.get_modpath("automobiles_catrelle") .. DIR_DELIM .. "entities.lua")
dofile(minetest.get_modpath("automobiles_catrelle") .. DIR_DELIM .. "forms.lua")
dofile(minetest.get_modpath("automobiles_catrelle") .. DIR_DELIM .. "crafts.lua")

View File

@ -1,74 +0,0 @@
-- destroy the catrelle
function catrelle.destroy(self, puncher)
automobiles_lib.remove_light(self)
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)
if puncher then
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
end
self.driver_name = nil
end
local pos = self.object:get_pos()
if self.front_suspension then self.front_suspension:remove() end
if self.lf_wheel then self.lf_wheel:remove() end
if self.rf_wheel then self.rf_wheel:remove() end
if self.rear_suspension then self.rear_suspension:remove() end
if self.lr_wheel then self.lr_wheel:remove() end
if self.rr_wheel then self.rr_wheel:remove() end
if self.driver_seat then self.driver_seat:remove() end
if self.passenger_seat then self.passenger_seat:remove() end
if self.fuel_gauge then self.fuel_gauge:remove() end
if self.lights then self.lights:remove() end
if self.r_lights then self.r_lights:remove() end
if self.turn_l_light then self.turn_l_light:remove() end
if self.turn_r_light then self.turn_r_light:remove() end
automobiles_lib.destroy_inventory(self)
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_catrelle:catrelle')
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:engine')
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel')
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel')
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel')
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'automobiles_lib:wheel')
end
function catrelle.engine_set_sound_and_animation(self, _longit_speed)
--minetest.chat_send_all('test1 ' .. dump(self._engine_running) )
if self.sound_handle then
if (math.abs(self._longit_speed) > math.abs(_longit_speed) + 0.03) or (math.abs(self._longit_speed) + 0.03 < math.abs(_longit_speed)) then
--minetest.chat_send_all('test2')
catrelle.engineSoundPlay(self)
end
end
end
function catrelle.engineSoundPlay(self)
--sound
if self.sound_handle then minetest.sound_stop(self.sound_handle) end
if self.object then
self.sound_handle = minetest.sound_play({name = catrelle.engine_sound},
{object = self.object, gain = 2,
pitch = 1 + ((self._longit_speed/10)/2),
max_hear_distance = 10,
loop = true,})
end
end