def _apply_altitude(self, v, altitude, routing_surface=None): if altitude is None or altitude is KEEP_ALTITUDE: return v final_surface = routing_surface if routing_surface is not None else self.routing_surface if final_surface: level = final_surface.secondary_id else: level = 0 zone_id = services.current_zone_id() world_surface = routing.SurfaceIdentifier( zone_id, level, routing.SurfaceType.SURFACETYPE_WORLD) water_surface = routing.SurfaceIdentifier( zone_id, level, routing.SurfaceType.SURFACETYPE_POOL) object_surface = routing.SurfaceIdentifier( zone_id, level, routing.SurfaceType.SURFACETYPE_OBJECT) world_height = get_terrain_height(v.x, v.z, routing_surface=world_surface) water_height = get_terrain_height(v.x, v.z, routing_surface=water_surface) object_height = get_terrain_height(v.x, v.z, routing_surface=object_surface) h = max(world_height, water_height, object_height) if h == routing_constants.INVALID_TERRAIN_HEIGHT: h = get_terrain_center().y return sims4.math.Vector3(v.x, h + altitude, v.z)
def notify_in_use(self, user, portal_instance, portal_object): if self.supports_landing_shoo: routing_surface = None exit_location = portal_instance.there_exit if exit_location.routing_surface.type == SurfaceType.SURFACETYPE_OBJECT: exit_height = terrain.get_terrain_height( exit_location.position.x, exit_location.position.z, routing_surface=exit_location.routing_surface) routing_surface = exit_location.routing_surface landing_points = [] for (there_start, there_end, back_start, back_end, _) in self.get_portal_locations(portal_object): for portal_location in (there_start, there_end, back_start, back_end): if portal_location.routing_surface.type == SurfaceType.SURFACETYPE_OBJECT: portal_height = terrain.get_terrain_height( portal_location.position.x, portal_location.position.z, routing_surface=portal_location.routing_surface ) if math.isclose(portal_height, exit_height): landing_points.append(portal_location.position) polygon = Polygon(landing_points) polygon = polygon.get_convex_hull() polygon = inflate_polygon( polygon, _PortalTypeDataStairs.STAIR_SHOO_POLYGON_PADDING) UserFootprintHelper.force_move_sims_in_polygon( polygon, routing_surface, exclude=(user, ))
def get_portal_asm_params(self, portal_instance, portal_id, sim): if portal_id == portal_instance.back: entry_location = portal_instance.back_entry exit_location = portal_instance.back_exit else: entry_location = portal_instance.there_entry exit_location = portal_instance.there_exit final_entry_height = terrain.get_terrain_height( entry_location.position.x, entry_location.position.z, entry_location.routing_surface) final_entry_position = sims4.math.Vector3(entry_location.position.x, final_entry_height, entry_location.position.z) final_exit_height = terrain.get_terrain_height( exit_location.position.x, exit_location.position.z, exit_location.routing_surface) final_exit_position = sims4.math.Vector3(exit_location.position.x, final_exit_height, exit_location.position.z) params = { ('InitialTranslation', 'x'): final_entry_position, ('InitialOrientation', 'x'): entry_location.orientation, ('TargetTranslation', 'x'): final_exit_position, ('TargetOrientation', 'x'): exit_location.orientation } if sim is not None: if self.buff_asm_parameters: for (buff, param) in self.buff_asm_parameters.items(): if sim.has_buff(buff.buff_type): params.update({ (param.parameter_name, 'x'): param.parameter_value }) return params
def _get_random_position_and_routing_surface(): theta = random.random()*sims4.math.TWO_PI scaled_dist = random.random()*max_dist x = scaled_dist*math.cos(theta) + lot_center.x z = scaled_dist*math.sin(theta) + lot_center.z routing_surface = routing.get_routing_surface_at_or_below_position(sims4.math.Vector3(x, sims4.math.MAX_FLOAT, z)) y = get_terrain_height(x, z, routing_surface=routing_surface) return (sims4.math.Vector3(x, y, z), routing_surface)
def _draw_goal_with_score(self, context, goal, goal_color, score_height, score_color, weight_height, weight_color): if goal is None: return self._draw_goal(context, goal, goal_color, weight_height, weight_color) ground_height = terrain.get_terrain_height(goal.location.position.x, goal.location.position.z, routing_surface=goal.routing_surface_id) bottom = sims4.math.Vector3(goal.location.position.x, ground_height, goal.location.position.z) top = sims4.math.Vector3(goal.location.position.x, ground_height + score_height, goal.location.position.z) context.add_segment(bottom, top, color=score_color, altitude=KEEP_ALTITUDE)
def test_surface_height(x: float = 0.0, y: float = 0.0, z: float = 0.0, _connection=None): terrain_height = get_terrain_height( x, z, SurfaceIdentifier(0, 0, SurfaceType.SURFACETYPE_WORLD)) sims4.commands.output('Terrain Surface: {}'.format(terrain_height), _connection) object_height = get_terrain_height( x, z, SurfaceIdentifier(0, 0, SurfaceType.SURFACETYPE_OBJECT)) sims4.commands.output('Object Surface: {}'.format(object_height), _connection) water_height = get_terrain_height( x, z, SurfaceIdentifier(0, 0, SurfaceType.SURFACETYPE_POOL)) sims4.commands.output('Water Surface: {}'.format(water_height), _connection) difference = water_height - terrain_height sims4.commands.output('Water Height: {}'.format(difference), _connection)
def create_sims(cls, sim_creators, household=None, tgt_client=None, generate_deterministic_sim=False, sim_position:sims4.math.Vector3=None, sim_spawner_tags=None, account=None, is_debug=False, skip_offset=False, additional_fgl_search_flags=None, creation_source:str='Unknown'): (sim_info_list, _) = cls.create_sim_infos(sim_creators, household=household, starting_funds=DEFAULT, tgt_client=tgt_client, account=account, generate_deterministic_sim=generate_deterministic_sim) offset = 0.0 for sim_info in sim_info_list: if sim_position is not None: sim_position = sims4.math.Vector3(*sim_position) if not skip_offset: offset = 2.0 sim_position.y = terrain.get_terrain_height(sim_position.x, sim_position.z) if is_debug: services.get_zone_situation_manager().add_debug_sim_id(sim_info.id) cls.spawn_sim(sim_info, sim_position, sim_spawner_tags=sim_spawner_tags, additional_fgl_search_flags=additional_fgl_search_flags, is_debug=is_debug) while sim_info.account is not None and tgt_client is not None: tgt_client.add_selectable_sim_info(sim_info)
def spread_fire(self): if not self._fire_objects: return logger.debug('Starting to attempt to spread fire.') fire_object_list = list(self._fire_objects) for attempt in range(self.MAX_NUM_ATTEMPTS_TO_PLACE_FIRE): logger.debug('Attempt {} to spread fire.', attempt) fire_object = random.choice(fire_object_list) distance_in_radii = self.FIRE_PLACEMENT_RANGE.random_float()*self.FIRE_QUADTREE_RADIUS new_position = fire_object.position + fire_object.forward*distance_in_radii new_position.y = terrain.get_terrain_height(new_position.x, new_position.z, fire_object.routing_surface) fire_object.move_to(transform=fire_object.transform, orientation=sims4.random.random_orientation()) if not self._placement_tests(new_position, level=fire_object.location.level, fire_object=fire_object): pass transform = sims4.math.Transform(new_position, sims4.random.random_orientation()) self._spawn_fire(transform, fire_object.routing_surface, run_placement_tests=False) logger.debug('Successfully placed fire object on attempt {}', attempt)
def create_sims(cls, sim_creators, household=None, tgt_client=None, generate_deterministic_sim=False, sim_position: sims4.math.Vector3 = None, sim_spawner_tags=None, account=None, is_debug=False, skip_offset=False, additional_fgl_search_flags=None, instantiate=True, creation_source: str = 'Unknown - create_sims'): (sim_info_list, _) = cls.create_sim_infos( sim_creators, household=household, starting_funds=DEFAULT, tgt_client=tgt_client, account=account, generate_deterministic_sim=generate_deterministic_sim, zone_id=0, creation_source=creation_source) if not instantiate: return offset = 0.0 for sim_info in sim_info_list: if sim_position is not None: sim_position = sims4.math.Vector3(*sim_position) sim_position.x += offset if not skip_offset: offset = 2.0 sim_position.y = terrain.get_terrain_height( sim_position.x, sim_position.z) if is_debug: services.get_zone_situation_manager().add_debug_sim_id( sim_info.id) cls.spawn_sim( sim_info, sim_position, sim_spawner_tags=sim_spawner_tags, additional_fgl_search_flags=additional_fgl_search_flags, is_debug=is_debug) client = services.client_manager().get_client_by_household_id( sim_info.household_id) if client is not None: client.add_selectable_sim_info(sim_info)
def _draw_goal(self, context, goal, goal_color, weight_height, weight_color): if goal is None: return (_, _, _, goal_color_alpha) = to_rgba(goal_color) goal_color_alpha = weight_height*goal_color_alpha goal_weight_color = from_rgba(0, 255, 0, goal_color_alpha) context.routing_surface = goal.routing_surface_id if goal.location.orientation != sims4.math.Quaternion.ZERO(): angle = sims4.math.yaw_quaternion_to_angle(goal.location.orientation) context.add_arrow(goal.location.position, angle, length=0.05, color=goal_color) context.add_arrow(goal.location.position, angle, length=0.1, color=goal_weight_color) else: context.add_circle(goal.location.position, 0.02, color=goal_color) context.add_circle(goal.location.position, 0.07, color=goal_weight_color) if weight_height > 0: ground_height = terrain.get_terrain_height(goal.location.position.x, goal.location.position.z, routing_surface=context.routing_surface) bottom = sims4.math.Vector3(goal.location.position.x, ground_height, goal.location.position.z) top = sims4.math.Vector3(bottom.x, bottom.y + weight_height, bottom.z) context.add_segment(bottom, top, color=weight_color, altitude=KEEP_ALTITUDE)
def get_height_at(self, x, z): return terrain.get_terrain_height(x, z)
def _apply_altitude(self, v, altitude, routing_surface=None): if altitude is None or altitude is KEEP_ALTITUDE: return v final_surface = routing_surface if routing_surface is not None else self.routing_surface h = get_terrain_height(v.x, v.z, routing_surface=final_surface) return sims4.math.Vector3(v.x, h + altitude, v.z)
def get_height_at(self, x, z): return terrain.get_terrain_height(x, z)