Ejemplo n.º 1
0
    def dq_finished_scan(self, ship, obj, success):
        if obj != None:
            logging.info(
                "Ship #%d finished scan of object #%d and was successful? [%s]",
                ship.id, obj.id, repr(success))
        else:
            logging.info(
                "Ship #%d finished scan of unknown object (never saw id)",
                ship.id)

        if success:
            ship.player.lastids.append(obj.id)

            if isinstance(obj, Outpost) and (ship.player in obj.home_for
                                             or ship.player.outpost == None):
                # scanned player's own Outpost, do Mission Stuff HERE
                if ship.player.outpost == None:
                    # establish as ship's Outpost
                    ship.player.outpost = obj
                    obj.home_for.append(ship.player)
                    ship.player.update_score(
                        ship.player.buffervalue + obj.value * 2
                    )  # Score initial points + 2*outpost value for establishing base
                    ship.player.buffervalue = 0
                    ship.player.sound = "SUCCESS"

                if self.usemissions and not ship.player.failed and len(
                        ship.player.mission) == 0:  # completed mission exactly
                    points = 0
                    # tally points of scanned objects
                    for obj in ship.player.scanned:
                        points += obj.value
                    ship.player.sound = "MISSION"
                    ship.player.update_score(points * self.cfg.getfloat(
                        "DiscoveryQuest", "mission_bonus_multiplier"))

                self.player_reset_mission(ship.player)

            elif ship.player in obj.scanned_by:
                logging.info("Ship #%d has ALREADY scanned object #%d",
                             ship.id, obj.id)
            else:
                # mission checks
                if friendly_type(obj) in ship.player.mission:
                    ship.player.mission.remove(friendly_type(obj))
                else:
                    ship.player.failed = True
                ship.player.scanned.append(obj)

                # track obj scan
                ship.player.scantimes[obj.id] = 0
                obj.scanned_by.append(ship.player)

                # update scores
                ship.player.sound = "SUCCESS"
                if ship.player.outpost != None or not self.mustbase:  # or we don't require bases for points
                    ship.player.update_score(obj.value)
                else:  #haven't found outpost, need to buffer points
                    ship.player.buffervalue += obj.value
Ejemplo n.º 2
0
    def world_add_remove_object(self, wobj, added):
        """
        Called by world when an object is added or destroyed (before added (guaranteed to not have update) and after removed (though may receive last update))

        For simple tasks involving players look to the player_died or player_added methods

        killed ships will not return (used to prevent respawn)
        """
        logging.debug("[Game] Add Object(%s): #%d (%s)", repr(added), wobj.id,
                      friendly_type(wobj))
        if not added and isinstance(wobj, SpaceMine) and wobj.active:
            self.world.causeExplosion(wobj.body.position, SpaceMine.RADIUS,
                                      SpaceMine.FORCE, True)
            # TODO: Cause splash damage?

        if not added and isinstance(
                wobj, Ship) and wobj.player.netid in self._players:
            nid = wobj.player.netid

            # if we were given an expiration time, means we haven't issued a command, so kill the ship
            if wobj.has_expired() and self.cfg.getboolean(
                    "Server", "disconnect_on_idle"):
                logging.info("Ship #%d killed due to timeout.", wobj.id)
                wobj.killed = True

            if hasattr(wobj, "killedby") and wobj.killedby != None:
                if isinstance(wobj.killedby, Ship):
                    self._players[nid].lastkilledby = wobj.killedby.player.name
                else:
                    self._players[nid].lastkilledby = friendly_type(
                        wobj.killedby) + " #" + str(wobj.killedby.id)

            self.player_died(self._players[nid],
                             (self._players[nid].disconnected or wobj.killed))

            self._players[nid].object = None

            if not self._players[nid].disconnected:
                if self._disconnect_on_death or wobj.killed:
                    if self.__allowreentry:
                        del self._players[nid]

                    # TODO: disconnect AI?
                    if nid >= 0:
                        self.server.sendDisconnect(nid)
                else:
                    if not self._players[nid].roundover:
                        # if the round isn't over, then re-add the ship
                        self._game_add_ship_for_player(nid)

        if not added:
            self.spawnmanager.check_number(wobj)
