-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_block_lists.py
More file actions
206 lines (187 loc) · 5.66 KB
/
Copy pathcommand_block_lists.py
File metadata and controls
206 lines (187 loc) · 5.66 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# Command-state names corresponding to nmspy's EnvironmentLocation values.
# nmspy's internal enum calls value 1 "Default", while the game-facing
# cGcEnvironmentLocation enum calls the same value "Space". It covers open
# space in both a ship and on-foot EVA; it is not the unknown/default fallback.
# The unset None_ value (0) intentionally resolves to UNKNOWN.
COMMAND_STATE_BY_LOCATION_VALUE = {
0: "UNKNOWN",
1: "Space",
2: "SpaceStation",
3: "PlanetOnFoot",
4: "PlanetInShip",
5: "PlanetInVehicle",
6: "Underwater",
7: "Cave",
8: "IndoorInBase",
9: "Freighter",
10: "FreighterInternals",
11: "AbandonedFreighter",
12: "InFleet",
13: "InSpaceObject",
14: "Nexus",
15: "Anomaly",
}
COMMAND_STATE_BY_LOCATION_NAME = {
"Default": "Space",
}
ON_PLANET_STATES = {
"PlanetOnFoot",
"PlanetInShip",
"PlanetInVehicle",
"Underwater",
"Cave",
"IndoorInBase",
}
# Restrictions shared by states where the player controls the character.
ON_FOOT_BLOCKED_COMMANDS = [
"land",
"anomaly",
"boost",
"cruise",
]
# Most character-control states block launch. Omit this layer in states where
# launching should remain available.
LAUNCH_BLOCKED_COMMANDS = [
"launch",
]
# Restrictions shared by states where the player controls a ship.
IN_COCKPIT_BLOCKED_COMMANDS = [
"sky",
"jet",
"walk",
"coords",
"ship",
"pet",
"dance",
"sit",
"selfie",
]
# EnvironmentLocation cannot distinguish a ship in open space from on-foot
# EVA. Keep the conservative cockpit restrictions there, except that jet and
# walk must remain usable for EVA recovery.
SPACE_BLOCKED_COMMANDS = [
command for command in IN_COCKPIT_BLOCKED_COMMANDS
if command not in {"jet", "walk"}
]
# Add commands here to block them in every planetary environment.
ON_PLANET_BLOCKED_COMMANDS = [
]
# Teleport is a recovery mechanism as well as normal travel, so location must
# never prevent it. Loading/in-progress guards still prevent overlapping warps.
LOCATION_INDEPENDENT_COMMANDS = {
"teleport",
}
# Restrictions shared by stations, space, freighters, and other non-planets.
OFF_PLANET_BLOCKED_COMMANDS = []
# Unknown includes the conservative cockpit baseline plus off-planet rules.
UNKNOWN_BLOCKED_COMMANDS = [
*IN_COCKPIT_BLOCKED_COMMANDS,
*OFF_PLANET_BLOCKED_COMMANDS,
]
BLOCKED_COMMANDS_BY_STATE = {
"Space": [
*SPACE_BLOCKED_COMMANDS,
*OFF_PLANET_BLOCKED_COMMANDS,
],
"SpaceStation": [
*ON_FOOT_BLOCKED_COMMANDS,
*OFF_PLANET_BLOCKED_COMMANDS,
],
"PlanetOnFoot": [
*ON_FOOT_BLOCKED_COMMANDS,
*LAUNCH_BLOCKED_COMMANDS,
*ON_PLANET_BLOCKED_COMMANDS,
],
"PlanetInShip": [
*IN_COCKPIT_BLOCKED_COMMANDS,
*ON_PLANET_BLOCKED_COMMANDS,
],
"PlanetInVehicle": [
*ON_FOOT_BLOCKED_COMMANDS,
*LAUNCH_BLOCKED_COMMANDS,
*ON_PLANET_BLOCKED_COMMANDS,
],
"Underwater": [
*ON_FOOT_BLOCKED_COMMANDS,
*LAUNCH_BLOCKED_COMMANDS,
*ON_PLANET_BLOCKED_COMMANDS,
],
"Cave": [
*ON_FOOT_BLOCKED_COMMANDS,
*LAUNCH_BLOCKED_COMMANDS,
*ON_PLANET_BLOCKED_COMMANDS,
],
"IndoorInBase": [
*ON_FOOT_BLOCKED_COMMANDS,
*LAUNCH_BLOCKED_COMMANDS,
*ON_PLANET_BLOCKED_COMMANDS,
],
"Freighter": [
*ON_FOOT_BLOCKED_COMMANDS,
*LAUNCH_BLOCKED_COMMANDS,
*OFF_PLANET_BLOCKED_COMMANDS,
],
"FreighterInternals": [
*ON_FOOT_BLOCKED_COMMANDS,
*LAUNCH_BLOCKED_COMMANDS,
*OFF_PLANET_BLOCKED_COMMANDS,
],
"AbandonedFreighter": [
*ON_FOOT_BLOCKED_COMMANDS,
*LAUNCH_BLOCKED_COMMANDS,
*OFF_PLANET_BLOCKED_COMMANDS,
],
"InFleet": [
*ON_FOOT_BLOCKED_COMMANDS,
*LAUNCH_BLOCKED_COMMANDS,
*OFF_PLANET_BLOCKED_COMMANDS,
],
"InSpaceObject": [
*ON_FOOT_BLOCKED_COMMANDS,
*LAUNCH_BLOCKED_COMMANDS,
*OFF_PLANET_BLOCKED_COMMANDS,
],
"Nexus": [
*ON_FOOT_BLOCKED_COMMANDS,
*OFF_PLANET_BLOCKED_COMMANDS,
],
"Anomaly": [
*ON_FOOT_BLOCKED_COMMANDS,
*OFF_PLANET_BLOCKED_COMMANDS,
],
"GALAXY_MAP": [
*UNKNOWN_BLOCKED_COMMANDS,
],
"UNKNOWN": [
*UNKNOWN_BLOCKED_COMMANDS,
],
}
def resolve_command_state(data, fallback="UNKNOWN"):
"""Resolve a state snapshot to one of the command block-list keys."""
data = data or {}
game_state = data.get("state")
if game_state in {"GALAXY_MAP", "UNKNOWN"}:
return game_state
environment = data.get("environment") or {}
location = environment.get("location_stable")
if location is None:
location = environment.get("location")
if location == "None_":
return "UNKNOWN"
location = COMMAND_STATE_BY_LOCATION_NAME.get(location, location)
if location in BLOCKED_COMMANDS_BY_STATE:
return location
raw = environment.get("location_stable_raw")
if raw is None:
raw = environment.get("location_raw")
try:
location = COMMAND_STATE_BY_LOCATION_VALUE.get(int(raw))
except (TypeError, ValueError):
location = None
fallback = COMMAND_STATE_BY_LOCATION_NAME.get(fallback, fallback)
return location or (fallback if fallback in BLOCKED_COMMANDS_BY_STATE else "UNKNOWN")
def blocked_commands_for_state(state):
"""Return the configured list, failing closed for an unrecognized state."""
state = COMMAND_STATE_BY_LOCATION_NAME.get(state, state)
blocked = BLOCKED_COMMANDS_BY_STATE.get(state, BLOCKED_COMMANDS_BY_STATE["UNKNOWN"])
return [command for command in blocked if command not in LOCATION_INDEPENDENT_COMMANDS]