mirror of
https://github.com/APercy/automobiles_pck
synced 2025-09-01 09:36:24 +02:00
added fuel indicator
This commit is contained in:
parent
3bb0ef9c49
commit
005bb306e2
@ -34,20 +34,8 @@ function automobiles.control(self, dtime, hull_direction, longit_speed, longit_d
|
||||
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 < roadster.max_speed and ctrl.up then
|
||||
if self._energy > 0 then
|
||||
if longit_speed < roadster.max_speed and ctrl.up then
|
||||
--get acceleration factor
|
||||
acc = automobiles.check_road_is_ok(self.object, max_acc_factor)
|
||||
--minetest.chat_send_all('engineacc: '.. engineacc)
|
||||
@ -55,14 +43,15 @@ function automobiles.control(self, dtime, hull_direction, longit_speed, longit_d
|
||||
--improper road will reduce speed
|
||||
acc = -1
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--reversing
|
||||
if ctrl.sneak and longit_speed <= 1.0 and longit_speed > -1.0 then
|
||||
acc = -1
|
||||
end
|
||||
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
|
||||
|
@ -39,3 +39,4 @@ function automobiles.loadFuel(self, player_name, free, max_fuel)
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
|
@ -19,12 +19,14 @@ function automobiles.ground_get_distances(self, radius, axis_distance)
|
||||
local rear_axis = {x=r_x, y=r_y, z=r_z}
|
||||
|
||||
local rear_obstacle_level = automobiles.get_obstacle(rear_axis)
|
||||
--minetest.chat_send_all("rear"..dump(rear_obstacle_level))
|
||||
|
||||
local f_x, f_z = automobiles.get_xz_from_hipotenuse(pos.x, pos.z, yaw, hip)
|
||||
local x, f_y = automobiles.get_xz_from_hipotenuse(f_x, r_y, pitch - math.rad(90), hip) --the x is only a mock
|
||||
--minetest.chat_send_all("r: "..r_y.." f: "..f_y .." - "..math.deg(pitch))
|
||||
local front_axis = {x=f_x, y=f_y, z=f_z}
|
||||
local front_obstacle_level = automobiles.get_obstacle(front_axis)
|
||||
--minetest.chat_send_all("front"..dump(front_obstacle_level))
|
||||
|
||||
--[[local left_front = {x=0, y=f_y, z=0}
|
||||
left_front.x, left_front.z = automobiles.get_xz_from_hipotenuse(f_x, f_z, yaw+math.rad(90), mid_axis)
|
||||
@ -50,8 +52,11 @@ function automobiles.ground_get_distances(self, radius, axis_distance)
|
||||
local m = (deltaY/deltaX)
|
||||
pitch = math.atan(m) --math.atan2(deltaY, deltaX);
|
||||
--minetest.chat_send_all("m: "..m.." pitch ".. math.deg(pitch))
|
||||
else
|
||||
self._pitch = 0
|
||||
end
|
||||
if math.abs(math.deg(pitch)) < 50 then
|
||||
|
||||
if math.abs(math.deg(pitch)) <= 45 then
|
||||
self._pitch = pitch
|
||||
end
|
||||
|
||||
@ -69,10 +74,14 @@ function automobiles.get_obstacle(ref_pos)
|
||||
--lets clone the table
|
||||
local retval = {x=ref_pos.x, y=ref_pos.y, z=ref_pos.z}
|
||||
--minetest.chat_send_all("aa y: " .. dump(retval.y))
|
||||
local i_pos = {x=ref_pos.x, y=ref_pos.y+0.5, z=ref_pos.z}
|
||||
local i_pos = {x=ref_pos.x, y=ref_pos.y, z=ref_pos.z}
|
||||
--minetest.chat_send_all("bb y: " .. dump(i_pos.y))
|
||||
|
||||
retval.y = automobiles.eval_interception(i_pos, {x=i_pos.x, y=i_pos.y - 2, z=i_pos.z})
|
||||
local y = automobiles.eval_interception(i_pos, {x=i_pos.x, y=i_pos.y - 2, z=i_pos.z})
|
||||
if y then
|
||||
retval.y = y
|
||||
end
|
||||
--minetest.chat_send_all(dump(retval.y))
|
||||
|
||||
--minetest.chat_send_all("y: " .. dump(ref_pos.y) .. " ye: ".. dump(retval.y))
|
||||
return retval
|
||||
|
@ -194,7 +194,13 @@ function automobiles.dettach_pax(self, player)
|
||||
--remove_physics_override(player, {speed=1,gravity=1,jump=1})
|
||||
end
|
||||
|
||||
|
||||
function automobiles.get_gauge_angle(value, initial_angle)
|
||||
initial_angle = initial_angle or 90
|
||||
local angle = value * 18
|
||||
angle = angle - initial_angle
|
||||
angle = angle * -1
|
||||
return angle
|
||||
end
|
||||
|
||||
dofile(minetest.get_modpath("automobiles") .. DIR_DELIM .. "custom_physics.lua")
|
||||
dofile(minetest.get_modpath("automobiles") .. DIR_DELIM .. "control.lua")
|
||||
|
BIN
automobiles/models/automobiles_pointer.b3d
Executable file
BIN
automobiles/models/automobiles_pointer.b3d
Executable file
Binary file not shown.
@ -9,6 +9,8 @@ roadster.max_speed = 15
|
||||
roadster.max_acc_factor = 5
|
||||
roadster.max_fuel = 10
|
||||
|
||||
ROADSTER_GAUGE_FUEL_POSITION = {x=0,y=8.04,z=17.84}
|
||||
|
||||
roadster.front_wheel_xpos = 10.26
|
||||
roadster.rear_wheel_xpos = 10.26
|
||||
|
||||
|
@ -159,6 +159,28 @@ initial_properties = {
|
||||
|
||||
})
|
||||
|
||||
minetest.register_entity('automobiles_roadster:pointer',{
|
||||
initial_properties = {
|
||||
physical = false,
|
||||
collide_with_objects=false,
|
||||
pointable=false,
|
||||
visual = "mesh",
|
||||
mesh = "automobiles_pointer.b3d",
|
||||
visual_size = {x = 1, y = 1, z = 1},
|
||||
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,
|
||||
})
|
||||
|
||||
minetest.register_entity("automobiles_roadster:roadster", {
|
||||
initial_properties = {
|
||||
physical = true,
|
||||
@ -312,6 +334,10 @@ minetest.register_entity("automobiles_roadster:roadster", {
|
||||
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
|
||||
|
||||
self.object:set_armor_groups({immortal=1})
|
||||
|
||||
mobkit.actfunc(self, staticdata, dtime_s)
|
||||
@ -467,6 +493,29 @@ minetest.register_entity("automobiles_roadster:roadster", {
|
||||
if accel.z > max_factor then accel.z = acc_adjusted end
|
||||
if accel.z < -max_factor then accel.z = -acc_adjusted end
|
||||
-- end correction
|
||||
|
||||
-- calculate energy consumption --
|
||||
----------------------------------
|
||||
if self._energy > 0 then
|
||||
local zero_reference = vector.new()
|
||||
local acceleration = automobiles.get_hipotenuse_value(accel, zero_reference)
|
||||
--minetest.chat_send_all(acceleration)
|
||||
local consumed_power = acceleration/40000
|
||||
self._energy = self._energy - consumed_power;
|
||||
end
|
||||
if self._energy <= 0 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")
|
||||
else
|
||||
roadster.engine_set_sound_and_animation(self, longit_speed)
|
||||
end
|
||||
|
||||
local energy_indicator_angle = automobiles.get_gauge_angle(self._energy)
|
||||
self.fuel_gauge:set_attach(self.object,'',ROADSTER_GAUGE_FUEL_POSITION,{x=0,y=0,z=energy_indicator_angle})
|
||||
----------------------------
|
||||
-- end energy consumption --
|
||||
|
||||
accel.y = -automobiles.gravity
|
||||
|
||||
if stop ~= true then
|
||||
@ -481,27 +530,11 @@ minetest.register_entity("automobiles_roadster:roadster", {
|
||||
end
|
||||
|
||||
if newyaw~=yaw or newpitch~=pitch then self.object:set_rotation({x=newpitch,y=newyaw,z=0}) end
|
||||
roadster.engine_set_sound_and_animation(self, longit_speed)
|
||||
|
||||
--saves last velocity for collision detection (abrupt stop)
|
||||
self.lastvelocity = self.object:get_velocity()
|
||||
self._longit_speed = longit_speed
|
||||
|
||||
-- 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)
|
||||
@ -521,7 +554,7 @@ minetest.register_entity("automobiles_roadster:roadster", {
|
||||
end
|
||||
|
||||
local is_attached = false
|
||||
if puncher:get_attach() == self.object then is_attached = true end
|
||||
if puncher:get_attach() == self.driver_seat then is_attached = true end
|
||||
|
||||
local itmstck=puncher:get_wielded_item()
|
||||
local item_name = ""
|
||||
|
@ -10,12 +10,14 @@ function roadster.destroy(self, puncher)
|
||||
|
||||
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")
|
||||
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
|
||||
@ -34,6 +36,7 @@ function roadster.destroy(self, puncher)
|
||||
if self.steering_axis then self.steering_axis: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
|
||||
|
||||
self.object:remove()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user