From 8fb020cba8fd9653bf98ec78a995c8278b93f791 Mon Sep 17 00:00:00 2001 From: Deer McDurr Date: Thu, 20 May 2021 19:56:48 +0200 Subject: [PATCH] deer's overhaul excluding UI work --- levels/east_coast_usa/fuelstations.json | 19 + levels/hirochi_raceway/fuelstations.json | 5 + levels/italy/fuelstations.json | 66 ++++ levels/utah/fuelstations.json | 6 + levels/west_coast_usa/fuelstations.json | 35 ++ lua/ge/extensions/fuelStations.lua | 338 ++++++------------ .../extensions/FuelStation/fuelStation.lua | 62 ---- lua/vehicle/extensions/auto/fuelStation.lua | 89 +++++ 8 files changed, 332 insertions(+), 288 deletions(-) create mode 100644 levels/east_coast_usa/fuelstations.json create mode 100644 levels/hirochi_raceway/fuelstations.json create mode 100644 levels/italy/fuelstations.json create mode 100644 levels/utah/fuelstations.json create mode 100644 levels/west_coast_usa/fuelstations.json delete mode 100644 lua/vehicle/extensions/FuelStation/fuelStation.lua create mode 100644 lua/vehicle/extensions/auto/fuelStation.lua diff --git a/levels/east_coast_usa/fuelstations.json b/levels/east_coast_usa/fuelstations.json new file mode 100644 index 0000000..a84836d --- /dev/null +++ b/levels/east_coast_usa/fuelstations.json @@ -0,0 +1,19 @@ +[ + { "location": [ -778.813, 485.973, 23.46 ], "type":"gas" }, + { "location": [ -776.504, 488.427, 23.46 ], "type":"gas" }, + { "location": [ -775.036, 490.828, 23.46 ], "type":"gas" }, + { "location": [ -772.457, 493.484, 23.46 ], "type":"gas" }, + { "location": [ -770.871, 495.714, 23.46 ], "type":"gas" }, + { "location": [ -768.417, 498.436, 23.46 ], "type":"gas" }, + { "location": [ 704.304, -23.125, 51.8 ], "type":"gas" }, + { "location": [ 708.497, -23.3151, 51.8 ], "type":"gas" }, + { "location": [ 711.115, -23.5511, 51.8 ], "type":"gas" }, + { "location": [ 714.968, -23.6462, 51.8 ], "type":"gas" }, + { "location": [ 717.663, -23.9071, 51.8 ], "type":"gas" }, + { "location": [ 721.414, -24.0725, 51.8 ], "type":"gas" }, + + { "location": [ 625.651, -183.448, 53.2 ], "type":"ev" }, + { "location": [ 622.667, -186.129, 53.2 ], "type":"ev" }, + { "location": [ 619.97, -189.098, 53.2 ], "type":"ev" }, + { "location": [ 617.164, -192.107, 53.2 ], "type":"ev" }, +] diff --git a/levels/hirochi_raceway/fuelstations.json b/levels/hirochi_raceway/fuelstations.json new file mode 100644 index 0000000..0bf578a --- /dev/null +++ b/levels/hirochi_raceway/fuelstations.json @@ -0,0 +1,5 @@ +[ + { "location": [ -423.444, 327.058, 24.7 ], "type":"any" }, + { "location": [ -313.5 , 62.4 , 31.9 ], "type":"any" }, + { "location": [ -311 , 60 , 31.9 ], "type":"any" }, +] diff --git a/levels/italy/fuelstations.json b/levels/italy/fuelstations.json new file mode 100644 index 0000000..25d1dcc --- /dev/null +++ b/levels/italy/fuelstations.json @@ -0,0 +1,66 @@ +[ + {"type":"ev", "location":[-972.806,948.605,392.40] }, + {"type":"ev", "location":[-971.062,950.279,392.48] }, + {"type":"ev", "location":[-969.27, 952.026,392.48] }, + {"type":"gas", "location":[-1115.35,773.865,378.202] }, + {"type":"gas", "location":[-1115.55,768.871,378.202] }, + {"type":"gas", "location":[-1111.74,768.029,378.203] }, + {"type":"gas", "location":[-1111.31,773.291,378.201] }, + + {"type":"gas", "location":[-1122.35,770.865,378.202] }, + {"type":"gas", "location":[-1117.80,770.871,378.202] }, + + {"type":"gas", "location":[ 1448.81,1348.93,147.298] }, + {"type":"gas", "location":[ 1453.59,1349.92,147.229] }, + {"type":"gas", "location":[ 1448.1,1352.97,147.26] }, + {"type":"gas", "location":[ 1453.08,1353.72,147.281] }, + {"type":"gas", "location":[-1611.84,1523.47,163] }, + {"type":"gas", "location":[-1614.28,1519.66,163] }, + {"type":"gas", "location":[-1617.71,1521.93,163] }, + {"type":"gas", "location":[-1615.34,1525.46,163] }, + {"type":"gas", "location":[-1626.79,1527.72,163] }, + {"type":"gas", "location":[-1624.43,1531.36,163] }, + {"type":"gas", "location":[-1623.26,1525.68,163] }, + {"type":"gas", "location":[-1621.03,1529.18,163] }, + {"type":"gas", "location":[-1758.49,1324.84,138.9] }, + {"type":"gas", "location":[-1758.03,1328.25,138.9] }, + {"type":"gas", "location":[1214.599,-810.765,145.173] }, + {"type":"gas", "location":[1216.699,-807.445,145.245] }, + {"type":"gas", "location":[1210.02,-807.812,145.234] }, + {"type":"gas", "location":[1212.06,-804.469,145.291] }, + {"type":"ev", "location":[1199.18,-797.823,145.786] }, + {"type":"ev", "location":[1202.29,-793.992,145.764] }, + {"type":"ev", "location":[1113.25,-686.448,146.031] }, + {"type":"ev", "location":[1113.96,1309.27,143.007] }, + {"type":"ev", "location":[1124.09,1308.87,143.007] }, + {"type":"ev", "location":[1156.11,1305.27,143.788] }, + {"type":"ev", "location":[1165.86,1304.98,143.981] }, + {"type":"ev", "location":[-730.8,-1327.5,143.2] }, + {"type":"ev", "location":[-725.4,-1324.7,143.2] }, + {"type":"gas", "location":[-543.223,-210.488,231.101] }, + {"type":"gas", "location":[-547.45,-207.176,231.119] }, + {"type":"gas", "location":[-539.732,-206.318,231.144] }, + {"type":"gas", "location":[-543.518,-202.954,231.179] }, + {"type":"ev", "location":[624.425,1357.562,155.989] }, + {"type":"ev", "location":[616.339,1357.562,155.989] }, + {"type":"ev", "location":[620.269,1357.562,155.989] }, + {"type":"ev", "location":[612.114,1357.562,155.989] }, + {"type":"gas", "location":[-1065.38,-1353.31,324.082] }, + {"type":"gas", "location":[-1065.42,-1358.48,324.082] }, + {"type":"gas", "location":[634.715,1482.61,139.093] }, + {"type":"gas", "location":[628.822,1482.6,139.093] }, + {"type":"gas", "location":[679.646,589.616,173.998] }, + {"type":"gas", "location":[683.65,585.714,173.998] }, + {"type":"gas", "location":[686.265,588.252,173.996] }, + {"type":"gas", "location":[682.307,592.144,173.969] }, + {"type":"ev", "location":[1433.68,1348.8,147.182] }, + {"type":"ev", "location":[1430.98,1348.11,147.165] }, + {"type":"gas", "location":[462.431,1276.049,171.582] }, + {"type":"gas", "location":[466.192,1270.933,171.507] }, + {"type":"gas", "location":[467.25,1274.76,171.584] }, + {"type":"gas", "location":[461.373,1272.222,171.504] }, + {"type":"gas", "location":[137.447,-270.667,193.566] }, + {"type":"gas", "location":[133.501,-265.86,193.566] }, + {"type":"gas", "location":[137.447,-265.86,193.566] }, + {"type":"gas", "location":[133.501,-270.667,193.566] } +] \ No newline at end of file diff --git a/levels/utah/fuelstations.json b/levels/utah/fuelstations.json new file mode 100644 index 0000000..73d268e --- /dev/null +++ b/levels/utah/fuelstations.json @@ -0,0 +1,6 @@ +[ + { "location": [ 809.5, -158 , 144.3 ], "type":"any" }, + { "location": [ 812.5, -157.6, 144.3 ], "type":"any" }, + { "location": [ 811.2, -150 , 144.3 ], "type":"any" }, + { "location": [ 808.2, -150.6, 144.3 ], "type":"any" }, +] diff --git a/levels/west_coast_usa/fuelstations.json b/levels/west_coast_usa/fuelstations.json new file mode 100644 index 0000000..cd8e69d --- /dev/null +++ b/levels/west_coast_usa/fuelstations.json @@ -0,0 +1,35 @@ +[ + { "location": [ -480.495, 134.616, 102.21 ], "type":"any"}, + { "location": [ -476.888, 133.500, 102.21 ], "type":"any"}, + { "location": [ -478.933, 126.744, 102.21 ], "type":"any"}, + { "location": [ -482.540, 127.860, 102.21 ], "type":"any"}, + { "location": [ -490.042, 130.875, 102.21 ], "type":"any"}, + { "location": [ -487.997, 137.631, 102.21 ], "type":"any"}, + { "location": [ -484.390, 136.515, 102.21 ], "type":"any"}, + { "location": [ -486.435, 129.759, 102.21 ], "type":"any"}, + { "location": [ -492.171, 138.235, 102.21 ], "type":"any"}, + { "location": [ -495.778, 139.350, 102.21 ], "type":"any"}, + { "location": [ -497.824, 132.595, 102.21 ], "type":"any"}, + { "location": [ -494.217, 131.479, 102.21 ], "type":"any"}, + { "location": [ -800.910, 861.350, 76.800 ], "type":"any"}, + { "location": [ -794.050, 852.340, 76.800 ], "type":"any"}, + { "location": [ -800.636, 852.330, 76.800 ], "type":"any"}, + { "location": [ -794.050, 848.565, 76.800 ], "type":"any"}, + { "location": [ -800.582, 848.555, 76.800 ], "type":"any"}, + { "location": [ -800.856, 857.575, 76.800 ], "type":"any"}, + { "location": [ -793.745, 861.358, 76.800 ], "type":"any"}, + { "location": [ -793.691, 857.583, 76.800 ], "type":"any"}, + { "location": [ -193.984, 522.874, 76.830 ], "type":"any"}, + { "location": [ -183.978, 516.118, 76.830 ], "type":"any"}, + { "location": [ -180.021, 522.874, 76.830 ], "type":"any"}, + { "location": [ -180.021, 516.118, 76.830 ], "type":"any"}, + { "location": [ -200.020, 516.517, 76.830 ], "type":"any"}, + { "location": [ -183.978, 522.874, 76.830 ], "type":"any"}, + { "location": [ -203.978, 516.517, 76.830 ], "type":"any"}, + { "location": [ -200.020, 522.781, 76.830 ], "type":"any"}, + { "location": [ -203.978, 522.781, 76.830 ], "type":"any"}, + { "location": [ -190.027, 522.874, 76.830 ], "type":"any"}, + { "location": [ -190.019, 515.983, 76.830 ], "type":"any"}, + { "location": [ -193.976, 515.983, 76.830 ], "type":"any"}, + { "location": [ 417.285, -229.916, 147.06 ], "type":"any"} +] diff --git a/lua/ge/extensions/fuelStations.lua b/lua/ge/extensions/fuelStations.lua index 776812a..775f9eb 100644 --- a/lua/ge/extensions/fuelStations.lua +++ b/lua/ge/extensions/fuelStations.lua @@ -1,248 +1,134 @@ local M = {} -print("Fuel Stations Initialising...") +log('I','[FuelStations]', "Initialising...") -local map = "" -local fuelType = "" + +local stations = nil +local fuelTypeMap = {} + +local ePressed = false local debug = false -local cVeh = 0 -local stations = { - ["/levels/east_coast_usa/info.json"] = { - {vec3(-778.813, 485.973, 23.4637), vec3(-778.813, 485.973, 25.4637), "Gas"}, - {vec3(-776.504, 488.427, 23.4637), vec3(-776.504, 488.427, 25.4637), "Gas"}, - {vec3(-775.036, 490.828, 23.4637), vec3(-775.036, 490.828, 25.4637), "Gas"}, - {vec3(-772.457, 493.484, 23.4637), vec3(-772.457, 493.484, 25.4637), "Gas"}, - {vec3(-770.871, 495.714, 23.4637), vec3(-770.871, 495.714, 25.4637), "Gas"}, - {vec3(-768.417, 498.436, 23.4637), vec3(-768.417, 498.436, 25.4637), "Gas"}, - {vec3(704.304, -23.125, 51.8), vec3(704.304, -23.125, 55.0), "Gas"}, - {vec3(708.497, -23.3151, 51.8), vec3(708.497, -23.3151, 55.0), "Gas"}, - {vec3(711.115, -23.5511, 51.8), vec3(711.115, -23.5511, 55.0), "Gas"}, - {vec3(714.968, -23.6462, 51.8), vec3(714.968, -23.6462, 55.0), "Gas"}, - {vec3(717.763, -23.9071, 51.8), vec3(717.763, -23.9071, 55.0), "Gas"}, - {vec3(721.414, -24.0725, 51.8), vec3(721.414, -24.0725, 55.0), "Gas"}, - {vec3(625.651, -183.448, 53.0), vec3(625.651, -183.448, 55.0), "EV"}, - {vec3(622.667, -186.129, 53.0), vec3(622.667, -186.129, 55.0), "EV"}, - {vec3(619.97, -189.098, 53.0), vec3(619.97, -189.098, 55.0), "EV"}, - {vec3(617.164, -192.107, 53.0), vec3(617.164, -192.107, 55.0), "EV"}, - }, - ["/levels/west_coast_usa/info.json"] = { - {vec3(-480.495, 134.616, 100.212), vec3(-480.495, 134.616, 102.212), "Gas/EV"}, - {vec3(-476.888, 133.5, 100.212), vec3(-476.888, 133.5, 102.212), "Gas/EV"}, - {vec3(-478.933, 126.744, 100.212), vec3(-478.933, 126.744, 102.212), "Gas/EV"}, - {vec3(-482.54, 127.86, 100.212), vec3(-482.54, 127.86, 102.212), "Gas/EV"}, - {vec3(-490.042, 130.875, 100.212), vec3(-490.042, 130.875, 102.212), "Gas/EV"}, - {vec3(-487.997, 137.631, 100.212), vec3(-487.997, 137.631, 102.212), "Gas/EV"}, - {vec3(-484.39, 136.515, 100.212), vec3(-484.39, 136.515, 102.212), "Gas/EV"}, - {vec3(-486.435, 129.759, 100.212), vec3(-486.435, 129.759, 102.212), "Gas/EV"}, - {vec3(-492.171,138.235,100.211), vec3(-492.171,138.235,102.211), "Gas/EV"}, - {vec3(-495.778,139.350,100.211), vec3(-495.778,139.350,102.211), "Gas/EV"}, - {vec3(-497.824,132.595,100.211), vec3(-497.824,132.595,102.211), "Gas/EV"}, - {vec3(-494.217,131.479,100.211), vec3(-494.217,131.479,102.211), "Gas/EV"}, - {vec3(-800.910, 861.350, 74.800), vec3(-800.910, 861.350, 76.800), "Gas/EV"}, - {vec3(-794.05, 852.340, 74.800), vec3(-794.05, 852.340, 76.800), "Gas/EV"}, - {vec3(-800.636, 852.330, 74.800), vec3(-800.636, 852.330, 76.800), "Gas/EV"}, - {vec3(-794.05, 848.565, 74.800), vec3(-794.05, 848.565, 76.800), "Gas/EV"}, - {vec3(-800.582, 848.555, 74.800), vec3(-800.582, 848.555, 76.800), "Gas/EV"}, - {vec3(-800.856, 857.575, 74.800), vec3(-800.856, 857.575, 76.800), "Gas/EV"}, - {vec3(-793.745, 861.358, 74.800), vec3(-793.745, 861.358, 76.800), "Gas/EV"}, - {vec3(-793.691, 857.583, 74.800), vec3(-793.691, 857.583, 76.800), "Gas/EV"}, - {vec3(-193.984,522.874,74.830), vec3(-193.984,522.874,76.830), "Gas/EV"}, - {vec3(-183.978,516.118,74.830), vec3(-183.978,516.118,76.830), "Gas/EV"}, - {vec3(-180.021,522.874,74.830), vec3(-180.021,522.874,76.830), "Gas/EV"}, - {vec3(-180.021,516.118,74.830), vec3(-180.021,516.118,76.830), "Gas/EV"}, - {vec3(-200.020,516.517,74.830), vec3(-200.020,516.517,76.830), "Gas/EV"}, - {vec3(-183.978,522.874,74.830), vec3(-183.978,522.874,76.830), "Gas/EV"}, - {vec3(-203.978,516.517,74.830), vec3(-203.978,516.517,76.830), "Gas/EV"}, - {vec3(-200.020,522.781,74.830), vec3(-200.020,522.781,76.830), "Gas/EV"}, - {vec3(-203.978,522.781,74.830), vec3(-203.978,522.781,76.830), "Gas/EV"}, - {vec3(-190.027,522.874,74.830), vec3(-190.027,522.874,76.830), "Gas/EV"}, - {vec3(-190.019,515.983,74.830), vec3(-190.019,515.983,76.830), "Gas/EV"}, - {vec3(-193.976,515.983,74.830), vec3(-193.976,515.983,76.830), "Gas/EV"}, - {vec3(417.285,-229.916,145.066), vec3(417.285,-229.916,147.066), "Gas/EV"}, - }, - ["/levels/hirochi_raceway/info.json"] = { - {vec3(-423.444, 327.058, 24.188), vec3(-423.444, 327.058, 26.188), "Gas/EV"}, - {vec3(-313.5, 62.4, 32), vec3(-313.5, 62.4, 34), "Gas/EV"}, - {vec3(-311, 60, 32), vec3(-311, 60, 34), "Gas/EV"}, - }, - ["/levels/utah/info.json"] = { - {vec3(809.5, -158, 144.3), vec3(809.5, -158, 146.3), "Gas/EV"}, - {vec3(812.5, -157.6, 144.3), vec3(812.5, -157.6, 146.3), "Gas/EV"}, - {vec3(811.2, -150, 144.3), vec3(811.2, -150, 146.3), "Gas/EV"}, - {vec3(808.2, -150.6, 144.3), vec3(808.2, -150.6, 146.3), "Gas/EV"}, - }, - ["/levels/italy/info.json"] = { - {vec3(-972.806, 948.605, 392.601), vec3(-972.806, 948.605, 394.601), "EV"}, - {vec3(-971.062, 950.279, 392.644), vec3(-971.062, 950.279, 394.644), "EV"}, - {vec3(-969.27, 952.026, 392.662), vec3(-969.27, 952.026, 394.662), "EV"}, - {vec3(-1105.25, 773.865, 378.202), vec3(-1105.25, 773.865, 380.202), "Gas"}, - {vec3(-1105.36, 768.871, 378.202), vec3(-1105.36, 768.871, 380.202), "Gas"}, - {vec3(-1101.64, 768.029, 378.203), vec3(-1101.64, 768.029, 380.203), "Gas"}, - {vec3(-1101.21, 773.291, 378.201), vec3(-1101.21, 773.291, 380.201), "Gas"}, +local inactiveColorMap = { gas = ColorF(1,1,0,0.3), ev = ColorF(0,1,0,0.3), any = ColorF(0,0,1,0.3) } +local activeColorMap = { gas = ColorF(1,1,0,0.5), ev = ColorF(0,1,0,0.5), any = ColorF(0,0,1,0.5) } - {vec3(1448.81, 1348.93, 147.298), vec3(1448.81, 1348.93, 149.498), "Gas"}, - {vec3(1453.59, 1349.92, 147.229), vec3(1453.59, 1349.92, 149.529), "Gas"}, - {vec3(1448.10, 1352.97, 147.26), vec3(1448.1, 1352.97, 149.56), "Gas"}, - {vec3(1453.08, 1353.72, 147.281), vec3(1453.08, 1353.72, 149.481), "Gas"}, +local function loadMapStations(infopath) + infopath = infopath or getMissionFilename() + if infopath == "" then return false end - {vec3(-1611.84, 1523.47, 162.251), vec3(-1611.84, 1523.47, 164.251), "Gas"}, - {vec3(-1614.28, 1519.66, 162.256), vec3(-1614.28, 1519.66, 164.256), "Gas"}, - {vec3(-1617.71, 1521.93, 162.261), vec3(-1617.71, 1521.93, 164.261), "Gas"}, - {vec3(-1615.34, 1525.46, 162.256), vec3(-1615.34, 1525.46, 164.256), "Gas"}, + local maproot = path.split(infopath) --infopath:sub(1,8+infopath:sub(9):find("/")) - {vec3(-1626.79, 1527.72, 162.254), vec3(-1626.79, 1527.72, 164.254), "Gas"}, - {vec3(-1624.43, 1531.36, 162.256), vec3(-1624.43, 1531.36, 164.256), "Gas"}, - {vec3(-1623.26, 1525.68, 162.261), vec3(-1623.26, 1525.68, 164.261), "Gas"}, - {vec3(-1621.03, 1529.18, 162.256), vec3(-1621.03, 1529.18, 164.256), "Gas"}, + stations = jsonReadFile(maproot .. "fuelstations.json") - {vec3(-1758.49, 1324.84, 138.19), vec3(-1758.49, 1324.84, 140.19), "Gas"}, - {vec3(-1758.03, 1328.25, 138.188), vec3(-1758.03, 1328.25, 140.188), "Gas"}, - - {vec3(1214.599,-810.765,145.173), vec3(1214.599,-810.765,147.173), "Gas"}, - {vec3(1216.699,-807.445,145.245), vec3(1216.699,-807.445,147.245), "Gas"}, - {vec3(1210.020,-807.812,145.234), vec3(1210.020,-807.812,147.234), "Gas"}, - {vec3(1212.060,-804.469,145.291), vec3(1212.060,-804.469,147.291), "Gas"}, - - {vec3(1199.18,-797.823,145.786), vec3(1199.18,-797.823,147.786), "EV"}, - {vec3(1202.29,-793.992,145.764), vec3(1202.29,-793.992,147.764), "EV"}, - - {vec3(1113.25, -686.448, 146.031), vec3(1113.25, -686.448, 147.531), "EV"}, - - {vec3(1113.96, 1309.27, 143.007), vec3(1113.96, 1309.27, 145.007), "EV"}, - {vec3(1124.09, 1308.87, 143.007), vec3(1124.09, 1308.87, 145.007), "EV"}, - {vec3(1156.11, 1305.27, 143.788), vec3(1156.11, 1305.27, 145.788), "EV"}, - {vec3(1165.86, 1304.98, 143.981), vec3(1165.86, 1304.98, 145.981), "EV"}, - - {vec3(-730.8, -1327.5, 142.65), vec3(-730.8, -1327.5, 144.65), "EV"}, - {vec3(-725.4, -1324.7, 142.65), vec3(-725.4, -1324.7, 144.65), "EV"}, - - {vec3(-543.223, -210.488, 231.101), vec3(-543.223, -210.488, 233.501), "Gas"}, - {vec3(-547.45, -207.176, 231.119), vec3(-547.45, -207.176, 233.519), "Gas"}, - {vec3(-539.732, -206.318, 231.144), vec3(-539.732, -206.318, 233.444), "Gas"}, - {vec3(-543.518, -202.954, 231.179), vec3(-543.518, -202.954, 233.479), "Gas"}, - - {vec3(624.425,1357.562,155.989),vec3(624.425,1357.562,157.989),"EV"}, - {vec3(616.339,1357.562,155.989),vec3(616.339,1357.562,157.989),"EV"}, - {vec3(620.269,1357.562,155.989),vec3(620.269,1357.562,157.989),"EV"}, - {vec3(612.114,1357.562,155.989),vec3(612.114,1357.562,157.989),"EV"}, - - {vec3(-1065.38, -1353.31, 324.082), vec3(-1065.38, -1353.31, 326.482), "Gas"}, - {vec3(-1065.42, -1358.48, 324.082), vec3(-1065.42, -1358.48, 326.482), "Gas"}, - - {vec3(634.715,1482.61,139.093), vec3(634.715,1482.61,141.093), "Gas"}, - {vec3(628.822,1482.6,139.093), vec3(628.822,1482.6,141.093), "Gas"}, - - {vec3(679.646, 589.616, 173.998), vec3(679.646, 589.616, 175.998), "Gas"}, - {vec3(683.65, 585.714, 173.998), vec3(683.65, 585.714, 175.998), "Gas"}, - {vec3(686.265, 588.252, 173.996), vec3(686.265, 588.252, 175.996), "Gas"}, - {vec3(682.307, 592.144, 173.969), vec3(682.307, 592.144, 175.969), "Gas"}, - - {vec3(1433.68, 1348.8, 147.182), vec3(1433.68, 1348.8, 149.182), "EV"}, - {vec3(1430.98, 1348.11, 147.165), vec3(1430.98, 1348.11, 149.165), "EV"}, - - {vec3(462.431, 1276.049, 171.582), vec3(462.431, 1276.049, 173.682), "Gas"}, - {vec3(466.192, 1270.933, 171.507), vec3(466.192, 1270.933, 173.707), "Gas"}, - {vec3(467.250, 1274.760, 171.584), vec3(467.250, 1274.760, 173.684), "Gas"}, - {vec3(461.373, 1272.222, 171.504), vec3(461.373, 1272.222, 173.704), "Gas"}, - - {vec3(137.447, -270.667, 193.566), vec3(137.447, -270.667, 195.766),"Gas"}, - {vec3(133.501, -265.860, 193.566), vec3(133.501, -265.860, 195.766),"Gas"}, - {vec3(137.447, -265.860, 193.566), vec3(137.447, -265.860, 195.766),"Gas"}, - {vec3(133.501, -270.667, 193.566), vec3(133.501, -270.667, 195.766),"Gas"}, - } -} - -local function distance (pos1, pos2, useZ) - local dx = pos1.x - pos2.x - local dy = pos1.y - pos2.y - local dz = pos1.z - pos2.z - if useZ then - return math.sqrt ( dx * dx + dy * dy + dz * dz ) - else - return math.sqrt ( dx * dx + dy * dy ) - end + return stations ~= nil end -local function IsEntityInsideArea(pos1, pos2) - if distance(pos1, pos2, true) < 1 then - return true - else - return false - end +local function onClientPostStartMission(infopath) + if loadMapStations(infopath) then + log('I','[FuelStations]', "Loaded stations") + else + log('I','[FuelStations]', "Could not load stations for map "..infopath) + end +end + +local function IsEntityInsideArea(pos1, pos2, radius) + return pos1:distance(pos2) < radius end local function addFuel() - --print("Should i add fuel?") - local veh = be:getObjectByID(cVeh) - if veh then - print("[Fuel Stations] [GE] Calling Add Fuel VE") - veh:queueLuaCommand("fuelStation.addFuel()") - end + local veh = be:getPlayerVehicle(0) + if veh then + veh:queueLuaCommand("fuelStation.addFuel()") + end end -local function onVehicleSwitched(oldID, newID) - print("[Fuel Stations] Active Vehicle Switched : "..oldID.." - "..newID) - cVeh = newID - local veh = be:getObjectByID(newID) - veh:queueLuaCommand("fuelStation.getFuelType()") -end - -local function onVehicleSpawned(gameVehicleID) - --print("[BeamMP] Vehicle spawned : "..gameVehicleID) - local veh = be:getObjectByID(gameVehicleID) - cVeh = gameVehicleID - veh:queueLuaCommand("extensions.addModulePath('lua/vehicle/extensions/FuelStation')") -- Load lua files - veh:queueLuaCommand("extensions.loadModulesInDirectory('lua/vehicle/extensions/FuelStation')") - veh:queueLuaCommand("fuelStation.getFuelType()") -end - -local function setFuelType(t) - fuelType = t +local function setFuelType(id, t) + fuelTypeMap[id] = t end local function onUpdate() - local atStation = false - if debug then - debugDrawer:drawTextAdvanced(be:getObject(0):getPosition(), String(" "..tostring(be:getObject(0):getPosition())), ColorF(194/255, 55/255, 55/255, 255/255), true, false, ColorI(0,0,0,127)) - end - map = getMissionFilename() - if string.match(map, "info.json") or string.match(map, "level.json") then - for k = 1, #stations[map] do - --print("Using Map: "..tostring(stations[map][k][3])) - local color = 0 - if stations[map][k][3] == "EV" then - color = ColorF(0.1,0.9,0.1,0.5) - elseif stations[map][k][3] == "Gas/EV" then - color = ColorF(0.1,0.8,1.0,0.5) - else - color = ColorF(0.9,0.1,0.1,0.5) - end - debugDrawer:drawCylinder(stations[map][k][1]:toPoint3F(), stations[map][k][2]:toPoint3F(), 1, color) - --for i = 0, be:getObjectCount() -1 do -- For each vehicle - --local veh = be:getObject(i) -- Get vehicle - local veh = be:getObjectByID(cVeh) - if IsEntityInsideArea(veh:getPosition(), stations[map][k][1]) then - if stations[map][k][3] == "Gas/EV" or stations[map][k][3] == fuelType then - -- we are inside one of the filling areas of the map - --ui_message("Press E To Refuel") - atStation = true - be:executeJS('fuelUIShowHide("true", "'..fuelType..'")') - break - end - end - --end - end - if not atStation then -- We are not in a spot for filling then we should force the UI to be hidden - be:executeJS('fuelUIShowHide("false")') - end - end + local canRefill = false + if debug then + local pos = be:getObject(0):getPosition() + debugDrawer:drawTextAdvanced(pos, String(" "..tostring(pos).." "), ColorF(0/255, 0/255, 0/255, 255/255), true, false, ColorI(255,255,255,255)) + local topPos = vec3(pos) + vec3(0,0,3) + debugDrawer:drawCylinder(pos, topPos:toPoint3F(), 0.05, ColorF(1,0.2,0.2,0.7)) --bottom, top, radius, color + end + + if not stations then return end + + local activeVeh = be:getPlayerVehicle(0) + local activeFuelType = "any" + + if activeVeh then -- prepare the vehicle + if MPVehicleGE and (MPGameNetwork.connectionStatus() == 1) and not MPVehicleGE.isOwn(activeVeh:getID()) then + activeVeh = nil + else + if fuelTypeMap[activeVeh:getID()] then + activeFuelType = fuelTypeMap[activeVeh:getID()] + else + activeVeh:queueLuaCommand("fuelStation.getFuelType()") + end + end + end + + for k, spot in pairs(stations) do -- loop through all spots on the current map + local bottomPos = vec3(spot.location[1], spot.location[2], spot.location[3]) + local topPos = bottomPos + vec3(0,0,2) -- offset vec to get top position (2m tall) + + local spotInRange = false -- is this spot in range? used for color + local spotCompatible = false -- is this spot compatible? + + if activeVeh then -- we have a car and its ours (if in mp) + local vehPos = activeVeh:getPosition() + + spotInRange = IsEntityInsideArea(vec3(vehPos.x, vehPos.y,vehPos.z), bottomPos, 1.5) + + spotCompatible = activeFuelType == "any" or spot.type == "any" or activeFuelType == spot.type + if spotInRange and spotCompatible then + if debug then + dump("activeFuelType",activeFuelType) + dump("spot.type",spot.type) + dump(fuelTypeMap) + end + canRefill = true + end + end + + local spotColor = (spotInRange and spotCompatible) and activeColorMap[spot.type] or inactiveColorMap[spot.type] or ColorF(1,1,1,0.5) + + + debugDrawer:drawCylinder(bottomPos:toPoint3F(), topPos:toPoint3F(), 1, spotColor) --bottom, top, radius, color + end + + if canRefill then + ui_message("Hold E To Refuel", 1, "fuelStations") + if ePressed then + addFuel() + end + else + ui_message("", 0, "fuelStations") + end end -M.onUpdate = onUpdate -M.addFuel = addFuel -M.setFuelType = setFuelType -M.onVehicleSwitched = onVehicleSwitched -M.onVehicleSpawned = onVehicleSpawned +--debug +M.debug = function(d) debug = d end +M.savespot = function(s) + local pos = be:getObject(0):getPosition() + local payload = pos.x.."|"..pos.y.."|"..pos.z.."|"..s + local f = jsonReadFile("waypoints.json") or {} + local mapname = getMissionFilename() + f[mapname] = f[mapname] or {} + table.insert(f[mapname], payload) + jsonWriteFile("waypoints.json", f) +end -print("Fuel Stations Loaded") +--events +M.onClientPostStartMission = onClientPostStartMission +M.onUpdate = onUpdate + +--VE +M.ePress = function(e) ePressed = e end +M.setFuelType = setFuelType + +log('I','[FuelStations]', "Loaded") return M diff --git a/lua/vehicle/extensions/FuelStation/fuelStation.lua b/lua/vehicle/extensions/FuelStation/fuelStation.lua deleted file mode 100644 index 6a2bbb2..0000000 --- a/lua/vehicle/extensions/FuelStation/fuelStation.lua +++ /dev/null @@ -1,62 +0,0 @@ -local M = {} -print("[Fuel Stations] [VE] Loaded") - -local function addFuel() - print("[Fuel Stations] [VE] Add Fuel Called") - if energyStorage.getStorage('mainTank') ~= nil then - local Tank = energyStorage.getStorage('mainTank').remainingRatio - if Tank < 1 then - local Level = Tank + 0.005 - print("Adding Fuel: "..Level) - energyStorage.getStorage('mainTank'):setRemainingRatio(Level) - else - energyStorage.getStorage('mainTank'):setRemainingRatio(1.0) - end - end - - if energyStorage.getStorage('mainBattery') ~= nil then - local Battery = energyStorage.getStorage('mainBattery').remainingRatio - if Battery < 1 then - local Level = Battery + 0.005 - print("Adding Fuel: "..Level) - energyStorage.getStorage('mainBattery'):setRemainingRatio(Level) - else - energyStorage.getStorage('mainBattery'):setRemainingRatio(1.0) - end - end - - if energyStorage.getStorage('mainTankL') ~= nil then - local Tank = energyStorage.getStorage('mainTankL').remainingRatio - if Tank < 1 then - local Level = Tank + 0.005 - print("Adding Fuel: "..Level) - energyStorage.getStorage('mainTankL'):setRemainingRatio(Level) - else - energyStorage.getStorage('mainTankL'):setRemainingRatio(1.0) - end - end - - if energyStorage.getStorage('mainTankR') ~= nil then - local Tank = energyStorage.getStorage('mainTankR').remainingRatio - if Tank < 1 then - local Level = Tank + 0.005 - print("Adding Fuel: "..Level) - energyStorage.getStorage('mainTankR'):setRemainingRatio(Level) - else - energyStorage.getStorage('mainTankR'):setRemainingRatio(1.0) - end - end -end - -local function getFuelType() - if energyStorage.getStorage('mainTankR') ~= nil or energyStorage.getStorage('mainTankL') ~= nil or energyStorage.getStorage('mainTank') ~= nil then - obj:queueGameEngineLua("fuelStations.setFuelType(\'Gas\')") - elseif energyStorage.getStorage('mainBattery') ~= nil then - obj:queueGameEngineLua("fuelStations.setFuelType(\'EV\')") - end -end - -M.addFuel = addFuel -M.getFuelType = getFuelType - -return M diff --git a/lua/vehicle/extensions/auto/fuelStation.lua b/lua/vehicle/extensions/auto/fuelStation.lua new file mode 100644 index 0000000..92adb41 --- /dev/null +++ b/lua/vehicle/extensions/auto/fuelStation.lua @@ -0,0 +1,89 @@ +local M = {} + +local eState = input.keys.E + +local function updateGFX() + if input.keys.E ~= eState then + eState = (input.keys.E == true) + obj:queueGameEngineLua("if fuelStations then fuelStations.ePress("..tostring(eState)..") end") + end +end + +local function addFuel() + --log('I',"[Fuel Stations]", "Add Fuel Called") + + local storageType = nil + + for name, storage in pairs(energyStorage.getStorages()) do + if storage.remainingRatio < 1 then + storageType = storage.type + storage:setRemainingRatio(math.min(storage.remainingRatio+0.005, 1)) + --log('I',"[Fuel Stations]", "refueled ".. name) + end + end + + if storageType and storageType == "fuelTank" and electrics.values.engineRunning == 1 then + if math.random() < 0.002 then + beamstate.breakAllBreakgroups() + fire.explodeVehicle() + ui_message("Turn off your engine!", 5, "fuelStationsBoom") + end + end +end + +local function getFuelType() + if tableSize(energyStorage.getStorages()) == 0 then + log('I',"[Fuel Stations]", "did not find any fuel sources") + obj:queueGameEngineLua("if fuelStations then fuelStations.setFuelType("..obj:getID()..",'none') end") + return + end + for _, storage in pairs(energyStorage.getStorages()) do + if storage.type == "fuelTank" then + log('I',"[Fuel Stations]", "found gas tank") + obj:queueGameEngineLua("if fuelStations then fuelStations.setFuelType("..obj:getID()..",'gas') end") + return + elseif storage.type == "electricBattery" then + log('I',"[Fuel Stations]", "found ev battery") + obj:queueGameEngineLua("if fuelStations then fuelStations.setFuelType("..obj:getID()..",'ev') end") + return + end + end + log('I',"[Fuel Stations]", "found other fuel source") + obj:queueGameEngineLua("if fuelStations then fuelStations.setFuelType("..obj:getID()..",'any') end") +end + +local function repairVehicle() + local fuelAmounts = {} + for name, storage in pairs(energyStorage.getStorages()) do + fuelAmounts[name] = storage.remainingRatio + end + + guihooks.reset() + + damageTracker.reset() + wheels.reset() + electrics.reset() + powertrain.reset() + energyStorage.reset() + controller.reset() + wheels.resetSecondStage() + controller.resetSecondStage() + drivetrain.reset() + + for name, ratio in pairs(fuelAmounts) do + energyStorage.getStorage(name):setRemainingRatio(ratio) + end +end + + +M.repairVehicle = repairVehicle + +M.addFuel = addFuel +M.getFuelType = getFuelType +M.onReset = getFuelType + +M.updateGFX = updateGFX + +log('I',"[Fuel Stations]", "Script loaded") + +return M