Exemple #1
0
entity *get_closest_mobile_entity (vec3d *pos)
{

	entity
		*closest_en = NULL,
		*en;

	int
		range,
		best_range = INT_MAX;

	vec3d
		pos2,
		test_pos;

	en = get_local_entity_list ();

	while (en)
	{

		if (get_local_entity_int_value (en, INT_TYPE_IDENTIFY_MOBILE))
		{
	
			get_local_entity_vec3d (en, VEC3D_TYPE_POSITION, &pos2);
	
			test_pos.x = pos->x - pos2.x;
	
			test_pos.y = 0.0;
	
			test_pos.z = pos->z - pos2.z;
	
			range = get_3d_vector_magnitude (&test_pos);
	
			if (range < best_range)
			{
	
				best_range = range;
	
				closest_en = en;
	
				if (range < 1.0)
				{
				
					return closest_en;
				}
			}
		}

		en = get_local_entity_succ (en);
	}
	
	return closest_en;
}
Exemple #2
0
static void check_no_entities_in_use (void)
{
	if (first_used_entity)
	{
		debug_colour_log (DEBUG_COLOUR_RED, "WARNING! Entities still in use");

		#if DEBUG_MODULE
		{
			entity
				*en;

			en = first_used_entity;

			while (en)
			{
				debug_log ("->ENTITY: %s (index = %d)", get_local_entity_type_name (en), get_local_entity_index (en));

				en = get_local_entity_succ (en);
			}
		}
		#endif
	}
}
Exemple #3
0
void kill_entities_awaiting_update (void)
{

	entity
		*destroy_en,
		*en;

	en = get_local_entity_list ();

	while (en)
	{

		destroy_en = en;

		en = get_local_entity_succ (en);

		if (get_local_entity_int_value (destroy_en, INT_TYPE_KILL_NEXT_UPDATE))
		{

			destroy_client_server_entity_family (destroy_en);
		}
	}
}
Exemple #4
0
void unpack_local_city_building_data (pack_modes mode)
{

	city_building
		*raw;

	entity
		*destroy_en,
		*en;

	int
		city_building_count,
		city_building_alive;

	if ((mode != PACK_MODE_SERVER_SESSION) && (mode != PACK_MODE_CLIENT_SESSION))
	{

		return;
	}

	//
	// RLE encoded
	//

	debug_log ("RLE CITY BLOCK");

	en = get_local_entity_list ();

	city_building_count = unpack_int_value (NULL, INT_TYPE_LENGTH);

	city_building_alive = unpack_int_value (NULL, INT_TYPE_ALIVE);

	while (en)
	{

		destroy_en = en;

		en = get_local_entity_succ (en);

		if (get_local_entity_type (destroy_en) == ENTITY_TYPE_CITY_BUILDING)
		{

			if (city_building_count == 0)
			{

				city_building_count = unpack_int_value (NULL, INT_TYPE_LENGTH);

				city_building_alive = unpack_int_value (NULL, INT_TYPE_ALIVE);
			}

			city_building_count --;

			raw = get_local_entity_data (destroy_en);

			raw->fix.alive = city_building_alive;

			if (!city_building_alive)
			{
				raw->fix.object_3d_shape = get_3d_object_destroyed_object_index (raw->fix.object_3d_shape);
			}
		}
	}
}
Exemple #5
0
void pack_local_city_building_data (pack_modes mode)
{

	entity
		*en;

	city_building
		*raw;

	int
		city_building_pack_size,
		city_building_count,
		city_building_alive,
		count;

	if ((mode != PACK_MODE_SERVER_SESSION) && (mode != PACK_MODE_CLIENT_SESSION))
	{

		return;
	}

	debug_log ("RLE CITY BLOCK");

	city_building_pack_size = 0;

	city_building_count = 0;

	city_building_alive = TRUE;

	count = 0;

	en = get_local_entity_list ();

	while (en)
	{

		if (get_local_entity_type (en) == ENTITY_TYPE_CITY_BUILDING)
		{

			count ++;

			raw = get_local_entity_data (en);

			if (city_building_alive == raw->fix.alive)
			{

				city_building_count ++;
			}
			else
			{

				pack_int_value (NULL, INT_TYPE_LENGTH, city_building_count);
				city_building_pack_size += NUM_LENGTH_BITS;

				pack_int_value (NULL, INT_TYPE_ALIVE, city_building_alive);
				city_building_pack_size += NUM_ALIVE_BITS;

				city_building_alive = raw->fix.alive;

				city_building_count = 1;
			}
		}

		en = get_local_entity_succ (en);
	}

	pack_int_value (NULL, INT_TYPE_LENGTH, city_building_count);
	city_building_pack_size += NUM_LENGTH_BITS;

	pack_int_value (NULL, INT_TYPE_ALIVE, city_building_alive);
	city_building_pack_size += NUM_ALIVE_BITS;

	//debug_log ("CB_PACK: packing %d city_building took %d bytes (%d bits)", count, city_building_pack_size / 8, city_building_pack_size);
}
Exemple #6
0
void unpack_local_site_updatable_data (pack_modes mode)
{

	site_updatable
		*raw;

	entity
		*en;

	int
		count,
		alive;

	if ((mode != PACK_MODE_SERVER_SESSION) && (mode != PACK_MODE_CLIENT_SESSION))
	{

		return;
	}

	//
	// RLE encoded
	//

	debug_log ("RLE SITE UPDATEABLE");

	en = get_local_entity_list ();

	count = unpack_int_value (NULL, INT_TYPE_LENGTH);

	alive = unpack_int_value (NULL, INT_TYPE_ALIVE);

	#if DEBUG_MODULE

	debug_log ("SU_PACK: unpacking count %d, alive %d", count, alive);

	#endif

	while (en)
	{

		if (get_local_entity_type (en) == ENTITY_TYPE_SITE_UPDATABLE)
		{

			if (count == 0)
			{

				count = unpack_int_value (NULL, INT_TYPE_LENGTH);

				alive = unpack_int_value (NULL, INT_TYPE_ALIVE);

				#if DEBUG_MODULE

				debug_log ("SU_PACK: unpacking count %d, alive %d", count, alive);

				#endif
			}

			count --;

			raw = get_local_entity_data (en);

			if (!alive)
			{
				delete_local_entity_from_parents_child_list (en, LIST_TYPE_UPDATE);

				// must be done BEFORE alive flag set, and BEFORE shape changed
//				subtract_local_entity_importance_from_keysite (en);

				raw->fix.object_3d_shape = get_3d_object_destroyed_object_index (raw->fix.object_3d_shape);
			}

			raw->fix.alive = alive;
		}

		en = get_local_entity_succ (en);
	}
}
Exemple #7
0
void pack_local_site_updatable_data (pack_modes mode)
{

	entity
		*en;

	site_updatable
		*raw;

	int
		pack_size,
		count,
		alive,
		total;

	if ((mode != PACK_MODE_SERVER_SESSION) && (mode != PACK_MODE_CLIENT_SESSION))
	{

		return;
	}

	debug_log ("RLE SITE UPDATEABLE");

	pack_size = 0;

	count = 0;

	alive = TRUE;

	total = 0;

	en = get_local_entity_list ();

	while (en)
	{

		if (get_local_entity_type (en) == ENTITY_TYPE_SITE_UPDATABLE)
		{

			total ++;

			raw = get_local_entity_data (en);

			if (alive == raw->fix.alive)
			{

				count ++;
			}
			else
			{

				pack_int_value (NULL, INT_TYPE_LENGTH, count);
				pack_size += NUM_LENGTH_BITS;

				pack_int_value (NULL, INT_TYPE_ALIVE, alive);
				pack_size += NUM_ALIVE_BITS;

				#if DEBUG_MODULE

				debug_log ("SU_PACK: packing count %d, alive %d", count, alive);

				#endif

				alive = raw->fix.alive;

				count = 1;
			}
		}

		en = get_local_entity_succ (en);
	}

	pack_int_value (NULL, INT_TYPE_LENGTH, count);
	pack_size += NUM_LENGTH_BITS;

	pack_int_value (NULL, INT_TYPE_ALIVE, alive);
	pack_size += NUM_ALIVE_BITS;

	#if DEBUG_MODULE

	debug_log ("SU_PACK: packing count %d, alive %d", count, alive);

	#endif

	//debug_log ("SU_PACK: packing %d entities took %d bytes (%d bits)", total, pack_size / 8, pack_size);
}
Exemple #8
0
void unpack_local_keysite_data (pack_modes mode)
{
   entity
      *en,
		*landing_en;

	landing
		*landing_raw;

   keysite
      *raw;

	int
		side,
		landing_lock,
		landed_lock,
		takeoff_lock,
		in_use,
		index;

   ASSERT (mode != PACK_MODE_UPDATE_ENTITY);

   if (mode == PACK_MODE_BROWSE_SESSION)
   {
      return;
   }

	en = get_local_entity_list ();

	while (en)
	{

		if (get_local_entity_type (en) == ENTITY_TYPE_KEYSITE)
		{

			//
			// unpack keysite
			//

			index = unpack_entity_safe_index ();

			raw = (keysite *) get_local_entity_data (en);

			raw->supplies.ammo_supply_level = unpack_float_value (en, FLOAT_TYPE_AMMO_SUPPLY_LEVEL);

			raw->supplies.fuel_supply_level = unpack_float_value (en, FLOAT_TYPE_FUEL_SUPPLY_LEVEL);

			raw->keysite_strength = unpack_float_value (en, FLOAT_TYPE_KEYSITE_STRENGTH);

			raw->keysite_maximum_strength = unpack_float_value (en, FLOAT_TYPE_KEYSITE_MAXIMUM_STRENGTH);

			raw->alive = unpack_int_value (en, INT_TYPE_ALIVE);

			side = unpack_int_value (en, INT_TYPE_SIDE);

			if (side != raw->side)
			{
				//
				// update I-Maps (remove old side)
				//

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

					if (mode == PACK_MODE_SERVER_SESSION)
					{
						update_imap_importance_level (en, FALSE);
					}
				}

				//
				// change side of keysite buildings
				//

				change_local_keysite_building_sides (en, (entity_sides) side);

				//
				// place into other sides force
				//

				delete_local_entity_from_parents_child_list (en, LIST_TYPE_KEYSITE_FORCE);

				insert_local_entity_into_parents_child_list (en, LIST_TYPE_KEYSITE_FORCE, get_local_force_entity ((entity_sides) side), NULL);

				if (mode == PACK_MODE_SERVER_SESSION)
				{
					// Must be done after removed from force
					update_imap_distance_to_friendly_base ((entity_sides) raw->side);
				}

				//
				// switch sides
				//

				raw->side = side;

				//
				// update I-Maps (add new side)
				//

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

					if (mode == PACK_MODE_SERVER_SESSION)
					{
						update_imap_importance_level (en, TRUE);

						update_keysite_distance_to_friendly_base (en, (entity_sides) side);
					}
				}
			}

			in_use = unpack_int_value (en, INT_TYPE_IN_USE);

			raw->keysite_id = unpack_int_value (en, INT_TYPE_KEYSITE_ID);

			raw->keysite_usable_state = unpack_int_value (en, INT_TYPE_KEYSITE_USABLE_STATE);

			if (raw->in_use != in_use)
			{
				//
				// Update I-Maps (in use flag changed)
				//

				raw->in_use = in_use;

				update_imap_sector_side (en, in_use);

				if (mode == PACK_MODE_SERVER_SESSION)
				{
					update_imap_importance_level (en, in_use);

					if (in_use)
					{
						update_keysite_distance_to_friendly_base (en, (entity_sides) side);
					}
					else
					{
						update_imap_distance_to_friendly_base ((entity_sides) side);
					}
				}
			}

			unpack_list_root (en, LIST_TYPE_UNASSIGNED_TASK, &raw->unassigned_task_root);
			unpack_list_root (en, LIST_TYPE_ASSIGNED_TASK, &raw->assigned_task_root);
			unpack_list_root (en, LIST_TYPE_COMPLETED_TASK, &raw->completed_task_root);

//			unpack_list_root (en, LIST_TYPE_KEYSITE_GROUP, &raw->keysite_group_root);

			unpack_list_root (en, LIST_TYPE_DIVISION_HEADQUARTERS, &raw->division_headquarters_root);

			if (unpack_int_value (en, INT_TYPE_VALID))
			{
				unpack_list_link (en, LIST_TYPE_CAMPAIGN_OBJECTIVE, &raw->campaign_objective_link);
			}

			#if DEBUG_MODULE

			debug_log ("KS_PACK: unpacking keysite %s", raw->keysite_name);

			#endif

			if (mode == PACK_MODE_SERVER_SESSION)
			{
				raw->repair_timer = unpack_float_value (en, FLOAT_TYPE_REPAIR_TIMER);

				raw->sleep = unpack_float_value (en, FLOAT_TYPE_SLEEP);

				raw->assist_timer = unpack_float_value (en, FLOAT_TYPE_ASSIST_TIMER);

				raw->assign_timer = unpack_float_value (en, FLOAT_TYPE_ASSIGN_TIMER);

				//
				// unpack landing data
				//

				landing_en = get_local_entity_first_child (en, LIST_TYPE_LANDING_SITE);
	
				while (landing_en)
				{
	
					landing_raw = (landing *) get_local_entity_data (landing_en);
	
					landing_raw->reserved_landing_sites = unpack_int_value (landing_en, INT_TYPE_RESERVED_LANDING_SITES);
	
					//landing_raw->free_landing_sites = unpack_int_value (en, INT_TYPE_FREE_LANDING_SITES);
					landing_raw->free_landing_sites = landing_raw->total_landing_sites;
	
					landing_lock = unpack_int_value (landing_en, INT_TYPE_LANDING_LOCK);
	
					landed_lock = unpack_int_value (landing_en, INT_TYPE_LANDED_LOCK);
	
					takeoff_lock = unpack_int_value (landing_en, INT_TYPE_TAKEOFF_LOCK);
	
					#if DEBUG_MODULE

					debug_log ("KS_PACK: %s (%d) unpacking %s landing entity, reserved %d, free %d, locks (saved :landing %d, landed %d, takeoff %d, calc landing %d, landed %d, takeoff %d)",
									raw->keysite_name,
									get_local_entity_index (en),
									entity_sub_type_landing_names [landing_raw->sub_type],
									landing_raw->reserved_landing_sites, landing_raw->free_landing_sites,
									landing_lock, landed_lock, takeoff_lock,
									landing_raw->landing_lock, landing_raw->landed_lock, landing_raw->takeoff_lock);

					if (landing_raw->landing_lock != landing_lock)
					{

						debug_log ("KS_PACK: %s %s landing entity needs landing_lock repairing", raw->keysite_name, entity_sub_type_landing_names [landing_raw->sub_type]);
					}
					if (landing_raw->landed_lock != landed_lock)
					{

						debug_log ("KS_PACK: %s %s landing entity needs landed_lock repairing", raw->keysite_name, entity_sub_type_landing_names [landing_raw->sub_type]);
					}
					if (landing_raw->takeoff_lock != takeoff_lock)
					{

						debug_log ("KS_PACK: %s %s landing entity needs takeoff_lock repairing", raw->keysite_name, entity_sub_type_landing_names [landing_raw->sub_type]);
					}

					#endif
	
					unpack_list_root (landing_en, LIST_TYPE_TAKEOFF_QUEUE, &landing_raw->takeoff_queue_root);

					landing_en = get_local_entity_child_succ (landing_en, LIST_TYPE_LANDING_SITE);
				}
			}
		}

		en = get_local_entity_succ (en);
	}
}
Exemple #9
0
void pack_local_keysite_data (pack_modes mode)
{
   entity
      *en,
		*landing_en;

	landing
		*landing_raw;

   keysite
      *raw;

   ASSERT (mode != PACK_MODE_UPDATE_ENTITY);

   if (mode == PACK_MODE_BROWSE_SESSION)
   {
      return;
   }

	en = get_local_entity_list ();

	while (en)
	{

		if (get_local_entity_type (en) == ENTITY_TYPE_KEYSITE)
		{

			//
			// pack keysite data
			//

			pack_entity_safe_ptr (en);

			raw = (keysite *) get_local_entity_data (en);

			pack_float_value (en, FLOAT_TYPE_AMMO_SUPPLY_LEVEL, raw->supplies.ammo_supply_level);

			pack_float_value (en, FLOAT_TYPE_FUEL_SUPPLY_LEVEL, raw->supplies.fuel_supply_level);

			pack_float_value (en, FLOAT_TYPE_KEYSITE_STRENGTH, raw->keysite_strength);

			pack_float_value (en, FLOAT_TYPE_KEYSITE_MAXIMUM_STRENGTH, raw->keysite_maximum_strength);

			pack_int_value (en, INT_TYPE_ALIVE, raw->alive);

			pack_int_value (en, INT_TYPE_SIDE, raw->side);

			pack_int_value (en, INT_TYPE_IN_USE, raw->in_use);

			pack_int_value (en, INT_TYPE_KEYSITE_ID, raw->keysite_id);

			pack_int_value (en, INT_TYPE_KEYSITE_USABLE_STATE, raw->keysite_usable_state);

			pack_list_root (en, LIST_TYPE_UNASSIGNED_TASK, &raw->unassigned_task_root);
			pack_list_root (en, LIST_TYPE_ASSIGNED_TASK, &raw->assigned_task_root);
			pack_list_root (en, LIST_TYPE_COMPLETED_TASK, &raw->completed_task_root);

//			pack_list_root (en, LIST_TYPE_KEYSITE_GROUP, &raw->keysite_group_root);

			pack_list_root (en, LIST_TYPE_DIVISION_HEADQUARTERS, &raw->division_headquarters_root);

			if (raw->campaign_objective_link.parent)
			{
				pack_int_value (en, INT_TYPE_VALID, TRUE);

				pack_list_link (en, LIST_TYPE_CAMPAIGN_OBJECTIVE, &raw->campaign_objective_link);
			}
			else
			{
				pack_int_value (en, INT_TYPE_VALID, FALSE);
			}

			#if DEBUG_MODULE

			debug_log ("KS_PACK: packing up keysite %s", raw->keysite_name);

			#endif

			if (mode == PACK_MODE_SERVER_SESSION)
			{
	
				pack_float_value (en, FLOAT_TYPE_REPAIR_TIMER, raw->repair_timer);

				pack_float_value (en, FLOAT_TYPE_SLEEP, raw->sleep);

				pack_float_value (en, FLOAT_TYPE_ASSIST_TIMER, raw->assist_timer);

				pack_float_value (en, FLOAT_TYPE_ASSIGN_TIMER, raw->assign_timer);

				//
				// pack landing data
				//
	
				landing_en = get_local_entity_first_child (en, LIST_TYPE_LANDING_SITE);
	
				while (landing_en)
				{
	
					landing_raw = (landing *) get_local_entity_data (landing_en);
	
					pack_int_value (landing_en, INT_TYPE_RESERVED_LANDING_SITES, landing_raw->reserved_landing_sites);
	
					//pack_int_value (en, INT_TYPE_FREE_LANDING_SITES, landing_raw->free_landing_sites);
	
					pack_int_value (landing_en, INT_TYPE_LANDING_LOCK, landing_raw->landing_lock);
	
					pack_int_value (landing_en, INT_TYPE_LANDED_LOCK, landing_raw->landed_lock);
	
					pack_int_value (landing_en, INT_TYPE_TAKEOFF_LOCK, landing_raw->takeoff_lock);

					pack_list_root (landing_en, LIST_TYPE_TAKEOFF_QUEUE, &landing_raw->takeoff_queue_root);

					#if DEBUG_MODULE

					debug_log ("KS_PACK: packing up %s landing entity, reserved %d, free %d, locks (landing %d, landed %d, takeoff %d)", entity_sub_type_landing_names [landing_raw->sub_type], landing_raw->reserved_landing_sites, landing_raw->free_landing_sites, landing_raw->landing_lock, landing_raw->landed_lock, landing_raw->takeoff_lock );

					#endif
	
					landing_en = get_local_entity_child_succ (landing_en, LIST_TYPE_LANDING_SITE);
				}
			}

		}

		en = get_local_entity_succ (en);
	}
}
Exemple #10
0
int pack_session (char *buffer, int *buffer_size, pack_modes mode)
{
	entity
		*en;

	int
		packed_data_size,
		pack_buffer_overflow;

	#if DEBUG_MODULE

	int
		pack_size,
		last_pack_size;

	#endif

	ASSERT (buffer);

	ASSERT (*buffer_size > 0);

	ASSERT ((mode >= 0) && (mode < NUM_PACK_MODES));

	#if !DEBUG_MODULE_PACK_ALL

	disable_debug_log_entity_args ();

	#endif

	#if DEBUG_MODULE_PACK_ALL

	debug_log (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
	debug_log ("PACK SESSION: buffer_size = %d", *buffer_size);
	debug_log (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");

	#endif

	open_pack_buffer (buffer, *buffer_size);

	//
	// kill any entities that are marked 'kill next update'
	//

	//kill_entities_awaiting_update ();

	//
	// Unlink all killed "local_only" entities from lists. Just
	//

	#if DEBUG_MODULE

	debug_log ("EN_SESSN: starting to pack current_pack_buffer_bit_size = %d", get_current_pack_buffer_bit_size ());

	memset (entity_pack_size_array, 0, sizeof (entity_pack_size_type) * NUM_ENTITY_TYPES);

	#endif

	//
	// pack sector entities first
	//

	pack_local_sector_data (mode);

	#if DEBUG_MODULE

	debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after sector", get_current_pack_buffer_bit_size ());

	#endif

	//
	// pack pylon entities
	//

	pack_local_pylon_data (mode);

	#if DEBUG_MODULE

	debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after pylon", get_current_pack_buffer_bit_size ());

	#endif

	//
	// pack segment entities
	//

	pack_local_segment_data (mode);

	//
	// pack bridge entities
	//

	pack_local_bridge_data (mode);

	//
	// pack Session and Force entities first
	//

	pack_local_session_data (mode);

	#if DEBUG_MODULE

	debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after session", get_current_pack_buffer_bit_size ());

	#endif
	
	en = get_local_entity_first_child (get_session_entity (), LIST_TYPE_FORCE);

	while (en)
	{
		pack_local_force_data (en, mode);

		en = get_local_entity_child_succ (en, LIST_TYPE_FORCE);
	}

	#if DEBUG_MODULE

	debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after force", get_current_pack_buffer_bit_size ());

	#endif
	
	//
	// pack remaining entities
	//

	en = get_local_entity_list ();

	#if DEBUG_MODULE

	debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after segment", get_current_pack_buffer_bit_size ());

	last_pack_size = get_current_pack_buffer_bit_size ();

	#endif

	while (en)
	{
		pack_local_entity_data (en, mode);

		#if DEBUG_MODULE

		debug_log ("EN_SESSN: packing entity %s index %d, pack_buffer_size %d", get_local_entity_type_name (en), get_local_entity_index (en), get_current_pack_buffer_bit_size () / 8);

		pack_size = get_current_pack_buffer_bit_size () - last_pack_size;

		last_pack_size = get_current_pack_buffer_bit_size ();

		entity_pack_size_array [en->type].count ++;

		entity_pack_size_array [en->type].size += pack_size;

		#endif

		en = get_local_entity_succ (en);
	}

	//
	// mark end of session data
	//

	pack_entity_type (ENTITY_TYPE_UNKNOWN);

	#if DEBUG_MODULE

	debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after session_data", get_current_pack_buffer_bit_size ());

	#endif

	//
	// pack other entity data
	//

	pack_local_keysite_data (mode);

	#if DEBUG_MODULE

	debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after keysite", get_current_pack_buffer_bit_size ());

	#endif

	pack_local_regen_data (mode);

	#if DEBUG_MODULE

	debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after regen", get_current_pack_buffer_bit_size ());

	#endif

	pack_local_city_building_data (mode);

	#if DEBUG_MODULE

	debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after city_building", get_current_pack_buffer_bit_size ());

	#endif

	pack_local_scenic_data (mode);

	#if DEBUG_MODULE

	debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after scenic", get_current_pack_buffer_bit_size ());

	#endif

	pack_local_site_data (mode);

	#if DEBUG_MODULE

	debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after site", get_current_pack_buffer_bit_size ());

	#endif

	pack_local_site_updatable_data (mode);

	#if DEBUG_MODULE

	debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after site_updatable", get_current_pack_buffer_bit_size ());

	#endif

	pack_local_anti_aircraft_data (mode);

	#if DEBUG_MODULE

	debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after anti_aircraft", get_current_pack_buffer_bit_size ());

	#endif

	pack_local_group_data (mode);

	#if DEBUG_MODULE

	debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after local groups", get_current_pack_buffer_bit_size ());

	#endif

	pack_local_division_database (mode);

	pack_local_message_log (mode);

	pack_group_callsign_database (mode);

	#if LANDING_ROUTE_CHECK

	pack_debug_entity_landing_locks (mode);

	#endif

	pack_buffer_overflow = get_pack_buffer_overflow ();

	packed_data_size = close_pack_buffer ();

	#if DEBUG_MODULE_PACK_ALL

	debug_log (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
	debug_log ("PACK SESSION: packed_data_size = %d", packed_data_size);
	debug_log ("PACK SESSION: pack_buffer_overflow = %d", pack_buffer_overflow);
	debug_log (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");

	#endif

	*buffer_size = packed_data_size;

	#if !DEBUG_MODULE_PACK_ALL

	enable_debug_log_entity_args ();

	#endif

	#if DEBUG_MODULE
	{

	int
		loop;

		for (loop = 0; loop < NUM_ENTITY_TYPES; loop ++)
		{

			if (entity_pack_size_array [loop].size)
			{
		
				debug_log ("EN_SESSN: %d bytes (%f each) for %d entity %s",
								entity_pack_size_array [loop].size / 8,
								(float) (entity_pack_size_array [loop].size / 8) / entity_pack_size_array [loop].count,
								entity_pack_size_array [loop].count, entity_type_names [loop]);
			}
		}
	}
	#endif

	//
	//
	//

	return (pack_buffer_overflow);
}
Exemple #11
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);
	}
}
Exemple #12
0
void unpack_local_bridge_data (pack_modes mode)
{
   entity
      *en;

   bridge
      *raw;

	int
		dead_bridge_count,
		alive,
		count;

   ASSERT (mode != PACK_MODE_UPDATE_ENTITY);

   if (mode != PACK_MODE_SERVER_SESSION)
   {
      return;
   }

	//
	// unpack alive status for each bridge
	//

	debug_log ("RLE BRIDGE");

	count = 0;

	count = unpack_int_value (NULL, INT_TYPE_LENGTH);

	alive = unpack_int_value (NULL, INT_TYPE_ALIVE);

	#if DEBUG_MODULE

	debug_log ("BR_PACK: unpacking count %d, alive %d", count, alive);

	#endif

	en = get_local_entity_list ();

	while (en)
	{
		if (en->type == ENTITY_TYPE_BRIDGE)
		{
			if (count == 0)
			{
				count = unpack_int_value (NULL, INT_TYPE_LENGTH);

				alive = unpack_int_value (NULL, INT_TYPE_ALIVE);

				#if DEBUG_MODULE
			
				debug_log ("BR_PACK: unpacking count %d, alive %d", count, alive);
			
				#endif
			}

			count --;

			raw = (bridge *) get_local_entity_data (en);

			raw->alive = alive;

			if (!alive)
			{
				//
				// Break road network link
				//

				dead_bridge_count = get_road_link_breaks (raw->start_node, raw->end_node);

				dead_bridge_count ++;
				
				set_road_link_breaks (raw->start_node, raw->end_node, dead_bridge_count);
			}
		}

		en = get_local_entity_succ (en);
	}
}
Exemple #13
0
void pack_local_bridge_data (pack_modes mode)
{
   entity
      *en;

   bridge
      *raw;

	int
		alive,
		count;

   ASSERT (mode != PACK_MODE_UPDATE_ENTITY);

   if (mode != PACK_MODE_SERVER_SESSION)
   {
      return;
   }

	//
	// RLE bridge alive flags
	//

	count = 0;

	alive = TRUE;

	debug_log ("RLE BRIDGE");

	en = get_local_entity_list ();

	while (en)
	{

		if (get_local_entity_type (en) == ENTITY_TYPE_BRIDGE)
		{

			raw = (bridge *) get_local_entity_data (en);

			if (alive == raw->alive)
			{
				count ++;
			}
			else
			{

				pack_int_value (NULL, INT_TYPE_LENGTH, count);

				pack_int_value (NULL, INT_TYPE_ALIVE, alive);

				#if DEBUG_MODULE

				debug_log ("BR_PACK: packing count %d, alive %d", count, alive);

				#endif

				alive = raw->alive;

				count = 1;
			}
		}
	
		en = get_local_entity_succ (en);
	}

	pack_int_value (NULL, INT_TYPE_LENGTH, count);

	pack_int_value (NULL, INT_TYPE_ALIVE, alive);

	#if DEBUG_MODULE

	debug_log ("BR_PACK: packing count %d, alive %d", count, alive);

	#endif
}
Exemple #14
0
void dump_aircraft_and_vehicle_count (void)
{
	entity
		*en;

	entity_sub_types
		sub_type;

	int
		total_count,
		total_blue_aircraft_count,
		total_blue_vehicle_count,
		total_red_aircraft_count,
		total_red_vehicle_count,
		blue_aircraft_count[NUM_ENTITY_SUB_TYPE_AIRCRAFT],
		blue_vehicle_count[NUM_ENTITY_SUB_TYPE_VEHICLES],
		red_aircraft_count[NUM_ENTITY_SUB_TYPE_AIRCRAFT],
		red_vehicle_count[NUM_ENTITY_SUB_TYPE_VEHICLES];

	total_count = 0;

	total_blue_aircraft_count = 0;
	total_blue_vehicle_count = 0;

	total_red_aircraft_count = 0;
	total_red_vehicle_count = 0;

	memset (blue_aircraft_count, 0, sizeof (blue_aircraft_count));
	memset (blue_vehicle_count, 0, sizeof (blue_vehicle_count));

	memset (red_aircraft_count, 0, sizeof (red_aircraft_count));
	memset (red_vehicle_count, 0, sizeof (red_vehicle_count));

	en = first_used_entity;

	while (en)
	{
		sub_type = get_local_entity_int_value (en, INT_TYPE_ENTITY_SUB_TYPE);

		if (get_local_entity_int_value (en, INT_TYPE_IDENTIFY_AIRCRAFT))
		{
			ASSERT (entity_sub_type_aircraft_valid (sub_type));

			if (get_local_entity_int_value (en, INT_TYPE_SIDE) == ENTITY_SIDE_BLUE_FORCE)
			{
				total_count++;

				blue_aircraft_count[sub_type]++;

				total_blue_aircraft_count++;
			}
			else if (get_local_entity_int_value (en, INT_TYPE_SIDE) == ENTITY_SIDE_RED_FORCE)
			{
				total_count++;

				red_aircraft_count[sub_type]++;

				total_red_aircraft_count++;
			}
		}
		else if (get_local_entity_int_value (en, INT_TYPE_IDENTIFY_VEHICLE))
		{
			ASSERT (entity_sub_type_vehicle_valid (get_local_entity_int_value (en, INT_TYPE_ENTITY_SUB_TYPE)));

			if (get_local_entity_int_value (en, INT_TYPE_SIDE) == ENTITY_SIDE_BLUE_FORCE)
			{
				total_count++;

				blue_vehicle_count[sub_type]++;

				total_blue_vehicle_count++;
			}
			else if (get_local_entity_int_value (en, INT_TYPE_SIDE) == ENTITY_SIDE_RED_FORCE)
			{
				total_count++;

				red_vehicle_count[sub_type]++;

				total_red_vehicle_count++;
			}
		}

		en = get_local_entity_succ (en);
	}

	debug_colour_log (DEBUG_COLOUR_AMBER, "=====================================");
	debug_colour_log (DEBUG_COLOUR_AMBER, "START FORCE COUNT (total = %d)", total_count);
	debug_colour_log (DEBUG_COLOUR_AMBER, "=====================================");

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

	debug_colour_log (DEBUG_COLOUR_AMBER, "-------------------------------------");
	debug_colour_log (DEBUG_COLOUR_AMBER, "BLUE AIRCRAFT (total = %d)", total_blue_aircraft_count);
	debug_colour_log (DEBUG_COLOUR_AMBER, "-------------------------------------");

	for (sub_type = 0; sub_type < NUM_ENTITY_SUB_TYPE_AIRCRAFT; sub_type++)
	{
		if (get_aircraft_side (sub_type) == ENTITY_SIDE_BLUE_FORCE)
		{
			debug_colour_log (DEBUG_COLOUR_AMBER, "%4dx %s", blue_aircraft_count[sub_type], entity_sub_type_aircraft_names[sub_type]);
		}
	}

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

	debug_colour_log (DEBUG_COLOUR_AMBER, "-------------------------------------");
	debug_colour_log (DEBUG_COLOUR_AMBER, "BLUE VEHICLES (total = %d)", total_blue_vehicle_count);
	debug_colour_log (DEBUG_COLOUR_AMBER, "-------------------------------------");

	for (sub_type = 0; sub_type < NUM_ENTITY_SUB_TYPE_VEHICLES; sub_type++)
	{
		if (get_vehicle_side (sub_type) == ENTITY_SIDE_BLUE_FORCE)
		{
			debug_colour_log (DEBUG_COLOUR_AMBER, "%4dx %s", blue_vehicle_count[sub_type], entity_sub_type_vehicle_names[sub_type]);
		}
	}

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

	debug_colour_log (DEBUG_COLOUR_AMBER, "-------------------------------------");
	debug_colour_log (DEBUG_COLOUR_AMBER, "RED AIRCRAFT (total = %d)", total_red_aircraft_count);
	debug_colour_log (DEBUG_COLOUR_AMBER, "-------------------------------------");

	for (sub_type = 0; sub_type < NUM_ENTITY_SUB_TYPE_AIRCRAFT; sub_type++)
	{
		if (get_aircraft_side (sub_type) == ENTITY_SIDE_RED_FORCE)
		{
			debug_colour_log (DEBUG_COLOUR_AMBER, "%4dx %s", red_aircraft_count[sub_type], entity_sub_type_aircraft_names[sub_type]);
		}
	}

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

	debug_colour_log (DEBUG_COLOUR_AMBER, "-------------------------------------");
	debug_colour_log (DEBUG_COLOUR_AMBER, "RED VEHICLES (total = %d)", total_red_vehicle_count);
	debug_colour_log (DEBUG_COLOUR_AMBER, "-------------------------------------");

	for (sub_type = 0; sub_type < NUM_ENTITY_SUB_TYPE_VEHICLES; sub_type++)
	{
		if (get_vehicle_side (sub_type) == ENTITY_SIDE_RED_FORCE)
		{
			debug_colour_log (DEBUG_COLOUR_AMBER, "%4dx %s", red_vehicle_count[sub_type], entity_sub_type_vehicle_names[sub_type]);
		}
	}

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

	debug_colour_log (DEBUG_COLOUR_AMBER, "=====================================");
	debug_colour_log (DEBUG_COLOUR_AMBER, "END FORCE COUNT");
	debug_colour_log (DEBUG_COLOUR_AMBER, "=====================================");
}
Exemple #15
0
void unpack_local_anti_aircraft_data (pack_modes mode)
{

	anti_aircraft
		*raw;

	entity
		*destroy_en,
		*en;

	int
		count,
		alive;

	if ((mode != PACK_MODE_SERVER_SESSION) && (mode != PACK_MODE_CLIENT_SESSION))
	{

		return;
	}

	//
	// RLE encoded
	//

	debug_log ("RLE SAM & AAA");

	en = get_local_entity_list ();

	count = unpack_int_value (NULL, INT_TYPE_LENGTH);

	alive = unpack_int_value (NULL, INT_TYPE_ALIVE);

	#if DEBUG_MODULE

	debug_log ("AA_PACK: unpacking count %d, alive %d", count, alive);

	#endif

	while (en)
	{

		destroy_en = en;

		en = get_local_entity_succ (en);

		if (get_local_entity_type (destroy_en) == ENTITY_TYPE_ANTI_AIRCRAFT)
		{

			if (count == 0)
			{

				count = unpack_int_value (NULL, INT_TYPE_LENGTH);

				alive = unpack_int_value (NULL, INT_TYPE_ALIVE);

				#if DEBUG_MODULE

				debug_log ("AA_PACK: unpacking count %d, alive %d", count, alive);

				#endif
			}

			count --;

			raw = (anti_aircraft *) get_local_entity_data (destroy_en);

			raw->vh.mob.alive = TRUE;

			if (!alive)
			{

				kill_local_restored_anti_aircraft_entity (destroy_en);
			}
		}
	}
}
Exemple #16
0
void pack_local_anti_aircraft_data (pack_modes mode)
{

	entity
		*en;

	anti_aircraft
		*raw;

	int
		pack_size,
		count,
		alive,
		total;

	if ((mode != PACK_MODE_SERVER_SESSION) && (mode != PACK_MODE_CLIENT_SESSION))
	{

		return;
	}

	debug_log ("RLE SAM & AAA");

	pack_size = 0;

	count = 0;

	alive = TRUE;

	total = 0;

	en = get_local_entity_list ();

	while (en)
	{

		if (get_local_entity_type (en) == ENTITY_TYPE_ANTI_AIRCRAFT)
		{

			total ++;

			raw = (anti_aircraft *) get_local_entity_data (en);

			if (alive == raw->vh.mob.alive)
			{

				count ++;
			}
			else
			{

				pack_int_value (NULL, INT_TYPE_LENGTH, count);
				pack_size += NUM_LENGTH_BITS;

				pack_int_value (NULL, INT_TYPE_ALIVE, alive);
				pack_size += NUM_ALIVE_BITS;

				#if DEBUG_MODULE

				debug_log ("AA_PACK: packing count %d, alive %d", count, alive);

				#endif

				alive = raw->vh.mob.alive;

				count = 1;
			}
		}

		en = get_local_entity_succ (en);
	}

	pack_int_value (NULL, INT_TYPE_LENGTH, count);
	pack_size += NUM_LENGTH_BITS;

	pack_int_value (NULL, INT_TYPE_ALIVE, alive);
	pack_size += NUM_ALIVE_BITS;

	#if DEBUG_MODULE

	debug_log ("AA_PACK: packing count %d, alive %d", count, alive);

	#endif

	//debug_log ("AA_PACK: packing %d anti_aircraft took %d bytes (%d bits)", total, pack_size / 8, pack_size);
}