Some CTF code cleanup

This commit is contained in:
Eric Froemling 2020-06-08 14:44:44 -07:00
parent 1e45d70d27
commit 86f01e4be1
2 changed files with 31 additions and 36 deletions

View File

@ -4132,16 +4132,16 @@
"assets/build/windows/x64/python.exe": "https://files.ballistica.net/cache/ba1/25/a7/dc87c1be41605eb6fefd0145144c", "assets/build/windows/x64/python.exe": "https://files.ballistica.net/cache/ba1/25/a7/dc87c1be41605eb6fefd0145144c",
"assets/build/windows/x64/python37.dll": "https://files.ballistica.net/cache/ba1/b9/e4/d912f56e42e9991bcbb4c804cfcb", "assets/build/windows/x64/python37.dll": "https://files.ballistica.net/cache/ba1/b9/e4/d912f56e42e9991bcbb4c804cfcb",
"assets/build/windows/x64/pythonw.exe": "https://files.ballistica.net/cache/ba1/6c/bb/b6f52c306aa4e88061510e96cefe", "assets/build/windows/x64/pythonw.exe": "https://files.ballistica.net/cache/ba1/6c/bb/b6f52c306aa4e88061510e96cefe",
"build/prefab/linux-server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/bf/e3/26df34acf7cada33af7f6f1d3431", "build/prefab/linux-server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/c8/9c/ea45597789b0b0ef00b3868dfd4b",
"build/prefab/linux-server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/fa/b3/4b528db89a74e80a050274f22b6c", "build/prefab/linux-server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/87/46/d99ad97bed02f7dbd8a22acfddea",
"build/prefab/linux/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/e0/02/c987aa278b2439db5a148971d8ba", "build/prefab/linux/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/0b/22/78866aed7517959f4e340318cc7c",
"build/prefab/linux/release/ballisticacore": "https://files.ballistica.net/cache/ba1/a2/9b/15a7833af0c21bbb6308a691a292", "build/prefab/linux/release/ballisticacore": "https://files.ballistica.net/cache/ba1/88/87/2a6cbc9558ff7a8244b77419055b",
"build/prefab/mac-server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/e7/9b/df93cfbca1c8feef57c3bf45b05a", "build/prefab/mac-server/debug/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/06/72/e400773b3e2765f764192acd67ac",
"build/prefab/mac-server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/25/c4/3370a0713974510c049d9c2486aa", "build/prefab/mac-server/release/dist/ballisticacore_headless": "https://files.ballistica.net/cache/ba1/41/c7/c9aafa0d4f9c83561f355495f50b",
"build/prefab/mac/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/08/3e/9506fbb6603a33434df94e9f0680", "build/prefab/mac/debug/ballisticacore": "https://files.ballistica.net/cache/ba1/db/a1/a5c09c8ee119acd9276862726fb1",
"build/prefab/mac/release/ballisticacore": "https://files.ballistica.net/cache/ba1/b3/20/b37a4700d2107b10f501b486a90e", "build/prefab/mac/release/ballisticacore": "https://files.ballistica.net/cache/ba1/ba/5f/4043991774fe98e496945c3c85fd",
"build/prefab/windows-server/debug/dist/ballisticacore_headless.exe": "https://files.ballistica.net/cache/ba1/e0/5f/89ac5f7407bba4192d4ee0a85971", "build/prefab/windows-server/debug/dist/ballisticacore_headless.exe": "https://files.ballistica.net/cache/ba1/a8/8f/953a7085c724a49ac8598819c09b",
"build/prefab/windows-server/release/dist/ballisticacore_headless.exe": "https://files.ballistica.net/cache/ba1/82/11/59011bd718f84ea698a1f8273d36", "build/prefab/windows-server/release/dist/ballisticacore_headless.exe": "https://files.ballistica.net/cache/ba1/30/95/822b29da86c0f8b0196f18723fe3",
"build/prefab/windows/debug/BallisticaCore.exe": "https://files.ballistica.net/cache/ba1/8e/3b/b1dd633355c80357bc3ddfe18e4a", "build/prefab/windows/debug/BallisticaCore.exe": "https://files.ballistica.net/cache/ba1/1f/9c/61ccc896b0c6f74910af629fc6ff",
"build/prefab/windows/release/BallisticaCore.exe": "https://files.ballistica.net/cache/ba1/21/d5/099fafed1d613b666f1b7187eea4" "build/prefab/windows/release/BallisticaCore.exe": "https://files.ballistica.net/cache/ba1/d6/c2/0708d5b471ad22ccee64de7a61e3"
} }

