Exemplo n.º 1
0
    def getObjectData(self, obj):
        objData = {}
        # Convert Type of Object to String
        objData["TYPE"] = friendly_type(obj)
        objData["ID"] = obj.id
        objData["POSITION"] = intpos(obj.body.position)
        objData["SPEED"] = obj.body.velocity.length
        # TODO: deal with -0.0 case OR match physics library coordinates?
        objData["DIRECTION"] = -obj.body.velocity.angle_degrees # 30 = -120?, -80 = -10
        #objData["VELOCITYDIRECTION"] = obj.velocity.direction
        objData["MAXSPEED"] = obj.body.velocity_limit
        objData["CURHEALTH"] = obj.health.value
        objData["MAXHEALTH"] = obj.health.maximum
        objData["CURENERGY"] = obj.energy.value
        objData["MAXENERGY"] = obj.energy.maximum
        objData["ENERGYRECHARGERATE"] = obj.energyRechargeRate
        objData["MASS"] = obj.mass
        objData["HITRADIUS"] = obj.radius #TODO: Move to entites that have this i.e. physicalround?
        objData["TIMEALIVE"] = obj.timealive

        obj.getExtraInfo(objData)

        self.__game.game_get_extra_radar_info(obj, objData)

        return objData
    def getObjectData(self, obj, player):
        #TODO: Move these properties to the 'getExtraInfo' of the base Entity and have child classes call super...
        objData = {}
        # Convert Type of Object to String
        objData["TYPE"] = friendly_type(obj)
        objData["ID"] = obj.id
        objData["POSITION"] = intpos(obj.body.position)
        objData["SPEED"] = obj.body.velocity.length
        # TODO: deal with -0.0 case OR match physics library coordinates?
        objData[
            "DIRECTION"] = -obj.body.velocity.angle_degrees % 360  # 30 = -120?, -80 = -10
        #objData["VELOCITYDIRECTION"] = obj.velocity.direction
        objData["MAXSPEED"] = obj.body.velocity_limit
        objData["CURHEALTH"] = obj.health.value
        objData["MAXHEALTH"] = obj.health.maximum
        objData["CURENERGY"] = obj.energy.value
        objData["MAXENERGY"] = obj.energy.maximum
        objData["ENERGYRECHARGERATE"] = obj.energyRechargeRate
        objData["MASS"] = obj.mass
        objData[
            "HITRADIUS"] = obj.radius  #TODO: Move to entites that have this i.e. physicalround?
        objData["TIMEALIVE"] = obj.timealive
        objData["INBODY"] = (len(obj.in_celestialbody) > 0)

        obj.getExtraInfo(objData, player)

        self.__game.game_get_extra_radar_info(obj, objData, player)

        return objData
Exemplo n.º 3
0
    def getEnvironment(self, ship, radarlevel=0, target=-1, getMessages=False):
        #TODO: abstract radar to game level?
        radardata = None
        if radarlevel > 0:
            objs = self.getObjectsInArea(ship.body.position, ship.radarRange)
            #TODO: Need to wait lock the removing of ships with accessing...???
            if ship in objs: objs.remove(ship) # Get rid of self...

            # remove ships with cloak
            for x in xrange(len(objs) - 1, -1, -1):
                if isinstance(objs[x], Ship) and objs[x].commandQueue.containstype(CloakCommand):
                    del objs[x]
                #eif
            #next

            if radarlevel == 1:
                # number of objects
                radardata = []
                for i in xrange(len(objs)):
                    radardata.append({})
            elif radarlevel == 2:
                # (pos, id) list
                radardata = []
                for e in objs:
                    radardata.append({"POSITION":intpos(e.body.position), "ID":e.id})
                #next
            elif radarlevel == 3:
                for obj in objs:
                    if obj.id == target:
                        radardata = [self.getObjectData(obj)]
                        break
            elif radarlevel == 4:
                # (pos, id, type)
                radardata = []
                for e in objs:
                    radardata.append({"POSITION":intpos(e.body.position), "ID":e.id, "TYPE":friendly_type(e)})
                #next
            elif radarlevel == 5:
                radardata = []
                for e in objs:
                    radardata.append(self.getObjectData(e))
                #next
            #eif
        #eif

        msgQueue = []
        if getMessages:
            msqQueue = list(ship.messageQueue)

        return {"SHIPDATA": self.getObjectData(ship),
                "RADARLEVEL": radarlevel,
                "RADARDATA": radardata,
                "GAMEDATA": self.__game.game_get_extra_environment(ship.player),
                "MESSAGES": msgQueue,
                }
    def getEnvironment(self, ship, radarlevel=0, target=-1, getMessages=False):
        #TODO: abstract radar to game level?
        radardata = None
        if radarlevel > 0:
            objs = self.getObjectsInArea(ship.body.position, ship.radarRange,
                                         True)
            #TODO: Need to wait lock the removing of ships with accessing...???
            if ship in objs: objs.remove(ship)  # Get rid of self...

            # remove ships with cloak
            for x in xrange(len(objs) - 1, -1, -1):
                if isinstance(objs[x],
                              Ship) and objs[x].commandQueue.containstype(
                                  CloakCommand):
                    del objs[x]
                #eif
            #next

            if radarlevel == 1:
                # number of objects
                radardata = []
                for i in xrange(len(objs)):
                    radardata.append({})
            elif radarlevel == 2:
                # (pos, id) list
                radardata = []
                for e in objs:
                    radardata.append({
                        "POSITION": intpos(e.body.position),
                        "ID": e.id
                    })
                #next
            elif radarlevel == 3:
                for obj in objs:
                    if obj.id == target:
                        radardata = [self.getObjectData(obj, ship.player)]
                        break
            elif radarlevel == 4:
                # (pos, id, type)
                radardata = []
                for e in objs:
                    radardata.append({
                        "POSITION": intpos(e.body.position),
                        "ID": e.id,
                        "TYPE": friendly_type(e)
                    })
                #next
            elif radarlevel == 5:
                radardata = []
                for e in objs:
                    radardata.append(self.getObjectData(e, ship.player))
                #next
            #eif
        #eif

        msgQueue = []
        if getMessages:
            msqQueue = list(ship.messageQueue)

        return {
            "SHIPDATA": self.getObjectData(ship, ship.player),
            "RADARLEVEL": radarlevel,
            "RADARDATA": radardata,
            "GAMEDATA": self.__game.game_get_extra_environment(ship.player),
            "MESSAGES": msgQueue,
        }