-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlogWorldStatistics.lua
More file actions
158 lines (128 loc) · 5.38 KB
/
Copy pathlogWorldStatistics.lua
File metadata and controls
158 lines (128 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
-- initialization
-- ensure imports are from file instead of cache
local function import(path)
package.loaded[path] = nil
local imported = require (path)
package.loaded[path] = nil
return imported
end
-- import dependencies
local json = import("./json.lua/json")
local compTools = import("./AM-CompTools/compTools")
local nodeTools = import"nodeTools"
--initialize GLBL table if needed
if GLBL == nil then
GLBL = {}
end
--initialize SCRIPT table
--Stores global variables for just this script
local SCRIPT = {}
--initialize RNG
math.randomseed( os.time() )
-- define player movement speeds in m/s
SCRIPT.walkingSpeed = 4.317
SCRIPT.sprintSpeed = 5.612
SCRIPT.sprintJumpingSpeed = 7
SCRIPT.sprintJumpingRooflessIceSpeed = 9.23
SCRIPT.sprintJumpingIceSpeed = 16.9
-- functions
function SCRIPT.slog(string)
log("&7[&6NodeStats&7]&f ", string)
end
function SCRIPT.pathTypeBetweenNodes(node1, node2)
--initialize function
--initialize function table
local FUNC = {}
--store arguments in known scoped table
FUNC.node1, FUNC.node2 = node1, node2
if FUNC.node1.pathType == FUNC.node2.pathType then
return FUNC.node1.pathType
else
return "normal"
end
end
function SCRIPT.getPathTypeTravelSpeed(pathType)
--initialize function
--initialize function table
local FUNC = {}
--store arguments in known scoped table
FUNC.pathType = pathType
if FUNC.pathType == "iceroad" then
return SCRIPT.sprintJumpingIceSpeed
elseif FUNC.pathType == "roofless iceroad" then
return SCRIPT.sprintJumpingRooflessIceSpeed
else
return SCRIPT.sprintSpeed
end
end
function SCRIPT.secondsToClock(seconds)
return os.date('!%d:%H:%M:%S', seconds)
end
function SCRIPT.tableKeyCount(table)
--initialize function
--initialize function table
local FUNC = {}
--store arguments in known scoped table
FUNC.table = table
FUNC.count = 0
for _ in pairs(FUNC.table) do
FUNC.count = FUNC.count + 1
end
return FUNC.count
end
--Main Program
--initialize MAIN table
--Stores variables for just MAIN function
local MAIN = {}
-- get GLBL.nodes
GLBL.nodes = nodeTools.loadNodesfromJSON()
-- get total path distance
MAIN.totalDistance = 0
MAIN.connectionsAlreadyUsed = {}
for key,value in pairs(GLBL.nodes) do
MAIN.node = key
for key,value in pairs(GLBL.nodes[MAIN.node]["connections"]) do
MAIN.neighbor = key
if MAIN.connectionsAlreadyUsed[MAIN.neighbor .. MAIN.node] == nil then
MAIN.totalDistance = MAIN.totalDistance + compTools.distanceBetweenPoints(GLBL.nodes[MAIN.neighbor].x,GLBL.nodes[MAIN.neighbor].y,GLBL.nodes[MAIN.neighbor].z, GLBL.nodes[MAIN.node].x,GLBL.nodes[MAIN.node].y,GLBL.nodes[MAIN.node].z)
MAIN.connectionsAlreadyUsed[MAIN.node .. MAIN.neighbor] = true
end
end
end
SCRIPT.slog("Distance of all paths (in meters): " .. math.floor(MAIN.totalDistance))
-- num nodes
SCRIPT.slog("Node count: " .. SCRIPT.tableKeyCount(GLBL.nodes))
-- intersections
MAIN.intersectionCount = 0
for key,value in pairs(GLBL.nodes) do
MAIN.node = key
if SCRIPT.tableKeyCount(GLBL.nodes[MAIN.node].connections) > 2 then
MAIN.intersectionCount = MAIN.intersectionCount + 1
end
end
SCRIPT.slog("Intersection count: " .. MAIN.intersectionCount)
-- display number of expandable rails
MAIN.nearestExpandableRail, MAIN.expandbleRailCount = nodeTools.nearestExpandableRail()
-- handle nil
if MAIN.expandbleRailCount == nil then
MAIN.expandbleRailCount = 0
end
SCRIPT.slog("Expandable rails: " .. MAIN.expandbleRailCount)
-- display minimum time to travel all paths
MAIN.totalTravelTime = 0
-- for each unuque path
for key,value in pairs(GLBL.nodes) do
MAIN.node = key
-- for each unuque path
for key,value in pairs(GLBL.nodes[MAIN.node]["connections"]) do
MAIN.neighbor = key
-- for each unuque path
if MAIN.connectionsAlreadyUsed[MAIN.neighbor .. MAIN.node] == nil then
MAIN.pathType = SCRIPT.pathTypeBetweenNodes(MAIN.node, MAIN.neighbor)
MAIN.travelSpeed = SCRIPT.getPathTypeTravelSpeed(MAIN.pathType)
MAIN.pathDistance = compTools.distanceBetweenPoints(GLBL.nodes[MAIN.neighbor].x,GLBL.nodes[MAIN.neighbor].y,GLBL.nodes[MAIN.neighbor].z, GLBL.nodes[MAIN.node].x,GLBL.nodes[MAIN.node].y,GLBL.nodes[MAIN.node].z)
MAIN.totalTravelTime = MAIN.totalTravelTime + MAIN.pathDistance / MAIN.travelSpeed
end
end
end
SCRIPT.slog("Minimum time to traverse all paths: " .. SCRIPT.secondsToClock(MAIN.totalTravelTime))