View File

@ -68,14 +68,9 @@ class CTFFlag(Flag):
@property @property
def team(self) -> Team: def team(self) -> Team:
"""return the flag's team.""" """The flag's team."""
return self._team return self._team
@classmethod
def from_node(cls, node: Optional[ba.Node]) -> Optional[CTFFlag]:
"""Attempt to get a CTFFlag from a flag node."""
return node.getdelegate(CTFFlag) if node else None
class Player(ba.Player['Team']): class Player(ba.Player['Team']):
"""Our player type for this game.""" """Our player type for this game."""
@ -285,9 +280,11 @@ class CaptureTheFlagGame(ba.TeamGameActivity[Player, Team]):
ba.playsound(self._swipsound, position=team.flag.node.position) ba.playsound(self._swipsound, position=team.flag.node.position)
def _handle_flag_entered_base(self, team: Team) -> None: def _handle_flag_entered_base(self, team: Team) -> None:
flag = CTFFlag.from_node(ba.getcollision().opposingnode) try:
if not flag: flag = ba.getcollision().opposingnode.getdelegate(CTFFlag, True)
print('Unable to get flag in _handle_flag_entered_base') except ba.NotFoundError:
# Don't think this should logically ever happen.
print('Error getting CTFFlag in entering-base callback.')
return return
if flag.team is team: if flag.team is team:
@ -396,13 +393,12 @@ class CaptureTheFlagGame(ba.TeamGameActivity[Player, Team]):
def _handle_flag_left_base(self, team: Team) -> None: def _handle_flag_left_base(self, team: Team) -> None:
cur_time = ba.time() cur_time = ba.time()
try: try:
flag = CTFFlag.from_node(ba.getcollision().opposingnode) flag = ba.getcollision().opposingnode.getdelegate(CTFFlag, True)
except ba.NodeNotFoundError: except ba.NotFoundError:
# We still get this call even if the flag stopped touching us # This can happen if the flag stops touching us due to being
# because it was deleted; that's ok. # deleted; that's ok.
flag = None
if not flag:
return return
if flag.team is team: if flag.team is team:
# Check times here to prevent too much flashing. # Check times here to prevent too much flashing.
@ -449,21 +445,20 @@ class CaptureTheFlagGame(ba.TeamGameActivity[Player, Team]):
return_score, return_score,
screenmessage=False) screenmessage=False)
@staticmethod
def _player_from_node(node: Optional[ba.Node]) -> Optional[Player]:
"""Return a player if given a node that is part of one's actor."""
if not node:
return None
delegate = node.getdelegate(PlayerSpaz)
return None if delegate is None else delegate.getplayer(Player)
def _handle_touching_own_flag(self, team: Team, connecting: bool) -> None: def _handle_touching_own_flag(self, team: Team, connecting: bool) -> None:
"""Called when a player touches or stops touching their own team flag. """Called when a player touches or stops touching their own team flag.
We keep track of when each player is touching their own flag so we We keep track of when each player is touching their own flag so we
can award points when returned. can award points when returned.
""" """
player = self._player_from_node(ba.getcollision().sourcenode) player: Optional[Player]
try:
player = ba.getcollision().sourcenode.getdelegate(
PlayerSpaz, True).getplayer(Player, True)
except ba.NotFoundError:
# This can happen if the player leaves but his corpse touches/etc.
player = None
if player: if player:
player.touching_own_flag += (1 if connecting else -1) player.touching_own_flag += (1 if connecting else -1)