Ejemplo n.º 3
0
    def dq_finished_scan(self, ship, obj, success):
        if obj != None:
            logging.info("Ship #%d finished scan of object #%d and was successful? [%s]", ship.id, obj.id, repr(success))
        else:
            logging.info("Ship #%d finished scan of unknown object (never saw id)", ship.id)

        if success:
            ship.player.lastids.append(obj.id)

            if isinstance(obj, Outpost) and (ship.player in obj.home_for or ship.player.outpost == None):
                # scanned player's own Outpost, do Mission Stuff HERE
                if ship.player.outpost == None:
                    # establish as ship's Outpost
                    ship.player.outpost = obj
                    obj.home_for.append(ship.player)
                    ship.player.update_score(ship.player.buffervalue + obj.value * 2) # Score initial points + 2*outpost value for establishing base
                    ship.player.buffervalue = 0
                    ship.player.sound = "SUCCESS"
                
                if self.usemissions and not ship.player.failed and len(ship.player.mission) == 0: # completed mission exactly
                    points = 0
                    # tally points of scanned objects
                    for obj in ship.player.scanned:
                        points += obj.value
                    ship.player.sound = "MISSION"
                    ship.player.update_score(points * self.cfg.getfloat("DiscoveryQuest", "mission_bonus_multiplier"))

                self.player_reset_mission(ship.player)

            elif ship.player in obj.scanned_by:
                logging.info("Ship #%d has ALREADY scanned object #%d", ship.id, obj.id)
            else:
                # mission checks
                if friendly_type(obj) in ship.player.mission:
                    ship.player.mission.remove(friendly_type(obj))
                else:
                    ship.player.failed = True
                ship.player.scanned.append(obj)

                # track obj scan
                ship.player.scantimes[obj.id] = 0
                obj.scanned_by.append(ship.player)

                # update scores
                ship.player.sound = "SUCCESS"
                if ship.player.outpost != None or not self.mustbase: # or we don't require bases for points
                    ship.player.update_score(obj.value)
                else: #haven't found outpost, need to buffer points
                    ship.player.buffervalue += obj.value
Ejemplo n.º 4
0
    def check_number(self, wobj):
        """
        Checks the number of objects in the world to see if more need to be added over minimum.

        Called by game when object removed from the world.
        """
        name = friendly_type(wobj)
        #logging.debug("Checking Number in Spawn Manager for %s - Running: %s Config: %s", name, repr(self._running), repr(self._spawns.has_key(name)))
        if self._running and self._spawns.has_key(name):
            sc = self._spawns[name]

            #logging.debug("Configured for Points: %s and Has Info %s", repr(sc.is_points()), repr(hasattr(wobj, "killedby")))
            if sc.is_points() and hasattr(wobj, "killedby") and wobj.killedby != None:
                obj = wobj.killedby
                #logging.debug("Killed By: %s", repr(obj))
                if isinstance(obj, Torpedo) and hasattr(obj, "owner") and obj.owner != None and isinstance(obj.owner, Ship):
                    obj.owner.player.update_score(sc.get_points_torpedo())
                    
                    logging.info("Torpedo Owner (#%d) Destroyed %s for %d Points", obj.owner.id, name, sc.get_points_torpedo())
                elif isinstance(obj, Ship) and obj.health.value > 0:
                    obj.player.update_score(sc.get_points_ram())
                    
                    logging.info("Ship (#%d) Destroyed %s for %d Points", obj.id, name, sc.get_points_ram())

            if sc.is_min():
                count = self._world.get_count_of_objects(type(wobj))
                logging.info("Found %d %s Entities", count, name)
                if count < sc.num_min:
                    self.spawn_entity(name, respawntimer=self._should_spawn(sc), number = sc.num_min - count)

            elif self._should_spawn(sc):
                self.add_timer(sc.name)
Ejemplo n.º 5
0
    def world_add_remove_object(self, wobj, added):
        logging.debug("CE Add Object(%s): #%d (%s)", repr(added), wobj.id, friendly_type(wobj))
        if not added and isinstance(wobj, Asteroid) and hasattr(wobj, "killedby") and wobj.killedby != None:
            obj = wobj.killedby
            if isinstance(obj, Torpedo):
                self.player_update_score(obj.owner.player, self.cfg.getint("CombatExercise", "points_shoot_asteroid"))
                    
                logging.info("Torpedo Owner (#%d) Destroyed Asteroid", obj.owner.id)
            """
            elif isinstance(obj, Ship) and obj.health.value > 0:
                self.player_update_score(obj.player, self.__shippoints)
                    
                logging.info("Ship (#%d) Destroyed Asteroid", obj.id)
            """
        elif not added and isinstance(wobj, Ship) and hasattr(wobj, "killedby") and wobj.killedby != None:
            obj = wobj.killedby
            if isinstance(obj, Torpedo):
                self.player_update_score(obj.owner.player, wobj.timealive / self.cfg.getint("CombatExercise", "points_time_alive_divide_by"))

                logging.info("Torpedo Owner (#%d) Destroyed Ship (#%d)", obj.owner.id, wobj.id)
            elif isinstance(obj, Ship) and obj.health.value > 0:
                self.player_update_score(obj.player, wobj.timealive / self.cfg.getint("CombatExercise", "points_time_alive_divide_by"))
                    
                logging.info("Ship (#%d) Destroyed Ship (#%d)", obj.id, wobj.id)

        super(CombatExerciseGame, self).world_add_remove_object(wobj, added)
Ejemplo n.º 6
0
    def world_add_remove_object(self, wobj, added):
        logging.debug("CE Add Object(%s): #%d (%s)", repr(added), wobj.id,
                      friendly_type(wobj))
        if not added and isinstance(wobj, Asteroid) and hasattr(
                wobj, "killedby") and wobj.killedby != None:
            obj = wobj.killedby
            if isinstance(obj, Torpedo):
                obj.owner.player.update_score(
                    self.cfg.getint("CombatExercise", "points_shoot_asteroid"))

                logging.info("Torpedo Owner (#%d) Destroyed Asteroid",
                             obj.owner.id)
            """
            elif isinstance(obj, Ship) and obj.health.value > 0:
                self.player_update_score(obj.player, self.__shippoints)
                    
                logging.info("Ship (#%d) Destroyed Asteroid", obj.id)
            """
        elif not added and isinstance(wobj, Ship) and hasattr(
                wobj, "killedby") and wobj.killedby != None:
            obj = wobj.killedby
            if isinstance(obj, Torpedo):
                obj.owner.player.update_score(wobj.timealive / self.cfg.getint(
                    "CombatExercise", "points_time_alive_divide_by"))

                logging.info("Torpedo Owner (#%d) Destroyed Ship (#%d)",
                             obj.owner.id, wobj.id)
            elif isinstance(obj, Ship) and obj.health.value > 0:
                obj.player.update_score(wobj.timealive / self.cfg.getint(
                    "CombatExercise", "points_time_alive_divide_by"))

                logging.info("Ship (#%d) Destroyed Ship (#%d)", obj.id,
                             wobj.id)

        super(CombatExerciseGame, self).world_add_remove_object(wobj, added)
Ejemplo n.º 7
0
    def world_add_remove_object(self, wobj, added):
        if isinstance(wobj, Outpost):
            if not added:
                del self._outposts[wobj.id]
            else:
                self._outposts[wobj.id] = wobj

        if added:
            wobj.scanned_by = []  # objects keep track of who scans them

            # give object point value
            opt = "points_" + friendly_type(wobj).lower()
            if self.cfg.has_option("DiscoveryQuest", opt):
                wobj.value = self.cfg.getint("DiscoveryQuest", opt)
            else:
                #guard
                wobj.value = 0
        else:
            # clean-up reference to scantime on obj death
            for player in self.game_get_current_player_list():
                if player in wobj.scanned_by:
                    del player.scantimes[wobj.id]

        return super(DiscoveryQuestGame,
                     self).world_add_remove_object(wobj, added)
