Esempio n. 1
0
void pack_effect_data (entity *en, effect *raw, pack_modes mode)
{
	ASSERT ((mode >= 0) && (mode < NUM_PACK_MODES));

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

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

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

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

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

				entity
					*spec;

				pack_int_value (en, INT_TYPE_VALID, TRUE);

				//
				// parent
				//

				link.parent = raw->special_effect_link.parent;

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

				spec = get_local_entity_child_succ (en, LIST_TYPE_SPECIAL_EFFECT);

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

						break;
					}

					spec = get_local_entity_child_succ (spec, LIST_TYPE_SPECIAL_EFFECT);
				}

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

				spec = get_local_entity_child_pred (en, LIST_TYPE_SPECIAL_EFFECT);

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

						break;
					}

					spec = get_local_entity_child_pred (spec, LIST_TYPE_SPECIAL_EFFECT);
				}

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

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

			// update_link

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

			break;
		}
	}
}
Esempio n. 2
0
static void update_server (entity *en)
{
	entity
		*parent,
		*next_segment,
		*prev_segment;

	entity_sub_types
		sub_type;

	vec3d
		*pos;

	float
		terrain_height;

	terrain_3d_point_data
		terrain_info;

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

	parent = get_local_entity_parent (en, LIST_TYPE_SEGMENT);

	ASSERT (parent);

	next_segment = get_local_entity_child_succ (en, LIST_TYPE_SEGMENT);

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

	prev_segment = get_local_entity_child_pred (en, LIST_TYPE_SEGMENT);

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

	sub_type = get_local_entity_int_value (en, INT_TYPE_ENTITY_SUB_TYPE);

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

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

		delete_local_entity_from_parents_child_list (en, LIST_TYPE_UPDATE);
	}
}
Esempio n. 3
0
static int get_local_int_value (entity *en, int_types type)
{
	vehicle
		*raw;

	int
		value;

	raw = (vehicle *) get_local_entity_data (en);

	switch (type)
	{
		////////////////////////////////////////
		case INT_TYPE_COLLISION_TEST_MOBILE:
		////////////////////////////////////////
		{
			value = TRUE;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_CPG_IDENTIFIED:
		////////////////////////////////////////
		{
			value = raw->cpg_identified;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_DAMAGE_LEVEL:
		////////////////////////////////////////
		{
			value = raw->damage_level;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_DEFAULT_3D_SHAPE:
		////////////////////////////////////////
		{
			value = vehicle_database[raw->mob.sub_type].default_3d_shape;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_DEFAULT_WEAPON_CONFIG_TYPE:
		////////////////////////////////////////
		{
			value = vehicle_database[raw->mob.sub_type].default_weapon_config_type;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_DEFAULT_WEAPON_TYPE:
		////////////////////////////////////////
		{
			value = vehicle_database[raw->mob.sub_type].default_weapon_type;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_DESTROYED_3D_SHAPE:
		////////////////////////////////////////
		{
			value = get_3d_object_destroyed_object_index (raw->object_3d_shape);

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_ENGAGE_ENEMY:
		////////////////////////////////////////
		{
			entity
				*group;
				
			value = FALSE;

			switch (raw->operational_state)
			{
				case OPERATIONAL_STATE_LANDED:
				{
					if (get_local_entity_parent (en, LIST_TYPE_TAKEOFF_QUEUE))
					{
						//
						// Don't engage if waiting to takeoff...
						//
						
						break;
					}

					// deliberate fall-through...
				}
				case OPERATIONAL_STATE_NAVIGATING:
				case OPERATIONAL_STATE_STOPPED:
				{
					group = get_local_entity_parent (en, LIST_TYPE_MEMBER);

					if (group)
					{
						value = get_local_entity_int_value (group, INT_TYPE_ENGAGE_ENEMY);
					}

					break;
				}
			}

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_EXPLOSIVE_POWER:
		////////////////////////////////////////
		{
			value = vehicle_database[raw->mob.sub_type].explosive_power;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_EXPLOSIVE_QUALITY:
		////////////////////////////////////////
		{
			value = vehicle_database[raw->mob.sub_type].explosive_quality;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_FORCE:
		////////////////////////////////////////
		{
			value = vehicle_database[raw->mob.sub_type].force;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_FORCE_INFO_CATAGORY:
		////////////////////////////////////////
		{
			value = vehicle_database[raw->mob.sub_type].force_info_catagory;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_FORMATION_POSITION:
		////////////////////////////////////////
		{
			value = raw->formation_position;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_GROUP_LEADER:
		////////////////////////////////////////
		{
			if ((get_local_entity_parent (en, LIST_TYPE_MEMBER)) && (get_local_entity_child_pred (en, LIST_TYPE_MEMBER) == NULL))
			{
				value = TRUE;
			}
			else
			{
				value = FALSE;
			}

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_GROUP_MEMBER_ID:
		////////////////////////////////////////
		{
			value = raw->group_member_number + 1;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_GROUP_MEMBER_NUMBER:
		////////////////////////////////////////
		{
			value = raw->group_member_number;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_GROUP_MEMBER_STATE:
		////////////////////////////////////////
		{
			entity
				*task;

			//
			// Check Task
			//
			
			task = get_local_entity_current_task (en);

			if (task)
			{
				if (get_local_entity_int_value (task, INT_TYPE_ENTITY_SUB_TYPE) == ENTITY_SUB_TYPE_TASK_ENGAGE)
				{
					value = GROUP_MEMBER_STATE_ATTACKING;
				}
				else
				{
					value = GROUP_MEMBER_STATE_NAVIGATING;
				}
			}
			else
			{
				value = GROUP_MEMBER_STATE_IDLE;
			}

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_GUNSHIP_RADAR_LOS_CLEAR:
		////////////////////////////////////////
		{
			value = raw->gunship_radar_los_clear;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_IDENTIFY_VEHICLE:
		////////////////////////////////////////
		{
			value = TRUE;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_ID_NUMBER:
		////////////////////////////////////////
		{
			value = raw->id_number;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_ID_NUMBER_SIGNIFICANT_DIGITS:
		////////////////////////////////////////
		{
			value = raw->id_number_significant_digits;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_INITIAL_DAMAGE_LEVEL:
		////////////////////////////////////////
		{
			value = vehicle_database[raw->mob.sub_type].initial_damage_level;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_LANDED:
		////////////////////////////////////////
		{

			switch (raw->operational_state)
			{

				case OPERATIONAL_STATE_LANDED:
				//case OPERATIONAL_STATE_REPAIRING:
				//case OPERATIONAL_STATE_REARMING:
				//case OPERATIONAL_STATE_REFUELING:
				{

					value = TRUE;

					break;
				}

				case OPERATIONAL_STATE_STOPPED:
				case OPERATIONAL_STATE_UNKNOWN:
				case OPERATIONAL_STATE_WAITING:
				case OPERATIONAL_STATE_ASLEEP:
				case OPERATIONAL_STATE_DEAD:
				case OPERATIONAL_STATE_DYING:
				case OPERATIONAL_STATE_LANDING:
				case OPERATIONAL_STATE_LANDING_HOLDING:
				case OPERATIONAL_STATE_NAVIGATING:
				case OPERATIONAL_STATE_TAKEOFF:
				case OPERATIONAL_STATE_TAKEOFF_HOLDING:
				case OPERATIONAL_STATE_TAXIING:
				{

					value = FALSE;

					break;
				}

				default:
				{

					debug_fatal ("VH_INT: unknown operational state");
				}
			}

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_LIGHTS_ON:
		////////////////////////////////////////
		{
			value = raw->lights_on;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_LOS_TO_TARGET:
		////////////////////////////////////////
		{
			value = raw->los_to_target;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_MAP_ICON:
		////////////////////////////////////////
		{
			value = vehicle_database [raw->mob.sub_type].map_icon;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_MAX_WEAPON_CONFIG_TYPE:
		////////////////////////////////////////
		{
			value = vehicle_database[raw->mob.sub_type].max_weapon_config_type;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_MIN_WEAPON_CONFIG_TYPE:
		////////////////////////////////////////
		{
			value = vehicle_database[raw->mob.sub_type].min_weapon_config_type;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_MOBILE_MOVING:
		////////////////////////////////////////
		{

			switch (raw->operational_state)
			{

				case OPERATIONAL_STATE_ASLEEP:
				case OPERATIONAL_STATE_DEAD:
				case OPERATIONAL_STATE_LANDED:
				case OPERATIONAL_STATE_STOPPED:
				case OPERATIONAL_STATE_UNKNOWN:
				case OPERATIONAL_STATE_WAITING:
				{

					value = FALSE;

					break;
				}

				case OPERATIONAL_STATE_DYING:
				case OPERATIONAL_STATE_LANDING:
				case OPERATIONAL_STATE_LANDING_HOLDING:
				case OPERATIONAL_STATE_NAVIGATING:
				case OPERATIONAL_STATE_TAKEOFF:
				case OPERATIONAL_STATE_TAKEOFF_HOLDING:
				case OPERATIONAL_STATE_TAXIING:
				{

					value = TRUE;

					break;
				}

				default:
				{

					debug_fatal ("VH_INT: unknown operational state");
				}
			}

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_OBJECT_3D_SHAPE:
		////////////////////////////////////////
		{
			value = raw->object_3d_shape;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_OFFENSIVE_CAPABILITY:
		////////////////////////////////////////
		{
			value = vehicle_database[raw->mob.sub_type].offensive_capability;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_OPERATIONAL_STATE:
		////////////////////////////////////////
		{
			value = raw->operational_state;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_POINTS_VALUE:
		////////////////////////////////////////
		{
			value = vehicle_database [raw->mob.sub_type].points_value;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_RADAR_ON:
		////////////////////////////////////////
		{
			//
			// vehicles must have radar and a target for the radar to be on
			//

			value = FALSE;

			if (vehicle_database[raw->mob.sub_type].threat_type != THREAT_TYPE_INVALID)
			{
				if (raw->mob.target_link.parent != NULL)
				{
					value = TRUE;
				}
			}

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_SELECTED_WEAPON:
		////////////////////////////////////////
		{
			value = raw->selected_weapon;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_SELECTED_WEAPON_SYSTEM_READY:
		////////////////////////////////////////
		{
			value = raw->selected_weapon_system_ready;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_TARGET_PRIORITY_TYPE:
		////////////////////////////////////////
		{
			value = vehicle_database[raw->mob.sub_type].target_priority_type;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_TARGET_SYMBOL_TYPE:
		////////////////////////////////////////
		{
			value = vehicle_database[raw->mob.sub_type].target_symbol_type;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_TARGET_TYPE:
		////////////////////////////////////////
		{
			value = vehicle_database[raw->mob.sub_type].target_type;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_TASK_LEADER:
		////////////////////////////////////////
		{
			entity
				*guide;

			value = FALSE;

			guide = get_local_entity_parent (en, LIST_TYPE_FOLLOWER);

			if (guide)
			{
				if (get_local_entity_ptr_value (guide, PTR_TYPE_TASK_LEADER) == en)
				{
					value = TRUE;
				}
			}

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_TASK_TARGET_TYPE:
		////////////////////////////////////////
		{
			value = (TASK_TARGET_TYPE_ANY | TASK_TARGET_TYPE_MOBILE | TASK_TARGET_TYPE_VEHICLE);

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_THREAT_TYPE:
		////////////////////////////////////////
		{
			value = vehicle_database[raw->mob.sub_type].threat_type;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_TRACK_ENTITY_ON_MAP:
		////////////////////////////////////////
		{
			value = TRUE;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_VIEW_CATEGORY:
		////////////////////////////////////////
		{
			value = vehicle_database[raw->mob.sub_type].view_category;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_VIEW_TYPE:
		////////////////////////////////////////
		{
			value = vehicle_database[raw->mob.sub_type].view_type;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_VIEWABLE:
		////////////////////////////////////////
		{
			value = raw->view_link.parent != NULL;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_WARHEAD_EFFECTIVE_CLASS:
		////////////////////////////////////////
		{
			value = vehicle_database[raw->mob.sub_type].warhead_effective_class;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_WEAPON_AND_TARGET_VECTORS_VALID:
		////////////////////////////////////////
		{
			value = raw->weapon_and_target_vectors_valid;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_WEAPON_CONFIG_TYPE:
		////////////////////////////////////////
		{
			value = raw->weapon_config_type;

			break;
		}
		////////////////////////////////////////
		case INT_TYPE_WEAPON_SYSTEM_READY:
		////////////////////////////////////////
		{
			////////////////////////////////////////
			//
			// WARNING! This only returns a valid value for vehicles that have weapon
			//          systems to be made ready in the current weapons configuration.
			//
			////////////////////////////////////////

			if (get_local_entity_float_value (en, FLOAT_TYPE_WEAPON_SYSTEM_READY_STATE) == VEHICLE_WEAPON_SYSTEM_READY_OPEN_FLOAT_VALUE)
			{
				value = TRUE;
			}
			else
			{
				value = FALSE;
			}

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

			break;
		}
	}

	return (value);
}
Esempio n. 4
0
void process_entity_list_link_validation (void)
{

	entity
		*en,
		*succ,
		*pred,
		*parent,
		*last_en;

	comms_entity_list_validation_type
		*this_entity_list;

	dump_entities ();

	while (entity_list_link_validation)
	{

		this_entity_list = entity_list_link_validation;

		entity_list_link_validation = entity_list_link_validation->next;

		en = this_entity_list->en;

		last_en = en;

		while (en)
		{

			parent = get_local_entity_parent (en, this_entity_list->list_type);

			/////////////////////////////////////////////////////////////////
			// if NULL its been removed from list, skip to next
			if (!parent)
			{

				en = get_local_entity_child_pred (en, this_entity_list->list_type);

				continue;
			}
			/////////////////////////////////////////////////////////////////

			ASSERT (parent->type != ENTITY_TYPE_UNKNOWN);

			/////////////////////////////////////////////////////////////////
			// check valid list type for parent
			get_local_entity_first_child (parent, this_entity_list->list_type);
			/////////////////////////////////////////////////////////////////

			/////////////////////////////////////////////////////////////////
			// check succ
			succ = get_local_entity_child_succ (en, this_entity_list->list_type);

			if (succ)
			{

				ASSERT (succ->type != ENTITY_TYPE_UNKNOWN);

				if (get_local_entity_child_pred (succ, this_entity_list->list_type) != en)
				{

					ASSERT (get_local_entity_child_pred (succ, this_entity_list->list_type) == NULL);

					#if DEBUG_MODULE

					debug_log ("EN_SESSN: LIST_REPAIRING: en %s (%d), list %s child_pred not set. Setting to %s (%d)", get_local_entity_type_name (en), get_local_entity_index (en), get_list_type_name (this_entity_list->list_type), get_local_entity_type_name (succ), get_local_entity_index (succ));

					#endif

					set_local_entity_child_pred (succ, this_entity_list->list_type, en);

					if (get_local_entity_parent (succ, this_entity_list->list_type) == NULL)
					{

						set_local_entity_parent (succ, this_entity_list->list_type, parent);

						#if DEBUG_MODULE

						debug_log ("EN_SESSN: LIST_REPAIRING: en %s (%d), list %s parent not set. Setting to %s (%d)", get_local_entity_type_name (succ), get_local_entity_index (succ), get_list_type_name (this_entity_list->list_type), get_local_entity_type_name (parent), get_local_entity_index (parent));

						#endif
					}
				}
			}
			/////////////////////////////////////////////////////////////////

			/////////////////////////////////////////////////////////////////
			// check pred
			pred = get_local_entity_child_pred (en, this_entity_list->list_type);

			if (pred)
			{

				ASSERT (pred->type != ENTITY_TYPE_UNKNOWN);

				if (get_local_entity_child_succ (pred, this_entity_list->list_type) != en)
				{

					ASSERT (get_local_entity_child_succ (pred, this_entity_list->list_type) == NULL);

					set_local_entity_child_succ (pred, this_entity_list->list_type, en);

					#if DEBUG_MODULE

					debug_log ("EN_SESSN: LIST_REPAIRING: en %s (%d), list %s child_succ not set. Setting to %s (%d)", get_local_entity_type_name (en), get_local_entity_index (en), get_list_type_name (this_entity_list->list_type), get_local_entity_type_name (pred), get_local_entity_index (pred));

					#endif

					if (get_local_entity_parent (pred, this_entity_list->list_type) == NULL)
					{

						set_local_entity_parent (pred, this_entity_list->list_type, parent);

						#if DEBUG_MODULE

						debug_log ("EN_SESSN: LIST_REPAIRING: en %s (%d), list %s parent not set. Setting to %s (%d)", get_local_entity_type_name (pred), get_local_entity_index (pred), get_list_type_name (this_entity_list->list_type), get_local_entity_type_name (parent), get_local_entity_index (parent));

						#endif
					}
				}
			}
			/////////////////////////////////////////////////////////////////

			last_en = en;

			en = get_local_entity_child_pred (en, this_entity_list->list_type);
		}

		/////////////////////////////////////////////////////////////////
		// check first child links to parent
		parent = get_local_entity_parent (last_en, this_entity_list->list_type);

		if (get_local_entity_first_child (parent, this_entity_list->list_type) != last_en)
		{

			//ASSERT (get_local_entity_first_child (parent, this_entity_list->list_type) == NULL);

			set_local_entity_first_child (parent, this_entity_list->list_type, last_en);

			#if DEBUG_MODULE

			debug_log ("EN_SESSN: LIST_REPAIRING: en %s (%d), list %s first_child not set. Setting to %s (%d)", get_local_entity_type_name (parent), get_local_entity_index (parent), get_list_type_name (this_entity_list->list_type), get_local_entity_type_name (last_en), get_local_entity_index (last_en));

			#endif
		}
		/////////////////////////////////////////////////////////////////

		free_mem (this_entity_list);
	}
}
Esempio n. 5
0
void destroy_client_server_entity_children (entity *en, list_types list)
{
   entity
      *child;

   child = get_local_entity_first_child (en, list);

   while (child)
   {

		#if DEBUG_MODULE
		{

			static int
				reported_segment = FALSE,
				reported_city_building = FALSE,
				reported_sector = FALSE;
	
			#if DEBUG_UPDATE_LIST_VALIDATION

			entity
				*succ,
				*pred,
				*updt;
		
			if (get_update_entity ())
			{
			
				updt = get_local_entity_first_child (get_update_entity (), LIST_TYPE_UPDATE);
		
				while (updt)
				{
		
					ASSERT (updt->type != ENTITY_TYPE_UNKNOWN);

				succ = get_local_entity_child_succ (updt, LIST_TYPE_UPDATE);

				if (succ)
				{

					ASSERT (get_local_entity_child_pred (succ, LIST_TYPE_UPDATE) == updt);
				}

				pred = get_local_entity_child_pred (updt, LIST_TYPE_UPDATE);

				if (pred)
				{

					ASSERT (get_local_entity_child_succ (pred, LIST_TYPE_UPDATE) == updt);
				}
	
				updt = get_local_entity_child_succ (updt, LIST_TYPE_UPDATE);
				}
			}

			#endif

			switch (get_local_entity_type (en))
			{
		
				case ENTITY_TYPE_SEGMENT:
				case ENTITY_TYPE_SECTOR:
				case ENTITY_TYPE_CITY_BUILDING:
				{
		
					if (get_local_entity_type (en) == ENTITY_TYPE_SEGMENT)
					{
			
						if (reported_segment)
						{
			
							break;
						}
			
						reported_segment = TRUE;
					}
		
					if (get_local_entity_type (en) == ENTITY_TYPE_SECTOR)
					{
			
						if (reported_sector)
						{
			
							break;
						}
			
						reported_sector = TRUE;
					}
		
					if (get_local_entity_type (en) == ENTITY_TYPE_CITY_BUILDING)
					{
			
						if (reported_city_building)
						{
			
							break;
						}
			
						reported_city_building = TRUE;
					}
				}
				default:
				{
	
					debug_log ("EN_DSTRY: destroying %s, index %d, sub_type %d", get_local_entity_type_name (child), get_local_entity_index (child), get_local_entity_int_value (en, INT_TYPE_ENTITY_SUB_TYPE));
		
					break;
				} 
			}
		}
		#endif

      destroy_client_server_entity_family (child);

      child = get_local_entity_first_child (en, list);
   }
}
Esempio n. 6
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;
}