コード例 #1
0
//	Recharge whole shield.
//	Apply delta/MAX_SHIELD_SECTIONS to each shield section.
void shield_add_strength(object* objp, float delta)
{
	// if we aren't going to change anything anyway then just bail
	if (delta == 0.0f)
		return;


	if (!(Ai_info[Ships[objp->instance].ai_index].ai_profile_flags & AIPF_SMART_SHIELD_MANAGEMENT)
		|| delta <= 0.0f) //SUSHI: We don't want smart shield management for negative delta
	{
		for (int i = 0; i < MAX_SHIELD_SECTIONS; i++)
			shield_add_quad(objp, i, delta / MAX_SHIELD_SECTIONS);
	}
	else
	{
		float section_max = shield_get_max_quad(objp);

		// smart shield repair
		while (delta > 0.0f)
		{
			//WMC - Set to INT_MAX so that this is set to something
			float weakest = i2fl(INT_MAX);
			int weakest_idx = -1;

			// find weakest shield quadrant
			for (int i = 0; i < MAX_SHIELD_SECTIONS; i++)
			{
				float quad = shield_get_quad(objp, i);
				if (weakest_idx < 0 || quad < weakest)
				{
					weakest = quad;
					weakest_idx = i;
				}
			}

			// all quads are at full strength
			if (weakest >= section_max)
				break;

			// throw all possible shield power at this quadrant
			// if there's any left over then apply it to the next weakest on the next pass
			float xfer_amount;
			if (weakest + delta > section_max)
				xfer_amount = section_max - weakest;
			else
				xfer_amount = delta;

			shield_add_quad(objp, weakest_idx, xfer_amount);
			delta -= xfer_amount;
		}
	}
}
コード例 #2
0
float shield_apply_damage(object *objp, int quadrant_num, float damage) {
	float remaining_damage;

	Assert(objp);

	// multiplayer clients bail here if nodamage
	// if(MULTIPLAYER_CLIENT && (Netgame.debug_flags & NETD_FLAG_CLIENT_NODAMAGE)){
	if (MULTIPLAYER_CLIENT)
		return damage;

	// check array bounds
	Assert(quadrant_num >= 0 && quadrant_num < objp->n_quadrants);
	if ((quadrant_num < 0) || (quadrant_num >= objp->n_quadrants))
		return damage;

	if (objp->type != OBJ_SHIP && objp->type != OBJ_START)
		return damage;

	Ai_info[Ships[objp->instance].ai_index].last_hit_quadrant = quadrant_num;

	remaining_damage = damage - shield_get_quad(objp, quadrant_num);
	if (remaining_damage > 0.0f) {
		shield_set_quad(objp, quadrant_num, 0.0f);
		return remaining_damage;
	} else {
		shield_add_quad(objp, quadrant_num, -damage);
		return 0.0f;
	}
}
コード例 #3
0
void shield_add_strength(object *objp, float delta) {
	Assert(objp);

	// if we aren't going to change anything anyway then just bail
	if (delta == 0.0f)
		return;

	float shield_str = shield_get_strength(objp);
	float shield_recharge_limit = shield_get_max_strength(objp);

	if ((delta > 0.0f) && (shield_str >= shield_recharge_limit))
		return;

	if (!(Ai_info[Ships[objp->instance].ai_index].ai_profile_flags[AI::Profile_Flags::Smart_shield_management])
		|| delta <= 0.0f) //SUSHI: We don't want smart shield management for negative delta
	{
		// set the limit for the shield recharge
		if ((delta > 0.0f) && ((shield_str + delta) > shield_recharge_limit))
			delta = shield_recharge_limit - shield_str;

		for (int i = 0; i < objp->n_quadrants; i++)
			shield_add_quad(objp, i, delta / objp->n_quadrants);
	}
	else
	{
		float section_max = shield_get_max_quad(objp);

		// smart shield repair
		while (delta > 0.0f)
		{
			//WMC - Set to INT_MAX so that this is set to something
			float weakest = i2fl(INT_MAX);
			int weakest_idx = -1;

			// find weakest shield quadrant
			for (int i = 0; i < objp->n_quadrants; i++)
			{
				float quad = shield_get_quad(objp, i);
				if (weakest_idx < 0 || quad < weakest)
				{
					weakest = quad;
					weakest_idx = i;
				}
			}

			// all quads are at full strength
			if (weakest >= section_max)
				break;

			// set the limit for the shield recharge
			if ((delta > 0.0f) && ((shield_str + delta) > shield_recharge_limit))
				delta = shield_recharge_limit - shield_str;

			// throw all possible shield power at this quadrant
			// if there's any left over then apply it to the next weakest on the next pass
			float xfer_amount;
			if (weakest + delta > section_max)
				xfer_amount = section_max - weakest;
			else
				xfer_amount = delta;

			shield_add_quad(objp, weakest_idx, xfer_amount);
			delta -= xfer_amount;
		}
	}
}