Ejemplo n.º 8
0
    def world_add_remove_object(self, wobj, added):
        """
        Called by world when an object is added or destroyed (before added (guaranteed to not have update) and after removed (though may receive last update))

        For simple tasks involving players look to the player_died or player_added methods

        killed ships will not return (used to prevent respawn)
        """
        logging.debug("[Game] Add Object(%s): #%d (%s)", repr(added), wobj.id, friendly_type(wobj))
        if not added and isinstance(wobj, Ship) and wobj.player.netid in self._players:
            nid = wobj.player.netid

            # if we were given an expiration time, means we haven't issued a command, so kill the ship
            if wobj.has_expired() and self.cfg.getboolean("Server", "disconnect_on_idle"):
                logging.info("Ship #%d killed due to timeout.", wobj.id)
                wobj.killed = True

            self.player_died(self._players[nid], (self._players[nid].disconnected or wobj.killed))

            self._players[nid].object = None

            if not self._players[nid].disconnected:
                if self._disconnect_on_death or wobj.killed:
                    if self.__allowreentry:
                        del self._players[nid]

                    # TODO: disconnect AI?
                    if nid >= 0:
                        self.server.sendDisconnect(nid)
                else:
                    if not self._players[nid].roundover:
                        # if the round isn't over, then re-add the ship
                        self._game_add_ship_for_player(nid, True)
Ejemplo n.º 9
0
    def world_add_remove_object(self, wobj, added):
        logging.debug("BH Add Object(%s): #%d (%s)", repr(added), wobj.id, friendly_type(wobj))
        if isinstance(wobj, Bubble) and not added:
            del self.__bubbles[wobj.id]
            # Bubble was removed, we should add a new one
            if len(self.__bubbles) < self.__maxbubbles:
                self.addBubbles(self.world, 1)

        super(KingOfTheBubbleGame, self).world_add_remove_object(wobj, added)
Ejemplo n.º 10
0
    def world_add_remove_object(self, wobj, added):
        logging.debug("BH Add Object(%s): #%d (%s)", repr(added), wobj.id, friendly_type(wobj))
        if isinstance(wobj, Bubble):
            if added:
                self.__bubbles[wobj.id] = wobj
            else:
                del self.__bubbles[wobj.id]

        super(KingOfTheBubbleGame, self).world_add_remove_object(wobj, added)
    def world_add_remove_object(self, wobj, added):
        logging.debug("BH Add Object(%s): #%d (%s)", repr(added), wobj.id, friendly_type(wobj))
        if isinstance(wobj, Bubble):
            if added:
                self.__bubbles[wobj.id] = wobj
            else:
                del self.__bubbles[wobj.id]

        super(KingOfTheBubbleGame, self).world_add_remove_object(wobj, added)
Ejemplo n.º 12
0
    def world_physics_pre_collision(self, shapes):
        types = []
        objs = []
        for shape in shapes:
            objs.append(self.world[shape.id])
            types.append(friendly_type(objs[-1]))

        if "Bubble" in types:
            return [ False, [] ]
            
        return super(KingOfTheBubbleGame, self).world_physics_pre_collision(shapes)
Ejemplo n.º 13
0
 def world_add_remove_object(self, wobj, added):
     logging.debug("BH Add Object(%s): #%d (%s)", repr(added), wobj.id, friendly_type(wobj))
     if not added and isinstance(wobj, Asteroid) and hasattr(wobj, "killedby") and wobj.killedby != None:
         obj = wobj.killedby
         if isinstance(obj, Torpedo):
             self.player_update_score(obj.owner.player, self.__torpedopoints)
                 
             logging.info("Torpedo Owner (#%d) Destroyed Asteroid", obj.owner.id)
         elif isinstance(obj, Ship) and obj.health.value > 0:
             self.player_update_score(obj.player, self.__shippoints)
                 
             logging.info("Ship (#%d) Destroyed Asteroid", obj.id)
     else:
         super(AsteroidMinerGame, self).world_add_remove_object(wobj, added)
