Last active
October 4, 2023 23:38
-
-
Save Novaras/097640f6638b4e5cdf20c02e31c08852 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HYPERSPACE_STATES = { | |
DEFAULT = 0, | |
INSIDE = 1, | |
EXITING = 2, | |
EXITED = 3 | |
}; | |
-- [ship id]: <hyperspace state> | |
SHIP_HYPERSPACE_STATES = {}; | |
LAST_HS_ENTER_NOISE_TIME = nil; | |
-- handles the next hyperspace action for this ship to perform, if any are necessary | |
function handle_hyperspace(group, ship_id) | |
local s = SHIP_HYPERSPACE_STATES; | |
if (s[ship_id] == nil) then | |
s[ship_id] = HYPERSPACE_STATES.DEFAULT; | |
end | |
local action_index = s[ship_id]; | |
-- the possible action types mapped to their implementations | |
-- they all have the same function signature: take the group, return the state to set for the caller ship | |
local hyperspace_actions = { | |
[HYPERSPACE_STATES.DEFAULT] = function (group) | |
if (SobGroup_IsDoingAbility(group, AB_Hyperspace) == 1) then | |
if (LAST_HS_ENTER_NOISE_TIME == nil or LAST_HS_ENTER_NOISE_TIME + 0.2 < clock()) then | |
LAST_HS_ENTER_NOISE_TIME = clock(); | |
Sound_SFXPlay3DPos("data:sound/sfx/etg/special/ftl_depart", SobGroup_GetPosition(group)); | |
FX_PlayEffect("bsg_hyperspace", group, 1); | |
end | |
return HYPERSPACE_STATES.INSIDE; | |
end | |
end, | |
[HYPERSPACE_STATES.INSIDE] = function (group) | |
if (SobGroup_AreAllInHyperspace(group) == 1) then | |
return HYPERSPACE_STATES.EXITING; | |
end | |
end, | |
[HYPERSPACE_STATES.EXITING] = function (group) | |
if (SobGroup_IsDoingAbility(group, AB_Hyperspace) == 0 or SobGroup_AreAllInHyperspace(group) == 0) then | |
if (LAST_HS_ENTER_NOISE_TIME == nil or LAST_HS_ENTER_NOISE_TIME + 0.2 < clock()) then | |
LAST_HS_ENTER_NOISE_TIME = clock(); | |
Sound_SFXPlay3DPos("data:sound/sfx/etg/special/ftl_arrive", SobGroup_GetPosition(group)); | |
FX_PlayEffect("bsg_hyperspace", group, 1); | |
end | |
end | |
return HYPERSPACE_STATES.EXITED; | |
end, | |
[HYPERSPACE_STATES.EXITED] = function (group) | |
if (SobGroup_IsDoingAbility(group, AB_Hyperspace) == 0 and SobGroup_AreAllInHyperspace(group) == 0) then | |
return HYPERSPACE_STATES.DEFAULT; | |
end | |
end | |
}; | |
-- here we call the correct function, and update our state as its return value | |
s[ship_id] = hyperspace_actions[action_index](group); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment