first
|
@ -0,0 +1,25 @@
|
|||
unused_args = false
|
||||
allow_defined_top = true
|
||||
|
||||
globals = {
|
||||
"minetest",
|
||||
"mobkit",
|
||||
"core",
|
||||
"player_api",
|
||||
"player_monoids",
|
||||
"math.sign",
|
||||
}
|
||||
|
||||
read_globals = {
|
||||
string = {fields = {"split"}},
|
||||
table = {fields = {"copy", "getn"}},
|
||||
|
||||
-- Builtin
|
||||
"vector", "ItemStack",
|
||||
"dump", "DIR_DELIM", "VoxelArea", "Settings",
|
||||
|
||||
-- MTG
|
||||
"default", "sfinv", "creative",
|
||||
}
|
||||
|
||||
ignore = {"611"}
|
|
@ -0,0 +1,167 @@
|
|||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
|
||||
Copyright Alexsandro Percy - 2021
|
72
README.md
|
@ -1,2 +1,70 @@
|
|||
# supercub
|
||||
A Super Cup airplane for minetest
|
||||
Minetest 5.4 mod: Hydroplane - Super Duck
|
||||
========================================
|
||||
|
||||
The Super Duck
|
||||
|
||||
This one tries to implement some flight, using the mobkit mod.
|
||||
In order to fly, it is necessary to first supply the airplane with biofuel.
|
||||
Then with a bottle or gallon selected, punch it against the airplane floater.
|
||||
You can use 10 bottles them to fill the tank. See the fuel gauge on the airplane
|
||||
panel (right below, with a green F). To embark, click with the right button.
|
||||
While the machine is off, it is possible to move it using the sneak and jump keys (shift an space).
|
||||
W ans S controls the pitch (elevator).
|
||||
Right and Left (A and D) controls the yaw (rudder and ailerons).
|
||||
|
||||
Then to fly, start the engine with the special key E. Press jump (space)
|
||||
to increase the engine power (check the panel for the indicator marked with a yellow P).
|
||||
Adjust to the maximum. Pull the elevator control (S) when it have the speed to lift.
|
||||
|
||||
During the cruise flight, it is ideal to keep the power setting below the red range,
|
||||
to control fuel consumption. Use the climb indicator to stabilize altitude,
|
||||
as at high altitudes you lose sustentation and you spend more fuel.
|
||||
|
||||
For landing, just lower the power and stabilize the airplane. Pay attention at air speed
|
||||
indicator, keeping it at green range, otherwise you will stall.
|
||||
|
||||
Care must be taken with impacts, as it causes damage to the aircraft and the pilot,
|
||||
so training landings is essential.
|
||||
|
||||
To brake the aircraft, use the sneak (shift) key until it comes to a complete stop.
|
||||
Do not stop the engine before this, or it will reverse when it stops
|
||||
|
||||
To repair damages, you can use the repair tool. It subtracts steel ingots to increase
|
||||
airplane hp.
|
||||
|
||||
It can be painted using dye of any color you want, you must punch the airplane with the dye.
|
||||
|
||||
Biofuel mod can be found here: https://github.com/APercy/minetest_biofuel
|
||||
|
||||
The limitations: because the lack in functions to roll the camera, and the rudder acting together the ailerons,
|
||||
the airplane is unable to do a tuneau, barrel roll, loopings and any kind of aerobatics maneuvers.
|
||||
It was limited at the source. You can modify it by your own, just making the roll movement cumulative and increasing the speeds
|
||||
|
||||
**Controls overview:**
|
||||
* Right click: enter in/get off plane
|
||||
* Left click (with biofuel): add fuel to plane
|
||||
* Right click and Sneak: enter in flight instructor mode (limited vision, so use debug info)
|
||||
* E: Start engine
|
||||
* Jump: Increase power, forward on ground
|
||||
* Sneak: Decrease power, brake on ground
|
||||
* Backward: go up flying - nose up
|
||||
* Forward: go down flying - nose down
|
||||
* Left/right: Turn to left/right, work on and out ground.
|
||||
* Left and Right together: center all commands
|
||||
* Sneak and Jump together: give/take the controls to/from pilot student
|
||||
* Up and Down together: enable/disable HUD
|
||||
|
||||
**Chat Commands: **
|
||||
|
||||
/hydro_eject - ejects from the vehicle
|
||||
|
||||
/hydro_manual - shows the manual
|
||||
|
||||
-----------------------
|
||||
License of source code:
|
||||
LGPL v3 (see file LICENSE)
|
||||
|
||||
License of media (textures and sounds):
|
||||
CC0
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
mobkit
|
||||
default
|
||||
biofuel
|
|
@ -0,0 +1,96 @@
|
|||
supercub={}
|
||||
supercub.fuel = {['biofuel:biofuel'] = 1,['biofuel:bottle_fuel'] = 1,
|
||||
['biofuel:phial_fuel'] = 0.25, ['biofuel:fuel_can'] = 10}
|
||||
supercub.gravity = tonumber(minetest.settings:get("movement_gravity")) or 9.8
|
||||
supercub.wing_angle_of_attack = 3
|
||||
supercub.min_speed = 6
|
||||
supercub.max_speed = 6
|
||||
supercub.max_engine_acc = 8 --4.5
|
||||
supercub.lift = 10 --12
|
||||
|
||||
supercub.colors ={
|
||||
black='#2b2b2b',
|
||||
blue='#0063b0',
|
||||
brown='#8c5922',
|
||||
cyan='#07B6BC',
|
||||
dark_green='#567a42',
|
||||
dark_grey='#6d6d6d',
|
||||
green='#4ee34c',
|
||||
grey='#9f9f9f',
|
||||
magenta='#ff0098',
|
||||
orange='#ff8b0e',
|
||||
pink='#ff62c6',
|
||||
red='#dc1818',
|
||||
violet='#a437ff',
|
||||
white='#FFFFFF',
|
||||
yellow='#ffe400',
|
||||
}
|
||||
|
||||
dofile(minetest.get_modpath("supercub") .. DIR_DELIM .. "supercub_global_definitions.lua")
|
||||
dofile(minetest.get_modpath("supercub") .. DIR_DELIM .. "supercub_crafts.lua")
|
||||
dofile(minetest.get_modpath("supercub") .. DIR_DELIM .. "supercub_control.lua")
|
||||
dofile(minetest.get_modpath("supercub") .. DIR_DELIM .. "supercub_fuel_management.lua")
|
||||
dofile(minetest.get_modpath("supercub") .. DIR_DELIM .. "supercub_custom_physics.lua")
|
||||
dofile(minetest.get_modpath("supercub") .. DIR_DELIM .. "supercub_utilities.lua")
|
||||
dofile(minetest.get_modpath("supercub") .. DIR_DELIM .. "supercub_entities.lua")
|
||||
dofile(minetest.get_modpath("supercub") .. DIR_DELIM .. "supercub_manual.lua")
|
||||
|
||||
--
|
||||
-- helpers and co.
|
||||
--
|
||||
|
||||
--
|
||||
-- items
|
||||
--
|
||||
|
||||
settings = Settings(minetest.get_worldpath() .. "/supercub_settings.conf")
|
||||
local function fetch_setting(name)
|
||||
local sname = name
|
||||
return settings and settings:get(sname) or minetest.settings:get(sname)
|
||||
end
|
||||
|
||||
supercub.restricted = fetch_setting("restricted")
|
||||
|
||||
minetest.register_privilege("flight_licence", {
|
||||
description = "Gives a flight licence to the player",
|
||||
give_to_singleplayer = true
|
||||
})
|
||||
|
||||
-- add chatcommand to eject from hydroplane
|
||||
|
||||
minetest.register_chatcommand("cub_eject", {
|
||||
params = "",
|
||||
description = "Ejects from Super Cub",
|
||||
privs = {interact = true},
|
||||
func = function(name, param)
|
||||
local colorstring = core.colorize('#ff0000', " >>> you are not inside your Super Cub")
|
||||
local player = minetest.get_player_by_name(name)
|
||||
local attached_to = player:get_attach()
|
||||
|
||||
if attached_to ~= nil then
|
||||
local seat = attached_to:get_attach()
|
||||
if seat ~= nil then
|
||||
local entity = seat:get_luaentity()
|
||||
if entity then
|
||||
if entity.driver_name == name and entity.name == "supercub:supercub" then
|
||||
supercub.dettachPlayer(entity, player)
|
||||
else
|
||||
minetest.chat_send_player(name,colorstring)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
minetest.chat_send_player(name,colorstring)
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("cub_manual", {
|
||||
params = "",
|
||||
description = "Super Cub operation manual",
|
||||
privs = {interact = true},
|
||||
func = function(name, param)
|
||||
supercub.manual_formspec(name)
|
||||
end
|
||||
})
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
name = supercub
|
||||
depends = mobkit,default,biofuel
|
||||
author = APercy
|
||||
description = Adds a craftable Super Cub
|
||||
title = Super Cub
|
|
@ -0,0 +1,266 @@
|
|||
--global constants
|
||||
supercub.vector_up = vector.new(0, 1, 0)
|
||||
supercub.ideal_step = 0.02
|
||||
supercub.rudder_limit = 30
|
||||
supercub.elevator_limit = 40
|
||||
|
||||
dofile(minetest.get_modpath("supercub") .. DIR_DELIM .. "supercub_utilities.lua")
|
||||
|
||||
function supercub.check_node_below(obj)
|
||||
local pos_below = obj:get_pos()
|
||||
pos_below.y = pos_below.y - 0.1
|
||||
local node_below = minetest.get_node(pos_below).name
|
||||
local nodedef = minetest.registered_nodes[node_below]
|
||||
local touching_ground = not nodedef or -- unknown nodes are solid
|
||||
nodedef.walkable or false
|
||||
local liquid_below = not touching_ground and nodedef.liquidtype ~= "none"
|
||||
return touching_ground, liquid_below
|
||||
end
|
||||
|
||||
function supercub.powerAdjust(self,dtime,factor,dir,max_power)
|
||||
local max = max_power or 100
|
||||
local add_factor = factor/2
|
||||
add_factor = add_factor * (dtime/supercub.ideal_step) --adjusting the command speed by dtime
|
||||
local power_index = self._power_lever
|
||||
|
||||
if dir == 1 then
|
||||
if self._power_lever < max then
|
||||
self._power_lever = self._power_lever + add_factor
|
||||
end
|
||||
if self._power_lever > max then
|
||||
self._power_lever = max
|
||||
end
|
||||
end
|
||||
if dir == -1 then
|
||||
if self._power_lever > 0 then
|
||||
self._power_lever = self._power_lever - add_factor
|
||||
if self._power_lever < 0 then self._power_lever = 0 end
|
||||
end
|
||||
if self._power_lever <= 0 then
|
||||
self._power_lever = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function supercub.control(self, dtime, hull_direction, longit_speed, longit_drag,
|
||||
later_speed, later_drag, accel, player, is_flying)
|
||||
--if self.driver_name == nil then return end
|
||||
local retval_accel = accel
|
||||
|
||||
local stop = false
|
||||
local ctrl = nil
|
||||
|
||||
-- player control
|
||||
if player then
|
||||
ctrl = player:get_player_control()
|
||||
|
||||
--engine and power control
|
||||
if ctrl.aux1 and self._last_time_command > 0.5 then
|
||||
self._last_time_command = 0
|
||||
if self._engine_running then
|
||||
self._engine_running = false
|
||||
self._autopilot = false
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
self._acceleration = 0
|
||||
if self._engine_running then
|
||||
--engine acceleration calc
|
||||
local engineacc = (self._power_lever * supercub.max_engine_acc) / 100;
|
||||
|
||||
local factor = 1
|
||||
|
||||
--increase power lever
|
||||
if ctrl.jump then
|
||||
supercub.powerAdjust(self, dtime, factor, 1)
|
||||
end
|
||||
--decrease power lever
|
||||
if ctrl.sneak then
|
||||
supercub.powerAdjust(self, dtime, factor, -1)
|
||||
if self._power_lever <= 0 and is_flying == false then
|
||||
--break
|
||||
if longit_speed > 0 then
|
||||
engineacc = -1
|
||||
if (longit_speed + engineacc) < 0 then engineacc = longit_speed * -1 end
|
||||
end
|
||||
if longit_speed < 0 then
|
||||
engineacc = 1
|
||||
if (longit_speed + engineacc) > 0 then engineacc = longit_speed * -1 end
|
||||
end
|
||||
if abs(longit_speed) < 0.1 then
|
||||
stop = true
|
||||
end
|
||||
end
|
||||
end
|
||||
--do not exceed
|
||||
local max_speed = 6
|
||||
if longit_speed > max_speed then
|
||||
engineacc = engineacc - (longit_speed-max_speed)
|
||||
if engineacc < 0 then engineacc = 0 end
|
||||
end
|
||||
self._acceleration = engineacc
|
||||
else
|
||||
local paddleacc = 0
|
||||
if longit_speed < 1.0 then
|
||||
if ctrl.jump then paddleacc = 0.5 end
|
||||
end
|
||||
if longit_speed > -1.0 then
|
||||
if ctrl.sneak then paddleacc = -0.5 end
|
||||
end
|
||||
self._acceleration = paddleacc
|
||||
end
|
||||
|
||||
local hull_acc = vector.multiply(hull_direction,self._acceleration)
|
||||
retval_accel=vector.add(retval_accel,hull_acc)
|
||||
|
||||
--pitch
|
||||
local pitch_cmd = 0
|
||||
if ctrl.up then pitch_cmd = 1 elseif ctrl.down then pitch_cmd = -1 end
|
||||
supercub.set_pitch(self, pitch_cmd, dtime)
|
||||
|
||||
-- yaw
|
||||
local yaw_cmd = 0
|
||||
if ctrl.right then yaw_cmd = 1 elseif ctrl.left then yaw_cmd = -1 end
|
||||
supercub.set_yaw(self, yaw_cmd, dtime)
|
||||
|
||||
--I'm desperate, center all!
|
||||
if ctrl.right and ctrl.left then
|
||||
self._elevator_angle = 0
|
||||
self._rudder_angle = 0
|
||||
end
|
||||
end
|
||||
|
||||
if longit_speed > 0 then
|
||||
if ctrl then
|
||||
if ctrl.right or ctrl.left then
|
||||
else
|
||||
supercub.rudder_auto_correction(self, longit_speed, dtime)
|
||||
end
|
||||
else
|
||||
supercub.rudder_auto_correction(self, longit_speed, dtime)
|
||||
end
|
||||
supercub.elevator_auto_correction(self, longit_speed, dtime)
|
||||
end
|
||||
|
||||
return retval_accel, stop
|
||||
end
|
||||
|
||||
function supercub.set_pitch(self, dir, dtime)
|
||||
local pitch_factor = 6
|
||||
if dir == -1 then
|
||||
self._elevator_angle = math.max(self._elevator_angle-pitch_factor*dtime,-supercub.elevator_limit)
|
||||
elseif dir == 1 then
|
||||
if self._angle_of_attack < 0 then pitch_factor = 1 end --lets reduce the command power to avoid accidents
|
||||
self._elevator_angle = math.min(self._elevator_angle+pitch_factor*dtime,supercub.elevator_limit)
|
||||
end
|
||||
end
|
||||
|
||||
function supercub.set_yaw(self, dir, dtime)
|
||||
local yaw_factor = 25
|
||||
if dir == 1 then
|
||||
self._rudder_angle = math.max(self._rudder_angle-(yaw_factor*dtime),-supercub.rudder_limit)
|
||||
elseif dir == -1 then
|
||||
self._rudder_angle = math.min(self._rudder_angle+(yaw_factor*dtime),supercub.rudder_limit)
|
||||
end
|
||||
end
|
||||
|
||||
function supercub.rudder_auto_correction(self, longit_speed, dtime)
|
||||
local factor = 1
|
||||
if self._rudder_angle > 0 then factor = -1 end
|
||||
local correction = (supercub.rudder_limit*(longit_speed/1000)) * factor * (dtime/supercub.ideal_step)
|
||||
local before_correction = self._rudder_angle
|
||||
local new_rudder_angle = self._rudder_angle + correction
|
||||
if math.sign(before_correction) ~= math.sign(new_rudder_angle) then
|
||||
self._rudder_angle = 0
|
||||
else
|
||||
self._rudder_angle = new_rudder_angle
|
||||
end
|
||||
end
|
||||
|
||||
function supercub.elevator_auto_correction(self, longit_speed, dtime)
|
||||
local factor = 1
|
||||
--if self._elevator_angle > -1.5 then factor = -1 end --here is the "compensator" adjusto to keep it stable
|
||||
if self._elevator_angle > 0 then factor = -1 end
|
||||
local correction = (supercub.elevator_limit*(longit_speed/10000)) * factor * (dtime/supercub.ideal_step)
|
||||
local before_correction = self._elevator_angle
|
||||
local new_elevator_angle = self._elevator_angle + correction
|
||||
if math.sign(before_correction) ~= math.sign(new_elevator_angle) then
|
||||
self._elevator_angle = 0
|
||||
else
|
||||
self._elevator_angle = new_elevator_angle
|
||||
end
|
||||
end
|
||||
|
||||
--obsolete, will be removed
|
||||
function getAdjustFactor(curr_y, desired_y)
|
||||
local max_difference = 0.1
|
||||
local adjust_factor = 0.5
|
||||
local difference = math.abs(curr_y - desired_y)
|
||||
if difference > max_difference then difference = max_difference end
|
||||
return (difference * adjust_factor) / max_difference
|
||||
end
|
||||
|
||||
function supercub.autopilot(self, dtime, hull_direction, longit_speed, accel, curr_pos)
|
||||
|
||||
local retval_accel = accel
|
||||
|
||||
local max_autopilot_power = 85
|
||||
local max_attack_angle = 1.8
|
||||
|
||||
--climb
|
||||
local velocity = self.object:get_velocity()
|
||||
local climb_rate = velocity.y * 1.5
|
||||
if climb_rate > 5 then climb_rate = 5 end
|
||||
if climb_rate < -5 then
|
||||
climb_rate = -5
|
||||
end
|
||||
|
||||
self._acceleration = 0
|
||||
if self._engine_running then
|
||||
--engine acceleration calc
|
||||
local engineacc = (self._power_lever * supercub.max_engine_acc) / 100;
|
||||
--self.engine:set_animation_frame_speed(60 + self._power_lever)
|
||||
|
||||
local factor = math.abs(climb_rate * 0.5) --getAdjustFactor(curr_pos.y, self._auto_pilot_altitude)
|
||||
--increase power lever
|
||||
if climb_rate > 0.2 then
|
||||
supercub.powerAdjust(self, dtime, factor, -1)
|
||||
end
|
||||
--decrease power lever
|
||||
if climb_rate < 0 then
|
||||
supercub.powerAdjust(self, dtime, factor, 1, max_autopilot_power)
|
||||
end
|
||||
--do not exceed
|
||||
local max_speed = supercub.max_speed
|
||||
if longit_speed > max_speed then
|
||||
engineacc = engineacc - (longit_speed-max_speed)
|
||||
if engineacc < 0 then engineacc = 0 end
|
||||
end
|
||||
self._acceleration = engineacc
|
||||
end
|
||||
|
||||
local hull_acc = vector.multiply(hull_direction,self._acceleration)
|
||||
retval_accel=vector.add(retval_accel,hull_acc)
|
||||
|
||||
--pitch
|
||||
if self._angle_of_attack > max_attack_angle then
|
||||
supercub.set_pitch(self, 1, dtime)
|
||||
elseif self._angle_of_attack < max_attack_angle then
|
||||
supercub.set_pitch(self, -1, dtime)
|
||||
end
|
||||
|
||||
-- yaw
|
||||
supercub.set_yaw(self, 0, dtime)
|
||||
|
||||
if longit_speed > 0 then
|
||||
supercub.rudder_auto_correction(self, longit_speed, dtime)
|
||||
supercub.elevator_auto_correction(self, longit_speed, dtime)
|
||||
end
|
||||
|
||||
return retval_accel
|
||||
end
|
|
@ -0,0 +1,69 @@
|
|||
-- wing
|
||||
minetest.register_craftitem("supercub:wings",{
|
||||
description = "Supercub wings",
|
||||
inventory_image = "wings.png",
|
||||
})
|
||||
-- fuselage
|
||||
minetest.register_craftitem("supercub:fuselage",{
|
||||
description = "Supercub fuselage",
|
||||
inventory_image = "fuselage.png",
|
||||
})
|
||||
|
||||
-- trike
|
||||
minetest.register_craftitem("supercub:supercub", {
|
||||
description = "Super Cub",
|
||||
inventory_image = "supercub.png",
|
||||
liquids_pointable = true,
|
||||
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
if pointed_thing.type ~= "node" then
|
||||
return
|
||||
end
|
||||
|
||||
local pointed_pos = pointed_thing.under
|
||||
--local node_below = minetest.get_node(pointed_pos).name
|
||||
--local nodedef = minetest.registered_nodes[node_below]
|
||||
|
||||
pointed_pos.y=pointed_pos.y+3
|
||||
local supercub = minetest.add_entity(pointed_pos, "supercub:supercub")
|
||||
if supercub and placer then
|
||||
local ent = hidro:get_luaentity()
|
||||
local owner = placer:get_player_name()
|
||||
ent.owner = owner
|
||||
supercub:set_yaw(placer:get_look_horizontal())
|
||||
itemstack:take_item()
|
||||
end
|
||||
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
--
|
||||
-- crafting
|
||||
--
|
||||
|
||||
if minetest.get_modpath("default") then
|
||||
--[[minetest.register_craft({
|
||||
output = "supercub:wings",
|
||||
recipe = {
|
||||
{"wool:white", "farming:string", "wool:white"},
|
||||
{"group:wood", "group:wood", "group:wood"},
|
||||
{"wool:white", "default:steel_ingot", "wool:white"},
|
||||
}
|
||||
})
|
||||
minetest.register_craft({
|
||||
output = "supercub:fuselage",
|
||||
recipe = {
|
||||
{"default:steel_ingot", "default:diamondblock", "default:steel_ingot"},
|
||||
{"wool:white", "default:steel_ingot", "wool:white"},
|
||||
{"default:steel_ingot", "default:mese_block", "default:steel_ingot"},
|
||||
}
|
||||
})
|
||||
minetest.register_craft({
|
||||
output = "supercub:supercub",
|
||||
recipe = {
|
||||
{"supercub:wings",},
|
||||
{"supercub:fuselage",},
|
||||
}
|
||||
})]]--
|
||||
end
|
|
@ -0,0 +1,55 @@
|
|||
|
||||
local min = math.min
|
||||
local abs = math.abs
|
||||
--local deg = math.deg
|
||||
|
||||
function supercub.physics(self)
|
||||
local friction = 0.99
|
||||
local vel=self.object:get_velocity()
|
||||
|
||||
-- bounciness
|
||||
if self.springiness and self.springiness > 0 then
|
||||
local vnew = vector.new(vel)
|
||||
|
||||
if not self.collided then -- ugly workaround for inconsistent collisions
|
||||
for _,k in ipairs({'y','z','x'}) do
|
||||
if vel[k]==0 and abs(self.lastvelocity[k])> 0.1 then
|
||||
vnew[k]=-self.lastvelocity[k]*self.springiness
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if not vector.equals(vel,vnew) then
|
||||
self.collided = true
|
||||
else
|
||||
if self.collided then
|
||||
vnew = vector.new(self.lastvelocity)
|
||||
end
|
||||
self.collided = false
|
||||
end
|
||||
|
||||
self.object:set_velocity(vnew)
|
||||
end
|
||||
|
||||
local new_velocity = nil
|
||||
|
||||
local accell = {x=0, y=0, z=0}
|
||||
self.water_drag = 0.1
|
||||
|
||||
mobkit.set_acceleration(self.object,{x=0,y=0,z=0})
|
||||
self.isinliquid = false
|
||||
new_velocity = vector.add(vel, {x=0,y=mobkit.gravity * self.dtime,z=0})
|
||||
--self.object:set_velocity(new_velocity)
|
||||
|
||||
new_velocity = vector.add(new_velocity, vector.multiply(self._last_accell, self.dtime))
|
||||
self.object:set_pos(self.object:get_pos())
|
||||
-- dumb friction
|
||||
if self.isonground and not self.isinliquid then
|
||||
self.object:set_velocity({x=new_velocity.x*friction,
|
||||
y=new_velocity.y,
|
||||
z=new_velocity.z*friction})
|
||||
else
|
||||
self.object:set_velocity(new_velocity)
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,588 @@
|
|||
dofile(minetest.get_modpath("supercub") .. DIR_DELIM .. "supercub_global_definitions.lua")
|
||||
|
||||
--
|
||||
-- entity
|
||||
--
|
||||
|
||||
supercub.vector_up = vector.new(0, 1, 0)
|
||||
|
||||
minetest.register_entity('supercub:engine',{
|
||||
initial_properties = {
|
||||
physical = false,
|
||||
collide_with_objects=false,
|
||||
pointable=false,
|
||||
visual = "mesh",
|
||||
backface_culling = false,
|
||||
mesh = "supercub_propeller.b3d",
|
||||
--visual_size = {x = 3, y = 3, z = 3},
|
||||
textures = {"supercub_rotor.png", "supercub_black.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('supercub:rudder',{
|
||||
initial_properties = {
|
||||
physical = false,
|
||||
collide_with_objects=false,
|
||||
pointable=false,
|
||||
visual = "mesh",
|
||||
mesh = "supercub_rudder.b3d",
|
||||
textures = {"supercub_painting.png",},
|
||||
},
|
||||
_color="",
|
||||
|
||||
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('supercub:elevator',{
|
||||
initial_properties = {
|
||||
physical = false,
|
||||
collide_with_objects=false,
|
||||
pointable=false,
|
||||
visual = "mesh",
|
||||
mesh = "supercub_elevator.b3d",
|
||||
textures = {"supercub_painting.png",},
|
||||
},
|
||||
_color="",
|
||||
|
||||
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('supercub:right_aileron',{
|
||||
initial_properties = {
|
||||
physical = false,
|
||||
collide_with_objects=false,
|
||||
pointable=false,
|
||||
visual = "mesh",
|
||||
mesh = "supercub_aileron_r.b3d",
|
||||
textures = {"supercub_painting.png",},
|
||||
},
|
||||
_color="",
|
||||
|
||||
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('supercub:left_aileron',{
|
||||
initial_properties = {
|
||||
physical = false,
|
||||
collide_with_objects=false,
|
||||
pointable=false,
|
||||
visual = "mesh",
|
||||
mesh = "supercub_aileron_l.b3d",
|
||||
textures = {"supercub_painting.png",},
|
||||
},
|
||||
_color="",
|
||||
|
||||
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('supercub:stick',{
|
||||
initial_properties = {
|
||||
physical = false,
|
||||
collide_with_objects=false,
|
||||
pointable=false,
|
||||
visual = "mesh",
|
||||
mesh = "supercub_stick.b3d",
|
||||
textures = {"supercub_metal.png", "supercub_black.png", "supercub_red.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,
|
||||
|
||||
})
|
||||
|
||||
--
|
||||
-- fuel
|
||||
--
|
||||
minetest.register_entity('supercub:pointer',{
|
||||
initial_properties = {
|
||||
physical = false,
|
||||
collide_with_objects=false,
|
||||
pointable=false,
|
||||
visual = "mesh",
|
||||
mesh = "supercub_pointer.b3d",
|
||||
visual_size = {x = 0.4, y = 0.4, z = 0.4},
|
||||
textures = {"supercub_grey.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,
|
||||
})
|
||||
|
||||
--
|
||||
-- seat pivot
|
||||
--
|
||||
minetest.register_entity('supercub:seat_base',{
|
||||
initial_properties = {
|
||||
physical = false,
|
||||
collide_with_objects=false,
|
||||
pointable=false,
|
||||
visual = "mesh",
|
||||
mesh = "supercub_seat_base.b3d",
|
||||
textures = {"supercub_black.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("supercub:supercub", {
|
||||
initial_properties = {
|
||||
physical = true,
|
||||
collide_with_objects = true,
|
||||
collisionbox = {-1.2, -1.28, -1.2, 1.2, 1, 1.2}, --{-1,0,-1, 1,0.3,1},
|
||||
selectionbox = {-2, -1.28, -2, 2, 0, 2},
|
||||
visual = "mesh",
|
||||
mesh = "supercub_fuselage.b3d",
|
||||
stepheight = 0.5,
|
||||
textures = {"supercub_metal.png",
|
||||
"supercub_black.png",
|
||||
"supercub_black.png",
|
||||
"supercub_metal.png",
|
||||
"supercub_painting.png",
|
||||
"supercub_grey.png",
|
||||
"supercub_painting.png",
|
||||
"supercub_painting.png",
|
||||
"supercub_panel.png",
|
||||
"supercub_painting.png",
|
||||
"supercub_glass.png", --glass
|
||||
"supercub_glass.png", -- glass
|
||||
"supercub_black.png",
|
||||
"supercub_grey.png",
|
||||
"supercub_black.png",
|
||||
"supercub_black2.png",
|
||||
"supercub_black.png",
|
||||
"supercub_metal.png",
|
||||
"supercub_black.png",
|
||||
"supercub_glass.png",
|
||||
"supercub_black.png",
|
||||
"supercub_metal.png",
|
||||
"supercub_painting.png"
|
||||
},
|
||||
},
|
||||
textures = {},
|
||||
driver_name = nil,
|
||||
sound_handle = nil,
|
||||
owner = "",
|
||||
static_save = true,
|
||||
infotext = "A nice airplane",
|
||||
hp_max = 50,
|
||||
shaded = true,
|
||||
show_on_minimap = true,
|
||||
springiness = 0.1,
|
||||
physics = supercub.physics,
|
||||
_passenger = nil,
|
||||
_color = "#ffe400",
|
||||
_rudder_angle = 0,
|
||||
_acceleration = 0,
|
||||
_engine_running = false,
|
||||
_angle_of_attack = 2,
|
||||
_elevator_angle = 0,
|
||||
_power_lever = 0,
|
||||
_last_applied_power = 0,
|
||||
_energy = 0.001,
|
||||
_last_vel = {x=0,y=0,z=0},
|
||||
_longit_speed = 0,
|
||||
_land_retracted = true,
|
||||
_show_hud = false,
|
||||
_instruction_mode = false, --flag to intruction mode
|
||||
_command_is_given = false, --flag to mark the "owner" of the commands now
|
||||
_autopilot = false,
|
||||
_auto_pilot_altitude = 0,
|
||||
_last_accell = {x=0,y=0,z=0},
|
||||
_last_time_command = 1,
|
||||
|
||||
get_staticdata = function(self) -- unloaded/unloads ... is now saved
|
||||
return minetest.serialize({
|
||||
--stored_sound_handle = self.sound_handle,
|
||||
stored_energy = self._energy,
|
||||
stored_owner = self.owner,
|
||||
stored_hp = self.hp_max,
|
||||
stored_color = self._color,
|
||||
stored_power_lever = self._power_lever,
|
||||
stored_driver_name = self.driver_name,
|
||||
stored_last_accell = self._last_accell,
|
||||
stored_engine_running = self._engine_running,
|
||||
})
|
||||
end,
|
||||
|
||||
on_activate = function(self, staticdata, dtime_s)
|
||||
mobkit.actfunc(self, staticdata, dtime_s)
|
||||
if staticdata ~= "" and staticdata ~= nil then
|
||||
local data = minetest.deserialize(staticdata) or {}
|
||||
self._energy = data.stored_energy
|
||||
self.owner = data.stored_owner
|
||||
self.hp_max = data.stored_hp
|
||||
self._color = data.stored_color
|
||||
self._power_lever = data.stored_power_lever
|
||||
self.driver_name = data.stored_driver_name
|
||||
self._last_accell = data.stored_last_accell
|
||||
self._engine_running = data.stored_engine_running
|
||||
--self.sound_handle = data.stored_sound_handle
|
||||
--minetest.debug("loaded: ", self._energy)
|
||||
if self._engine_running then
|
||||
self._last_applied_power = -1 --signal to start
|
||||
end
|
||||
end
|
||||
supercub.setText(self)
|
||||
self.object:set_animation({x = 1, y = 12}, 0, 0, true)
|
||||
|
||||
local pos = self.object:get_pos()
|
||||
|
||||
local engine=minetest.add_entity(pos,'supercub:engine')
|
||||
engine:set_attach(self.object,'',{x=0,y=0,z=0},{x=0,y=0,z=0})
|
||||
-- set the animation once and later only change the speed
|
||||
engine:set_animation({x = 1, y = 12}, 0, 0, true)
|
||||
self.engine = engine
|
||||
|
||||
local rudder=minetest.add_entity(pos,'supercub:rudder')
|
||||
rudder:set_attach(self.object,'',{x=0,y=0.12,z=-36.85},{x=0,y=0,z=0})
|
||||
self.rudder = rudder
|
||||
|
||||
local right_aileron=minetest.add_entity(pos,'supercub:right_aileron')
|
||||
right_aileron:set_attach(self.object,'',{x=0,y=8.08,z=-7},{x=0,y=0,z=0})
|
||||
self.right_aileron = right_aileron
|
||||
|
||||
local left_aileron=minetest.add_entity(pos,'supercub:left_aileron')
|
||||
left_aileron:set_attach(self.object,'',{x=0,y=8.08,z=-7},{x=0,y=0,z=0})
|
||||
self.left_aileron = left_aileron
|
||||
|
||||
local elevator=minetest.add_entity(pos,'supercub:elevator')
|
||||
elevator:set_attach(self.object,'',{x=0,y=4,z=-35.5},{x=0,y=0,z=0})
|
||||
self.elevator = elevator
|
||||
|
||||
local fuel_gauge=minetest.add_entity(pos,'supercub:pointer')
|
||||
local energy_indicator_angle = supercub.get_gauge_angle(self._energy)
|
||||
fuel_gauge:set_attach(self.object,'',supercub_GAUGE_FUEL_POSITION,{x=0,y=0,z=energy_indicator_angle})
|
||||
self.fuel_gauge = fuel_gauge
|
||||
|
||||
local power_gauge=minetest.add_entity(pos,'supercub:pointer')
|
||||
local power_indicator_angle = supercub.get_gauge_angle(self._power_lever)
|
||||
power_gauge:set_attach(self.object,'',supercub_GAUGE_POWER_POSITION,{x=0,y=0,z=power_indicator_angle})
|
||||
self.power_gauge = power_gauge
|
||||
|
||||
local climb_gauge=minetest.add_entity(pos,'supercub:pointer')
|
||||
local climb_angle = supercub.get_gauge_angle(0)
|
||||
climb_gauge:set_attach(self.object,'',supercub_GAUGE_CLIMBER_POSITION,{x=0,y=0,z=climb_angle})
|
||||
self.climb_gauge = climb_gauge
|
||||
|
||||
local speed_gauge=minetest.add_entity(pos,'supercub:pointer')
|
||||
local speed_angle = supercub.get_gauge_angle(100)
|
||||
speed_gauge:set_attach(self.object,'',supercub_GAUGE_SPEED_POSITION,{x=0,y=0,z=speed_angle})
|
||||
self.speed_gauge = speed_gauge
|
||||
|
||||
local pilot_seat_base=minetest.add_entity(pos,'supercub:seat_base')
|
||||
pilot_seat_base:set_attach(self.object,'',{x=0,y=-4,z=2},{x=0,y=0,z=0})
|
||||
self.pilot_seat_base = pilot_seat_base
|
||||
|
||||
local passenger_seat_base=minetest.add_entity(pos,'supercub:seat_base')
|
||||
passenger_seat_base:set_attach(self.object,'',{x=0,y=-5,z=-6},{x=0,y=0,z=0})
|
||||
self.passenger_seat_base = passenger_seat_base
|
||||
|
||||
local stick=minetest.add_entity(pos,'supercub:stick')
|
||||
stick:set_attach(self.object,'',{x=0,y=-6.85,z=8},{x=0,y=0,z=0})
|
||||
self.stick = stick
|
||||
|
||||
supercub.paint(self, self.object, self._color, "supercub_painting.png")
|
||||
supercub.paint(self, self.elevator, self._color, "supercub_painting.png")
|
||||
supercub.paint(self, self.rudder, self._color, "supercub_painting.png")
|
||||
supercub.paint(self, self.right_aileron, self._color, "supercub_painting.png")
|
||||
supercub.paint(self, self.left_aileron, self._color, "supercub_painting.png")
|
||||
|
||||
self.object:set_armor_groups({immortal=1})
|
||||
end,
|
||||
|
||||
--on_step = mobkit.stepfunc,
|
||||
on_step = function(self,dtime,colinfo)
|
||||
self.dtime = math.min(dtime,0.2)
|
||||
self.colinfo = colinfo
|
||||
self.height = mobkit.get_box_height(self)
|
||||
|
||||
-- physics comes first
|
||||
local vel = self.object:get_velocity()
|
||||
|
||||
if colinfo then
|
||||
self.isonground = colinfo.touching_ground
|
||||
else
|
||||
if self.lastvelocity.y==0 and vel.y==0 then
|
||||
self.isonground = true
|
||||
else
|
||||
self.isonground = false
|
||||
end
|
||||
end
|
||||
|
||||
self:physics()
|
||||
|
||||
if self.logic then
|
||||
self:logic()
|
||||
end
|
||||
|
||||
self.lastvelocity = self.object:get_velocity()
|
||||
self.time_total=self.time_total+self.dtime
|
||||
end,
|
||||
logic = supercub.flightstep,
|
||||
|
||||
on_punch = function(self, puncher, ttime, toolcaps, dir, damage)
|
||||
if not puncher or not puncher:is_player() then
|
||||
return
|
||||
end
|
||||
|
||||
local is_admin = false
|
||||
is_admin = minetest.check_player_privs(puncher, {server=true})
|
||||
local name = puncher:get_player_name()
|
||||
if self.owner and self.owner ~= name and self.owner ~= "" then
|
||||
if is_admin == false then return end
|
||||
end
|
||||
if self.owner == nil then
|
||||
self.owner = name
|
||||
end
|
||||
|
||||
if self.driver_name and self.driver_name ~= name then
|
||||
-- do not allow other players to remove the object while there is a driver
|
||||
return
|
||||
end
|
||||
|
||||
local is_attached = false
|
||||
if puncher:get_attach() == self.object then is_attached = true end
|
||||
|
||||
local itmstck=puncher:get_wielded_item()
|
||||
local item_name = ""
|
||||
if itmstck then item_name = itmstck:get_name() end
|
||||
|
||||
if is_attached == false then
|
||||
if supercub.loadFuel(self, puncher:get_player_name()) then
|
||||
return
|
||||
end
|
||||
|
||||
--repair
|
||||
if (item_name == "airutils:repair_tool" or item_name == "trike:repair_tool")
|
||||
and self._engine_running == false then
|
||||
if self.hp_max < 50 then
|
||||
local inventory_item = "default:steel_ingot"
|
||||
local inv = puncher:get_inventory()
|
||||
if inv:contains_item("main", inventory_item) then
|
||||
local stack = ItemStack(inventory_item .. " 1")
|
||||
inv:remove_item("main", stack)
|
||||
self.hp_max = self.hp_max + 10
|
||||
if self.hp_max > 50 then self.hp_max = 50 end
|
||||
supercub.setText(self)
|
||||
else
|
||||
minetest.chat_send_player(puncher:get_player_name(), "You need steel ingots in your inventory to perform this repair.")
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
-- deal with painting or destroying
|
||||
if itmstck then
|
||||
local _,indx = item_name:find('dye:')
|
||||
if indx then
|
||||
|
||||
--lets paint!!!!
|
||||
local color = item_name:sub(indx+1)
|
||||
local colstr = supercub.colors[color]
|
||||
--minetest.chat_send_all(color ..' '.. dump(colstr))
|
||||
if colstr then
|
||||
supercub.paint(self, self.object, colstr, "supercub_painting.png")
|
||||
supercub.paint(self, self.elevator, colstr, "supercub_painting.png")
|
||||
supercub.paint(self, self.rudder, colstr, "supercub_painting.png")
|
||||
supercub.paint(self, self.right_aileron, colstr, "supercub_painting.png")
|
||||
supercub.paint(self, self.left_aileron, colstr, "supercub_painting.png")
|
||||
itmstck:set_count(itmstck:get_count()-1)
|
||||
puncher:set_wielded_item(itmstck)
|
||||
end
|
||||
-- end painting
|
||||
|
||||
else -- deal damage
|
||||
if not self.driver and toolcaps and toolcaps.damage_groups
|
||||
and toolcaps.damage_groups.fleshy and item_name ~= supercub.fuel then
|
||||
--mobkit.hurt(self,toolcaps.damage_groups.fleshy - 1)
|
||||
--mobkit.make_sound(self,'hit')
|
||||
self.hp_max = self.hp_max - 10
|
||||
minetest.sound_play("collision", {
|
||||
object = self.object,
|
||||
max_hear_distance = 5,
|
||||
gain = 1.0,
|
||||
fade = 0.0,
|
||||
pitch = 1.0,
|
||||
})
|
||||
supercub.setText(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if self.hp_max <= 0 then
|
||||
supercub.destroy(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end,
|
||||
|
||||
on_rightclick = function(self, clicker)
|
||||
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
|
||||
|
||||
--check if is the owner
|
||||
if self.owner == name then
|
||||
-- pilot section
|
||||
local can_access = true
|
||||
if supercub.restricted == "true" then
|
||||
can_access = minetest.check_player_privs(clicker, {flight_licence=true})
|
||||
end
|
||||
if can_access then
|
||||
if name == self.driver_name then
|
||||
--=========================
|
||||
-- dettach player
|
||||
--=========================
|
||||
-- eject passenger if the plane is on ground
|
||||
local touching_ground, liquid_below = supercub.check_node_below(self.object)
|
||||
if self.isinliquid or touching_ground or liquid_below then --isn't flying?
|
||||
--ok, remove pax
|
||||
if self._passenger then
|
||||
local passenger = minetest.get_player_by_name(self._passenger)
|
||||
if passenger then supercub.dettach_pax(self, passenger) end
|
||||
end
|
||||
else
|
||||
--give the control to the pax
|
||||
if self._passenger then
|
||||
self._autopilot = false
|
||||
supercub.transfer_control(self, true)
|
||||
end
|
||||
end
|
||||
self._instruction_mode = false
|
||||
supercub.dettachPlayer(self, clicker)
|
||||
--[[ sound and animation
|
||||
if self.sound_handle then
|
||||
minetest.sound_stop(self.sound_handle)
|
||||
self.sound_handle = nil
|
||||
end
|
||||
self.engine:set_animation_frame_speed(0)]]--
|
||||
elseif not self.driver_name then
|
||||
--=========================
|
||||
-- attach player
|
||||
--=========================
|
||||
--attach player
|
||||
local is_under_water = supercub.check_is_under_water(self.object)
|
||||
if is_under_water then return end
|
||||
|
||||
--remove pax to prevent bug
|
||||
if self._passenger then
|
||||
local passenger = minetest.get_player_by_name(self._passenger)
|
||||
if passenger then supercub.dettach_pax(self, passenger) end
|
||||
end
|
||||
|
||||
if clicker:get_player_control().sneak == true then
|
||||
-- flight instructor mode
|
||||
self._instruction_mode = true
|
||||
supercub.attach(self, clicker, true)
|
||||
else
|
||||
-- no driver => clicker is new driver
|
||||
self._instruction_mode = false
|
||||
supercub.attach(self, clicker)
|
||||
end
|
||||
self._command_is_given = false
|
||||
end
|
||||
else
|
||||
minetest.show_formspec(name, "supercub:flightlicence",
|
||||
"size[4,2]" ..
|
||||
"label[0.0,0.0;Sorry ...]"..
|
||||
"label[0.0,0.7;You need a flight licence to fly it.]" ..
|
||||
"label[0.0,1.0;You must obtain it from server admin.]" ..
|
||||
"button_exit[1.5,1.9;0.9,0.1;e;Exit]")
|
||||
end
|
||||
-- end pilot section
|
||||
else
|
||||
--passenger section
|
||||
--only can enter when the pilot is inside
|
||||
local message = core.colorize('#ff0000', " >>> You aren't the owner of this airplane.")
|
||||
if self.driver_name ~= nil then
|
||||
local player = minetest.get_player_by_name(self.driver_name)
|
||||
if player then
|
||||
if self._passenger == nil then
|
||||
supercub.attach_pax(self, clicker)
|
||||
else
|
||||
supercub.dettach_pax(self, clicker)
|
||||
end
|
||||
else
|
||||
minetest.chat_send_player(clicker:get_player_name(), message)
|
||||
end
|
||||
else
|
||||
minetest.chat_send_player(clicker:get_player_name(), message)
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
|
@ -0,0 +1,55 @@
|
|||
function supercub.contains(table, val)
|
||||
for k,v in pairs(table) do
|
||||
if k == val then
|
||||
return v
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function supercub.loadFuel(self, player_name)
|
||||
local player = minetest.get_player_by_name(player_name)
|
||||
local inv = player:get_inventory()
|
||||
|
||||
local itmstck=player:get_wielded_item()
|
||||
local item_name = ""
|
||||
if itmstck then item_name = itmstck:get_name() end
|
||||
|
||||
local fuel = supercub.contains(supercub.fuel, item_name)
|
||||
if fuel then
|
||||
local stack = ItemStack(item_name .. " 1")
|
||||
|
||||
if self._energy < 10 then
|
||||
inv:remove_item("main", stack)
|
||||
self._energy = self._energy + fuel
|
||||
if self._energy > 10 then self._energy = 10 end
|
||||
|
||||
local energy_indicator_angle = supercub.get_gauge_angle(self._energy)
|
||||
self.fuel_gauge:set_attach(self.object,'',SUPERCUB_GAUGE_FUEL_POSITION,{x=0,y=0,z=energy_indicator_angle})
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function supercub.consumptionCalc(self, accel)
|
||||
if accel == nil then return end
|
||||
if self._energy > 0 and self._engine_running and accel ~= nil then
|
||||
local consumed_power = self._power_lever/700000
|
||||
--minetest.chat_send_all('consumed: '.. consumed_power)
|
||||
self._energy = self._energy - consumed_power;
|
||||
|
||||
local energy_indicator_angle = supercub.get_gauge_angle(self._energy)
|
||||
if self.fuel_gauge:get_luaentity() then
|
||||
self.fuel_gauge:set_attach(self.object,'',SUPERCUB_GAUGE_FUEL_POSITION,{x=0,y=0,z=energy_indicator_angle})
|
||||
end
|
||||
end
|
||||
if self._energy <= 0 and self._engine_running and accel ~= nil then
|
||||
self._engine_running = false
|
||||
self._autopilot = false
|
||||
if self.sound_handle then minetest.sound_stop(self.sound_handle) end
|
||||
self.engine:set_animation_frame_speed(0)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,13 @@
|
|||
--
|
||||
-- constants
|
||||
--
|
||||
SUPERCUB_LONGIT_DRAG_FACTOR = 0.13*0.13
|
||||
SUPERCUB_LATER_DRAG_FACTOR = 2.0
|
||||
|
||||
deg = math.deg
|
||||
abs = math.abs
|
||||
|
||||
SUPERCUB_GAUGE_FUEL_POSITION = {x=2.35,y=0.05,z=10.64}
|
||||
SUPERCUB_GAUGE_POWER_POSITION = {x=2.35,y=1.55,z=10.64}
|
||||
SUPERCUB_GAUGE_CLIMBER_POSITION = {x=-2.05,y=1.40,z=10.64}
|
||||
SUPERCUB_GAUGE_SPEED_POSITION = {x=-0.25,y=1.40,z=10.64}
|
|
@ -0,0 +1,216 @@
|
|||
supercub.hud_list = {}
|
||||
|
||||
function supercub.animate_gauge(player, ids, prefix, x, y, angle)
|
||||
local angle_in_rad = math.rad(angle + 180)
|
||||
local dim = 10
|
||||
local pos_x = math.sin(angle_in_rad) * dim
|
||||
local pos_y = math.cos(angle_in_rad) * dim
|
||||
player:hud_change(ids[prefix .. "2"], "offset", {x = pos_x + x, y = pos_y + y})
|
||||
dim = 20
|
||||
pos_x = math.sin(angle_in_rad) * dim
|
||||
pos_y = math.cos(angle_in_rad) * dim
|
||||
player:hud_change(ids[prefix .. "3"], "offset", {x = pos_x + x, y = pos_y + y})
|
||||
dim = 30
|
||||
pos_x = math.sin(angle_in_rad) * dim
|
||||
pos_y = math.cos(angle_in_rad) * dim
|
||||
player:hud_change(ids[prefix .. "4"], "offset", {x = pos_x + x, y = pos_y + y})
|
||||
dim = 40
|
||||
pos_x = math.sin(angle_in_rad) * dim
|
||||
pos_y = math.cos(angle_in_rad) * dim
|
||||
player:hud_change(ids[prefix .. "5"], "offset", {x = pos_x + x, y = pos_y + y})
|
||||
dim = 50
|
||||
pos_x = math.sin(angle_in_rad) * dim
|
||||
pos_y = math.cos(angle_in_rad) * dim
|
||||
player:hud_change(ids[prefix .. "6"], "offset", {x = pos_x + x, y = pos_y + y})
|
||||
dim = 60
|
||||
pos_x = math.sin(angle_in_rad) * dim
|
||||
pos_y = math.cos(angle_in_rad) * dim
|
||||
player:hud_change(ids[prefix .. "7"], "offset", {x = pos_x + x, y = pos_y + y})
|
||||
end
|
||||
|
||||
function supercub.update_hud(player, climb, speed)
|
||||
local player_name = player:get_player_name()
|
||||
|
||||
local screen_pos_y = -150
|
||||
local screen_pos_x = 10
|
||||
|
||||
local clb_gauge_x = screen_pos_x + 80
|
||||
local clb_gauge_y = screen_pos_y + 5
|
||||
local sp_gauge_x = screen_pos_x + 180
|
||||
local sp_gauge_y = clb_gauge_y
|
||||
|
||||
local ids = supercub.hud_list[player_name]
|
||||
if ids then
|
||||
supercub.animate_gauge(player, ids, "clb_pt_", clb_gauge_x, clb_gauge_y, climb)
|
||||
supercub.animate_gauge(player, ids, "sp_pt_", sp_gauge_x, sp_gauge_y, speed)
|
||||
else
|
||||
ids = {}
|
||||
|
||||
ids["title"] = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = screen_pos_x +140, y = screen_pos_y -100},
|
||||
text = "Flight Information",
|
||||
alignment = 0,
|
||||
scale = { x = 100, y = 30},
|
||||
number = 0xFFFFFF,
|
||||
})
|
||||
|
||||
ids["bg"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = screen_pos_x, y = screen_pos_y},
|
||||
text = "supercub_hud_panel.png",
|
||||
scale = { x = 0.5, y = 0.5},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
|
||||
ids["clb_pt_1"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = clb_gauge_x, y = clb_gauge_y},
|
||||
text = "supercub_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
|
||||
ids["clb_pt_2"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = clb_gauge_x, y = clb_gauge_y},
|
||||
text = "supercub_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["clb_pt_3"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = clb_gauge_x, y = clb_gauge_y},
|
||||
text = "supercub_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["clb_pt_4"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = clb_gauge_x, y = clb_gauge_y},
|
||||
text = "supercub_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["clb_pt_5"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = clb_gauge_x, y = clb_gauge_y},
|
||||
text = "supercub_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["clb_pt_6"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = clb_gauge_x, y = clb_gauge_y},
|
||||
text = "supercub_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["clb_pt_7"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = clb_gauge_x, y = clb_gauge_y},
|
||||
text = "supercub_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
|
||||
ids["sp_pt_1"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = sp_gauge_x, y = sp_gauge_y},
|
||||
text = "supercub_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["sp_pt_2"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = sp_gauge_x, y = sp_gauge_y},
|
||||
text = "supercub_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["sp_pt_3"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = sp_gauge_x, y = sp_gauge_y},
|
||||
text = "supercub_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["sp_pt_4"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = sp_gauge_x, y = sp_gauge_y},
|
||||
text = "supercub_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["sp_pt_5"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = sp_gauge_x, y = sp_gauge_y},
|
||||
text = "supercub_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["sp_pt_6"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = sp_gauge_x, y = sp_gauge_y},
|
||||
text = "supercub_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
ids["sp_pt_7"] = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = 0, y = 1},
|
||||
offset = {x = sp_gauge_x, y = sp_gauge_y},
|
||||
text = "supercub_ind_box.png",
|
||||
scale = { x = 6, y = 6},
|
||||
alignment = { x = 1, y = 0 },
|
||||
})
|
||||
|
||||
supercub.hud_list[player_name] = ids
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function supercub.remove_hud(player)
|
||||
if player then
|
||||
local player_name = player:get_player_name()
|
||||
--minetest.chat_send_all(player_name)
|
||||
local ids = supercub.hud_list[player_name]
|
||||
if ids then
|
||||
--player:hud_remove(ids["altitude"])
|
||||
--player:hud_remove(ids["time"])
|
||||
player:hud_remove(ids["title"])
|
||||
player:hud_remove(ids["bg"])
|
||||
player:hud_remove(ids["clb_pt_7"])
|
||||
player:hud_remove(ids["clb_pt_6"])
|
||||
player:hud_remove(ids["clb_pt_5"])
|
||||
player:hud_remove(ids["clb_pt_4"])
|
||||
player:hud_remove(ids["clb_pt_3"])
|
||||
player:hud_remove(ids["clb_pt_2"])
|
||||
player:hud_remove(ids["clb_pt_1"])
|
||||
player:hud_remove(ids["sp_pt_7"])
|
||||
player:hud_remove(ids["sp_pt_6"])
|
||||
player:hud_remove(ids["sp_pt_5"])
|
||||
player:hud_remove(ids["sp_pt_4"])
|
||||
player:hud_remove(ids["sp_pt_3"])
|
||||
player:hud_remove(ids["sp_pt_2"])
|
||||
player:hud_remove(ids["sp_pt_1"])
|
||||
end
|
||||
supercub.hud_list[player_name] = nil
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,176 @@
|
|||
dofile(minetest.get_modpath("supercub") .. DIR_DELIM .. "supercub_global_definitions.lua")
|
||||
|
||||
--------------
|
||||
-- Manual --
|
||||
--------------
|
||||
|
||||
function supercub.manual_formspec(name)
|
||||
local basic_form = table.concat({
|
||||
"formspec_version[3]",
|
||||
"size[16,10]",
|
||||
"background[-0.7,-0.5;17.5,11.5;supercub_manual_bg.png]"
|
||||
}, "")
|
||||
|
||||
basic_form = basic_form.."button[1.75,1.5;4,1;short;Shortcuts]"
|
||||
basic_form = basic_form.."button[1.75,3.5;4,1;panel;Panel]"
|
||||
basic_form = basic_form.."button[1.75,5.5;4,1;fuel;Refueling]"
|
||||
basic_form = basic_form.."button[1.75,7.5;4,1;op;Operation]"
|
||||
basic_form = basic_form.."button[10.25,1.5;4,1;paint;Painting]"
|
||||
basic_form = basic_form.."button[10.25,3.5;4,1;tips;Tips]"
|
||||
|
||||
minetest.show_formspec(name, "supercub:manual_main", basic_form)
|
||||
end
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname == "supercub:manual_main" then
|
||||
if fields.short then
|
||||
local text = {
|
||||
"Shortcuts \n\n",
|
||||
"* Right click: enter in/get off plane \n",
|
||||
"* Left click (with biofuel): add fuel to plane \n",
|
||||
"* Right click and Sneak: enter in flight instructor mode (limited \n",
|
||||
" vision, so use external camera) \n",
|
||||
"* E (aux1): Start/stop engine \n",
|
||||
"* Jump: Increase power, forward on ground \n",
|
||||
"* Sneak: Decrease power, brake on ground \n",
|
||||
"* Backward: go up flying - nose up \n",
|
||||
"* Forward: go down flying - nose down \n",
|
||||
"* Left/right: Turn to left/right, work on and out ground. \n",
|
||||
"* Left and Right together: center all commands \n",
|
||||
"* Sneak and Jump together (normal): activates the autopilot \n",
|
||||
"* Sneak and Jump together (instruction mode): give/take the \n",
|
||||
" controls to/from pilot student \n",
|
||||
"* Up and Down together: enable/disable HUD"
|
||||
}
|
||||
local shortcut_form = table.concat({
|
||||
"formspec_version[3]",
|
||||
"size[16,10]",
|
||||
"background[-0.7,-0.5;17.5,11.5;supercub_manual_bg.png]",
|
||||
"image[0.5,3.75;6,6;supercub_manual_up_view.png]",
|
||||
"label[9.25,0.5;", table.concat(text, ""), "]",
|
||||
}, "")
|
||||
minetest.show_formspec(player:get_player_name(), "supercub:manual_shortcut", shortcut_form)
|
||||
end
|
||||
if fields.panel then
|
||||
local text = {
|
||||
"The Panel \n\n",
|
||||
"In front of the pilot is the instrument panel. \n",
|
||||
"It's used to obtain important flight information, namely: \n",
|
||||
"rate of climb/descent, speed, power applied and fuel level. \n\n",
|
||||
"The climber is the instrument that indicates the rate \n",
|
||||
" of climb and descent, it's on the left of the panel, \n",
|
||||
" marked with the letter C in blue. \n",
|
||||
"The speed indicator indicates the longitudinal speed of the \n",
|
||||
" aircraft. It's on the center of the panel and is marked \n",
|
||||
" with the letter S in white. \n",
|
||||
"The power gauge indicates the power applied to the engine. \n",
|
||||
"It's at upper right position of the panel, with an yellow P. \n",
|
||||
"The fuel gauge, located on the right and below, indicates the \n",
|
||||
"fuel available on the aircraft. It's marked with the green F."
|
||||
}
|
||||
local panel_form = table.concat({
|
||||
"formspec_version[3]",
|
||||
"size[16,10]",
|
||||
"background[-0.7,-0.5;17.5,11.5;supercub_manual_bg.png]",
|
||||
"image[0.2,1.75;7,7;supercub_manual_panel.png]",
|
||||
"label[9.25,0.5;", table.concat(text, ""), "]",
|
||||
}, "")
|
||||
minetest.show_formspec(player:get_player_name(), "supercub:manual_panel", panel_form)
|
||||
end
|
||||
if fields.fuel then
|
||||
local text = {
|
||||
"Fuel \n\n",
|
||||
"To fly, the aircraft needs fuel for its engine. So it is \n",
|
||||
"necessary to supply it. To do this, it is necessary to \n",
|
||||
"have the selected fuel in hand and punch it in the float. \n",
|
||||
"Depending on the fuel mod used and which container, a \n",
|
||||
"greater or lesser number of fuel units may be required to \n",
|
||||
"fill the tank. In the case of the Lokrates biofuel mod, \n",
|
||||
"with 10 bottles it is possible to fill the tank. With the \n",
|
||||
"vial, 40 units will be needed. \n",
|
||||
"Don't forget to check the fuel gauge on the panel."
|
||||
}
|
||||
local fuel_form = table.concat({
|
||||
"formspec_version[3]",
|
||||
"size[16,10]",
|
||||
"background[-0.7,-0.5;17.5,11.5;supercub_manual_bg.png]",
|
||||
"image[2,3.75;4,2;supercub_manual_fuel.png]",
|
||||
"label[9.25,0.5;", table.concat(text, ""), "]",
|
||||
}, "")
|
||||
minetest.show_formspec(player:get_player_name(), "supercub:fuel", fuel_form)
|
||||
end
|
||||
if fields.op then
|
||||
local text = {
|
||||
"Operation \n\n",
|
||||
"The aircraft can operate directly from the water or land. \n",
|
||||
"When operating on land the landing gear will \n",
|
||||
"automatically extend. \n",
|
||||
"When boarding the aircraft, centralize the commands (A \n",
|
||||
"and D keys), press E to start the engine and hold Jump \n",
|
||||
"until full power. When the speed reaches the green range, \n",
|
||||
"lightly pull the stick using the S key. Always keep the \n",
|
||||
"speed within the green range to avoid stalling. To land, \n",
|
||||
"remove all power, but keep the speed at the limit \n",
|
||||
"between the green and white range. \n",
|
||||
"When you are about to touch the soil or water, lightly pull \n",
|
||||
"the stick to level and touch it gently. It's possible to \n",
|
||||
"operate with an external camera, activating the HUD. \n",
|
||||
"The autopilot (jump and sneak) only keeps the airplane at the \n",
|
||||
"activation level, limited by power and designed ceiling. \n",
|
||||
"It's possible for a passenger to board the aircraft, just \n",
|
||||
"click the right button on the floater. But the passenger \n",
|
||||
"will only be able to enter if the pilot has already boarded."
|
||||
}
|
||||
local op_form = table.concat({
|
||||
"formspec_version[3]",
|
||||
"size[16,10]",
|
||||
"background[-0.7,-0.5;17.5,11.5;supercub_manual_bg.png]",
|
||||
"image[0.5,1.75;6,6;supercub_manual_side_view.png]",
|
||||
"label[9.25,0.25;", table.concat(text, ""), "]",
|
||||
}, "")
|
||||
minetest.show_formspec(player:get_player_name(), "supercub:op", op_form)
|
||||
end
|
||||
if fields.paint then
|
||||
local text = {
|
||||
"Painting \n\n",
|
||||
"Painting the aircraft is quite simple. It works in the same \n",
|
||||
"way as the fuel supply, but instead of using fuel to punch \n",
|
||||
"the floater, use a dye of the chosen color."
|
||||
}
|
||||
local paint_form = table.concat({
|
||||
"formspec_version[3]",
|
||||
"size[16,10]",
|
||||
"background[-0.7,-0.5;17.5,11.5;supercub_manual_colors.png]",
|
||||
"label[9.25,0.5;", table.concat(text, ""), "]",
|
||||
}, "")
|
||||
minetest.show_formspec(player:get_player_name(), "supercub:paint", paint_form)
|
||||
end
|
||||
if fields.tips then
|
||||
local text = {
|
||||
"Tips \n\n",
|
||||
"* During a stall, centralize the controls (A + D shortcut) \n",
|
||||
" and apply maximum power, then gently pull the control. \n",
|
||||
"* The \"repair tool\" can repair damage suffered by the \n",
|
||||
" aircraft. To use it, have some steel ingots in the \n",
|
||||
" inventory, which will be subtracted for repair \n",
|
||||
"* There is a turbo mode that can be used for long climbs, \n",
|
||||
" just hold the jump key. But be careful with the angle of \n",
|
||||
" attack, because even with full power it is not possible to \n",
|
||||
" climb with an angle of attack that is too high. \n",
|
||||
"* When boarding as a flight instructor, use \n",
|
||||
" the external camera with the hud on. \n",
|
||||
"* As an instructor, only pass control to the student at \n",
|
||||
" altitudes that allow time for reaction, unless you \n",
|
||||
" already trust that student.",
|
||||
}
|
||||
local tips_form = table.concat({
|
||||
"formspec_version[3]",
|
||||
"size[16,10]",
|
||||
"background[-0.7,-0.5;17.5,11.5;supercub_manual_bg.png]",
|
||||
"label[0.5,0.5;", table.concat(text, ""), "]",
|
||||
}, "")
|
||||
minetest.show_formspec(player:get_player_name(), "supercub:tips", tips_form)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
|
@ -0,0 +1,744 @@
|
|||
dofile(minetest.get_modpath("supercub") .. DIR_DELIM .. "supercub_global_definitions.lua")
|
||||
dofile(minetest.get_modpath("supercub") .. DIR_DELIM .. "supercub_hud.lua")
|
||||
|
||||
function supercub.get_hipotenuse_value(point1, point2)
|
||||
return math.sqrt((point1.x - point2.x) ^ 2 + (point1.y - point2.y) ^ 2 + (point1.z - point2.z) ^ 2)
|
||||
end
|
||||
|
||||
function supercub.dot(v1,v2)
|
||||
return v1.x*v2.x+v1.y*v2.y+v1.z*v2.z
|
||||
end
|
||||
|
||||
function supercub.sign(n)
|
||||
return n>=0 and 1 or -1
|
||||
end
|
||||
|
||||
function supercub.minmax(v,m)
|
||||
return math.min(math.abs(v),m)*supercub.sign(v)
|
||||
end
|
||||
|
||||
--lift
|
||||
local function pitchroll2pitchyaw(aoa,roll)
|
||||
if roll == 0.0 then return aoa,0 end
|
||||
-- assumed vector x=0,y=0,z=1
|
||||
local p1 = math.tan(aoa)
|
||||
local y = math.cos(roll)*p1
|
||||
local x = math.sqrt(p1^2-y^2)
|
||||
local pitch = math.atan(y)
|
||||
local yaw=math.atan(x)*math.sign(roll)
|
||||
return pitch,yaw
|
||||
end
|
||||
|
||||
function supercub.getLiftAccel(self, velocity, accel, longit_speed, roll, curr_pos)
|
||||
--lift calculations
|
||||
-----------------------------------------------------------
|
||||
local max_height = 15000
|
||||
|
||||
local retval = accel
|
||||
if longit_speed > 1 then
|
||||
local angle_of_attack = math.rad(self._angle_of_attack + supercub.wing_angle_of_attack)
|
||||
local lift = supercub.lift
|
||||
--local acc = 0.8
|
||||
local daoa = deg(angle_of_attack)
|
||||
|
||||
--to decrease the lift coefficient at hight altitudes
|
||||
local curr_percent_height = (100 - ((curr_pos.y * 100) / max_height))/100
|
||||
|
||||
local rotation=self.object:get_rotation()
|
||||
local vrot = mobkit.dir_to_rot(velocity,rotation)
|
||||
|
||||
local hpitch,hyaw = pitchroll2pitchyaw(angle_of_attack,roll)
|
||||
|
||||
local hrot = {x=vrot.x+hpitch,y=vrot.y-hyaw,z=roll}
|
||||
local hdir = mobkit.rot_to_dir(hrot) --(hrot)
|
||||
local cross = vector.cross(velocity,hdir)
|
||||
local lift_dir = vector.normalize(vector.cross(cross,hdir))
|
||||
|
||||
local lift_coefficient = (0.24*abs(daoa)*(1/(0.025*daoa+3))^4*math.sign(angle_of_attack))
|
||||
local lift_val = math.abs((lift*(vector.length(velocity)^2)*lift_coefficient)*curr_percent_height)
|
||||
--minetest.chat_send_all('lift: '.. lift_val)
|
||||
|
||||
local lift_acc = vector.multiply(lift_dir,lift_val)
|
||||
--lift_acc=vector.add(vector.multiply(minetest.yaw_to_dir(rotation.y),acc),lift_acc)
|
||||
|
||||
retval = vector.add(retval,lift_acc)
|
||||
end
|
||||
-----------------------------------------------------------
|
||||
-- end lift
|
||||
return retval
|
||||
end
|
||||
|
||||
|
||||
function supercub.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
|
||||
|
||||
-- attach player
|
||||
function supercub.attach(self, player, instructor_mode)
|
||||
instructor_mode = instructor_mode or false
|
||||
local name = player:get_player_name()
|
||||
self.driver_name = name
|
||||
|
||||
-- attach the driver
|
||||
if instructor_mode == true then
|
||||
player:set_attach(self.passenger_seat_base, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
||||
player:set_eye_offset({x = 0, y = -2.5, z = 2}, {x = 0, y = 1, z = -30})
|
||||
else
|
||||
player:set_attach(self.pilot_seat_base, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
||||
player:set_eye_offset({x = 0, y = -4, z = 2}, {x = 0, y = 1, z = -30})
|
||||
end
|
||||
player:set_eye_offset({x = 0, y = -4, z = 2}, {x = 0, y = 1, z = -30})
|
||||
player_api.player_attached[name] = true
|
||||
-- make the driver sit
|
||||
minetest.after(0.2, function()
|
||||
player = minetest.get_player_by_name(name)
|
||||
if player then
|
||||
player_api.set_animation(player, "sit")
|
||||
--apply_physics_override(player, {speed=0,gravity=0,jump=0})
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- attach passenger
|
||||
function supercub.attach_pax(self, player)
|
||||
local name = player:get_player_name()
|
||||
self._passenger = name
|
||||
|
||||
-- attach the driver
|
||||
if self._instruction_mode == true then
|
||||
player:set_attach(self.pilot_seat_base, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
||||
player:set_eye_offset({x = 0, y = -4, z = 2}, {x = 0, y = 3, z = -30})
|
||||
else
|
||||
player:set_attach(self.passenger_seat_base, "", {x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
||||
player:set_eye_offset({x = 0, y = -2.5, z = 2}, {x = 0, y = 3, z = -30})
|
||||
end
|
||||
player_api.player_attached[name] = true
|
||||
-- make the driver sit
|
||||
minetest.after(0.2, function()
|
||||
player = minetest.get_player_by_name(name)
|
||||
if player then
|
||||
player_api.set_animation(player, "sit")
|
||||
--apply_physics_override(player, {speed=0,gravity=0,jump=0})
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function supercub.dettachPlayer(self, player)
|
||||
local name = self.driver_name
|
||||
supercub.setText(self)
|
||||
|
||||
supercub.remove_hud(player)
|
||||
|
||||
--self._engine_running = false
|
||||
|
||||
-- driver clicked the object => driver gets off the vehicle
|
||||
self.driver_name = nil
|
||||
|
||||
-- detach the player
|
||||
player:set_detach()
|
||||
player_api.player_attached[name] = nil
|
||||
player:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})
|
||||
player_api.set_animation(player, "stand")
|
||||
self.driver = nil
|
||||
--remove_physics_override(player, {speed=1,gravity=1,jump=1})
|
||||
end
|
||||
|
||||
function supercub.dettach_pax(self, player)
|
||||
local name = self._passenger
|
||||
|
||||
-- passenger clicked the object => driver gets off the vehicle
|
||||
self._passenger = nil
|
||||
|
||||
-- detach the player
|
||||
player:set_detach()
|
||||
player_api.player_attached[name] = nil
|
||||
player_api.set_animation(player, "stand")
|
||||
player:set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})
|
||||
--remove_physics_override(player, {speed=1,gravity=1,jump=1})
|
||||
end
|
||||
|
||||
function supercub.checkAttach(self, player)
|
||||
if player then
|
||||
local player_attach = player:get_attach()
|
||||
if player_attach then
|
||||
if player_attach == self.pilot_seat_base or player_attach == self.passenger_seat_base then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
--painting
|
||||
function supercub.paint(self, object, colstr, search_string)
|
||||
if colstr then
|
||||
self._color = colstr
|
||||
local entity = object:get_luaentity()
|
||||
local l_textures = entity.initial_properties.textures
|
||||
for _, texture in ipairs(l_textures) do
|
||||
local indx = texture:find(search_string)
|
||||
if indx then
|
||||
l_textures[_] = search_string .."^[multiply:".. colstr
|
||||
end
|
||||
end
|
||||
object:set_properties({textures=l_textures})
|
||||
end
|
||||
end
|
||||
|
||||
-- destroy the boat
|
||||
function supercub.destroy(self)
|
||||
if self.sound_handle then
|
||||
minetest.sound_stop(self.sound_handle)
|
||||
self.sound_handle = nil
|
||||
end
|
||||
|
||||
if self._passenger then
|
||||
-- detach the passenger
|
||||
local passenger = minetest.get_player_by_name(self._passenger)
|
||||
if passenger then
|
||||
supercub.dettach_pax(self, passenger)
|
||||
end
|
||||
end
|
||||
|
||||
if self.driver_name then
|
||||
-- detach the driver
|
||||
local player = minetest.get_player_by_name(self.driver_name)
|
||||
supercub.dettachPlayer(self, player)
|
||||
end
|
||||
|
||||
local pos = self.object:get_pos()
|
||||
if self.fuel_gauge then self.fuel_gauge:remove() end
|
||||
if self.power_gauge then self.power_gauge:remove() end
|
||||
if self.climb_gauge then self.climb_gauge:remove() end
|
||||
if self.speed_gauge then self.speed_gauge:remove() end
|
||||
if self.engine then self.engine:remove() end
|
||||
if self.pilot_seat_base then self.pilot_seat_base:remove() end
|
||||
if self.passenger_seat_base then self.passenger_seat_base:remove() end
|
||||
|
||||
if self.elevator then self.elevator:remove() end
|
||||
if self.rudder then self.rudder:remove() end
|
||||
if self.right_aileron then self.right_aileron:remove() end
|
||||
if self.left_aileron then self.left_aileron:remove() end
|
||||
|
||||
if self.stick then self.stick:remove() end
|
||||
|
||||
self.object:remove()
|
||||
|
||||
pos.y=pos.y+2
|
||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'hidroplane:wings')
|
||||
|
||||
for i=1,5 do
|
||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'default:tin_ingot')
|
||||
end
|
||||
|
||||
for i=1,6 do
|
||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'default:steel_ingot')
|
||||
end
|
||||
|
||||
for i=1,2 do
|
||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'wool:white')
|
||||
end
|
||||
|
||||
for i=1,6 do
|
||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'default:mese_crystal')
|
||||
minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'default:diamond')
|
||||
end
|
||||
|
||||
--minetest.add_item({x=pos.x+math.random()-0.5,y=pos.y,z=pos.z+math.random()-0.5},'hidroplane:hidro')
|
||||
end
|
||||
|
||||
function supercub.check_node_below(obj)
|
||||
local pos_below = obj:get_pos()
|
||||
if pos_below then
|
||||
pos_below.y = pos_below.y - 2.5
|
||||
local node_below = minetest.get_node(pos_below).name
|
||||
local nodedef = minetest.registered_nodes[node_below]
|
||||
local touching_ground = not nodedef or -- unknown nodes are solid
|
||||
nodedef.walkable or false
|
||||
local liquid_below = not touching_ground and nodedef.liquidtype ~= "none"
|
||||
return touching_ground, liquid_below
|
||||
end
|
||||
return nil, nil
|
||||
end
|
||||
|
||||
function supercub.setText(self)
|
||||
local properties = self.object:get_properties()
|
||||
local formatted = string.format(
|
||||
"%.2f", self.hp_max
|
||||
)
|
||||
if properties then
|
||||
properties.infotext = "Nice hydroplane of " .. self.owner .. ". Current hp: " .. formatted
|
||||
self.object:set_properties(properties)
|
||||
end
|
||||
end
|
||||
|
||||
function supercub.testImpact(self, velocity, position)
|
||||
local p = position --self.object:get_pos()
|
||||
local collision = false
|
||||
if self._last_vel == nil then return end
|
||||
--lets calculate the vertical speed, to avoid the bug on colliding on floor with hard lag
|
||||
if abs(velocity.y - self._last_vel.y) > 2 then
|
||||
local noded = mobkit.nodeatpos(mobkit.pos_shift(p,{y=-2.8}))
|
||||
if (noded and noded.drawtype ~= 'airlike') then
|
||||
collision = true
|
||||
else
|
||||
self.object:set_velocity(self._last_vel)
|
||||
--self.object:set_acceleration(self._last_accell)
|
||||
self.object:set_velocity(vector.add(velocity, vector.multiply(self._last_accell, self.dtime/8)))
|
||||
end
|
||||
end
|
||||
local impact = abs(supercub.get_hipotenuse_value(velocity, self._last_vel))
|
||||
--minetest.chat_send_all('impact: '.. impact .. ' - hp: ' .. self.hp_max)
|
||||
if impact > 2 then
|
||||
--minetest.chat_send_all('impact: '.. impact .. ' - hp: ' .. self.hp_max)
|
||||
local nodeu = mobkit.nodeatpos(mobkit.pos_shift(p,{y=1}))
|
||||
local noded = mobkit.nodeatpos(mobkit.pos_shift(p,{y=-2.8}))
|
||||
local nodel = mobkit.nodeatpos(mobkit.pos_shift(p,{x=-1}))
|
||||
local noder = mobkit.nodeatpos(mobkit.pos_shift(p,{x=1}))
|
||||
local nodef = mobkit.nodeatpos(mobkit.pos_shift(p,{z=1}))
|
||||
local nodeb = mobkit.nodeatpos(mobkit.pos_shift(p,{z=-1}))
|
||||
if (nodeu and nodeu.drawtype ~= 'airlike') or
|
||||
(nodef and nodef.drawtype ~= 'airlike') or
|
||||
(nodeb and nodeb.drawtype ~= 'airlike') or
|
||||
(noder and noder.drawtype ~= 'airlike') or
|
||||
(nodel and nodel.drawtype ~= 'airlike') then
|
||||
collision = true
|
||||
end
|
||||
end
|
||||
|
||||
if collision then
|
||||
--self.object:set_velocity({x=0,y=0,z=0})
|
||||
local damage = impact / 2
|
||||
self.hp_max = self.hp_max - damage --subtract the impact value directly to hp meter
|
||||
minetest.sound_play("supercub_collision", {
|
||||
--to_player = self.driver_name,
|
||||
object = self.object,
|
||||
max_hear_distance = 15,
|
||||
gain = 1.0,
|
||||
fade = 0.0,
|
||||
pitch = 1.0,
|
||||
}, true)
|
||||
|
||||
if self.driver_name then
|
||||
local player_name = self.driver_name
|
||||
supercub.setText(self)
|
||||
|
||||
--minetest.chat_send_all('damage: '.. damage .. ' - hp: ' .. self.hp_max)
|
||||
if self.hp_max < 0 then --if acumulated damage is greater than 50, adieu
|
||||
supercub.destroy(self)
|
||||
end
|
||||
|
||||
local player = minetest.get_player_by_name(player_name)
|
||||
if player then
|
||||
if player:get_hp() > 0 then
|
||||
player:set_hp(player:get_hp()-(damage/2))
|
||||
end
|
||||
end
|
||||
if self._passenger ~= nil then
|
||||
local passenger = minetest.get_player_by_name(self._passenger)
|
||||
if passenger then
|
||||
if passenger:get_hp() > 0 then
|
||||
passenger:set_hp(passenger:get_hp()-(damage/2))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
function supercub.checkattachBug(self)
|
||||
-- for some engine error the player can be detached from the submarine, so lets set him attached again
|
||||
if self.owner and self.driver_name then
|
||||
-- attach the driver again
|
||||
local player = minetest.get_player_by_name(self.owner)
|
||||
if player then
|
||||
if player:get_hp() > 0 then
|
||||
supercub.attach(self, player, self._instruction_mode)
|
||||
else
|
||||
supercub.dettachPlayer(self, player)
|
||||
end
|
||||
else
|
||||
if self._passenger ~= nil and self._command_is_given == false then
|
||||
self._autopilot = false
|
||||
supercub.transfer_control(self, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function supercub.check_is_under_water(obj)
|
||||
local pos_up = obj:get_pos()
|
||||
pos_up.y = pos_up.y + 0.1
|
||||
local node_up = minetest.get_node(pos_up).name
|
||||
local nodedef = minetest.registered_nodes[node_up]
|
||||
local liquid_up = nodedef.liquidtype ~= "none"
|
||||
return liquid_up
|
||||
end
|
||||
|
||||
function supercub.transfer_control(self, status)
|
||||
if status == false then
|
||||
self._command_is_given = false
|
||||
if self._passenger then
|
||||
minetest.chat_send_player(self._passenger,
|
||||
core.colorize('#ff0000', " >>> The flight instructor got the control."))
|
||||
end
|
||||
if self.driver_name then
|
||||
minetest.chat_send_player(self.driver_name,
|
||||
core.colorize('#00ff00', " >>> The control is with you now."))
|
||||
end
|
||||
else
|
||||
self._command_is_given = true
|
||||
if self._passenger then
|
||||
minetest.chat_send_player(self._passenger,
|
||||
core.colorize('#00ff00', " >>> The control is with you now."))
|
||||
end
|
||||
if self.driver_name then minetest.chat_send_player(self.driver_name," >>> The control was given.") end
|
||||
end
|
||||
end
|
||||
|
||||
function supercub.engineSoundPlay(self)
|
||||
--sound
|
||||
if self.sound_handle then minetest.sound_stop(self.sound_handle) end
|
||||
if self.object then
|
||||
self.sound_handle = minetest.sound_play({name = "supercub_engine"},
|
||||
{object = self.object, gain = 2.0,
|
||||
pitch = 0.5 + ((self._power_lever/100)/2),
|
||||
max_hear_distance = 15,
|
||||
loop = true,})
|
||||
end
|
||||
end
|
||||
|
||||
function supercub.engine_set_sound_and_animation(self)
|
||||
--minetest.chat_send_all('test1 ' .. dump(self._engine_running) )
|
||||
if self._engine_running then
|
||||
if self._last_applied_power ~= self._power_lever then
|
||||
--minetest.chat_send_all('test2')
|
||||
self._last_applied_power = self._power_lever
|
||||
self.engine:set_animation_frame_speed(60 + self._power_lever)
|
||||
supercub.engineSoundPlay(self)
|
||||
end
|
||||
else
|
||||
if self.sound_handle then
|
||||
minetest.sound_stop(self.sound_handle)
|
||||
self.sound_handle = nil
|
||||
self.engine:set_animation_frame_speed(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function supercub.flightstep(self)
|
||||
local velocity = self.object:get_velocity()
|
||||
local curr_pos = self.object:get_pos()
|
||||
|
||||
self._last_time_command = self._last_time_command + self.dtime
|
||||
|
||||
if self._last_time_command > 1 then self._last_time_command = 1 end
|
||||
|
||||
local player = nil
|
||||
if self.driver_name then player = minetest.get_player_by_name(self.driver_name) end
|
||||
local passenger = nil
|
||||
if self._passenger then passenger = minetest.get_player_by_name(self._passenger) end
|
||||
|
||||
if player then
|
||||
local ctrl = player:get_player_control()
|
||||
---------------------
|
||||
-- change the driver
|
||||
---------------------
|
||||
if passenger and self._last_time_command >= 1 and self._instruction_mode == true then
|
||||
if self._command_is_given == true then
|
||||
if ctrl.sneak or ctrl.jump or ctrl.up or ctrl.down or ctrl.right or ctrl.left then
|
||||
self._last_time_command = 0
|
||||
--take the control
|
||||
supercub.transfer_control(self, false)
|
||||
end
|
||||
else
|
||||
if ctrl.sneak == true and ctrl.jump == true then
|
||||
self._last_time_command = 0
|
||||
--trasnfer the control to student
|
||||
supercub.transfer_control(self, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
-----------
|
||||
--autopilot
|
||||
-----------
|
||||
if self._instruction_mode == false and self._last_time_command >= 1 then
|
||||
if self._autopilot == true then
|
||||
if ctrl.sneak or ctrl.jump or ctrl.up or ctrl.down or ctrl.right or ctrl.left then
|
||||
self._last_time_command = 0
|
||||
self._autopilot = false
|
||||
minetest.chat_send_player(self.driver_name," >>> Autopilot deactivated")
|
||||
end
|
||||
else
|
||||
if ctrl.sneak == true and ctrl.jump == true then
|
||||
self._last_time_command = 0
|
||||
self._autopilot = true
|
||||
self._auto_pilot_altitude = curr_pos.y
|
||||
minetest.chat_send_player(self.driver_name,core.colorize('#00ff00', " >>> Autopilot on"))
|
||||
end
|
||||
end
|
||||
end
|
||||
----------------------------------
|
||||
-- shows the hud for the player
|
||||
----------------------------------
|
||||
if ctrl.up == true and ctrl.down == true and self._last_time_command >= 1 then
|
||||
self._last_time_command = 0
|
||||
if self._show_hud == true then
|
||||
self._show_hud = false
|
||||
else
|
||||
self._show_hud = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local accel_y = self.object:get_acceleration().y
|
||||
local rotation = self.object:get_rotation()
|
||||
local yaw = rotation.y
|
||||
local newyaw=yaw
|
||||
local pitch = rotation.x
|
||||
local roll = rotation.z
|
||||
local newroll=roll
|
||||
if newroll > 360 then newroll = newroll - 360 end
|
||||
if newroll < -360 then newroll = newroll + 360 end
|
||||
|
||||
local hull_direction = mobkit.rot_to_dir(rotation) --minetest.yaw_to_dir(yaw)
|
||||
local nhdir = {x=hull_direction.z,y=0,z=-hull_direction.x} -- lateral unit vector
|
||||
|
||||
local longit_speed = vector.dot(velocity,hull_direction)
|
||||
self._longit_speed = longit_speed
|
||||
local longit_drag = vector.multiply(hull_direction,longit_speed*
|
||||
longit_speed*SUPERCUB_LONGIT_DRAG_FACTOR*-1*supercub.sign(longit_speed))
|
||||
local later_speed = supercub.dot(velocity,nhdir)
|
||||
--minetest.chat_send_all('later_speed: '.. later_speed)
|
||||
local later_drag = vector.multiply(nhdir,later_speed*later_speed*
|
||||
SUPERCUB_LATER_DRAG_FACTOR*-1*supercub.sign(later_speed))
|
||||
local accel = vector.add(longit_drag,later_drag)
|
||||
local stop = false
|
||||
|
||||
local node_bellow = mobkit.nodeatpos(mobkit.pos_shift(curr_pos,{y=-1.3}))
|
||||
local is_flying = true
|
||||
if node_bellow and node_bellow.drawtype ~= 'airlike' then is_flying = false end
|
||||
--if is_flying then minetest.chat_send_all('is flying') end
|
||||
|
||||
local is_attached = supercub.checkAttach(self, player)
|
||||
|
||||
--ajustar angulo de ataque
|
||||
local percentage = math.abs(((longit_speed * 100)/(supercub.min_speed + 5))/100)
|
||||
if percentage > 1.5 then percentage = 1.5 end
|
||||
self._angle_of_attack = self._angle_of_attack - ((self._elevator_angle / 20)*percentage)
|
||||
if self._angle_of_attack < -0.5 then
|
||||
self._angle_of_attack = -0.1
|
||||
self._elevator_angle = self._elevator_angle - 0.1
|
||||
end --limiting the negative angle]]--
|
||||
if self._angle_of_attack > 20 then
|
||||
self._angle_of_attack = 20
|
||||
self._elevator_angle = self._elevator_angle + 0.1
|
||||
end --limiting the very high climb angle due to strange behavior]]--
|
||||
|
||||
--minetest.chat_send_all(self._angle_of_attack)
|
||||
|
||||
-- pitch
|
||||
local speed_factor = 0
|
||||
if longit_speed > supercub.min_speed then speed_factor = (velocity.y * math.rad(2)) end
|
||||
local newpitch = math.rad(self._angle_of_attack) + speed_factor
|
||||
|
||||
|
||||
-- adjust pitch at ground
|
||||
local tail_lift_min_speed = 4
|
||||
local tail_lift_max_speed = 8
|
||||
local tail_angle = 12
|
||||
if math.abs(longit_speed) > tail_lift_min_speed then
|
||||
if math.abs(longit_speed) < tail_lift_max_speed then
|
||||
--minetest.chat_send_all(math.abs(longit_speed))
|
||||
local speed_range = tail_lift_max_speed - tail_lift_min_speed
|
||||
percentage = 1-((math.abs(longit_speed) - tail_lift_min_speed)/speed_range)
|
||||
if percentage > 1 then percentage = 1 end
|
||||
if percentage < 0 then percentage = 0 end
|
||||
local angle = tail_angle * percentage
|
||||
local calculated_newpitch = math.rad(angle)
|
||||
if newpitch < calculated_newpitch then newpitch = calculated_newpitch end --ja aproveita o pitch atual se ja estiver cerrto
|
||||
if newpitch > math.rad(tail_angle) then newpitch = math.rad(tail_angle) end --não queremos arrastar o cauda no chão
|
||||
end
|
||||
else
|
||||
if math.abs(longit_speed) < tail_lift_min_speed then
|
||||
newpitch = math.rad(tail_angle)
|
||||
end
|
||||
end
|
||||
|
||||
if is_flying == false then --isn't flying?
|
||||
--animate wheels
|
||||
if math.abs(longit_speed) > 0.1 then
|
||||
self.object:set_animation_frame_speed(longit_speed * 8)
|
||||
else
|
||||
self.object:set_animation_frame_speed(0)
|
||||
end
|
||||
else
|
||||
--stop wheels
|
||||
self.object:set_animation_frame_speed(0)
|
||||
end
|
||||
|
||||
-- new yaw
|
||||
if math.abs(self._rudder_angle)>1.5 then
|
||||
local turn_rate = math.rad(14)
|
||||
local yaw_turn = self.dtime * math.rad(self._rudder_angle) * turn_rate *
|
||||
supercub.sign(longit_speed) * math.abs(longit_speed/2)
|
||||
newyaw = yaw + yaw_turn
|
||||
end
|
||||
|
||||
--roll adjust
|
||||
---------------------------------
|
||||
local delta = 0.002
|
||||
if is_flying then
|
||||
local roll_reference = newyaw
|
||||
local sdir = minetest.yaw_to_dir(roll_reference)
|
||||
local snormal = {x=sdir.z,y=0,z=-sdir.x} -- rightside, dot is negative
|
||||
local prsr = supercub.dot(snormal,nhdir)
|
||||
local rollfactor = -90
|
||||
local roll_rate = math.rad(10)
|
||||
newroll = (prsr*math.rad(rollfactor)) * (later_speed * roll_rate) * supercub.sign(longit_speed)
|
||||
--minetest.chat_send_all('newroll: '.. newroll)
|
||||
else
|
||||
delta = 0.2
|
||||
if roll > 0 then
|
||||
newroll = roll - delta
|
||||
if newroll < 0 then newroll = 0 end
|
||||
end
|
||||
if roll < 0 then
|
||||
newroll = roll + delta
|
||||
if newroll > 0 then newroll = 0 end
|
||||
end
|
||||
end
|
||||
|
||||
---------------------------------
|
||||
-- end roll
|
||||
|
||||
if not is_attached then
|
||||
-- for some engine error the player can be detached from the machine, so lets set him attached again
|
||||
supercub.checkattachBug(self)
|
||||
end
|
||||
|
||||
local pilot = player
|
||||
if self._command_is_given and passenger then
|
||||
pilot = passenger
|
||||
else
|
||||
self._command_is_given = false
|
||||
end
|
||||
|
||||
------------------------------------------------------
|
||||
--accell calculation block
|
||||
------------------------------------------------------
|
||||
if is_attached or passenger then
|
||||
if self._autopilot ~= true then
|
||||
accel, stop = supercub.control(self, self.dtime, hull_direction,
|
||||
longit_speed, longit_drag, later_speed, later_drag, accel, pilot, is_flying)
|
||||
else
|
||||
accel = supercub.autopilot(self, self.dtime, hull_direction, longit_speed, accel, curr_pos)
|
||||
end
|
||||
end
|
||||
|
||||
--end accell
|
||||
|
||||
if accel == nil then accel = {x=0,y=0,z=0} end
|
||||
|
||||
--lift calculation
|
||||
--accel.y = accel_y --accel.y + mobkit.gravity --accel_y
|
||||
|
||||
--lets apply some bob in water
|
||||
if self.isinliquid then
|
||||
local bob = supercub.minmax(supercub.dot(accel,hull_direction),0.2) -- vertical bobbing
|
||||
accel.y = accel.y + bob
|
||||
local max_pitch = 6
|
||||
local h_vel_compensation = (((longit_speed * 2) * 100)/max_pitch)/100
|
||||
if h_vel_compensation < 0 then h_vel_compensation = 0 end
|
||||
if h_vel_compensation > max_pitch then h_vel_compensation = max_pitch end
|
||||
newpitch = newpitch + (velocity.y * math.rad(max_pitch - h_vel_compensation))
|
||||
end
|
||||
|
||||
local new_accel = accel
|
||||
if longit_speed > 1.5 then
|
||||
new_accel = supercub.getLiftAccel(self, velocity, new_accel, longit_speed, roll, curr_pos)
|
||||
end
|
||||
-- end lift
|
||||
|
||||
if stop ~= true then
|
||||
self._last_accell = new_accel
|
||||
elseif stop == false then
|
||||
self.object:set_acceleration({x=0,y=0,z=0})
|
||||
self.object:set_velocity({x=0,y=0,z=0})
|
||||
end
|
||||
------------------------------------------------------
|
||||
-- end accell
|
||||
------------------------------------------------------
|
||||
|
||||
------------------------------------------------------
|
||||
-- sound and animation
|
||||
------------------------------------------------------
|
||||
supercub.engine_set_sound_and_animation(self)
|
||||
------------------------------------------------------
|
||||
|
||||
--self.object:get_luaentity() --hack way to fix jitter on climb
|
||||
|
||||
--adjust climb indicator
|
||||
local climb_rate = velocity.y
|
||||
if climb_rate > 5 then climb_rate = 5 end
|
||||
if climb_rate < -5 then
|
||||
climb_rate = -5
|
||||
end
|
||||
|
||||
--is an stall, force a recover
|
||||
if self._angle_of_attack > 3 and climb_rate < -2.8 then
|
||||
self._elevator_angle = 0
|
||||
self._angle_of_attack = -1
|
||||
newpitch = math.rad(self._angle_of_attack)
|
||||
end
|
||||
|
||||
--minetest.chat_send_all('rate '.. climb_rate)
|
||||
local climb_angle = supercub.get_gauge_angle(climb_rate)
|
||||
self.climb_gauge:set_attach(self.object,'',SUPERCUB_GAUGE_CLIMBER_POSITION,{x=0,y=0,z=climb_angle})
|
||||
|
||||
local indicated_speed = longit_speed
|
||||
if indicated_speed < 0 then indicated_speed = 0 end
|
||||
local speed_angle = supercub.get_gauge_angle(indicated_speed, -45)
|
||||
self.speed_gauge:set_attach(self.object,'',SUPERCUB_GAUGE_SPEED_POSITION,{x=0,y=0,z=speed_angle})
|
||||
|
||||
if is_attached then
|
||||
if self._show_hud then
|
||||
supercub.update_hud(player, climb_angle, speed_angle)
|
||||
else
|
||||
supercub.remove_hud(player)
|
||||
end
|
||||
end
|
||||
|
||||
--adjust power indicator
|
||||
local power_indicator_angle = supercub.get_gauge_angle(self._power_lever/10)
|
||||
self.power_gauge:set_attach(self.object,'',SUPERCUB_GAUGE_POWER_POSITION,{x=0,y=0,z=power_indicator_angle})
|
||||
|
||||
--apply rotations
|
||||
self.object:set_rotation({x=newpitch,y=newyaw,z=newroll})
|
||||
--end
|
||||
|
||||
--adjust elevator pitch (3d model)
|
||||
self.elevator:set_attach(self.object,'',{x=0,y=4,z=-35.5},{x=-self._elevator_angle*2,y=0,z=0})
|
||||
--adjust rudder
|
||||
self.rudder:set_attach(self.object,'',{x=0,y=0.12,z=-36.85},{x=0,y=self._rudder_angle,z=0})
|
||||
--adjust ailerons
|
||||
self.right_aileron:set_attach(self.object,'',{x=0,y=8.08,z=-7},{x=-self._rudder_angle,y=0,z=0})
|
||||
self.left_aileron:set_attach(self.object,'',{x=0,y=8.08,z=-7},{x=self._rudder_angle,y=0,z=0})
|
||||
--set stick position
|
||||
self.stick:set_attach(self.object,'',{x=0,y=-6,85,z=8},{x=self._elevator_angle/2,y=0,z=self._rudder_angle})
|
||||
|
||||
-- calculate energy consumption --
|
||||
supercub.consumptionCalc(self, accel)
|
||||
|
||||
--test collision
|
||||
supercub.testImpact(self, velocity, curr_pos)
|
||||
|
||||
--saves last velocity for collision detection (abrupt stop)
|
||||
self._last_vel = self.object:get_velocity()
|
||||
end
|
||||
|
After Width: | Height: | Size: 6.1 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 382 B |
After Width: | Height: | Size: 5.3 KiB |
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 4.8 KiB |
After Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 303 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 98 KiB |
After Width: | Height: | Size: 286 KiB |
After Width: | Height: | Size: 307 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 5.4 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 8.7 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 5.1 KiB |