Commit 1b3d7bd7 authored by talljosh's avatar talljosh
Browse files

Approving changes

parent 3b6c8e2fe3ff
......@@ -585,8 +585,9 @@ class BulletsSmall(Streak, OncePerPlayerPerGame):
self.shotFired, lifespan=self.lifespan)
self.player.onDied.addListener(self.died, lifespan=self.lifespan)
def shotFired(self, *args, **kwargs):
self.increment()
def shotFired(self, shot):
if shot.gun_type.shots_hurt_players:
self.increment()
def died(self, *args, **kwargs):
self.reset()
......@@ -604,8 +605,9 @@ class BulletsMedium(Streak, OncePerPlayerPerGame):
self.player.onShotFired.addListener(
self.shotFired, lifespan=self.lifespan)
def shotFired(self, *args, **kwargs):
self.increment()
def shotFired(self, shot):
if shot.gun_type.shots_hurt_players:
self.increment()
class WinnerBase(Streak, OnceEverPerPlayer):
......@@ -1019,8 +1021,8 @@ class MinimapDisruptionTag(OncePerPlayerPerGame):
self.player.onTaggedZone.addListener(
self.taggedZone, lifespan=self.lifespan)
def taggedZone(self, *args, **kwargs):
if self.player.team and self.player.team.usingMinimapDisruption:
def taggedZone(self, zone, previous_owner):
if previous_owner and previous_owner.is_minimap_disrupted():
self.achievementTriggered()
......@@ -1040,7 +1042,10 @@ class ChokepointSpam(Streak, OncePerPlayerPerGame):
self.player.onShotFired.addListener(
self.shotFired, lifespan=self.lifespan)
def shotFired(self, *args, **kwargs):
def shotFired(self, shot):
if not shot.gun_type.shots_hurt_players:
return
# Strictly speaking, the player is still able to move or die, but if
# they don't shoot from exactly the same spot it won't count anyway.
if self.player.pos != self.pos:
......@@ -1048,7 +1053,7 @@ class ChokepointSpam(Streak, OncePerPlayerPerGame):
self.pos = self.player.pos
def killedPlayer(self, shooter, deathType, *args, **kwargs):
if not self.player.items.hasAny() and deathType != GRENADE_HIT:
if not self.player.items.hasAny() and deathType in {SHOT_HIT, SHOXWAVE_HIT}:
self.increment()
......
......@@ -94,7 +94,9 @@ class PlayerStatKeeper(object):
self.player.onCoinsChanged.removeListener(self.coinsChanged)
self.paused = True
def shotFired(self, *args, **kwargs):
def shotFired(self, shot):
if not shot.gun_type.shots_hurt_players:
return
self.shotsFired += 1
if self.shotsFired >= 100:
......@@ -195,7 +197,9 @@ class PlayerStatKeeper(object):
self.zoneScore += captureInfo['points'] / len(captureInfo['attackers'])
def shotHit(self, *args, **kwargs):
def shotHit(self, shot):
if not shot.gun_type.shots_hurt_players:
return
self.shotsHit += 1
def coinsSpent(self, coins):
......@@ -306,6 +310,9 @@ class StatKeeper(object):
# We want to identify by user rather than nickname if the user
# is authenticated.
yield player.onJoinComplete.wait()
if player.id == -1:
# Player has already been removed from game
return
statkeeper = self.allPlayerStatLists.get(player.identifyingName)
if statkeeper:
......@@ -321,7 +328,11 @@ class StatKeeper(object):
self.playerStatList[oldId].goneFromGame()
# Just remove this from the list of current players
# (retain in list of all stats)
del self.playerStatList[oldId]
try:
del self.playerStatList[oldId]
except KeyError:
# Player might still be waiting for onJoinComplete()
pass
def gameOver(self, team):
self.winningTeamId = team.id if team else NEUTRAL_TEAM_ID
......
......@@ -44,5 +44,6 @@ from trosnoth.messages.special import ( # noqa
from trosnoth.messages.upgrades import ( # noqa
BuyUpgradeMsg, PlayerHasUpgradeMsg, PlayerCoinsSpentMsg, BuyAmmoMsg,
AwardPlayerCoinMsg, CannotBuyUpgradeMsg, SetPlayerCoinsMsg,
UpgradeChangedMsg, UpgradeApprovedMsg, MineLaunchedMsg, MineExplodedMsg,
UpgradeChangedMsg, UpgradeApprovedMsg, TeamUpgradePaidMsg,
MineLaunchedMsg, MineExplodedMsg,
)
......@@ -359,6 +359,8 @@ class SetPlayerTeamMsg(ServerCommand):
def applyOrderToWorld(self, world):
player = world.getPlayer(self.playerId)
if not player:
return
player.team = world.getTeam(self.teamId)
player.onTeamSet()
......@@ -518,7 +520,8 @@ class SetAgentPlayerMsg(ServerCommand):
def applyOrderToLocalState(self, localState, world):
player = world.getPlayer(self.playerId)
assert self.playerId == NO_PLAYER or player is not None
player.agent = localState.agent
if player:
player.agent = localState.agent
localState.agent.setPlayer(player)
......
......@@ -9,7 +9,6 @@ log = logging.getLogger(__name__)
class PhysicsConstants(object):
STATE_ATTRS = [
'normal',
'shooting',
'shotSpeed',
'shotLifetime',
......@@ -24,13 +23,8 @@ class PhysicsConstants(object):
'playerOwnDarkReloadTime',
'playerNeutralReloadTime',
'playerEnemyDarkReloadTime',
'playerMachineGunReloadRate',
'playerMachineGunFireRate',
'playerShotHeat',
'playerRespawnTotal',
'playerBounce',
'playerRespawnHealth',
'playerShoxwaveReloadRate',
'grenadeMaxFallVel',
'grenadeGravity',
'grenadeInitVel',
......@@ -56,11 +50,9 @@ class PhysicsConstants(object):
def _standard(self, pace=1, fireRate=1, gravity=1, jumpHeight=1,
respawnRate=1, shotSpeed=1, shotLength=1, bounce=False,
respawnHealth=1, shooting=True, trosballTime=5, shotFactor=1,
normal=False, playerDampingFactor=0.3):
normal=False):
self.normal = normal
self.shooting = shooting
self.playerDampingFactor = playerDampingFactor
# Speed that shots travel at.
self.shotSpeed = 600 * shotSpeed # pix/s
......@@ -85,14 +77,9 @@ class PhysicsConstants(object):
self.playerOwnDarkReloadTime = 1 / 2.7 / fireRate # s
self.playerNeutralReloadTime = 1 / 2. / fireRate # s
self.playerEnemyDarkReloadTime = 1 / 1.4 / fireRate # s
self.playerMachineGunReloadRate = 8 # times normal reload time
self.playerMachineGunFireRate = 0.1 / fireRate # s
self.playerShotHeat = 0.4
self.playerRespawnTotal = 7.5 / respawnRate
self.bomberRespawnTime = self.playerRespawnTotal * 0.4
self.playerBounce = bounce
self.playerRespawnHealth = respawnHealth
self.playerShoxwaveReloadRate = 1 / 0.7
self.grenadeMaxFallVel = 700. * gravity
self.grenadeGravity = 300 * gravity
......@@ -101,11 +88,6 @@ class PhysicsConstants(object):
self.trosballExplodeTime = trosballTime
# For calculation of cost of shortest path
xMax = max(self.playerXVel, self.playerSlowXVel)
yMax = max(self.playerMaxFallVel, self.playerJumpThrust)
self.maxLivePlayerSpeed = (xMax ** 2 + yMax ** 2) ** 0.5
def dumpState(self):
return {k: getattr(self, k) for k in self.STATE_ATTRS}
......
......@@ -23,8 +23,8 @@ from trosnoth.messages import (
PlaySoundMsg, SetPlayerCoinsMsg, UpdateGameInfoMsg, SetWorldAbilitiesMsg,
UpdateScoreBoardModeMsg, SetTeamScoreMsg, SetPlayerScoreMsg,
SetTeamAbilitiesMsg, EmoteMsg, AgentDetachedMsg, ChangeHeadMsg,
SetPlayerAbilitiesMsg, ChangeTeamMsg, SwitchGunMsg,
SetMaxHealthMsg, SetHealthMsg, BuyAmmoMsg,
SetPlayerAbilitiesMsg, ChangeTeamMsg, SwitchGunMsg, MineLaunchedMsg, MineExplodedMsg,
SetMaxHealthMsg, SetHealthMsg, TeamUpgradePaidMsg, BuyAmmoMsg,
)
from trosnoth.network.base import MsgClientProtocol
from trosnoth.utils.event import Event
......@@ -40,6 +40,7 @@ clientMsgs = netmsg.MessageCollection(
TaggingZoneMsg,
PlayerCoinsSpentMsg,
PlayerHasUpgradeMsg,
TeamUpgradePaidMsg,
ShotFiredMsg,
AddPlayerMsg,
SetPlayerTeamMsg,
......@@ -99,6 +100,8 @@ clientMsgs = netmsg.MessageCollection(
SetHealthMsg,
SwitchGunMsg,
BuyAmmoMsg,
MineLaunchedMsg,
MineExplodedMsg,
)
......
......@@ -251,7 +251,6 @@ class ThemeSprites(object):
def mine(self, angle, team_colour=None):
sheet = self.coloured_mine_sprite_sheet(team_colour)
j, i = divmod(round(angle * 32 / pi) % 64, 8)
return sheet.subsurface(
get_sprite_sheet_source_rect(i, j, sheet=sheet, cell_map_width=16, cell_map_height=16))
......@@ -321,10 +320,6 @@ class ThemeSprites(object):
frames.append(surface)
return Animation(0.05, timer, *frames)
def explosion(self, timer):
return Animation(
0.07, timer, *(self.explosionFrame(i) for i in range(4)))
def grenade_explosion(self, timer):
return SpriteSheetAnimation(1 / 60, timer, self.grenade_explosion_sprite_sheet(), 6, 6)
......@@ -749,4 +744,4 @@ UNSCALED_FONTS = {
'newChatFont',
'winMessageFont',
'bigZoneFont',
}
\ No newline at end of file
}
......@@ -76,6 +76,7 @@ class GameInterface(framework.CompoundElement, ConcreteAgent):
self.world.onGrenadeExplosion.addListener(self.grenadeExploded)
self.world.onTrosballExplosion.addListener(self.trosballExploded)
self.world.onBomberExplosion.addListener(self.trosballExploded)
self.world.on_mine_explosion.addListener(self.mine_exploded)
self.world.uiOptions.onChange.addListener(self.uiOptionsChanged)
self.world.elephant.on_transfer.addListener(self.elephant_transferred)
self.world.juggernaut.on_transfer.addListener(self.juggernaut_transferred)
......@@ -213,6 +214,7 @@ class GameInterface(framework.CompoundElement, ConcreteAgent):
self.world.onGrenadeExplosion.removeListener(self.grenadeExploded)
self.world.onTrosballExplosion.removeListener(self.trosballExploded)
self.world.onBomberExplosion.removeListener(self.trosballExploded)
self.world.on_mine_explosion.removeListener(self.mine_exploded)
self.world.uiOptions.onChange.removeListener(self.uiOptionsChanged)
self.timingsLoop.stop()
self.gameViewer.stop()
......@@ -414,7 +416,8 @@ class GameInterface(framework.CompoundElement, ConcreteAgent):
self.subscribedPlayers.discard(player)
def lostPlayer(self):
self.runningPlayerInterface.stop()
if self.runningPlayerInterface:
self.runningPlayerInterface.stop()
self.runningPlayerInterface = None
self.detailsInterface.setPlayer(None)
self.setElements()
......@@ -598,6 +601,11 @@ class GameInterface(framework.CompoundElement, ConcreteAgent):
localPlayer = self.localState.player
self.gameViewer.worldgui.addShoxwaveExplosion(localPlayer.pos)
def mine_exploded(self, pos):
self.gameViewer.worldgui.add_mine_explosion(pos)
dist = self.distance(pos)
self.playSound('explodeGrenade', self.getSoundVolume(dist))
@UpgradeChangedMsg.handler
def upgradeChanged(self, msg):
self.detailsInterface.upgradeDisplay.refresh()
......
......@@ -116,12 +116,15 @@ class MiniMap(framework.Element):
area.top = 0
return self.disruption_frame
def mapPosToMinimap(self, sRect, xxx_todo_changeme):
(x, y) = xxx_todo_changeme
def mapPosToMinimap(self, s_rect, pos):
x, y = pos
fx, fy = self._focus
cx, cy = sRect.center
cx, cy = s_rect.center
s = self.scale
return (int((x - fx + 0.5) / s + cx), int((y - fy + 0.5) / s + cy))
x1, y1 = round(x / s), round(y / s)
x0, y0 = round(fx / s), round(fy / s)
return (x1 - x0 + cx, y1 - y0 + cy)
def minimapPosToMap(self, sRect, xxx_todo_changeme1):
(x, y) = xxx_todo_changeme1
......
......@@ -13,7 +13,7 @@ from trosnoth.const import (
from trosnoth.gui.framework import framework
from trosnoth.gui.keyboard import mouseButton
from trosnoth.messages import (
UpdatePlayerStateMsg, AimPlayerAtMsg, ShootMsg, GrapplingHookMsg,
UpdatePlayerStateMsg, AimPlayerAtMsg, GrapplingHookMsg,
)
from trosnoth.model.unit import TrajectoryClickAction
from trosnoth.utils import globaldebug
......@@ -93,7 +93,7 @@ class PlayerInterface(framework.Element):
self.updateMouse()
self.updatePlayerViewAngle()
if self.player.can_shoot():
if self.player.machineGunner and self.mouse_down:
if self.player.current_gun.can_hold_mouse and self.mouse_down:
self._fireShot()
# Sometimes Pygame seems to miss some keyboard events, so double
......@@ -207,10 +207,13 @@ class PlayerInterface(framework.Element):
else:
di.doAction(ACTION_USE_UPGRADE)
elif self.player.dead:
di.doAction(ACTION_RESPAWN)
# Don’t immediately fire machine gun
self.mouse_down = False
elif not self.player.machineGunner:
elif not self.player.current_gun.can_hold_mouse:
self._fireShot()
else:
self.processKeyEvent(mouseButton(event.button), True)
......@@ -254,4 +257,4 @@ class PlayerInterface(framework.Element):
'''Fires a shot in the direction the player's currently looking.'''
if self.world.uiOptions.showPauseMessage:
return
self.gameInterface.sendRequest(ShootMsg(self.getTickId()))
self.player.current_gun.please_shoot()
......@@ -2,6 +2,7 @@ import pygame
from trosnoth.const import MAP_TO_SCREEN_SCALE
def blitPart(surface, source, dest, part):
'''
Performs a blit, positioning the source on the surface as for
......@@ -24,10 +25,13 @@ def zonePosToScreen(pt, focus, area):
def mapPosToScreen(pt, focus, area):
return (int((pt[0] - focus[0]) * MAP_TO_SCREEN_SCALE + area.centerx + 0.5),
int((pt[1] - focus[1]) * MAP_TO_SCREEN_SCALE + area.centery + 0.5))
# To ensure rounding error doesn't result in drifting pixels, we need to
# separately multiply the point and focus and round each.
x1, y1 = round(pt[0] * MAP_TO_SCREEN_SCALE), round(pt[1] * MAP_TO_SCREEN_SCALE)
x0, y0 = round(focus[0] * MAP_TO_SCREEN_SCALE), round(focus[1] * MAP_TO_SCREEN_SCALE)
return (x1 - x0 + area.centerx, y1 - y0 + area.centery)
def screenToMapPos(pt, focus, area):
return (int((pt[0] - area.centerx) / MAP_TO_SCREEN_SCALE + 0.5) + focus[0],
int((pt[1] - area.centery) / MAP_TO_SCREEN_SCALE + 0.5) + focus[1])
\ No newline at end of file
int((pt[1] - area.centery) / MAP_TO_SCREEN_SCALE + 0.5) + focus[1])
......@@ -281,6 +281,9 @@ class ViewManager(framework.Element):
for coin in self.universe.iterCollectableCoins():
drawSprite(coin)
for projectile in self.universe.iter_projectiles():
drawSprite(projectile)
try:
# Draw the grenades.
for grenade in self.universe.iterGrenades():
......@@ -976,7 +979,7 @@ class GameViewer(framework.CompoundElement):
self.worldgui.setTweenFraction(self.app.tweener.uiTick(deltaT))
target = self.viewManager.target
if isinstance(target, PlayerSprite) and target.isMinimapDisrupted:
if isinstance(target, PlayerSprite) and target.is_minimap_disrupted():
self.miniMap.disrupted()
self.zoneBar.disrupt = True
else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment