示例#1
0
//==========================================
// BOT_DMclass_UpdateStatus
// update ai.status values based on bot state,
// so ai can decide based on these settings
//==========================================
static void BOT_DMclass_UpdateStatus( edict_t *self )
{
	float LowNeedFactor = 0.5;
	gclient_t *client;
	int i;
	bool onlyGotGB = true;
	edict_t *ent;
	ai_handle_t *ai;
	nav_ents_t *goalEnt;

	client = self->r.client;

	ai = self->ai;

	FOREACH_GOALENT( goalEnt )
	{
		i = goalEnt->id;
		ent = goalEnt->ent;

		// item timing disabled by now
		if( ent->r.solid == SOLID_NOT )
		{
			ai->status.entityWeights[i] = 0;
			continue;
		}

		if( ent->r.client )
		{
			ai->status.entityWeights[i] = BOT_DMclass_PlayerWeight( self, ent ) * self->ai->pers.cha.offensiveness;
			continue;
		}

		if( ent->item )
		{
			if( ent->r.solid == SOLID_NOT )
			{
				ai->status.entityWeights[i] = 0;
				continue;
			}

			if( ent->item->type & IT_WEAPON )
			{
				if( client->ps.inventory[ent->item->tag] )
				{
					if( client->ps.inventory[ent->item->ammo_tag] )
					{
						// find ammo item for this weapon
						gsitem_t *ammoItem = GS_FindItemByTag( ent->item->ammo_tag );
						if( ammoItem->inventory_max )
						{
							ai->status.entityWeights[i] *= (0.5 + 0.5 * (1.0 - (float)client->ps.inventory[ent->item->ammo_tag] / ammoItem->inventory_max));
						}
						ai->status.entityWeights[i] *= LowNeedFactor;
					}
					else
					{
						// we need some ammo
						ai->status.entityWeights[i] *= LowNeedFactor;
					}
					onlyGotGB = false;
				}
			}
			else if( ent->item->type & IT_AMMO )
			{
				if( client->ps.inventory[ent->item->tag] >= ent->item->inventory_max )
				{
					ai->status.entityWeights[i] = 0.0;
				}
				else
				{
#if 0
					// find weapon item for this ammo
					gsitem_t *weaponItem;
					int weapon;

					for( weapon = WEAP_GUNBLADE; weapon < WEAP_TOTAL; weapon++ )
					{
						weaponItem = GS_FindItemByTag( weapon );
						if( weaponItem->ammo_tag == ent->item->tag )
						{
							if( !client->ps.inventory[weaponItem->tag] )
								self->ai->status.entityWeights[i] *= LowNeedFactor;
						}
					}
#endif
				}
			}
			else if( ent->item->type & IT_ARMOR )
			{
				if ( self->r.client->resp.armor < ent->item->inventory_max || !ent->item->inventory_max )
				{
					if( ent->item->inventory_max )
					{
						if( ( (float)self->r.client->resp.armor / (float)ent->item->inventory_max ) > 0.75 )
							ai->status.entityWeights[i] = self->ai->pers.inventoryWeights[ent->item->tag] * LowNeedFactor;
					}
					else
						ai->status.entityWeights[i] = self->ai->pers.inventoryWeights[ent->item->tag];
				}
				else
				{
					ai->status.entityWeights[i] = 0;
				}
			}
			else if( ent->item->type & IT_HEALTH )
			{
				if( ent->item->tag == HEALTH_MEGA || ent->item->tag == HEALTH_ULTRA || ent->item->tag == HEALTH_SMALL )
					ai->status.entityWeights[i] = self->ai->pers.inventoryWeights[ent->item->tag];
				else
				{
					if( self->health >= self->max_health )
						ai->status.entityWeights[i] = 0;
					else
					{
						float health_func;

						health_func = self->health / self->max_health;
						health_func *= health_func;

						ai->status.entityWeights[i] = self->ai->pers.inventoryWeights[ent->item->tag] + ( 1.1f - health_func );
					}
				}
			}
			else if( ent->item->type & IT_POWERUP )
			{
				ai->status.entityWeights[i] = self->ai->pers.inventoryWeights[ent->item->tag];
			}
		}
	}

	if( onlyGotGB )
	{
		FOREACH_GOALENT( goalEnt )
		{
			i = goalEnt->id;
			ent = goalEnt->ent;

			if( ent->item && ent->item->type & IT_WEAPON )
				self->ai->status.entityWeights[i] *= 2.0f;
		}
	}
}
示例#2
0
//==========================================
// BOT_DMclass_UpdateStatus
// update ai.status values based on bot state,
// so ai can decide based on these settings
//==========================================
static void BOT_DMclass_UpdateStatus( edict_t *self )
{
	float LowNeedFactor = 0.5;
	gclient_t *client;
	int i;
	qboolean onlyGotGB = qtrue;
	edict_t *ent;
	ai_handle_t *ai;

	client = self->r.client;

	ai = &self->ai;

	for( i = 0; i < nav.num_goalEnts; i++ )
	{
		ent = nav.goalEnts[i].ent;

		// item timing disabled by now
		if( ent->r.solid == SOLID_NOT )
		{
			ai->status.entityWeights[i] = 0;
			continue;
		}

		if( ent->r.client )
		{
			ai->status.entityWeights[i] = BOT_DMclass_PlayerWeight( self, ent ) * self->ai.pers.cha.offensiveness;
			continue;
		}

		if( ent->item )
		{
			if( ent->r.solid == SOLID_NOT )
			{
				ai->status.entityWeights[i] = 0;
				continue;
			}

			if( ent->item->type & IT_WEAPON )
			{
				if( client->ps.inventory[ent->item->tag] )
				{
					ai->status.entityWeights[i] *= LowNeedFactor;
					onlyGotGB = qfalse;
				}
			}
			else if( ent->item->type & IT_AMMO )
			{
				if( client->ps.inventory[ent->item->tag] >= ent->item->inventory_max )
				{
					ai->status.entityWeights[i] = 0.0;
				}
				else
				{
					// find weapon item for this ammo
					gsitem_t *weaponItem;
					int weapon;

					for( weapon = WEAP_GUNBLADE; weapon < WEAP_TOTAL; weapon++ )
					{
						weaponItem = GS_FindItemByTag( weapon );
						if( weaponItem->ammo_tag == ent->item->tag )
						{
							if( !client->ps.inventory[weaponItem->tag] )
								self->ai.status.entityWeights[i] *= LowNeedFactor;
						}
					}
				}
			}
			else if( ent->item->type & IT_ARMOR )
			{
				if ( self->r.client->resp.armor < ent->item->inventory_max || !ent->item->inventory_max )
				{
					if( ent->item->inventory_max )
					{
						if( ( (float)self->r.client->resp.armor / (float)ent->item->inventory_max ) > 0.75 )
							ai->status.entityWeights[i] = self->ai.pers.inventoryWeights[ent->item->tag] * LowNeedFactor;
					}
					else
						ai->status.entityWeights[i] = self->ai.pers.inventoryWeights[ent->item->tag];
				}
				else
				{
					ai->status.entityWeights[i] = 0;
				}
			}
			else if( ent->item->type & IT_HEALTH )
			{
				if( ent->item->tag == HEALTH_MEGA || ent->item->tag == HEALTH_ULTRA )
					ai->status.entityWeights[i] = self->ai.pers.inventoryWeights[ent->item->tag];
				else
				{
					if( self->health == self->max_health )
						ai->status.entityWeights[i] = 0;
					else
					{
						float health_func;

						health_func = self->health / self->max_health;
						health_func *= health_func;

						ai->status.entityWeights[i] = self->ai.pers.inventoryWeights[ent->item->tag] + ( 1.1f - health_func );
					}
				}
			}
			else if( ent->item->type & IT_POWERUP )
			{
				ai->status.entityWeights[i] = self->ai.pers.inventoryWeights[ent->item->tag];
			}
		}
	}

	if( onlyGotGB )
	{
		for( i = 0; i < nav.num_goalEnts; i++ )
		{
			ent = nav.goalEnts[i].ent;

			if( ent->item && ent->item->type & IT_WEAPON )
				self->ai.status.entityWeights[i] *= 2.0f;
		}
	}
}