def run_in_item(self, item): n=self.config r=self.root i=0 while i!=dget(n, "number", 1): r.state_manager.states["game"].entities.insert(1,Projectile(r.gamedb.get_asset(n["image"]), r, item, n["lifetime"], n["homing"], n["velocity"], n["impact"], n["maxspeed"], n["accel"], dget(n, "particlestyle", {"particles":0}), dget(n, "turnrate", 60), dget(n, "offset_min", 0), dget(n, "offset_max", 0), n)) i+=1
def run_in_item(self, item): n = self.config r = self.root i = 0 while i != dget(n, "number", 1): r.state_manager.states["game"].entities.insert( 1, Projectile(r.gamedb.get_asset(n["image"]), r, item, n["lifetime"], n["homing"], n["velocity"], n["impact"], n["maxspeed"], n["accel"], dget(n, "particlestyle", {"particles": 0}), dget(n, "turnrate", 60), dget(n, "offset_min", 0), dget(n, "offset_max", 0), n)) i += 1
def __init__(self, damage_model, config): self.damage_model=damage_model self.config=config self.status=0 self.name=config["name"] self.attributes=config["attributes"] self.effects_damaged=config["effects_damaged"] self.effects_destroyed=config["effects_destroyed"] self.health=config["health"] self.maxhealth=self.health self.threshold=config["threshold_damaged"] self.regen_const=config["regen"] self.image_damaged=damage_model.root.gamedb.get_asset(dget(config, "image_damaged", "$BLANK")) self.image_destroyed=damage_model.root.gamedb.get_asset(dget(config, "image_destroyed", "$BLANK")) self.update_olds()
def can_fire(self): for i in self.fire_required: if i=="energy": if self.parent.current_power<self.fire_required[i]: return False if i=="enemy_selected": if self.parent.targeted==None and self.fire_required[i]: return False if i=="cooldown": if self.root.game_time-self.last_fired<self.fire_required[i]: return False if i=="distance<": targetdistancex = abs(self.parent.rotated_rect.centerx - self.parent.targeted.rotated_rect.centerx) targetdistancey = abs(self.parent.rotated_rect.centery - self.parent.targeted.rotated_rect.centery) targetdistance = math.sqrt(targetdistancex**2 + targetdistancey**2) if self.fire_required[i]<targetdistance: return False if i=="item": g=1 for item in self.parent.inventory: if item.id_str==self.fire_required[i]: g=0 if g: return False self.parent.current_power-=dget(self.fire_required,"energy",0) return True
def update(self): try: for controller in self.controllers: controller.update() if self.can_fire: i=0 priorities={} while i!=len(self.ship.hardpoints): #for each item equipped if self.ship.get_item_in_hardpoint(i): fire=True for hint in self.ship.get_item_in_hardpoint(i).ai_hints: if not hint.get_suggested(self): #check if any of the AIItemHints disagree fire = False if fire: priorities[i]=dget(self.ship.get_item_in_hardpoint(i)._config, "ai_priority", 5) i+=1 if self.ship.targeted: for i in sorted(priorities, key=lambda hardpoint: priorities[hardpoint]): self.ship.get_item_in_hardpoint(i).fire() #then fire except BaseException as e: if not (isinstance(e, AttributeError) and "_config" not in str(e)): error("AI ERROR (BASE): " + str(e)) exc_type, exc_value, exc_traceback = sys.exc_info() for i in traceback.format_exception(exc_type, exc_value, exc_traceback): error(i)
def __init__(self, damage_model, config): self.damage_model = damage_model self.config = config self.status = 0 self.name = config["name"] self.attributes = config["attributes"] self.effects_damaged = config["effects_damaged"] self.effects_destroyed = config["effects_destroyed"] self.health = config["health"] self.maxhealth = self.health self.threshold = config["threshold_damaged"] self.regen_const = config["regen"] self.image_damaged = damage_model.root.gamedb.get_asset( dget(config, "image_damaged", "$BLANK")) self.image_destroyed = damage_model.root.gamedb.get_asset( dget(config, "image_destroyed", "$BLANK")) self.update_olds()
def get_suggested(self, ai): system = ai.ship.targeted.damage.search_system( dget(self.config, "search_name", None), dget(self.config, "search_key", None)) translate = {"optimal": 0, "damaged": 1, "destroyed": 2} if system: if "exactly" in self.config.keys(): # print "e"+str(translate[self.config["exactly"]]) if system.status == translate[self.config["exactly"]]: return True if "below" in self.config.keys(): # print "b"+str(translate[self.config["below"]]) if system.status > translate[self.config["below"]]: return True if "above" in self.config.keys(): # print "a"+str(translate[self.config["above"]]) if system.status < translate[self.config["above"]]: return True return False
def run_in_item(self, item): if dget(self.config, "root", False): self.root.particlemanager.add_particles( particles.make_explosion_cfg( self.root, item.parent.rotated_rect.center[0], item.parent.rotated_rect.center[1], self.config["style"])) else: item.parent.particlemanager.add_particles( particles.make_explosion_cfg( self.root, item.parent.rotated_rect.center[0], item.parent.rotated_rect.center[1], self.config["style"]))
def run_in_ship(self, ship): if dget(self.config, "root", False): self.root.particlemanager.add_particles( particles.make_explosion_cfg(self.root, ship.rotated_rect.center[0], ship.rotated_rect.center[1], self.config["style"])) else: ship.particlemanager.add_particles( particles.make_explosion_cfg(self.root, ship.rotated_rect.center[0], ship.rotated_rect.center[1], self.config["style"]))
def run_in_impact(self, item, impacted, projectile): if dget(self.config, "root", False): self.root.particlemanager.add_particles( particles.make_explosion_cfg(self.root, projectile.rotated_rect.center[0], projectile.rotated_rect.center[1], self.config["style"])) else: impacted.particlemanager.add_particles( particles.make_explosion_cfg(self.root, projectile.rotated_rect.center[0], projectile.rotated_rect.center[1], self.config["style"]))
def get_suggested(self, ai): system=ai.ship.targeted.damage.search_system(dget(self.config, "search_name", None), dget(self.config, "search_key", None)) translate={ "optimal":0, "damaged":1, "destroyed":2 } if system: if "exactly" in self.config.keys(): # print "e"+str(translate[self.config["exactly"]]) if system.status==translate[self.config["exactly"]]: return True if "below" in self.config.keys(): # print "b"+str(translate[self.config["below"]]) if system.status>translate[self.config["below"]]: return True if "above" in self.config.keys(): # print "a"+str(translate[self.config["above"]]) if system.status<translate[self.config["above"]]: return True return False
def do(root, target, px, py, source): target.damage(root.config["damage"], dget(root.config, "peirce", 0), px, py, source)
def make_explosion_cfg(r, x, y, n): i = 0 ps = [] pcount = random.randint( dget(n, "particles_min", dget(n, "particles", 200)), dget(n, "particles_max", dget(n, "particles", 200))) if pcount > 0: while i < pcount: surf = pygame.Surface( (int( random.uniform(dget(n, "size_min", 2), dget(n, "size_max", 2))), int( random.uniform( dget(n, "size_min", 2), (dget(n, "size_max", 2)))))).convert_alpha() surf.fill( pygame.Color( int( random.uniform(dget(n, "r_min", 200), dget(n, "r_max", 255))), int( random.uniform(dget(n, "g_min", 150), dget(n, "g_max", 200))), int( random.uniform(dget(n, "b_min", 0), dget(n, "b_max", 0))), int( random.uniform(dget(n, "a_min", 255), dget(n, "a_max", 255))))) exec("""def move_direction(self): self.x+=""" + str((random.random() - random.random()) * (random.uniform( dget(n, "speed_min", 3), dget(n, "speed_max", 3)))) + """ self.y+=""" + str((random.random() - random.random()) * (random.uniform( dget(n, "speed_min", 3), dget(n, "speed_max", 3))))) ps.append( Particle( r, surf, x + random.uniform(n.get("offset_x_min", 0), n.get("offset_x_max", 0)), y + random.uniform(n.get("offset_y_min", 0), n.get("offset_y_max", 0)), move_direction, random.uniform(dget(n, "time_min", 15), dget(n, "time_max", 45)), True)) i += 1 return ps
def run_in_item(self, item): item.parent.targeted.damage.damage_system(self.config["damage"], dget(self.config, "system_name", None), dget(self.config, "system_key", None))
def run_in_impact(self, item, impacted, projectile): impacted.damage.damage_system(self.config["damage"], dget(self.config, "system_name", None), dget(self.config, "system_key", None))
def make_explosion_cfg(r, x, y, n): i=0 ps=[] pcount=random.randint(dget(n, "particles_min", dget(n, "particles", 200)), dget(n, "particles_max", dget(n, "particles", 200))) if pcount>0: while i<pcount: surf=pygame.Surface((int(random.uniform(dget(n, "size_min", 2), dget(n, "size_max", 2))), int(random.uniform(dget(n, "size_min", 2), (dget(n, "size_max", 2)))))).convert_alpha() surf.fill( pygame.Color( int(random.uniform(dget(n, "r_min", 200), dget(n, "r_max", 255))) , int(random.uniform(dget(n, "g_min", 150), dget(n, "g_max", 200))) , int(random.uniform(dget(n, "b_min", 0), dget(n, "b_max", 0) ) ) , int(random.uniform(dget(n, "a_min", 255), dget(n, "a_max", 255))) ) ) exec("""def move_direction(self): self.x+="""+str((random.random()-random.random())*(random.uniform(dget(n, "speed_min", 3), dget(n, "speed_max", 3))))+""" self.y+="""+str((random.random()-random.random())*(random.uniform(dget(n, "speed_min", 3), dget(n, "speed_max", 3))))) ps.append(Particle(r, surf, x+random.uniform(n.get("offset_x_min",0), n.get("offset_x_max",0)), y+random.uniform(n.get("offset_y_min",0), n.get("offset_y_max",0)), move_direction, random.uniform(dget(n, "time_min", 15), dget(n, "time_max", 45)), True)) i+=1 return ps
def die(self): debug(self.name+" was destroyed") self.sg_postevent(UE_SHIP_DIE_RUN, ship=self) primitives.do_group_for_ship(self.root, dget(self.config, "ship_die", []), self)
def run_in_item(self, item): item.parent.targeted.damage.damage_system( self.config["damage"], dget(self.config, "system_name", None), dget(self.config, "system_key", None))
def die(self): debug(self.name + " was destroyed") self.sg_postevent(UE_SHIP_DIE_RUN, ship=self) primitives.do_group_for_ship(self.root, dget(self.config, "ship_die", []), self)