def _generate_events(self): for player_cp, enemy_cp in self.theater.conflicts(True): if enemy_cp.is_global: continue for event_class, ( player_probability, enemy_probability) in EVENT_PROBABILITIES.items(): if event_class in [ FrontlineAttackEvent, FrontlinePatrolEvent, InfantryTransportEvent ]: # skip events requiring frontline if not Conflict.has_frontline_between(player_cp, enemy_cp): continue if player_cp.is_global: # skip events requiring ground CP if event_class not in [ InterceptEvent, StrikeEvent, NavalInterceptEvent ]: continue if player_probability == 100 or self._roll( player_probability, player_cp.base.strength): self._generate_player_event(event_class, player_cp, enemy_cp) if enemy_probability == 100 or self._roll( enemy_probability, enemy_cp.base.strength): self._generate_enemy_event(event_class, player_cp, enemy_cp)
def _generate_events(self): strikes_generated_for = set() base_attack_generated_for = set() for player_cp, enemy_cp in self.theater.conflicts(True): for event_class, (player_probability, enemy_probability) in EVENT_PROBABILITIES.items(): if event_class in [FrontlineAttackEvent, FrontlinePatrolEvent, InfantryTransportEvent, ConvoyStrikeEvent]: # skip events requiring frontline if not Conflict.has_frontline_between(player_cp, enemy_cp): continue # don't generate multiple 100% events from each attack direction if event_class is StrikeEvent: if enemy_cp in strikes_generated_for: continue if event_class is BaseAttackEvent: if enemy_cp in base_attack_generated_for: continue if player_probability == 100 or player_probability > 0 and self._roll(player_probability, player_cp.base.strength): self._generate_player_event(event_class, player_cp, enemy_cp) if event_class is StrikeEvent: strikes_generated_for.add(enemy_cp) if event_class is BaseAttackEvent: base_attack_generated_for.add(enemy_cp) if enemy_probability == 100 or enemy_probability > 0 and self._roll(enemy_probability, enemy_cp.base.strength): self._generate_enemy_event(event_class, player_cp, enemy_cp)
def compute_conflicts_position(self): """ Compute the current conflict center position(s), mainly used for culling calculation :return: List of points of interests """ points = [] # By default, use the existing frontline conflict position for front_line in self.theater.conflicts(): position = Conflict.frontline_position(front_line.control_point_a, front_line.control_point_b, self.theater) points.append(position[0]) points.append(front_line.control_point_a.position) points.append(front_line.control_point_b.position) # If do_not_cull_carrier is enabled, add carriers as culling point if self.settings.perf_do_not_cull_carrier: for cp in self.theater.controlpoints: if cp.is_carrier or cp.is_lha: points.append(cp.position) # If there is no conflict take the center point between the two nearest opposing bases if len(points) == 0: cpoint = None min_distance = sys.maxsize for cp in self.theater.player_points(): for cp2 in self.theater.enemy_points(): d = cp.position.distance_to_point(cp2.position) if d < min_distance: min_distance = d cpoint = Point((cp.position.x + cp2.position.x) / 2, (cp.position.y + cp2.position.y) / 2) points.append(cp.position) points.append(cp2.position) break if cpoint is not None: break if cpoint is not None: points.append(cpoint) packages = itertools.chain(self.blue_ato.packages, self.red_ato.packages) for package in packages: if package.primary_task is FlightType.BARCAP: # BARCAPs will be planned at most locations on smaller theaters, # rendering culling fairly useless. BARCAP packages don't really # need the ground detail since they're defensive. SAMs nearby # are only interesting if there are enemies in the area, and if # there are they won't be culled because of the enemy's mission. continue points.append(package.target.position) # Else 0,0, since we need a default value # (in this case this means the whole map is owned by the same player, so it is not an issue) if len(points) == 0: points.append(Point(0, 0)) self.__culling_points = points
def prepare(self, terrain: Terrain, is_quick: bool): super(FrontlineAttackOperation, self).prepare(terrain, is_quick) if self.defender_name == self.game.player_name: self.attackers_starting_position = None self.defenders_starting_position = None conflict = Conflict.frontline_cas_conflict( attacker_name=self.attacker_name, defender_name=self.defender_name, attacker=self.current_mission.country(self.attacker_country), defender=self.current_mission.country(self.defender_country), from_cp=self.from_cp, to_cp=self.to_cp, theater=self.game.theater) self.initialize(mission=self.current_mission, conflict=conflict)
def compute_conflicts_position(self): """ Compute the current conflict center position(s), mainly used for culling calculation :return: List of points of interests """ points = [] # By default, use the existing frontline conflict position for front_line in self.theater.conflicts(): position = Conflict.frontline_position(self.theater, front_line.control_point_a, front_line.control_point_b) points.append(position[0]) points.append(front_line.control_point_a.position) points.append(front_line.control_point_b.position) # If there is no conflict take the center point between the two nearest opposing bases if len(points) == 0: cpoint = None min_distance = sys.maxsize for cp in self.theater.player_points(): for cp2 in self.theater.enemy_points(): d = cp.position.distance_to_point(cp2.position) if d < min_distance: min_distance = d cpoint = Point((cp.position.x + cp2.position.x) / 2, (cp.position.y + cp2.position.y) / 2) points.append(cp.position) points.append(cp2.position) break if cpoint is not None: break if cpoint is not None: points.append(cpoint) # Else 0,0, since we need a default value # (in this case this means the whole map is owned by the same player, so it is not an issue) if len(points) == 0: points.append(Point(0, 0)) return points
def update(self): self.canvas.delete(ALL) self.canvas.create_image((self.image.width()/2, self.image.height()/2), image=self.image) for cp in self.game.theater.controlpoints: for ground_object in cp.ground_objects: x, y = self.transform_point(ground_object.position) self.canvas.create_text(x, y, text=".", fill="black" if ground_object.is_dead else self._enemy_color(), font=("Helvetica", 18)) coords = self.transform_point(cp.position) for connected_cp in cp.connected_points: connected_coords = self.transform_point(connected_cp.position) if connected_cp.captured != cp.captured: color = self._enemy_color() elif connected_cp.captured and cp.captured: color = self._player_color() else: color = "black" self.canvas.create_line((coords[0], coords[1], connected_coords[0], connected_coords[1]), width=2, fill=color) if cp.captured and not connected_cp.captured and Conflict.has_frontline_between(cp, connected_cp): frontline = Conflict.frontline_vector(cp, connected_cp, self.game.theater) if not frontline: continue frontline_pos, heading, distance = frontline if distance < 10000: frontline_pos = frontline_pos.point_from_heading(heading + 180, 5000) distance = 10000 start_coords = self.transform_point(frontline_pos, treshold=10) end_coords = self.transform_point(frontline_pos.point_from_heading(heading, distance), treshold=60) self.canvas.create_line((*start_coords, *end_coords), width=2, fill=color) for cp in self.game.theater.controlpoints: coords = self.transform_point(cp.position) arc_size = 16 * math.pow(cp.importance, 1) extent = max(cp.base.strength * 180, 10) start = (180 - extent) / 2 if cp.captured: color = self._player_color() else: color = self._enemy_color() cp_id = self.canvas.create_arc((coords[0] - arc_size/2, coords[1] - arc_size/2), (coords[0] + arc_size/2, coords[1] + arc_size/2), fill=color, style=PIESLICE, start=start, extent=extent) """ #For debugging purposes for r in cp.radials: p = self.transform_point(cp.position.point_from_heading(r, 20000)) self.canvas.create_text(p[0], p[1], text="{}".format(r)) continue """ self.canvas.tag_bind(cp_id, "<Button-1>", self.display(cp)) self.create_cp_title((coords[0] + arc_size/4, coords[1] + arc_size/4), cp) units_title = "{}/{}/{}".format(cp.base.total_planes, cp.base.total_armor, cp.base.total_aa) self.canvas.create_text(coords[0]+1, coords[1] - arc_size / 1.5 +1, text=units_title, font=("Helvetica", 8), fill=color) self.canvas.create_text(coords[0], coords[1] - arc_size / 1.5, text=units_title, font=("Helvetica", 8), fill="white")
from matplotlib import lines from shapely import geometry from shapely.geometry import Polygon from descartes.patch import PolygonPatch def put_lines(ls, ax): for g in ls.geoms: ax.plot([g.xy[0][0], g.xy[0][1]], [g.xy[1][0], g.xy[1][1]]) cau = CaucasusTheater() #left, heading, dist = Conflict.frontline_vector(cau.soganlug, cau.kutaisi, cau) #right = left.point_from_heading(heading, dist) left, heading = Conflict.frontline_position(cau, cau.soganlug, cau.kutaisi) right = left.point_from_heading(heading + 90, 80000) left = left.point_from_heading(heading - 90, 80000) line = geometry.LineString([(left.x, left.y), (right.x, right.y)]) line = line.intersection(cau.land_poly) fig = pyplot.figure(1, figsize=(20, 20), dpi=90) ax = fig.add_subplot(121) ax.set_ylim([0, 1500000]) ax.set_xlim([-600000, 400000]) patch = PolygonPatch(cau.land_poly, facecolor=(0, 0, 0), edgecolor=(0, 0, 0), alpha=0.5,