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 or in Nebula # TODO: Should there be an 'invisible' flag? Would need more testing. Would a degradation/range be useful? for x in xrange(len(objs) - 1, -1, -1): if isinstance(objs[x], Ship) and (objs[x].commandQueue.containstype(CloakCommand) \ or any(isinstance(y, Nebula) for y in objs[x].in_celestialbody)): 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, }
def __init__(self, game, worldsize, pys=True): """ Parameters: game: game object that manages rules for world worldsize: tuple of world width,height pys: flag to indicate whether this should be the main world running a physics/game loop or not """ self.__game = game self.size = intpos(worldsize) self.width = worldsize[0] self.height = worldsize[1] self.__space = pymunk.Space() #self.__space.add_collision_handler(0, 0, post_solve=self.collideShipStellarObject) self.__space.set_default_collision_handler(begin=self.__beginCollideObject, post_solve=self.__collideObject) self.__objects = ThreadSafeDict() self.__addremovesem = threading.Semaphore() self.__planets = [] self.__nebulas = [] self.__objectListener = [] self.__toremove = [] self.__toadd = [] self.__active = True self.__pys = pys self.gameerror = False logging.info("Initialized World of size %s", repr(worldsize)) if pys: logging.debug("Started gameloop for World %s", repr(self)) threading.Thread(None, self.__THREAD__gameloop, "WorldMap_gameloop_" + repr(self)).start()
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
def __init__(self, game, worldsize, objlistener=None): """ Parameters: game: game object that manages rules for world worldsize: tuple of world width,height pys: flag to indicate whether this should be the main world running a physics/game loop or not objlistener: initial listner callback function """ self.__game = game self.size = intpos(worldsize) self.width = worldsize[0] self.height = worldsize[1] self.__space = pymunk.Space() #self.__space.add_collision_handler(0, 0, post_solve=self.collideShipStellarObject) self.__space.set_default_collision_handler( begin=self.__beginCollideObject, post_solve=self.__collideObject, separate=self.__endCollideObject) self.__objects = ThreadSafeDict() self.__addremovesem = threading.Semaphore() self.__influential = [] if objlistener == None: self.__objectListener = [] else: self.__objectListener = [objlistener] self.__toremove = [] self.__toadd = [] self.__active = False self.__started = False self.gameerror = False logging.info("Initialized World of size %s", repr(worldsize))
def __init__(self, game, worldsize, objlistener=None): """ Parameters: game: game object that manages rules for world worldsize: tuple of world width,height pys: flag to indicate whether this should be the main world running a physics/game loop or not objlistener: initial listner callback function """ self.__game = game self.size = intpos(worldsize) self.width = worldsize[0] self.height = worldsize[1] self.__space = pymunk.Space() #self.__space.add_collision_handler(0, 0, post_solve=self.collideShipStellarObject) self.__space.set_default_collision_handler(begin=self.__beginCollideObject, post_solve=self.__collideObject, separate=self.__endCollideObject) self.__objects = ThreadSafeDict() self.__addremovesem = threading.Semaphore() self.__influential = [] if objlistener == None: self.__objectListener = [] else: self.__objectListener = [objlistener] self.__toremove = [] self.__toadd = [] self.__active = False self.__started = False self.gameerror = False logging.info("Initialized World of size %s", repr(worldsize))
def __init__(self, obj): obj.lasernodes.append(intpos(obj.body.position)) super(DeployLaserBeaconCommand, self).__init__(obj, DeployLaserBeaconCommand.NAME, True, ttl=0.05)
def mid_point(self, xoff = 0, yoff = 0): return intpos((self.width / 2 + xoff, self.height / 2 + yoff))
def __repr__(self): return super(WarpCommand, self).__repr__() + " DEST: " + repr( intpos(self.__dest))
def mid_point(self, xoff=0, yoff=0): return intpos((self.width / 2 + xoff, self.height / 2 + yoff))
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, }
def __repr__(self): return super(WarpCommand, self).__repr__() + " DEST: " + repr(intpos(self.__dest))