compatibilizing on_activite method on cars for future improvements

This commit is contained in:
Alexsandro Percy 2023-12-02 19:35:16 -03:00
parent a857d7db7d
commit b14dd24921
18 changed files with 417 additions and 894 deletions

View File

@ -302,131 +302,35 @@ minetest.register_entity("automobiles_buggy:buggy", {
_formspec_function = buggy.driver_formspec,
_destroy_function = buggy.destroy,
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,
stored_rag = self._show_rag,
stored_pitch = self._pitch,
stored_light_old_pos = self._light_old_pos,
stored_inv_id = self._inv_id,
})
end,
_vehicle_name = "Buggy",
_drive_wheel_pos = {x=-4.26,y=6.01,z=14.18},
_drive_wheel_angle = 15,
_steering_ent = 'automobiles_buggy:steering',
_rag_extended_ent = 'automobiles_buggy:rag',
_seat_pos = {{x=-4.25,y=0.48,z=9.5},{x=4.25,y=0.48,z=9.5}},
_front_suspension_ent = 'automobiles_buggy:front_suspension',
_front_suspension_pos = {x=0,y=-0.7,z=23},
_front_wheel_ent = 'automobiles_buggy:f_wheel',
_front_wheel_xpos = 8,
_front_wheel_frames = {x = 1, y = 13},
_rear_suspension_ent = 'automobiles_buggy:rear_suspension',
_rear_suspension_pos = {x=0,y=0,z=0},
_rear_wheel_ent = 'automobiles_buggy:r_wheel',
_rear_wheel_xpos = 8,
_rear_wheel_frames = {x = 1, y = 13},
_fuel_gauge_pos = {x=0,y=4.65,z=15.17},
_front_lights = 'automobiles_buggy:f_lights',
_rear_lights = 'automobiles_buggy:r_lights',
get_staticdata = automobiles_lib.get_staticdata,
on_deactivate = function(self)
automobiles_lib.save_inventory(self)
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
self._show_rag = data.stored_rag
self._pitch = data.stored_pitch
self._light_old_pos = data.stored_light_old_pos
self._inv_id = data.stored_inv_id
automobiles_lib.setText(self, "Buggy")
end
self.object:set_animation({x = 1, y = 8}, 0, 0, true)
automobiles_lib.paint(self, self._color)
local pos = self.object:get_pos()
local rag=minetest.add_entity(self.object:get_pos(),'automobiles_buggy:rag')
rag:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.rag = rag
local front_suspension=minetest.add_entity(self.object:get_pos(),'automobiles_buggy:front_suspension')
front_suspension:set_attach(self.object,'',{x=0,y=-0.7,z=23},{x=0,y=0,z=0})
self.front_suspension = front_suspension
local lf_wheel=minetest.add_entity(pos,'automobiles_buggy:f_wheel')
lf_wheel:set_attach(self.front_suspension,'',{x=-buggy.front_wheel_xpos,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 = 1, y = 13}, 0, 0, true)
self.lf_wheel = lf_wheel
local rf_wheel=minetest.add_entity(pos,'automobiles_buggy:f_wheel')
rf_wheel:set_attach(self.front_suspension,'',{x=buggy.front_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
-- set the animation once and later only change the speed
rf_wheel:set_animation({x = 1, y = 13}, 0, 0, true)
self.rf_wheel = rf_wheel
local rear_suspension=minetest.add_entity(self.object:get_pos(),'automobiles_buggy: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_buggy:r_wheel')
lr_wheel:set_attach(self.rear_suspension,'',{x=-buggy.rear_wheel_xpos,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 = 1, y = 13}, 0, 0, true)
self.lr_wheel = lr_wheel
local rr_wheel=minetest.add_entity(pos,'automobiles_buggy:r_wheel')
rr_wheel:set_attach(self.rear_suspension,'',{x=buggy.rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
-- set the animation once and later only change the speed
rr_wheel:set_animation({x = 1, y = 13}, 0, 0, true)
self.rr_wheel = rr_wheel
local steering_axis=minetest.add_entity(pos,'automobiles_buggy:pivot_mesh')
steering_axis:set_attach(self.object,'',{x=-4.26,y=6.01,z=14.18},{x=15,y=0,z=0})
self.steering_axis = steering_axis
local steering=minetest.add_entity(self.steering_axis:get_pos(),'automobiles_buggy: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_buggy:pivot_mesh')
driver_seat:set_attach(self.object,'',{x=-4.25,y=0.48,z=9.5},{x=0,y=0,z=0})
self.driver_seat = driver_seat
local passenger_seat=minetest.add_entity(pos,'automobiles_buggy:pivot_mesh')
passenger_seat:set_attach(self.object,'',{x=4.25,y=0.48,z=9.5},{x=0,y=0,z=0})
self.passenger_seat = passenger_seat
local fuel_gauge=minetest.add_entity(pos,'automobiles_buggy:pointer')
fuel_gauge:set_attach(self.object,'',BUGGY_GAUGE_FUEL_POSITION,{x=0,y=0,z=0})
self.fuel_gauge = fuel_gauge
local lights = minetest.add_entity(pos,'automobiles_buggy:f_lights')
lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.lights = lights
self.lights:set_properties({is_visible=true})
local r_lights = minetest.add_entity(pos,'automobiles_buggy:r_lights')
r_lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.r_lights = r_lights
self.r_lights:set_properties({is_visible=true})
self.object:set_armor_groups({immortal=1})
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, self._trunk_slots)
else
self.inv = inv
end
automobiles_lib.actfunc(self, staticdata, dtime_s)
end,
on_activate = automobiles_lib.on_activate,
on_step = function(self, dtime)
automobiles_lib.stepfunc(self, dtime)
@ -576,8 +480,8 @@ minetest.register_entity("automobiles_buggy:buggy", {
--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=-buggy.front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=buggy.front_wheel_xpos,y=0,z=0},{x=0,y=(-self._steering_angle+angle_factor)+180,z=0})
self.lf_wheel:set_attach(self.front_suspension,'',{x=-self._front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=self._front_wheel_xpos,y=0,z=0},{x=0,y=(-self._steering_angle+angle_factor)+180,z=0})
if math.abs(self._steering_angle)>5 then
local turn_rate = math.rad(40)
@ -620,7 +524,7 @@ minetest.register_entity("automobiles_buggy:buggy", {
end
local energy_indicator_angle = automobiles_lib.get_gauge_angle(self._energy)
self.fuel_gauge:set_attach(self.object,'',BUGGY_GAUGE_FUEL_POSITION,{x=0,y=0,z=energy_indicator_angle})
self.fuel_gauge:set_attach(self.object,'',self._fuel_gauge_pos,{x=0,y=0,z=energy_indicator_angle})
----------------------------
-- end energy consumption --

View File

@ -8,16 +8,10 @@ buggy.gravity = automobiles_lib.gravity
buggy.max_speed = 15
buggy.max_acc_factor = 5
BUGGY_GAUGE_FUEL_POSITION = {x=0,y=4.65,z=15.17}
buggy.front_wheel_xpos = 8
buggy.rear_wheel_xpos = 8
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_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

@ -282,138 +282,35 @@ minetest.register_entity("automobiles_catrelle:catrelle", {
_engine_sound = "automobiles_engine",
_max_fuel = 10,
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,
stored_rag = self._show_rag,
stored_pitch = self._pitch,
stored_light_old_pos = self._light_old_pos,
stored_inv_id = self._inv_id,
stored_catrelle_type = self._catrelle_type,
stored_car_gravity = self._car_gravity,
})
end,
_vehicle_name = "Catrelle",
_drive_wheel_pos = {x=-4.0, y=8.00, z=21},
_drive_wheel_angle = 15,
_seat_pos = {{x=-4.0,y=3,z=15},{x=4.0,y=3,z=15}},
_front_suspension_ent = 'automobiles_catrelle:front_suspension',
_front_suspension_pos = {x=0,y=-0.2,z=30.5},
_front_wheel_ent = 'automobiles_catrelle:wheel',
_front_wheel_xpos = 7.5,
_front_wheel_frames = {x = 1, y = 49},
_rear_suspension_ent = 'automobiles_catrelle:rear_suspension',
_rear_suspension_pos = {x=0,y=-0.2,z=0},
_rear_wheel_ent = 'automobiles_catrelle:wheel',
_rear_wheel_xpos = 7.5,
_rear_wheel_frames = {x = 1, y = 49},
_fuel_gauge_pos = {x=-4.47,y=8.50,z=20.5},
_front_lights = 'automobiles_catrelle:f_lights',
_rear_lights = 'automobiles_catrelle:r_lights',
_turn_left_lights = 'automobiles_catrelle:turn_left_light',
_turn_right_lights = 'automobiles_catrelle:turn_right_light',
get_staticdata = automobiles_lib.get_staticdata,
on_deactivate = function(self)
automobiles_lib.save_inventory(self)
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
self._show_rag = data.stored_rag
self._pitch = data.stored_pitch
self._light_old_pos = data.stored_light_old_pos
self._inv_id = data.stored_inv_id
self._catrelle_type = data.stored_catrelle_type
self._car_gravity = data.stored_car_gravity or -automobiles_lib.gravity
automobiles_lib.setText(self, "catrelle")
end
self.object:set_animation({x = 1, y = 8}, 0, 0, true)
automobiles_lib.paint(self, self._color)
local pos = self.object:get_pos()
local front_suspension=minetest.add_entity(self.object:get_pos(),'automobiles_catrelle:front_suspension')
front_suspension:set_attach(self.object,'',{x=0,y=-0.2,z=30.5},{x=0,y=0,z=0})
self.front_suspension = front_suspension
local lf_wheel=minetest.add_entity(pos,'automobiles_catrelle:wheel')
lf_wheel:set_attach(self.front_suspension,'',{x=-catrelle.front_wheel_xpos,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 = 1, y = 49}, 0, 0, true)
self.lf_wheel = lf_wheel
local rf_wheel=minetest.add_entity(pos,'automobiles_catrelle:wheel')
rf_wheel:set_attach(self.front_suspension,'',{x=catrelle.front_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
-- set the animation once and later only change the speed
rf_wheel:set_animation({x = 1, y = 49}, 0, 0, true)
self.rf_wheel = rf_wheel
local rear_suspension=minetest.add_entity(self.object:get_pos(),'automobiles_catrelle:rear_suspension')
rear_suspension:set_attach(self.object,'',{x=0,y=-0.2,z=0},{x=0,y=0,z=0})
self.rear_suspension = rear_suspension
local lr_wheel=minetest.add_entity(pos,'automobiles_catrelle:wheel')
lr_wheel:set_attach(self.rear_suspension,'',{x=-catrelle.rear_wheel_xpos,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 = 1, y = 49}, 0, 0, true)
self.lr_wheel = lr_wheel
local rr_wheel=minetest.add_entity(pos,'automobiles_catrelle:wheel')
rr_wheel:set_attach(self.rear_suspension,'',{x=catrelle.rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
-- set the animation once and later only change the speed
rr_wheel:set_animation({x = 1, y = 49}, 0, 0, true)
self.rr_wheel = rr_wheel
self.object:set_bone_position("drive_adjust", {x=-4.0, y=8.00, z=21}, {x=15, y=0, z=0})
local driver_seat=minetest.add_entity(pos,'automobiles_catrelle:pivot_mesh')
driver_seat:set_attach(self.object,'',{x=-4.0,y=3,z=15},{x=0,y=0,z=0})
self.driver_seat = driver_seat
local passenger_seat=minetest.add_entity(pos,'automobiles_catrelle:pivot_mesh')
passenger_seat:set_attach(self.object,'',{x=4.0,y=3,z=15},{x=0,y=0,z=0})
self.passenger_seat = passenger_seat
local fuel_gauge=minetest.add_entity(pos,'automobiles_catrelle:pointer')
fuel_gauge:set_attach(self.object,'',catrelle_GAUGE_FUEL_POSITION,{x=0,y=0,z=0})
self.fuel_gauge = fuel_gauge
local lights = minetest.add_entity(pos,'automobiles_catrelle:f_lights')
lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.lights = lights
self.lights:set_properties({is_visible=true})
local r_lights = minetest.add_entity(pos,'automobiles_catrelle:r_lights')
r_lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.r_lights = r_lights
self.r_lights:set_properties({is_visible=true})
local turn_l_light = minetest.add_entity(pos,'automobiles_catrelle:turn_left_light')
turn_l_light:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.turn_l_light = turn_l_light
self.turn_l_light:set_properties({is_visible=true})
local turn_r_light = minetest.add_entity(pos,'automobiles_catrelle:turn_right_light')
turn_r_light:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.turn_r_light = turn_r_light
self.turn_r_light:set_properties({is_visible=true})
self.object:set_armor_groups({immortal=1})
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, self._trunk_slots)
else
self.inv = inv
end
automobiles_lib.actfunc(self, staticdata, dtime_s)
end,
on_activate = automobiles_lib.on_activate,
on_step = function(self, dtime)
automobiles_lib.stepfunc(self, dtime)
@ -539,10 +436,10 @@ minetest.register_entity("automobiles_catrelle:catrelle", {
local angle_factor = self._steering_angle / 10
--whell turn
self.lf_wheel:set_attach(self.front_suspension,'',{x=-catrelle.front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=catrelle.front_wheel_xpos,y=0,z=0},{x=0,y=(-self._steering_angle+angle_factor)+180,z=0})
self.lr_wheel:set_attach(self.rear_suspension,'',{x=-catrelle.rear_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
self.rr_wheel:set_attach(self.rear_suspension,'',{x=catrelle.rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
self.lf_wheel:set_attach(self.front_suspension,'',{x=-self._front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=self._front_wheel_xpos,y=0,z=0},{x=0,y=(-self._steering_angle+angle_factor)+180,z=0})
self.lr_wheel:set_attach(self.rear_suspension,'',{x=-self._rear_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
self.rr_wheel:set_attach(self.rear_suspension,'',{x=self._rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
--check if the tyres is touching the pavement
local noded = automobiles_lib.nodeatpos(automobiles_lib.pos_shift(curr_pos,{y=-0.5}))
@ -638,7 +535,7 @@ minetest.register_entity("automobiles_catrelle:catrelle", {
end
local energy_indicator_angle = automobiles_lib.get_gauge_angle(self._energy)
self.fuel_gauge:set_attach(self.object,'',catrelle_GAUGE_FUEL_POSITION,{x=0,y=0,z=energy_indicator_angle})
self.fuel_gauge:set_attach(self.object,'',self._fuel_gauge_pos,{x=0,y=0,z=energy_indicator_angle})
----------------------------
-- end energy consumption --

View File

@ -9,16 +9,10 @@ catrelle.max_speed = 14
catrelle.max_acc_factor = 5
catrelle.ideal_step = 0.2
catrelle_GAUGE_FUEL_POSITION = {x=-4.47,y=8.50,z=20.5}
catrelle.front_wheel_xpos = 7.5
catrelle.rear_wheel_xpos = 7.5
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "custom_physics.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 .. "control.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 .. "crafts.lua")

View File

@ -305,143 +305,37 @@ minetest.register_entity("automobiles_coupe:coupe", {
_engine_sound = "coupe_engine",
_max_fuel = 10,
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,
stored_rag = self._show_rag,
stored_pitch = self._pitch,
stored_light_old_pos = self._light_old_pos,
stored_inv_id = self._inv_id,
})
end,
_vehicle_name = "Coupe",
_drive_wheel_pos = {x=-4.26,y=6.01,z=14.18},
_drive_wheel_angle = 15,
_steering_ent = 'automobiles_coupe:steering',
_seat_pos = {{x=-4.25,y=0.48,z=9.5},{x=4.25,y=0.48,z=9.5}},
_front_suspension_ent = 'automobiles_coupe:front_suspension',
_front_suspension_pos = {x=0,y=1.5,z=24.5},
_front_wheel_ent = 'automobiles_lib:wheel',
_front_wheel_xpos = 9.5,
_front_wheel_frames = {x = 1, y = 49},
_rear_suspension_ent = 'automobiles_coupe:rear_suspension',
_rear_suspension_pos = {x=0,y=1.5,z=0},
_rear_wheel_ent = 'automobiles_lib:wheel',
_rear_wheel_xpos = 9.5,
_rear_wheel_frames = {x = 1, y = 49},
_fuel_gauge_pos = {x=0,y=6.2,z=15.8},
_front_lights = 'automobiles_coupe:f_lights',
_rear_lights = 'automobiles_coupe:r_lights',
_reverse_lights = 'automobiles_coupe:reverse_lights',
_turn_left_lights = 'automobiles_coupe:turn_left_light',
_turn_right_lights = 'automobiles_coupe:turn_right_light',
get_staticdata = automobiles_lib.get_staticdata,
on_deactivate = function(self)
automobiles_lib.save_inventory(self)
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
self._show_rag = data.stored_rag
self._pitch = data.stored_pitch
self._light_old_pos = data.stored_light_old_pos
self._inv_id = data.stored_inv_id
automobiles_lib.setText(self, "Coupe")
end
self.object:set_animation({x = 1, y = 8}, 0, 0, true)
automobiles_lib.paint(self, self._color)
local pos = self.object:get_pos()
local front_suspension=minetest.add_entity(self.object:get_pos(),'automobiles_coupe:front_suspension')
front_suspension:set_attach(self.object,'',{x=0,y=1.5,z=24.5},{x=0,y=0,z=0})
self.front_suspension = front_suspension
local lf_wheel=minetest.add_entity(pos,'automobiles_lib:wheel')
lf_wheel:set_attach(self.front_suspension,'',{x=-coupe.front_wheel_xpos,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 = 1, y = 49}, 0, 0, true)
self.lf_wheel = lf_wheel
local rf_wheel=minetest.add_entity(pos,'automobiles_lib:wheel')
rf_wheel:set_attach(self.front_suspension,'',{x=coupe.front_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
-- set the animation once and later only change the speed
rf_wheel:set_animation({x = 1, y = 49}, 0, 0, true)
self.rf_wheel = rf_wheel
local rear_suspension=minetest.add_entity(self.object:get_pos(),'automobiles_coupe:rear_suspension')
rear_suspension:set_attach(self.object,'',{x=0,y=1.5,z=0},{x=0,y=0,z=0})
self.rear_suspension = rear_suspension
local lr_wheel=minetest.add_entity(pos,'automobiles_lib:wheel')
lr_wheel:set_attach(self.rear_suspension,'',{x=-coupe.rear_wheel_xpos,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 = 1, y = 49}, 0, 0, true)
self.lr_wheel = lr_wheel
local rr_wheel=minetest.add_entity(pos,'automobiles_lib:wheel')
rr_wheel:set_attach(self.rear_suspension,'',{x=coupe.rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
-- set the animation once and later only change the speed
rr_wheel:set_animation({x = 1, y = 49}, 0, 0, true)
self.rr_wheel = rr_wheel
local steering_axis=minetest.add_entity(pos,'automobiles_coupe:pivot_mesh')
steering_axis:set_attach(self.object,'',{x=-4.26,y=6.01,z=14.18},{x=15,y=0,z=0})
self.steering_axis = steering_axis
local steering=minetest.add_entity(self.steering_axis:get_pos(),'automobiles_coupe: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_coupe:pivot_mesh')
driver_seat:set_attach(self.object,'',{x=-4.25,y=0.48,z=9.5},{x=0,y=0,z=0})
self.driver_seat = driver_seat
local passenger_seat=minetest.add_entity(pos,'automobiles_coupe:pivot_mesh')
passenger_seat:set_attach(self.object,'',{x=4.25,y=0.48,z=9.5},{x=0,y=0,z=0})
self.passenger_seat = passenger_seat
local fuel_gauge=minetest.add_entity(pos,'automobiles_coupe:pointer')
fuel_gauge:set_attach(self.object,'',COUPE_GAUGE_FUEL_POSITION,{x=0,y=0,z=0})
self.fuel_gauge = fuel_gauge
local lights = minetest.add_entity(pos,'automobiles_coupe:f_lights')
lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.lights = lights
self.lights:set_properties({is_visible=true})
local r_lights = minetest.add_entity(pos,'automobiles_coupe:r_lights')
r_lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.r_lights = r_lights
self.r_lights:set_properties({is_visible=true})
local reverse_lights = minetest.add_entity(pos,'automobiles_coupe:reverse_lights')
reverse_lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.reverse_lights = reverse_lights
self.reverse_lights:set_properties({is_visible=true})
local turn_l_light = minetest.add_entity(pos,'automobiles_coupe:turn_left_light')
turn_l_light:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.turn_l_light = turn_l_light
self.turn_l_light:set_properties({is_visible=true})
local turn_r_light = minetest.add_entity(pos,'automobiles_coupe:turn_right_light')
turn_r_light:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.turn_r_light = turn_r_light
self.turn_r_light:set_properties({is_visible=true})
self.object:set_armor_groups({immortal=1})
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, self._trunk_slots)
else
self.inv = inv
end
automobiles_lib.actfunc(self, staticdata, dtime_s)
end,
on_activate = automobiles_lib.on_activate,
on_step = function(self, dtime)
automobiles_lib.stepfunc(self, dtime)
@ -590,8 +484,8 @@ minetest.register_entity("automobiles_coupe:coupe", {
--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=-coupe.front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=coupe.front_wheel_xpos,y=0,z=0},{x=0,y=(-self._steering_angle+angle_factor)+180,z=0})
self.lf_wheel:set_attach(self.front_suspension,'',{x=-self._front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=self._front_wheel_xpos,y=0,z=0},{x=0,y=(-self._steering_angle+angle_factor)+180,z=0})
if math.abs(self._steering_angle)>5 then
local turn_rate = math.rad(40)
@ -654,7 +548,7 @@ minetest.register_entity("automobiles_coupe:coupe", {
end
local energy_indicator_angle = automobiles_lib.get_gauge_angle(self._energy)
self.fuel_gauge:set_attach(self.object,'',COUPE_GAUGE_FUEL_POSITION,{x=0,y=0,z=energy_indicator_angle})
self.fuel_gauge:set_attach(self.object,'',self._fuel_gauge_pos,{x=0,y=0,z=energy_indicator_angle})
----------------------------
-- end energy consumption --

View File

@ -8,16 +8,10 @@ coupe.gravity = automobiles_lib.gravity
coupe.max_speed = 22
coupe.max_acc_factor = 8
COUPE_GAUGE_FUEL_POSITION = {x=0,y=6.2,z=15.8}
coupe.front_wheel_xpos = 9.5
coupe.rear_wheel_xpos = 9.5
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_lib") .. DIR_DELIM .. "entities.lua")
dofile(minetest.get_modpath("automobiles_coupe") .. DIR_DELIM .. "coupe_entities.lua")
dofile(minetest.get_modpath("automobiles_coupe") .. DIR_DELIM .. "coupe_crafts.lua")

View File

@ -29,7 +29,7 @@ minetest.register_craftitem("automobiles_delorean:delorean", {
local owner = placer:get_player_name()
if ent then
ent.owner = owner
ent._delorean_type = 0
ent._car_type = 0
--minetest.chat_send_all("owner: " .. ent.owner)
car:set_yaw(placer:get_look_horizontal())
itemstack:take_item()
@ -62,8 +62,8 @@ minetest.register_craftitem("automobiles_delorean:time_machine", {
local owner = placer:get_player_name()
if ent then
ent.owner = owner
ent._delorean_type = 1
--minetest.chat_send_all("delorean: " .. ent._delorean_type)
ent._car_type = 1
--minetest.chat_send_all("delorean: " .. ent._car_type)
--minetest.chat_send_all("owner: " .. ent.owner)
car:set_yaw(placer:get_look_horizontal())
itemstack:take_item()

View File

@ -420,7 +420,7 @@ minetest.register_entity("automobiles_delorean:delorean", {
_inv_id = "",
_change_color = automobiles_lib.paint,
_intensity = 4,
_delorean_type = 0,
_car_type = 0,
_car_gravity = -automobiles_lib.gravity,
_is_flying = 0,
_trunk_slots = 8,
@ -429,146 +429,37 @@ minetest.register_entity("automobiles_delorean:delorean", {
_formspec_function = delorean.driver_formspec,
_destroy_function = delorean.destroy,
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,
stored_rag = self._show_rag,
stored_pitch = self._pitch,
stored_light_old_pos = self._light_old_pos,
stored_inv_id = self._inv_id,
stored_delorean_type = self._delorean_type,
stored_car_gravity = self._car_gravity,
})
end,
_vehicle_name = "Delorean",
_drive_wheel_pos = {x=-4.66, y=6.31, z=15.69},
_drive_wheel_angle = 15,
_seat_pos = {{x=-4.65,y=0.48,z=9.5},{x=4.65,y=0.48,z=9.5}},
_front_suspension_ent = 'automobiles_delorean:front_suspension',
_front_suspension_pos = {x=0,y=1.5,z=27.7057},
_front_wheel_ent = 'automobiles_delorean:wheel',
_front_wheel_xpos = 9.5,
_front_wheel_frames = {x = 1, y = 49},
_rear_suspension_ent = 'automobiles_delorean:rear_suspension',
_rear_suspension_pos = {x=0,y=1.5,z=0},
_rear_wheel_ent = 'automobiles_delorean:wheel',
_rear_wheel_xpos = 9.5,
_rear_wheel_frames = {x = 1, y = 49},
_fuel_gauge_pos = {x=-4.66,y=6.2,z=17.9},
_front_lights = 'automobiles_delorean:f_lights',
_rear_lights = 'automobiles_delorean:r_lights',
_reverse_lights = 'automobiles_delorean:reverse_lights',
_turn_left_lights = 'automobiles_delorean:turn_left_light',
_turn_right_lights = 'automobiles_delorean:turn_right_light',
_extra_items_function = delorean.set_kit, --uses _car_type do change "skin"
get_staticdata = automobiles_lib.get_staticdata,
on_deactivate = function(self)
automobiles_lib.save_inventory(self)
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
self._show_rag = data.stored_rag
self._pitch = data.stored_pitch
self._light_old_pos = data.stored_light_old_pos
self._inv_id = data.stored_inv_id
self._delorean_type = data.stored_delorean_type
self._car_gravity = data.stored_car_gravity or -automobiles_lib.gravity
automobiles_lib.setText(self, "Delorean")
end
self.object:set_animation({x = 1, y = 8}, 0, 0, true)
automobiles_lib.paint(self, self._color)
local pos = self.object:get_pos()
local front_suspension=minetest.add_entity(self.object:get_pos(),'automobiles_delorean:front_suspension')
front_suspension:set_attach(self.object,'',{x=0,y=1.5,z=27.7057},{x=0,y=0,z=0})
self.front_suspension = front_suspension
local lf_wheel=minetest.add_entity(pos,'automobiles_delorean:wheel')
lf_wheel:set_attach(self.front_suspension,'',{x=-delorean.front_wheel_xpos,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 = 1, y = 49}, 0, 0, true)
self.lf_wheel = lf_wheel
local rf_wheel=minetest.add_entity(pos,'automobiles_delorean:wheel')
rf_wheel:set_attach(self.front_suspension,'',{x=delorean.front_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
-- set the animation once and later only change the speed
rf_wheel:set_animation({x = 1, y = 49}, 0, 0, true)
self.rf_wheel = rf_wheel
local rear_suspension=minetest.add_entity(self.object:get_pos(),'automobiles_delorean:rear_suspension')
rear_suspension:set_attach(self.object,'',{x=0,y=1.5,z=0},{x=0,y=0,z=0})
self.rear_suspension = rear_suspension
local lr_wheel=minetest.add_entity(pos,'automobiles_delorean:wheel')
lr_wheel:set_attach(self.rear_suspension,'',{x=-delorean.rear_wheel_xpos,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 = 1, y = 49}, 0, 0, true)
self.lr_wheel = lr_wheel
local rr_wheel=minetest.add_entity(pos,'automobiles_delorean:wheel')
rr_wheel:set_attach(self.rear_suspension,'',{x=delorean.rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
-- set the animation once and later only change the speed
rr_wheel:set_animation({x = 1, y = 49}, 0, 0, true)
self.rr_wheel = rr_wheel
self.object:set_bone_position("drive_adjust", {x=-4.66, y=6.31, z=15.69}, {x=15, y=0, z=0})
local driver_seat=minetest.add_entity(pos,'automobiles_delorean:pivot_mesh')
driver_seat:set_attach(self.object,'',{x=-4.65,y=0.48,z=9.5},{x=0,y=0,z=0})
self.driver_seat = driver_seat
local passenger_seat=minetest.add_entity(pos,'automobiles_delorean:pivot_mesh')
passenger_seat:set_attach(self.object,'',{x=4.65,y=0.48,z=9.5},{x=0,y=0,z=0})
self.passenger_seat = passenger_seat
local fuel_gauge=minetest.add_entity(pos,'automobiles_delorean:pointer')
fuel_gauge:set_attach(self.object,'',DELOREAN_GAUGE_FUEL_POSITION,{x=0,y=0,z=0})
self.fuel_gauge = fuel_gauge
local lights = minetest.add_entity(pos,'automobiles_delorean:f_lights')
lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.lights = lights
self.lights:set_properties({is_visible=true})
--normal or time machine?
delorean.set_kit(self)
local r_lights = minetest.add_entity(pos,'automobiles_delorean:r_lights')
r_lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.r_lights = r_lights
self.r_lights:set_properties({is_visible=true})
local reverse_lights = minetest.add_entity(pos,'automobiles_delorean:reverse_lights')
reverse_lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.reverse_lights = reverse_lights
self.reverse_lights:set_properties({is_visible=true})
local turn_l_light = minetest.add_entity(pos,'automobiles_delorean:turn_left_light')
turn_l_light:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.turn_l_light = turn_l_light
self.turn_l_light:set_properties({is_visible=true})
local turn_r_light = minetest.add_entity(pos,'automobiles_delorean:turn_right_light')
turn_r_light:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.turn_r_light = turn_r_light
self.turn_r_light:set_properties({is_visible=true})
self.object:set_armor_groups({immortal=1})
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, self._trunk_slots)
else
self.inv = inv
end
automobiles_lib.actfunc(self, staticdata, dtime_s)
end,
on_activate = automobiles_lib.on_activate,
on_step = function(self, dtime)
automobiles_lib.stepfunc(self, dtime)
@ -802,7 +693,7 @@ minetest.register_entity("automobiles_delorean:delorean", {
end
local energy_indicator_angle = automobiles_lib.get_gauge_angle(self._energy)
self.fuel_gauge:set_attach(self.object,'',DELOREAN_GAUGE_FUEL_POSITION,{x=0,y=0,z=energy_indicator_angle})
self.fuel_gauge:set_attach(self.object,'',self._fuel_gauge_pos,{x=0,y=0,z=energy_indicator_angle})
----------------------------
-- end energy consumption --

View File

@ -2,12 +2,12 @@ function delorean.set_kit(self)
local normal_kit = nil
if self.normal_kit then self.normal_kit:remove() end
local pos = self.object:get_pos()
if self._delorean_type == 0 or self._delorean_type == nil then
if self._car_type == 0 or self._car_type == nil then
normal_kit = minetest.add_entity(pos,'automobiles_delorean:normal_kit')
normal_kit:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.normal_kit = normal_kit
self.normal_kit:set_properties({is_visible=true})
elseif self._delorean_type == 1 then
elseif self._car_type == 1 then
--time machine
normal_kit = minetest.add_entity(pos,'automobiles_delorean:time_machine_kit')
normal_kit:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
@ -71,16 +71,16 @@ end
function delorean.set_wheels_mode(self, angle_factor)
if not self._is_flying or self._is_flying == 0 then
--whell turn
self.lf_wheel:set_attach(self.front_suspension,'',{x=-delorean.front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=delorean.front_wheel_xpos,y=0,z=0},{x=0,y=(-self._steering_angle+angle_factor)+180,z=0})
self.lr_wheel:set_attach(self.rear_suspension,'',{x=-delorean.rear_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
self.rr_wheel:set_attach(self.rear_suspension,'',{x=delorean.rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
self.lf_wheel:set_attach(self.front_suspension,'',{x=-self._front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=self._front_wheel_xpos,y=0,z=0},{x=0,y=(-self._steering_angle+angle_factor)+180,z=0})
self.lr_wheel:set_attach(self.rear_suspension,'',{x=-self._rear_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
self.rr_wheel:set_attach(self.rear_suspension,'',{x=self._rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
else
local extra_space = 0.5
self.lf_wheel:set_attach(self.front_suspension,'',{x=-delorean.front_wheel_xpos-extra_space,y=0,z=0},{x=0,y=0,z=90})
self.rf_wheel:set_attach(self.front_suspension,'',{x=delorean.front_wheel_xpos+extra_space,y=0,z=0},{x=0,y=180,z=-90})
self.lr_wheel:set_attach(self.rear_suspension,'',{x=-delorean.rear_wheel_xpos-extra_space,y=0,z=0},{x=0,y=0,z=90})
self.rr_wheel:set_attach(self.rear_suspension,'',{x=delorean.rear_wheel_xpos+extra_space,y=0,z=0},{x=0,y=180,z=-90})
self.lf_wheel:set_attach(self.front_suspension,'',{x=-self._front_wheel_xpos-extra_space,y=0,z=0},{x=0,y=0,z=90})
self.rf_wheel:set_attach(self.front_suspension,'',{x=self._front_wheel_xpos+extra_space,y=0,z=0},{x=0,y=180,z=-90})
self.lr_wheel:set_attach(self.rear_suspension,'',{x=-self._rear_wheel_xpos-extra_space,y=0,z=0},{x=0,y=0,z=90})
self.rr_wheel:set_attach(self.rear_suspension,'',{x=self._rear_wheel_xpos+extra_space,y=0,z=0},{x=0,y=180,z=-90})
end
end
@ -95,7 +95,7 @@ function delorean.turn_flight_mode(self)
end
function delorean.set_mode(self, is_attached, curr_pos, velocity, player, dtime)
if self._delorean_type == 1 then
if self._car_type == 1 then
local ent_propertioes = self.normal_kit:get_properties()
if ent_propertioes.mesh ~= "automobiles_delorean_time_machine_accessories.b3d" then
delorean.set_kit(self)

View File

@ -33,7 +33,7 @@ function delorean.driver_formspec(name)
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._delorean_type == 1 then basic_form = basic_form.."checkbox[1,4.0;flight;Flight Mode;"..flight.."]" end
if ent._car_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, "delorean:driver_main", basic_form)

View File

@ -9,11 +9,6 @@ delorean.max_speed = 30
delorean.max_acc_factor = 8
delorean.ideal_step = 0.2
DELOREAN_GAUGE_FUEL_POSITION = {x=-4.66,y=6.2,z=17.9}
delorean.front_wheel_xpos = 9.5
delorean.rear_wheel_xpos = 9.5
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "custom_physics.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,3 +1,46 @@
minetest.register_entity('automobiles_lib: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_lib:pointer',{
initial_properties = {
physical = false,
collide_with_objects=false,
pointable=false,
visual = "mesh",
mesh = "automobiles_pointer.b3d",
visual_size = {x = 0.5, y = 0.5, z = 0.5},
textures = {"automobiles_white.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,
})
function automobiles_lib.on_rightclick (self, clicker)
if not clicker or not clicker:is_player() then
@ -132,5 +175,181 @@ function automobiles_lib.on_punch (self, puncher, ttime, toolcaps, dir, damage)
end
end
end
function automobiles_lib.get_staticdata(self)
return minetest.serialize({
stored_owner = self.owner,
stored_hp = self.hp,
stored_color = self._color,
stored_det_color = self._det_color,
stored_steering = self._steering_angle,
stored_energy = self._energy,
stored_rag = self._show_rag,
stored_pitch = self._pitch,
stored_light_old_pos = self._light_old_pos,
stored_inv_id = self._inv_id,
stored_car_type = self._car_type,
stored_car_gravity = self._car_gravity,
--race data
stored_last_checkpoint = self._last_checkpoint,
stored_total_laps = self._total_laps,
stored_race_id = self._race_id,
})
end
function automobiles_lib.on_activate(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._det_color = data.stored_det_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
self._show_rag = data.stored_rag
self._pitch = data.stored_pitch
self._light_old_pos = data.stored_light_old_pos
self._inv_id = data.stored_inv_id
self._car_type = data.stored_car_type
self._car_gravity = data.stored_car_gravity or -automobiles_lib.gravity
automobiles_lib.setText(self, self._vehicle_name)
end
if self._painting_load then
self._painting_load(self, self._color)
else
automobiles_lib.paint(self, self._color)
end
local pos = self.object:get_pos()
local front_suspension=minetest.add_entity(self.object:get_pos(),self._front_suspension_ent)
front_suspension:set_attach(self.object,'',self._front_suspension_pos,{x=0,y=0,z=0})
self.front_suspension = front_suspension
local lf_wheel=minetest.add_entity(pos,self._front_wheel_ent)
lf_wheel:set_attach(self.front_suspension,'',{x=-self._front_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
-- set the animation once and later only change the speed
lf_wheel:set_animation(self._front_wheel_frames, 0, 0, true)
self.lf_wheel = lf_wheel
local rf_wheel=minetest.add_entity(pos,self._front_wheel_ent)
rf_wheel:set_attach(self.front_suspension,'',{x=self._front_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
-- set the animation once and later only change the speed
rf_wheel:set_animation(self._front_wheel_frames, 0, 0, true)
self.rf_wheel = rf_wheel
local rear_suspension=minetest.add_entity(self.object:get_pos(),self._rear_suspension_ent)
rear_suspension:set_attach(self.object,'',self._rear_suspension_pos,{x=0,y=0,z=0})
self.rear_suspension = rear_suspension
local lr_wheel=minetest.add_entity(pos,self._rear_wheel_ent)
lr_wheel:set_attach(self.rear_suspension,'',{x=-self._rear_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
-- set the animation once and later only change the speed
lr_wheel:set_animation(self._rear_wheel_frames, 0, 0, true)
self.lr_wheel = lr_wheel
local rr_wheel=minetest.add_entity(pos,self._rear_wheel_ent)
rr_wheel:set_attach(self.rear_suspension,'',{x=self._rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
-- set the animation once and later only change the speed
rr_wheel:set_animation(self._rear_wheel_frames, 0, 0, true)
self.rr_wheel = rr_wheel
if self._steering_ent then
local steering_axis=minetest.add_entity(pos,'automobiles_lib:pivot_mesh')
steering_axis:set_attach(self.object,'',self._drive_wheel_pos,{x=self._drive_wheel_angle,y=0,z=0})
self.steering_axis = steering_axis
local steering=minetest.add_entity(self.steering_axis:get_pos(), self._steering_ent)
steering:set_attach(self.steering_axis,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.steering = steering
else
self.object:set_bone_position("drive_adjust", self._drive_wheel_pos, {x=self._drive_wheel_angle, y=0, z=0})
end
if self._rag_retracted_ent then
local rag_rect=minetest.add_entity(self.object:get_pos(),self._rag_retracted_ent)
rag_rect:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.rag_rect = rag_rect
self.rag_rect:set_properties({is_visible=false})
end
if self._rag_extended_ent then
local rag=minetest.add_entity(self.object:get_pos(),self._rag_extended_ent)
rag:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.rag = rag
end
local driver_seat=minetest.add_entity(pos,'automobiles_lib:pivot_mesh')
driver_seat:set_attach(self.object,'',self._seat_pos[1],{x=0,y=0,z=0})
self.driver_seat = driver_seat
local passenger_seat=minetest.add_entity(pos,'automobiles_lib:pivot_mesh')
passenger_seat:set_attach(self.object,'',self._seat_pos[2],{x=0,y=0,z=0})
self.passenger_seat = passenger_seat
local pointer_entity = 'automobiles_lib:pointer'
if self._gauge_pointer_ent then pointer_entity = self._gauge_pointer_ent end
local fuel_gauge=minetest.add_entity(pos, pointer_entity)
fuel_gauge:set_attach(self.object,'',self._fuel_gauge_pos,{x=0,y=0,z=0})
self.fuel_gauge = fuel_gauge
if self._front_lights then
local lights = minetest.add_entity(pos,self._front_lights)
lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.lights = lights
self.lights:set_properties({is_visible=true})
end
if self._rear_lights then
local r_lights = minetest.add_entity(pos,self._rear_lights)
r_lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.r_lights = r_lights
self.r_lights:set_properties({is_visible=true})
end
if self._reverse_lights then
local reverse_lights = minetest.add_entity(pos,self._reverse_lights)
reverse_lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.reverse_lights = reverse_lights
self.reverse_lights:set_properties({is_visible=true})
end
if self._turn_left_lights then
local turn_l_light = minetest.add_entity(pos,self._turn_left_lights)
turn_l_light:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.turn_l_light = turn_l_light
self.turn_l_light:set_properties({is_visible=true})
end
if self._turn_right_lights then
local turn_r_light = minetest.add_entity(pos,self._turn_right_lights)
turn_r_light:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.turn_r_light = turn_r_light
self.turn_r_light:set_properties({is_visible=true})
end
if self._extra_items_function then
self._extra_items_function(self)
end
self.object:set_armor_groups({immortal=1})
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, self._trunk_slots)
else
self.inv = inv
end
automobiles_lib.actfunc(self, staticdata, dtime_s)
end

View File

@ -15,7 +15,6 @@ 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_motorcycle") .. DIR_DELIM .. "motorcycle_forms.lua")
dofile(minetest.get_modpath("automobiles_motorcycle") .. DIR_DELIM .. "motorcycle_player.lua")
dofile(minetest.get_modpath("automobiles_motorcycle") .. DIR_DELIM .. "motorcycle_utilities.lua")

View File

@ -8,11 +8,6 @@ roadster.gravity = automobiles_lib.gravity
roadster.max_speed = 12
roadster.max_acc_factor = 5
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_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")

View File

@ -283,131 +283,36 @@ minetest.register_entity("automobiles_roadster:roadster", {
_formspec_function = roadster.driver_formspec,
_destroy_function = roadster.destroy,
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,
stored_rag = self._show_rag,
stored_pitch = self._pitch,
stored_light_old_pos = self._light_old_pos,
stored_inv_id = self._inv_id,
})
end,
_vehicle_name = "Roadster",
_drive_wheel_pos = {x=-4.25,y=12,z=14},
_drive_wheel_angle = 70,
_steering_ent = 'automobiles_roadster:steering',
_rag_extended_ent = 'automobiles_roadster:top1',
_rag_retracted_ent = 'automobiles_roadster:top2',
_seat_pos = {{x=-4.25,y=7.12,z=9.5},{x=4.25,y=7.12,z=9.5}},
_front_suspension_ent = 'automobiles_roadster:front_suspension',
_front_suspension_pos = {x=0,y=0,z=24.22},
_front_wheel_ent = 'automobiles_roadster:wheel',
_front_wheel_xpos = 10.26,
_front_wheel_frames = {x = 2, y = 13},
_rear_suspension_ent = 'automobiles_trans_am:rear_suspension',
_rear_suspension_pos = {x=0,y=0,z=0},
_rear_wheel_ent = 'automobiles_roadster:wheel',
_rear_wheel_xpos = 10.26,
_rear_wheel_frames = {x = 2, y = 13},
_fuel_gauge_pos = {x=0,y=8.04,z=17.84},
_gauge_pointer_ent = 'automobiles_roadster:pointer',
_front_lights = 'automobiles_roadster:lights',
get_staticdata = automobiles_lib.get_staticdata,
on_deactivate = function(self)
automobiles_lib.save_inventory(self)
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
self._show_rag = data.stored_rag
self._pitch = data.stored_pitch
self._light_old_pos = data.stored_light_old_pos
self._inv_id = data.stored_inv_id
automobiles_lib.setText(self, "Roadster")
end
self.object:set_animation({x = 1, y = 8}, 0, 0, true)
automobiles_lib.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 top2=minetest.add_entity(self.object:get_pos(),'automobiles_roadster:top2')
top2:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.top2 = top2
self.top2:set_properties({is_visible=false})
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=24.22},{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=-roadster.front_wheel_xpos,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=roadster.front_wheel_xpos,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=-roadster.rear_wheel_xpos,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=roadster.rear_wheel_xpos,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=14},{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.12,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.12,z=9.5},{x=0,y=0,z=0})
self.passenger_seat = passenger_seat
local fuel_gauge=minetest.add_entity(pos,'automobiles_roadster:pointer')
fuel_gauge:set_attach(self.object,'',ROADSTER_GAUGE_FUEL_POSITION,{x=0,y=0,z=0})
self.fuel_gauge = fuel_gauge
local lights = minetest.add_entity(pos,'automobiles_roadster:lights')
lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.lights = lights
self.lights:set_properties({is_visible=false})
self.object:set_armor_groups({immortal=1})
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, self._trunk_slots)
else
self.inv = inv
end
automobiles_lib.actfunc(self, staticdata, dtime_s)
end,
on_activate = automobiles_lib.on_activate,
on_step = function(self, dtime)
automobiles_lib.stepfunc(self, dtime)
@ -441,12 +346,12 @@ minetest.register_entity("automobiles_roadster:roadster", {
if self._show_rag == true then
self.object:set_bone_position("windshield", {x=0, z=15.8317, y=15.0394}, {x=145, y=0, z=0})
self.top2:set_properties({is_visible=true})
self.top1:set_properties({is_visible=false})
self.rag_rect:set_properties({is_visible=true})
self.rag:set_properties({is_visible=false})
else
self.object:set_bone_position("windshield", {x=0, z=15.8317, y=15.0394}, {x=0, y=0, z=0})
self.top2:set_properties({is_visible=false})
self.top1:set_properties({is_visible=true})
self.rag_rect:set_properties({is_visible=false})
self.rag:set_properties({is_visible=true})
end
local player = nil
@ -548,8 +453,8 @@ minetest.register_entity("automobiles_roadster:roadster", {
--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=roadster.front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=-roadster.front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle+angle_factor,z=0})
self.lf_wheel:set_attach(self.front_suspension,'',{x=self._front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=-self._front_wheel_xpos,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)
@ -592,7 +497,7 @@ minetest.register_entity("automobiles_roadster:roadster", {
end
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})
self.fuel_gauge:set_attach(self.object,'',self._fuel_gauge_pos,{x=0,y=0,z=energy_indicator_angle})
----------------------------
-- end energy consumption --

View File

@ -189,51 +189,7 @@ initial_properties = {
})
minetest.register_entity('automobiles_trans_am: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_trans_am:pointer',{
initial_properties = {
physical = false,
collide_with_objects=false,
pointable=false,
visual = "mesh",
mesh = "automobiles_pointer.b3d",
visual_size = {x = 0.5, y = 0.5, z = 0.5},
textures = {"automobiles_white.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,
})
local function paint(self, colstr)
function trans_am.paint(self, colstr)
automobiles_lib.paint_with_mask(self, colstr, self._det_color, "automobiles_trans_am_painting.png", "automobiles_trans_am_marks.png")
local l_textures = self.initial_properties.textures
@ -243,11 +199,11 @@ local function paint(self, colstr)
for _, texture in ipairs(l_textures) do
local indx = texture:find(target_texture)
if indx then
l_textures[_] = target_texture.."^[multiply:".. self._det_color
l_textures[_] = target_texture.."^[multiply:".. self._det_color --apply the deatil color color
end
local indx = texture:find(accessorie_texture)
if indx then
l_textures[_] = accessorie_texture.."^[multiply:".. colstr
l_textures[_] = accessorie_texture.."^[multiply:".. colstr --here changes the main color
end
end
self.object:set_properties({textures=l_textures})
@ -268,7 +224,7 @@ function trans_am.set_paint(self, puncher, itmstck)
local meta = itmstck:get_meta()
local colstr = meta:get_string("paint_color")
self._det_color = colstr
paint(self, self._color)
trans_am.paint(self, self._color)
return true
else
--painting with dyes
@ -286,7 +242,7 @@ function trans_am.set_paint(self, puncher, itmstck)
--minetest.chat_send_all(color ..' '.. dump(colstr))
if colstr then
self._det_color = colstr
paint(self, self._color)
trans_am.paint(self, self._color)
itmstck:set_count(itmstck:get_count()-1)
puncher:set_wielded_item(itmstck)
return true
@ -366,7 +322,7 @@ minetest.register_entity("automobiles_trans_am:trans_am", {
_turn_light_timer = 0,
_inv = nil,
_inv_id = "",
_change_color = paint,
_change_color = trans_am.paint,
_intensity = 4,
_car_gravity = -automobiles_lib.gravity,
--acc control
@ -376,144 +332,37 @@ minetest.register_entity("automobiles_trans_am:trans_am", {
_engine_sound = "trans_am_engine",
_max_fuel = 10,
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_det_color = self._det_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,
stored_rag = self._show_rag,
stored_pitch = self._pitch,
stored_light_old_pos = self._light_old_pos,
stored_inv_id = self._inv_id,
stored_trans_am_type = self._trans_am_type,
stored_car_gravity = self._car_gravity,
})
end,
_vehicle_name = "Trans Am",
_painting_load = trans_am.paint,
_drive_wheel_pos = {x=-4.0, y=6.50, z=15.06},
_drive_wheel_angle = 15,
_seat_pos = {{x=-4.0,y=0.8,z=9},{x=4.0,y=0.8,z=9}},
_front_suspension_ent = 'automobiles_trans_am:front_suspension',
_front_suspension_pos = {x=0,y=1.5,z=27.0},
_front_wheel_ent = 'automobiles_trans_am:wheel',
_front_wheel_xpos = 9.5,
_front_wheel_frames = {x = 1, y = 49},
_rear_suspension_ent = 'automobiles_trans_am:rear_suspension',
_rear_suspension_pos = {x=0,y=1.5,z=0},
_rear_wheel_ent = 'automobiles_trans_am:wheel',
_rear_wheel_xpos = 9.5,
_rear_wheel_frames = {x = 1, y = 49},
_fuel_gauge_pos = {x=-4,y=6.8,z=16.6},
_front_lights = 'automobiles_trans_am:f_lights',
_rear_lights = 'automobiles_trans_am:r_lights',
_reverse_lights = 'automobiles_trans_am:reverse_lights',
_turn_left_lights = 'automobiles_trans_am:turn_left_light',
_turn_right_lights = 'automobiles_trans_am:turn_right_light',
get_staticdata = automobiles_lib.get_staticdata,
on_deactivate = function(self)
automobiles_lib.save_inventory(self)
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._det_color = data.stored_det_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
self._show_rag = data.stored_rag
self._pitch = data.stored_pitch
self._light_old_pos = data.stored_light_old_pos
self._inv_id = data.stored_inv_id
self._trans_am_type = data.stored_trans_am_type
self._car_gravity = data.stored_car_gravity or -automobiles_lib.gravity
automobiles_lib.setText(self, "Trans Am")
end
self.object:set_animation({x = 1, y = 8}, 0, 0, true)
paint(self, self._color)
local pos = self.object:get_pos()
local front_suspension=minetest.add_entity(self.object:get_pos(),'automobiles_trans_am:front_suspension')
front_suspension:set_attach(self.object,'',{x=0,y=1.5,z=27.0},{x=0,y=0,z=0})
self.front_suspension = front_suspension
local lf_wheel=minetest.add_entity(pos,'automobiles_trans_am:wheel')
lf_wheel:set_attach(self.front_suspension,'',{x=-trans_am.front_wheel_xpos,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 = 1, y = 49}, 0, 0, true)
self.lf_wheel = lf_wheel
local rf_wheel=minetest.add_entity(pos,'automobiles_trans_am:wheel')
rf_wheel:set_attach(self.front_suspension,'',{x=trans_am.front_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
-- set the animation once and later only change the speed
rf_wheel:set_animation({x = 1, y = 49}, 0, 0, true)
self.rf_wheel = rf_wheel
local rear_suspension=minetest.add_entity(self.object:get_pos(),'automobiles_trans_am:rear_suspension')
rear_suspension:set_attach(self.object,'',{x=0,y=1.5,z=0},{x=0,y=0,z=0})
self.rear_suspension = rear_suspension
local lr_wheel=minetest.add_entity(pos,'automobiles_trans_am:wheel')
lr_wheel:set_attach(self.rear_suspension,'',{x=-trans_am.rear_wheel_xpos,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 = 1, y = 49}, 0, 0, true)
self.lr_wheel = lr_wheel
local rr_wheel=minetest.add_entity(pos,'automobiles_trans_am:wheel')
rr_wheel:set_attach(self.rear_suspension,'',{x=trans_am.rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
-- set the animation once and later only change the speed
rr_wheel:set_animation({x = 1, y = 49}, 0, 0, true)
self.rr_wheel = rr_wheel
self.object:set_bone_position("drive_adjust", {x=-4.0, y=6.50, z=15.06}, {x=15, y=0, z=0})
local driver_seat=minetest.add_entity(pos,'automobiles_trans_am:pivot_mesh')
driver_seat:set_attach(self.object,'',{x=-4.0,y=0.8,z=9},{x=0,y=0,z=0})
self.driver_seat = driver_seat
local passenger_seat=minetest.add_entity(pos,'automobiles_trans_am:pivot_mesh')
passenger_seat:set_attach(self.object,'',{x=4.0,y=0.8,z=9},{x=0,y=0,z=0})
self.passenger_seat = passenger_seat
local fuel_gauge=minetest.add_entity(pos,'automobiles_trans_am:pointer')
fuel_gauge:set_attach(self.object,'',trans_am_GAUGE_FUEL_POSITION,{x=0,y=0,z=0})
self.fuel_gauge = fuel_gauge
local lights = minetest.add_entity(pos,'automobiles_trans_am:f_lights')
lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.lights = lights
self.lights:set_properties({is_visible=true})
local r_lights = minetest.add_entity(pos,'automobiles_trans_am:r_lights')
r_lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.r_lights = r_lights
self.r_lights:set_properties({is_visible=true})
local reverse_lights = minetest.add_entity(pos,'automobiles_trans_am:reverse_lights')
reverse_lights:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.reverse_lights = reverse_lights
self.reverse_lights:set_properties({is_visible=true})
local turn_l_light = minetest.add_entity(pos,'automobiles_trans_am:turn_left_light')
turn_l_light:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.turn_l_light = turn_l_light
self.turn_l_light:set_properties({is_visible=true})
local turn_r_light = minetest.add_entity(pos,'automobiles_trans_am:turn_right_light')
turn_r_light:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
self.turn_r_light = turn_r_light
self.turn_r_light:set_properties({is_visible=true})
self.object:set_armor_groups({immortal=1})
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, self._trunk_slots)
else
self.inv = inv
end
automobiles_lib.actfunc(self, staticdata, dtime_s)
end,
on_activate = automobiles_lib.on_activate,
on_step = function(self, dtime)
automobiles_lib.stepfunc(self, dtime)
@ -663,10 +512,10 @@ minetest.register_entity("automobiles_trans_am:trans_am", {
--whell turn
if self.lf_wheel and self.rf_wheel and self.lr_wheel and self.rr_wheel then
self.lf_wheel:set_attach(self.front_suspension,'',{x=-trans_am.front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=trans_am.front_wheel_xpos,y=0,z=0},{x=0,y=(-self._steering_angle+angle_factor)+180,z=0})
self.lr_wheel:set_attach(self.rear_suspension,'',{x=-trans_am.rear_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
self.rr_wheel:set_attach(self.rear_suspension,'',{x=trans_am.rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
self.lf_wheel:set_attach(self.front_suspension,'',{x=-self._front_wheel_xpos,y=0,z=0},{x=0,y=-self._steering_angle-angle_factor,z=0})
self.rf_wheel:set_attach(self.front_suspension,'',{x=self._front_wheel_xpos,y=0,z=0},{x=0,y=(-self._steering_angle+angle_factor)+180,z=0})
self.lr_wheel:set_attach(self.rear_suspension,'',{x=-self._rear_wheel_xpos,y=0,z=0},{x=0,y=0,z=0})
self.rr_wheel:set_attach(self.rear_suspension,'',{x=self._rear_wheel_xpos,y=0,z=0},{x=0,y=180,z=0})
end
--check if the tyres is touching the pavement
@ -768,7 +617,7 @@ minetest.register_entity("automobiles_trans_am:trans_am", {
local energy_indicator_angle = automobiles_lib.get_gauge_angle(self._energy)
if self.fuel_gauge then
self.fuel_gauge:set_attach(self.object,'',trans_am_GAUGE_FUEL_POSITION,{x=0,y=0,z=energy_indicator_angle})
self.fuel_gauge:set_attach(self.object,'',self._fuel_gauge_pos,{x=0,y=0,z=energy_indicator_angle})
end
----------------------------
-- end energy consumption --

View File

@ -9,16 +9,10 @@ trans_am.max_speed = 40
trans_am.max_acc_factor = 12
trans_am.ideal_step = 0.2
trans_am_GAUGE_FUEL_POSITION = {x=-4,y=6.8,z=16.6}
trans_am.front_wheel_xpos = 9.5
trans_am.rear_wheel_xpos = 9.5
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "custom_physics.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 .. "control.lua")
dofile(minetest.get_modpath("automobiles_lib") .. DIR_DELIM .. "entities.lua")
dofile(minetest.get_modpath("automobiles_trans_am") .. DIR_DELIM .. "entities.lua")
dofile(minetest.get_modpath("automobiles_trans_am") .. DIR_DELIM .. "crafts.lua")

View File

@ -15,7 +15,6 @@ 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_vespa") .. DIR_DELIM .. "vespa_forms.lua")
dofile(minetest.get_modpath("automobiles_vespa") .. DIR_DELIM .. "vespa_player.lua")
dofile(minetest.get_modpath("automobiles_vespa") .. DIR_DELIM .. "vespa_utilities.lua")