예제 #1
0
파일: group.c 프로젝트: DexterWard/comanche
void assess_group_supplies (entity *en)
{

	entity
		*keysite,
		*force;

	group
		*raw;

	float
		required,
		level;

	raw = get_local_entity_data (en);

	if (get_local_entity_int_value (en, INT_TYPE_RESUPPLY_SOURCE) == RESUPPLY_SOURCE_GROUP)
	{

		//
		// Check if Group needs to request Supplies via Mission...
		//

		if (raw->supplies.ammo_supply_level < 100.0)
		{

			force = get_local_force_entity (get_local_entity_int_value (en, INT_TYPE_SIDE));

			#if DEBUG_MODULE || DEBUG_SUPPLY

			debug_log ("GROUP: SUPPLY_INFO: ground group %s low on ammo, requesting Supply mission", get_local_entity_string (en, STRING_TYPE_FULL_NAME));

			#endif

			notify_local_entity (ENTITY_MESSAGE_FORCE_LOW_ON_SUPPLIES, force, en, ENTITY_SUB_TYPE_CARGO_AMMO);
		}
		else if (raw->supplies.fuel_supply_level < 100.0)
		{

			force = get_local_force_entity (get_local_entity_int_value (en, INT_TYPE_SIDE));

			#if DEBUG_MODULE || DEBUG_SUPPLY

			debug_log ("GROUP: SUPPLY_INFO: ground group %s low on fuel, requesting Supply mission", get_local_entity_string (en, STRING_TYPE_FULL_NAME));

			#endif

			notify_local_entity (ENTITY_MESSAGE_FORCE_LOW_ON_SUPPLIES, force, en, ENTITY_SUB_TYPE_CARGO_FUEL);
		}
	}
	else if (get_local_entity_int_value (en, INT_TYPE_RESUPPLY_SOURCE) == RESUPPLY_SOURCE_KEYSITE)
	{
		//
		// check all group is landed. If so refuel/rearm group via keysite supplies
		//

		if (get_local_entity_int_value (en, INT_TYPE_GROUP_MODE) == GROUP_MODE_IDLE)
		{

			if (raw->supplies.ammo_supply_level < 100.0)
			{

				//
				// re-arm
				//

				keysite = get_local_entity_parent (en, LIST_TYPE_KEYSITE_GROUP);

				if ((!keysite) || (get_local_entity_type (keysite) != ENTITY_TYPE_KEYSITE))
				{
					keysite = get_closest_keysite (NUM_ENTITY_SUB_TYPE_KEYSITES, raw->side, get_local_entity_vec3d_ptr (en, VEC3D_TYPE_POSITION), 1.0 * KILOMETRE, NULL, NULL);
				}

				ASSERT (keysite);

				level = get_local_entity_float_value (keysite, FLOAT_TYPE_AMMO_SUPPLY_LEVEL);

				required = 100.0 - (raw->supplies.ammo_supply_level * AMMO_USAGE_ACCELERATOR);

				required = bound (required, 0.0, level);

				level -= required;

				set_client_server_entity_float_value (keysite, FLOAT_TYPE_AMMO_SUPPLY_LEVEL, level);

				set_client_server_entity_float_value (en, FLOAT_TYPE_AMMO_SUPPLY_LEVEL, raw->supplies.ammo_supply_level + required);

				#if DEBUG_MODULE || DEBUG_SUPPLY

				debug_log ("GROUP: SUPPLY_INFO: Air group %s members landed, rearming group (now ammo = %f, fuel = %f) from keysite %s (%d) (now ammo = %f, fuel = %f)",
							get_local_entity_string (en, STRING_TYPE_FULL_NAME),
							get_local_entity_float_value (en, FLOAT_TYPE_AMMO_SUPPLY_LEVEL),
							get_local_entity_float_value (en, FLOAT_TYPE_FUEL_SUPPLY_LEVEL),
							get_local_entity_string (keysite, STRING_TYPE_FULL_NAME),
							get_local_entity_index (keysite),
							get_local_entity_float_value (keysite, FLOAT_TYPE_AMMO_SUPPLY_LEVEL),
							get_local_entity_float_value (keysite, FLOAT_TYPE_FUEL_SUPPLY_LEVEL));

				#endif
			}

			if (raw->supplies.fuel_supply_level < 100.0)
			{

				//
				// re-fuel
				//

				keysite = get_local_entity_parent (en, LIST_TYPE_KEYSITE_GROUP);

				if ((!keysite) || (get_local_entity_type (keysite) != ENTITY_TYPE_KEYSITE))
				{
					keysite = get_closest_keysite (NUM_ENTITY_SUB_TYPE_KEYSITES, raw->side, get_local_entity_vec3d_ptr (en, VEC3D_TYPE_POSITION), 1.0 * KILOMETRE, NULL, NULL);
				}

				ASSERT (keysite);

				level = get_local_entity_float_value (keysite, FLOAT_TYPE_FUEL_SUPPLY_LEVEL);

				required = 100.0 - (raw->supplies.fuel_supply_level * FUEL_USAGE_ACCELERATOR);

				required = bound (required, 0.0, level);

				level -= required;

				set_client_server_entity_float_value (keysite, FLOAT_TYPE_FUEL_SUPPLY_LEVEL, level);

				set_client_server_entity_float_value (en, FLOAT_TYPE_FUEL_SUPPLY_LEVEL, raw->supplies.fuel_supply_level + required);

				#if DEBUG_MODULE || DEBUG_SUPPLY

				debug_log ("GROUP: SUPPLY_INFO: Air group %s members landed, refuelling group (now ammo = %f, fuel = %f) from keysite %s (%d) (now ammo = %f, fuel = %f)",
							get_local_entity_string (en, STRING_TYPE_FULL_NAME),
							get_local_entity_float_value (en, FLOAT_TYPE_AMMO_SUPPLY_LEVEL),
							get_local_entity_float_value (en, FLOAT_TYPE_FUEL_SUPPLY_LEVEL),
							get_local_entity_string (keysite, STRING_TYPE_FULL_NAME),
							get_local_entity_index (keysite),
							get_local_entity_float_value (keysite, FLOAT_TYPE_AMMO_SUPPLY_LEVEL),
							get_local_entity_float_value (keysite, FLOAT_TYPE_FUEL_SUPPLY_LEVEL));

				#endif
			}
		}
	}
}
예제 #2
0
파일: ss_updt.c 프로젝트: Comanche93/eech
void update_lightning_effect (entity *en)
{
	session
		*raw;

	int
		lightning_flag = FALSE;

	float
		new_time;

	ASSERT (en);

	raw = (session *) get_local_entity_data (en);

	if (get_comms_model () == COMMS_MODEL_SERVER)
	{
		//
		// SERVER : decrease timer, if timer reaches zero create a strike, and reset timer (c/s)
		//

		raw->lightning_timer -= get_delta_time ();

		if (raw->lightning_timer <= 0.0)
		{
			lightning_flag = TRUE;

			new_time = LIGHTNING_EFFECT_MINIMUM_TIMER + ((LIGHTNING_EFFECT_MAXIMUM_TIMER - LIGHTNING_EFFECT_MINIMUM_TIMER) * frand1 ());

			#if DEBUG_MODULES

			debug_log ("SS_UPDT : Set lightning timer %.2f", new_time);

			#endif

			set_client_server_entity_float_value (en, FLOAT_TYPE_LIGHTNING_TIMER, new_time);
		}
	}
	else
	{
		//
		// CLIENT : decrease timer only if non-zero and create strike if zero reached ( new timer will be set by server )
		//

		if (raw->lightning_timer > 0.0)
		{
			raw->lightning_timer -= get_delta_time ();

			if (raw->lightning_timer <= 0.0)
			{
				lightning_flag = TRUE;

				raw->lightning_timer = 0.0;
			}
		}
	}

	if (lightning_flag)
	{
		//
		// create lightning
		//

		env_3d
			*current_3d_env;

		current_3d_env = get_3d_active_environment ();

		if (current_3d_env == main_3d_env)
		{
			current_3d_env = NULL;
		}
		else
		{
			set_3d_active_environment (main_3d_env);
		}
		
		add_3d_lightning_strike (LIGHTNING_TYPE_CLOUD_BURST, 0.3, raw->weather_position.x, raw->weather_position.z);

		add_3d_lightning_strike (LIGHTNING_TYPE_FORKED_1, 0.3, raw->weather_position.x, raw->weather_position.z);

		if (current_3d_env)
		{
			set_3d_active_environment (current_3d_env);
		}

		if (get_comms_model () == COMMS_MODEL_SERVER)
		{
			sound_sample_indices
				sound_effect_index;

			//
			// lightning sound effect
			//

			sound_effect_index = SOUND_SAMPLE_INDEX_AMBIENT_LIGHTNING;

			create_client_server_sound_effect_entity
			(
				get_local_sector_entity (&(raw->weather_position)),
				ENTITY_SIDE_NEUTRAL,
				ENTITY_SUB_TYPE_EFFECT_SOUND_MISC,
				SOUND_CHANNEL_SOUND_EFFECT,
				SOUND_LOCALITY_ALL,
				&raw->weather_position,						// position
				1.0,												// amplification
				0.85+(0.3* frand1 ()), //pitch
				TRUE,												// valid sound effect
				FALSE,											// looping
				1,													// sample count
				&sound_effect_index							// sample index list
			);

			//
			// thunder sound effect
			//

			sound_effect_index = SOUND_SAMPLE_INDEX_AMBIENT_THUNDER;

			create_client_server_sound_effect_entity
			(
				get_local_sector_entity (&(raw->weather_position)),
				ENTITY_SIDE_NEUTRAL,
				ENTITY_SUB_TYPE_EFFECT_SOUND_MISC,
				SOUND_CHANNEL_SOUND_EFFECT,
				SOUND_LOCALITY_ALL,
				&raw->weather_position,						// position
				1.0,												// amplification
				0.85+(0.3* frand1 ()), //pitch
				TRUE,												// valid sound effect
				FALSE,											// looping
				1,													// sample count
				&sound_effect_index							// sample index list
			);
		}
	}
}
예제 #3
0
파일: assign.c 프로젝트: Comanche93/eech
int assign_primary_task_to_group (entity *group_en, entity *task_en)
{
	entity_sub_types
		task_type,
		group_type;

	entity
		*force,
		*keysite;

	int
		side,
		formation,
		air_threat,
		enemy_sectors;

	unsigned int
		threat;

	ASSERT (get_comms_model () == COMMS_MODEL_SERVER);
		
	task_type = get_local_entity_int_value (task_en, INT_TYPE_ENTITY_SUB_TYPE);

	ASSERT (task_database [task_type].primary_task);

	group_type = get_local_entity_int_value (group_en, INT_TYPE_ENTITY_SUB_TYPE);

	ASSERT (!get_local_group_primary_task (group_en));

	if (assign_task_to_group (group_en, task_en, TASK_ASSIGN_ALL_MEMBERS))
	{
		//
		// set default group formation
		//

		formation = get_local_entity_int_value (group_en, INT_TYPE_GROUP_DEFAULT_FORMATION);

		if (formation != get_local_entity_int_value (group_en, INT_TYPE_GROUP_FORMATION))
		{
			set_client_server_entity_int_value (group_en, INT_TYPE_GROUP_FORMATION, formation);
		}

		//
		// Link to new keysite
		// 

		if (get_local_entity_int_value (group_en, INT_TYPE_GROUP_LIST_TYPE) == LIST_TYPE_KEYSITE_GROUP)
		{
			keysite = ( entity * ) get_local_entity_ptr_value (task_en, PTR_TYPE_RETURN_KEYSITE);

			if (keysite)
			{
				set_client_server_entity_parent (group_en, LIST_TYPE_KEYSITE_GROUP, keysite);
			}	
		}

		//
		// Notify Force
		//

		side = get_local_entity_int_value (group_en, INT_TYPE_SIDE);

		force = get_local_force_entity ( ( entity_sides ) side );

		ASSERT (force);

		notify_local_entity (ENTITY_MESSAGE_TASK_ASSIGNED, force, task_en);

		//
		// Assess for Escort task
		//

		if (task_database [task_type].escort_required_threshold != ESCORT_NEVER)
		{
			threat = assess_task_difficulty (task_en, &air_threat, &enemy_sectors);

			#if DEBUG_ESCORT_TASK_CREATION

			debug_filtered_log ("(ASSIGN) Side %s: Assigned %s to %s, objective %s",
											entity_side_short_names [side],
											get_local_entity_string (group_en, STRING_TYPE_FULL_NAME),
											get_local_entity_string (task_en, STRING_TYPE_FULL_NAME),
											get_task_objective_string (task_en)
									);

			debug_filtered_log ("Threat: %d (air_threat: %d, enemy_sectors: %d) - Threshold %d",
											threat, air_threat, enemy_sectors,
											task_database [task_type].escort_required_threshold);

			#endif

			if (threat >= task_database [task_type].escort_required_threshold)
			{
				create_escort_task (group_en, (threat >= ESCORT_CRITICAL), task_database [ENTITY_SUB_TYPE_TASK_ESCORT].task_priority, NULL, NULL);

				ai_log ("(ASSIGN) Created Escort Task for %s :- Threat %d / Threshold %d",
											get_local_entity_string (task_en, STRING_TYPE_FULL_NAME),
											threat,
											task_database [task_type].escort_required_threshold
											);
			}
		}

		//
		// Store Start Time
		//

		set_client_server_entity_float_value (task_en, FLOAT_TYPE_START_TIME, get_local_entity_float_value (get_session_entity (), FLOAT_TYPE_ELAPSED_TIME));

		//
		// Clear Expire Timer (now also used for destroying completed tasks)
		//

		set_local_entity_float_value (task_en, FLOAT_TYPE_EXPIRE_TIMER, 0.0);

		ai_log ("(ASSIGN) Side %s: Assigned %s (%d) to %s (%d) - Priority %f",
					entity_side_short_names [side],
					get_local_entity_string (group_en, STRING_TYPE_FULL_NAME),
					get_local_entity_safe_index (group_en),
					get_local_entity_string (task_en, STRING_TYPE_FULL_NAME),
					get_local_entity_safe_index (task_en),
					get_local_entity_float_value (task_en, FLOAT_TYPE_TASK_PRIORITY));

		return TRUE;
	}

	return FALSE;
}