From 2b7036eb2c2bfdab6556d0ab10f1db456302afca Mon Sep 17 00:00:00 2001 From: Alexsandro Percy Date: Mon, 20 Nov 2023 14:36:24 -0300 Subject: [PATCH] added support for destroyed plane placing --- lib_planes/entities.lua | 9 +- lib_planes/utilities.lua | 132 ++++++++++++++++++++++++++++- textures/airutils_burned_metal.png | Bin 0 -> 6139 bytes 3 files changed, 133 insertions(+), 8 deletions(-) create mode 100644 textures/airutils_burned_metal.png diff --git a/lib_planes/entities.lua b/lib_planes/entities.lua index 6681101..3febef1 100644 --- a/lib_planes/entities.lua +++ b/lib_planes/entities.lua @@ -98,7 +98,7 @@ function airutils.on_activate(self, staticdata, dtime_s) if not inv then airutils.create_inventory(self, self._trunk_slots) else - self.inv = inv + self._inv = inv end airutils.seats_create(self) @@ -203,6 +203,9 @@ function airutils.logic(self) local co_pilot = nil if self.co_pilot and self._have_copilot then co_pilot = minetest.get_player_by_name(self.co_pilot) end + --test collision + airutils.testImpact(self, velocity, curr_pos) + if player then local ctrl = player:get_player_control() --------------------- @@ -614,9 +617,6 @@ function airutils.logic(self) -- calculate energy consumption -- airutils.consumptionCalc(self, accel) - --test collision - airutils.testImpact(self, velocity, curr_pos) - --saves last velocity for collision detection (abrupt stop) self._last_accel = new_accel self._last_vel = self.object:get_velocity() @@ -658,6 +658,7 @@ function airutils.on_punch(self, puncher, ttime, toolcaps, dir, damage) if self.hp_max <= 0 then airutils.destroy(self, name) + return end airutils.setText(self, self._vehicle_name) diff --git a/lib_planes/utilities.lua b/lib_planes/utilities.lua index c6e5294..b8ca4e9 100644 --- a/lib_planes/utilities.lua +++ b/lib_planes/utilities.lua @@ -256,11 +256,16 @@ end function airutils.destroy(self, by_name) by_name = by_name or "" local with_fire = self._enable_fire_explosion - if by_name == self.owner then with_fire = false end + local owner = self.owner + if by_name == owner then with_fire = false end local pos = self.object:get_pos() + local rot = self.object:get_rotation() + local trunk_slots = self._trunk_slots + local inv_id = self._inv_id + if pos == nil then return end - if self.owner and self._vehicle_name then - minetest.log("action", "airutils: The player "..self.owner.." had it's "..self._vehicle_name.." destroyed at position x="..math.floor(pos.x).." y="..math.floor(pos.y).." z="..math.floor(pos.z)) + if owner and self._vehicle_name then + minetest.log("action", "airutils: The player "..owner.." had it's "..self._vehicle_name.." destroyed at position x="..math.floor(pos.x).." y="..math.floor(pos.y).." z="..math.floor(pos.z)) else minetest.log("action", "airutils: An airplane was destroyed at position x="..math.floor(pos.x).." y="..math.floor(pos.y).." z="..math.floor(pos.z)) end @@ -293,11 +298,39 @@ function airutils.destroy(self, by_name) self._destroy_parts_method(self) end - airutils.destroy_inventory(self) + local destroyed_ent = nil + if self._destroyed_ent then + destroyed_ent = self._destroyed_ent + end + + --if dont have a destroyed version, destroy the inventory + if not destroyed_ent then + airutils.destroy_inventory(self) + else + if not with_fire then + airutils.destroy_inventory(self) + end + end + self.object:remove() if airutils.blast_damage == true and with_fire == true then airutils.add_blast_damage(pos, 7, 10) + if destroyed_ent then + + local dest_ent = minetest.add_entity(pos, destroyed_ent) + if dest_ent then + local ent = dest_ent:get_luaentity() + if ent then + ent.owner = owner + ent._inv_id = inv_id + ent._trunk_slots = trunk_slots + ent._game_time = minetest.get_gametime() + dest_ent:set_yaw(rot.y) + end + end + + end end end @@ -305,6 +338,7 @@ function airutils.testImpact(self, velocity, position) if self.hp_max < 0 then --if acumulated damage is greater than 50, adieu airutils.destroy(self) end + if velocity == nil then return end local impact_speed = 2 local p = position --self.object:get_pos() local collision = false @@ -1080,4 +1114,94 @@ function airutils.get_adf_angle(self, pos) return adf end +function airutils.destroyed_save_static_data(self) + return minetest.serialize( + { + stored_owner = self.owner, + stored_slots = self._trunk_slots, + stored_inv_id = self._inv_id, + stored_game_time = self._game_time, + } + ) +end +function airutils.destroyed_on_activate(self, staticdata, dtime_s) + local pos = self.object:get_pos() + + if staticdata ~= "" and staticdata ~= nil then + local data = minetest.deserialize(staticdata) or {} + self.owner = data.stored_owner + self._inv_id = data.stored_inv_id + self._trunk_slots = data.stored_slots + self._game_time = data.stored_game_time + end + + 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 inv then + self._inv = inv + end + + airutils.set_acceleration(self.object,{x=0,y=airutils.gravity,z=0}) + self.object:set_bone_position("elevator", self._elevator_pos, {x=-170, y=0, z=0}) +end + +local function check_shared_by_time(self) + local shared_by_time = false + if self._game_time then + --check if it was created in the last 20 minutes (1200 seconds) + if minetest.get_gametime() - self._game_time >= 1200 then shared_by_time = true end + end + return shared_by_time +end + +function airutils.destroyed_open_inventory(self, clicker) + local message = "" + if not clicker or not clicker:is_player() then + return + end + + local name = clicker:get_player_name() + + if self.owner == "" then + self.owner = name + end + + local shared_by_time = check_shared_by_time(self) + + if name == self.owner or shared_by_time then + if not self._inv then + airutils.create_inventory(self, self._trunk_slots) + end + airutils.show_vehicle_trunk_formspec(self, clicker, self._trunk_slots) + else + minetest.chat_send_player(name, core.colorize('#ff0000', '>>> You cannot claim this scrap yet, wait some minutes.')) + end +end + +function airutils.destroyed_on_punch(self, puncher, ttime, toolcaps, dir, damage) + if not puncher or not puncher:is_player() then + return + end + + local name = puncher:get_player_name() + local shared_by_time = check_shared_by_time(self) + + local is_admin = false + is_admin = minetest.check_player_privs(puncher, {server=true}) + if shared_by_time == false then + if self.owner and self.owner ~= name and self.owner ~= "" then + if is_admin == false then return end + end + end + + minetest.sound_play("airutils_collision", { + object = self.object, + max_hear_distance = 5, + gain = 1.0, + fade = 0.0, + pitch = 1.0, + }) + airutils.destroy_inventory(self) + self.object:remove() +end diff --git a/textures/airutils_burned_metal.png b/textures/airutils_burned_metal.png new file mode 100644 index 0000000000000000000000000000000000000000..2ce17fd1a2c601eb5b927f99ffc4134d01d90d0f GIT binary patch literal 6139 zcmeHKc{r5o`yVL^IhK?5#Od)At>!Q`hhNPuKPP{?}aBJMZ&8&wYRH`~KYbv&B0*ZCx$3 zK?(wathTqab^+gVqGzQ9_^&?ui41|Pm<)IG;Jc7Rp&Txo&Ik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