Example #1
0
void initialise_formation_database_table (void)
{

	formation_type
		*this_formation;

	if (formation_database_table)
	{

		free_mem (formation_database_table);
	}

	formation_database_table = (formation_type **) malloc_heap_mem (sizeof (formation_type *) * (last_formation_index + 1));

	memset (formation_database_table, 0, sizeof (formation_type *) * (last_formation_index + 1));
	
	this_formation = formation_database;

	while (this_formation)
	{

		formation_database_table [this_formation->formation] = this_formation;

		this_formation = this_formation->next;
	}
}
Example #2
0
int register_entity_list_root_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_root_validation;

	entity_list_root_validation = new_entity_list;

	#if DEBUG_MODULE
	{

		entity
			*first_child;

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

		first_child = get_local_entity_first_child (en, list_type);
	}
	#endif

	return TRUE;
}
Example #3
0
void add_friction_force (rigid_body_dynamics *rb, double_vec3d *force, double_vec3d *torque)
{

	constraint_forces
		*new_friction;

	new_friction = (constraint_forces *) malloc_heap_mem (sizeof (constraint_forces));

	new_friction->owner = rb;
	new_friction->force = *force;
	new_friction->torque = *torque;

	new_friction->next = friction_force_list_head;

	friction_force_list_head = new_friction;

	#if DEBUG_MODULE

	//if (rb == camera_object->rigid_body)
	{
	
			debug_log ("BODY: FRICTION: adding %s friction force [%f, %f, %f] and torque [%f, %f, %f]",
						rb->name,
						force->x, force->y, force->z,
						torque->x, torque->y, torque->z);
	}

	#endif
}
Example #4
0
void initialise_group_task_array (void)
{
	int
		group,
		task;

	ASSERT (!group_task_array);

	group_task_array = malloc_heap_mem (sizeof (float *) * NUM_ENTITY_SUB_TYPE_GROUPS);

	for (group = 0; group < NUM_ENTITY_SUB_TYPE_GROUPS; group ++)
	{
		group_task_array [group] = malloc_heap_mem (sizeof (float) * NUM_ENTITY_SUB_TYPE_TASKS);

		for (task = 0; task < NUM_ENTITY_SUB_TYPE_TASKS; task ++)
		{
			group_task_array [group][task] = calculate_group_to_task_suitability (group, task);
		}
	}

	#if DEBUG_MODULE

	for (task = 0; task < NUM_ENTITY_SUB_TYPE_TASKS; task ++)
	{
		debug_filtered_log ("TASK %s", task_database [task].full_name);
		debug_filtered_log ("=========================");

		for (group = 0; group < NUM_ENTITY_SUB_TYPE_GROUPS; group ++)
		{
			if (group_task_array [group][task] > 0.0)
			{
				debug_filtered_log ("%s (%f)", group_database [group].full_name, group_task_array [group][task]);
			}
		}

		debug_filtered_log ("");
		debug_filtered_log ("");
	}

	#endif
}
Example #5
0
void add_constraint_force (rigid_body_dynamics *rb, double_vec3d *force, double_vec3d *position, rigid_body_dynamics *owner)
{

	constraint_forces
		*new_constraint;

	// debug
	//if ((get_3d_double_vector_magnitude (force) > 0.5))
	// debug
	if (!check_zero_3d_double_vector (force))
	{

		new_constraint = (constraint_forces *) malloc_heap_mem (sizeof (constraint_forces));

		memset (new_constraint, 0, sizeof (constraint_forces));
	
		new_constraint->owner = rb;
		new_constraint->force = *force;
		new_constraint->position = *position;
	
		new_constraint->next = constraint_force_list_head;
	
		constraint_force_list_head = new_constraint;
	
		#if DEBUG_MODULE

		if (((camera_object) && (rb == camera_object->rigid_body)))// && (stricmp (owner->name, "body") == 0))
		{

			double_vec3d
				temp_direction,
				temp_position;
	
			temp_position.x = rb->position_cm [0].x + position->x;
			temp_position.y = rb->position_cm [0].y + position->y;
			temp_position.z = rb->position_cm [0].z + position->z;
	
			temp_direction = *force;
			normalise_any_3d_double_vector (&temp_direction);
	
			//create_arrow ("TAIL_ARROW", &temp_position, &temp_direction, 6.0);
		
			debug_log ("BODY: 	adding %s constraint force %f dir [%f, %f, %f], pos [%f, %f, %f] from %s",
						rb->name,
						get_3d_double_vector_magnitude (force),
						temp_direction.x, temp_direction.y, temp_direction.z,
						position->x, position->y, position->z,
						(owner) ? owner->name : "NONE");
		}

		#endif
	}
}
Example #6
0
int add_formation_to_database (int number_in_formation, vec3d *site_positions)
{

	formation_type
		*new_formation;

	char
		name [128];

	new_formation = (formation_type *) malloc_heap_mem (sizeof (formation_type));
	memset (new_formation, 0, sizeof (formation_type));

	last_formation_index ++;
	new_formation->formation = (formation_types) last_formation_index;

	sprintf (name, "USER FORMATION %d", last_formation_index);
	new_formation->name = (char *) malloc_heap_mem (sizeof (char) * (strlen (name) + 1));
	strcpy (new_formation->name, name);

	new_formation->number_in_formation = number_in_formation;

	if (number_in_formation > 0)
	{

		new_formation->sites = (vec3d *) malloc_heap_mem (sizeof (vec3d) * (number_in_formation));

		memcpy (new_formation->sites, site_positions, sizeof (vec3d) * number_in_formation);
	}

	//
	// link into database
	//

	new_formation->next = formation_database;

	formation_database = new_formation;

	return last_formation_index;
}
Example #7
0
void initialise_entity_type_names (void)
{

	int
		loop;

	entity_type_names = (char **) malloc_heap_mem (sizeof (char *) * NUM_ENTITY_TYPES + 1);

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

		entity_type_names [loop] = get_entity_type_name (loop);
	}
}
Example #8
0
// FIXME: 'int type' was 'meta_smoke_list_types type', 'int attachment_point was 'object_3d_sub_object_index_numbers attachment_point'
void register_attach_meta_smoke_list_to_object (entity *en, int type, int attachment_point, int *entity_index_list, int count)
{

	comms_entity_smoke_list_creation_type
		*new_smoke_list_creation;

	new_smoke_list_creation = (comms_entity_smoke_list_creation_type *) malloc_heap_mem (sizeof (comms_entity_smoke_list_creation_type));

	new_smoke_list_creation->en = en;

	new_smoke_list_creation->meta_smoke_type = type;

	new_smoke_list_creation->attachment_point = attachment_point;

	new_smoke_list_creation->count = count;

	new_smoke_list_creation->entity_index_list = (int *) malloc_heap_mem (sizeof (int) * count);

	memcpy (new_smoke_list_creation->entity_index_list, entity_index_list, sizeof (int) * count);

	new_smoke_list_creation->next = entity_smoke_list_creation;

	entity_smoke_list_creation = new_smoke_list_creation;
}
Example #9
0
void initialise_comms_manager (void)
{

	#if DEBUG_MODULE

	debug_log ("COMMS MAN: initialising comms manager: data size = %d", command_line_comms_data_record_size, direct_play_get_player_id ());

	#endif

	set_server_response (SERVER_RESPONSE_UNKNOWN);

	data_record = (char *) malloc_heap_mem (command_line_comms_data_record_size);

	add_update_function (send_comms_data, 1.0 / command_line_max_game_update_rate , 1.0);
	//add_update_function (data_exchange, 1.0 / command_line_max_game_update_rate , 1.0);

	if (command_line_comms_validate_connections)
	{

		add_update_function (validate_connections, command_line_comms_timeout, 1.0);
	}

	tx_pack_buffer = (char *) malloc_heap_mem (sizeof (char) * command_line_comms_pack_buffer_size);
}
Example #10
0
void initialise_entity_heap (int num_entities)
{
	ASSERT ((num_entities > 0) && (num_entities < MAX_NUM_ENTITIES));

	number_of_entities = num_entities;

	//Xhit: The last 10000 entities in the heap is local only. (030428)
	//VJ 030508 if downwash 
	if (command_line_downwash)
		start_of_local_entity_heap = number_of_entities - 10000;

	entities = (entity *) malloc_heap_mem (number_of_entities * sizeof (entity));
	//VJ 050308 if not downwash than number_of_entities = 125000 (original)

	reset_entity_heap ();
}
Example #11
0
void add_division_id_data (int side, int type, int count, int *number_list)
{
	debug_assert (division_id_database [side][type].count == 0);

	debug_assert (!division_id_database [side][type].number_list);

	debug_assert (count > 0);

	debug_assert (number_list);

	division_id_database [side][type].valid = TRUE;

	division_id_database [side][type].count = count;

	division_id_database [side][type].next = 0;

	division_id_database [side][type].number_list = (int *) malloc_heap_mem (sizeof (int) * count);

	memcpy (division_id_database [side][type].number_list, number_list, sizeof (int) * count);
}
Example #12
0
void unpack_local_division_database (pack_modes mode)
{
	int
		side,
		type,
		loop,
		count,
		valid;

	if (mode == PACK_MODE_SERVER_SESSION)
	{
		for (side = 0; side < NUM_ENTITY_SIDES; side ++)
		{
			for (type = 0; type < NUM_ENTITY_SUB_TYPE_DIVISIONS; type ++)
			{
				valid = unpack_int_value (NULL, INT_TYPE_VALID);
	
				division_id_database [side][type].valid = valid;
	
				if (valid)
				{
					count = unpack_int_value (NULL, INT_TYPE_COUNT);
	
					ASSERT (count > 0);
	
					division_id_database [side][type].count = count;
	
					division_id_database [side][type].next = unpack_int_value (NULL, INT_TYPE_COUNT);
	
					division_id_database [side][type].number_list = (int *) malloc_heap_mem (sizeof (int) * count);
	
					for (loop = 0; loop < count; loop ++)
					{
						division_id_database [side][type].number_list [loop] = unpack_int_value (NULL, INT_TYPE_COUNT);
					}
				}
			}
		}
	}
}
Example #13
0
void register_attach_sound_effect_to_object (entity *en, int index, entity_sides side, entity_sub_types sub_type, int valid, int sample_index)
{

	comms_entity_sound_effect_creation_type
		*new_sound_effect_creation;

	new_sound_effect_creation = (comms_entity_sound_effect_creation_type *) malloc_heap_mem (sizeof (comms_entity_sound_effect_creation_type));

	new_sound_effect_creation->en = en;

	new_sound_effect_creation->side = side;

	new_sound_effect_creation->sub_type = sub_type;

	new_sound_effect_creation->entity_index = index;

	new_sound_effect_creation->sample_index = sample_index;

	new_sound_effect_creation->valid = valid;

	new_sound_effect_creation->next = entity_sound_effect_creation;

	entity_sound_effect_creation = new_sound_effect_creation;
}
Example #14
0
int store_session (session_list_data_type *game_session, const char *filename)
{
	#if !DEMO_VERSION

	entity
		*force;

	int
		count;

	char
		limited_filename [32],
		title [128],
		extension [5],
		data_filename [256],
		script_filename [256];

	FILE
		*file_ptr;

	count = 0;

	strncpy (limited_filename, filename, sizeof (limited_filename) - 2);
	limited_filename [31] = '\0';

	sprintf (data_filename, "%s\\%s\\%s", game_session->data_path, game_session->campaign_directory, limited_filename);

	strcat (data_filename, ".sav");

	sprintf (script_filename, "%s\\%s\\%s.", game_session->data_path, game_session->campaign_directory, limited_filename);

	sprintf (extension, "%s", game_type_extensions [get_game_type ()]);
	extension [2] = extension [1];
	extension [1] = extension [0];
	extension [0] = 'S';

	strcat(script_filename, extension);

	//
	// Create scripting file
	//

	file_ptr = fopen (script_filename, "w");

	if (!file_ptr)
	{

		debug_log ("SESSION: failed to open file %s", script_filename);

		return FALSE;
	}

	ASSERT (file_ptr);

	// Start

	set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");
	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_START);
	set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");

	// Campaign title

	set_file_new_line (file_ptr, 1);

	sprintf (title, "%s", game_session->title);

	set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");
	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_TITLE);
	set_file_string (file_ptr, title);
	set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");

	set_file_new_line (file_ptr, 1);

	set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");
	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_SHORT_TEXT_START);

	// campaign title

	set_file_string (file_ptr, game_session->title);

	set_file_new_line (file_ptr, 2);

	// elapsed campaign time
	{
		float
			elapsed_time;

		int
			hours,
			minutes,
			seconds,
			elapsed_days;

		elapsed_time = get_local_entity_float_value (get_session_entity (), FLOAT_TYPE_ELAPSED_TIME);

		convert_float_to_int (elapsed_time / ONE_DAY, &elapsed_days);

		elapsed_time = fmod (elapsed_time, ONE_DAY);

		get_digital_clock_int_values (elapsed_time, &hours, &minutes, &seconds);

		sprintf (script_filename, "%s %d %s, %02d.%02d.%02d",
						get_trans ("Elapsed Time"),
						elapsed_days,
						get_trans ("days"),
						hours, minutes, seconds);



		set_file_string (file_ptr, script_filename);

		set_file_new_line (file_ptr, 1);
	}
	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_TEXT_END);
	set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");
	set_file_new_line (file_ptr, 1);

	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_CAMPAIGN_DATA);

	if (side_data_filename)
	{

		// side data
		set_file_tag (file_ptr, application_tag_strings, FILE_TAG_FILENAME);
		set_file_string (file_ptr, side_data_filename);
	}

	if (population_placement_filename)
	{

		// population data
		set_file_tag (file_ptr, application_tag_strings, FILE_TAG_FILENAME);
		set_file_string (file_ptr, population_placement_filename);
	}

	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_MAP_X_SIZE);
	set_file_int (file_ptr, world_map.num_map_x_sectors);
	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_MAP_Z_SIZE);
	set_file_int (file_ptr, world_map.num_map_z_sectors);
	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_MAP_SECTOR_SIZE);
	set_file_int (file_ptr, world_map.sector_side_length);

	if (campaign_population_filename)
	{

		// population data
		set_file_tag (file_ptr, application_tag_strings, FILE_TAG_FILENAME);
		set_file_string (file_ptr, campaign_population_filename);
	}

	//
	// save force in reverse order to list (so that they are read_in in the correct order)
	//

	force = get_local_entity_first_child (get_session_entity (), LIST_TYPE_FORCE);

	ASSERT (force);

	while (get_local_entity_child_succ (force, LIST_TYPE_FORCE))
	{

		force = get_local_entity_child_succ (force, LIST_TYPE_FORCE);
	}

	while (force)
	{

		set_file_tag (file_ptr, application_tag_strings, FILE_TAG_FACTION);
		set_file_tag (file_ptr, application_tag_strings, FILE_TAG_SIDE);
		set_file_enum (file_ptr, entity_side_names, get_local_entity_int_value (force, INT_TYPE_SIDE));

		set_file_tag (file_ptr, application_tag_strings, FILE_TAG_COLOUR);
		set_file_enum (file_ptr, sys_colour_names, get_local_entity_int_value (force, INT_TYPE_COLOUR));

		force = get_local_entity_child_pred (force, LIST_TYPE_FORCE);
	}

	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_END);

	// Campaign saved filename

	set_file_new_line (file_ptr, 1);

	set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");
	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_SAVED_CAMPAIGN);

	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_PATH);
	set_file_string (file_ptr, game_session->data_path);

	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_PATH);
	set_file_string (file_ptr, game_session->campaign_directory);

	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_FILENAME);
	set_file_string (file_ptr, game_session->campaign_filename);

	set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");

	set_file_new_line (file_ptr, 1);

	//
	// Version number
	//

	{

		int
			value;
		set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");

		set_file_tag (file_ptr, application_tag_strings, FILE_TAG_VERSION_NUMBER);
		value = get_local_entity_int_value ( get_session_entity (), INT_TYPE_VERSION_NUMBER );
		set_file_int (file_ptr, value);

		set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");
	}

	// End

	//VJ 051202 add season (camo) info to file description
	//use set and get_global_season
	set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");
	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_SEASON);
	set_file_int (file_ptr, (int) get_global_season() );
	set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");

	set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");
	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_END);
	set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");

	fclose (file_ptr);

	//
	// Save entity data
	//

	file_ptr = fopen (data_filename, "wb");

	if (file_ptr)
	{

		unsigned char
			*save_ptr,
			*buffer;

		int
			extra_data,
			server_version_number,
			buffer_size;

		buffer_size = 1024 * 1024;

		buffer = (unsigned char *) malloc_heap_mem (buffer_size);

		save_ptr = buffer;

		extra_data = 0;

		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		// write out version number
		server_version_number = get_local_entity_int_value (get_session_entity (), INT_TYPE_VERSION_NUMBER);

		quick_set_list_item (save_ptr, int, server_version_number);

		buffer_size -= sizeof (int);
		extra_data += sizeof (int);
		//
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		// write out session
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

		while (pack_session (save_ptr, &buffer_size, PACK_MODE_SERVER_SESSION))
		{

			debug_log ("SESSION: mallocing store pack buffer from %d to %d", buffer_size, buffer_size * 2);

			free_mem (buffer);

			buffer_size *= 2;

			buffer = (unsigned char *) malloc_heap_mem (buffer_size);

			save_ptr = buffer;

			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			// write out version number
			server_version_number = get_local_entity_int_value (get_session_entity (), INT_TYPE_VERSION_NUMBER);

			quick_set_list_item (save_ptr, int, server_version_number);

			buffer_size -= sizeof (int);
			//
			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		}

		fwrite (buffer, buffer_size + extra_data, 1, file_ptr);

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

		free_mem (buffer);
	}

	fclose (file_ptr);

	//
	//
	//

	// arneh feb 2009 - this call shouldn't be necessary, and it will double initialise things which confuses EECH
	//	set_current_game_session (game_session);

	#endif

	return TRUE;
}
Example #15
0
static int load_local_pylon_entities (char *name)
{
	entity
		*last_entity,
		*last_last_entity,
		*new_entity;

	entity_sub_types
		sub_type;

	int
		type,
		node_count,
		*node_link_count,
		path_count,
		node_loop,
		path_loop,
		start,
		end,
		link_count,
		link_loop;

	vec3d
		*node_positions,
		pos;

	FILE
		*pylon_node_file_ptr,
		*pylon_link_file_ptr;

	char
		filename [1024];

	session_list_data_type
		*current_session;

	//
	// Create "Node" Pylons
	//

	ASSERT (get_valid_current_game_session ());

	ASSERT (name);

	current_session = get_current_game_session ();

	sprintf (filename, "%s//route//%s.nde", current_session->data_path, name);

	if (file_exist (filename))
	{
		pylon_node_file_ptr = safe_fopen (filename, "rb");

		fread (&node_count, sizeof (int), 1, pylon_node_file_ptr);

		node_positions = malloc_heap_mem (sizeof (vec3d) * node_count);

		node_link_count = malloc_heap_mem (sizeof (int) * node_count);

		for (node_loop = 0 ; node_loop < node_count ; node_loop ++)
		{
			fread (&pos, sizeof (vec3d), 1, pylon_node_file_ptr);

			node_positions [node_loop].x = pos.x;
			node_positions [node_loop].y = pos.y;
			node_positions [node_loop].z = pos.z;

			node_link_count [node_loop] = 0;
		}

		fclose (pylon_node_file_ptr);

		//
		// Create "Link" Pylons
		//

		sprintf (filename, "%s//route//%s.wp", current_session->data_path, name);

		pylon_link_file_ptr = safe_fopen (filename, "rb");

		fread (&path_count, sizeof (int), 1, pylon_link_file_ptr);

		new_entity = NULL;

		for (path_loop = 0 ; path_loop < path_count ; path_loop ++)
		{
			fread (&start, sizeof (int), 1, pylon_link_file_ptr);

			fread (&end, sizeof (int), 1, pylon_link_file_ptr);

			fread (&type, sizeof (int), 1, pylon_link_file_ptr);

			fread (&link_count, sizeof (int), 1, pylon_link_file_ptr);

			node_link_count [start] += 1;
			node_link_count [end] += 1;

			if (link_count > 0)
			{
				last_entity = NULL;

				last_last_entity = NULL;

				for (link_loop = 0 ; link_loop < link_count ; link_loop ++)
				{
					fread (&pos, sizeof (vec3d), 1, pylon_link_file_ptr);

					if (link_loop == 0)
					{
						sub_type = ENTITY_SUB_TYPE_FIXED_ELECTRICITY_PYLON_START_TERMINATOR;
					}
					else if (link_loop == link_count - 1)
					{
						sub_type = ENTITY_SUB_TYPE_FIXED_ELECTRICITY_PYLON_END_TERMINATOR;
					}
					else
					{
						sub_type = ENTITY_SUB_TYPE_FIXED_ELECTRICITY_PYLON_STANDARD;
					}

					new_entity = create_local_entity
					(
						ENTITY_TYPE_PYLON,
						ENTITY_INDEX_DONT_CARE,
						ENTITY_ATTR_INT_VALUE (INT_TYPE_ENTITY_SUB_TYPE, sub_type),
						ENTITY_ATTR_VEC3D (VEC3D_TYPE_POSITION, pos.x, pos.y, pos.z),
						ENTITY_ATTR_FLOAT_VALUE (FLOAT_TYPE_HEADING, 0),
						ENTITY_ATTR_PTR_VALUE (PTR_TYPE_SUCC, last_entity),
						ENTITY_ATTR_END
					);

					calculate_pylon_heading (last_last_entity, last_entity, new_entity, &node_positions [start], &node_positions [end]);

					last_last_entity = last_entity;

					last_entity = new_entity;
				}

				// last pylon in the link
				calculate_pylon_heading (last_last_entity, last_entity, NULL, &node_positions [start], &node_positions [end]);
			}
		}

		for (node_loop = 0 ; node_loop < node_count ; node_loop ++)
		{
			//
			// create node entities here
			//
		}

		fclose (pylon_link_file_ptr);

		free_mem (node_positions);

		free_mem (node_link_count);

		return TRUE;
	}

	return FALSE;
}
Example #16
0
void comms_process_data (void)
{

	session_list_data_type
		*current_session;

	connection_list_type
		*this_connection,
		*connection;

	char
		*received_data;

	int
		planner_event,
		frame_id,
		packet_id,
		receive_flag,
		received_size;

	GUID
		received_id = 0;

	entity
		*member;

	send_types
		send_type;

	packet_types
		type;

	// receive all packets in queue

	current_session = get_current_game_session ();

	received_size = MAX_RECEIVE_SIZE;

	connection = get_connection_list_head ();

	while (connection)
	{

		this_connection = connection;

		connection = connection->next;

		send_type = SEND_TYPE_GROUP;

		while (send_type >= SEND_TYPE_PERSONAL)
		{

			receive_flag = TRUE;

			while (receive_flag)
			{

				type = process_packet_list (send_type, this_connection, &received_id, &received_data, &received_size);

				switch (type)
				{

					///////////////////////////////////////////////////////////////////////////////////////////////
					//
					// System packets, used internally
					//
					///////////////////////////////////////////////////////////////////////////////////////////////

					case PACKET_TYPE_INVALID:
					{

						receive_flag = FALSE;

						if (get_comms_model () == COMMS_MODEL_SERVER)
						{

							if (this_connection->packet_rerequested > command_line_comms_packet_rerequest_limit)
							{

								debug_log ("COMM_MAN: REJECTING CONNECTION. CONNECTION TOO BAD (re-request limit %d reached)", command_line_comms_packet_rerequest_limit);

								send_packet (this_connection->connection_id, PACKET_TYPE_SERVER_REJECTED, NULL, 0, SEND_TYPE_PERSONAL);
							}
						}

						break;
					}

					case PACKET_TYPE_RESEND_PACKET:
					{

						send_types
							resend_send_type;

						frame_id = get_list_item (received_data, int);

						packet_id = get_list_item (received_data, int);

						resend_send_type = get_list_item (received_data, send_types);

						#if DEBUG_MODULE

						if (this_connection->pilot_entity)
						{

							debug_log ("COMMS MAN: received RESEND PACKET for frame %d packet %d from %s (dpid %d)",
											frame_id, packet_id,
											get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME),
											received_id);
						}
						else
						{

							debug_log ("COMMS MAN: received RESEND PACKET by unknown (pdid %d)",
											received_id);
						}

						#endif

						resend_packet (received_id, frame_id, packet_id, resend_send_type);

						break;
					}

					///////////////////////////////////////////////////////////////////////////////////////////////
					//
					// Packets for initialisation and joining
					//
					///////////////////////////////////////////////////////////////////////////////////////////////

					case PACKET_TYPE_SESSION_QUERY:
					{

						char
							*ptr;

						int
							server_version_number,
							player_count,
							size;

						connection_list_type
							*new_connection;

						if (get_comms_model () == COMMS_MODEL_SERVER)
						{

							#if DEBUG_MODULE

							if (this_connection->pilot_entity)
							{

								debug_log ("COMMS MAN: RECEIVED SESSION QUERY from %s (dpid %d)",
												get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME),
												received_id);
							}
							else
							{

								debug_log ("COMMS MAN: RECEIVED SESSION QUERY from %d", received_id);
							}

							#endif

							new_connection = get_connection_list_item (received_id);

							if (!new_connection->already_sent_query_data)
							{

								new_connection->already_sent_query_data = TRUE;

								while (TRUE)
								{

									ptr = new_connection->connection_receive_buffer;

									size = 0;

									/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
									//
									// Check both client and server are running same campaign data
									//
									server_version_number = get_local_entity_int_value (get_session_entity (), INT_TYPE_VERSION_NUMBER);

									quick_set_list_item (ptr, int, server_version_number);

									size += sizeof (int);
									//
									/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

									// map details

									quick_set_list_item (ptr, int, NUM_MAP_X_SECTORS);

									quick_set_list_item (ptr, int, NUM_MAP_Z_SECTORS);

									quick_set_list_item (ptr, int, SECTOR_SIDE_LENGTH);

									size += sizeof (int) * 3;

									// data path

									strcpy (ptr, current_session->data_path);

									ptr += strlen (current_session->data_path) + 1;

									size += strlen (current_session->data_path) + 1;

									// population_placement filename

									if (population_placement_filename)
									{

										strcpy (ptr, population_placement_filename);

										ptr += strlen (population_placement_filename) + 1;

										size += strlen (population_placement_filename) + 1;
									}
									else
									{

										strcpy (ptr, "\0");

										ptr += strlen ("\0") + 1;

										size += strlen ("\0") + 1;
									}

									//

									// side_data filename

									if (side_data_filename)
									{

										strcpy (ptr, side_data_filename);

										ptr += strlen (side_data_filename) + 1;

										size += strlen (side_data_filename) + 1;
									}
									else
									{

										strcpy (ptr, "\0");

										ptr += strlen ("\0") + 1;

										size += strlen ("\0") + 1;
									}

									// campaign_population filename

									if (campaign_population_filename)
									{

										strcpy (ptr, campaign_population_filename);

										ptr += strlen (campaign_population_filename) + 1;

										size += strlen (campaign_population_filename) + 1;
									}
									else
									{

										strcpy (ptr, "\0");

										ptr += strlen ("\0") + 1;

										size += strlen ("\0") + 1;
									}

									//
									// planner position and zoom
									//

//									quick_set_list_item (ptr, float, planner_map_data.centre_map_x);

//									quick_set_list_item (ptr, float, planner_map_data.centre_map_z);

//									size += sizeof (float) * 2;

//									quick_set_list_item (ptr, int, planner_map_data.map_zoom);

//									size += sizeof (int);

									//
									// Pilots
									//

									player_count = get_number_of_connected_players ();

									quick_set_list_item (ptr, int, player_count);

									size += sizeof (int);

									//
									//
									//

									#if DEBUG_MODULE

									debug_log ("COMM_MAN: sending data path %s, population placement %s, side data %s, campaign_pop file %s",
													current_session->data_path, population_placement_filename, side_data_filename, campaign_population_filename);

									#endif

									new_connection->connection_receive_buffer_size -= size;

									if (!pack_session (ptr, &new_connection->connection_receive_buffer_size, PACK_MODE_BROWSE_SESSION))
									{

										break;
									}

									new_connection->connection_receive_buffer_size *= 2;

									#if DEBUG_MODULE

									debug_log ("COMMS MAN: Browse: connection_receive_buffer too small, mallocing to %d", new_connection->connection_receive_buffer_size);

									#endif

									free_mem (new_connection->connection_receive_buffer);

									new_connection->connection_receive_buffer = malloc_heap_mem (new_connection->connection_receive_buffer_size);
								}

								//
								//
								//

								send_packet (received_id, PACKET_TYPE_SESSION_INFO, new_connection->connection_receive_buffer, new_connection->connection_receive_buffer_size + size, SEND_TYPE_PERSONAL);

								/*
								{

									FILE
										*test_ptr;

									test_ptr = fopen ("out.txt", "wb");

									fwrite (new_connection->connection_receive_buffer, 1, new_connection->connection_receive_buffer_size + size, test_ptr);

									fclose (test_ptr);
								}
								*/
							}
							else
							{

								debug_log ("COMM_MAN: not resending query data");
							}
						}

						break;
					}

					case PACKET_TYPE_CONNECTION_VALIDATION:
					{

						debug_log ("COMM_MAN: received CONNECTION_VALIDATION, sending RESPONSE");

						send_packet (received_id, PACKET_TYPE_CONNECTION_RESPONSE, NULL, 0, SEND_TYPE_PERSONAL);

						break;
					}

					case PACKET_TYPE_CONNECTION_RESPONSE:
					{

						connection_list_type
							*connection;

						connection = get_connection_list_item (received_id);

						connection->validation_count = 0;

						debug_log ("COMM_MAN: received CONNECTION_RESPONSE, connection still alive");

						break;
					}

					case PACKET_TYPE_SESSION_INFO:
					{

						entity
							*force,
							*pilot;

						int
							client_version_number,
							server_version_number;

						int
							size,
							x_size,
							z_size,
							sector_size,
							player_count,
							loop;

						char
							*ptr,
							warzone_ffp_filename [256],
							temp_campaign_population_filename [256],
							temp_population_placement_filename [256],
							temp_side_data_filename [256],
							buffer [128];

						session_data = FALSE;

						reinitialise_entity_system ();

						ptr = received_data;

						size = 0;

						set_ui_object_redraw (gunships_screen, TRUE);

						ui_force_update ();

						/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
						//
						// Check both client and server are running same campaign data
						//
						client_version_number = get_global_version_number ();

						server_version_number = get_list_item (ptr, int);

						size += sizeof (int);

						if (client_version_number != server_version_number)
						{

							debug_fatal ("COMM_MAN: Incorrect version. Server Version No. %d, Client Version No. %d", server_version_number, client_version_number);
						}
						//
						/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

						// map details

						x_size = get_list_item (ptr, int);

						z_size = get_list_item (ptr, int);

						sector_size = get_list_item (ptr, int);

						size += (sizeof (int) * 3);

						set_entity_world_map_size (x_size, z_size, sector_size);

						// data path

						strncpy (current_session->data_path, ptr, sizeof (current_session->data_path));

						ptr += strlen (current_session->data_path) + 1;

						size += strlen (current_session->data_path) + 1;

						// population_placement_filename

						strncpy (temp_population_placement_filename, ptr, sizeof (temp_population_placement_filename));

						ptr += strlen (temp_population_placement_filename) + 1;

						size += strlen (temp_population_placement_filename) + 1;

						if (population_placement_filename)
						{

							free_mem (population_placement_filename);
						}

						if (strlen (temp_population_placement_filename) > 0)
						{

							population_placement_filename = (char *) malloc_heap_mem (strlen (temp_population_placement_filename) + 1);

							sprintf (population_placement_filename, "%s", temp_population_placement_filename);
						}
						else
						{

							population_placement_filename = NULL;
						}

						// side_data filename

						strncpy (temp_side_data_filename, ptr, sizeof (temp_side_data_filename));

						ptr += strlen (temp_side_data_filename) + 1;

						size += strlen (temp_side_data_filename) + 1;

						if (side_data_filename)
						{

							free_mem (side_data_filename);
						}

						if (strlen (temp_side_data_filename) > 0)
						{

							side_data_filename = (char *) malloc_heap_mem (strlen (temp_side_data_filename) + 1);

							sprintf (side_data_filename, "%s", temp_side_data_filename);
						}
						else
						{

							side_data_filename = NULL;
						}

						// campaign_population_filename

						strncpy (temp_campaign_population_filename, ptr, sizeof (temp_campaign_population_filename));

						ptr += strlen (temp_campaign_population_filename) + 1;

						size += strlen (temp_campaign_population_filename) + 1;

						if (campaign_population_filename)
						{

							free_mem (campaign_population_filename);
						}

						if (strlen (temp_campaign_population_filename) > 0)
						{

							campaign_population_filename = (char *) malloc_heap_mem (strlen (temp_campaign_population_filename) + 1);

							sprintf (campaign_population_filename, "%s", temp_campaign_population_filename);
						}
						else
						{

							campaign_population_filename = NULL;
						}

						//
						//
						//

						player_count = get_list_item (ptr, int);

						size += sizeof (int);

						//
						//
						//

						received_size -= size;

						#if DEBUG_MODULE

						debug_log ("COMM_MAN: data path %s population placement filename %s, side data filename %s", current_session->data_path, population_placement_filename, side_data_filename);

						debug_log ("COMM_MAN: campaign data path = %s", current_session->data_path);

						#endif

						//
						// check we have the correct warzone locally
						//

						sprintf (warzone_ffp_filename, "%s\\terrain\\terrain.ffp", current_session->data_path);

						if (!file_exist (warzone_ffp_filename))
						{

							add_to_pop_up_list_with_word_wrap (get_trans ("UNRECOGNISED_WARZONE"), session_info_list, NULL, 0, UI_FONT_ARIAL_10, sys_col_white);
							//add_to_pop_up_list (get_trans ("Server using unrecognised warzone"), session_info_list, NULL, 0, UI_FONT_ARIAL_10, sys_col_white);

							break;
						}

						//
						//
						//

						create_local_only_entities (PACK_MODE_BROWSE_SESSION);

						if (unpack_session (ptr, received_size, PACK_MODE_BROWSE_SESSION))
						{

							debug_fatal ("COMMS MAN: browse: received size overflow");
						}

						#if DEBUG_MODULE

						if (this_connection->pilot_entity)
						{

							debug_log ("COMMS MAN: received SESSION INFO from %s (dpid %d) (setting server id)",
											get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME),
											received_id);
						}
						else
						{

							debug_log ("COMMS MAN: RECEIVED SESSION INFO from %d", received_id);
						}

						debug_log ("COMMS MAN: session info: time of day = %f",
										get_local_entity_float_value (get_session_entity (), FLOAT_TYPE_TIME_OF_DAY));

						debug_log ("COMMS MAN: map dimensions %d, %d, sector size %d", x_size, z_size, sector_size);

						#endif

						set_ui_object_drawable (session_screen_next_button, TRUE);

						//
						// Display game info
						//

						ui_object_destroy_list_items (session_info_list);

						if (get_local_entity_int_value (get_session_entity (), INT_TYPE_CAMPAIGN_REQUIRES_APACHE_HAVOC))
						{

							// campaign requires apache havoc to be installed
							// check it is...

							if (!get_global_apache_havoc_installed ())
							{

								add_to_pop_up_list_with_word_wrap (get_trans ("REQUIRES_APACHE_HAVOC"), session_info_list, NULL, 0, UI_FONT_ARIAL_10, sys_col_white);

								set_ui_object_drawable (session_screen_next_button, FALSE);

								break;
							}
						}

						loop = 3;

						sprintf (buffer, "%s : %d", get_trans ("Players"), player_count);

						add_to_pop_up_list_with_word_wrap (buffer, session_info_list, NULL, 0, UI_FONT_ARIAL_10, sys_col_white);

						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)
							{
								{
									rgb_colour
										col;

									sprintf (buffer, "%2d  ", loop - 2);

									strncat (buffer, get_local_entity_string (pilot, STRING_TYPE_PILOTS_NAME), 64);

									switch (get_local_entity_int_value (pilot, INT_TYPE_SIDE))
									{
										case ENTITY_SIDE_BLUE_FORCE:
										{
											col.r = 120;
											col.g = 158;
											col.b = 255;
											col.a = 255;

											break;
										}
										case ENTITY_SIDE_RED_FORCE:
										{
											col.r = 255;
											col.g = 120;
											col.b = 80;
											col.a = 255;

											break;
										}
										default:
										{
									      col = ui_colour_white;

											break;
										}
									}

									add_to_pop_up_list_with_word_wrap (buffer, session_info_list, NULL, 0, UI_FONT_ARIAL_10, col);

									loop ++;
								}

								pilot = get_local_entity_child_succ (pilot, LIST_TYPE_PILOT);
							}

							force = get_local_entity_child_succ (force, LIST_TYPE_FORCE);
						}

						set_server_id (received_id);

						//
						// destroy all entities created by browse info
						//

						reinitialise_entity_system ();

						break;
					}

					case PACKET_TYPE_CLIENT_PILOT_REQUEST:
					{

						connection_list_type
							*new_connection;

						client_pilot_request_data
							pilot_data;

						entity
							*new_pilot;

						int
							index;

						ASSERT (get_comms_model () == COMMS_MODEL_SERVER);

//						#if DEBUG_MODULE

						debug_log ("COMMS MAN: RECEIVED PILOT REQUEST from %d", received_id);

//						#endif

						//
						// unpack name
						//

						memcpy (&pilot_data, (client_pilot_request_data *) received_data, sizeof (client_pilot_request_data));

						new_pilot = create_new_pilot_entity
										(
											pilot_data.name,
											pilot_data.side,
											pilot_data.rank,
											pilot_data.sub_type,
											pilot_data.unique_id,
											pilot_data.difficulty
										);

						ASSERT (new_pilot);

						index = get_local_entity_safe_index (new_pilot);

						new_connection = get_connection_list_item (received_id);

						transmit_entity_comms_message (ENTITY_COMMS_PILOT_REQUEST_ACCEPTED, NULL, received_id, index);

						new_connection->pilot_entity = new_pilot;

						break;
					}

					case PACKET_TYPE_CLIENT_GUNSHIP_REQUEST:
					{

						connection_list_type
							*new_connection;

						client_gunship_request_data
							pilot_data;

						int
							index_number,
							buffer [2];

						if (get_comms_model () == COMMS_MODEL_SERVER)
						{

//							#if DEBUG_MODULE

							if (this_connection->pilot_entity)
							{

								debug_log ("COMMS MAN: RECEIVED GUNSHIP REQUEST from %s (dpid %d)",
												get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME),
												received_id);
							}
							else
							{

								debug_log ("COMMS MAN: RECEIVED GUNSHIP REQUEST from %d", received_id);
							}

//							#endif

							memcpy (&pilot_data, (client_gunship_request_data *) received_data, sizeof (client_gunship_request_data));

							index_number = pilot_data.gunship_index;

							ASSERT (index_number != ENTITY_INDEX_DONT_CARE);

							member = get_local_entity_safe_ptr (index_number);

							if (!member)
							{
//								#if DEBUG_MODULE

								if (this_connection->pilot_entity)
								{

									debug_log ("COMMS MAN: REFUSING GUNSHIP FOR PLAYER %s (dpid %d) for helicopter %d",
													get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME),
													received_id, pilot_data.gunship_index);
								}
								else
								{

									debug_log ("COMMS MAN: Refusing gunship for player %d to helicopter %d", received_id, pilot_data.gunship_index);
								}

//								#endif

								send_packet (received_id, PACKET_TYPE_GUNSHIP_REQUEST_REFUSED, NULL, 0, SEND_TYPE_PERSONAL);

								break;
							}

							new_connection = get_connection_list_item (received_id);

							//
							// send acceptance
							//

							buffer [0] = index_number;

