Skip to content

Commit

Permalink
added the ADF function and ailerons are working now
Browse files Browse the repository at this point in the history
  • Loading branch information
APercy committed Aug 21, 2022
1 parent 9d38a80 commit a791976
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 10 deletions.
1 change: 1 addition & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ ju52.textures = {
"ju52_metal.png", "ju52_black.png", --manetes potencia
"ju52_glass.png", --vidro porta
"ju52_bege.png", --interno porta
"ju52_compass_plan.png", --indicador ADF
"ju52_engine.png", "ju52_black.png", --motor
"ju52_engine.png", "ju52_black.png", --motores
ju52.skin_texture, --fuselagem
Expand Down
9 changes: 8 additions & 1 deletion ju52_entities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ minetest.register_entity("ju52:ju52", {
_inv_id = "",
_door_closed = true,
_door_command = 1, --1 close, 0 open
_adf = false,
_adf_destiny = {x=0,z=0},

_change_color = function(self, colstr)
airutils.paint(self, colstr, ju52.skin_texture)
Expand All @@ -129,6 +131,8 @@ minetest.register_entity("ju52:ju52", {
stored_color = self._color,
stored_skin = self._skin,
stored_inv_id = self._inv_id,
stored_adf = self._adf,
stored_adf_destiny = self._adf_destiny,
})
end,

Expand All @@ -149,6 +153,8 @@ minetest.register_entity("ju52:ju52", {
self._color = data.stored_color
self._skin = data.stored_skin
self._inv_id = data.stored_inv_id
self._adf = data.stored_adf
self._adf_destiny = data.stored_adf_destiny
--minetest.debug("loaded: ", self._energy)
end
airutils.setText(self, "Ju 52")
Expand Down Expand Up @@ -334,7 +340,8 @@ minetest.register_entity("ju52:ju52", {
else
local _,indx = item_name:find('dye:')
if indx and self._engine_running == false then
ju52.paint_formspec(self.owner)
local name = puncher:get_player_name()
ju52.paint_formspec(name)
itmstck:set_count(itmstck:get_count()-1)
puncher:set_wielded_item(itmstck)
end
Expand Down
55 changes: 51 additions & 4 deletions ju52_forms.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,39 @@ function ju52.pilot_formspec(name)
local door_is_open = "true"
if ent._door_closed then door_is_open = "false" end

local adf = "false"
if ent._adf then adf = "true" end
local x, z = 0
if ent._adf_destiny then
if ent._adf_destiny.x then
if type(ent._adf_destiny.x) ~= nil then
x = math.floor(ent._adf_destiny.x)
end
end
if ent._adf_destiny.z then
if type(ent._adf_destiny.z) ~= nil then
z = math.floor(ent._adf_destiny.z)
end
end
else
return
end

local copilot_name = "test"
basic_form = basic_form.."button[1,1.0;4,1;turn_on;Start/Stop Engines]"
basic_form = basic_form.."button[1,2.0;4,1;hud;Show/Hide Gauges]"
--basic_form = basic_form.."button[1,3.0;4,1;turn_auto_pilot_on;Auto Pilot]"
basic_form = basic_form.."button[1,4.0;4,1;pass_control;Pass the Control]"
basic_form = basic_form.."checkbox[1,5.8;flap_is_down;Flaps down;"..flap_is_down.."]"
basic_form = basic_form.."checkbox[1,6.8;door_is_open;Door opened;"..door_is_open.."]"
basic_form = basic_form.."button[1,7.8;4,1;go_out;Go Offboard]"
basic_form = basic_form.."checkbox[1,5.4;flap_is_down;Flaps down;"..flap_is_down.."]"
basic_form = basic_form.."checkbox[1,6.0;door_is_open;Door opened;"..door_is_open.."]"

basic_form = basic_form.."checkbox[1,7.0;adf;Auto Direction Find;"..adf.."]"
basic_form = basic_form.."field[1,7.6;1.5,0.6;adf_x;pos x;"..x.."]"
basic_form = basic_form.."field[2.7,7.6;1.5,0.6;adf_z;pos z;"..z.."]"
basic_form = basic_form.."button[4.5,7.6;0.6,0.6;save_adf;OK]"


basic_form = basic_form.."button[1,8.6;4,1;go_out;Go Offboard]"
basic_form = basic_form.."label[1,10;Bring a copilot:]"
basic_form = basic_form.."dropdown[1,10.2;4,1;copilot;"..pass_list..";0;false]"

Expand All @@ -71,7 +96,7 @@ function ju52.paint_formspec(name)
basic_form = basic_form.."image_button[0.5,0.5;3,1;ju52_p_lufthansa.png;lufthansa;Lufthansa;false;true;]"
basic_form = basic_form.."image_button[0.5,1.6;3,1;ju52_p_lufthansa.png;lufthansa2;Lufthansa 2;false;true;]"
basic_form = basic_form.."image_button[0.5,2.7;3,1;ju52_p_luftwaffe.png;luftwaffe;Luftwaffe;false;true;]"
--basic_form = basic_form.."image_button[1,4.3;3,1;ju52_white.png^[multiply:#2b2b2b;black;Black;false;true;]"
--basic_form = basic_form.."image_button[1,4.3;3,1;ju52_white.png^[multiply:#2b2b2b;black;Black;false;true;]"

minetest.show_formspec(name, "ju52:paint", basic_form)
end
Expand Down Expand Up @@ -228,6 +253,28 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
end
end
if fields.adf then
if ent._adf == true then
ent._adf = false
else
ent._adf = true
end
end
if fields.save_adf then
if ent._adf_destiny then
if fields.adf_x then
if tonumber(fields.adf_x, 10) ~= nil then
ent._adf_destiny.x = tonumber(fields.adf_x, 10)
end
end
if fields.adf_z then
if tonumber(fields.adf_z, 10) ~= nil then
ent._adf_destiny.z = tonumber(fields.adf_z, 10)
end
end
end
end

end
minetest.close_formspec(name, "ju52:pilot_main")
end
Expand Down
24 changes: 19 additions & 5 deletions ju52_utilities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,19 @@ function ju52.flightstep(self)
self.object:set_bone_position("fuel", {x=0, y=-40.6, z=15.35}, {x=0, y=(energy_indicator_angle+180), z=0})
self.object:set_bone_position("compass", {x=0, y=-40.55, z=18.2}, {x=0, y=(math.deg(newyaw)), z=0})

local adf = 0
if self._adf == true then
if airutils.getAngleFromPositions then
adf = airutils.getAngleFromPositions(curr_pos, self._adf_destiny)
adf = (adf + math.deg(newyaw))
--minetest.chat_send_all(adf)
else
minetest.chat_send_player(self.driver_name," >>> Impossible to activate the ADF - the airutils lib is outdated")
end
end

self.object:set_bone_position("compass_plan", {x=0, y=-40.4, z=18.2}, {x=0, y=adf, z=0})

--altimeters
local altitude = (curr_pos.y / 0.32) / 100
local hour, minutes = math.modf( altitude )
Expand Down Expand Up @@ -937,12 +950,13 @@ function ju52.flightstep(self)
ju52.flap_off(self)
end

--self.object:set_bone_position("l_aileron", {x=-93.79, y=4.8, z=6.5}, {x=6.7, y=0, z=97.25})
--local l_aileron_rotation = {x=1, y=1, z=-2}
--local l_aileron_rotation = vector.rotate_around_axis({x=6.7, y=5, z=97.25}, l_aileron_rotation, math.rad(30))
--minetest.chat_send_all("x: " .. l_aileron_rotation.x .. " - y: " .. l_aileron_rotation.y .. " - z: " .. l_aileron_rotation.z)
--self.object:set_bone_position("l_aileron", {x=-93.79, y=4.8, z=6.5}, l_aileron_rotation)
self.object:set_bone_position("aileron_base_r", {x=93.79, y=4.8, z=6.5}, {x=-90, y=174.7, z=-7.4})
local r_aileron_rotation = {x=0, y=-self._rudder_angle + 90, z=90}
self.object:set_bone_position("r_aileron", {x=0, y=0, z=0}, r_aileron_rotation)

self.object:set_bone_position("aileron_base_l", {x=-93.79, y=4.8, z=6.5}, {x=90, y=5.3, z=7.4})
local l_aileron_rotation = {x=0, y=-self._rudder_angle + 90, z=90}
self.object:set_bone_position("l_aileron", {x=0, y=0, z=0}, r_aileron_rotation)

-- calculate energy consumption --
ju52.consumptionCalc(self, accel)
Expand Down
Binary file modified models/ju52_mine.b3d
Binary file not shown.
Binary file modified models/ju52_mine_old.b3d
100644 → 100755
Binary file not shown.
Binary file added textures/ju52_compass_plan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a791976

Please sign in to comment.