Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a translator for friendly fire events. #106

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion helpers/replay_sm5.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ def __hash__(self):
return self.row_index


# Laserforce sometimes incorrectly stores friendly fire as _OPPONENT rather than _TEAM events. So we need to translate
# them when we detect an event done on the same team.
_FRIENDLY_FIRE_MAPPING = {
EventType.DAMAGED_OPPONENT: EventType.DAMANGED_TEAM,
EventType.DOWNED_OPPONENT: EventType.DOWNED_TEAM,
EventType.MISSILE_DAMAGE_OPPONENT: EventType.MISSILE_DAMAGE_TEAM,
EventType.MISSILE_DOWN_OPPONENT: EventType.MISSILE_DOWN_TEAM,
}

_SCORE_COLUMN = 2
_LIVES_COLUMN = 3
_SHOTS_COLUMN = 4
Expand Down Expand Up @@ -272,6 +281,12 @@ async def generate(self, game: SM5Game) -> Replay:
)

def handle_event(self, event: Events, player1, player2):
if player1 and player2 and player1.team == player2.team:
# If this is an action performed on players on the same team, it may be a _TEAM event but Laserforce
# incorrectly stores those as _OPPONENT events. So let's see if we need to translate them.
if event.type in _FRIENDLY_FIRE_MAPPING:
event.type = _FRIENDLY_FIRE_MAPPING[event.type]

# Count successful hits. Must be done before removing the shot so the accuracy is correct.
if event.type in _EVENTS_SUCCESSFUL_HITS:
player1.total_shots_hit += 1
Expand Down Expand Up @@ -369,7 +384,7 @@ def handle_event(self, event: Events, player1, player2):
self.add_sound(self.boost_audio, player1.team)

case EventType.PENALTY:
self._add_score(player1, -1000) # TODO: replace this with the penalty amount from the game info
self._add_score(player1, -1000) # TODO: replace this with the penalty amount from the game info

# Handle a player being down.
if event.type in _EVENTS_DOWNING_PLAYER:
Expand Down
Loading