def doTurn( self, game ): (ao,ro,ag) = Ship.doTurn(self, game) if self.inNebula and self.ttl%(config.fps*2)==0: self.loseTarget( game ) if self.lostTarget and (self.originalTtl-self.ttl)>config.fps: self.launcher = None # detect hit for obj in game.objects.getWithinRadius( self, self.stats.maxRadius ): if obj.alive and obj.player and (not self.launcher or obj.player != self.launcher.player): if self.launcher: sender = self.launcher.player else: sender = None (ao0, ro0, ag0) = obj.hit( game, utils.angleBetweenObjects( obj, self ), sender, self.weapon.stats.energyDamage, self.weapon.stats.massDamage ) (ao1, ro1, ag1) = self.explode( game ) (ao, ro, ag) = (ao+ao0+ao1, ro+ro0+ro1, ag+ag0+ag1) break if self.alive and not (self.originalTtl-self.ttl)%self.thinkFreq: if isinstance( self.target, Object ): target = ( self.target.xp, self.target.yp ) if not self.target.alive: self.target = target else: target = self.target # ori destAngle = utils.angleBetween( (self.xp,self.yp), target ) angle = utils.angleDiff( destAngle, self.ori ) absAngle = fabs( angle ) if absAngle > self.stats.maxRg*2: # *(config.fps/10): #*5: if angle > 0: self.rg = self.stats.maxRg else: self.rg = -1*self.stats.maxRg else: self.rg = 0 self.thrust = self.stats.maxThrust if utils.distLowerThan( (self.xp,self.yp), target, self.stats.maxRadius*4 ): (ao1, ro1, ag1) = self.explode( game ) (ao, ro, ag) = (ao+ao1, ro+ro1, ag+ag1) # self.alive = False # ro.append( self ) # ag.append( GfxExplosion( (self.xp,self.yp), self.stats.maxRadius*3 ) ) if self.alive: if self.ttl == 0: self.alive = False ro.append( self ) else: self.ttl = self.ttl - 1 return (ao,ro,ag)
def doTurn(self, game): oldRadius = self.radius self.radius += self.speed for player in game.players: if (player != self.sender or oldRadius != 0 ) \ and player.flagship and player.flagship.alive: # ship listening dist = utils.distBetween(self.origin, player.flagship.pos) if dist < self.radius and dist >= oldRadius - self.overlap: # ship in area covered this turn if self.angle and oldRadius > 0.1: angle = utils.angleBetween(self.origin, player.flagship.pos) inAngle = angle > self.angle - self.angleCover and angle < self.angle + self.angleCover else: inAngle = True if inAngle: player.msgs.append( self.getMessageArchived(game, player)) if self.radius > self.maxRadius * 5: self.alive = False elif self.radius > self.maxRadius: # degrade message quality if random() < self.pDegradation: # *len(self.text): # probability if len(self.text) == 1: self.alive = False else: posLost = randint(0, len(self.text) - 1) # pos to lose self.text = self.text[:posLost] + self.text[posLost + 1:]
def doTurn( self, game ): oldRadius = self.radius self.radius += self.speed for player in game.players: if (player != self.sender or oldRadius != 0 ) \ and player.flagship and player.flagship.alive: # ship listening dist = utils.distBetween( self.origin, player.flagship.pos ) if dist < self.radius and dist >= oldRadius-self.overlap: # ship in area covered this turn if self.angle and oldRadius > 0.1: angle = utils.angleBetween( self.origin, player.flagship.pos ) inAngle = angle > self.angle-self.angleCover and angle < self.angle+self.angleCover else: inAngle = True if inAngle: player.msgs.append( self.getMessageArchived( game, player ) ) if self.radius > self.maxRadius*5: self.alive = False elif self.radius > self.maxRadius: # degrade message quality if random() < self.pDegradation: # *len(self.text): # probability if len( self.text ) == 1: self.alive = False else: posLost = randint( 0, len( self.text )-1 ) # pos to lose self.text = self.text[:posLost]+self.text[posLost+1:]
class LaserWeapon(Weapon): def fire(self, ship, game, target): (ao, ro, gfxs) = Weapon.fire(self, ship, game) for o in self.getPoss(ship, game): (ao0, ro0, gfxs0) = self.hits(o, ship.ori, game, ship, target, ship.weapon) (ao, ro, gfxs) = (ao + ao0, ro + ro0, gfxs + gfxs0) return (ao, ro, gfxs) def hits(self, (xo, yo), ori, game, ship, target, weapon): """Logic: compares the angle to target with the weapon orientation to atan( target.radius / dist between weapon and target )""" angle = utils.angleBetween((xo, yo), (target.xp, target.yp)) dist = utils.distBetween((xo, yo), (target.xp, target.yp)) if dist: angleSec = atan(float(target.stats.radius) / dist) else: angleSec = 0 diff = (ori - angle) % (2 * pi) if diff < angleSec or 2 * pi - diff < angleSec: ## hit! a = ori + pi hullBefore = target.hull (ao, ro, gfxs) = target.hit(game, pi + ori, ship.player, weapon.stats.energyDamage, weapon.stats.massDamage) if hullBefore != target.hull: # went throught the shield d = (xo + cos(ori) * dist, yo + sin(ori) * dist) else: d = (xo + cos(ori) * (dist - target.stats.maxRadius / 2), yo + sin(ori) * (dist - target.stats.maxRadius / 2)) else: (ao, ro, gfxs) = ([], [], []) d = (xo + cos(ori) * weapon.stats.maxRange, yo + sin(ori) * weapon.stats.maxRange) # print (xo,yo), max( ship.zp, target.zp)+1, d, weapon.stats.laserWidth, 0 gfxs.append( weapon.stats.gfxAtFire((xo, yo), max(ship.zp, target.zp) + 1, d, weapon.stats.laserWidth, color=ship.player.race.type)) return (ao, ro, gfxs) # (None, None)
class OmniLaserWeaponTurret(LaserWeaponTurret): def hits(self, (xo, yo), ori, game, ship, target, weapon): """Logic: compares the angle to target with the weapon orientation to atan( target.radius / dist between weapon and target )""" angle = utils.angleBetween((target.xp, target.yp), (xo, yo)) hullBefore = target.hull (ao, ro, gfxs) = target.hit(game, angle, ship.player, weapon.stats.energyDamage, weapon.stats.massDamage) if hullBefore != target.hull: # went throught the shield d = (target.xp + target.stats.maxRadius / 4 * cos(angle), target.yp + target.stats.maxRadius / 4 * sin(angle)) else: d = (target.xp + target.stats.maxRadius * cos(angle), target.yp + target.stats.maxRadius * sin(angle)) gfxs.append( weapon.stats.gfxAtFire((xo, yo), max(ship.zp, target.zp) + 1, d, weapon.stats.laserWidth, color=ship.player.race.type)) return (ao, ro, gfxs)
def addWideBroadcast( self, game, player, text, ship=None, encryption=None ): if not ship: ship = player.flagship if encryption == None: encryption = ship.cryptionStrength origin = ship.pos self.addCommunication( game, MessageActive( game, player, text, encryption=encryption, origin=origin ) ) def addDirectedBroadcast( self, game, player, text, (x,y), ship=None, encryption=None ): if not ship: ship = player.flagship if encryption == None: encryption = ship.cryptionStrength origin = ship.pos angle = utils.angleBetween( origin, (x,y) ) dist = utils.distBetween( origin, (x,y) ) radiusAtTarget = max( 100, min( 500, dist/25 ) ) angleCover = atan2( radiusAtTarget, dist ) # origin = (origin[0]-1*cos(angle), origin[1]-1*cos(angle)) # overwrite to allow sender to receive message # print text, encryption, origin, angle, dist+radiusAtTarget, angleCover self.addCommunication( game, MessageActive( game, player, text, encryption=encryption, origin=origin, angle=angle, radius=dist+radiusAtTarget, angleCover=angleCover ) ) def doTurn( self, game ): newList = [] for communication in self.communications: communication.doTurn( game ) if communication.alive: newList.append( communication ) self.communications = newList
encryption=encryption, origin=origin)) def addDirectedBroadcast(self, game, player, text, (x, y), ship=None, encryption=None): if not ship: ship = player.flagship if encryption == None: encryption = ship.cryptionStrength origin = ship.pos angle = utils.angleBetween(origin, (x, y)) dist = utils.distBetween(origin, (x, y)) radiusAtTarget = max(100, min(500, dist / 25)) angleCover = atan2(radiusAtTarget, dist) # origin = (origin[0]-1*cos(angle), origin[1]-1*cos(angle)) # overwrite to allow sender to receive message # print text, encryption, origin, angle, dist+radiusAtTarget, angleCover self.addCommunication( game, MessageActive(game, player, text, encryption=encryption, origin=origin, angle=angle, radius=dist + radiusAtTarget, angleCover=angleCover))
def doTurn(self, game): (ao, ro, ag) = Ship.doTurn(self, game) if self.inNebula and self.ttl % (config.fps * 2) == 0: self.loseTarget(game) if self.lostTarget and (self.originalTtl - self.ttl) > config.fps: self.launcher = None # detect hit for obj in game.objects.getWithinRadius(self, self.stats.maxRadius): if obj.alive and obj.player and ( not self.launcher or obj.player != self.launcher.player): if self.launcher: sender = self.launcher.player else: sender = None (ao0, ro0, ag0) = obj.hit(game, utils.angleBetweenObjects(obj, self), sender, self.weapon.stats.energyDamage, self.weapon.stats.massDamage) (ao1, ro1, ag1) = self.explode(game) (ao, ro, ag) = (ao + ao0 + ao1, ro + ro0 + ro1, ag + ag0 + ag1) break if self.alive and not (self.originalTtl - self.ttl) % self.thinkFreq: if isinstance(self.target, Object): target = (self.target.xp, self.target.yp) if not self.target.alive: self.target = target else: target = self.target # ori destAngle = utils.angleBetween((self.xp, self.yp), target) angle = utils.angleDiff(destAngle, self.ori) absAngle = fabs(angle) if absAngle > self.stats.maxRg * 2: # *(config.fps/10): #*5: if angle > 0: self.rg = self.stats.maxRg else: self.rg = -1 * self.stats.maxRg else: self.rg = 0 self.thrust = self.stats.maxThrust if utils.distLowerThan((self.xp, self.yp), target, self.stats.maxRadius * 4): (ao1, ro1, ag1) = self.explode(game) (ao, ro, ag) = (ao + ao1, ro + ro1, ag + ag1) # self.alive = False # ro.append( self ) # ag.append( GfxExplosion( (self.xp,self.yp), self.stats.maxRadius*3 ) ) if self.alive: if self.ttl == 0: self.alive = False ro.append(self) else: self.ttl = self.ttl - 1 return (ao, ro, ag)