added air capture

This commit is contained in:
Alexsandro Percy 2024-02-17 17:36:09 -03:00
parent e57d36d299
commit a405b75b51
3 changed files with 70 additions and 2 deletions

View file

@ -528,9 +528,11 @@ minetest.register_entity("ap_airship:airship", {
_disconnection_check_time = 0,
_inv = nil,
_inv_id = "",
_rescue_plane = false,
_name_color = 0,
_name_hor_aligment = 3.0,
_simple_attach_pos = {x=0,y=-35,z=-70},
_simple_attach_ent_list = {"albatros_d5:albatros_d5","sopwith_f1_camel:sopwith_f1_camel","supercub:supercub"},
item = "ap_airship:airship",
@ -552,6 +554,7 @@ minetest.register_entity("ap_airship:airship", {
stored_passengers_locked = self._passengers_locked,
stored_vehicle_custom_data = self._vehicle_custom_data or {},
stored_ship_name = self._ship_name,
stored_rescue_plane = self._rescue_plane,
})
end,
@ -582,6 +585,7 @@ minetest.register_entity("ap_airship:airship", {
self._passengers = data.stored_passengers or ap_airship.copy_vector({[1]=nil, [2]=nil, [3]=nil, [4]=nil, [5]=nil, [6]=nil, [7]=nil, [8]=nil, [9]=nil, [10]=nil, [11]=nil, [12]=nil})
self._passengers_locked = data.stored_passengers_locked
self._ship_name = data.stored_ship_name
self._rescue_plane = data.stored_rescue_plane or false
local custom_data = data.stored_vehicle_custom_data or nil
if custom_data then
@ -829,6 +833,10 @@ minetest.register_entity("ap_airship:airship", {
self.object:set_bone_position("door", {x=0,y=-13.1266,z=54.1922}, {x=-28,y=0,z=0})
else
self.object:set_bone_position("door", {x=0,y=-13.1266,z=54.1922}, {x=0,y=0,z=0})
if self._rescue_plane then
ap_airship.timed_anchor_entity(self, curr_pos, yaw, 3, self.dtime)
end
end
--saves last velocy for collision detection (abrupt stop)

View file

@ -62,7 +62,17 @@ function ap_airship.external_attach(name)
"size[6,4]",
}, "")
local entities = "albatros_d5:albatros_d5,sopwith_f1_camel:sopwith_f1_camel,supercub:supercub"
local player = minetest.get_player_by_name(name)
local plane_obj = ap_airship.getPlaneFromPlayer(player)
if plane_obj == nil then
return
end
local ent = plane_obj:get_luaentity()
local entities = ""
for k, v in pairs(ent._simple_attach_ent_list) do
entities = entities .. v .. ","
end
basic_form = basic_form.."label[1,1.0;Attach Outside:]"
basic_form = basic_form.."dropdown[1,1.6;4,0.6;entity;"..entities..";1;false]"
@ -159,7 +169,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local name = player:get_player_name()
local plane_obj = ap_airship.getPlaneFromPlayer(player)
if plane_obj == nil then
minetest.close_formspec(name, "ap_airship:logo_main")
minetest.close_formspec(name, "ap_airship:attach_main")
return
end
local ent = plane_obj:get_luaentity()

View file

@ -464,3 +464,53 @@ function ap_airship.copy_vector(original_vector)
return tablecopy
end
function ap_airship.eval_interception(initial_pos, end_pos, target_list)
target_list = target_list or {}
--minetest.chat_send_all(dump(end_pos))
local ret_y = nil
local cast = minetest.raycast(initial_pos, end_pos, true, false)
local thing = cast:next()
while thing do
if thing.type == "object" then
local object = thing.ref
local ent = object:get_luaentity()
if ent then
for k, v in pairs(target_list) do
--minetest.chat_send_all(ent.name)
if v == ent.name then
return ent, object
end
end
end
end
thing = cast:next()
end
return nil, nil
end
function ap_airship.timed_anchor_entity(self, curr_pos, yaw, time, dtime)
local time = time or 0
if self._vehicle_custom_data.simple_external_attach_entity ~= nil then return end
if not self._timed_anchor_counter then self._timed_anchor_counter = time end
self._timed_anchor_counter = self._timed_anchor_counter + dtime
if self._timed_anchor_counter < time then return nil, nil end --go out before the right time
if self._timed_anchor_counter >= time then
self._timed_anchor_counter = 0
local relative_pos = vector.new(self._simple_attach_pos)
local rel_pos = vector.divide(relative_pos,10)
local move = -1*rel_pos.z
local raycast_pos = vector.new(curr_pos)
raycast_pos.x = raycast_pos.x + move * math.sin(yaw)
raycast_pos.z = raycast_pos.z - move * math.cos(yaw)
raycast_pos.y = raycast_pos.y + rel_pos.y
local ent, obj = ap_airship.eval_interception(raycast_pos, {x=raycast_pos.x, y=raycast_pos.y-4, z=raycast_pos.z}, self._simple_attach_ent_list)
if ent then
local dest_pos = vector.add(vector.new(curr_pos), relative_pos)
--airutils.attach_external_object(self, object, ent, destination_pos, relative_pos, attach_up)
airutils.attach_external_object(self, obj, ent, dest_pos, relative_pos, true)
end
end
end