예제 #1
0
entity *switch_auto_edit_entity (camera *raw)
{
    entity
    *new_;

    ASSERT (raw);

    ASSERT (raw->external_view_entity);

    if (frand1 () < 0.667)
    {
        new_ = get_best_view_entity (raw);

        if (new_)
        {
            set_external_view_entity (new_);
        }
    }
    else
    {
        new_ = NULL;
    }

    return (new_);
}
예제 #2
0
camera_modes get_auto_edit_random_camera_mode (camera *raw)
{
    camera_modes
    mode;

    ASSERT (raw);

    ASSERT (raw->external_view_entity);

    //
    // if the viewed entity is not moving then avoid the fly-by camera
    //

    mode = CAMERA_MODE_CINEMATIC;

    if (frand1 () < 0.5)
    {
        if (get_local_entity_vec3d_magnitude (raw->external_view_entity, VEC3D_TYPE_MOTION_VECTOR) >= 1.0)
        {
            mode = CAMERA_MODE_FLY_BY;
        }
    }

    return (mode);
}
예제 #3
0
파일: lib_rand.c 프로젝트: 1015472/PX4NuttX
static unsigned int nrand(unsigned int nLimit)
{
  unsigned long result;
  double_t ratio;

  /* Loop to be sure a legal random number is generated */

  do
    {
      /* Get a random integer in the requested range */

#if (CONFIG_LIB_RAND_ORDER == 1)
      ratio = frand1();
#elif (CONFIG_LIB_RAND_ORDER == 2)
      ratio = frand2();
#else /* if (CONFIG_LIB_RAND_ORDER > 2) */
      ratio = frand3();
#endif

      /* Then, produce the return-able value */

      result = (unsigned long)(((double_t)nLimit) * ratio);
    }
  while (result >= (unsigned long)nLimit);

  return (unsigned int)result;
}
예제 #4
0
void update_good_tone (void)
{
	if (good_tone_delay > 0.0)
	{
		good_tone_delay -= get_delta_time ();

		if (good_tone_delay <= 0.0)
		{
			good_tone_delay = 0.0;

			play_client_server_cpg_message (get_gunship_entity (), 0.5, 1.0, SPEECH_CATEGORY_CPG_SYSTEMS, 1.0, SPEECH_CPG_GOOD_TONE);
		}
	}

	if (!good_tone)
	{
		if (frand1 () < 0.5)
		{
			good_tone_delay = 0.5 + (frand1 () * 0.5);
		}
	}

	good_tone = TRUE;
}
예제 #5
0
파일: cyclic.c 프로젝트: Comanche93/eech
void damage_hydraulics(int damaging)
{
	if (damaging)
	{
		hydraulic_pressure = 0.65 + (sfrand1() * 0.1);  // lose some hydraulics pressure immediately
		// lock cyclic in a random position
		damaged_lock_x_pos = sfrand1() * 50.0;
		damaged_lock_y_pos = 25.0 + sfrand1() * 50.0;
		hydraulic_pressure_loss_rate = hydraulic_pressure * frand1() * (MAX_HYDRAULICS_LOSS_RATE - MIN_HYDRAULICS_LOSS_RATE) + MIN_HYDRAULICS_LOSS_RATE;
	}
	else
	{
		hydraulic_pressure = 1.0;
		hydraulic_pressure_loss_rate = 0.0;
	}
}
예제 #6
0
파일: ki_vckpt.c 프로젝트: Comanche93/eech
void draw_kiowa_virtual_cockpit (void)
{
	int
		draw_main_rotors;

	float
		theta;

	object_3d_instance
		*inst3d;

	object_3d_sub_object_search_data
		search;

	switch (get_view_mode ())
	{
		case VIEW_MODE_VIRTUAL_COCKPIT_CREW:
		case VIEW_MODE_VIRTUAL_COCKPIT_PILOT_LHS_DISPLAY:
		case VIEW_MODE_VIRTUAL_COCKPIT_PILOT_RHS_DISPLAY:
		case VIEW_MODE_VIRTUAL_COCKPIT_CO_PILOT_LHS_DISPLAY:
		case VIEW_MODE_VIRTUAL_COCKPIT_CO_PILOT_RHS_DISPLAY:
		{
			break;
		}
		default:
		{
			if (!get_global_draw_cockpit_graphics ())
			{
				return;
			}

			break;
		}
	}

	//
	// lamps
	//

	draw_kiowa_virtual_cockpit_lamps ();

	//
	// crew animation
	//

	set_kiowa_crew_head_positions ();

	//
	// animate main rotors
	//

	if (get_local_entity_int_value (get_gunship_entity (), INT_TYPE_MAIN_ROTOR_DAMAGED))
	{
		animate_damaged_helicopter_main_rotors (get_gunship_entity (), TRUE);
	}
	else
	{
		animate_helicopter_main_rotors (get_gunship_entity (), TRUE, FALSE);
	}

	inst3d = (object_3d_instance *) get_local_entity_ptr_value (get_gunship_entity (), PTR_TYPE_INSTANCE_3D_OBJECT);

	theta = get_rotation_angle_of_helicopter_main_rotors (inst3d);

	set_rotation_angle_of_helicopter_main_rotors (virtual_cockpit_inst3d, theta);

	animate_helicopter_virtual_cockpit_main_rotors (get_gunship_entity (), virtual_cockpit_inst3d);

	draw_main_rotors = TRUE;

	if (get_global_glass_cockpit ())
	{
		draw_main_rotors = FALSE;
	}
	else
	{
		if (get_view_mode () != VIEW_MODE_VIRTUAL_COCKPIT_CREW)
		{
			if (get_helicopter_main_rotors_blurred (get_gunship_entity ()))
			{
				if (!get_global_blurred_main_rotors_visible_from_cockpit ())
				{
					draw_main_rotors = FALSE;
				}
			}
		}
	}

	search.search_depth = 0;
	search.search_object = virtual_cockpit_inst3d;
	search.sub_object_index = OBJECT_3D_SUB_OBJECT_MAIN_ROTOR_SHAFT;

	if (find_object_3d_sub_object (&search) == SUB_OBJECT_SEARCH_RESULT_OBJECT_FOUND)
	{
		search.result_sub_object->visible_object = draw_main_rotors;
	}

	//
	// draw 3D scene
	//

	set_3d_view_distances (main_3d_env, 10.0, 0.1, 1.0, 0.0);

	realise_3d_clip_extents (main_3d_env);

	recalculate_3d_environment_settings (main_3d_env);

	clear_zbuffer_screen ();

	if (begin_3d_scene ())
	{
		//
		// light direction is in world coordinates
		//

		light_3d_source
			*display_backlight,
			*cockpit_light;

		vec3d
			direction;

		matrix3x3
			m1,
			m2;

//VJ 050131 update on wideview mod, much better movement
		if (get_global_wide_cockpit () &&
			( get_view_mode () != VIEW_MODE_VIRTUAL_COCKPIT_PILOT_LHS_DISPLAY &&
				get_view_mode () != VIEW_MODE_VIRTUAL_COCKPIT_PILOT_RHS_DISPLAY &&
				get_view_mode () != VIEW_MODE_VIRTUAL_COCKPIT_CO_PILOT_LHS_DISPLAY &&
				get_view_mode () != VIEW_MODE_VIRTUAL_COCKPIT_CO_PILOT_RHS_DISPLAY )
			)
		{
				get_kiowa_crew_viewpoint ();

				virtual_cockpit_inst3d->vp.x += wide_cockpit_position[wide_cockpit_nr].c.x;
				virtual_cockpit_inst3d->vp.y += wide_cockpit_position[wide_cockpit_nr].c.y;
				virtual_cockpit_inst3d->vp.z += wide_cockpit_position[wide_cockpit_nr].c.z;

				//ataribaby 27/12/2008
				//virtual_cockpit_inst3d->vp.x += bound(current_flight_dynamics->model_acceleration_vector.x * ONE_OVER_G, -3.0, 3.0) * 0.025 * command_line_g_force_head_movment_modifier;
				//virtual_cockpit_inst3d->vp.y += bound(current_flight_dynamics->g_force.value - 1.0, -1.5, 5.0) * 0.025 * command_line_g_force_head_movment_modifier;

				if (wide_cockpit_nr == WIDEVIEW_KIOWA_PILOT)
					pilot_head_pitch_datum = rad ( wide_cockpit_position[wide_cockpit_nr].c.p );
				if (wide_cockpit_nr == WIDEVIEW_KIOWA_COPILOT)
					co_pilot_head_pitch_datum = rad ( wide_cockpit_position[wide_cockpit_nr].c.p );

				set_3d_view_distances (main_3d_env, 10.0, 0.1, 1.0, 0.0);

		}

		//ataribaby 27/12/2008 new head g-force movement and vibration from main rotor
		if (get_view_mode () != VIEW_MODE_VIRTUAL_COCKPIT_PILOT_LHS_DISPLAY &&
				get_view_mode () != VIEW_MODE_VIRTUAL_COCKPIT_PILOT_RHS_DISPLAY &&
				get_view_mode () != VIEW_MODE_VIRTUAL_COCKPIT_CO_PILOT_LHS_DISPLAY &&
				get_view_mode () != VIEW_MODE_VIRTUAL_COCKPIT_CO_PILOT_RHS_DISPLAY)
		{
			if (get_time_acceleration() != TIME_ACCELERATION_PAUSE)
			{
				random_vibration_x = (frand1() * (current_flight_dynamics->main_rotor_rpm.value * 0.00002)) * command_line_g_force_head_movment_modifier;
				random_vibration_y = (frand1() * (current_flight_dynamics->main_rotor_rpm.value * 0.00002)) * command_line_g_force_head_movment_modifier;
			}
			x_head_g_movement = move_by_rate(x_head_g_movement, random_vibration_x + (bound(current_flight_dynamics->model_acceleration_vector.x * ONE_OVER_G, -3.0, 3.0) * 0.025 * command_line_g_force_head_movment_modifier), 0.05);
			y_head_g_movement = move_by_rate(y_head_g_movement, random_vibration_y + (bound(current_flight_dynamics->g_force.value - 1.0, -1.5, 5.0) * 0.025 * command_line_g_force_head_movment_modifier), 0.05);

			virtual_cockpit_inst3d->vp.x -= x_head_g_movement;
			//if (!current_flight_dynamics->auto_hover)   // arneh - auto hover has some weird dynamics which cause lots of g-forces, so disable head movement when auto hover is enabled
			virtual_cockpit_inst3d->vp.y -= y_head_g_movement;
		}

		{
				//
				// ADI
				//

				search.search_depth = 0;
				search.search_object = virtual_cockpit_inst3d;
				search.sub_object_index = OBJECT_3D_SUB_OBJECT_APACHE_VIRTUAL_COCKPIT_ADI;

				if (find_object_3d_sub_object (&search) == SUB_OBJECT_SEARCH_RESULT_OBJECT_FOUND)
				{
					float
						heading,
						pitch,
						roll;

					get_kiowa_virtual_cockpit_adi_angles (virtual_cockpit_inst3d->vp.attitude, &heading, &pitch, &roll);

					search.result_sub_object->relative_heading = -heading;

					search.result_sub_object->relative_pitch = pitch;

					search.result_sub_object->relative_roll = -roll;
				}

				//
				// ADI slip
				//

				search.search_depth = 0;
				search.search_object = virtual_cockpit_inst3d;
				search.sub_object_index = OBJECT_3D_SUB_OBJECT_APACHE_VIRTUAL_COCKPIT_ADI_SIDE_SLIP;

				if (find_object_3d_sub_object (&search) == SUB_OBJECT_SEARCH_RESULT_OBJECT_FOUND)
				{
					search.result_sub_object->relative_roll = get_kiowa_virtual_cockpit_adi_slip_indicator_needle_value ();
				}

				//
				// airspeed
				//

				search.search_depth = 0;
				search.search_object = virtual_cockpit_inst3d;
				search.sub_object_index = OBJECT_3D_SUB_OBJECT_APACHE_VIRTUAL_COCKPIT_AIRSPEED;

				if (find_object_3d_sub_object (&search) == SUB_OBJECT_SEARCH_RESULT_OBJECT_FOUND)
				{
					search.result_sub_object->relative_roll = get_kiowa_virtual_cockpit_airspeed_indicator_needle_value ();
				}

				//
				// altimeter
				//

				search.search_depth = 0;
				search.search_object = virtual_cockpit_inst3d;
				search.sub_object_index = OBJECT_3D_SUB_OBJECT_APACHE_VIRTUAL_COCKPIT_ALTIMETER;

				if (find_object_3d_sub_object (&search) == SUB_OBJECT_SEARCH_RESULT_OBJECT_FOUND)
				{
					search.result_sub_object->relative_roll = get_kiowa_virtual_cockpit_barometric_altimeter_needle_value ();
				}

				search.search_depth = 0;
				search.search_object = virtual_cockpit_inst3d;
				search.sub_object_index = OBJECT_3D_SUB_OBJECT_APACHE_VIRTUAL_COCKPIT_COMPASS_HEADING_NULL;

				if (find_object_3d_sub_object (&search) == SUB_OBJECT_SEARCH_RESULT_OBJECT_FOUND)
				{
					search.result_sub_object->relative_heading = -current_flight_dynamics->heading.value;
				}

				//
				// clock
				//

				{
					float
						hours,
						minutes,
						seconds;

					//
					// only read clock values if drawing virtual cockpit needles to prevent speeding up clock debug values
					//

					get_kiowa_virtual_cockpit_clock_hand_values (&hours, &minutes, &seconds);

					//
					// hour hand
					//

					search.search_depth = 0;
					search.search_object = virtual_cockpit_inst3d;
					search.sub_object_index = OBJECT_3D_SUB_OBJECT_APACHE_VIRTUAL_COCKPIT_CLOCK_HOUR_HAND;

					if (find_object_3d_sub_object (&search) == SUB_OBJECT_SEARCH_RESULT_OBJECT_FOUND)
					{
						search.result_sub_object->relative_roll = hours;
					}

					//
					// minute hand
					//

					search.search_depth = 0;
					search.search_object = virtual_cockpit_inst3d;
					search.sub_object_index = OBJECT_3D_SUB_OBJECT_APACHE_VIRTUAL_COCKPIT_CLOCK_MINUTE_HAND;

					if (find_object_3d_sub_object (&search) == SUB_OBJECT_SEARCH_RESULT_OBJECT_FOUND)
					{
						search.result_sub_object->relative_roll = minutes;
					}

					//
					// second hand
					//

					search.search_depth = 0;
					search.search_object = virtual_cockpit_inst3d;
					search.sub_object_index = OBJECT_3D_SUB_OBJECT_APACHE_VIRTUAL_COCKPIT_CLOCK_SECOND_HAND;

					if (find_object_3d_sub_object (&search) == SUB_OBJECT_SEARCH_RESULT_OBJECT_FOUND)
					{
						search.result_sub_object->relative_roll = seconds;
					}
				}
		}

		if (get_local_entity_int_value (get_session_entity (), INT_TYPE_DAY_SEGMENT_TYPE) == DAY_SEGMENT_TYPE_DAY)
		{
			////////////////////////////////////////
			//
			// DAY LIGHTING
			//
			////////////////////////////////////////

			if (night_vision_system_active && (get_view_mode () != VIEW_MODE_VIRTUAL_COCKPIT_CREW))
			{
				//
				// active night vision system
				//

				get_3d_transformation_matrix (m1, rad (0.0), rad (135.0), rad (0.0));

				multiply_matrix3x3_matrix3x3 (m2, m1, virtual_cockpit_inst3d->vp.attitude);

				direction.x = m2[2][0];
				direction.y = m2[2][1];
				direction.z = m2[2][2];

				cockpit_light = create_light_3d_source (LIGHT_3D_TYPE_DIRECTIONAL, FALSE, &direction, 0, 0.0000, 0.5000, 0.0000);

				insert_light_3d_source_into_3d_scene (cockpit_light);

				insert_relative_object_into_3d_scene (OBJECT_3D_DRAW_TYPE_ZBUFFERED_OBJECT, &virtual_cockpit_inst3d->vp.position, virtual_cockpit_inst3d);

				draw_3d_scene ();

				end_3d_scene ();

				remove_light_3d_source_from_3d_scene (cockpit_light);

				destroy_light_3d_source (cockpit_light);
			}
			else
			{
				//
				// inactive night vision system
				//

				insert_relative_object_into_3d_scene (OBJECT_3D_DRAW_TYPE_ZBUFFERED_OBJECT, &virtual_cockpit_inst3d->vp.position, virtual_cockpit_inst3d);

				draw_3d_scene ();

				print_edit_wide_cockpit ();

				end_3d_scene ();
			}
		}
		else
		{
			////////////////////////////////////////
			//
			// NIGHT LIGHTING
			//
			////////////////////////////////////////

			direction.x = virtual_cockpit_inst3d->vp.zv.x;
			direction.y = virtual_cockpit_inst3d->vp.zv.y;
			direction.z = virtual_cockpit_inst3d->vp.zv.z;

			display_backlight = create_light_3d_source (LIGHT_3D_TYPE_DIRECTIONAL, FALSE, &direction, 0, 0.0627, 0.2039, 0.0392);

			if (night_vision_system_active && (get_view_mode () != VIEW_MODE_VIRTUAL_COCKPIT_CREW))
			{
				//
				// active night vision system
				//

				get_3d_transformation_matrix (m1, rad (0.0), rad (135.0), rad (0.0));

				multiply_matrix3x3_matrix3x3 (m2, m1, virtual_cockpit_inst3d->vp.attitude);

				direction.x = m2[2][0];
				direction.y = m2[2][1];
				direction.z = m2[2][2];

				cockpit_light = create_light_3d_source (LIGHT_3D_TYPE_DIRECTIONAL, FALSE, &direction, 0, 0.0000, 0.5000, 0.0000);
			}
			else
			{
				//
				// inactive night vision system
				//

				direction.x = virtual_cockpit_inst3d->vp.yv.x;
				direction.y = virtual_cockpit_inst3d->vp.yv.y;
				direction.z = virtual_cockpit_inst3d->vp.yv.z;

				cockpit_light = create_light_3d_source (LIGHT_3D_TYPE_DIRECTIONAL, FALSE, &direction, 0, 0.0666, 0.1098, 0.6431);
			}

			insert_light_3d_source_into_3d_scene (display_backlight);

			insert_light_3d_source_into_3d_scene (cockpit_light);

			insert_relative_object_into_3d_scene (OBJECT_3D_DRAW_TYPE_ZBUFFERED_OBJECT, &virtual_cockpit_inst3d->vp.position, virtual_cockpit_inst3d);

			draw_3d_scene ();

			print_edit_wide_cockpit ();

			end_3d_scene ();

			remove_light_3d_source_from_3d_scene (display_backlight);

			remove_light_3d_source_from_3d_scene (cockpit_light);

			destroy_light_3d_source (display_backlight);

			destroy_light_3d_source (cockpit_light);
		}
	}

	move_edit_wide_cockpit ();

#if RECOGNITION_GUIDE
	set_3d_view_distances (main_3d_env, 10000.0, 100.0, 1.0, 0.0);
#else
	set_3d_view_distances (main_3d_env, 10000.0, 1.0, 1.0, 0.0);
#endif

	realise_3d_clip_extents (main_3d_env);
}
예제 #7
0
파일: rv_pack.c 프로젝트: Comanche93/eech
static void unpack_local_data (entity *en, entity_types type, pack_modes mode)
{
	ASSERT ((mode >= 0) && (mode < NUM_PACK_MODES));

	switch (mode)
	{
		////////////////////////////////////////
		case PACK_MODE_SERVER_SESSION:
		case PACK_MODE_CLIENT_SESSION:
		////////////////////////////////////////
		{

			int
				index;

			routed_vehicle
				*raw;

			node_link_data
				*route_data;

			//
			// create entity
			//

			index = unpack_entity_safe_index ();

			en = get_free_entity (index);

			set_local_entity_type (en, type);

			raw = (routed_vehicle *) malloc_fast_mem (sizeof (routed_vehicle));

			set_local_entity_data (en, raw);

			memset (raw, 0, sizeof (routed_vehicle));

			//
			// unpack vehicle data (in exactly the same order as the data was packed)
			//

			unpack_vehicle_data (en, &raw->vh, mode);

			if (unpack_int_value (en, INT_TYPE_VALID))
			{

				raw->vh.mob.velocity = 0.0;

				raw->desired_velocity = 0.0;
			}
			else
			{

				raw->vh.mob.velocity = unpack_float_value (en, FLOAT_TYPE_LOW_VELOCITY);

				raw->desired_velocity = unpack_float_value (en, FLOAT_TYPE_DESIRED_VELOCITY);
			}

			//
			// unpack routed data
			//

			if (unpack_int_value (en, INT_TYPE_VALID))
			{
	
				raw->sub_waypoint_count = unpack_int_value (en, INT_TYPE_SUB_WAYPOINT_COUNT);
	
				raw->waypoint_next_index = unpack_int_value (en, INT_TYPE_WAYPOINT_NEXT_INDEX);
	
				raw->waypoint_this_index = unpack_int_value (en, INT_TYPE_WAYPOINT_THIS_INDEX);
			}

			//
			// turn lights on if necessary
			//

			set_vehicle_headlight_state (en, raw->vh.lights_on);

			//
			// setup waypoint route pointer
			//

			#if DEBUG_MODULE

			debug_log ("ROUTED ENTITY PACK: client setting up waypoint list pointer");

			#endif

			route_data = get_road_sub_route (raw->waypoint_this_index, raw->waypoint_next_index, &index, NULL);

			if ((route_data) && (route_data->link_positions))
			{

				raw->sub_route = route_data;
			}
			else
			{

				if ((raw->waypoint_this_index + raw->waypoint_next_index) != 0)
				{

					debug_log ("RV_PACK: WARNING NO SUB ROUTE FOUND BETWEEN %d AND %d", raw->waypoint_this_index, raw->waypoint_next_index);
				}
			}

			//
			// radar dish rotation (ok to use a random number as this is for visual effect only)
			//

			raw->vh.radar_rotation_state = frand1 ();

			set_routed_vehicle_id_number (en);

			set_initial_rotation_angle_of_routed_vehicle_wheels (raw->vh.inst3d);

			//
			// link into system
			//

			insert_local_entity_into_parents_child_list (en, LIST_TYPE_VIEW, get_camera_entity (), NULL);

			insert_local_entity_into_parents_child_list (en, LIST_TYPE_SECTOR, get_local_sector_entity (&raw->vh.mob.position), NULL);

			insert_local_entity_into_parents_child_list (en, LIST_TYPE_UPDATE, get_update_entity (), NULL);

			add_to_force_info (get_local_force_entity ((entity_sides) raw->vh.mob.side), en);

			//
			// attached smoke lists must be unpacked after the entity is linked into the world
			//

			unpack_routed_vehicle_meta_smoke_lists (en, mode);
	
			unpack_mobile_local_sound_effects (en, mode);

			break;
		}
		////////////////////////////////////////
		case PACK_MODE_BROWSE_SESSION:
		////////////////////////////////////////
		{

			break;
		}
		////////////////////////////////////////
		case PACK_MODE_UPDATE_ENTITY:
		////////////////////////////////////////
		{
			//
			// always use access functions to set the data
			//

			vec3d
				position;

			matrix3x3
				attitude;

			int
				sub_waypoint_count;

			//
			// unpack all data (even if the echoed data is to be ignored)
			//

			unpack_vec3d (en, VEC3D_TYPE_POSITION, &position);

			unpack_attitude_matrix (en, attitude);

			sub_waypoint_count = unpack_int_value (en, INT_TYPE_SUB_WAYPOINT_COUNT);

			set_local_entity_vec3d (en, VEC3D_TYPE_POSITION, &position);

			set_local_entity_attitude_matrix (en, attitude);

			set_local_entity_int_value (en, INT_TYPE_SUB_WAYPOINT_COUNT, sub_waypoint_count);

			// Vehicle is moving so sleep must equal 0
			set_local_entity_float_value (en, FLOAT_TYPE_SLEEP, 0.0);

			break;
		}
	}
}
예제 #8
0
void reset_cinematic_camera (camera *raw)
{
	entity
		*en;

	object_3d_instance
		*inst3d;

	int
		num_moving_cameras,
		num_static_cameras,
		attempts;

	//
	// pre-amble
	//

	ASSERT (raw);

	ASSERT (raw->external_view_entity);

	en = raw->external_view_entity;

	inst3d = get_local_entity_ptr_value (en, PTR_TYPE_INSTANCE_3D_OBJECT);

	//
	// select 3D camera
	//

	raw->cinematic_camera_index = OBJECT_3D_INVALID_CAMERA_INDEX;

	if (inst3d)
	{
		num_moving_cameras = get_number_of_3d_object_cameras (inst3d, OBJECT_3D_CAMERA_SCENIC_MOVING);

		num_static_cameras = get_number_of_3d_object_cameras (inst3d, OBJECT_3D_CAMERA_SCENIC_STATIC);

		if ((num_moving_cameras > 0) && (num_static_cameras > 0))
		{
			if (frand1 () < 0.333)
			{
				raw->cinematic_camera_index = OBJECT_3D_CAMERA_SCENIC_MOVING;
			}
			else
			{
				raw->cinematic_camera_index = OBJECT_3D_CAMERA_SCENIC_STATIC;
			}
		}
		else if (num_moving_cameras > 0)
		{
			raw->cinematic_camera_index = OBJECT_3D_CAMERA_SCENIC_MOVING;
		}
		else if (num_static_cameras > 0)
		{
			raw->cinematic_camera_index = OBJECT_3D_CAMERA_SCENIC_STATIC;
		}
	}

	switch (raw->cinematic_camera_index)
	{
		////////////////////////////////////////
		case OBJECT_3D_INVALID_CAMERA_INDEX:
		////////////////////////////////////////
		{
			raw->cinematic_camera_depth = 0;

			raw->cinematic_camera_lifetime = (frand1 () * 2.0) + 2.0;

			raw->cinematic_camera_heading = rad (45.0) * ((float) (rand16 () % 8));

			raw->cinematic_camera_pitch = rad (-45.0) * ((float) (rand16 () % 2));

			#if DEBUG_MODULE

			debug_log
			(
				"CINEMATIC CAMERA is INVALID (object = %s, moving cameras = %d, static cameras = %d, depth = %d, lifetime = %.2f, heading = %.2f, pitch = %.2f)",
				get_local_entity_string (en, STRING_TYPE_FULL_NAME),
				num_moving_cameras,
				num_static_cameras,
		  		raw->cinematic_camera_depth,
				raw->cinematic_camera_lifetime,
				deg (raw->cinematic_camera_heading),
				deg (raw->cinematic_camera_pitch)
			);

			#endif

			break;
		}
		////////////////////////////////////////
		case OBJECT_3D_CAMERA_SCENIC_MOVING:
		////////////////////////////////////////
		{
			//
			// try and prevent using the same moving camera twice in succession
			//

			if (num_moving_cameras > 1)
			{
				attempts = 10;

				while (attempts--)
				{
					raw->cinematic_camera_depth = rand16 () % num_moving_cameras;

					if (raw->cinematic_camera_depth != raw->cinematic_camera_previous_moving_depth)
					{
						break;
					}
				}
			}
			else
			{
				raw->cinematic_camera_depth = 0;
			}

			raw->cinematic_camera_previous_moving_depth = raw->cinematic_camera_depth;

			raw->cinematic_camera_lifetime = get_object_3d_camera_lifetime (inst3d, raw->cinematic_camera_index, raw->cinematic_camera_depth);

			#if DEBUG_MODULE

			debug_log
			(
				"CINEMATIC CAMERA is MOVING (object = %s, moving cameras = %d, static cameras = %d, depth = %d, lifetime = %.2f)",
				get_local_entity_string (en, STRING_TYPE_FULL_NAME),
				num_moving_cameras,
				num_static_cameras,
		  		raw->cinematic_camera_depth,
				raw->cinematic_camera_lifetime
			);

			#endif

			ASSERT (raw->cinematic_camera_lifetime > 0.0);

			break;
		}
		////////////////////////////////////////
		case OBJECT_3D_CAMERA_SCENIC_STATIC:
		////////////////////////////////////////
		{
			//
			// try and prevent using the same static camera twice in succession
			//

			if (num_static_cameras > 1)
			{
				attempts = 10;

				while (attempts--)
				{
					raw->cinematic_camera_depth = rand16 () % num_static_cameras;

					if (raw->cinematic_camera_depth != raw->cinematic_camera_previous_static_depth)
					{
						break;
					}
				}
			}
			else
			{
				raw->cinematic_camera_depth = 0;
			}

			raw->cinematic_camera_previous_static_depth = raw->cinematic_camera_depth;

			raw->cinematic_camera_lifetime = (frand1 () * 2.0) + 2.0;

			#if DEBUG_MODULE

			debug_log
			(
				"CINEMATIC CAMERA is STATIC (object = %s, moving cameras = %d, static cameras = %d, depth = %d, lifetime = %.2f)",
				get_local_entity_string (en, STRING_TYPE_FULL_NAME),
				num_moving_cameras,
				num_static_cameras,
		  		raw->cinematic_camera_depth,
				raw->cinematic_camera_lifetime
			);

			#endif
		}
	}

	raw->cinematic_camera_timer = 0.0;

	//
	// motion vector
	//

	get_local_entity_vec3d (en, VEC3D_TYPE_MOTION_VECTOR, &raw->motion_vector);
}
예제 #9
0
void update_3d_rain ( env_3d *env, float time, matrix3x3 view_attitude )
{

	int
		start_raindrop_number,
		end_raindrop_number,
		total_raindrop_number,

		start_snowdrop_number,
		end_snowdrop_number,
		total_snowdrop_number,

		creation_allowed,
		count;

	float
		displacement_magnitude,
		snow_displacement_magnitude,
		snow_fall_displacement,
		weather_t;

	vec3d
		distance_moved,
		rain_displacement,
		snow_drift_displacement,
		rain_streak_displacement,
		creation_vector;

	//
	// Calculate how many rain drops we should have. This is a linear scale, from 0, to TOTAL_3D_RAINDROPS.
	//  DRY = 0
	//  LIGHT_RAIN = TOTAL_3D_RAINDROPS / 2
	//  HEAVY_RAIN = TOTAL_3D_RAINDROPS
	//

	if ( visual_3d_vp )
	{

		if ( visual_3d_vp->position.y > get_cloud_3d_base_height () )
		{

			creation_allowed = FALSE;
		}
		else
		{

			creation_allowed = TRUE;
		}
	}
	else
	{

		creation_allowed = FALSE;
	}

	start_raindrop_number = number_of_weather_particles_allowed[env->weathermode].number_of_raindrops;
	start_snowdrop_number = number_of_weather_particles_allowed[env->weathermode].number_of_snowdrops;

	end_raindrop_number = number_of_weather_particles_allowed[env->target_weathermode].number_of_raindrops;
	end_snowdrop_number = number_of_weather_particles_allowed[env->target_weathermode].number_of_snowdrops;

	weather_t = env->weather_targetdistance;

	if ( weather_t == 0 )
	{

		total_raindrop_number = start_raindrop_number;
		total_snowdrop_number = start_snowdrop_number;
	}
	else if ( weather_t == 1 )
	{

		total_raindrop_number = end_raindrop_number;
		total_snowdrop_number = end_snowdrop_number;
	}
	else
	{

		total_raindrop_number = start_raindrop_number + ( ( ( float ) ( end_raindrop_number - start_raindrop_number ) ) * weather_t );
		total_snowdrop_number = start_snowdrop_number + ( ( ( float ) ( end_snowdrop_number - start_snowdrop_number ) ) * weather_t );
	}

	//
	// Special snow flag stuff
	//

	if ( special_snow_flag )
	{
/*
		if ( visual_3d_vp )
		{

			int
				x,
				z;

			int
				near_snow;

			float
				old_rain_total;

			near_snow = FALSE;

			for ( z = -1; z <= 1; z++ )
			{

				for ( x = -1; x <= 1; x++ )
				{

					float
						x_pos,
						z_pos;

					x_pos = visual_3d_vp->x + x * TERRAIN_3D_SECTOR_SIDE_LENGTH;
					z_pos = visual_3d_vp->z + z * TERRAIN_3D_SECTOR_SIDE_LENGTH;

					x_pos = bound ( x_pos, terrain_3d_min_map_x, terrain_3d_max_map_x );
					z_pos = bound ( z_pos, terrain_3d_min_map_z, terrain_3d_max_map_z );

					get_terrain_3d_types_in_sector ( x_pos, z_pos );

					if ( terrain_types_in_sector[TERRAIN_TYPE_ALTERED_LAND3] )
					{

						near_snow = TRUE;
					}
				}
			}

			if ( near_snow )
			{

				old_rain_total = total_raindrop_number;

				total_raindrop_number = old_rain_total * 0.0;
				total_snowdrop_number = old_rain_total * 1.0;
			}
		}
		*/
	}

	//
	//
	//

	rain_3d_delta_time = time - time_rain_last_updated;

	time_rain_last_updated = time;

	//
	// Calculate the distance moved by each raindrop.
	//

	distance_moved.x = rain_3d_wind_direction.x * rain_3d_wind_speed * rain_3d_delta_time;
	distance_moved.y = rain_3d_wind_direction.y * rain_3d_wind_speed * rain_3d_delta_time;
	distance_moved.z = rain_3d_wind_direction.z * rain_3d_wind_speed * rain_3d_delta_time;

	rain_displacement.x = distance_moved.x;
	rain_displacement.y = distance_moved.y + ( rain_3d_speed * rain_3d_delta_time );
	rain_displacement.z = distance_moved.z;

	//
	// Calculate the distance moved by each snowdrop.
	//

	snow_drift_displacement.x = distance_moved.x;
	snow_drift_displacement.y = distance_moved.y;
	snow_drift_displacement.z = distance_moved.z;

	snow_fall_displacement = ( rain_3d_speed / 4 ) * rain_3d_delta_time;

	snow_displacement_magnitude = get_3d_vector_magnitude ( &snow_drift_displacement );

	//
	// Calculate the 'streak' effect - this is now NOT framerate related
	//

	rain_streak_displacement = rain_displacement;

	displacement_magnitude = get_3d_vector_magnitude ( &rain_streak_displacement );

	if ( displacement_magnitude != 0 )
	{

		displacement_magnitude = 1.5 / displacement_magnitude;

		rain_streak_displacement.x *= displacement_magnitude;
		rain_streak_displacement.y *= displacement_magnitude;
		rain_streak_displacement.z *= displacement_magnitude;
	}
	else
	{

		//
		// Put artificial streaking in there ( game paused )
		//

		rain_streak_displacement.x = rain_3d_wind_direction.x * rain_3d_wind_speed * 0.05;
		rain_streak_displacement.y = rain_3d_wind_direction.y * rain_3d_wind_speed * 0.05 + ( rain_3d_speed * 0.05 );
		rain_streak_displacement.z = rain_3d_wind_direction.z * rain_3d_wind_speed * 0.05;

		displacement_magnitude = get_3d_vector_magnitude ( &rain_streak_displacement );

		if ( displacement_magnitude != 0 )
		{

			displacement_magnitude = 1.5 / displacement_magnitude;

			rain_streak_displacement.x *= displacement_magnitude;
			rain_streak_displacement.y *= displacement_magnitude;
			rain_streak_displacement.z *= displacement_magnitude;
		}
	}

	//
	// Remove any raindrops that have strayed out of the area of effect
	//

	creation_vector.x = rain_3d_wind_direction.x * rain_3d_wind_speed * 0.5;
	creation_vector.y = rain_3d_wind_direction.y * rain_3d_wind_speed * 0.5 + ( rain_3d_speed * 0.5 );
	creation_vector.z = rain_3d_wind_direction.z * rain_3d_wind_speed * 0.5;

	normalise_any_3d_vector ( &creation_vector );

	for ( count = 0; count < TOTAL_3D_RAINDROPS; count++ )
	{

		switch ( rain_3d_drops[count].type )
		{

			case RAINDROP_RAIN:
			{

				vec3d
					rel;

				//
				// Update the rain position
				//

				rain_3d_drops[count].current_position.x -= rain_displacement.x;
				rain_3d_drops[count].current_position.y -= rain_displacement.y;
				rain_3d_drops[count].current_position.z -= rain_displacement.z;

				rel.x = rain_3d_drops[count].current_position.x - visual_3d_vp->x;
				rel.y = rain_3d_drops[count].current_position.y - visual_3d_vp->y;
				rel.z = rain_3d_drops[count].current_position.z - visual_3d_vp->z;

				if (
						( rel.x > RAINDROPS_AREA_WIDTH ) || ( rel.x < ( -RAINDROPS_AREA_WIDTH ) ) ||
						( rel.y > RAINDROPS_AREA_HEIGHT ) || ( rel.y < ( -RAINDROPS_AREA_HEIGHT ) ) ||
						( rel.z > RAINDROPS_AREA_DEPTH ) || ( rel.z < ( -RAINDROPS_AREA_DEPTH ) )
					)
				{


					rain_3d_raindrops_valid--;

					rain_3d_drops[count].type = RAINDROP_INVALID;
				}

				break;
			}

			case RAINDROP_SNOW:
			{

				vec3d
					snow_noise,
					rel;

				float
					relative_speed;

				//
				// Update the rain position
				//

				snow_noise.x = sfrand1 () * rain_3d_delta_time;	//0.1	;//snow_displacement_magnitude;
				snow_noise.y = sfrand1 () * rain_3d_delta_time;	//0.1	;//snow_displacement_magnitude;
				snow_noise.z = sfrand1 () * rain_3d_delta_time;	//0.1	;//snow_displacement_magnitude;

				relative_speed = rain_3d_drops[count].relative_speed;

				rain_3d_drops[count].current_position.x -= ( snow_drift_displacement.x + snow_noise.x );
				rain_3d_drops[count].current_position.y -= ( snow_drift_displacement.y );
				rain_3d_drops[count].current_position.z -= ( snow_drift_displacement.z + snow_noise.x );

				rain_3d_drops[count].current_position.y -= ( snow_fall_displacement * relative_speed );

				rel.x = rain_3d_drops[count].current_position.x - visual_3d_vp->x;
				rel.y = rain_3d_drops[count].current_position.y - visual_3d_vp->y;
				rel.z = rain_3d_drops[count].current_position.z - visual_3d_vp->z;

				if (
						( rel.x > SNOWDROPS_AREA_WIDTH ) || ( rel.x < ( -SNOWDROPS_AREA_WIDTH ) ) ||
						( rel.y > SNOWDROPS_AREA_HEIGHT ) || ( rel.y < ( -SNOWDROPS_AREA_HEIGHT ) ) ||
						( rel.z > SNOWDROPS_AREA_DEPTH ) || ( rel.z < ( -SNOWDROPS_AREA_DEPTH ) )
					)
				{

					rain_3d_snowdrops_valid--;

					rain_3d_drops[count].type = RAINDROP_INVALID;
				}

				break;
			}
		}

		if ( ( rain_3d_drops[count].type == RAINDROP_INVALID ) && ( creation_allowed ) )
		{

			if ( rain_3d_raindrops_valid < total_raindrop_number )
			{

				float
					x,
					y,
					z,
					creation_distance;

				//
				// Generate a new rain drop randomly
				//

				z = ( ( frand1 () * 0.8 ) + 0.2 ) * ( RAINDROPS_AREA_DEPTH / 5 );
				x = sfrand1 () * ( RAINDROPS_AREA_WIDTH / 5 );
				y = sfrand1 () * ( RAINDROPS_AREA_HEIGHT / 5 );

				x *= z / 50;
				y *= z / 50;

				//
				// Now project along the motion vector
				//

				creation_distance = frand1 () * 8;
				x += creation_vector.x * creation_distance;
				y += creation_vector.y * creation_distance;
				z += creation_vector.z * creation_distance;

				//
				// Rotate this back into the view coordinate system
				//

				rain_3d_drops[count].current_position.x = x * view_attitude[0][0] + y * view_attitude[1][0] + z * view_attitude[2][0];
				rain_3d_drops[count].current_position.y = x * view_attitude[0][1] + y * view_attitude[1][1] + z * view_attitude[2][1];
				rain_3d_drops[count].current_position.z = x * view_attitude[0][2] + y * view_attitude[1][2] + z * view_attitude[2][2];

				rain_3d_drops[count].current_position.x += visual_3d_vp->x;
				rain_3d_drops[count].current_position.y += visual_3d_vp->y;
				rain_3d_drops[count].current_position.z += visual_3d_vp->z;

				rain_3d_drops[count].type = RAINDROP_RAIN;

				rain_3d_raindrops_valid++;
			}
			else if ( rain_3d_snowdrops_valid < total_snowdrop_number )
			{

				float
					x,
					y,
					z,
					creation_distance;

				//
				// Generate a new snowdrop
				//

				z = ( ( frand1 () * 0.8 ) + 0.2 ) * ( SNOWDROPS_AREA_DEPTH / 5 );
				x = sfrand1 () * ( SNOWDROPS_AREA_WIDTH / 5 );
				y = sfrand1 () * ( SNOWDROPS_AREA_HEIGHT / 5 );

				x *= z / 50;
				y *= z / 50;

				//
				// Now project along the motion vector
				//

				creation_distance = frand1 () * 8;
				x += creation_vector.x * creation_distance;
				y += creation_vector.y * creation_distance;
				z += creation_vector.z * creation_distance;

				//
				// Rotate this back into the view coordinate system
				//

				rain_3d_drops[count].current_position.x = x * view_attitude[0][0] + y * view_attitude[1][0] + z * view_attitude[2][0];
				rain_3d_drops[count].current_position.y = x * view_attitude[0][1] + y * view_attitude[1][1] + z * view_attitude[2][1];
				rain_3d_drops[count].current_position.z = x * view_attitude[0][2] + y * view_attitude[1][2] + z * view_attitude[2][2];

				rain_3d_drops[count].current_position.x += visual_3d_vp->x;
				rain_3d_drops[count].current_position.y += visual_3d_vp->y;
				rain_3d_drops[count].current_position.z += visual_3d_vp->z;

				rain_3d_drops[count].relative_speed = ( frand1() * 0.5 ) + 0.5;

				rain_3d_drops[count].type = RAINDROP_SNOW;

				rain_3d_snowdrops_valid++;
			}
		}
	}

	//
	// Now calculate the predicted positions for rendering
	//

	for ( count = 0; count < TOTAL_3D_RAINDROPS; count++ )
	{

		if ( rain_3d_drops[count].type == RAINDROP_RAIN )
		{

			rain_3d_drops[count].predicted_position.x = rain_3d_drops[count].current_position.x - rain_streak_displacement.x;
			rain_3d_drops[count].predicted_position.y = rain_3d_drops[count].current_position.y - rain_streak_displacement.y;
			rain_3d_drops[count].predicted_position.z = rain_3d_drops[count].current_position.z - rain_streak_displacement.z;
		}
	}
}
예제 #10
0
파일: ki_dam.c 프로젝트: Comanche93/eech
void partially_repair_kiowa_damage (void)
{
	fire_extinguisher_used = FALSE;

	////////////////////////////////////////

	if (kiowa_damage.flir)
	{
		kiowa_damage.flir = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (kiowa_damage.dtv)
	{
		kiowa_damage.dtv = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (kiowa_damage.laser_designator)
	{
		kiowa_damage.laser_designator = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (kiowa_damage.infra_red_jammer)
	{
		kiowa_damage.infra_red_jammer = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (kiowa_damage.navigation_computer)
	{
		kiowa_damage.navigation_computer = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (kiowa_damage.communications)
	{
		kiowa_damage.communications = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (kiowa_damage.radar_warning_system)
	{
		kiowa_damage.radar_warning_system = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (kiowa_damage.co_pilot_main_mfd)
	{
		kiowa_damage.co_pilot_main_mfd = frand1 () > 0.90;

		if (!kiowa_damage.co_pilot_main_mfd)
		{
			select_kiowa_main_mfd_mode (KIOWA_MAIN_MFD_MODE_OFF, KIOWA_MAIN_MFD_LOCATION_CO_PILOT);
		}
	}

	////////////////////////////////////////

	if (kiowa_damage.pilot_main_mfd)
	{
		kiowa_damage.pilot_main_mfd = frand1 () > 0.90;

		if (!kiowa_damage.pilot_main_mfd)
		{
			select_kiowa_main_mfd_mode (KIOWA_MAIN_MFD_MODE_OFF, KIOWA_MAIN_MFD_LOCATION_PILOT);
		}
	}

	////////////////////////////////////////

	if (kiowa_damage.center_main_mfd)
	{
		kiowa_damage.center_main_mfd = frand1 () > 0.90;

		if (!kiowa_damage.center_main_mfd)
		{
			select_kiowa_main_mfd_mode (KIOWA_MAIN_MFD_MODE_OFF, KIOWA_MAIN_MFD_LOCATION_CENTER);
		}
	}

	////////////////////////////////////////

	if (kiowa_damage.pnvs)
	{
		kiowa_damage.pnvs = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (kiowa_damage.lh_pylon)
	{
		kiowa_damage.lh_pylon = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (kiowa_damage.rh_pylon)
	{
		kiowa_damage.rh_pylon = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (kiowa_damage.chaff_dispenser)
	{
		kiowa_damage.chaff_dispenser = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (kiowa_damage.flare_dispenser)
	{
		kiowa_damage.flare_dispenser = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (kiowa_damage.hud)
	{
		kiowa_damage.hud = frand1 () > 0.90;
	}

	////////////////////////////////////////

	set_kiowa_weapon_damage_status ();
}
예제 #11
0
파일: setup.c 프로젝트: DexterWard/comanche
void create_force_campaign_objectives (entity *force)
{
	entity
		*keysite,
		*target_force,
		**list;

	int
		loop,
		count,
		side,
		target_side;

	float
		highest,
		*rating;

	ASSERT (get_comms_model () == COMMS_MODEL_SERVER);

	ASSERT (get_session_entity ());

	ASSERT (force);

	side = get_local_entity_int_value (force, INT_TYPE_SIDE);

	//
	// count up potential objective keysites
	//

	count = 0;

	target_force = get_local_entity_first_child (get_session_entity (), LIST_TYPE_FORCE);

	while (target_force)
	{
		if (target_force != force)
		{
			keysite = get_local_entity_first_child (target_force, LIST_TYPE_KEYSITE_FORCE);

			while (keysite)
			{
				if (get_local_entity_int_value (keysite, INT_TYPE_POTENTIAL_CAMPAIGN_OBJECTIVE))
				{
					if (get_local_entity_int_value (keysite, INT_TYPE_IN_USE))
					{
						count ++;
					}
				}

				keysite = get_local_entity_child_succ (keysite, LIST_TYPE_KEYSITE_FORCE);
			}
		}

		target_force = get_local_entity_child_succ (target_force, LIST_TYPE_FORCE);
	}

	if (count == 0)
	{
		debug_fatal ("SETUP: No potential campaign objectives for side %s", entity_side_short_names [side]);
	}

	//
	// construct the list and rate each keysite according to sector importance
	//

	list = malloc_heap_mem (sizeof (entity *) * count);

	rating = malloc_heap_mem (sizeof (float) * count);

	highest = 0.0;

	count = 0;

	target_force = get_local_entity_first_child (get_session_entity (), LIST_TYPE_FORCE);

	while (target_force)
	{
		if (target_force != force)
		{
			target_side = get_local_entity_int_value (target_force, INT_TYPE_SIDE);

			keysite = get_local_entity_first_child (target_force, LIST_TYPE_KEYSITE_FORCE);

			while (keysite)
			{
				if (get_local_entity_int_value (keysite, INT_TYPE_POTENTIAL_CAMPAIGN_OBJECTIVE))
				{
					if (get_local_entity_int_value (keysite, INT_TYPE_IN_USE))
					{
						float
							actual_range;
	
						vec3d
							*pos;
	
						list [count] = keysite;
	
						pos = get_local_entity_vec3d_ptr (keysite, VEC3D_TYPE_POSITION);
	
						get_closest_keysite (NUM_ENTITY_SUB_TYPE_KEYSITES, target_side, pos, 1.0 * KILOMETRE, &actual_range, keysite);
	
						rating [count] = actual_range;
	
						highest = max (highest, rating [count]);
		
						count ++;
					}
				}

				keysite = get_local_entity_child_succ (keysite, LIST_TYPE_KEYSITE_FORCE);
			}
		}

		target_force = get_local_entity_child_succ (target_force, LIST_TYPE_FORCE);
	}

	//
	// Normalise ratings
	//

	if (highest == 0.0)
	{
		debug_fatal ("SETUP: No sector importance for side %s", entity_side_short_names [side]);
	}
	
	for (loop = 0; loop < count; loop ++)
	{
		rating [loop] = rating [loop] / highest;
	}

	//
	// obligatory random factor
	//

	for (loop = 0; loop < count; loop ++)
	{
		rating [loop] += frand1 ();
	}

	//
	// sort the list
	//

	quicksort_entity_list (list, count, rating);

	//
	// now find the best N targets and link them into the force
	//

	count = min (count, NUMBER_OF_CAMPAIGN_OBJECTIVES_PER_SIDE);

	for (loop = 0; loop < count; loop ++)
	{
		insert_local_entity_into_parents_child_list (list [loop], LIST_TYPE_CAMPAIGN_OBJECTIVE, force, NULL);

		debug_log ("Side %s Objective :- %s (%s)", entity_side_short_names [side],
						get_local_entity_string (list [loop], STRING_TYPE_KEYSITE_NAME),
						get_local_entity_string (list [loop], STRING_TYPE_FULL_NAME));
	}

	free_mem (list);

	free_mem (rating);
}
예제 #12
0
파일: engage.c 프로젝트: Comanche93/eech
entity *create_engage_task (entity *group, entity *objective, entity *originator, int expire)
{
	entity
		*force_en,
		*new_task;

	force
		*force_raw;

	vec3d
		*pos;

	entity_sides
		side;

	float
		expire_time;

	formation_types
		original_formation;

	ASSERT (group);

	ASSERT (get_local_entity_int_value (group, INT_TYPE_ENGAGE_ENEMY));

	ASSERT (objective);

	#if DEBUG_MODULE
	
	debug_log ("ENGAGE: Trying to engage against %s (%d)",
									get_local_entity_string (objective, STRING_TYPE_FULL_NAME),
									get_local_entity_index (objective));

	#endif

	ASSERT ((get_local_entity_int_value (objective, INT_TYPE_IDENTIFY_AIRCRAFT)) ||
				(get_local_entity_int_value (objective, INT_TYPE_IDENTIFY_VEHICLE)) ||
				(get_local_entity_int_value (objective, INT_TYPE_IDENTIFY_FIXED)));

	if (get_local_entity_int_value (get_session_entity (), INT_TYPE_SUPPRESS_AI_FIRE))
	{
		return NULL;
	}

	force_en = get_local_force_entity ((entity_sides)get_local_entity_int_value (group, INT_TYPE_SIDE));

	force_raw = (force*) get_local_entity_data (force_en);

	if (expire)
	{
		expire_time = (2.0 * ONE_MINUTE) + (frand1 () * ONE_MINUTE);
	}
	else
	{
		//
		// Max time for ENGAGE - stops attackers hanging around target area for too long (especially if they can NEVER get to their target)
		//
		
		expire_time = (15.0 * ONE_MINUTE) + (frand1 () * 5.0 * ONE_MINUTE);
	}

	new_task = NULL;

	//
	// Create engage task to expire in task_time seconds - debug
	//

	side = (entity_sides) get_local_entity_int_value (group, INT_TYPE_SIDE);

	pos = get_local_entity_vec3d_ptr (objective, VEC3D_TYPE_POSITION);

	ASSERT (get_local_entity_first_child (group, LIST_TYPE_MEMBER));

	original_formation = FORMATION_ROW_LEFT;

	new_task = create_task (ENTITY_SUB_TYPE_TASK_ENGAGE,
									side,
									(movement_types) get_local_entity_int_value (group, INT_TYPE_MOVEMENT_TYPE),
									NULL,
									NULL,
									originator,
									TRUE,
									expire_time,
									0.0,
									objective,
									task_database [ENTITY_SUB_TYPE_TASK_ENGAGE].task_priority,
									pos, objective, ENTITY_SUB_TYPE_WAYPOINT_TARGET, original_formation,
									&terminator_point, NULL, NUM_ENTITY_SUB_TYPE_WAYPOINTS, FORMATION_NONE);

	#if DEBUG_MODULE
	
	debug_log ("ENGAGE: Created Engage task against %s (%d)",
									get_local_entity_string (objective, STRING_TYPE_FULL_NAME),
									get_local_entity_index (objective));

	#endif

	return new_task;
}
예제 #13
0
static entity *find_matching_entity (camera *raw, entity_forces force, entity_sides side, motion_states state)
{
    entity
    *this_entity,
    *best_entity;

    float
    this_score,
    best_score,
    view_interest_level;

    ASSERT (raw);

    this_entity = raw->view_root.first_child;

    best_entity = NULL;

    best_score = -1.0;

    while (this_entity)
    {
        if (get_entity_available_from_view_menu (this_entity))
        {
            this_score = 0.0;

            if (get_local_entity_int_value (this_entity, INT_TYPE_ALIVE))
            {
                if ((force == ENTITY_FORCE_UNKNOWN) || (get_local_entity_int_value (this_entity, INT_TYPE_FORCE) == force))
                {
                    this_score += 1.0;
                }

                ////////////////////////////////////////

                if ((side == ENTITY_SIDE_NEUTRAL) || (get_local_entity_int_value (this_entity, INT_TYPE_SIDE) == side))
                {
                    this_score += 1.0;
                }

                ////////////////////////////////////////

                if (state == MOTION_STATE_DONT_CARE)
                {
                    this_score += 1.0;
                }
                else if ((state == MOTION_STATE_STATIC) && (get_local_entity_vec3d_magnitude (this_entity, VEC3D_TYPE_MOTION_VECTOR) < 1.0))
                {
                    this_score += 1.0;
                }
                else if ((state == MOTION_STATE_MOVING) && (get_local_entity_vec3d_magnitude (this_entity, VEC3D_TYPE_MOTION_VECTOR) >= 1.0))
                {
                    this_score += 1.0;
                }

                ////////////////////////////////////////

                view_interest_level = get_local_entity_float_value (this_entity, FLOAT_TYPE_VIEW_INTEREST_LEVEL);

                view_interest_level = bound (view_interest_level, 0.0, DEFAULT_VIEW_INTEREST_LEVEL);

                view_interest_level *= (2.0 / DEFAULT_VIEW_INTEREST_LEVEL);

                this_score += view_interest_level;

                ////////////////////////////////////////

                this_score += frand1 ();
            }

            if (this_score > best_score)
            {
                best_score = this_score;

                best_entity = this_entity;
            }

            ////////////////////////////////////////
        }

        this_entity = get_local_entity_child_succ (this_entity, LIST_TYPE_VIEW);
    }

    return (best_entity);
}
예제 #14
0
static entity *get_best_view_entity (camera *raw)
{
    entity
    *en;

    entity_forces
    force;

    entity_sides
    side;

    motion_states
    state;

    float
    x;

    ASSERT (raw);

    ////////////////////////////////////////
    //
    // force
    //
    ////////////////////////////////////////

    x = frand1 ();

    if (x <= 0.6)
    {
        force = ENTITY_FORCE_AIR;
    }
    else if (x <= 0.9)
    {
        force = ENTITY_FORCE_GROUND;
    }
    else
    {
        force = ENTITY_FORCE_SEA;
    }

    ////////////////////////////////////////
    //
    // side
    //
    ////////////////////////////////////////

    x = frand1 ();

    if (x <= 0.5)
    {
        side = ENTITY_SIDE_BLUE_FORCE;
    }
    else
    {
        side = ENTITY_SIDE_RED_FORCE;
    }

    ////////////////////////////////////////
    //
    // motion state
    //
    ////////////////////////////////////////

    x = frand1 ();

    if (x <= 0.333)
    {
        state = MOTION_STATE_STATIC;
    }
    else
    {
        state = MOTION_STATE_MOVING;
    }

    ////////////////////////////////////////
    //
    // find ideal entity, if not, relax parameters until something is found
    //
    ////////////////////////////////////////

    en = find_matching_entity (raw, force, side, state);

    if (!en)
    {
        en = find_matching_entity (raw, force, side, MOTION_STATE_DONT_CARE);

        if (!en)
        {
            en = find_matching_entity (raw, force, ENTITY_SIDE_NEUTRAL, MOTION_STATE_DONT_CARE);

            if (!en)
            {
                en = find_matching_entity (raw, ENTITY_FORCE_UNKNOWN, ENTITY_SIDE_NEUTRAL, MOTION_STATE_DONT_CARE);
            }
        }
    }

    return (en);
}
예제 #15
0
파일: ac_msgs.c 프로젝트: Comanche93/eech
static int response_to_guide_cover_position_reached (entity_messages message, entity *receiver, entity *sender, va_list pargs)
{
	entity
		*aggressor;
		
	float
		silence_timer;
		
	ASSERT (sender);

	ASSERT (get_local_entity_type (sender) == ENTITY_TYPE_GUIDE);

	ASSERT (get_local_entity_int_value (receiver, INT_TYPE_GROUP_LEADER));

	if (get_local_entity_int_value (receiver, INT_TYPE_PLAYER) == ENTITY_PLAYER_AI)
	{
		//
		// AI group leader notifies sender to fire straight away (PLAYER group leader must use radio message)
		//

		attack_guide_proceed_to_fire_positon (sender);

		return (TRUE);
	}

	aggressor = get_local_entity_first_child (sender, LIST_TYPE_FOLLOWER);

	ASSERT (aggressor);

	ASSERT (get_local_entity_int_value (aggressor, INT_TYPE_IDENTIFY_AIRCRAFT));

	if (!get_local_entity_int_value (aggressor, INT_TYPE_WEAPONS_HOLD))
	{
		//
		// If the aggressor is in weapons free mode, then he does not have to wait for the player's notification
		//

		attack_guide_proceed_to_fire_positon (sender);

		return (TRUE);
	}

	//
	// Play Speech
	//

	silence_timer = 15.0 + (frand1 () * 12.0);

	play_client_server_wingman_message
	(
		aggressor,
		0.8,
		1.5,
		SPEECH_CATEGORY_IN_POSITION,
		silence_timer,
		SPEECH_INTRODUCTION_ALWAYS,
		SPEECH_ARRAY_WINGMAN_MESSAGES,
		SPEECH_WINGMAN_IN_POSITION
	);

	return (TRUE);
}
예제 #16
0
void partially_repair_apache_damage (void)
{
	set_apache_upfront_display_text ("", "", NULL, NULL);

	fire_extinguisher_used = FALSE;

	////////////////////////////////////////

	if (apache_damage.radar)
	{
		apache_damage.radar = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (apache_damage.flir)
	{
		apache_damage.flir = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (apache_damage.dtv)
	{
		apache_damage.dtv = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (apache_damage.dvo)
	{
		apache_damage.dvo = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (apache_damage.laser_designator)
	{
		apache_damage.laser_designator = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (apache_damage.radar_jammer)
	{
		apache_damage.radar_jammer = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (apache_damage.infra_red_jammer)
	{
		apache_damage.infra_red_jammer = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (apache_damage.navigation_computer)
	{
		apache_damage.navigation_computer = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (apache_damage.communications)
	{
		apache_damage.communications = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (apache_damage.radar_warning_system)
	{
		apache_damage.radar_warning_system = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (apache_damage.ihadss)
	{
		apache_damage.ihadss = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (apache_damage.lh_mfd)
	{
		apache_damage.lh_mfd = frand1 () > 0.90;

		if (!apache_damage.lh_mfd)
		{
			select_apache_mfd_mode (MFD_MODE_OFF, MFD_LOCATION_LHS);
		}
	}

	////////////////////////////////////////

	if (apache_damage.rh_mfd)
	{
		apache_damage.rh_mfd = frand1 () > 0.90;

		if (!apache_damage.rh_mfd)
		{
			select_apache_mfd_mode (MFD_MODE_OFF, MFD_LOCATION_RHS);
		}
	}

	////////////////////////////////////////

	if (apache_damage.pnvs)
	{
		apache_damage.pnvs = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (apache_damage.gun_jammed)
	{
		apache_damage.gun_jammed = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (apache_damage.lh_wing_tip_mount)
	{
		apache_damage.lh_wing_tip_mount = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (apache_damage.lh_outer_pylon)
	{
		apache_damage.lh_outer_pylon = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (apache_damage.lh_inner_pylon)
	{
		apache_damage.lh_inner_pylon = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (apache_damage.rh_wing_tip_mount)
	{
		apache_damage.rh_wing_tip_mount = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (apache_damage.rh_outer_pylon)
	{
		apache_damage.rh_outer_pylon = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (apache_damage.rh_inner_pylon)
	{
		apache_damage.rh_inner_pylon = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (apache_damage.chaff_dispenser)
	{
		apache_damage.chaff_dispenser = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (apache_damage.flare_dispenser)
	{
		apache_damage.flare_dispenser = frand1 () > 0.90;
	}

	////////////////////////////////////////

	set_apache_weapon_damage_status ();
}
예제 #17
0
void update_aircraft_decoy_release (entity *en)
{
	aircraft
		*raw;

	int
		chaff_available,
		flare_available,
		chaff_released,
		flare_released;

	float
		range,
		velocity,
		time_to_impact;

	entity_sub_types
		weapon_sub_type;

	entity
		*persuer;

	vec3d
		*target_position,
		*weapon_position;

	ASSERT (en);

	#ifdef DEBUG

	if (get_comms_model () == COMMS_MODEL_CLIENT)
	{
		ASSERT (en == get_gunship_entity ());
	}

	#endif

	raw = get_local_entity_data (en);

	////////////////////////////////////////
	//
	// update timer
	//
	////////////////////////////////////////

	raw->decoy_release_timer -= get_delta_time ();

	if (raw->decoy_release_timer >= 0.0)
	{
		return;
	}

	raw->decoy_release_timer = 2.0 + frand1 ();

	////////////////////////////////////////
	//
	// validate
	//
	////////////////////////////////////////

	if (en == get_gunship_entity ())
	{
		if (!get_global_auto_counter_measures ())
		{
			return;
		}
	}
	else if (get_local_entity_int_value (en, INT_TYPE_PLAYER) != ENTITY_PLAYER_AI)
	{
		return;
	}

	if (!get_local_entity_int_value (en, INT_TYPE_AIRBORNE_AIRCRAFT))
	{
		return;
	}

	persuer = get_local_entity_first_child (en, LIST_TYPE_TARGET);

	if (!persuer)
	{
		return;
	}

	chaff_available = get_local_entity_weapon_available (en, ENTITY_SUB_TYPE_WEAPON_CHAFF);

	flare_available = get_local_entity_weapon_available (en, ENTITY_SUB_TYPE_WEAPON_FLARE);

	if (!(chaff_available || flare_available))
	{
		return;
	}

	////////////////////////////////////////
	//
	// check all persuers
	//
	////////////////////////////////////////

	target_position = get_local_entity_vec3d_ptr (en, VEC3D_TYPE_POSITION);

	chaff_released = FALSE;
	flare_released = FALSE;

	while (persuer)
	{
		if (get_local_entity_type (persuer) == ENTITY_TYPE_WEAPON)
		{
			if (get_local_entity_int_value (persuer, INT_TYPE_WEAPON_GUIDANCE_TYPE) != WEAPON_GUIDANCE_TYPE_NONE)
			{
				weapon_sub_type = get_decoy_type_for_weapon (persuer);

				if (weapon_sub_type == ENTITY_SUB_TYPE_WEAPON_CHAFF)
				{
					if (chaff_available)
					{
						if (!chaff_released)
						{
							weapon_position = get_local_entity_vec3d_ptr (persuer, VEC3D_TYPE_POSITION);

							range = get_approx_3d_range (weapon_position, target_position);

							velocity = get_local_entity_float_value (persuer, FLOAT_TYPE_VELOCITY);

							time_to_impact = range / max (velocity, 1.0);

							if (time_to_impact < 10.0)
							{
								launch_client_server_weapon (en, ENTITY_SUB_TYPE_WEAPON_CHAFF);

								chaff_released = TRUE;

								if (flare_released)
								{
									break;
								}
							}
						}
					}
				}
				else if (weapon_sub_type == ENTITY_SUB_TYPE_WEAPON_FLARE)
				{
					if (flare_available)
					{
						if (!flare_released)
						{
							weapon_position = get_local_entity_vec3d_ptr (persuer, VEC3D_TYPE_POSITION);

							range = get_approx_3d_range (weapon_position, target_position);

							velocity = get_local_entity_float_value (persuer, FLOAT_TYPE_VELOCITY);

							time_to_impact = range / max (velocity, 1.0);

							if (time_to_impact < 10.0)
							{
								launch_client_server_weapon (en, ENTITY_SUB_TYPE_WEAPON_FLARE);

								flare_released = TRUE;

								if (chaff_released)
								{
									break;
								}
							}
						}
					}
				}
			}
		}

		persuer = get_local_entity_child_succ (persuer, LIST_TYPE_TARGET);
	}
}
예제 #18
0
파일: downwash.c 프로젝트: Comanche93/eech
int create_downwash_effect_component(downwash_component *this_downwash_component, downwash_types downwash_type, vec3d *position, int *entity_index_list, float main_rotor_radius, float main_rotor_rpm, float min_altitude)
{
	int
		loop,
		count,
		terrain_type,
		trail_type;

	short int
		quadrant_x,
		quadrant_z;
	
	unsigned char
		alpha_percentage;

	float
		lifetime,
		lifetime_min,
		lifetime_max,
		scale_min,
		scale_max,
		scale,
		angle,
		radius,
		relative_radius,
		height,
		altitude,
		half_altitude,
		main_rotor_radius_minus_altitude;

	vec3d
		pos,
		offset,
		iv;

	terrain_3d_point_data
		terrain_info;

	entity
		*new_entity;

	memset (&terrain_info, 0, sizeof (terrain_3d_point_data));

	count = this_downwash_component->trail_count;

	if ( count < 1 )
	{
		return 0;
	}

	// Xhit: This is the altitude of the helicopter relative to the ground level. (030328)
	altitude = position->y - min_altitude;
	half_altitude = (altitude / 2.0);

	main_rotor_radius_minus_altitude = main_rotor_radius - altitude;

	scale_min = this_downwash_component->scale_min;
	scale_max = this_downwash_component->scale_max;

	lifetime_min = this_downwash_component->lifetime_min;
	lifetime_max = this_downwash_component->lifetime_max;

	// Xhit: initialising quadrant variables (030328)
	quadrant_x = 1;
	quadrant_z = 1;

	//
	// create smoke trails
	//

	for ( loop = 0 ; loop < count ; loop ++ )
	{
		lifetime = lifetime_min + fabs( ( lifetime_max - lifetime_min ) * sfrand1() );

		angle = frand1() * PI_OVER_TWO;

		relative_radius = main_rotor_radius * frand1();

		scale = relative_radius + scale_min;
		if(scale > scale_max)
				scale = scale_max;

		switch(downwash_type)
		{
			case DOWNWASH_TYPE_LAND:
			case DOWNWASH_TYPE_LAND_DUAL_ROTORS:
			{
				//Xhit: If altitude bigger than main rotor radius then the smoke should be centered beneath the helicopter. (030328)
				if(altitude >= main_rotor_radius)
				{
					radius = relative_radius;
					height = (half_altitude * (radius / main_rotor_radius) + half_altitude) * frand1();
			
				}else
				{
					radius = relative_radius + main_rotor_radius_minus_altitude;
					height = (half_altitude * ((radius - main_rotor_radius_minus_altitude) / main_rotor_radius) + half_altitude + scale ) * frand1();
				}
				break;
			}
			case DOWNWASH_TYPE_WATER:
			case DOWNWASH_TYPE_WATER_DUAL_ROTORS:
			{
				if(altitude >= main_rotor_radius)
				{
					radius = relative_radius;
			
				}else
				{
					radius = relative_radius + main_rotor_radius_minus_altitude;
				}

				// Xhit: Changed to 2 instead of main_rotor_radius so smoke is created just over water level (030515)
				height =  2 * frand1();
				break;
			}
			default:
			{
				debug_fatal("DOWNWASH : trying to create an unrecogniseable downwash effect");
				break;
			}
		}


		//Xhit: If main rotor(s) only (not displaced main rotors) then. (030328)
		if((this_downwash_component->create_in_all_quadrants) && (loop < 4))
		{
			//Xhit:	This cryptical thing is to determine in which quadrant this sprite is going to be created. (030328)
			//		 ^z
			//		 |
			//		1|0  x
			//		-+--->
			//		3|2
			//
			//		loop = 0 -> x=	1,	z=	1; loop = 1 -> x=	-1, z=	 1;
			//		loop = 2 -> x=   1,	z= -1; loop = 3 -> x=	-1, z=	-1;
			quadrant_x = 1 | -(loop & 1);
			quadrant_z = 1 | -(loop & 2);
						
			offset.x = quadrant_x * radius * ( cos ( angle ) );
			offset.y = height;
			offset.z = quadrant_z * radius * ( sin ( angle ) );

		}else
		//Xhit:	If scattered downwash effect and if the heli got more than one main rotor (on different axis) then 
		//			add two more trails at the sides of the heli. (030328)
		if((this_downwash_component->create_in_all_quadrants) && (loop >= 4) && (count == 6))
		{
			//Xhit: loop = 4 -> x=	1; loop = 5 -> x=	-1; (030328)
			quadrant_x = 1 | -(loop & 1);

			relative_radius = main_rotor_radius * frand1();

			offset.x = quadrant_x * radius;
			offset.y = height;
			offset.z = frand1() * (main_rotor_radius / 2);
		}else
		{
			debug_fatal("DOWNWASH : trying to create an unrecogniseable downwash effect");
		}

		pos.x = position->x + offset.x ;
		pos.z = position->z + offset.z;

		//Xhit: This is necessary if it's going to work on tilting terrain. (030328)
		get_3d_terrain_point_data (pos.x, pos.z, &terrain_info);
		pos.y = get_3d_terrain_point_data_elevation (&terrain_info);

		pos.y = pos.y + offset.y;

		bound_position_to_map_volume( &pos );

		//Xhit: Decide which trail type is going to be used, this makes mapping to type of downwash effect fast. (030328)
		terrain_type = get_3d_terrain_point_data_type(&terrain_info);
		trail_type = get_terrain_surface_type(terrain_type) + SMOKE_LIST_TYPE_DOWNWASH_START;

		#if DEBUG_MODULE
		
		debug_log("DOWNWASH.C: terrain_type: %d, trail_type: %d", terrain_type, trail_type);

		#endif		

		iv.x = pos.x - position->x;
		iv.y = relative_radius;
		iv.z = pos.z - position->z;

		//Xhit:	If heli on ground then let the dust-smoke fade in according to increasing main_rotor_rpm
		//		otherwise set it according to the altitude of the heli (higher = less dust smoke) (030328)
		if(altitude < 1.0)
		{
			alpha_percentage = (unsigned char)(main_rotor_rpm);
		}else
		{
			//Xhit: "+ 1.0" is to guarantee that alpha_percentage > 0. (030328)
			alpha_percentage = (unsigned char)((1.0 - (altitude / (DOWNWASH_EFFECT_MAX_ALTITUDE + 1.0))) * 100);
		}

		new_entity = create_local_entity
		(
			ENTITY_TYPE_SMOKE_LIST,
			entity_index_list[ loop ],
			ENTITY_ATTR_INT_VALUE (INT_TYPE_ENTITY_SUB_TYPE, ENTITY_SUB_TYPE_EFFECT_SMOKE_LIST_DOWNWASH),
			ENTITY_ATTR_INT_VALUE (INT_TYPE_SMOKE_TYPE, trail_type),
			ENTITY_ATTR_INT_VALUE (INT_TYPE_COLOUR_ALPHA, alpha_percentage),
			ENTITY_ATTR_FLOAT_VALUE (FLOAT_TYPE_GENERATOR_LIFETIME, this_downwash_component->generator_lifetime),
			ENTITY_ATTR_FLOAT_VALUE (FLOAT_TYPE_FREQUENCY, this_downwash_component->frequency),
			ENTITY_ATTR_FLOAT_VALUE (FLOAT_TYPE_SMOKE_LIFETIME, lifetime),
			ENTITY_ATTR_FLOAT_VALUE (FLOAT_TYPE_SCALE, scale),
			ENTITY_ATTR_VEC3D (VEC3D_TYPE_INITIAL_VELOCITY, iv.x, iv.y, iv.z),
			ENTITY_ATTR_VEC3D (VEC3D_TYPE_POSITION, pos.x, pos.y, pos.z),
			ENTITY_ATTR_END
		);

		entity_index_list[ loop ] = get_local_entity_index( new_entity );
	}

	return count;
}
예제 #19
0
void partially_repair_havoc_damage (void)
{
	set_havoc_ekran_display_text ("", "", NULL, NULL);

	fire_extinguisher_used = FALSE;

	////////////////////////////////////////

	if (havoc_damage.radar)
	{
		havoc_damage.radar = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (havoc_damage.flir)
	{
		havoc_damage.flir = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (havoc_damage.llltv)
	{
		havoc_damage.llltv = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (havoc_damage.laser_range_finder)
	{
		havoc_damage.laser_range_finder = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (havoc_damage.radar_jammer)
	{
		havoc_damage.radar_jammer = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (havoc_damage.infra_red_jammer)
	{
		havoc_damage.infra_red_jammer = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (havoc_damage.navigation_computer)
	{
		havoc_damage.navigation_computer = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (havoc_damage.communications)
	{
		havoc_damage.communications = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (havoc_damage.radar_warning_system)
	{
		havoc_damage.radar_warning_system = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (havoc_damage.head_up_display)
	{
		havoc_damage.head_up_display = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (havoc_damage.helmet_mounted_sight)
	{
		havoc_damage.helmet_mounted_sight = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (havoc_damage.tv_display)
	{
		havoc_damage.tv_display = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (havoc_damage.threat_warning_display)
	{
		havoc_damage.threat_warning_display = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (havoc_damage.night_vision_goggles)
	{
		havoc_damage.night_vision_goggles = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (havoc_damage.gun_jammed)
	{
		havoc_damage.gun_jammed = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (havoc_damage.lh_outer_pylon)
	{
		havoc_damage.lh_outer_pylon = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (havoc_damage.lh_inner_pylon)
	{
		havoc_damage.lh_inner_pylon = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (havoc_damage.rh_outer_pylon)
	{
		havoc_damage.rh_outer_pylon = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (havoc_damage.rh_inner_pylon)
	{
		havoc_damage.rh_inner_pylon = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (havoc_damage.chaff_dispenser)
	{
		havoc_damage.chaff_dispenser = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (havoc_damage.flare_dispenser)
	{
		havoc_damage.flare_dispenser = frand1 () > 0.90;
	}

	////////////////////////////////////////

	set_havoc_weapon_damage_status ();
}
예제 #20
0
파일: hm_dam.c 프로젝트: Comanche93/eech
void partially_repair_ka50_damage (void)
{
	set_ka50_text_display_text ("", "", "");

	fire_extinguisher_used = FALSE;

	////////////////////////////////////////

	if (ka50_damage.flir)
	{
		ka50_damage.flir = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (ka50_damage.laser_designator)
	{
		ka50_damage.laser_designator = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (ka50_damage.radar_jammer)
	{
		ka50_damage.radar_jammer = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (ka50_damage.infra_red_jammer)
	{
		ka50_damage.infra_red_jammer = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (ka50_damage.navigation_computer)
	{
		ka50_damage.navigation_computer = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (ka50_damage.communications)
	{
		ka50_damage.communications = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (ka50_damage.radar_warning_system)
	{
		ka50_damage.radar_warning_system = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (ka50_damage.head_up_display)
	{
		ka50_damage.head_up_display = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (ka50_damage.helmet_mounted_sight)
	{
		ka50_damage.helmet_mounted_sight = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (ka50_damage.shkval_mfd)
	{
		ka50_damage.shkval_mfd = frand1 () > 0.90;

		if (!ka50_damage.shkval_mfd)
		{
			select_ka50_mfd_mode (KA50_MFD_MODE_OFF, KA50_MFD_LOCATION_SHKVAL);
		}
	}

	////////////////////////////////////////

	if (ka50_damage.abris_mfd)
	{
		ka50_damage.abris_mfd = frand1 () > 0.90;

		if (!ka50_damage.abris_mfd)
		{
			select_ka50_mfd_mode (KA50_MFD_MODE_OFF, KA50_MFD_LOCATION_ABRIS);
		}
	}

	////////////////////////////////////////

	if (ka50_damage.night_vision_goggles)
	{
		ka50_damage.night_vision_goggles = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (ka50_damage.gun_jammed)
	{
		ka50_damage.gun_jammed = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (ka50_damage.lh_outer_pylon)
	{
		ka50_damage.lh_outer_pylon = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (ka50_damage.lh_inner_pylon)
	{
		ka50_damage.lh_inner_pylon = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (ka50_damage.rh_outer_pylon)
	{
		ka50_damage.rh_outer_pylon = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (ka50_damage.rh_inner_pylon)
	{
		ka50_damage.rh_inner_pylon = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (ka50_damage.lh_chaff_dispensers)
	{
		ka50_damage.lh_chaff_dispensers = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (ka50_damage.rh_chaff_dispensers)
	{
		ka50_damage.rh_chaff_dispensers = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (ka50_damage.lh_flare_dispensers)
	{
		ka50_damage.lh_flare_dispensers = frand1 () > 0.90;
	}

	////////////////////////////////////////

	if (ka50_damage.rh_flare_dispensers)
	{
		ka50_damage.rh_flare_dispensers = frand1 () > 0.90;
	}

	////////////////////////////////////////

	set_ka50_weapon_damage_status ();
}
예제 #21
0
static entity *create_local (entity_types type, int index, char *pargs)
{

	char
		 name [STRING_TYPE_KEYSITE_NAME_MAX_LENGTH];

	entity
		*group,
		*force,
		*sector,
		*en;

	keysite
		*raw;

	////////////////////////////////////////
  	//
  	// VALIDATE
  	//
	////////////////////////////////////////

	validate_local_create_entity_index (index);

	#if DEBUG_MODULE

	debug_log_entity_args (ENTITY_DEBUG_LOCAL, ENTITY_DEBUG_CREATE, NULL, type, index);

	#endif

	en = get_free_entity (index);

	if (en)
	{
		////////////////////////////////////////
   	//
   	// MALLOC ENTITY DATA
   	//
		////////////////////////////////////////

		set_local_entity_type (en, type);

		raw = malloc_fast_mem (sizeof (keysite));

		set_local_entity_data (en, raw);

		////////////////////////////////////////
   	//
   	// INITIALISE ALL ENTITY DATA TO 'WORKING' DEFAULT VALUES
		//
		// DO NOT USE ACCESS FUNCTIONS
		//
		// DO NOT USE RANDOM VALUES
		//
		////////////////////////////////////////

		memset (raw, 0, sizeof (keysite));

		sprintf (name, "KEYSITE %d", (int) en % 100);

		strncpy (raw->keysite_name, name, STRING_TYPE_KEYSITE_NAME_MAX_LENGTH);

		//
		// fixed
		//

		raw->position.x = MID_MAP_X;
		raw->position.y = MID_MAP_Y;
		raw->position.z = MID_MAP_Z;

		raw->alive = TRUE;

		raw->keysite_usable_state = KEYSITE_STATE_USABLE;

		raw->in_use = FALSE;
		raw->object_index = OBJECT_3D_INVALID_OBJECT_INDEX;

		raw->side = ENTITY_SIDE_NEUTRAL;

		raw->supplies.ammo_supply_level = 0.0;

		raw->supplies.fuel_supply_level = 0.0;

		raw->assign_timer = frand1 () * KEYSITE_TASK_ASSIGN_TIMER;		// SERVER ONLY - OK TO USE RANDOM

		raw->sleep = frand1 () * KEYSITE_UPDATE_SLEEP_TIMER;				// SERVER ONLY - OK TO USE RANDOM

		////////////////////////////////////////
		//
		// OVERWRITE DEFAULT VALUES WITH GIVEN ATTRIBUTES
		//
		////////////////////////////////////////

		set_local_entity_attributes (en, pargs);

		////////////////////////////////////////
		//
		// CHECK MANDATORY ATTRIBUTES HAVE BEEN GIVEN
		//
		////////////////////////////////////////

		ASSERT (raw->side != ENTITY_SIDE_NEUTRAL);

		ASSERT (entity_sub_type_keysite_valid (raw->sub_type));

		ASSERT (keysite_database [raw->sub_type].minimum_efficiency < 1.0);

		// the following is currently required for the campaign to progress properly...
		ASSERT (keysite_database [raw->sub_type].repairable == keysite_database [raw->sub_type].troop_insertion_target);

		////////////////////////////////////////
		//
		// RESOLVE DEFAULT VALUES
		//
		////////////////////////////////////////

		update_keysite_cargo (en, raw->supplies.ammo_supply_level, ENTITY_SUB_TYPE_CARGO_AMMO, CARGO_AMMO_SIZE);

		update_keysite_cargo (en, raw->supplies.fuel_supply_level, ENTITY_SUB_TYPE_CARGO_FUEL, CARGO_FUEL_SIZE);

		////////////////////////////////////////
		//
		// BUILD COMPONENTS
		//
		////////////////////////////////////////

		////////////////////////////////////////
		//
		// LINK INTO SYSTEM
		//
		////////////////////////////////////////

		force = get_local_entity_parent (en, LIST_TYPE_KEYSITE_FORCE);

		debug_assert (get_local_entity_type (force) == ENTITY_TYPE_FORCE);

		ASSERT (force);

		sector = get_local_sector_entity (&raw->position);

		ASSERT (sector);

		insert_local_entity_into_parents_child_list (en, LIST_TYPE_KEYSITE_FORCE, force, NULL);

		insert_local_entity_into_parents_child_list (en, LIST_TYPE_SECTOR, sector, NULL);

		insert_local_entity_into_parents_child_list (en, LIST_TYPE_UPDATE, get_update_entity (), NULL);

		set_local_entity_int_value (sector, INT_TYPE_KEYSITE_COUNT, get_local_entity_int_value (sector, INT_TYPE_KEYSITE_COUNT) + 1);

		if (raw->in_use)
		{
			update_imap_sector_side (en, TRUE);

			update_imap_importance_level (en, TRUE);

			update_keysite_distance_to_friendly_base (en, raw->side);
		}

		////////////////////////////////////////
		//
		//	CREATE SUB ENTITIES
		//
		////////////////////////////////////////

		// for site buildings

		group = create_local_entity
		(
			ENTITY_TYPE_GROUP,
			ENTITY_INDEX_DONT_CARE,
			ENTITY_ATTR_PARENT (LIST_TYPE_BUILDING_GROUP, en),
			ENTITY_ATTR_VEC3D (VEC3D_TYPE_POSITION, raw->position.x, raw->position.y, raw->position.z),
			ENTITY_ATTR_INT_VALUE (INT_TYPE_ENTITY_SUB_TYPE, ENTITY_SUB_TYPE_GROUP_BUILDINGS),
			ENTITY_ATTR_END
		);

		#if DEBUG_MODULE
		{
			int
				sx,
				sz;

			get_x_sector (sx, raw->position.x);
			get_z_sector (sz, raw->position.z);
			
			debug_log ("KS_CREAT: Side %s creating keysite %s (type %d) index %d at %f, %f (%d, %d)", entity_side_short_names [raw->side], raw->keysite_name, raw->sub_type, get_local_entity_index (en), raw->position.x, raw->position.z, sx, sz);
		}
		#endif
	}

	return (en);
}
예제 #22
0
파일: ss_updt.c 프로젝트: Comanche93/eech
void update_lightning_effect (entity *en)
{
	session
		*raw;

	int
		lightning_flag = FALSE;

	float
		new_time;

	ASSERT (en);

	raw = (session *) get_local_entity_data (en);

	if (get_comms_model () == COMMS_MODEL_SERVER)
	{
		//
		// SERVER : decrease timer, if timer reaches zero create a strike, and reset timer (c/s)
		//

		raw->lightning_timer -= get_delta_time ();

		if (raw->lightning_timer <= 0.0)
		{
			lightning_flag = TRUE;

			new_time = LIGHTNING_EFFECT_MINIMUM_TIMER + ((LIGHTNING_EFFECT_MAXIMUM_TIMER - LIGHTNING_EFFECT_MINIMUM_TIMER) * frand1 ());

			#if DEBUG_MODULES

			debug_log ("SS_UPDT : Set lightning timer %.2f", new_time);

			#endif

			set_client_server_entity_float_value (en, FLOAT_TYPE_LIGHTNING_TIMER, new_time);
		}
	}
	else
	{
		//
		// CLIENT : decrease timer only if non-zero and create strike if zero reached ( new timer will be set by server )
		//

		if (raw->lightning_timer > 0.0)
		{
			raw->lightning_timer -= get_delta_time ();

			if (raw->lightning_timer <= 0.0)
			{
				lightning_flag = TRUE;

				raw->lightning_timer = 0.0;
			}
		}
	}

	if (lightning_flag)
	{
		//
		// create lightning
		//

		env_3d
			*current_3d_env;

		current_3d_env = get_3d_active_environment ();

		if (current_3d_env == main_3d_env)
		{
			current_3d_env = NULL;
		}
		else
		{
			set_3d_active_environment (main_3d_env);
		}
		
		add_3d_lightning_strike (LIGHTNING_TYPE_CLOUD_BURST, 0.3, raw->weather_position.x, raw->weather_position.z);

		add_3d_lightning_strike (LIGHTNING_TYPE_FORKED_1, 0.3, raw->weather_position.x, raw->weather_position.z);

		if (current_3d_env)
		{
			set_3d_active_environment (current_3d_env);
		}

		if (get_comms_model () == COMMS_MODEL_SERVER)
		{
			sound_sample_indices
				sound_effect_index;

			//
			// lightning sound effect
			//

			sound_effect_index = SOUND_SAMPLE_INDEX_AMBIENT_LIGHTNING;

			create_client_server_sound_effect_entity
			(
				get_local_sector_entity (&(raw->weather_position)),
				ENTITY_SIDE_NEUTRAL,
				ENTITY_SUB_TYPE_EFFECT_SOUND_MISC,
				SOUND_CHANNEL_SOUND_EFFECT,
				SOUND_LOCALITY_ALL,
				&raw->weather_position,						// position
				1.0,												// amplification
				0.85+(0.3* frand1 ()), //pitch
				TRUE,												// valid sound effect
				FALSE,											// looping
				1,													// sample count
				&sound_effect_index							// sample index list
			);

			//
			// thunder sound effect
			//

			sound_effect_index = SOUND_SAMPLE_INDEX_AMBIENT_THUNDER;

			create_client_server_sound_effect_entity
			(
				get_local_sector_entity (&(raw->weather_position)),
				ENTITY_SIDE_NEUTRAL,
				ENTITY_SUB_TYPE_EFFECT_SOUND_MISC,
				SOUND_CHANNEL_SOUND_EFFECT,
				SOUND_LOCALITY_ALL,
				&raw->weather_position,						// position
				1.0,												// amplification
				0.85+(0.3* frand1 ()), //pitch
				TRUE,												// valid sound effect
				FALSE,											// looping
				1,													// sample count
				&sound_effect_index							// sample index list
			);
		}
	}
}
예제 #23
0
static entity *create_local (entity_types type, int index, char *pargs)
{
	entity
		*en;

	routed_vehicle
		*raw;

	entity_sub_types
		group_sub_type;

	float
		heading;

	vec3d
		*face_normal;

	////////////////////////////////////////
  	//
  	// VALIDATE
  	//
	////////////////////////////////////////

	validate_local_create_entity_index (index);

	#if DEBUG_MODULE

	debug_log_entity_args (ENTITY_DEBUG_LOCAL, ENTITY_DEBUG_CREATE, NULL, type, index);

	#endif

	en = get_free_entity (index);

	if (en)
	{
		////////////////////////////////////////
   	//
   	// MALLOC ENTITY DATA
   	//
		////////////////////////////////////////

		set_local_entity_type (en, type);

		raw = malloc_fast_mem (sizeof (routed_vehicle));

		set_local_entity_data (en, raw);

		////////////////////////////////////////
   	//
   	// INITIALISE ALL ENTITY DATA TO 'WORKING' DEFAULT VALUES
		//
		// DO NOT USE ACCESS FUNCTIONS
		//
		// DO NOT USE RANDOM VALUES
		//
		////////////////////////////////////////

		memset (raw, 0, sizeof (routed_vehicle));

		//
		// mobile
		//

		raw->vh.mob.sub_type = ENTITY_SUB_TYPE_UNINITIALISED;

		raw->vh.mob.position.x = MID_MAP_X;
		raw->vh.mob.position.y = MID_MAP_Y;
		raw->vh.mob.position.z = MID_MAP_Z;

		get_identity_matrix3x3 (raw->vh.mob.attitude);

		raw->vh.mob.alive = TRUE;

		raw->vh.mob.side = ENTITY_SIDE_UNINITIALISED;

		raw->vh.operational_state = OPERATIONAL_STATE_UNKNOWN;

		//
		// vehicle
		//

		raw->vh.object_3d_shape = OBJECT_3D_INVALID_OBJECT_INDEX;

		raw->vh.weapon_config_type = WEAPON_CONFIG_TYPE_UNINITIALISED;

		raw->vh.selected_weapon = ENTITY_SUB_TYPE_WEAPON_NO_WEAPON;

		raw->vh.weapon_vector.x = 0.0;
		raw->vh.weapon_vector.y = 0.0;
		raw->vh.weapon_vector.z = 1.0;

		raw->vh.weapon_to_target_vector.x = 0.0;
		raw->vh.weapon_to_target_vector.y = 0.0;
		raw->vh.weapon_to_target_vector.z = -1.0;

		raw->vh.loading_door_state = VEHICLE_LOADING_DOORS_OPEN_FLOAT_VALUE;

		//
		// routed
		//

		////////////////////////////////////////
		//
		// OVERWRITE DEFAULT VALUES WITH GIVEN ATTRIBUTES
		//
		////////////////////////////////////////

		set_local_entity_attributes (en, pargs);

		////////////////////////////////////////
		//
		// CHECK MANDATORY ATTRIBUTES HAVE BEEN GIVEN
		//
		////////////////////////////////////////

		ASSERT (raw->vh.member_link.parent);

		ASSERT (get_local_entity_type (raw->vh.member_link.parent) == ENTITY_TYPE_GROUP);

		////////////////////////////////////////
		//
		// RESOLVE DEFAULT VALUES
		//
		////////////////////////////////////////

		raw->sub_route = NULL;

		//
		// side
		//

		if (raw->vh.mob.side == ENTITY_SIDE_UNINITIALISED)
		{
			raw->vh.mob.side = get_local_entity_int_value (raw->vh.member_link.parent, INT_TYPE_SIDE);
		}

		ASSERT (raw->vh.mob.side != ENTITY_SIDE_NEUTRAL);

		//
		// sub_type
		//

		if (raw->vh.mob.sub_type == ENTITY_SUB_TYPE_UNINITIALISED)
		{
			group_sub_type = get_local_entity_int_value (raw->vh.member_link.parent, INT_TYPE_ENTITY_SUB_TYPE);

			if (raw->vh.mob.side == ENTITY_SIDE_BLUE_FORCE)
			{
				raw->vh.mob.sub_type = group_database[group_sub_type].default_blue_force_sub_type;
			}
			else
			{
				raw->vh.mob.sub_type = group_database[group_sub_type].default_red_force_sub_type;
			}
		}

		ASSERT (entity_sub_type_vehicle_valid (raw->vh.mob.sub_type));

		//
		// 3D shape
		//

		if (raw->vh.object_3d_shape == OBJECT_3D_INVALID_OBJECT_INDEX)
		{
			raw->vh.object_3d_shape = vehicle_database[raw->vh.mob.sub_type].default_3d_shape;
		}

		//
		// weapon config
		//

		if (raw->vh.weapon_config_type == WEAPON_CONFIG_TYPE_UNINITIALISED)
		{
			raw->vh.weapon_config_type = vehicle_database[raw->vh.mob.sub_type].default_weapon_config_type;
		}

		ASSERT (weapon_config_type_valid (raw->vh.weapon_config_type));

		//
		// damage levels
		//

		raw->vh.damage_level = vehicle_database[raw->vh.mob.sub_type].initial_damage_level;

		//
		// radar dish rotation (ok to use a random number as this is for visual effect only)
		//

		raw->vh.radar_rotation_state = frand1 ();

		////////////////////////////////////////
		//
		// BUILD COMPONENTS
		//
		////////////////////////////////////////

		//
		// 3D object
		//

		raw->vh.inst3d = construct_3d_object (raw->vh.object_3d_shape);

		set_routed_vehicle_id_number (en);

		set_initial_rotation_angle_of_routed_vehicle_wheels (raw->vh.inst3d);

		//
		// align with terrain
		//

		get_3d_terrain_point_data (raw->vh.mob.position.x, raw->vh.mob.position.z, &raw->vh.terrain_info);

		heading = get_heading_from_attitude_matrix (raw->vh.mob.attitude);

		face_normal = get_3d_terrain_point_data_normal (&raw->vh.terrain_info);

		get_3d_transformation_matrix_from_face_normal_and_heading (raw->vh.mob.attitude, face_normal, heading);

		//
		// weapon config
		//

		raw->vh.weapon_package_status_array = malloc_fast_mem (SIZE_WEAPON_PACKAGE_STATUS_ARRAY);

		memset (raw->vh.weapon_package_status_array, 0, SIZE_WEAPON_PACKAGE_STATUS_ARRAY);

		load_local_entity_weapon_config (en);

		//
		// update force info
		//

		add_to_force_info (get_local_force_entity (raw->vh.mob.side), en);

		////////////////////////////////////////
		//
		// LINK INTO SYSTEM
		//
		////////////////////////////////////////

		insert_local_entity_into_parents_child_list (en, LIST_TYPE_MEMBER, raw->vh.member_link.parent, raw->vh.member_link.child_pred);

		//
		// insert into LIST_TYPE_MEMBER before LIST_TYPE_VIEW
		//

		insert_local_entity_into_parents_child_list (en, LIST_TYPE_VIEW, get_camera_entity (), get_local_entity_view_list_pred (en));

		insert_local_entity_into_parents_child_list (en, LIST_TYPE_SECTOR, get_local_sector_entity (&raw->vh.mob.position), NULL);

		insert_local_entity_into_parents_child_list (en, LIST_TYPE_UPDATE, get_update_entity (), NULL);
	}

	return (en);
}
예제 #24
0
파일: cm_satel.c 프로젝트: Comanche93/eech
void reset_satellite_camera (camera *raw)
{
	entity
		*en;

	vec3d
		pos,
		v;

	matrix3x3
		m;

	float
		heading,
		z_min,
		z_max,
		length;

	ASSERT (raw);

	ASSERT (raw->external_view_entity);

	en = raw->external_view_entity;

	z_min = get_local_entity_float_value (en, FLOAT_TYPE_CHASE_VIEW_MIN_DISTANCE);
	z_max = get_local_entity_float_value (en, FLOAT_TYPE_CHASE_VIEW_MAX_DISTANCE);

	//ASSERT (z_min < z_max);

	heading = get_local_entity_float_value (en, FLOAT_TYPE_HEADING);

	get_3d_transformation_matrix (m, heading, CHASE_CAMERA_RESET_PITCH, 0.0);

	v.x = 0.0;
	v.y = 0.0;
	v.z = 0.0;

	multiply_matrix3x3_vec3d (&v, m, &v);

	get_local_entity_target_point (en, &pos);

	raw->position.x = pos.x + v.x;
	raw->position.y = pos.y + v.y;
	raw->position.z = pos.z + v.z;
	
	//
	// keep point above ground (unless point off map)
	//
	
		if (point_inside_map_area (&raw->position))
		{
			raw->position.y = max (raw->position.y, get_3d_terrain_point_data (raw->position.x, raw->position.z, &raw->terrain_info) + CAMERA_MIN_HEIGHT_ABOVE_GROUND);
		}

	
	raw->motion_vector.y = raw->position.y;
	
	raw->position.y += 5000;
		
	//
	// attitude
	//

	v.x = pos.x - raw->position.x;
	v.y = pos.y - raw->position.y;
	v.z = pos.z - raw->position.z;

	length = (v.x * v.x) + (v.y * v.y) + (v.z * v.z);

	if (length > 1.0)
	{
		length = sqrt (length);

		normalise_3d_vector_given_magnitude (&v, length);

		get_matrix3x3_from_unit_vec3d (raw->attitude, &v);
	}
	else
	{
		get_identity_matrix3x3 (raw->attitude);
	}

	//
	// motion vector
	//

	raw->motion_vector.x = 0.0;
	raw->motion_vector.z = 0.0;
	
	raw->fly_by_camera_timer = frand1() * 150 + 80; // parasiting on the struct, can't get my own data...

}