Esempio n. 1
0
entity *get_group_at_road_node (int node)
{
	entity
		*force,
		*group;

	force = get_local_entity_first_child (get_session_entity (), LIST_TYPE_FORCE);

	while (force)
	{
		group = get_local_entity_first_child (force, LIST_TYPE_GROUND_REGISTRY);

		while (group)
		{
			if ((get_local_entity_int_value (group, INT_TYPE_ROUTE_NODE) == node) &&
				(get_local_entity_int_value (group, INT_TYPE_ALIVE)))
			{
				#if DEBUG_MODULE

				debug_log ("GP_MSGS: found retreat group %d side %s at node %d", group, entity_side_names [get_local_entity_int_value (group, INT_TYPE_SIDE)], node);

				#endif

				return group;
			}

			group = get_local_entity_child_succ (group, LIST_TYPE_GROUND_REGISTRY);
		}

		force = get_local_entity_child_succ (force, LIST_TYPE_FORCE);
	}

	return NULL;
}
Esempio n. 2
0
int get_session_pilot_count (void)
{
	entity
		*force,
		*pilot;

	int
		count;
	
	ASSERT (get_session_entity ());

	count = 0;

	force = get_local_entity_first_child (get_session_entity (), LIST_TYPE_FORCE);

	while (force)
	{
		pilot = get_local_entity_first_child (force, LIST_TYPE_PILOT);

		while (pilot)
		{
			count ++;

			pilot = get_local_entity_child_succ (pilot, LIST_TYPE_PILOT);
		}

		force = get_local_entity_child_succ (force, LIST_TYPE_FORCE);
	}

	return count;
}
Esempio n. 3
0
void kill_client_server_entity_sound_type (entity *en, entity_sub_types type)
{
	entity
		*spec,
		*next;

	sound_effect
		*raw;

	spec = get_local_entity_first_child (en, LIST_TYPE_SPECIAL_EFFECT);
	
	while (spec)
	{
		next = get_local_entity_child_succ (spec, LIST_TYPE_SPECIAL_EFFECT);

		if (get_local_entity_type (spec) == ENTITY_TYPE_SOUND_EFFECT)
		{
			raw = get_local_entity_data (spec);

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

				kill_client_server_entity (spec);
			}
		}

		spec = next;
	}
}
Esempio 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);
}
Esempio n. 5
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;
}
Esempio n. 6
0
void group_destroy_all_members (entity *en)
{
	entity
		*next,
		*member;

	ASSERT (get_comms_model () == COMMS_MODEL_SERVER);

	//
	// DESTROY each member
	//

	member = get_local_entity_first_child (en, LIST_TYPE_MEMBER);

	while (member)
	{
		next = get_local_entity_child_succ (member, LIST_TYPE_MEMBER);

		destroy_client_server_entity (member);

		member = next;
	}

	//
	// Must also KILL the group
	//

	kill_client_server_group_entity (en);
}
Esempio n. 7
0
int get_local_entity_sound_type_valid (entity *en, entity_sub_types type)
{
	entity
		*spec;

	sound_effect
		*raw;

	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)
			{
				return (raw->valid_sound_effect);
			}
		}

		spec = get_local_entity_child_succ (spec, LIST_TYPE_SPECIAL_EFFECT);
	}

	return FALSE;
}
Esempio n. 8
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;
}
Esempio n. 9
0
void setup_campaign (void)
{
	entity
		*force;
		
	ASSERT (get_comms_model () == COMMS_MODEL_SERVER);

	ASSERT (get_session_entity ());

	//
	// Create force overall campaign objectives
	//

	force = get_local_entity_first_child (get_session_entity (), LIST_TYPE_FORCE);

	ASSERT (force);

	while (force)
	{
		create_force_campaign_objectives (force);

		force = get_local_entity_child_succ (force, LIST_TYPE_FORCE);
	}

	//
	// Setup Order Of Battle
	//

	initialise_order_of_battle ();
}
Esempio n. 10
0
int get_local_group_member_max_formation_position (entity *group)
{

	entity
		*member;

	int
		max_formation_position;

	max_formation_position = 0;

	member = get_local_entity_first_child (group, LIST_TYPE_MEMBER);

	while (member)
	{

		if (max_formation_position < get_local_entity_int_value (member, INT_TYPE_FORMATION_POSITION))
		{

			max_formation_position = get_local_entity_int_value (member, INT_TYPE_FORMATION_POSITION);
		}

		member = get_local_entity_child_succ (member, LIST_TYPE_MEMBER);
	}

	return max_formation_position;
}
Esempio n. 11
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;
}
Esempio n. 12
0
int clear_ship_fires (entity *ship_en, entity_sub_types type)
{
	entity
		*en;

	vec3d
		*pos;

	en = get_local_entity_first_child (ship_en, LIST_TYPE_SPECIAL_EFFECT);

	while (en)
	{
		if (en->type == ENTITY_TYPE_SMOKE_LIST)
		{
			if (get_local_entity_int_value (en, INT_TYPE_ENTITY_SUB_TYPE) == type)
			{
				pos = get_local_entity_vec3d_ptr (en, VEC3D_TYPE_POSITION);

				if (pos->y < 0.0)
				{
					set_local_entity_float_value (en, FLOAT_TYPE_GENERATOR_LIFETIME, 0.0);
				}
			}
      }

		en = get_local_entity_child_succ (en, LIST_TYPE_SPECIAL_EFFECT);
	}

	return TRUE;
}
Esempio n. 13
0
entity *get_local_force_entity (entity_sides side)
{

	entity
		*force;

	if (!get_session_entity ())
	{

		return NULL;
	}

	force = get_local_entity_first_child (get_session_entity (), LIST_TYPE_FORCE);

	while (force)
	{

		debug_assert (get_local_entity_type (force) == ENTITY_TYPE_FORCE);

		if (get_local_entity_int_value (force, INT_TYPE_SIDE) == side)
		{

			return force;
		}

		force = get_local_entity_child_succ (force, LIST_TYPE_FORCE);
	}

	return NULL;
}
Esempio n. 14
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);
	}
}
Esempio n. 15
0
void set_group_member_numbers (entity *en)
{
	int
		number;

	entity
		*member;

	ASSERT (en);

	ASSERT (get_comms_model () == COMMS_MODEL_SERVER);

	number = 0;

	member = get_local_entity_first_child (en, LIST_TYPE_MEMBER);

	while (member)
	{
		set_client_server_entity_int_value (member, INT_TYPE_GROUP_MEMBER_NUMBER, number);

		member = get_local_entity_child_succ (member, LIST_TYPE_MEMBER);

		number ++;
	}
}
Esempio n. 16
0
int get_group_suitable_for_player (entity *group, entity *pilot)
{
	entity
		*member;

	ASSERT (group);

	if (!group)
	{
		return FALSE;
	}

	member = get_local_entity_first_child (group, LIST_TYPE_MEMBER);

	while (member)
	{
		if (get_local_entity_suitable_for_player (member, pilot))
		{
			return TRUE;
		}

		member = get_local_entity_child_succ (member, LIST_TYPE_MEMBER);
	}

	return FALSE;
}
Esempio n. 17
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);
}
Esempio n. 18
0
static void dedicated_server_build_player_list (void)
{
	entity
		*force,
		*pilot;

	entity_sides
		side;

	rgb_colour
		col;

	ui_object_destroy_list_items (player_list);

	force = get_local_entity_first_child (get_session_entity (), LIST_TYPE_FORCE);

	while (force)
	{
		pilot = get_local_entity_first_child (force, LIST_TYPE_PILOT);

		while (pilot)
		{
			if (pilot != get_pilot_entity ())
			{
				side = (entity_sides) get_local_entity_int_value (pilot, INT_TYPE_SIDE);

				col.r = 255;
				col.g = 255;
				col.b = 255;
				col.a = 255;

				add_to_pop_up_list (get_local_entity_string (pilot, STRING_TYPE_PILOTS_NAME), player_list, NULL, 0, UI_FONT_ARIAL_16, col);
			}
			
			pilot = get_local_entity_child_succ (pilot, LIST_TYPE_PILOT);
		}

		force = get_local_entity_child_succ (force, LIST_TYPE_FORCE);
	}
}
Esempio n. 19
0
void kill_client_server_group_entity (entity *en)
{
	entity
		*guide,
		*task,
		*next;

	ASSERT (en);

	ASSERT (get_comms_model () == COMMS_MODEL_SERVER);

	//
	// abort tasks (NOTE: Notifying each guide could indirectly destroy other guides on the stack)
	//

	do
	{
		guide = get_local_entity_first_child (en, LIST_TYPE_GUIDE_STACK);

		if (guide)
		{
			notify_local_entity (ENTITY_MESSAGE_GROUP_KILLED, guide, en);
		}
	}
	while (guide);

	//
	// notify task dependents
	//

	task = get_local_entity_first_child (en, LIST_TYPE_TASK_DEPENDENT);

	while (task)
	{
		next = get_local_entity_child_succ (task, LIST_TYPE_TASK_DEPENDENT);

		if (task->type == ENTITY_TYPE_TASK)
		{
			notify_local_entity (ENTITY_MESSAGE_TASK_COMPLETED, task, en, TASK_TERMINATED_OBJECTIVE_MESSAGE);
		}

		task = next;
	}

	kill_client_server_entity (en);
}
Esempio n. 20
0
void set_group_formation_positions (entity *en)
{
	entity
		*member;

	ASSERT (en);

	ASSERT (get_comms_model () == COMMS_MODEL_SERVER);

	member = get_local_entity_first_child (en, LIST_TYPE_MEMBER);

	while (member)
	{
		set_client_server_entity_int_value (member, INT_TYPE_FORMATION_POSITION, get_local_entity_int_value (member, INT_TYPE_GROUP_MEMBER_NUMBER));

		member = get_local_entity_child_succ (member, LIST_TYPE_MEMBER);
	}
}
Esempio n. 21
0
int pause_local_entity_sound_type (entity *en, entity_sub_types type, float delay)
{
	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)
			{
				//
				// "pause" sound
				//

				if (raw->valid_sound_effect)
				{
					raw->valid_sound_effect = FALSE;

					raw->valid_effect_lifetime = delay;

					count ++;
				}
			}
		}

		spec = get_local_entity_child_succ (spec, LIST_TYPE_SPECIAL_EFFECT);
	}

	return count;
}
Esempio n. 22
0
void group_kill_all_members (entity *en)
{
	entity
		*next,
		*member;

	ASSERT (get_comms_model () == COMMS_MODEL_SERVER);

	member = get_local_entity_first_child (en, LIST_TYPE_MEMBER);

	while (member)
	{
		next = get_local_entity_child_succ (member, LIST_TYPE_MEMBER);

		kill_client_server_entity (member);

		member = next;
	}
}
Esempio n. 23
0
unsigned int assign_specific_engage_task_to_group (entity *group, entity *task, unsigned int valid_members)
{
	entity
		*member;

	unsigned int
		member_number;

	ASSERT (group);

	ASSERT (task);

	ASSERT (get_comms_model () == COMMS_MODEL_SERVER);
		
	member = get_local_entity_first_child (group, LIST_TYPE_MEMBER);

	while ((member) && (valid_members))
	{
		//
		// Only assign AI entities to ENGAGE tasks
		//
		
		if (get_local_entity_int_value (member, INT_TYPE_PLAYER) == ENTITY_PLAYER_AI)
		{
			if (get_local_entity_int_value (member, INT_TYPE_ENGAGE_ENEMY))
			{
				member_number = (1 << get_local_entity_int_value (member, INT_TYPE_GROUP_MEMBER_NUMBER));
		
				if (member_number & valid_members)
				{
					if (assign_new_task_to_group_member (group, member, task, NULL))
					{
						valid_members &= (~member_number);
					}
				}
			}
		}
		
		member = get_local_entity_child_succ (member, LIST_TYPE_MEMBER);
	}

	return valid_members;
}
Esempio n. 24
0
void destroy_client_server_sound_effects (entity *en)
{
	entity
		*spec,
		*next;

	spec = get_local_entity_first_child (en, LIST_TYPE_SPECIAL_EFFECT);
	
	while (spec)
	{
		next = get_local_entity_child_succ (spec, LIST_TYPE_SPECIAL_EFFECT);

		if (get_local_entity_type (spec) == ENTITY_TYPE_SOUND_EFFECT)
		{
			destroy_client_server_entity_family (spec);
		}

		spec = next;
	}
}
Esempio n. 25
0
int check_group_members_awake (entity *group)
{

	entity
		*mb;

	mb = get_local_entity_first_child (group, LIST_TYPE_MEMBER);

	while (mb)
	{

		if (get_local_entity_float_value (mb, FLOAT_TYPE_SLEEP) > 0.0)
		{

			return FALSE;
		}

		mb = get_local_entity_child_succ (mb, LIST_TYPE_MEMBER);
	}

	return TRUE;
}
Esempio n. 26
0
int get_local_group_member_count (entity *group)
{

	entity
		*member;

	int
		count;

	count = 0;

	member = get_local_entity_first_child (group, LIST_TYPE_MEMBER);

	while (member)
	{

		count ++;

		member = get_local_entity_child_succ (member, LIST_TYPE_MEMBER);
	}

	return count;
}
Esempio n. 27
0
static void kill_local (entity *en)
{
	site
		*raw;

	vec3d
		pos;

	entity
		*task,
		*destroy_task;

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

	#if DEBUG_MODULE

	debug_log_entity_args (ENTITY_DEBUG_LOCAL, ENTITY_DEBUG_KILL, en);

	#endif

	raw = get_local_entity_data (en);

	////////////////////////////////////////
	//
	// 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 ("ST_DSTRY: killing site, 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

	//
	// site
	//

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

	// must be done BEFORE alive flag set
	subtract_local_entity_importance_from_keysite (en);

	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);

		get_local_entity_vec3d (en, VEC3D_TYPE_POSITION, &pos);

		pos.y = get_3d_terrain_elevation (pos.x, pos.z);

		create_client_server_crater (CRATER_TYPE_LARGE_EXPLOSION, &pos);
	}

	//
	// must be done AFTER object explosion
	//

	raw->fix.object_3d_shape = get_3d_object_destroyed_object_index (raw->fix.object_3d_shape);
}
Esempio n. 28
0
void pack_effect_data (entity *en, effect *raw, pack_modes mode)
{
	ASSERT ((mode >= 0) && (mode < NUM_PACK_MODES));

	switch (mode)
	{
		////////////////////////////////////////
		case PACK_MODE_SERVER_SESSION:
		case PACK_MODE_CLIENT_SESSION:
		////////////////////////////////////////
		{
			//
			// some effects should never be packed up ( should be re-constructed when the vehicle is unpacked )
			//

			ASSERT (!effect_database [raw->sub_type].constructed_locally);

			pack_int_value (en, INT_TYPE_ENTITY_SUB_TYPE, raw->sub_type);

			pack_vec3d (en, VEC3D_TYPE_POSITION, &raw->position);

			/////////////////////////////////////////////////////////////////
			//
			// Special effect packing, manually packing link data
			//
			if (raw->special_effect_link.parent)
			{
				list_link
					link;

				entity
					*spec;

				pack_int_value (en, INT_TYPE_VALID, TRUE);

				//
				// parent
				//

				link.parent = raw->special_effect_link.parent;

				//
				// succ : search forwards through special effect list for valid child succ
				//

				spec = get_local_entity_child_succ (en, LIST_TYPE_SPECIAL_EFFECT);

				while (TRUE)
				{
					if ((spec == NULL) ||
							(effect_database [get_local_entity_int_value (spec, INT_TYPE_ENTITY_SUB_TYPE)].constructed_locally == FALSE))
					{
						link.child_succ = spec;

						break;
					}

					spec = get_local_entity_child_succ (spec, LIST_TYPE_SPECIAL_EFFECT);
				}

				//
				// pred : search backwards through special effect list for valid child pred
				//

				spec = get_local_entity_child_pred (en, LIST_TYPE_SPECIAL_EFFECT);

				while (TRUE)
				{
					if ((spec == NULL) ||
							(effect_database [get_local_entity_int_value (spec, INT_TYPE_ENTITY_SUB_TYPE)].constructed_locally == FALSE))
					{
						link.child_pred = spec;

						break;
					}

					spec = get_local_entity_child_pred (spec, LIST_TYPE_SPECIAL_EFFECT);
				}

				pack_list_link (en, LIST_TYPE_SPECIAL_EFFECT, &link);
			}
			else
			{

				pack_int_value (en, INT_TYPE_VALID, FALSE);
			}
			/////////////////////////////////////////////////////////////////

			// update_link

			break;
		}
		////////////////////////////////////////
		case PACK_MODE_BROWSE_SESSION:
		////////////////////////////////////////
		{
			break;
		}
		////////////////////////////////////////
		case PACK_MODE_UPDATE_ENTITY:
		////////////////////////////////////////
		{
			//
			// cannot update entity at this level as the update may not apply to all entity types below
			//

			break;
		}
	}
}
Esempio n. 29
0
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);
}
Esempio n. 30
0
void update_client_server_entities (void)
{
	entity
		*en;

	float
		delta_time;

	int
		loop,
		iterations;

	ASSERT (get_update_entity ());

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

	iterations = 1;

	if (!locked_frame_rate)
	{
	
		delta_time = get_delta_time ();
	
		iterations = set_entity_update_frame_rate (command_line_entity_update_frame_rate);
	}

	for (loop = 0; loop < iterations; loop ++)
	{
	
		////////////////////////////////////////

		//
		// update_entities is coded around the entity system to avoid spinning through
		// the update list twice (which Vtune shows up as slow). MB_INT sets and gets
		// the values. You may only set the value to true. It is set to false by the
		// memset below.
		//

		memset (updated_entities, 0, MAX_NUM_ENTITIES / (sizeof (unsigned int) * 8));

		//
		// replaces....
		//
		/*
		en = get_local_entity_first_child (get_update_entity (), LIST_TYPE_UPDATE);
	
		while (en)
		{

			set_local_entity_int_value (en, INT_TYPE_UPDATED, FALSE);
	
			en = get_local_entity_child_succ (en, LIST_TYPE_UPDATE);
		}
		*/
		////////////////////////////////////////

		en = get_local_entity_first_child (get_update_entity (), LIST_TYPE_UPDATE);
	
		while (en)
		{
			set_update_succ (get_local_entity_child_succ (en, LIST_TYPE_UPDATE));
	
			update_client_server_entity (en);
	
			set_local_entity_int_value (en, INT_TYPE_UPDATED, TRUE);
	
			en = get_update_succ ();
		}
	
		set_update_succ (NULL);

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

	if (!locked_frame_rate)
	{

		set_manual_delta_time (delta_time);
	}

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