Exemple #1
0
 def get_waypoint_constraints_gen(self, routing_agent, waypoint_count):
     zone_id = services.current_zone_id()
     object_constraints = defaultdict(list)
     if self.object_tag_generator is not None:
         object_tag_generator = self.object_tag_generator(WaypointContext(self._sim), None)
         for constraint in itertools.chain((object_tag_generator.get_start_constraint(),), object_tag_generator.get_waypoint_constraints_gen(routing_agent, MAX_INT32)):
             level = constraint.routing_surface.secondary_id
             block_id = get_block_id(zone_id, constraint.average_position, level)
             object_constraints[block_id].append(constraint)
     plex_id = services.get_plex_service().get_active_zone_plex_id() or plex_enums.INVALID_PLEX_ID
     block_data = get_all_block_polygons(plex_id)
     polygons = defaultdict(list)
     if self._routing_surface.secondary_id == 0:
         polygons[0] = self._get_polygons_for_lot()
     for (block_id, (polys, level)) in block_data.items():
         if level != self._routing_surface.secondary_id:
             continue
         polygon = CompoundPolygon([Polygon(list(reversed(p))) for p in polys])
         if not polygon.area():
             continue
         polygons[block_id].append((polygon, self._routing_surface))
     if not polygons:
         return False
         yield
     final_constraints = self._get_waypoint_constraints_from_polygons(polygons, object_constraints, waypoint_count)
     final_constraints = self.apply_water_constraint(final_constraints)
     yield from final_constraints
Exemple #2
0
 def create_surface_proxy_from_location(location):
     position = location.transform.translation
     zone_id = services.current_zone_id()
     routing_surface = location.routing_surface
     level = routing_surface.secondary_id
     pool_block_id = 0
     if build_buy.is_location_pool(position, level):
         pool_block_id = build_buy.get_block_id(zone_id, position,
                                                level - 1)
         if not pool_block_id:
             logger.error('Failed ot get pool block id from location: {} ',
                          location)
             return
         pool = pool_utils.get_pool_by_block_id(pool_block_id)
         if pool is None:
             logger.error(
                 'Failed to get pool from pool block id {} at location: {}',
                 pool_block_id, location)
             return
         return PoolPoint(location, pool)
     if routing_surface.type == routing.SurfaceType.SURFACETYPE_POOL:
         if services.terrain_service.ocean_object() is None:
             logger.error('Ocean does not exist at location: {}', location)
             return
         return OceanPoint(location)
     return TerrainPoint(location)
 def get_room_id(location, position=None, level=None):
     zone_id = TurboWorldUtil.Zone.get_current_zone_id()
     return build_buy.get_block_id(
         zone_id, position if position is not None else
         TurboMathUtil.Location.get_location_translation(location),
         level if level is not None else
         TurboMathUtil.Location.get_location_level(location))
Exemple #4
0
 def constraint_gen(cls, inst, sim, target, participant_type, *args, **kwargs):
     if inst is not None and inst._edge_constraint is not None:
         yield inst._edge_constraint
         return
     inst_or_cls = cls if inst is None else inst
     pick_position = inst_or_cls.context.pick
     if pick_position is None:
         pick_position = target.position
     else:
         pick_position = pick_position.location
     pool_block_id = build_buy.get_block_id(sim.zone_id, pick_position, inst_or_cls.context.pick.level - 1)
     if pool_block_id == 0:
         if inst_or_cls.context.pick.routing_surface.type == SurfaceType.SURFACETYPE_POOL:
             if get_water_depth(sim.position.x, sim.position.z, sim.level) > 0:
                 pool_edge_constraints = ANYWHERE
             else:
                 pool_edge_constraints = OceanStartLocationConstraint.create_simple_constraint(WaterDepthIntervals.WET, 1, sim, target)
                 return
         else:
             return
     else:
         pool = pool_utils.get_pool_by_block_id(pool_block_id)
         if pool is None:
             return
         pool_edge_constraints = pool.get_edge_constraint(constraint_width=inst_or_cls.edge_constraint_width, inward_dir=False, return_constraint_list=True, los_reference_point=pick_position)
     constraint_set = create_constraint_set(pool_edge_constraints)
     inst._edge_constraint = constraint_set
     yield constraint_set
Exemple #5
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     sim = self._context.sim
     self._routing_surface = routing.SurfaceIdentifier(
         self._routing_surface.primary_id,
         self._routing_surface.secondary_id,
         routing.SurfaceType.SURFACETYPE_POOL)
     position = self._target.position if self._target is not None else sim.position
     level = self._routing_surface.secondary_id
     self._start_constraint = None
     self._master_depth_constraint = None
     self._waypoint_constraints = []
     self.keep_away_constraint = None
     self._location_is_pool = build_buy.is_location_pool(position, level)
     if self._location_is_pool:
         pool_block_id = build_buy.get_block_id(sim.zone_id, position,
                                                level - 1)
         pool = pool_utils.get_pool_by_block_id(pool_block_id)
         if pool is not None:
             pool_edge_constraints = pool.get_edge_constraint(
                 constraint_width=self.constraint_width,
                 inward_dir=True,
                 return_constraint_list=True)
             pool_edge_constraints = [
                 constraint.generate_geometry_only_constraint()
                 for constraint in pool_edge_constraints
             ]
             if self.keep_away_from_edges is not None:
                 bb_polys = build_buy.get_pool_polys(
                     pool_block_id, level - 1)
                 if len(bb_polys) > 0:
                     bb_poly = bb_polys[0]
                     _WaypointGeneratorPool._push_poly_inward(
                         bb_poly, self.keep_away_from_edges)
                     bb_poly.reverse()
                     keep_away_geom = sims4.geometry.RestrictedPolygon(
                         sims4.geometry.Polygon(bb_poly), ())
                     self.keep_away_constraint = Constraint(
                         routing_surface=pool.provided_routing_surface,
                         geometry=keep_away_geom)
                 else:
                     logger.error(
                         f'Pool Waypoint Generator: Pool polygon data unexpectedly empty while ${sim} was routing on a pool with id ${pool_block_id}.',
                         owner='jmorrow')
                 for i in range(len(pool_edge_constraints)):
                     pool_edge_constraints[i] = pool_edge_constraints[
                         i].intersect(self.keep_away_constraint)
             self._start_constraint = create_constraint_set(
                 pool_edge_constraints)
             self._waypoint_constraints = pool_edge_constraints
Exemple #6
0
    def get_block_id(zone_id: int, position: CommonVector3,
                     surface_level: int) -> int:
        """get_block_id(zone_id, position, surface_level)

        Retrieve the decimal identifier of the block containing the position.

        :param zone_id: The decimal identifier of a Zone.
        :type zone_id: int
        :param position: An instance of a vector.
        :type position: CommonVector3
        :param surface_level: The surface level of the position.
        :type surface_level: int
        :return: A decimal identifier of the block containing the position.
        :rtype: int
        """
        return build_buy.get_block_id(zone_id, position, surface_level)
Exemple #7
0
def get_block_id_for_node(node):
    block_id = build_buy.get_block_id(services.current_zone_id(),
                                      sims4.math.Vector3(*node.position),
                                      node.routing_surface_id.secondary_id)
    return block_id
Exemple #8
0
 def block_id(self):
     return get_block_id(
         self.zone_id, self._location.transform.translation + self.forward,
         self.portal_exit_routing_surface.secondary_id - 1)
Exemple #9
0
 def _get_block_id_for_node(node):
     zone_id = services.current_zone().id
     block_id = build_buy.get_block_id(zone_id, sims4.math.Vector3(*node.position), node.routing_surface_id.secondary_id)
     return block_id