Example #1
0
int assign_task_to_group (entity *group, entity *task_en, unsigned int valid_members)
{

	int
		sites_required;

	entity_sub_types
		sub_type,
		group_type;

	entity
		*force,
		*landing,
		*end_keysite,
		*start_keysite,
		*guide,
		*member;

	vec3d
		*pos;

	task
		*task_raw;

   debug_assert (get_comms_model () == COMMS_MODEL_SERVER);

	ASSERT (task_en);

	ASSERT (group);

	ASSERT (!(get_local_group_primary_task (group) && (get_local_entity_int_value (task_en, INT_TYPE_PRIMARY_TASK))));

	task_raw = ( task * ) get_local_entity_data (task_en);

	group_type = get_local_entity_int_value (group, INT_TYPE_ENTITY_SUB_TYPE);

	member = get_local_entity_first_child (group, LIST_TYPE_MEMBER);

	// don't if no members or if the group is a CARRIER
	if (!member)
	{
		return FALSE;
	}

	if (get_local_entity_int_value (group, INT_TYPE_ENTITY_SUB_TYPE) == ENTITY_SUB_TYPE_GROUP_ASSAULT_SHIP)
	{
		if (task_raw->sub_type != ENTITY_SUB_TYPE_TASK_ENGAGE)
		{
			return FALSE;
		}
	}

	//
	// check for invalid tasks
	//
	
	switch (task_raw->sub_type)
	{
		case ENTITY_SUB_TYPE_TASK_LANDING:
		case ENTITY_SUB_TYPE_TASK_LANDING_HOLDING:
		case ENTITY_SUB_TYPE_TASK_TAKEOFF:
		case ENTITY_SUB_TYPE_TASK_TAKEOFF_HOLDING:
		{
			#ifdef DEBUG

			debug_fatal ("ASSIGN: Invalid task type (%s) for assign_task_to_group", get_local_entity_string (task_en, STRING_TYPE_FULL_NAME));

			#endif

			return FALSE;
		}
	}

	//
	// Create route
	//

	if (get_local_entity_int_value (group, INT_TYPE_GROUP_LIST_TYPE) == LIST_TYPE_KEYSITE_GROUP)
	{
		start_keysite = get_local_entity_parent (group, LIST_TYPE_KEYSITE_GROUP);
	}
	else
	{
//		start_keysite = get_closest_keysite (NUM_ENTITY_SUB_TYPE_KEYSITES, task_raw->side, get_local_entity_vec3d_ptr (group, VEC3D_TYPE_POSITION), 1.0 * KILOMETRE, NULL);
		start_keysite = NULL;
	}

	pos = get_local_entity_vec3d_ptr (task_en, VEC3D_TYPE_STOP_POSITION);

	force = get_local_force_entity ( ( entity_sides ) get_local_entity_int_value (task_en, INT_TYPE_SIDE) );

	sub_type = group_database [group_type].default_landing_type;

	landing = NULL;

	end_keysite = NULL;

	if (get_local_entity_int_value (task_en, INT_TYPE_ASSESS_LANDING))
	{
		ASSERT (start_keysite);

		end_keysite = ( entity * ) get_local_entity_ptr_value (task_en, PTR_TYPE_RETURN_KEYSITE);

		if (end_keysite)
		{
			//
			// check end keysite has suitble free landing sites
			//

			if (start_keysite != end_keysite)
			{
				//
				// if end keysite == start keysite then keysite MUST have enough sites because the aircraft are already there
				//
				
				sites_required = get_local_group_member_count (group);
	
				if (get_keysite_landing_sites_available (end_keysite, sub_type) < sites_required)
				{
					//
					// END keysite was specified - but no free landing sites for this group
					//
					
					return FALSE;
				}
			}
		}
		else
		{
			//
			// No END keysite specified so return to start keysite
			//

			end_keysite = start_keysite;

			set_local_entity_ptr_value (task_en, PTR_TYPE_RETURN_KEYSITE, end_keysite);
		}

		ASSERT (end_keysite);

		landing = get_local_entity_landing_entity (end_keysite, group_database [get_local_entity_int_value (group, INT_TYPE_ENTITY_SUB_TYPE)].default_landing_type);
	}

	if (create_generic_waypoint_route (group, task_en, end_keysite, NULL, NULL, NULL, 0))
	{
		#if DEBUG_MODULE

		debug_log ("ASSIGN: group %s (%d) assigned to task %s (%d)",
							get_local_entity_string (group, STRING_TYPE_FULL_NAME),
							get_local_entity_index (group),
							get_local_entity_string (task_en, STRING_TYPE_FULL_NAME),
							get_local_entity_index (task_en));

		#endif

		//
		// Assign task
		//

		guide = push_task_onto_group_task_stack (group, task_en, valid_members);

		assign_task_to_group_members (group, guide, valid_members);

		return TRUE;
	}

	return FALSE;
}
Example #2
0
void repair_landing_entity_locks (pack_modes mode)
{

	entity
		*en,
		*guide,
		*group,
		*keysite,
		*landing,
		*task;

	int
		landing_flag;

	if (mode != PACK_MODE_SERVER_SESSION)
	{
		return;
	}

	en = get_local_entity_list ();

	while (en)
	{

		landing_flag = FALSE;

		// debug
		if (get_local_entity_type (en) != ENTITY_TYPE_GROUP)
		// debug
		{
	
			if ((get_local_entity_int_value (en, INT_TYPE_IDENTIFY_AIRCRAFT)) || (get_local_entity_int_value (en, INT_TYPE_IDENTIFY_VEHICLE)))
			{
	
				guide = get_local_entity_parent (en, LIST_TYPE_FOLLOWER);
	
				if (guide)
				{
	
					task = get_local_entity_parent (guide, LIST_TYPE_GUIDE);
	
					if (task)
					{
	
						switch (get_local_entity_int_value (task, INT_TYPE_ENTITY_SUB_TYPE))
						{
	
							case ENTITY_SUB_TYPE_TASK_LANDING:
							{
	
								//
								// LANDING
								//
						
								landing = get_local_entity_parent (task, LIST_TYPE_ASSIGNED_TASK);
		
								ASSERT (landing);
		
								#if DEBUG_MODULE
		
								debug_log ("EN_SESSN: LOCK_REPAIRING: %s landing lock for %s (%d) locks (total %d, free %d, landing %d, landed %d takeoff %d)", get_local_entity_string (keysite, STRING_TYPE_KEYSITE_NAME), get_local_entity_type_name (en), get_local_entity_index (en),
								get_local_entity_int_value (landing, INT_TYPE_TOTAL_LANDING_SITES),
								get_local_entity_int_value (landing, INT_TYPE_FREE_LANDING_SITES),
								get_local_entity_int_value (landing, INT_TYPE_LANDING_LOCK),
								get_local_entity_int_value (landing, INT_TYPE_LANDED_LOCK),
								get_local_entity_int_value (landing, INT_TYPE_TAKEOFF_LOCK));
		
								#endif
		
								notify_local_entity (ENTITY_MESSAGE_LOCK_LANDING_ROUTE, landing, en);
		
								landing_flag = TRUE;
	
								break;
							}
	
							case ENTITY_SUB_TYPE_TASK_LANDING_HOLDING:
							{
	
								//
								// LANDING HOLDING
								//
						
								landing_flag = TRUE;
	
								break;
							}
	
							case ENTITY_SUB_TYPE_TASK_TAKEOFF:
							{
			
								landing = get_local_entity_parent (task, LIST_TYPE_ASSIGNED_TASK);
		
								keysite = get_local_entity_parent (landing, LIST_TYPE_LANDING_SITE);
	
								#if DEBUG_MODULE
		
								debug_log ("EN_SESSN: LOCK_REPAIRING: %s takeoff lock for %s (%d) total %d, free %d, locks (landing %d, landed %d takeoff %d)", get_local_entity_string (keysite, STRING_TYPE_KEYSITE_NAME), get_local_entity_type_name (en), get_local_entity_index (en),
									get_local_entity_int_value (landing, INT_TYPE_TOTAL_LANDING_SITES),
									get_local_entity_int_value (landing, INT_TYPE_FREE_LANDING_SITES),
									get_local_entity_int_value (landing, INT_TYPE_LANDING_LOCK),
									get_local_entity_int_value (landing, INT_TYPE_LANDED_LOCK),
									get_local_entity_int_value (landing, INT_TYPE_TAKEOFF_LOCK));
		
								#endif
			
								notify_local_entity (ENTITY_MESSAGE_LOCK_TAKEOFF_ROUTE, landing, en);
	
								break;
							}
						}
					}
				}
	
				//
				// LANDED
				//
	
				if ((get_local_entity_int_value (en, INT_TYPE_LANDED)) || (landing_flag))
				{
	
					group = get_local_entity_parent (en, LIST_TYPE_MEMBER);
	
					keysite = get_local_entity_parent (group, LIST_TYPE_KEYSITE_GROUP);

					if (get_local_entity_type (keysite) != ENTITY_TYPE_KEYSITE)
					{
			
						ASSERT (get_local_entity_type (en) == ENTITY_TYPE_SHIP_VEHICLE);
			
						ASSERT (get_local_entity_type (keysite) == ENTITY_TYPE_FORCE);
			
						#if DEBUG_MODULE
			
						debug_log ("LANDING: %s. Not repairing locks", get_local_entity_string (en, STRING_TYPE_FULL_NAME));
			
						#endif

					}
					else
					{
		
						landing = get_local_entity_landing_entity (keysite, group_database [get_local_entity_int_value (group, INT_TYPE_ENTITY_SUB_TYPE)].default_landing_type);
		
						#if DEBUG_MODULE
		
						debug_log ("EN_SESSN: LOCK_REPAIRING: %s landed site lock for %s (%d) total %d, free %d, locks (landing %d, landed %d takeoff %d)", get_local_entity_string (keysite, STRING_TYPE_KEYSITE_NAME), get_local_entity_type_name (en), get_local_entity_index (en),
							get_local_entity_int_value (landing, INT_TYPE_TOTAL_LANDING_SITES),
							get_local_entity_int_value (landing, INT_TYPE_FREE_LANDING_SITES),
							get_local_entity_int_value (landing, INT_TYPE_LANDING_LOCK),
							get_local_entity_int_value (landing, INT_TYPE_LANDED_LOCK),
							get_local_entity_int_value (landing, INT_TYPE_TAKEOFF_LOCK));
		
						#endif
			
						notify_local_entity (ENTITY_MESSAGE_LOCK_LANDING_SITE, landing, en);
					}
				}
			}
		}

		en = get_local_entity_succ (en);
	}
}
Example #3
0
entity *regen_update (entity *en)
{

	regen_management_element
		*m1;

	entity_sub_types
		member_type,
		group_type;

	entity
		*wp,
		*task,
		*group,
		*member,
		*building,
		*force_en,
		*landing,
		*keysite;

	unsigned int
		member_number;

	int
		reserve_count;

	force
		*force_raw;

	regen
		*raw;

	regen_list_element
		*e1;

	raw = (regen *) get_local_entity_data (en);

	wp = get_local_entity_parent (en, LIST_TYPE_CURRENT_WAYPOINT);

	task = get_local_entity_parent (wp, LIST_TYPE_WAYPOINT);

	landing = get_local_entity_parent (task, LIST_TYPE_UNASSIGNED_TASK);
			
	keysite = get_local_entity_parent (landing, LIST_TYPE_LANDING_SITE);

	force_en = get_local_force_entity ((entity_sides) raw->side);

	force_raw = (force *) get_local_entity_data (force_en);

	group_type = NUM_ENTITY_SUB_TYPE_GROUPS;

	m1 = &regen_manager [raw->side][raw->sub_type];

	//
	// is there anything in the regen queues?
	//
	
	if (m1->count == 0)
	{
		return NULL;
	}

	//
	// Can regen operate
	//

	building = raw->member_root.first_child;

	if ((!get_local_entity_int_value (building, INT_TYPE_ALIVE)) || (get_local_entity_int_value (keysite, INT_TYPE_KEYSITE_USABLE_STATE) != KEYSITE_STATE_USABLE))
	{
		#if DEBUG_MODULE

		debug_log ("RG_UPDT: keysite %s too damaged to regen", get_local_entity_string (keysite, STRING_TYPE_KEYSITE_NAME));

		#endif

		return NULL;
	}

	e1 = &regen_queue [raw->side][raw->sub_type][m1->front];

	ASSERT (e1->type != -1);
	ASSERT (e1->sub_type != -1);
	ASSERT (e1->group != -1);

	// is there a reserve of this type?
	if ((e1->type == ENTITY_TYPE_FIXED_WING) || (e1->type == ENTITY_TYPE_HELICOPTER))
	{
		reserve_count = force_raw->force_info_reserve_hardware[aircraft_database[e1->sub_type].force_info_catagory];
	}
	else
	{
		reserve_count = force_raw->force_info_reserve_hardware[vehicle_database[e1->sub_type].force_info_catagory];
	}

	if (reserve_count <= 0)
	{
		return NULL;
	}

	#if DEBUG_MODULE

	debug_log ("RG_UPDT: Trying to Regen %s Sub Type %d at %s - reserve count %d",
								get_entity_type_name (e1->type), e1->sub_type,
								get_local_entity_string (keysite, STRING_TYPE_KEYSITE_NAME), reserve_count);

	#endif

	//
	// Don't regen if PLAYER landed there
	//

	group = get_local_entity_first_child (keysite, LIST_TYPE_KEYSITE_GROUP);

	while (group)
	{
		member = get_local_entity_first_child (group, LIST_TYPE_MEMBER);

		while (member)
		{

			if (get_local_entity_int_value (member, INT_TYPE_PLAYER) != ENTITY_PLAYER_AI)
			{

				if (get_local_entity_int_value (member, INT_TYPE_LANDED))
				{
					#if DEBUG_MODULE

					debug_log ("RG_UPDT: PLAYER landed at keysite %s, can't regen", get_local_entity_string (keysite, STRING_TYPE_KEYSITE_NAME));

					#endif

					return NULL;
				}
			}

			member = get_local_entity_child_succ (member, LIST_TYPE_MEMBER);
		}

		group = get_local_entity_child_succ (group, LIST_TYPE_KEYSITE_GROUP);
	}

	group_type = e1->group;
	
	member_type = e1->sub_type;

	////////////////////////////////////////////////////////////////////////////
	// Dont regen people or transport aircraft in apache havoc campaign as airport might not be correct (landing routes etc)
	////////////////////////////////////////////////////////////////////////////
	if (get_local_entity_int_value (get_session_entity (), INT_TYPE_CAMPAIGN_REQUIRES_APACHE_HAVOC))
	{

		switch (get_local_entity_int_value (en, INT_TYPE_ENTITY_SUB_TYPE))
		{

			case ENTITY_SUB_TYPE_REGEN_PEOPLE:
			{

				#if DEBUG_MODULE

				debug_log ("RG_UPDT: Stopping Regening People - wrong warzone");

				#endif

				return NULL;
			}

			case ENTITY_SUB_TYPE_REGEN_FIXED_WING:
			{

				if (group_database [group_type].default_landing_type == ENTITY_SUB_TYPE_LANDING_FIXED_WING_TRANSPORT)
				{

					#if DEBUG_MODULE

					debug_log ("RG_UPDT: Stopping Regening Transport aircraft - wrong warzone");

					#endif

					return NULL;
				}
			}
		}
	}
	////////////////////////////////////////////////////////////////////////////
	// Dont regen people or transport aircraft in apache havoc campaign as airport might not be correct (landing routes etc)
	////////////////////////////////////////////////////////////////////////////

	if (group_type != NUM_ENTITY_SUB_TYPE_GROUPS)
	{

		int
			route_node;

		entity
			*building,
			*member,
			*guide,
			*group = NULL;

		group = create_landing_faction_members (keysite, member_type, group_type, 1, wp, &raw->position);

		if (group)
		{

			//
			// Assign closest route_node (only needed for routed vehicles)
			//

			if (get_local_entity_int_value (group, INT_TYPE_FRONTLINE))
			{
	
				route_node = get_closest_side_road_node ((entity_sides) get_local_entity_int_value (group, INT_TYPE_SIDE), &raw->position, 5 * KILOMETRE);
	
				set_client_server_entity_int_value (group, INT_TYPE_ROUTE_NODE, route_node);
			}

			//
			//
			//
			
			member = get_local_entity_first_child (group, LIST_TYPE_MEMBER);

			//
			// close members doors
			//

			close_client_server_entity_cargo_doors (member);

			close_client_server_entity_loading_doors (member);

			//
			// open building doors
			//

			building = get_local_entity_first_child (en, LIST_TYPE_MEMBER);

			open_client_server_entity_loading_doors (building);

			set_local_entity_float_value (building, FLOAT_TYPE_LOADING_DOOR_TIMER, 30.0);

			//
			// create guide entity for task (TEST)
			//

			// Debug for Transport aircraft.
			// Locate nearest Transport landing wp and insert into it
			if (group_database [group_type].default_landing_type == ENTITY_SUB_TYPE_LANDING_FIXED_WING_TRANSPORT)
			{

				float
					range,
					best_range;

				entity
					*transport_wp,
					*transport_task,
					*transport_landing;

				best_range = 999999999.0;

				transport_landing = get_local_entity_landing_entity (keysite, ENTITY_SUB_TYPE_LANDING_FIXED_WING_TRANSPORT);

				if (transport_landing)
				{
	
					transport_task = get_local_landing_entity_task (transport_landing, ENTITY_SUB_TYPE_TASK_LANDING);

					ASSERT (transport_task);
	
					transport_wp = get_local_entity_first_child (transport_task, LIST_TYPE_WAYPOINT);

					ASSERT (transport_wp);
	
					while (transport_wp)
					{
	
						range = get_sqr_2d_range (get_local_entity_vec3d_ptr (transport_wp, VEC3D_TYPE_POSITION), get_local_entity_vec3d_ptr (building, VEC3D_TYPE_POSITION));
	
						if (range < best_range)
						{
	
							wp = transport_wp;
	
							task = transport_task;
	
							best_range = range;
						}
	
						transport_wp = get_local_entity_child_succ (transport_wp, LIST_TYPE_WAYPOINT);
					}
				}
			}
			// Debug for Transport aircraft.

			member_number = get_local_entity_int_value (member, INT_TYPE_GROUP_MEMBER_NUMBER);

			guide = create_client_server_guide_entity (task, wp, (1 << member_number));

			attach_group_to_guide_entity (group, guide);

			attach_group_member_to_guide_entity (member, guide);

			//#if DEBUG_MODULE
			{

				entity
					*keysite;

				keysite = get_local_entity_parent (landing, LIST_TYPE_LANDING_SITE);

				member = get_local_entity_first_child (group, LIST_TYPE_MEMBER);

				debug_log ("RG_UPDT: %s creating %s (%d) at keysite %s free landing sites %d, reserved %d, lock %d, available lock: %d",
						entity_side_names [get_local_entity_int_value (keysite, INT_TYPE_SIDE)],
						get_local_entity_type_name (member),
						get_local_entity_index (member),
						get_local_entity_string (keysite, STRING_TYPE_KEYSITE_NAME), 
						get_local_entity_int_value (landing, INT_TYPE_FREE_LANDING_SITES),
						get_local_entity_int_value (landing, INT_TYPE_RESERVED_LANDING_SITES),
						get_local_entity_int_value (landing, INT_TYPE_LANDING_LOCK),
						check_available_landing_route_lock (landing)
						);

				if ((e1->type == ENTITY_TYPE_FIXED_WING) || (e1->type == ENTITY_TYPE_HELICOPTER))
				{
					debug_log("%s reserves left: %d",
							force_info_catagory_names[aircraft_database[e1->sub_type].force_info_catagory],
							force_raw->force_info_reserve_hardware[aircraft_database[e1->sub_type].force_info_catagory]
							);
				}
				else
				{
					debug_log("%s reserves left: %d",
							force_info_catagory_names[vehicle_database[e1->sub_type].force_info_catagory],
							force_raw->force_info_reserve_hardware[vehicle_database[e1->sub_type].force_info_catagory]
							);
				}

			}
			//#endif

			#if DEBUG_MODULE
			switch (e1->type)
			{
				case ENTITY_TYPE_FIXED_WING:
				case ENTITY_TYPE_HELICOPTER:
				{
					ASSERT (regen_ac_debug[e1->sub_type] > 0);

					break;
				}
				
				case ENTITY_TYPE_ROUTED_VEHICLE:
				case ENTITY_TYPE_SHIP_VEHICLE:
				case ENTITY_TYPE_PERSON:
				{
					ASSERT (regen_vh_debug[e1->sub_type] > 0);

					break;
				}
				
				default:
				{
					debug_fatal ("RG_UPDT: Unknown entity type for debug");
				}
				
			}
			#endif

			// update markers
			regen_queue_use ((entity_sides) raw->side, (raw->sub_type));

			return member;
		}
	}
	else
	{
		#if DEBUG_MODULE >= 2

		debug_log ("RG_UPDT: not creating anything at keysite %s free landing sites %d, reserved %d, lock %d",
						get_local_entity_string (keysite, STRING_TYPE_KEYSITE_NAME), 
						get_local_entity_int_value (landing, INT_TYPE_FREE_LANDING_SITES),
						get_local_entity_int_value (landing, INT_TYPE_RESERVED_LANDING_SITES),
						check_available_landing_route_lock (landing));

		#endif
	}

	return NULL;
}