2019-03-28 15:07:44 +01:00
local S = minetest.get_translator ( " orienteering " )
2019-09-14 22:43:52 +02:00
local mod_map = minetest.get_modpath ( " map " ) -- map mod from Minetest Game
2016-07-29 11:02:10 +02:00
2015-08-28 22:29:35 +02:00
local orienteering = { }
orienteering.playerhuds = { }
2016-07-28 02:58:20 +02:00
orienteering.settings = { }
2016-07-29 11:02:10 +02:00
orienteering.settings . speed_unit = S ( " m/s " )
orienteering.settings . length_unit = S ( " m " )
2016-10-28 15:03:54 +02:00
orienteering.settings . hud_pos = { x = 0.5 , y = 0 }
orienteering.settings . hud_offset = { x = 0 , y = 15 }
orienteering.settings . hud_alignment = { x = 0 , y = 0 }
2017-06-20 16:46:59 +02:00
local set = tonumber ( minetest.settings : get ( " orienteering_hud_pos_x " ) )
2016-10-28 15:03:54 +02:00
if set then orienteering.settings . hud_pos.x = set end
2017-06-20 16:46:59 +02:00
set = tonumber ( minetest.settings : get ( " orienteering_hud_pos_y " ) )
2016-10-28 15:03:54 +02:00
if set then orienteering.settings . hud_pos.y = set end
2017-06-20 16:46:59 +02:00
set = tonumber ( minetest.settings : get ( " orienteering_hud_offset_x " ) )
2016-10-28 15:03:54 +02:00
if set then orienteering.settings . hud_offset.x = set end
2017-06-20 16:46:59 +02:00
set = tonumber ( minetest.settings : get ( " orienteering_hud_offset_y " ) )
2016-10-28 15:03:54 +02:00
if set then orienteering.settings . hud_offset.y = set end
2017-06-20 16:46:59 +02:00
set = minetest.settings : get ( " orienteering_hud_alignment " )
2016-10-28 15:03:54 +02:00
if set == " left " then
orienteering.settings . hud_alignment.x = 1
elseif set == " center " then
orienteering.settings . hud_alignment.x = 0
elseif set == " right " then
orienteering.settings . hud_alignment.x = - 1
end
2015-08-28 22:29:35 +02:00
2016-10-28 01:12:26 +02:00
local o_lines = 4 -- Number of lines in HUD
2016-07-29 11:50:12 +02:00
-- Helper function to switch between 12h and 24 mode for the time
2016-10-28 16:09:45 +02:00
function orienteering . toggle_time_mode ( itemstack , user , pointed_thing )
2017-06-08 00:17:09 +02:00
--[[ Player attribute “orienteering:twelve”:
* " true " : Use 12 h mode for time
* " false " or unset : Use 24 h mode for time ] ]
2020-01-28 15:10:14 +01:00
if user : get_meta ( ) : get_string ( " orienteering:twelve " ) == " true " then
user : get_meta ( ) : set_string ( " orienteering:twelve " , " false " )
2016-07-29 11:50:12 +02:00
else
2020-01-28 15:10:14 +01:00
user : get_meta ( ) : set_string ( " orienteering:twelve " , " true " )
2016-07-29 11:50:12 +02:00
end
2016-10-28 16:09:45 +02:00
orienteering.update_hud_displays ( user )
2016-07-29 11:50:12 +02:00
end
2016-10-30 04:15:20 +01:00
local use = S ( " Put this tool in your hotbar to see the data it provides. " )
2019-03-28 16:26:59 +01:00
local use_time = S ( " Put this tool in your hotbar to make use of its functionality. Punch to toggle between 24-hour and 12-hour display for the time feature. " )
2016-10-30 04:15:20 +01:00
2015-08-28 20:39:05 +02:00
-- Displays height (Y)
minetest.register_tool ( " orienteering:altimeter " , {
2016-07-29 11:02:10 +02:00
description = S ( " Altimeter " ) ,
2020-11-07 00:54:28 +01:00
_tt_help = S ( " Shows your elevation " ) ,
2016-11-16 06:49:20 +01:00
_doc_items_longdesc = S ( " It shows you your current elevation (Y). " ) ,
_doc_items_usagehelp = use ,
2015-08-28 20:39:05 +02:00
wield_image = " orienteering_altimeter.png " ,
inventory_image = " orienteering_altimeter.png " ,
2018-10-16 12:55:11 +02:00
groups = { disable_repair = 1 } ,
2015-08-28 20:39:05 +02:00
} )
-- Displays X and Z coordinates
minetest.register_tool ( " orienteering:triangulator " , {
2016-07-29 11:02:10 +02:00
description = S ( " Triangulator " ) ,
2020-11-07 00:54:28 +01:00
_tt_help = S ( " Shows your horizontal coordinates " ) ,
2016-11-16 06:49:20 +01:00
_doc_items_longdesc = S ( " It shows you the coordinates of your current position in the horizontal plane (X and Z). " ) ,
_doc_items_usagehelp = use ,
2015-08-28 20:39:05 +02:00
wield_image = " orienteering_triangulator.png " ,
inventory_image = " orienteering_triangulator.png " ,
2018-10-16 12:55:11 +02:00
groups = { disable_repair = 1 } ,
2015-08-28 20:39:05 +02:00
} )
2016-07-28 23:46:52 +02:00
-- Displays player yaw
-- TODO: calculate yaw difference between 2 points
2015-08-28 20:39:05 +02:00
minetest.register_tool ( " orienteering:compass " , {
2016-07-29 11:02:10 +02:00
description = S ( " Compass " ) ,
2020-11-07 00:54:28 +01:00
_tt_help = S ( " Shows your yaw " ) ,
2016-11-16 06:49:20 +01:00
_doc_items_longdesc = S ( " It shows you your yaw (horizontal viewing angle) in degrees. " ) ,
_doc_items_usagehelp = use ,
2015-08-28 20:39:05 +02:00
wield_image = " orienteering_compass_wield.png " ,
inventory_image = " orienteering_compass_inv.png " ,
2018-10-16 12:55:11 +02:00
groups = { disable_repair = 1 } ,
2015-08-28 20:39:05 +02:00
} )
2016-07-28 23:46:52 +02:00
-- Displays player pitch
-- TODO: calculate pitch difference between 2 points
2015-08-28 20:39:05 +02:00
minetest.register_tool ( " orienteering:sextant " , {
2016-07-29 11:02:10 +02:00
description = S ( " Sextant " ) ,
2020-11-07 00:54:28 +01:00
_tt_help = S ( " Shows your pitch " ) ,
2016-11-16 06:49:20 +01:00
_doc_items_longdesc = S ( " It shows you your pitch (vertical viewing angle) in degrees. " ) ,
_doc_items_usagehelp = use ,
2015-08-28 20:39:05 +02:00
wield_image = " orienteering_sextant_wield.png " ,
inventory_image = " orienteering_sextant_inv.png " ,
2018-10-16 12:55:11 +02:00
groups = { disable_repair = 1 } ,
2015-08-28 20:39:05 +02:00
} )
2016-07-28 23:46:12 +02:00
-- Ultimate orienteering tool: Displays X,Y,Z, yaw, pitch, time, speed and enables the minimap
minetest.register_tool ( " orienteering:quadcorder " , {
2016-07-29 11:02:10 +02:00
description = S ( " Quadcorder " ) ,
2020-11-07 00:54:28 +01:00
_tt_help = S ( " Shows your coordinates, yaw, pitch, time, speed and enables minimap " ) ,
2016-11-16 06:49:20 +01:00
_doc_items_longdesc = S ( " This is the ultimate orientieering tool. It shows you your coordinates (X, Y and Z), shows your yaw and pitch (horizontal and vertical viewing angles), the current time, your current speed and it enables you to access the minimap. " ) ,
2016-07-28 23:46:12 +02:00
wield_image = " orienteering_quadcorder.png " ,
2016-11-16 06:49:20 +01:00
_doc_items_usagehelp = use_time ,
2016-07-28 23:46:12 +02:00
wield_scale = { x = 1 , y = 1 , z = 3.5 } ,
inventory_image = " orienteering_quadcorder.png " ,
2018-10-16 12:55:11 +02:00
groups = { disable_repair = 1 } ,
2016-10-28 16:09:45 +02:00
on_use = orienteering.toggle_time_mode ,
2016-07-28 23:46:12 +02:00
} )
2015-08-28 20:39:05 +02:00
-- Displays game time
minetest.register_tool ( " orienteering:watch " , {
2016-07-29 11:02:10 +02:00
description = S ( " Watch " ) ,
2020-11-07 00:54:28 +01:00
_tt_help = S ( " Shows the time " ) ,
2016-11-16 06:49:20 +01:00
_doc_items_longdesc = S ( " It shows you the current time. " ) ,
2019-03-28 16:26:59 +01:00
_doc_items_usagehelp = S ( " Put the watch in your hotbar to see the time. Punch to toggle between the 24-hour and 12-hour display. " ) ,
2015-08-28 20:39:05 +02:00
wield_image = " orienteering_watch.png " ,
inventory_image = " orienteering_watch.png " ,
2018-10-16 12:55:11 +02:00
groups = { disable_repair = 1 } ,
2016-10-28 16:09:45 +02:00
on_use = orienteering.toggle_time_mode ,
2015-08-28 20:39:05 +02:00
} )
-- Displays speed
minetest.register_tool ( " orienteering:speedometer " , {
2016-07-29 11:02:10 +02:00
description = S ( " Speedometer " ) ,
2020-11-07 00:54:28 +01:00
_tt_help = S ( " Shows your speed " ) ,
2016-11-16 06:49:20 +01:00
_doc_items_longdesc = S ( " It shows you your current horizontal (“hor.”) and vertical (“ver.”) speed in meters per second, where one meter is the side length of a single cube. " ) ,
_doc_items_usagehelp = use ,
2015-08-28 20:39:05 +02:00
wield_image = " orienteering_speedometer_wield.png " ,
inventory_image = " orienteering_speedometer_inv.png " ,
2018-10-16 12:55:11 +02:00
groups = { disable_repair = 1 } ,
2015-08-28 20:39:05 +02:00
} )
2019-03-28 15:55:32 +01:00
if not mod_map then
-- Enables minimap (surface)
minetest.register_tool ( " orienteering:map " , {
description = S ( " Map " ) ,
2020-11-07 00:54:28 +01:00
_tt_help = S ( " Allows using the minimap " ) ,
2019-03-28 15:55:32 +01:00
_doc_items_longdesc = S ( " The map allows you to view a minimap of the area around you. " ) ,
2019-09-14 22:50:53 +02:00
_doc_items_usagehelp = S ( " If you put a map in your hotbar, you will be able to access the minimap (only surface mode). Press the “minimap” key to view the minimap. " ) ,
2019-03-28 15:55:32 +01:00
wield_image = " orienteering_map.png " ,
wield_scale = { x = 1.5 , y = 1.5 , z = 0.15 } ,
inventory_image = " orienteering_map.png " ,
groups = { disable_repair = 1 } ,
} )
end
-- Enables minimap (radar)
2015-08-28 20:39:05 +02:00
minetest.register_tool ( " orienteering:automapper " , {
2019-03-28 15:57:46 +01:00
description = S ( " Radar Mapper " ) ,
2020-11-07 00:54:28 +01:00
_tt_help = S ( " Allows using the minimap and radar " ) ,
2019-03-28 15:57:46 +01:00
_doc_items_longdesc = S ( " The radar mapper is a device that combines a map with a radar. It unlocks both the surface mode and radar mode of the minimap. " ) ,
2019-09-14 22:50:53 +02:00
_doc_items_usagehelp = S ( " If you put a radar mapper in your hotbar, you will be able to access the minimap. Press the “minimap” key to view the minimap. " ) ,
2015-08-28 20:39:05 +02:00
wield_image = " orienteering_automapper_wield.png " ,
2016-07-28 23:46:12 +02:00
wield_scale = { x = 1 , y = 1 , z = 2 } ,
2015-08-28 20:39:05 +02:00
inventory_image = " orienteering_automapper_inv.png " ,
2018-10-16 12:55:11 +02:00
groups = { disable_repair = 1 } ,
2015-08-28 20:39:05 +02:00
} )
2016-07-28 03:39:33 +02:00
-- Displays X,Y,Z coordinates, yaw and game time
2015-08-28 20:39:05 +02:00
minetest.register_tool ( " orienteering:gps " , {
2016-07-29 11:02:10 +02:00
description = S ( " GPS device " ) ,
2020-11-07 00:54:28 +01:00
_tt_help = S ( " Shows your coordinates, yaw and the time " ) ,
2016-11-16 06:49:20 +01:00
_doc_items_longdesc = S ( " The GPS device shows you your coordinates (X, Y and Z), your yaw (horizontal viewing angle) and the time. " ) ,
_doc_items_usagehelp = use_time ,
2015-08-28 20:39:05 +02:00
wield_image = " orienteering_gps_wield.png " ,
2016-07-28 23:46:12 +02:00
wield_scale = { x = 1 , y = 1 , z = 2 } ,
2015-08-28 20:39:05 +02:00
inventory_image = " orienteering_gps_inv.png " ,
2018-10-16 12:55:11 +02:00
groups = { disable_repair = 1 } ,
2016-10-28 16:09:45 +02:00
on_use = orienteering.toggle_time_mode ,
2015-08-28 20:39:05 +02:00
} )
2016-07-28 03:39:33 +02:00
if minetest.get_modpath ( " default " ) ~= nil then
-- Register crafts
minetest.register_craft ( {
output = " orienteering:altimeter " ,
recipe = {
2016-10-27 22:56:25 +02:00
{ " default:glass " } ,
2016-08-08 06:36:50 +02:00
{ " default:steel_ingot " } ,
{ " default:steel_ingot " } ,
2016-07-28 03:39:33 +02:00
}
} )
minetest.register_craft ( {
output = " orienteering:triangulator " ,
recipe = {
2017-06-07 23:59:58 +02:00
{ " " , " default:bronze_ingot " , " " } ,
{ " default:bronze_ingot " , " " , " default:bronze_ingot " } ,
2016-07-28 03:39:33 +02:00
}
} )
minetest.register_craft ( {
output = " orienteering:sextant " ,
recipe = {
2017-06-07 23:59:58 +02:00
{ " " , " default:gold_ingot " , " " } ,
{ " default:gold_ingot " , " default:gold_ingot " , " default:gold_ingot " } ,
2016-07-28 03:39:33 +02:00
}
} )
minetest.register_craft ( {
output = " orienteering:compass " ,
recipe = {
2017-06-07 23:59:58 +02:00
{ " " , " default:tin_ingot " , " " } ,
{ " default:tin_ingot " , " group:stick " , " default:tin_ingot " } ,
{ " " , " default:tin_ingot " , " " } ,
2016-07-28 03:39:33 +02:00
}
} )
minetest.register_craft ( {
output = " orienteering:speedometer " ,
recipe = {
2016-08-08 06:36:50 +02:00
{ " " , " default:gold_ingot " , " " } ,
{ " default:steel_ingot " , " group:stick " , " default:steel_ingot " } ,
{ " " , " default:steel_ingot " , " " } ,
2016-07-28 03:39:33 +02:00
}
} )
minetest.register_craft ( {
output = " orienteering:automapper " ,
recipe = {
{ " default:gold_ingot " , " default:gold_ingot " , " default:gold_ingot " } ,
{ " default:mese_crystal " , " default:obsidian_shard " , " default:mese_crystal " } ,
{ " default:gold_ingot " , " default:gold_ingot " , " default:gold_ingot " }
}
} )
minetest.register_craft ( {
output = " orienteering:gps " ,
recipe = {
{ " default:gold_ingot " , " orienteering:triangulator " , " default:gold_ingot " } ,
{ " orienteering:compass " , " default:bronze_ingot " , " orienteering:watch " } ,
2017-06-07 23:59:58 +02:00
{ " default:tin_ingot " , " orienteering:altimeter " , " default:tin_ingot " }
2016-07-28 03:39:33 +02:00
}
} )
2016-07-29 00:25:28 +02:00
minetest.register_craft ( {
output = " orienteering:quadcorder " ,
recipe = {
{ " default:gold_ingot " , " default:gold_ingot " , " default:gold_ingot " } ,
{ " orienteering:speedometer " , " default:diamond " , " orienteering:automapper " , } ,
{ " orienteering:sextant " , " default:diamond " , " orienteering:gps " }
}
} )
2016-07-28 03:39:33 +02:00
minetest.register_craft ( {
output = " orienteering:watch " ,
recipe = {
{ " default:copper_ingot " } ,
{ " default:glass " } ,
{ " default:copper_ingot " }
}
} )
2019-03-28 15:55:32 +01:00
if ( not mod_map ) and minetest.get_modpath ( " dye " ) then
minetest.register_craft ( {
output = " orienteering:map " ,
recipe = {
{ " default:paper " , " default:paper " , " default:paper " } ,
{ " default:paper " , " dye:black " , " default:paper " } ,
{ " default:paper " , " default:paper " , " default:paper " } ,
}
} )
end
2016-07-28 03:39:33 +02:00
2018-10-16 12:54:04 +02:00
end
2015-08-28 21:02:08 +02:00
2016-10-28 16:09:45 +02:00
function orienteering . update_automapper ( player )
2020-11-07 00:25:38 +01:00
if orienteering.tool_active ( player , " orienteering:automapper " ) or orienteering.tool_active ( player , " orienteering:quadcorder " ) or minetest.is_creative_enabled ( player : get_player_name ( ) ) then
2019-09-14 22:43:52 +02:00
player : hud_set_flags ( { minimap = true , minimap_radar = true } )
elseif ( ( not mod_map ) and orienteering.tool_active ( player , " orienteering:map " ) ) or ( ( mod_map ) and orienteering.tool_active ( player , " map:mapping_kit " ) ) then
player : hud_set_flags ( { minimap = true , minimap_radar = false } )
2015-08-28 21:02:08 +02:00
else
2019-09-14 22:43:52 +02:00
player : hud_set_flags ( { minimap = false , minimap_radar = false } )
2015-08-28 21:02:08 +02:00
end
end
2016-10-28 16:47:27 +02:00
-- Checks whether a certain orienteering tool is “active” and ready for use
function orienteering . tool_active ( player , item )
-- Requirement: player carries the tool in the hotbar
local inv = player : get_inventory ( )
2019-09-14 22:43:52 +02:00
-- Exception: MTG's Mapping Kit can be anywhere
if item == " map:mapping_kit " then
return inv : contains_item ( " main " , item )
end
2016-10-28 16:47:27 +02:00
local hotbar = player : hud_get_hotbar_itemcount ( )
for i = 1 , hotbar do
if inv : get_stack ( " main " , i ) : get_name ( ) == item then
return true
end
end
return false
end
2016-10-28 15:03:54 +02:00
2016-10-28 16:09:45 +02:00
function orienteering . init_hud ( player )
orienteering.update_automapper ( player )
2015-08-28 22:29:35 +02:00
local name = player : get_player_name ( )
orienteering.playerhuds [ name ] = { }
2016-10-28 01:12:26 +02:00
for i = 1 , o_lines do
orienteering.playerhuds [ name ] [ " o_line " .. i ] = player : hud_add ( {
2015-08-28 22:29:35 +02:00
hud_elem_type = " text " ,
text = " " ,
2016-10-28 15:03:54 +02:00
position = orienteering.settings . hud_pos ,
offset = { x = orienteering.settings . hud_offset.x , y = orienteering.settings . hud_offset.y + 20 * ( i - 1 ) } ,
alignment = orienteering.settings . hud_alignment ,
2015-08-28 22:29:35 +02:00
number = 0xFFFFFF ,
scale = { x = 100 , y = 20 } ,
2020-04-07 16:20:26 +02:00
z_index = 0 ,
2015-08-28 22:29:35 +02:00
} )
end
end
2015-08-28 21:02:08 +02:00
2016-10-28 16:09:45 +02:00
function orienteering . update_hud_displays ( player )
2016-11-24 20:27:22 +01:00
local toDegrees = 180 / math.pi
2015-08-28 23:18:49 +02:00
local name = player : get_player_name ( )
2016-07-28 23:46:12 +02:00
local gps , altimeter , triangulator , compass , sextant , watch , speedometer , quadcorder
2015-08-28 23:18:49 +02:00
2016-10-28 16:47:27 +02:00
if orienteering.tool_active ( player , " orienteering:gps " ) then
2015-08-28 22:29:35 +02:00
gps = true
end
2016-10-28 16:47:27 +02:00
if orienteering.tool_active ( player , " orienteering:altimeter " ) then
2015-08-28 22:29:35 +02:00
altimeter = true
end
2016-10-28 16:47:27 +02:00
if orienteering.tool_active ( player , " orienteering:triangulator " ) then
2015-08-28 22:29:35 +02:00
triangulator = true
end
2016-10-28 16:47:27 +02:00
if orienteering.tool_active ( player , " orienteering:compass " ) then
2015-08-28 22:29:35 +02:00
compass = true
end
2016-10-28 16:47:27 +02:00
if orienteering.tool_active ( player , " orienteering:sextant " ) then
2015-08-28 22:29:35 +02:00
sextant = true
end
2016-10-28 16:47:27 +02:00
if orienteering.tool_active ( player , " orienteering:watch " ) then
2015-08-28 22:29:35 +02:00
watch = true
end
2016-10-28 16:47:27 +02:00
if orienteering.tool_active ( player , " orienteering:speedometer " ) then
2015-08-28 22:29:35 +02:00
speedometer = true
end
2016-10-28 16:47:27 +02:00
if orienteering.tool_active ( player , " orienteering:quadcorder " ) then
2016-07-28 23:46:12 +02:00
quadcorder = true
end
2015-08-28 22:29:35 +02:00
local str_pos , str_angles , str_time , str_speed
2019-03-28 16:29:15 +01:00
local pos = vector.round ( player : get_pos ( ) )
2016-07-28 23:46:12 +02:00
if ( altimeter and triangulator ) or gps or quadcorder then
2016-12-16 20:12:43 +01:00
str_pos = S ( " Coordinates: X=@1, Y=@2, Z=@3 " , pos.x , pos.y , pos.z )
2015-08-28 22:29:35 +02:00
elseif altimeter then
2016-12-16 20:12:43 +01:00
str_pos = S ( " Height: Y=@1 " , pos.y )
2015-08-28 22:29:35 +02:00
elseif triangulator then
2016-12-16 20:12:43 +01:00
str_pos = S ( " Coordinates: X=@1, Z=@2 " , pos.x , pos.z )
2015-08-28 22:29:35 +02:00
else
str_pos = " "
end
2019-09-14 22:21:27 +02:00
-- Yaw in Minetest goes counter-clockwise, which is opposite of how compasses work
local yaw = 360 - player : get_look_horizontal ( ) * toDegrees
2016-12-26 00:03:56 +01:00
local pitch = player : get_look_vertical ( ) * toDegrees
2016-07-28 23:46:12 +02:00
if ( ( compass or gps ) and sextant ) or quadcorder then
2016-12-16 20:12:43 +01:00
str_angles = S ( " Yaw: @1°, pitch: @2° " , string.format ( " %.1f " , yaw ) , string.format ( " %.1f " , pitch ) )
2015-08-28 22:29:35 +02:00
elseif compass or gps then
2016-12-16 20:12:43 +01:00
str_angles = S ( " Yaw: @1° " , string.format ( " %.1f " , yaw ) )
2015-08-28 22:29:35 +02:00
elseif sextant then
2016-12-16 20:12:43 +01:00
str_angles = S ( " Pitch: @1° " , string.format ( " %.1f " , pitch ) )
2015-08-28 22:29:35 +02:00
else
str_angles = " "
end
local time = minetest.get_timeofday ( )
2016-07-28 23:46:12 +02:00
if watch or gps or quadcorder then
2015-08-28 22:29:35 +02:00
local totalminutes = time * 1440
2016-11-19 01:14:43 +01:00
local minutes = totalminutes % 60
local hours = math.floor ( ( totalminutes - minutes ) / 60 )
2016-12-16 20:44:36 +01:00
minutes = math.floor ( minutes )
2020-01-28 15:10:14 +01:00
local twelve = player : get_meta ( ) : get_string ( " orienteering:twelve " ) == " true "
2015-08-28 23:18:49 +02:00
if twelve then
if hours == 12 and minutes == 0 then
2016-07-29 11:02:10 +02:00
str_time = S ( " Time: noon " )
2015-08-28 23:18:49 +02:00
elseif hours == 0 and minutes == 0 then
2016-07-29 11:02:10 +02:00
str_time = S ( " Time: midnight " )
2015-08-28 23:18:49 +02:00
else
2016-12-16 20:47:59 +01:00
local hours12 = math.fmod ( hours , 12 )
if hours12 == 0 then hours12 = 12 end
2016-12-16 20:12:43 +01:00
if hours >= 12 then
2016-12-16 20:47:59 +01:00
str_time = S ( " Time: @1:@2 p.m. " , string.format ( " %i " , hours12 ) , string.format ( " %02i " , minutes ) )
2016-12-16 20:12:43 +01:00
else
2016-12-16 20:47:59 +01:00
str_time = S ( " Time: @1:@2 a.m. " , string.format ( " %i " , hours12 ) , string.format ( " %02i " , minutes ) )
2016-12-16 20:12:43 +01:00
end
2015-08-28 23:18:49 +02:00
end
else
2016-12-16 20:12:43 +01:00
str_time = S ( " Time: @1:@2 " , string.format ( " %02i " , hours ) , string.format ( " %02i " , minutes ) )
2015-08-28 23:18:49 +02:00
end
2015-08-28 22:29:35 +02:00
else
str_time = " "
end
2016-07-28 23:46:12 +02:00
if speedometer or quadcorder then
2016-12-16 20:21:13 +01:00
local speed_hor , speed_ver
local v
local attach = player : get_attach ( )
if attach == nil then
v = player : get_player_velocity ( )
else
2019-03-28 16:29:15 +01:00
v = attach : get_velocity ( )
2016-12-16 20:21:13 +01:00
if not v then
v = player : get_player_velocity ( )
end
end
speed_ver = v.y
v.y = 0
speed_hor = vector.length ( v )
2016-10-27 23:49:59 +02:00
local u = orienteering.settings . speed_unit
2016-12-16 20:12:43 +01:00
str_speed = S ( " Speed: hor.: @1 @2, vert.: @3 @4 " , string.format ( " %.1f " , speed_hor ) , u , string.format ( " %.1f " , speed_ver ) , u )
2015-08-28 22:29:35 +02:00
else
str_speed = " "
end
2016-10-28 01:12:26 +02:00
local strs = { str_pos , str_angles , str_time , str_speed }
local line = 1
for i = 1 , o_lines do
if strs [ i ] ~= " " then
player : hud_change ( orienteering.playerhuds [ name ] [ " o_line " .. line ] , " text " , strs [ i ] )
line = line + 1
end
end
for l = line , o_lines do
player : hud_change ( orienteering.playerhuds [ name ] [ " o_line " .. l ] , " text " , " " )
end
2015-08-28 22:29:35 +02:00
end
2019-09-14 22:43:52 +02:00
if mod_map then
-- Disable all HUD flag handling in map mod because we already handle it
-- ourselves.
map.update_hud_flags = function ( ) end
end
2016-10-28 16:09:45 +02:00
minetest.register_on_newplayer ( orienteering.init_hud )
minetest.register_on_joinplayer ( orienteering.init_hud )
2015-08-28 22:29:35 +02:00
minetest.register_on_leaveplayer ( function ( player )
orienteering.playerhuds [ player : get_player_name ( ) ] = nil
2015-08-28 21:02:08 +02:00
end )
local updatetimer = 0
minetest.register_globalstep ( function ( dtime )
updatetimer = updatetimer + dtime
if updatetimer > 0.1 then
local players = minetest.get_connected_players ( )
for i = 1 , # players do
2016-10-28 16:09:45 +02:00
orienteering.update_automapper ( players [ i ] )
orienteering.update_hud_displays ( players [ i ] )
2015-08-28 21:02:08 +02:00
end
updatetimer = updatetimer - dtime
end
end )
2016-08-01 15:26:33 +02:00
2016-08-01 15:26:56 +02:00
if minetest.get_modpath ( " awards " ) ~= nil and minetest.get_modpath ( " default " ) ~= nil then
2016-08-01 15:26:33 +02:00
awards.register_achievement ( " orienteering_quadcorder " , {
title = S ( " Master of Orienteering " ) ,
description = S ( " Craft a quadcorder. " ) ,
icon = " orienteering_quadcorder.png " ,
trigger = {
type = " craft " ,
item = " orienteering:quadcorder " ,
target = 1
}
} )
end