Ejemplo n.º 1
0
void initialise_attack_guide (entity *en)
{
	entity
		*task,
		*aggressor,
		*target;

	ASSERT (en);

	task = get_local_entity_parent (en, LIST_TYPE_GUIDE);

	ASSERT (task);

	ASSERT (get_local_entity_int_value (task, INT_TYPE_ENTITY_SUB_TYPE) == ENTITY_SUB_TYPE_TASK_ENGAGE);

	aggressor = get_local_entity_ptr_value (en, PTR_TYPE_TASK_LEADER);

	ASSERT (aggressor);

	target = get_local_entity_parent (task, LIST_TYPE_TASK_DEPENDENT);

	ASSERT (target);

	if (!get_local_entity_int_value (aggressor, INT_TYPE_IDENTIFY_AIRCRAFT))
	{
		//
		// Surface-Air & Surface-Surface
		//

		entity_sub_types
			best_weapon;

		//
		// find best weapon for target
		//

		best_weapon = get_best_weapon_for_target (aggressor, target, BEST_WEAPON_CRITERIA_ALL);
	
		set_client_server_entity_int_value (aggressor, INT_TYPE_SELECTED_WEAPON, best_weapon);

		return;
	}

	//
	// Air-Air & Air-Surface
	//

	if (get_local_entity_int_value (target, INT_TYPE_AIRBORNE_AIRCRAFT))
	{			
		initialise_air_to_air_attack_guide (en, aggressor, target);
	}
	else
	{
		initialise_air_to_ground_attack_guide (en, aggressor, target);
	}
}
Ejemplo n.º 2
0
void set_next_waypoint (void)
{
	entity
		*guide;

	//
	// Can only change your current waypoint if you have a gunship, and you are leader of your current task
	//

	if (!get_gunship_entity ())
	{
		return;
	}

	if (!get_local_entity_int_value (get_gunship_entity (), INT_TYPE_TASK_LEADER))
	{
		return;
	}

	guide = get_local_entity_parent (get_gunship_entity (), LIST_TYPE_FOLLOWER);

	if (!guide)
	{
		return;
	}

	set_guide_next_waypoint (guide);
}
Ejemplo n.º 3
0
int register_entity_list_link_for_post_unpack_validation (struct ENTITY *en, int list_type)
{

	comms_entity_list_validation_type
		*new_entity_list;

	new_entity_list = (comms_entity_list_validation_type *) malloc_heap_mem (sizeof (comms_entity_list_validation_type));

	new_entity_list->en = en;

	new_entity_list->list_type = list_type;

	new_entity_list->next = entity_list_link_validation;

	entity_list_link_validation = new_entity_list;

	#if DEBUG_MODULE
	{

		entity
			*parent;

		debug_log ("EN_SESSN: registering entity %s (%d) for link list %s validation", get_local_entity_type_name (en), get_local_entity_index (en), get_list_type_name (list_type));

		parent = get_local_entity_parent (en, list_type);

	}
	#endif

	return TRUE;
}
Ejemplo n.º 4
0
void terminate_all_engage_tasks (entity *group)
{
	entity
		*guide,
		*task;

	ASSERT (group);

	ASSERT (get_comms_model () == COMMS_MODEL_SERVER);

	do
	{
		guide = get_local_entity_first_child (group, LIST_TYPE_GUIDE_STACK);

		while (guide)
		{
			if (get_local_entity_int_value (guide, INT_TYPE_VALID_GUIDE_MEMBERS) == 0)
			{
				task = get_local_entity_parent (guide, LIST_TYPE_GUIDE);

				ASSERT (get_local_entity_int_value (task, INT_TYPE_ENTITY_SUB_TYPE) == ENTITY_SUB_TYPE_TASK_ENGAGE);

				if (get_local_entity_int_value (task, INT_TYPE_TASK_TERMINATED) == TASK_TERMINATED_IN_PROGRESS)
				{
					notify_local_entity (ENTITY_MESSAGE_TASK_TERMINATED, task, group, TASK_TERMINATED_ABORTED);

					break;
				}
			}

			guide = get_local_entity_child_succ (guide, LIST_TYPE_GUIDE_STACK);
		}
	}
	while (guide);
}
Ejemplo n.º 5
0
int check_group_task_type_valid_members (entity *group, entity_sub_types task_type)
{
	entity
		*guide,
		*task;

	guide = get_local_entity_first_child (group, LIST_TYPE_GUIDE_STACK);

	while (guide)
	{
		if (get_local_entity_int_value (guide, INT_TYPE_VALID_GUIDE_MEMBERS) != TASK_ASSIGN_NO_MEMBERS)
		{
			task = get_local_entity_parent (guide, LIST_TYPE_GUIDE);

			if (get_local_entity_int_value (task, INT_TYPE_ENTITY_SUB_TYPE) == task_type)
			{
				return TRUE;
			}
		}

		guide = get_local_entity_child_succ (guide, LIST_TYPE_GUIDE_STACK);
	}

	return FALSE;
}
Ejemplo n.º 6
0
int assign_task_to_group_members (entity *group, entity *guide, unsigned int valid_members)
{
	entity
		*task,
		*member;

	ASSERT (group);

	ASSERT (guide);

	task = get_local_entity_parent (guide, LIST_TYPE_GUIDE);

	ASSERT (task);

	member = get_local_entity_first_child (group, LIST_TYPE_MEMBER);

	while (member)
	{
		if (valid_members & (1 << get_local_entity_int_value (member, INT_TYPE_GROUP_MEMBER_NUMBER)))
		{
			attach_group_member_to_guide_entity (member, guide);

			notify_local_entity (ENTITY_MESSAGE_TASK_ASSIGNED, member, task);
		}
		
		member = get_local_entity_child_succ (member, LIST_TYPE_MEMBER);
	}

	return TRUE;
}
Ejemplo n.º 7
0
void dump_guide_stack (entity *group)
{
	entity
		*guide,
		*task;

	debug_filtered_log ("GUIDE STACK:-");
	debug_filtered_log ("-------------");

	guide = get_local_entity_first_child (group, LIST_TYPE_GUIDE_STACK);

	while (guide)
	{
		task = get_local_entity_parent (guide, LIST_TYPE_GUIDE);

		ASSERT (task);

		debug_filtered_log ("Task %s (%d) - Guide (%d) - Valid Members %d",
									get_local_entity_string (task, STRING_TYPE_FULL_NAME),
									get_local_entity_index (task),
									get_local_entity_index (guide),
									get_local_entity_int_value (guide, INT_TYPE_VALID_GUIDE_MEMBERS));

		guide = get_local_entity_child_succ (guide, LIST_TYPE_GUIDE_STACK);
	}
}
Ejemplo n.º 8
0
void engage_specific_targets(entity *wingman, entity *targets[])
{
	entity
		*group;

	unsigned int valid_members = 0, member_number, i;

	ASSERT(get_local_entity_int_value (wingman, INT_TYPE_PLAYER) == ENTITY_PLAYER_AI);

	group = get_local_entity_parent(wingman, LIST_TYPE_MEMBER);
	
	if (!get_local_entity_int_value (group, INT_TYPE_ENGAGE_ENEMY))
		return;

	member_number = get_local_entity_int_value(wingman, INT_TYPE_GROUP_MEMBER_NUMBER);
	valid_members = (1 << member_number);
	
	for (i = 0; i < 16; i++)
	{
		entity* target = targets[i];
		if (!target)
			break;

		engage_specific_target(group, target, valid_members, FALSE);
	}
}
Ejemplo n.º 9
0
entity *collision_test_weapon_with_any_target (entity *weapon, vec3d *weapon_old_position, vec3d *weapon_new_position)
{
	entity
		*launcher,
		*collision_entity;

	vec3d
		weapon_intercept_point,
		face_normal;

	ASSERT (weapon);

	ASSERT (weapon_old_position);

	ASSERT (weapon_new_position);

	ASSERT (get_comms_model () == COMMS_MODEL_SERVER);

	launcher = get_local_entity_parent (weapon, LIST_TYPE_LAUNCHED_WEAPON);

	collision_entity = get_line_of_sight_collision_entity (launcher, NULL, weapon_old_position, weapon_new_position, &weapon_intercept_point, &face_normal);

	if (collision_entity)
	{
		*weapon_new_position = weapon_intercept_point;
	}

	return (collision_entity);
}
Ejemplo n.º 10
0
void add_mobile_to_force_losses_stats (entity *en, entity *victim)
{
	force
		*raw;

	int
		sub_type;

	entity
		*group;

	ASSERT (en);

	ASSERT (victim);

	raw = (force *) get_local_entity_data (en);

	group = get_local_entity_parent (victim, LIST_TYPE_MEMBER);

	ASSERT (group);

	sub_type = get_local_entity_int_value (group, INT_TYPE_ENTITY_SUB_TYPE);

	raw->losses [sub_type] ++;
}
Ejemplo n.º 11
0
int check_group_task_type (entity *group, entity_sub_types task_type)
{

	entity
		*guide,
		*task;

	guide = get_local_entity_first_child (group, LIST_TYPE_GUIDE_STACK);

	while (guide)
	{

		task = get_local_entity_parent (guide, LIST_TYPE_GUIDE);

		if (get_local_entity_int_value (task, INT_TYPE_ENTITY_SUB_TYPE) == task_type)
		{

			return TRUE;
		}

		guide = get_local_entity_child_succ (guide, LIST_TYPE_GUIDE_STACK);
	}

	return FALSE;
}
Ejemplo n.º 12
0
float get_ka50_missile_flight_time (void)
{
	entity
		*en,
		*weapon,
		*target;

	vec3d
		*weapon_position,
		*target_position;

	float
		flight_time,
		weapon_velocity,
		target_range;

	flight_time = 0.0;

	en = get_gunship_entity ();

	//
	// find most recently launched Vikhr with a target (first found on list)
	//

	weapon = get_local_entity_first_child (en, LIST_TYPE_LAUNCHED_WEAPON);

	while (weapon)
	{
		if (get_local_entity_int_value (weapon, INT_TYPE_ENTITY_SUB_TYPE) == ENTITY_SUB_TYPE_WEAPON_VIKHR)
		{
			target = get_local_entity_parent (weapon, LIST_TYPE_TARGET);

			if (target)
			{
				weapon_position = get_local_entity_vec3d_ptr (weapon, VEC3D_TYPE_POSITION);

				target_position = get_local_entity_vec3d_ptr (target, VEC3D_TYPE_POSITION);

				target_range = get_3d_range (weapon_position, target_position);

				weapon_velocity = get_local_entity_float_value (weapon, FLOAT_TYPE_VELOCITY);

				if (weapon_velocity > 0.0)
				{
					flight_time = target_range / weapon_velocity;

					break;
				}
			}
		}

		weapon = get_local_entity_child_succ (weapon, LIST_TYPE_LAUNCHED_WEAPON);
	}

	return (flight_time);
}
Ejemplo n.º 13
0
// arneh 2006-11-16 - manual laser control
static void activate_laser_event(event* ev)
{
	if (!laser_is_active() && !havoc_damage.laser_range_finder)
	{
		if (target_acquisition_system == TARGET_ACQUISITION_SYSTEM_OFF)
			lase_range_for_ballistics_sight();
		else
			set_laser_is_active(eo_is_tracking_point() || get_local_entity_parent(get_gunship_entity(), LIST_TYPE_TARGET));
	}
	else
		set_laser_is_active(FALSE);
}
Ejemplo n.º 14
0
void terminate_entity_current_engage_task (entity *en)
{
	entity
		*guide,
		*task;

	ASSERT (en);

	ASSERT (get_comms_model () == COMMS_MODEL_SERVER);

	guide = get_local_entity_parent (en, LIST_TYPE_FOLLOWER);

	if (guide)
	{
		task = get_local_entity_parent (guide, LIST_TYPE_GUIDE);

		if (get_local_entity_int_value (task, INT_TYPE_ENTITY_SUB_TYPE) == ENTITY_SUB_TYPE_TASK_ENGAGE)
		{
			delete_group_member_from_engage_guide (en, guide, FALSE);
		}
	}
}
Ejemplo n.º 15
0
entity *get_player_task (entity *en)
{
	if (!en)
	{
		en = get_pilot_entity ();
	}

	ASSERT (en);

	ASSERT (get_local_entity_type (en) == ENTITY_TYPE_PILOT);

	return get_local_entity_parent (en, LIST_TYPE_PLAYER_TASK);
}
Ejemplo n.º 16
0
static void set_local_ptr_value (entity *en, ptr_types type, void *ptr)
{
	group
		*raw;

	#if DEBUG_MODULE

	debug_log_entity_args (ENTITY_DEBUG_LOCAL, ENTITY_DEBUG_PTR_VALUE, en, type, ptr);

	#endif

	raw = (group *) get_local_entity_data (en);

	switch (type)
	{
		////////////////////////////////////////
		case PTR_TYPE_GROUP_LEADER:
		////////////////////////////////////////
		{
			entity
				*member;
				
			//
			// make an entity group leader by removing it from the member list, and inserting it at the front
			//

			member = (entity *) ptr;

			ASSERT (member);

			ASSERT (get_local_entity_parent (member, LIST_TYPE_MEMBER) == en);
	
			delete_local_entity_from_parents_child_list (member, LIST_TYPE_MEMBER);

			insert_local_entity_into_parents_child_list (member, LIST_TYPE_MEMBER, en, NULL);

			break;
		}
		////////////////////////////////////////
		default:
		////////////////////////////////////////
		{
			debug_fatal_invalid_ptr_type (en, type);

			break;
		}
	}
}
Ejemplo n.º 17
0
static void update_rotors (entity *en)
{
	helicopter
		*raw;

	raw = get_local_entity_data (en);

	if (!get_local_entity_parent (en, LIST_TYPE_FOLLOWER))
	{
		raw->main_rotor_rpm -= 5.0 * get_delta_time ();

		raw->main_rotor_rpm = bound (raw->main_rotor_rpm, 0.0, 100.0);

		raw->tail_rotor_rpm = raw->main_rotor_rpm;
	}
}
Ejemplo n.º 18
0
void navigation_guide_waypoint_reached (entity *en)
{
	entity
		*current_wp;

	//
	// set next waypoint (actual set function is called from within wp_msgs)
	//

	current_wp = get_local_entity_parent (en, LIST_TYPE_CURRENT_WAYPOINT);

	ASSERT (current_wp);

	// WARNING : must be done last because it can destroy the current guide entity
	notify_local_entity (ENTITY_MESSAGE_WAYPOINT_REACHED, current_wp, en);
}
Ejemplo n.º 19
0
int attack_guide_find_best_weapon (entity *en)
{
	entity
		*target,
		*aggressor;
		
	entity_sub_types
		best_weapon;

	//
	// check weapon
	//

	aggressor = get_local_entity_ptr_value (en, PTR_TYPE_TASK_LEADER);

	ASSERT (aggressor);

	target = get_local_entity_parent (aggressor, LIST_TYPE_TARGET);

	ASSERT (target);

	best_weapon = get_best_weapon_for_target (aggressor, target, BEST_WEAPON_RANGE_CHECK);

	if (best_weapon == ENTITY_SUB_TYPE_WEAPON_NO_WEAPON)
	{
		//
		// No suitable weapon at current range
		//
		
		best_weapon = get_best_weapon_for_target (aggressor, target, BEST_WEAPON_CRITERIA_MINIMAL);

		if (best_weapon == ENTITY_SUB_TYPE_WEAPON_NO_WEAPON)
		{
			//
			// Entity is not capable of destroying the target - abort the attack 
			//

			delete_group_member_from_engage_guide (aggressor, en, TRUE);

			return FALSE;
		}
	}

	set_client_server_entity_int_value (aggressor, INT_TYPE_SELECTED_WEAPON, best_weapon);

	return TRUE;
}
Ejemplo n.º 20
0
static void display_target_information (void)
{
	const char
		*s;
	char
		buffer[200];

	entity
		*target = get_local_entity_parent (get_gunship_entity (), LIST_TYPE_TARGET);

	set_mono_font_type (MONO_FONT_TYPE_8X14);
	s = get_target_display_name (target, buffer, FALSE);
	if (s && strcmp(s, "NO TARGET") != 0)
	{
		float width = get_mono_font_string_width (s);
		set_2d_mono_font_position (0.0, -0.75);
		set_mono_font_rel_position (-width * 0.5, 0.0);
		print_mono_font_string (s);
	}
}
Ejemplo n.º 21
0
void group_terminate_all_tasks (entity *en)
{
	entity
		*task,
		*guide;

	int
		task_type;

	ASSERT (en);

	ASSERT (get_comms_model () == COMMS_MODEL_SERVER);

	terminate_all_engage_tasks (en);

	do
	{
		guide = get_local_entity_first_child (en, LIST_TYPE_GUIDE_STACK);

		if (guide)
		{
			task = get_local_entity_parent (guide, LIST_TYPE_GUIDE);

			ASSERT (task);

			task_type = get_local_entity_int_value (task, INT_TYPE_ENTITY_SUB_TYPE);

			if (task_database [task_type].persistent_task)
			{
				destroy_client_server_entity (guide);
			}
			else
			{
				notify_local_entity (ENTITY_MESSAGE_TASK_TERMINATED, task, NULL, TASK_TERMINATED_ABORTED);
			}
		}
	}
	while (guide);
}
Ejemplo n.º 22
0
static void notify_member_list (ui_object *obj, void *arg)
{
	int
		index;

	entity
		*en,
		*group;

	index = get_ui_object_item_number (obj);

	en = get_local_entity_safe_ptr (index);

	ASSERT (en);

	set_ui_object_item_number (page_member_list, index);

	group = get_local_entity_parent (en, LIST_TYPE_MEMBER);

	ASSERT (group);

	show_weapon_loading_page (group, FALSE);
}
Ejemplo n.º 23
0
void respond_to_player_task_assign_request (entity *pilot, entity *task, entity *mobile)
{
	entity
		*group;
		
	ASSERT (pilot);

	ASSERT (mobile);

	ASSERT (task);

	ASSERT (get_comms_model () == COMMS_MODEL_SERVER);

	group = get_local_entity_parent (mobile, LIST_TYPE_MEMBER);

	if ((!get_local_entity_first_child (task, LIST_TYPE_GUIDE)) && (!get_local_group_primary_task (group)))
	{
		if (assign_primary_task_to_group (group, task))
		{
			transmit_entity_comms_message (ENTITY_COMMS_TASK_ASSIGN_RESULT, pilot, task, mobile);

			return;
		}
	}
	else
	{
		if (get_local_group_primary_task (group))
		{
			transmit_entity_comms_message (ENTITY_COMMS_TASK_ASSIGN_RESULT, pilot, task, mobile);

			return;
		}
	}

	transmit_entity_comms_message (ENTITY_COMMS_TASK_ASSIGN_RESULT, pilot, NULL, NULL);
}
Ejemplo n.º 24
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);
}
Ejemplo n.º 25
0
static void pack_local_data (entity *en, pack_modes mode)
{
	ASSERT ((mode >= 0) && (mode < NUM_PACK_MODES));

	switch (mode)
	{
		////////////////////////////////////////
		case PACK_MODE_SERVER_SESSION:
		case PACK_MODE_CLIENT_SESSION:
		////////////////////////////////////////
		{
			sound_effect
				*raw;

			int
				loop;

			raw = get_local_entity_data (en);

			if (effect_database [raw->eff.sub_type].constructed_locally)
			{
				return;
			}

			if (mode == PACK_MODE_SERVER_SESSION)
			{
	
				if (get_local_entity_type (raw->eff.special_effect_link.parent) == ENTITY_TYPE_SESSION)
				{
	
					return;
				}
			}

			pack_entity_type (get_local_entity_type (en));

			pack_entity_safe_ptr (en);

			//
			// pack effect data
			//

			pack_effect_data (en, &raw->eff, mode);

			//
			// pack sound effect data
			//

			pack_int_value (en, INT_TYPE_SOUND_EFFECT_SEQUENCE_COUNT, raw->sound_effect_sequence_count);

			for (loop = 0; loop < raw->sound_effect_sequence_count; loop ++)
			{
				pack_int_value (en, INT_TYPE_SOUND_EFFECT_INDEX, raw->effect_index [loop]);
			}

			pack_float_value (en, FLOAT_TYPE_AMPLIFICATION, raw->amplification);

			pack_float_value (en, FLOAT_TYPE_EFFECT_LIFETIME, raw->effect_lifetime);

			pack_float_value (en, FLOAT_TYPE_VALID_EFFECT_LIFETIME, raw->valid_effect_lifetime);

			// sound_effect_data

			pack_int_value (en, INT_TYPE_SOUND_CHANNEL, raw->sound_channel);

			pack_int_value (en, INT_TYPE_SOUND_LOCALITY, raw->sound_locality);

			pack_int_value (en, INT_TYPE_VALID_SOUND_EFFECT, raw->valid_sound_effect);

			pack_int_value (en, INT_TYPE_SOUND_EFFECT_LOOPING, raw->looping);

			pack_int_value (en, INT_TYPE_SOUND_EFFECT_PANNING, raw->panning);

			if (get_local_entity_parent (en, LIST_TYPE_UPDATE))
			{
				pack_int_value (en, INT_TYPE_VALID, TRUE);
			}
			else
			{
				pack_int_value (en, INT_TYPE_VALID, FALSE);
			}

			#if DEBUG_MODULE

			debug_log ("SE_PACK: Packed %d - Sub-type %d", get_local_entity_safe_index (en), raw->eff.sub_type);

			#endif

			break;
		}
		////////////////////////////////////////
		case PACK_MODE_BROWSE_SESSION:
		////////////////////////////////////////
		{
			break;
		}
		////////////////////////////////////////
		case PACK_MODE_UPDATE_ENTITY:
		////////////////////////////////////////
		{
			break;
		}
	}
}
Ejemplo n.º 26
0
static void update_server (entity *en)
{
	entity
		*parent,
		*next_segment,
		*prev_segment;

	entity_sub_types
		sub_type;

	vec3d
		*pos;

	float
		terrain_height;

	terrain_3d_point_data
		terrain_info;

	//
	// notify the segments neighbours as applicable
	//

	parent = get_local_entity_parent (en, LIST_TYPE_SEGMENT);

	ASSERT (parent);

	next_segment = get_local_entity_child_succ (en, LIST_TYPE_SEGMENT);

	if (next_segment)
	{
		notify_local_entity (ENTITY_MESSAGE_COLLISION, parent, next_segment);
	}

	prev_segment = get_local_entity_child_pred (en, LIST_TYPE_SEGMENT);

	if (prev_segment)
	{
		notify_local_entity (ENTITY_MESSAGE_COLLISION, parent, prev_segment);
	}

	sub_type = get_local_entity_int_value (en, INT_TYPE_ENTITY_SUB_TYPE);

	if (sub_type == ENTITY_SUB_TYPE_FIXED_BRIDGE_UNSUPPORTED_MID_SECTION)
	{
		//
		// make the segment drop to the floor ( removing it from the update list when it hits )
		//
	
		pos = get_local_entity_vec3d_ptr (en, VEC3D_TYPE_POSITION);
	
		pos->y -= ( 10.0 * get_delta_time() );
	
		memset (&terrain_info, 0, sizeof (terrain_3d_point_data));
	
		terrain_height = get_3d_terrain_point_data (pos->x, pos->z, &terrain_info);

		if (get_terrain_type_class (terrain_info.terrain_type) == TERRAIN_CLASS_WATER)
		{
			terrain_height -= 1.0;
		}
	
		if ( pos->y <= terrain_height )
		{
			pos->y = terrain_height;
	
			delete_local_entity_from_parents_child_list (en, LIST_TYPE_UPDATE);
	
			if (get_comms_model () == COMMS_MODEL_SERVER)
			{
				create_client_server_object_hit_ground_explosion_effect (en, terrain_info.terrain_type);
			}
		}
	}
	else
	{
		//
		// segment is supported, and so should be instantly removed from the update list
		// ( only put there in the first place so that neighbours would be notified )
		//

		delete_local_entity_from_parents_child_list (en, LIST_TYPE_UPDATE);
	}
}
Ejemplo n.º 27
0
static void kill_local (entity *en)
{

	int
		losses;

	entity
		*task,
		*group,
		*keysite,
		*destroy_task;

	ship_vehicle
		*raw;

	////////////////////////////////////////
	//
	// PRE-AMBLE
	//
	////////////////////////////////////////

	#if DEBUG_MODULE >= 2

	debug_log_entity_args (ENTITY_DEBUG_LOCAL, ENTITY_DEBUG_KILL, en);

	#endif

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

	raw = (ship_vehicle *) get_local_entity_data (en);

	group = get_local_entity_parent (en, LIST_TYPE_MEMBER);

	ASSERT (group);

	keysite = NULL;

	if (tacview_is_logging())
		write_tacview_unit_event(en, TACVIEW_UNIT_DESTROYED, NULL);

	//
	// update force info
	//

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

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

	////////////////////////////////////////
	//
	// DESTROY COMPONENTS
	//
	////////////////////////////////////////

	if (get_comms_model () == COMMS_MODEL_SERVER)
	{
		task = get_local_entity_first_child (en, LIST_TYPE_TASK_DEPENDENT);

		while (task)
		{
			destroy_task = task;

			task = get_local_entity_child_succ (task, LIST_TYPE_TASK_DEPENDENT);

			if (destroy_task->type == ENTITY_TYPE_TASK)
			{
				#if DEBUG_MODULE

				debug_log ("SH_DSTRY: killing ship, notifying task %s complete", entity_sub_type_task_names [get_local_entity_int_value (destroy_task, INT_TYPE_ENTITY_SUB_TYPE)]);

				#endif

				notify_local_entity (ENTITY_MESSAGE_TASK_COMPLETED, destroy_task, en, TASK_TERMINATED_OBJECTIVE_MESSAGE);
			}
		}

		//
		// Release landing lock (if any)
		//

		release_mobile_entity_landing_locks (en);

		////////////////////////////////////////
		//
		// UNLINK FROM SYSTEM
		//
		////////////////////////////////////////

		//
		// Destroy keysite entity if ship is carrier
		//

		keysite = get_local_entity_first_child (en, LIST_TYPE_MOVEMENT_DEPENDENT);

		while (keysite)
		{
			if (get_local_entity_type (keysite) == ENTITY_TYPE_KEYSITE)
			{
				break;
			}

			keysite = get_local_entity_child_succ (keysite, LIST_TYPE_MOVEMENT_DEPENDENT);
		}
	}

	//
	// ship_vehicle
	//

	//
	// vehicle
	//

	unlink_local_entity_children (en, LIST_TYPE_TASK_DEPENDENT);

	unlink_local_entity_children (en, LIST_TYPE_MOVEMENT_DEPENDENT);

	delete_local_entity_from_parents_child_list (en, LIST_TYPE_MEMBER);

	delete_local_entity_from_parents_child_list (en, LIST_TYPE_MOVEMENT_DEPENDENT);

	delete_local_entity_from_parents_child_list (en, LIST_TYPE_FOLLOWER);

	// gunship_target_link

	// member_link

	// view_link

	delete_local_entity_from_parents_child_list (en, LIST_TYPE_TAKEOFF_QUEUE);

	//
	// mobile
	//

	//
	// kill weapon sound effects
	//

	kill_local_entity_sound_type (en, ENTITY_SUB_TYPE_EFFECT_SOUND_CHAIN_GUN);

	//
	// kill engine sound effects
	//

	kill_local_entity_sound_type (en, ENTITY_SUB_TYPE_EFFECT_SOUND_ENGINE_LOOPING1);
	kill_local_entity_sound_type (en, ENTITY_SUB_TYPE_EFFECT_SOUND_ENGINE_LOOPING2);

	unlink_local_entity_children (en, LIST_TYPE_TARGET);

	delete_local_entity_from_parents_child_list (en, LIST_TYPE_PADLOCK);

	// sector_link

	delete_local_entity_from_parents_child_list (en, LIST_TYPE_TARGET);

	// update_link

	set_local_entity_int_value (en, INT_TYPE_OPERATIONAL_STATE, OPERATIONAL_STATE_STOPPED);

	////////////////////////////////////////
	//
	// KILL
	//
	////////////////////////////////////////

	// must be done before alive flag set
	remove_mobile_values_from_sector (get_local_entity_parent (en, LIST_TYPE_SECTOR), en);

	set_local_entity_int_value (en, INT_TYPE_ALIVE, FALSE);

	damage_ship_3d_object (en);

	//
	// group losses
	//

	losses = get_local_entity_int_value (group, INT_TYPE_LOSSES);

	losses ++;

	set_local_entity_int_value (group, INT_TYPE_LOSSES, losses);

	//
	// task losses
	//

	task = get_local_group_primary_task (group);

	if (task)
	{
		losses = get_local_entity_int_value (task, INT_TYPE_LOSSES);

		losses ++;

		set_local_entity_int_value (task, INT_TYPE_LOSSES, losses);
	}

	//
	// Notify Campaign Screen
	//

	notify_campaign_screen (CAMPAIGN_SCREEN_GROUP_REMOVE_MEMBER, group);

	if (get_comms_model () == COMMS_MODEL_SERVER)
	{
		//
		// Notify the GROUP that the mobile has been killed  (N.B. must be done AFTER mobile is unlinked from member list)
		//

		notify_local_entity (ENTITY_MESSAGE_MOBILE_KILLED, group, en);

		//
		// Kill the keysite if ship is the carrier (N.B. must be done AFTER ships alive flag cleared)
		//

		if (keysite)
		{
			kill_client_server_entity (keysite);
		}
	}

	////////////////////////////////////////
	//
	// SPECIAL EFFECTS
	//
	////////////////////////////////////////

	if (get_comms_model () == COMMS_MODEL_SERVER)
	{
		create_client_server_object_killed_explosion_effect (en);
	}

	#if LANDING_ROUTE_CHECK

	destroy_debug_entity_landing_route_check (en);

	#endif

	/////////////////////////////////////////////////////////////////
	//
	// SPECIAL_EFFECT_HOOK FOR BEING_DESTROYED
	//
	/////////////////////////////////////////////////////////////////

	/////////////////////////////////////////////////////////////////
	//
	//
	/////////////////////////////////////////////////////////////////
}
Ejemplo n.º 28
0
static void display_weapon_information (void)
{
	entity_sub_types
		weapon_sub_type;

	float
		x,
		y,
		angle_of_drop,
		drop_hud_distance,
		roll;

	weapon_sub_type = get_local_entity_int_value (get_gunship_entity (), INT_TYPE_SELECTED_WEAPON);

	if (weapon_sub_type != ENTITY_SUB_TYPE_WEAPON_NO_WEAPON)
	{
		//
		// weapon specific
		//

		if ((weapon_sub_type == ENTITY_SUB_TYPE_WEAPON_S5)
			|| (weapon_sub_type == ENTITY_SUB_TYPE_WEAPON_S8)
			|| (weapon_sub_type == ENTITY_SUB_TYPE_WEAPON_S13)
			|| (weapon_sub_type == ENTITY_SUB_TYPE_WEAPON_GSH23L_23MM_ROUND)
			|| (weapon_sub_type == ENTITY_SUB_TYPE_WEAPON_9A642_12P7MM_ROUND && target_acquisition_system != TARGET_ACQUISITION_SYSTEM_HMS))
		{
			float
				x,y;
				angle_of_drop = 0.0;
				drop_hud_distance;
				roll = get_local_entity_float_value (get_gunship_entity (), FLOAT_TYPE_ROLL);

			angle_of_drop = get_ballistic_weapon_drop(weapon_sub_type);
			drop_hud_distance = atan(angle_of_drop) * hud_position_z / (0.5 * hud_height);

			y = cos(roll) * -drop_hud_distance;
			x = sin(roll) * drop_hud_distance;

			draw_aim_marker(x, y, hud_aim_range, weapon_database[weapon_sub_type].min_range);

			// draw target marker around target if having cpg assist
			if (get_global_cpg_assist_type() != CPG_ASSIST_TYPE_NONE && eo_is_locked())
			{
				float az, el;

				get_eo_azimuth_and_elevation(&az, &el);
				if (angles_to_hud_coordinates(az, el, &x, &y, TRUE))
					draw_2d_circle(x, y, 0.15, hud_colour);
			}
		}
		else
		{
			entity* target = get_local_entity_parent (get_gunship_entity (), LIST_TYPE_TARGET);
			vec3d* tracking_point;

			// will use point lock if no target
			tracking_point = get_eo_tracking_point();
			if (target || tracking_point)
			{
				vec3d
					target_position,
					*source_position;

				float
					elevation,
					azimuth;

				if (target)
					get_local_entity_target_point (target, &target_position);
				else
					target_position = *tracking_point;

				source_position = get_local_entity_vec3d_ptr(get_gunship_entity(), VEC3D_TYPE_POSITION);

				get_eo_azimuth_and_elevation(&azimuth, &elevation);

				hud_aim_range = get_triangulated_by_position_range(source_position, &target_position);

				if (angles_to_hud_coordinates(azimuth, elevation, &x, &y, TRUE))
					draw_aim_marker(x, y, hud_aim_range, weapon_database[weapon_sub_type].min_range);
			}
		}
	}
}
Ejemplo n.º 29
0
int resume_local_entity_sound_type (entity *en, entity_sub_types type)
{
	entity
		*spec;

	sound_effect
		*raw;

	int
		count;

	count = 0;

	spec = get_local_entity_first_child (en, LIST_TYPE_SPECIAL_EFFECT);
	
	while (spec)
	{
		if (get_local_entity_type (spec) == ENTITY_TYPE_SOUND_EFFECT)
		{
			raw = get_local_entity_data (spec);

			if (raw->eff.sub_type == type)
			{
				//
				// "unpause" sound
				//

				if (!raw->valid_sound_effect)
				{
					//
					// set flag and start playing
					//

					raw->valid_sound_effect = TRUE;
	
					if (en == get_session_entity ())
					{
						play_local_entity_sound (en, &main_vp, 0);
					}
					else
					{
						vec3d
							*position;
	
						viewpoint
							*vp;
	
						float
							range;
	
						vp = &main_vp;
	
						position = get_local_entity_vec3d_ptr (en, VEC3D_TYPE_POSITION);
	
						range = get_approx_3d_range (&vp->position, position);
	
						play_local_entity_sound (en, vp, range);
					}

					if (!get_local_entity_parent (spec, LIST_TYPE_UPDATE))
					{
						insert_local_entity_into_parents_child_list (spec, LIST_TYPE_UPDATE, get_update_entity (), NULL);
					}

					count ++;
				}
			}
		}

		spec = get_local_entity_child_succ (spec, LIST_TYPE_SPECIAL_EFFECT);
	}

	return count;
}
Ejemplo n.º 30
0
static void kill_local (entity *en)
{
	entity
		*parent;

	entity
		*task,
		*destroy_task;

	////////////////////////////////////////
	//
	// PRE-AMBLE
	//
	////////////////////////////////////////

	#if DEBUG_MODULE

	debug_log_entity_args (ENTITY_DEBUG_LOCAL, ENTITY_DEBUG_KILL, en);

	#endif

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

	ASSERT (get_local_entity_int_value (en, INT_TYPE_ALIVE));

	parent = get_local_entity_parent (en, LIST_TYPE_SEGMENT);

	ASSERT (parent);

	////////////////////////////////////////
	//
	// UNLINK FROM SYSTEM
	//
	////////////////////////////////////////

	if (get_comms_model () == COMMS_MODEL_SERVER)
	{
		task = get_local_entity_first_child (en, LIST_TYPE_TASK_DEPENDENT);

		while (task)
		{

			destroy_task = task;

			task = get_local_entity_child_succ (task, LIST_TYPE_TASK_DEPENDENT);

			if (destroy_task->type == ENTITY_TYPE_TASK)
			{

				#if DEBUG_MODULE

				debug_log ("SG_DSTRY: killing segment, notifying task %s complete", entity_sub_type_task_names [get_local_entity_int_value (destroy_task, INT_TYPE_ENTITY_SUB_TYPE)]);

				#endif

				notify_local_entity (ENTITY_MESSAGE_TASK_COMPLETED, destroy_task, en, TASK_TERMINATED_OBJECTIVE_MESSAGE);
			}
		}
	}

	//
	// fixed
	//

	unlink_local_entity_children (en, LIST_TYPE_TASK_DEPENDENT);

	unlink_local_entity_children (en, LIST_TYPE_TARGET);

	// gunship_target_link

	// sector_link

	//
	// segment
	//

	// segment_link

	// update_link

	////////////////////////////////////////
	//
	// KILL
	//
	////////////////////////////////////////

	set_local_entity_int_value (en, INT_TYPE_ALIVE, FALSE);

	////////////////////////////////////////
	//
	// SPECIAL EFFECTS
	//
	////////////////////////////////////////

	if (get_comms_model () == COMMS_MODEL_SERVER)
	{
		create_client_server_object_killed_explosion_effect (en);

		//
		// kill any routed vehicles that are on the bridge at the time
		//

		kill_routed_vehicles_on_segment (en);
	}

	//
	// notify the parent's collision function ( primarily to change the objects shape ),
	// and the parents killed function ( to handle breaking of links, and setting off chain reactions etc. )
	//

	notify_local_entity (ENTITY_MESSAGE_COLLISION, parent, en);

	notify_local_entity (ENTITY_MESSAGE_CHILD_KILLED, parent, en);
}