Beispiel #1
0
class Ship(PhysicalRound):
    """
    A Ship is the main entity a player controls in the world.
    
    Attributes:
        killed: boolean different than destroyed, represents an object forcibly removed from the world (by GUI or end of round), should NOT respawn
    """
    def __init__(self, pos, world):
        super(Ship, self).__init__(28, 500, pos)
        self._world = world  # NOTE: The ONLY reason this is here/needed is because the ship is creating a Torpedo from it's command system...
        self.energyRechargeRate = 4

        self.body.velocity_limit = 100

        # Ship Specific
        self.commandQueue = CommandSystem(self, 4)

        self.shield = PlayerStat(100)
        self.shieldConversionRate = 1.0  # Amount of Shield Recovered Per Energy (Higher Better)
        self.shieldDamageReduction = 0.8  # Amount Damage is Multiplied by and taken from Shields before health is touched (Higher Better)
        self.radarRange = 300

        self.energy = PlayerStat(100)
        self.energyRechargeRate = 4

        self.thrusterForce = 3500
        self.rotationAngle = random.randint(0, 359)
        self.rotationSpeed = 120

        #self.resources = PlayerStat(1000)
        #self.resources.empty()
        #self.miningSpeed = 8
        self.tractorbeamForce = 10000

        self.lasernodes = []

        # extra state
        self.killed = False  # forcibly removed object 'for good'

    def setCommandBufferSize(self, size):
        old = self.commandQueue[:]
        self.commandQueue = MessageQueue(size)
        self.commandQueue.extend(old)

    def take_damage(self, damage, by=None, force=False):
        logging.debug("Ship #%d taking damage %d", self.id, damage)
        if self.commandQueue.containstype(RaiseShieldsCommand,
                                          force) and self.shield.value > 0:
            logging.debug("Shields of #%d absorbed %d damage", self.id,
                          damage * self.shieldDamageReduction)
            self.shield -= damage * self.shieldDamageReduction
            super(Ship, self).take_damage(
                damage * (1.0 - self.shieldDamageReduction), by)
        else:
            super(Ship, self).take_damage(damage, by)
        #eif

        if self.health == 0:
            if self.killedby != None:
                if isinstance(self.killedby, Star):
                    self.player.sound = "BURN"
                elif isinstance(self.killedby, BlackHole):
                    self.player.sound = "CRUSH"
                else:
                    self.player.sound = "EXPLODE"
            else:
                self.player.sound = "EXPLODE"
        elif by != None:
            if isinstance(by, Dragon):
                self.player.sound = "CHOMP"
            elif isinstance(by, Weapon):
                self.player.sound = "IMPACT"
            elif not isinstance(by, Star):
                self.player.sound = "HIT"

    def update(self, t):
        super(Ship, self).update(t)
        if len(self.commandQueue) > 0:
            self.commandQueue.update(t)
            self.TTL = None
        elif self.TTL == None and hasattr(
                self, "player"
        ) and self.player.netid >= 0:  # if we're a human player, make sure we issue another command within 10 seconds, or kill scuttle the ship.
            logging.info(
                "Ship #%d on clock for not issuing a command in given time.",
                self.id)
            self.TTL = self.timealive + 10
        self.energy += self.energyRechargeRate * t

    def getExtraInfo(self, objData, player):
        objData["RADARRANGE"] = self.radarRange
        objData["ROTATION"] = int(self.rotationAngle) % 360
        objData["ROTATIONSPEED"] = self.rotationSpeed
        objData["CURSHIELD"] = self.shield.value
        objData["MAXSHIELD"] = self.shield.maximum

        # Only show some properties to the owner of the ship
        if player != None and hasattr(
                self, "player"
        ) and self.player != None and self.player.netid == player.netid:
            objData["CMDQ"] = self.commandQueue.getRadarRepr()
        else:
            # Remove this property for other ships
            del objData["CURENERGY"]
class Ship(PhysicalRound):
    """
    A Ship is the main entity a player controls in the world.
    
    Attributes:
        killed: boolean different than destroyed, represents an object forcibly removed from the world (by GUI or end of round), should NOT respawn
    """

    def __init__(self, pos, world):
        super(Ship, self).__init__(28, 500, pos)
        self._world = world # NOTE: The ONLY reason this is here/needed is because the ship is creating a Torpedo from it's command system...
        self.energyRechargeRate = 4

        self.body.velocity_limit = 100

        # Ship Specific
        self.commandQueue = CommandSystem(self, 4)

        self.shield = PlayerStat(100)
        self.shieldConversionRate = 1.0 # Amount of Shield Recovered Per Energy (Higher Better)
        self.shieldDamageReduction = 0.8 # Amount Damage is Multiplied by and taken from Shields before health is touched (Higher Better)
        self.radarRange = 300

        self.energy = PlayerStat(100)
        self.energyRechargeRate = 4

        self.thrusterForce = 3500
        self.rotationAngle = random.randint(0, 359)
        self.rotationSpeed = 120

        #self.resources = PlayerStat(1000)
        #self.resources.empty()
        #self.miningSpeed = 8
        self.tractorbeamForce = 10000
        
        self.lasernodes = []

        # extra state
        self.killed = False # forcibly removed object 'for good'

    def setCommandBufferSize(self, size):
        old = self.commandQueue[:]
        self.commandQueue = MessageQueue(size)
        self.commandQueue.extend(old)

    def take_damage(self, damage, by=None, force=False):
        logging.debug("Ship #%d taking damage %d", self.id, damage)
        if self.commandQueue.containstype(RaiseShieldsCommand, force) and self.shield.value > 0:
            logging.debug("Shields of #%d absorbed %d damage", self.id, damage * self.shieldDamageReduction)
            self.shield -= damage * self.shieldDamageReduction
            super(Ship, self).take_damage(damage * (1.0 - self.shieldDamageReduction), by)
        else:
            super(Ship, self).take_damage(damage, by)
        #eif

        if self.health == 0:
            if self.killedby != None:
                if isinstance(self.killedby, Star):
                    self.player.sound = "BURN"
                elif isinstance(self.killedby, BlackHole):
                    self.player.sound = "CRUSH"
                else:
                    self.player.sound = "EXPLODE"
            else:
                self.player.sound = "EXPLODE"
        elif by != None:
            if isinstance(by, Dragon):
                self.player.sound = "CHOMP"
            elif isinstance(by, Weapon):
                self.player.sound = "IMPACT"
            elif not isinstance(by, Star):
                self.player.sound = "HIT"

    def update(self, t):
        super(Ship, self).update(t)
        if len(self.commandQueue) > 0: 
            self.commandQueue.update(t)
            self.TTL = None
        elif self.TTL == None and hasattr(self, "player") and self.player.netid >= 0: # if we're a human player, make sure we issue another command within 10 seconds, or kill scuttle the ship.
            logging.info("Ship #%d on clock for not issuing a command in given time.", self.id)
            self.TTL = self.timealive + 10
        self.energy += self.energyRechargeRate * t

    def getExtraInfo(self, objData, player):
        objData["RADARRANGE"] = self.radarRange
        objData["ROTATION"] = int(self.rotationAngle) % 360
        objData["ROTATIONSPEED"] = self.rotationSpeed
        objData["CURSHIELD"] = self.shield.value
        objData["MAXSHIELD"] = self.shield.maximum

        # Only show some properties to the owner of the ship
        if player != None and hasattr(self, "player") and self.player != None and self.player.netid == player.netid:
            objData["CMDQ"] = self.commandQueue.getRadarRepr()
        else:
            # Remove this property for other ships
            del objData["CURENERGY"]