added smoke by damage

This commit is contained in:
Alexsandro Percy 2023-08-26 14:34:02 -03:00
parent 5ae1a76779
commit 0963a3dc1a
2 changed files with 68 additions and 4 deletions

View file

@ -274,6 +274,28 @@ function airutils.logic(self)
airutils.landing_lights_operate(self)
end
--smoke and fire
if self._engine_running then
local curr_health_percent = (self.hp_max * 100)/self._max_plane_hp
if curr_health_percent < 20 then
airutils.add_smoke_trail(self, 2)
elseif curr_health_percent < 50 then
airutils.add_smoke_trail(self, 1)
end
else
if self._smoke_spawner and not self._smoke_semaphore then
self._smoke_semaphore = 1 --to set it only one time
minetest.after(5, function()
if self._smoke_spawner then
minetest.delete_particlespawner(self._smoke_spawner)
self._smoke_spawner = nil
self._smoke_semaphore = nil
end
end)
end
end
if longit_speed == 0 and is_flying == false and is_attached == false and self._engine_running == false then
return
end
@ -477,8 +499,6 @@ function airutils.logic(self)
end
end
------------------------------------------------------
-- end accell
------------------------------------------------------
@ -487,6 +507,7 @@ function airutils.logic(self)
-- sound and animation
------------------------------------------------------
airutils.engine_set_sound_and_animation(self)
------------------------------------------------------
--self.object:get_luaentity() --hack way to fix jitter on climb

View file

@ -689,6 +689,42 @@ function airutils.pid_controller(current_value, setpoint, last_error, d_time, kp
return output, last_error
end
function airutils.add_smoke_trail(self, smoke_type)
smoke_type = smoke_type or 1
local smoke_texture = "airutils_smoke.png"
if smoke_type == 2 then
smoke_texture = "airutils_smoke.png^[multiply:#020202"
end
if self._curr_smoke_type ~= smoke_type then
self._curr_smoke_type = smoke_type
if self._smoke_spawner then
minetest.delete_particlespawner(self._smoke_spawner)
self._smoke_spawner = nil
end
end
if self._smoke_spawner == nil then
local radius = 1
self._smoke_spawner = minetest.add_particlespawner({
amount = 3,
time = 0,
--minpos = vector.subtract(pos, radius / 2),
--maxpos = vector.add(pos, radius / 2),
minvel = {x = -1, y = -1, z = -1},
maxvel = {x = 1, y = 5, z = 1},
minacc = vector.new(),
maxacc = vector.new(),
attached = self.object,
minexptime = 3,
maxexptime = 5.5,
minsize = 10,
maxsize = 15,
texture = smoke_texture,
})
end
end
function airutils.add_destruction_effects(pos, radius, w_fire)
if pos == nil then return end
w_fire = w_fire
@ -801,8 +837,15 @@ function airutils.start_engine(self)
self._power_lever = 0 --zero power
self._last_applied_power = 0 --zero engine
elseif self._engine_running == false and self._energy > 0 then
self._engine_running = true
self._last_applied_power = -1 --send signal to start
local curr_health_percent = (self.hp_max * 100)/self._max_plane_hp
if curr_health_percent > 20 then
self._engine_running = true
self._last_applied_power = -1 --send signal to start
else
if self.driver_name then
minetest.chat_send_player(self.driver_name,core.colorize('#ff0000', " >>> The engine is damaged, start procedure failed."))
end
end
end
end