//							#if DEBUG_MODULE

							debug_log ("COMMS MAN: sending gunship request accepted for gunship %d pilot id %d", index_number, received_id);

//							#endif

							send_packet (received_id, PACKET_TYPE_GUNSHIP_REQUEST_ACCEPTED, (void *) &buffer, 4, SEND_TYPE_PERSONAL);

							new_connection->gunship_number = pilot_data.gunship_index;

							new_connection->gunship_entity = member;
						}

						break;
					}

					case PACKET_TYPE_CLIENT_CAMPAIGN_DATA_REQUEST:
					{

						connection_list_type
							*new_connection;

						int
							index_number;

						if (get_comms_model () == COMMS_MODEL_SERVER)
						{

							#if DEBUG_MODULE

							if (this_connection->pilot_entity)
							{

								debug_log ("COMMS MAN: RECEIVED JOIN REQUEST by %s (dpid %d)",
												get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME),
												received_id);
							}
							else
							{

								debug_log ("COMMS MAN: received JOIN REQUEST by %d", received_id);
							}

							#endif

							//
							// flush group send buffer
							//

							send_comms_data ();

							//
							// pack mission data into packet
							//

							new_connection = get_connection_list_item (received_id);

							//
							// Store entity data
							//

							while (pack_session (new_connection->connection_receive_buffer, &new_connection->connection_receive_buffer_size, PACK_MODE_CLIENT_SESSION))
							{

								new_connection->connection_receive_buffer_size *= 2;

								#if DEBUG_MODULE

								debug_log ("COMMS MAN: Mission data: connection_receive_buffer too small, mallocing to %d", new_connection->connection_receive_buffer_size);

								#endif

								free_mem (new_connection->connection_receive_buffer);

								new_connection->connection_receive_buffer = malloc_heap_mem (new_connection->connection_receive_buffer_size);

								memset (new_connection->connection_receive_buffer, 0, new_connection->connection_receive_buffer_size);
							}

							// add frame id
							index_number = get_group_frame_id ();
							memcpy (&new_connection->connection_receive_buffer [new_connection->connection_receive_buffer_size], (void *) &index_number, sizeof (int));
							new_connection->connection_receive_buffer_size += sizeof (int);

							send_packet (received_id, PACKET_TYPE_MISSION_DATA, new_connection->connection_receive_buffer, new_connection->connection_receive_buffer_size, SEND_TYPE_PERSONAL);

							memset (new_connection->connection_receive_buffer, 0, new_connection->connection_receive_buffer_size);

							//
							// send group frame id
							//

							SDL_Delay (100);

							index_number = get_group_frame_id ();

							//send_packet (received_id, PACKET_TYPE_FRAME_ID, (void *) &index_number, 4, SEND_TYPE_PERSONAL);

							zero_average_pack_size ();
						}

						break;
					}

					case PACKET_TYPE_CLIENT_FRAME_ID:
					{

						int
							loop1,
							loop2,
							index_number;

						stub_packet_type
							*stub_packet;

						connection_list_type
							*new_connection;

						index_number = get_list_item (received_data, int);

						new_connection = get_connection_list_item (received_id);

						//#if DEBUG_MODULE

						if (new_connection)
						{

							debug_log ("COMMS MAN: received CLIENT FRAME ID (%d) by %d %s", index_number, received_id, direct_play_get_player_name (received_id));
						}

						//#endif

						//
						// send all packets between when the client started to join and when it actually joined.
						//

						for (loop1 = index_number; loop1 < get_group_frame_id () - 1; loop1 ++)
						{

							//#if DEBUG_MODULE

							debug_log ("COMMS MAN: sending packet %d frame %d to recently joined client", loop1, 0);

							//#endif

							stub_packet = resend_packet (received_id, loop1, 1, SEND_TYPE_GROUP);

							ASSERT (stub_packet);

							for (loop2 = 2; loop2 <= stub_packet->packet->number_of_packets; loop2 ++)
							{

								//#if DEBUG_MODULE

								debug_log ("COMMS MAN: sending packet %d frame %d to recently joined client", loop1, loop2);

								//#endif

								stub_packet = resend_packet (received_id, loop1, loop2, SEND_TYPE_GROUP);
							}
						}

						break;
					}

					case PACKET_TYPE_GUNSHIP_REQUEST_REFUSED:
					{

//						#if DEBUG_MODULE

						debug_log ("COMMS MAN: Gunship refused");

//						#endif

						set_server_response (SERVER_RESPONSE_REFUSE);

						break;
					}

					case PACKET_TYPE_GUNSHIP_REQUEST_ACCEPTED:
					{

						entity
							*gunship;

						int
							index_number;

//						#if DEBUG_MODULE

						debug_log ("COMMS MAN: received GUNSHIP ACCEPTED by %d", received_id);

//						#endif

						//
						// set gunship
						//

						index_number = get_list_item (received_data, int);

						ASSERT (get_pilot_entity ());

						gunship = get_local_entity_safe_ptr (index_number);

						debug_filtered_log ("COMM_MAN: setting gunship");

						planner_event = FALSE;

						if (get_event_stack_head_function() == ingame_screen_set_events)
						{

							pop_event (ingame_screen_set_events);

							planner_event = TRUE;
						}

						assign_entity_to_user (gunship);

						if (planner_event)
						{

							push_event (ingame_screen_set_events, "ingame screen events");
						}

						debug_filtered_log ("COMM_MAN: gunship set");

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

						break;
					}

					case PACKET_TYPE_PILOT_REQUEST_ACCEPTED:
					{

						int
							index_number;

						ASSERT (get_comms_model () == COMMS_MODEL_CLIENT);

//						#if DEBUG_MODULE

						debug_log ("COMMS MAN: received PILOT ACCEPTED by %d", received_id);

//						#endif

						index_number = get_list_item (received_data, int);

						set_pilot_entity (get_local_entity_safe_ptr (index_number));

						break;
					}

					case PACKET_TYPE_MISSION_DATA:
					{

						#if DEBUG_MODULE

						debug_log ("COMMS MAN: received MISSION DATA by %d", received_id);

						#endif

						set_mouse_graphic_off ();

						//
						// LOAD TERRAIN DATA
						//

						load_3d_terrain_game_data ();

						initialise_population_name_database ();

						load_route_data (); // might need to send what route filename to load...

						//
						// Initialise stuff
						//

						create_local_only_entities (PACK_MODE_CLIENT_SESSION);

						/////////////////////////////////////////////////////////////////
						if (strstr ((char*) stoupper (side_data_filename), "SID"))
						{

							read_sector_side_file (side_data_filename);
						}
						else if (strstr ((char*) stoupper (side_data_filename), "DAT"))
						{

							load_ai_sector_data (side_data_filename);
						}
						/////////////////////////////////////////////////////////////////

						deinitialise_formation_database ();

						initialise_formation_database ();

						deinitialise_formation_component_database ();

						initialise_formation_component_database ();

						if (unpack_session (received_data, received_size - 4, PACK_MODE_CLIENT_SESSION))
						{

							debug_fatal ("COMMS MAN: received size overflow");
						}
/*
						force = get_local_entity_first_child (get_session_entity (), LIST_TYPE_FORCE);

						while (force)
						{

							create_frontline (force);

							force = get_local_entity_child_succ (force, LIST_TYPE_FORCE);
						}

*/
						{
							int
								index_number;

							connection_list_type
								*new_connection;

							received_data += received_size - 4;
							index_number = get_list_item (received_data, int);

							new_connection = get_connection_list_item (received_id);

							new_connection->receive_group_frame_id = index_number;

							send_packet (get_server_id (), PACKET_TYPE_CLIENT_FRAME_ID, (void *) &index_number, 4, SEND_TYPE_PERSONAL);
						}

						session_data = TRUE;

						//direct_play_join_group ();

						set_gunship_waiting_for_connection ( FALSE );

						zero_average_pack_size ();

						set_mouse_graphic_on ();

						break;
					}

					case PACKET_TYPE_FRAME_ID:
					{

						int
							index_number;

						connection_list_type
							*new_connection;

						index_number = get_list_item (received_data, int);

						#if DEBUG_MODULE

						debug_log ("COMMS MAN: received FRAME ID (%d) by %d", index_number, received_id);

						#endif

						new_connection = get_connection_list_item (received_id);

						new_connection->receive_group_frame_id = index_number;

						send_packet (get_server_id (), PACKET_TYPE_CLIENT_FRAME_ID, (void *) &index_number, 4, SEND_TYPE_PERSONAL);

						break;
					}

					///////////////////////////////////////////////////////////////////////////////////////////////
					//
					// In game packets
					//
					///////////////////////////////////////////////////////////////////////////////////////////////

					case PACKET_TYPE_AI_DATA:
					{

						int
							//padding,
							data_size;

						#if DEBUG_MODULE >= 2

						debug_log ("COMMS MAN: received AI DATA by %d", received_id);

						#endif

						if (get_comms_model () == COMMS_MODEL_CLIENT)
						{

							ASSERT (session_data);
						}

						data_size = get_list_item (received_data, int);

						//debug
						//padding = get_list_item (received_data, int);
						//end

						open_unpack_buffer (received_data, received_size);

						process_received_entity_comms_messages ();

						ASSERT (!get_unpack_buffer_overflow ());

						close_unpack_buffer ();

						//debug
						//padding = get_list_item (received_data, int);
						//end

						memset (received_data, 0, this_connection->connection_receive_buffer_size);

						break;
					}

					case PACKET_TYPE_END_GAME:
					{

						debug_log ("COMMS MAN: received END GAME from %d", received_id);

						if (get_comms_model () == COMMS_MODEL_SERVER)
						{
							if (this_connection->gunship_entity)
							{

								set_client_server_entity_int_value (this_connection->gunship_entity, INT_TYPE_PLAYER, ENTITY_PLAYER_AI);
							}

							if (this_connection->pilot_entity)
							{

								debug_log ("	from %s ", get_local_entity_string (this_connection->pilot_entity, STRING_TYPE_PILOTS_NAME));
							}

							unregister_connection (received_id);
						}
						else
						{

							if (received_id == get_server_id ())
							{

								//setup_campaign_over_screen (get_local_force_entity (get_global_gunship_side ()), CAMPAIGN_RESULT_STALEMATE);

								start_game_exit (GAME_EXIT_KICKOUT, FALSE);
							}
						}

						receive_flag = FALSE;

						break;
					}

					case PACKET_TYPE_SERVER_REJECTED:
					{

						debug_log ("COMMS MAN: received SERVER REJECTED (server id %d)", received_id);

						//setup_campaign_over_screen (get_local_force_entity (get_global_gunship_side ()), CAMPAIGN_RESULT_SERVER_REJECTED);

						start_game_exit (GAME_EXIT_KICKOUT, FALSE);

						break;
					}

					default:
					{

						debug_fatal ("ERROR: Data Exchange, unknown packet type %d", type);

						break;
					}
				}
			}

			send_type --;
		}
	}
}
Example #17
0
void initialise_smoke_grenade_explosion_criteria_table ()
{
	weapon_explosion_criteria
		*table;

	weapon_kill_codes
		kill_code;

	int
		count;

	table = &smoke_grenade_explosion_criteria_table;

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

	kill_code =  WEAPON_KILL_CODE_OK;

	table->kill_code_criteria_count [kill_code] = 0;

	table->kill_code_criteria [kill_code] = NULL;

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

	kill_code = WEAPON_KILL_CODE_EXHAUSTED;

	count = 1;

	table->kill_code_criteria_count [kill_code] = count;

	table->kill_code_criteria [kill_code] = malloc_heap_mem (sizeof (weapon_explosion_kill_code_criteria) * count);

	add_explosion_criteria (0, kill_code, 0, INT_MAX, META_EXPLOSION_TYPE_NONE, table);

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

	kill_code = WEAPON_KILL_CODE_OUT_OF_BOUNDS;

	count = 1;

	table->kill_code_criteria_count [kill_code] = count;

	table->kill_code_criteria [kill_code] = malloc_heap_mem (sizeof (weapon_explosion_kill_code_criteria) * count);

	add_explosion_criteria (0, kill_code, 0, INT_MAX, META_EXPLOSION_TYPE_NONE, table);

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

	kill_code = WEAPON_KILL_CODE_HIT_LAND;

	count = 1;

	table->kill_code_criteria_count [kill_code] = count;

	table->kill_code_criteria [kill_code] = malloc_heap_mem (sizeof (weapon_explosion_kill_code_criteria) * count);

	add_explosion_criteria (0, kill_code, 0, INT_MAX, PURPLE_FLARE_META_EXPLOSION, table);

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

	kill_code = WEAPON_KILL_CODE_HIT_WATER;

	count = 1;

	table->kill_code_criteria_count [kill_code] = count;

	table->kill_code_criteria [kill_code] = malloc_heap_mem (sizeof (weapon_explosion_kill_code_criteria) * count);

	add_explosion_criteria (0, kill_code, 0, INT_MAX, META_EXPLOSION_TYPE_NONE, table);

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

	kill_code = WEAPON_KILL_CODE_HIT_TARGET;

	table->kill_code_criteria_count [kill_code] = 0;

	table->kill_code_criteria [kill_code] = NULL;

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

	kill_code = WEAPON_KILL_CODE_OVERSHOT_TARGET;

	table->kill_code_criteria_count [kill_code] = 0;

	table->kill_code_criteria [kill_code] = NULL;

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

	kill_code = WEAPON_KILL_CODE_SELF_DESTRUCT;

	table->kill_code_criteria_count [kill_code] = 0;

	table->kill_code_criteria [kill_code] = NULL;
}
Example #18
0
void initialise_formation_database (void)
{

	session_list_data_type
		*current_session;

	formation_type
		*new_formation;

	FILE
		*file_ptr;

	file_tags
		tag;

	int
		loop,
		type,
		count,
		result;

	char
		name [1024],
		temp_filename [1024];

	float
		x,
		y,
		z;

	formation_component_database = NULL;

	formation_database = NULL;

	last_formation_index = NUM_FORMATION_TYPES;

	new_formation = NULL;

	ASSERT (!formation_database);

	current_session = get_current_game_session ();

	sprintf (temp_filename, "%s", FORMATION_DEFAULT_FULLPATH);

	file_ptr = safe_fopen (temp_filename, "r");

	while (TRUE)
	{

		tag = (file_tags) get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG);

		switch (tag)
		{

			case FILE_TAG_START:
			{

				continue;
			}

			case FILE_TAG_FORMATION:
			{

				new_formation = (formation_type *) malloc_heap_mem (sizeof (formation_type));
				memset (new_formation, 0, sizeof (formation_type));

				result = get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG);
				ASSERT (result == FILE_TAG_TYPE);
				type = get_next_file_enum (file_ptr, formation_names, NUM_FORMATION_TYPES);

				new_formation->formation = (formation_types) type;

				result = get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG);
				ASSERT (result == FILE_TAG_NAME);
				get_next_file_string (file_ptr, name, sizeof (name));

				new_formation->name = (char *) malloc_heap_mem (sizeof (char) * (strlen (name) + 1));
				strcpy (new_formation->name, name);

				result = get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG);
				ASSERT (result == FILE_TAG_RADIUS);
				//new_formation->max_formation_radius = get_next_file_int (file_ptr);

				result = get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG);
				ASSERT (result == FILE_TAG_COUNT);
				count = get_next_file_int (file_ptr);

				new_formation->number_in_formation = count;

				if (count > 0)
				{
	
					new_formation->sites = (vec3d *) malloc_heap_mem (sizeof (vec3d) * (count));
	
					loop = 0;
	
  					#if DEBUG_MODULE

					debug_log ("EN_FORMS: loading formation %s", formation_names [new_formation->formation]);

					#endif
	
					while (loop < count)
					{
	
						result = get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG);
						ASSERT (result == FILE_TAG_POSITION);
	
						x = get_next_file_float (file_ptr);
						y = get_next_file_float (file_ptr);
						z = get_next_file_float (file_ptr);
	
						new_formation->sites [loop].x = x;
						new_formation->sites [loop].y = y;
						new_formation->sites [loop].z = z;
	
						#if DEBUG_MODULE

						debug_log ("	adding site %f, %f, %f", x, y, z);

						#endif
	
						loop ++;
					}
				}

				result = get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG);

				ASSERT (result == FILE_TAG_END);

				//
				// link into database
				//

				new_formation->next = formation_database;

				formation_database = new_formation;

				break;
			}

			case FILE_TAG_END:
			{

				fclose (file_ptr);

				return;
			}
		}
	}
}
Example #19
0
connection_list_type *register_connection (DPID connection_id)
{

	connection_list_type
		*new_connection;

	//
	// stop pause or time acceleration if game is not single player
	//

	set_min_time_acceleration (NULL);

	//
	//
	//

	if (new_connection = get_connection_list_item (connection_id))
	{

		#if SERVER_DEBUG

		debug_log ("SERVER: already registered connection %d", connection_id);

		#endif

		return new_connection;
	}
	else
	{

		new_connection = (connection_list_type *) malloc_heap_mem (sizeof (connection_list_type));

		memset (new_connection, 0, sizeof (connection_list_type));

		new_connection->connection_receive_buffer = (unsigned char *) malloc_heap_mem (command_line_comms_connection_receive_size);

		new_connection->connection_receive_buffer_size = command_line_comms_connection_receive_size;

		debug_log ("SERVER: connection receive buffer size = %d, commandline %d", new_connection->connection_receive_buffer_size, command_line_comms_connection_receive_size);

		new_connection->already_sent_query_data = FALSE;

		new_connection->group_resend_timer = 0.0;

		new_connection->personal_resend_timer = 0.0;

		new_connection->connection_id = connection_id;

		new_connection->next = connection_list_head;

		new_connection->receive_group_frame_id = 0;

		new_connection->receive_personal_frame_id = 0;

		new_connection->send_personal_frame_id = 0;

		connection_list_head = new_connection;

		debug_log ("SERVER: registering new connection %d", connection_id);

		#if SERVER_DEBUG

		debug_watch ("Connection id %d data", MT_INT, &new_connection->connection_id);
		debug_watch ("	number of packets				= %d", MT_INT, &new_connection->number_of_packets);
		debug_watch ("	size								= %d", MT_INT, &new_connection->size);
		//debug_watch ("	send group id					= %d", MT_INT, &new_connection->send_group_frame_id);
		debug_watch ("	send personal id				= %d", MT_INT, &new_connection->send_personal_frame_id);
		debug_watch ("	receive group id				= %d", MT_INT, &new_connection->receive_group_frame_id);
		debug_watch ("	receive personal id				= %d", MT_INT, &new_connection->receive_personal_frame_id);
		debug_watch ("	rerequest counter				= %d", MT_INT, &new_connection->packet_rerequested);
		debug_watch ("	gunship ptr						= %d", MT_INT, &new_connection->gunship_entity);
		debug_watch ("	player ptr							= %d", MT_INT, &new_connection->pilot_entity);
		debug_watch ("	gunship number				= %d", MT_INT, &new_connection->gunship_number);
		//debug_watch ("	last packet time				 	= %d", MT_INT, &new_connection->time);
		debug_watch ("	group resend time				 	= %f", MT_FLOAT, &new_connection->group_resend_timer);
		debug_watch ("	personal resend time			 	= %f", MT_FLOAT, &new_connection->personal_resend_timer);

		#endif

		return new_connection;
	}
}
Example #20
0
void unpack_local_force_data (entity *en, pack_modes mode)
{

	int
		count,
		loop;

	force
		*raw;

	campaign_criteria_type
		*last_campaign_criteria,
		*campaign_criteria;

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

	ASSERT (en);

	raw = (force *) get_local_entity_data (en);
		
	switch (mode)
	{
		////////////////////////////////////////
		case PACK_MODE_SERVER_SESSION:
		////////////////////////////////////////
		{
         unpack_string (en, STRING_TYPE_FORCE_NAME, raw->force_name);

			// keysite_force
		
			// pilot root
		
			unpack_list_root (en, LIST_TYPE_DIVISION, &raw->division_root);
	
			unpack_list_root (en, LIST_TYPE_CAMPAIGN_OBJECTIVE, &raw->campaign_objective_root);
	
			// air_registry_root
			// ground_registry_root
			// sea_registry_root
	
//			unpack_list_root (en, LIST_TYPE_INDEPENDENT_GROUP, &raw->independent_group_root);
	
			// force_link
		
			// update link
		
			// task generation //////////////////////////////////////////////
		
			for (loop = 0; loop < NUM_ENTITY_SUB_TYPE_TASKS; loop ++)
			{
				raw->task_generation [loop].valid = unpack_int_value (en, INT_TYPE_VALID);

				raw->task_generation [loop].created = unpack_int_value (en, INT_TYPE_TASK_GENERATION);
			}
			/////////////////////////////////////////////////////////////////
		
			// campaign criteria ////////////////////////////////////////////
		
			count = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_COUNT);
	
			last_campaign_criteria = NULL;
	
			while (count)
			{
	
				campaign_criteria = (campaign_criteria_type *) malloc_heap_mem (sizeof (campaign_criteria_type));
	
				memset (campaign_criteria, 0, sizeof (campaign_criteria_type));
		
				campaign_criteria->criteria_type = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_TYPE);
		
				campaign_criteria->valid = unpack_int_value (en, INT_TYPE_VALID);
		
				campaign_criteria->result = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_RESULT);
		
				campaign_criteria->value1 = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_VALUE);
		
				campaign_criteria->value2 = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_VALUE);
		
				campaign_criteria->value3 = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_VALUE);
		
				campaign_criteria->value4 = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_VALUE);
		
				campaign_criteria->next = last_campaign_criteria;
	
				raw->campaign_criteria = campaign_criteria;
	
				last_campaign_criteria = campaign_criteria;
	
				count --;
			}
			/////////////////////////////////////////////////////////////////
		
			// force_info_criteria
		
			for (loop = 0; loop < NUM_FORCE_INFO_CATAGORIES; loop ++)
			{
				raw->force_info_current_hardware [loop] = unpack_int_value (en, INT_TYPE_VALUE);
		
				raw->force_info_reserve_hardware [loop] = unpack_int_value (en, INT_TYPE_VALUE);
			}
			/////////////////////////////////////////////////////////////////
	
			for (loop = 0; loop < NUM_ENTITY_SUB_TYPE_GROUPS; loop ++)
			{
				raw->kills [loop] = unpack_int_value (en, INT_TYPE_VALUE);
				raw->losses [loop] = unpack_int_value (en, INT_TYPE_VALUE);
//				raw->group_count [loop] = unpack_int_value (en, INT_TYPE_VALUE);
			}

			raw->sleep = unpack_float_value (en, FLOAT_TYPE_SLEEP);
		
			raw->force_attitude = unpack_int_value (en, INT_TYPE_FORCE_ATTITUDE);
		
			// sector_count
		
			raw->colour = unpack_int_value (en, INT_TYPE_COLOUR);
		
			raw->side = unpack_int_value (en, INT_TYPE_SIDE);
	
			break;
		}
		////////////////////////////////////////
		case PACK_MODE_CLIENT_SESSION:
		////////////////////////////////////////
		{
			//
			// create entity
			//

			debug_assert (get_free_entity (get_local_entity_safe_index (en)));

			set_local_entity_type (en, ENTITY_TYPE_FORCE);

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

			set_local_entity_data (en, raw);

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

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

         unpack_string (en, STRING_TYPE_FORCE_NAME, raw->force_name);

			// keysite_force
	
			unpack_list_root (en, LIST_TYPE_PILOT, &raw->pilot_root);

			unpack_list_root (en, LIST_TYPE_DIVISION, &raw->division_root);

			unpack_list_root (en, LIST_TYPE_CAMPAIGN_OBJECTIVE, &raw->campaign_objective_root);

			//	air_registry_root
			//	ground_registry_root
			//	sea_registry_root

//			unpack_list_root (en, LIST_TYPE_INDEPENDENT_GROUP, &raw->independent_group_root);
	
			unpack_list_link (en, LIST_TYPE_FORCE, &raw->force_link);

			// update_link

			////////////////////////////////////////////
			// task_generation
			for (loop = 0; loop < NUM_ENTITY_SUB_TYPE_TASKS; loop ++)
			{
				raw->task_generation [loop].valid = unpack_int_value (en, INT_TYPE_VALID);

				raw->task_generation [loop].created = unpack_int_value (en, INT_TYPE_TASK_GENERATION);
			}
			////////////////////////////////////////////

			////////////////////////////////////////////
			// campaign criteria 
			raw->campaign_criteria = NULL;

			count = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_COUNT);

			while (count)
			{

				count --;

				campaign_criteria = (campaign_criteria_type *) malloc_heap_mem (sizeof (campaign_criteria_type));

				memset (campaign_criteria, 0, sizeof (campaign_criteria_type));

				campaign_criteria->next = raw->campaign_criteria;

				raw->campaign_criteria = campaign_criteria;

				campaign_criteria->criteria_type = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_TYPE);

				campaign_criteria->valid = unpack_int_value (en, INT_TYPE_VALID);

				campaign_criteria->result = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_RESULT);

				campaign_criteria->value1 = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_VALUE);

				campaign_criteria->value2 = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_VALUE);

				campaign_criteria->value3 = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_VALUE);

				campaign_criteria->value4 = unpack_int_value (en, INT_TYPE_CAMPAIGN_CRITERIA_VALUE);
			}
			/////////////////////////////////////////////////////////////////

			////////////////////////////////////////////
			// force_info_criteria
			for (loop = 0; loop < NUM_FORCE_INFO_CATAGORIES; loop ++)
			{
				raw->force_info_current_hardware [loop] = unpack_int_value (en, INT_TYPE_VALUE);

				raw->force_info_reserve_hardware [loop] = unpack_int_value (en, INT_TYPE_VALUE);
			}
			// force_info_criteria

			for (loop = 0; loop < NUM_ENTITY_SUB_TYPE_GROUPS; loop ++)
			{
				raw->kills [loop] = unpack_int_value (en, INT_TYPE_VALUE);
				raw->losses [loop] = unpack_int_value (en, INT_TYPE_VALUE);
//				raw->group_count [loop] = unpack_int_value (en, INT_TYPE_VALUE);
			}

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

			raw->force_attitude = unpack_int_value (en, INT_TYPE_FORCE_ATTITUDE);

			raw->sector_count = unpack_int_value (en, INT_TYPE_FORCE_SECTOR_COUNT);

			raw->colour = unpack_int_value (en, INT_TYPE_COLOUR);

			raw->side = unpack_int_value (en, INT_TYPE_SIDE);

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

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

			debug_assert (get_free_entity (get_local_entity_safe_index (en)));

			set_local_entity_type (en, ENTITY_TYPE_FORCE);

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

			set_local_entity_data (en, raw);

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

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

         unpack_string (en, STRING_TYPE_FORCE_NAME, raw->force_name);

			// keysite_force_root

			unpack_list_root (en, LIST_TYPE_PILOT, &raw->pilot_root);

			unpack_list_link (en, LIST_TYPE_FORCE, &raw->force_link);

			// update_link

			// task_generation

			// campaign_criteria

			// force_info_catagories

			// sleep

			raw->force_attitude = unpack_int_value (en, INT_TYPE_FORCE_ATTITUDE);

			raw->colour = unpack_int_value (en, INT_TYPE_COLOUR);

			raw->side = unpack_int_value (en, INT_TYPE_SIDE);

			break;
		}
	}
}
Example #21
0
void comms_record_data (char *data, int size)
{

	char
		*new_data_record;

	//
	// Check data_record is big enough
	//

	while (data_record_size + size > command_line_comms_data_record_size)
	{

		new_data_record = (char *) malloc_heap_mem (command_line_comms_data_record_size * 2);

		ASSERT (data_record);

		memcpy (new_data_record, data_record, command_line_comms_data_record_size);

		command_line_comms_data_record_size *= 2;

		free_mem (data_record);

		data_record = new_data_record;

		#if DEBUG_MODULE

		debug_log ("COMMS MAN: MAX_DATA_RECORD_SIZE exceeded, mallocing %d (requested %d)", command_line_comms_data_record_size, data_record_size + size);

		#endif
	}

	//
	// Store size of data
	//

	memcpy (&data_record [data_record_size], &size, sizeof (int));

	data_record_size += sizeof (int);

	//
	// Store data
	//

	#if DEBUG_MODULE >= 2

	debug_log ("COMMS MAN: recording %d data", size);

	#endif

	#if COMMS_STATS

	packet_record_data_count ++;

	#endif

	memcpy (&data_record [data_record_size], data, size);

	data_record_size += size;

	//
	// latency test
	//
	{

		int
			packet_count;

		packet_count = data_record_size / command_line_comms_packet_data_size;

		if (packet_count > 1)
		{

			//debug_log ("COMM_MAN: possible packet latency problem. Holding %d packets", packet_count);
		}
  	}
	//
	// end
	//
}
Example #22
0
void initialise_heat_explosion_criteria_table ()
{
	weapon_explosion_criteria
		*table;

	weapon_kill_codes
		kill_code;

	int
		count;

	table = &heat_explosion_criteria_table;

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

	kill_code =  WEAPON_KILL_CODE_OK;

	table->kill_code_criteria_count [kill_code] = 0;

	table->kill_code_criteria [kill_code] = NULL;

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

	kill_code = WEAPON_KILL_CODE_EXHAUSTED;

	count = 1;

	table->kill_code_criteria_count [kill_code] = count;

	table->kill_code_criteria [kill_code] = malloc_heap_mem (sizeof (weapon_explosion_kill_code_criteria) * count);

	add_explosion_criteria (0, kill_code, 0, INT_MAX, SMALL_HE_META_EXPLOSION, table);

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

	kill_code = WEAPON_KILL_CODE_OUT_OF_BOUNDS;

	count = 1;

	table->kill_code_criteria_count [kill_code] = count;

	table->kill_code_criteria [kill_code] = malloc_heap_mem (sizeof (weapon_explosion_kill_code_criteria) * count);

	add_explosion_criteria (0, kill_code, 0, INT_MAX, META_EXPLOSION_TYPE_NONE, table);

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

	kill_code = WEAPON_KILL_CODE_HIT_LAND;

	count = 3;

	table->kill_code_criteria_count [kill_code] = count;

	table->kill_code_criteria [kill_code] = malloc_heap_mem (sizeof (weapon_explosion_kill_code_criteria) * count);

	add_explosion_criteria (0, kill_code, 0, 99, SMALL_HE_META_EXPLOSION, table);
	add_explosion_criteria (1, kill_code, 100, 999, MEDIUM_HE_META_EXPLOSION, table);
	add_explosion_criteria (2, kill_code, 1000, INT_MAX, LARGE_HE_META_EXPLOSION, table);

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

	kill_code = WEAPON_KILL_CODE_HIT_WATER;

	count = 3;

	table->kill_code_criteria_count [kill_code] = count;

	table->kill_code_criteria [kill_code] = malloc_heap_mem (sizeof (weapon_explosion_kill_code_criteria) * count);

	add_explosion_criteria (0, kill_code, 0, 99, SMALL_WATER_META_EXPLOSION, table);
	add_explosion_criteria (1, kill_code, 100, 999, MEDIUM_WATER_META_EXPLOSION, table);
	add_explosion_criteria (2, kill_code, 1000, INT_MAX, LARGE_WATER_META_EXPLOSION, table);

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

	kill_code = WEAPON_KILL_CODE_HIT_TARGET;

	count = 3;

	table->kill_code_criteria_count [kill_code] = count;

	table->kill_code_criteria [kill_code] = malloc_heap_mem (sizeof (weapon_explosion_kill_code_criteria) * count);

	add_explosion_criteria (0, kill_code, 0, 99, SMALL_HE_META_EXPLOSION, table);
	add_explosion_criteria (1, kill_code, 100, 999, MEDIUM_HE_META_EXPLOSION, table);
	add_explosion_criteria (2, kill_code, 1000, INT_MAX, LARGE_HE_META_EXPLOSION, table);

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

	kill_code = WEAPON_KILL_CODE_OVERSHOT_TARGET;

	count = 3;

	table->kill_code_criteria_count [kill_code] = count;

	table->kill_code_criteria [kill_code] = malloc_heap_mem (sizeof (weapon_explosion_kill_code_criteria) * count);

	add_explosion_criteria (0, kill_code, 0, 99, SMALL_HE_META_EXPLOSION, table);
	add_explosion_criteria (1, kill_code, 100, 999, MEDIUM_HE_META_EXPLOSION, table);
	add_explosion_criteria (2, kill_code, 1000, INT_MAX, LARGE_HE_META_EXPLOSION, table);

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

	kill_code = WEAPON_KILL_CODE_SELF_DESTRUCT;

	count = 3;

	table->kill_code_criteria_count [kill_code] = count;

	table->kill_code_criteria [kill_code] = malloc_heap_mem (sizeof (weapon_explosion_kill_code_criteria) * count);

	add_explosion_criteria (0, kill_code, 0, 99, SMALL_HE_META_EXPLOSION, table);
	add_explosion_criteria (1, kill_code, 100, 999, MEDIUM_HE_META_EXPLOSION, table);
	add_explosion_criteria (2, kill_code, 1000, INT_MAX, LARGE_HE_META_EXPLOSION, table);
}
Example #23
0
static void unpack_local_data (entity *en, entity_types type, pack_modes mode)
{
	ASSERT ((mode >= 0) && (mode < NUM_PACK_MODES));

	switch (mode)
	{
		////////////////////////////////////////
		case PACK_MODE_SERVER_SESSION:
		case PACK_MODE_CLIENT_SESSION:
		////////////////////////////////////////
		{
			int
				loop,
				index;

			sound_effect
				*raw;

			//
			// create entity
			//

			index = unpack_entity_safe_index ();

			en = get_free_entity (index);

			set_local_entity_type (en, type);

			raw = malloc_heap_mem (sizeof (sound_effect));

			set_local_entity_data (en, raw);

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

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

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

			//
			// unpack sound data
			//

			raw->sound_effect_sequence_count = unpack_int_value (en, INT_TYPE_SOUND_EFFECT_SEQUENCE_COUNT);

			ASSERT (raw->sound_effect_sequence_count > 0);

			raw->effect_index = malloc_fast_mem (sizeof (sound_sample_indices) * raw->sound_effect_sequence_count);

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

			raw->amplification = unpack_float_value (en, FLOAT_TYPE_AMPLIFICATION);

			raw->effect_lifetime = unpack_float_value (en, FLOAT_TYPE_EFFECT_LIFETIME);

			raw->valid_effect_lifetime = unpack_float_value (en, FLOAT_TYPE_VALID_EFFECT_LIFETIME);

			//sound_effect_data 

			raw->sound_channel = unpack_int_value (en, INT_TYPE_SOUND_CHANNEL);

			raw->sound_locality = unpack_int_value (en, INT_TYPE_SOUND_LOCALITY);

			raw->valid_sound_effect = unpack_int_value (en, INT_TYPE_VALID_SOUND_EFFECT);

			raw->looping = unpack_int_value (en, INT_TYPE_SOUND_EFFECT_LOOPING);

			raw->panning = unpack_int_value (en, INT_TYPE_SOUND_EFFECT_PANNING);

			//
			// link into system
			//

			// sound effect needs a parent
			//ASSERT (raw->eff.special_effect_link.parent);

			if (unpack_int_value (en, INT_TYPE_VALID))
			{
				insert_local_entity_into_parents_child_list (en, LIST_TYPE_UPDATE, get_update_entity (), NULL);
			}

			#if DEBUG_MODULE

			debug_log ("SE_PACK: Unpacked %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:
		////////////////////////////////////////
		{
			//
			// always use access functions to set the data
			//

			break;
		}
	}
}
Example #24
0
void initialise_formation_component_database (void)
{

	formation_type
		*formation_data;

	session_list_data_type
		*current_session;

	formation_vehicle_components
		*new_formation_component;

	FILE
		*file_ptr;

	file_tags
		tag;

	int
		loop,
		type,
		count,
		result;

	char
		temp_filename [1024];

	ASSERT (!formation_component_database);

	current_session = get_current_game_session ();

	file_ptr = NULL;

	// check if this campaign has its own formation component database
	if (current_game_session->data_path && current_game_session->campaign_directory)
	{
		sprintf (temp_filename, "%s\\%s\\%s", current_game_session->data_path, current_game_session->campaign_directory, FORMATION_COMPONENT_FILENAME);
		if (file_exist(temp_filename))
			file_ptr = safe_fopen (temp_filename, "r");

		if (file_ptr)
		{
			debug_log("formcomp file: %s", temp_filename);
		}
	}

	// check if this map has its own formation component database
	if (!file_ptr && current_game_session->data_path)
	{
		sprintf (temp_filename, "%s\\%s", current_game_session->data_path, FORMATION_COMPONENT_FILENAME);
		if (file_exist(temp_filename))
			file_ptr = safe_fopen (temp_filename, "r");

		if (file_ptr)
		{
			debug_log("formcomp file: %s", temp_filename);
		}
	}

	// use default if there is no specific one
	if (!file_ptr)
	{
		sprintf (temp_filename, "%s", FORMATION_COMPONENT_DEFAULT_FULLPATH);

		file_ptr = safe_fopen (temp_filename, "r");
	}

	while (TRUE)
	{

		tag = (file_tags) get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG);

		switch (tag)
		{

			case FILE_TAG_START:
			{

				continue;
			}

			case FILE_TAG_FORMATION_COMPONENT:
			{

				new_formation_component = (formation_vehicle_components *) malloc_heap_mem (sizeof (formation_vehicle_components));
				memset (new_formation_component, 0, sizeof (formation_vehicle_components));

				result = get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG);
				ASSERT (result == FILE_TAG_TYPE);
				type = get_next_file_enum (file_ptr, formation_component_names, NUM_FORMATION_COMPONENT_TYPES);

				new_formation_component->formation_component = (formation_component_types) type;

				result = get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG);
				ASSERT (result == FILE_TAG_TYPE);
				type = get_next_file_enum (file_ptr, formation_names, NUM_FORMATION_TYPES);

				new_formation_component->formation = (formation_types) type;

				result = get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG);
				ASSERT (result == FILE_TAG_COUNT);
				count = get_next_file_int (file_ptr);

				formation_data = get_formation (new_formation_component->formation);

				new_formation_component->group_type = get_next_file_enum (file_ptr, entity_sub_type_group_names, NUM_ENTITY_SUB_TYPE_GROUPS);

				ASSERT (count <= formation_data->number_in_formation);

				new_formation_component->count = count;

				if (count > 0)
				{
	
					new_formation_component->components = (entity_sub_types *) malloc_heap_mem (sizeof (entity_sub_types) * (count * 2));
	
					loop = 0;
	
					#if DEBUG_MODULE

					debug_log ("EN_FORMS: loading formation components %s, formation %s", formation_component_names [new_formation_component->formation_component], formation_names [new_formation_component->formation]);

					#endif
	
					while (loop < count * 2)
					{

						switch (group_database [new_formation_component->group_type].default_landing_type)
						{

							case ENTITY_SUB_TYPE_LANDING_GROUND:
							case ENTITY_SUB_TYPE_LANDING_PEOPLE:
							case ENTITY_SUB_TYPE_LANDING_SEA:
							{
		
								type = get_next_file_enum (file_ptr, entity_sub_type_vehicle_names, NUM_ENTITY_SUB_TYPE_VEHICLES);

								#if DEBUG_MODULE
								debug_log ("	adding component %d %s", loop, entity_sub_type_vehicle_names [type]);
								#endif

								break;
							}

							case ENTITY_SUB_TYPE_LANDING_HELICOPTER:
							case ENTITY_SUB_TYPE_LANDING_FIXED_WING:
							case ENTITY_SUB_TYPE_LANDING_FIXED_WING_TRANSPORT:
							{
		
								type = get_next_file_enum (file_ptr, entity_sub_type_aircraft_names, NUM_ENTITY_SUB_TYPE_AIRCRAFT);

								#if DEBUG_MODULE
								debug_log ("	adding component %d %s", loop, entity_sub_type_aircraft_names [type]);
								#endif

								break;
							}
						}
	
						new_formation_component->components [loop] = type;
	
						loop ++;
					}
				}

				result = get_next_file_tag (file_ptr, application_tag_strings, FILE_TAG_APPLICATION_LAST_TAG);

				ASSERT (result == FILE_TAG_END);

				//
				// link into database
				//

				new_formation_component->next = formation_component_database;

				formation_component_database = new_formation_component;

				break;
			}

			case FILE_TAG_END:
			{

				fclose (file_ptr);

				return;
			}
		}
	}
}
Example #25
0
session_list_data_type *add_session (const char *title, session_list_types type, int type_id, session_table_type *join_session, char *path, char *directory, char *filename, char *warzone_name, session_list_data_type **list, const char *address, int season)
{

	char
		*ptr,
		*filename_ptr;

	int
		unique_session;

	session_list_data_type
		*child,
		*session_item,
		*insert_position,
		*new_session;

	new_session = (session_list_data_type *) malloc_heap_mem (sizeof (session_list_data_type));

	memset (new_session, 0, sizeof (session_list_data_type));

	new_session->title = (char *) malloc_heap_mem (strlen (title) + 1);
	if (address)
		sprintf (new_session->ip_address, "%s", address);

	// 15JUN09 Casm retrieving season earlier
	new_session->season = season;

	// test
	if (type == SESSION_LIST_TYPE_RESTORE)
	{

		// strip off "campaign\" part of filename
		filename_ptr = strstr (filename, "\\");

		if (filename_ptr)
		{

			// advance ptr past '\'

			filename_ptr ++;

			//new_session->displayed_title = (char *) malloc_heap_mem (strlen (title) + strlen (filename_ptr) + 4);
			//sprintf (new_session->displayed_title, "%s (%s)", title, filename_ptr);

			new_session->displayed_title = (char *) malloc_heap_mem (strlen (filename_ptr) + 1);

			sprintf (new_session->displayed_title, "%s", filename_ptr);

			ptr = strrchr (new_session->displayed_title, '.');

			if (ptr)
			{

				*ptr = '\0';
			}
		}
		else
		{

			//new_session->displayed_title = (char *) malloc_heap_mem (strlen (title) + strlen (filename) + 4);
			//sprintf (new_session->displayed_title, "%s (%s)", title, filename);

			new_session->displayed_title = (char *) malloc_heap_mem (strlen (filename) + 1);

			sprintf (new_session->displayed_title, "%s", filename);

			ptr = strrchr (new_session->displayed_title, '.');

			if (ptr)
			{

				*ptr = '\0';
			}
		}
	}
	else
	{

		new_session->displayed_title = (char *) malloc_heap_mem (strlen (title) + 1);

		sprintf (new_session->displayed_title, "%s", title);
	}
	// test

	// work out where new item belongs in list (Alphabetically)

	session_item = *list;

	insert_position = NULL;

	unique_session = TRUE;

	while (session_item)
	{

		//
		// non-unique sessions
		//

		if ((strcmp (new_session->displayed_title, session_item->displayed_title) == 0) && (type == session_item->type))
		{

			unique_session = FALSE;

			insert_position = session_item;

			break;
		}

		//
		// unique sessions
		//

// Jabberwock 040201 Session filter
		if (session_item->type == SESSION_LIST_TYPE_FILTER)
		{
			if (type == SESSION_LIST_TYPE_FILTER)
			{
				if ((strcmp (new_session->displayed_title, session_item->displayed_title) < 0))
				{
					break;
				}
			}
		}
		else
		{
			if (type == SESSION_LIST_TYPE_FILTER)
			{
				break;
			}
			else
			{
				if ((strcmp (new_session->displayed_title, session_item->displayed_title) < 0))
				{
					break;
				}
			}
		}

// Jabberwock ends
		insert_position = session_item;

		session_item = session_item->next;
	}

	//
	// create new list item
	//

	list_id ++;

	sprintf (new_session->data_path, "%s", path);

	if (filename)
	{

			sprintf (new_session->campaign_directory, "%s", directory);

		sprintf (new_session->campaign_filename, "%s", filename);
	}

	if (warzone_name)
	{

	new_session->warzone_name = (char *) malloc_heap_mem (strlen (warzone_name) + 1);

	sprintf (new_session->warzone_name, "%s", warzone_name);
	}
	else
	{

		char
			*ptr,
			*last_ptr,
			path [512];

		strcpy (path, new_session->data_path);

		ptr = strstr (path, "\\maps\\");

		ptr += strlen ("\\maps\\");

		last_ptr = ptr;

		if (strstr (ptr, "\\"))
		{

			while (strstr (ptr, "\\"))
			{

				ptr = strstr (ptr, "\\");

				ptr += strlen ("\\");
			}

			ptr -= strlen ("\\");

			*ptr = '\0';
		}

		new_session->warzone_name = (char *) malloc_heap_mem (strlen (last_ptr) + 1);

		sprintf (new_session->warzone_name, "%s", last_ptr);
	}

	sprintf (new_session->title, "%s", title);

	new_session->type_id = type_id;

	new_session->list_id = list_id;

	new_session->type = type;

	new_session->join_session = join_session;

	//
	// add to session list
	//

	// Casm 18AUG05 Allow to show different saved games with the same name
	if (unique_session || type == SESSION_LIST_TYPE_RESTORE)
	{

		if (insert_position)
		{

			new_session->next = insert_position->next;

			insert_position->next = new_session;
		}
		else
		{

			// first session

			new_session->next = *list;

			*list = new_session;
		}
	}
	else
	{

		child = insert_position->child;

		insert_position->child = new_session;

		new_session->child = child;
	}

	return new_session;
}
Example #26
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);
}
Example #27
0
void create_local_sector_entities (void)
{
	static int
		old_min_map_z_sector = -1,
		old_max_map_z_sector = -1,
		old_num_map_z_sectors = -1,
		old_min_map_x_sector = -1,
		old_max_map_x_sector = -1,
		old_num_map_x_sectors = -1;

	int
		x_sec,
		z_sec;

	//
	// First time setup
	//

	if (old_min_map_z_sector == -1)
	{
		old_min_map_z_sector = MIN_MAP_Z_SECTOR;

		old_max_map_z_sector = MAX_MAP_Z_SECTOR;

		old_num_map_z_sectors = NUM_MAP_Z_SECTORS;

		old_min_map_x_sector = MIN_MAP_X_SECTOR;

		old_max_map_x_sector = MAX_MAP_X_SECTOR;

		old_num_map_x_sectors = NUM_MAP_X_SECTORS;
	}

	//
	// Deinitialise sectors (must be the 'old' map size)
	//

	if (entity_sector_map)
	{
		for (z_sec = old_min_map_z_sector; z_sec <= old_max_map_z_sector; z_sec ++)
		{
			for (x_sec = old_min_map_x_sector; x_sec <= old_max_map_x_sector; x_sec ++)
			{
				if (entity_sector_map [x_sec + (z_sec * old_num_map_x_sectors)]->type != ENTITY_TYPE_UNKNOWN)
				{
					debug_fatal ("SC_CREAT: uninitialised sector entity");
				}
			}
		}

		free_mem (entity_sector_map);
	}

	//
	// Store new map size
	//

	old_min_map_z_sector = MIN_MAP_Z_SECTOR;

	old_max_map_z_sector = MAX_MAP_Z_SECTOR;

	old_num_map_z_sectors = NUM_MAP_Z_SECTORS;

	old_min_map_x_sector = MIN_MAP_X_SECTOR;

	old_max_map_x_sector = MAX_MAP_X_SECTOR;

	old_num_map_x_sectors = NUM_MAP_X_SECTORS;

	//
	// Malloc memory
	//

	entity_sector_map = (entity **) malloc_heap_mem (sizeof (entity) * NUM_MAP_X_SECTORS * NUM_MAP_Z_SECTORS);

	//
	// Create sector entities
	//

	for (z_sec = MIN_MAP_Z_SECTOR; z_sec <= MAX_MAP_Z_SECTOR; z_sec++)
	{
		for (x_sec = MIN_MAP_X_SECTOR; x_sec <= MAX_MAP_X_SECTOR; x_sec++)
		{
			entity_sector_map[x_sec + (z_sec * NUM_MAP_X_SECTORS)] = create_local_entity
			(
				ENTITY_TYPE_SECTOR,
				ENTITY_INDEX_DONT_CARE,
				ENTITY_ATTR_INT_VALUE (INT_TYPE_X_SECTOR, x_sec),
				ENTITY_ATTR_INT_VALUE (INT_TYPE_Z_SECTOR, z_sec),
				ENTITY_ATTR_END
			);
		}
	}

	debug_log ("SC_CREAT: creating sectors. Start entity %d", get_local_entity_index (entity_sector_map [0]));
}