Ejemplo n.º 14
0
    def world_physics_pre_collision(self, shapes):
        types = []
        objs = []
        for shape in shapes:
            objs.append(self.world[shape.id])
            types.append(friendly_type(objs[-1]))

        if "Ship" in types and "HomeBase" in types:
            ship = None
            myhome = None
            homes = []
            for obj in objs:
                if isinstance(obj, HomeBase):
                    homes.append(obj)
                elif isinstance(obj, Ship):
                    ship = obj            
            if ship != None:
                logging.info("Ship #%d hit bases %d owner id #%d", ship.id, len(homes), homes[0].owner.id)
                for h in homes:
                    if ship.id == h.owner.id:
                        myhome = h
                        logging.info("Ship #%d hit their base", ship.id)
                        break
                    #eif
                #next
            else:
                logging.error("Ship not found after collision with Ship?")
            #eif
            if myhome != None:
                return [ False, [ [self.depositBaubles, ship, myhome] ] ]
            else:
                logging.info("Ship #%d hit some other base", ship.id)
                return [ False, [] ]            
        if "Ship" in types and "Bauble" in types:
            b = []
            ship = None
            for obj in objs:
                if isinstance(obj, Bauble):
                    b.append(obj)
                elif isinstance(obj, Ship):
                    ship = obj
                #eif
            #next

            return [ False, [ [self.collectBaubles, ship, b] ] ]
        elif "HomeBase" in types or "Bauble" in types:
            return [ False, [] ]
        
        return super(BaubleHuntGame, self).world_physics_pre_collision(shapes)
    def world_add_remove_object(self, wobj, added):
        if isinstance(wobj, Outpost):
            if not added:
                del self._outposts[wobj.id]
            else:
                self._outposts[wobj.id] = wobj

        if added:
            wobj.scanned_by = [] # objects keep track of who scans them

            # give object point value
            opt = "points_" + friendly_type(wobj).lower()
            if self.cfg.has_option("DiscoveryQuest", opt):
                wobj.value = self.cfg.getint("DiscoveryQuest", opt)

        return super(DiscoveryQuestGame, self).world_add_remove_object(wobj, added)
Ejemplo n.º 16
0
    def check_number(self, wobj):
        """
        Checks the number of objects in the world to see if more need to be added over minimum.
        """
        name = friendly_type(wobj)
        if self._running and self._spawns.has_key(name):            
            sc = self._spawns[name]

            if sc.is_min():
                count = self._world.get_count_of_objects(type(wobj))
                logging.info("Found %d %s Entities", count, name)
                if count < sc.num_min:
                    self.spawn_entity(name, respawntimer=self._should_spawn(sc), number = sc.num_min - count)

            elif self._should_spawn(sc):
                self.add_timer(sc.name)
Ejemplo n.º 17
0
    def world_add_remove_object(self, wobj, added):
        if isinstance(wobj, Outpost):
            if not added:
                del self._outposts[wobj.id]
            else:
                self._outposts[wobj.id] = wobj

        if added:
            wobj.scanned_by = [] # objects keep track of who scans them

            # give object point value
            opt = "points_" + friendly_type(wobj).lower()
            if self.cfg.has_option("DiscoveryQuest", opt):
                wobj.value = self.cfg.getint("DiscoveryQuest", opt)

        return super(DiscoveryQuestGame, self).world_add_remove_object(wobj, added)
    def world_physics_pre_collision(self, shapes):
        types = []
        objs = []
        for shape in shapes:
            objs.append(self.world[shape.id])
            types.append(friendly_type(objs[-1]))

        if "Ship" in types and "Bauble" in types:
            b = []
            ship = None
            for i in xrange(len(objs) - 1, -1, -1):
                if isinstance(objs[i], Bauble):
                    b.append(objs[i])
                    del objs[i]
                elif isinstance(objs[i], Ship):
                    ship = objs[i]

            return [False, [[self.collectBaubles, ship, b]]]
Ejemplo n.º 19
0
    def world_add_remove_object(self, wobj, added):
        if isinstance(wobj, Outpost):
            if not added:
                del self._outposts[wobj.id]
            else:
                self._outposts[wobj.id] = wobj

        if added:
            wobj.scanned_by = [] # objects keep track of who scans them

            # give object point value
            opt = "points_" + friendly_type(wobj).lower()
            if self.cfg.has_option("DiscoveryQuest", opt):
                wobj.value = self.cfg.getint("DiscoveryQuest", opt)
            else:
                #guard
                wobj.value = 0
        else:
            # clean-up reference to scantime on obj death
            for player in self.game_get_current_player_list():
                if player in wobj.scanned_by:
                    del player.scantimes[wobj.id]

        return super(DiscoveryQuestGame, self).world_add_remove_object(wobj, added)