Exemplo n.º 1
0
//
// Name:        ItemPickup()
// Class:       Armor
//
// Description: Handles Sentients Picking up armor... In this case, however,
//              Only Actors are allowed to actually pick up armor
//
// Parameters:  Entity *other - The entity doing the picking up
//              qboolean add_to_inventory - Here to make parameters match
//
// Returns:     NULL -- This function doesn't actually return the armor, instead
//              it has the entity picking it up process and armor event
//
Item *Armor::ItemPickup( Entity *other, qboolean add_to_inventory, qboolean )
{
	Sentient *sent;
	str      realname;

	Q_UNUSED(add_to_inventory);
	
	// For right now, we only want players to pick up armor
	if ( !other->isSubclassOf( Player ) )
		return NULL;

	if ( !Pickupable( other ) )
		return NULL;
	
	sent = (Sentient*)other;
	
	// Check if we NEED to pick up the armor, if the armor we are about to pick up is
	// less than the armor we have, we don't want to pick it up
	if ( !_needThisArmor(sent) )
		return NULL;
	
	// Handle the actual "Picking Up"
	_pickupArmor(sent);
	
	// Give the Sentient the Armor
	Event *armorEvent;
	armorEvent = new Event(EV_Sentient_GiveArmor);
	armorEvent->AddString( item_name.c_str() );
	armorEvent->AddFloat( amount );
	armorEvent->AddInteger( true );
	
	sent->ProcessEvent(armorEvent);	
	
	return NULL; // This doesn't create any items
}
Exemplo n.º 2
0
void Health::PickupHealth( Event *ev )
{
	Sentient *sen;
	Entity *other;
	
	other = ev->GetEntity( 1 );
	if ( !other || !other->isSubclassOf( Sentient ) )
	{
		return;
	}
	
	sen = ( Sentient * )other;
	
	if ( sen->health >= sen->max_health )
		return;
	
	if ( !ItemPickup( other, false ) )
	{
		return;
	}
	
	GameplayManager *gpm = GameplayManager::getTheGameplayManager();
	if ( gpm->hasObject(getArchetype()) )
	{
		if ( gpm->hasFormula("HealthPotion") )
		{
			GameplayFormulaData fd(this);
			amount = gpm->calculate("HealthPotion", fd, sen->max_health);
		}
		str snd = gpm->getStringValue(getArchetype() + ".Use", "wav");
		if ( snd.length() )
		{
			int channel = CHAN_BODY;
			float volume = -1.0f;
			float mindist = -1.0f;
			if ( gpm->hasProperty(getArchetype() + ".Use","channel") )
				channel = (int)gpm->getFloatValue(getArchetype() + ".Use", "channel");
			if ( gpm->hasProperty(getArchetype() + ".Use","volume") )
				volume = (int)gpm->getFloatValue(getArchetype() + ".Use", "volume");
			if ( gpm->hasProperty(getArchetype() + ".Use","mindist") )
				mindist = (int)gpm->getFloatValue(getArchetype() + ".Use", "mindist");
			Sound(snd, channel, volume, mindist);
		}
	}
	
	sen->health += (float)amount;
	
	if ( sen->health > sen->max_health )
	{
		sen->health = sen->max_health;
	}
	
	// If we are on fire stop it
	
	sen->ProcessEvent( EV_Sentient_StopOnFire );
}
Exemplo n.º 3
0
qboolean Item::Pickupable( Entity *other )
{
	if ( level.time < _nextPickupTime )
		return false;

	if ( multiplayerManager.inMultiplayer() && other->isSubclassOf( Player ) )
	{
		if ( !multiplayerManager.canPickup( (Player *)other, getMultiplayerItemType(), getName().c_str() ) )
			return false;
	}

	if ( getSolidType() == SOLID_NOT )
	{
		return NULL;
	}
	
	if ( !other->isSubclassOf( Sentient ) )
	{
		return false;
	}
	else
	{
		Sentient * sent;
		Item * item;
		
		sent = ( Sentient * )other;

		if ( sent->deadflag || sent->health <= 0.0f )
		{
			return false;
		}
		
		item = sent->FindItem( getName() );
		
		if ( item && ( item->getAmount() >= item->MaxAmount() ) )
		{
			return false;
		}
		
		// TODO : fixme
		// If deathmatch and already in a powerup, don't pickup anymore when DF_INSTANT_ITEMS is on
		/* if ( multiplayerManager.checkFlag( MP_FLAG_INSTANT_ITEMS ) &&
		this->isSubclassOf( InventoryItem ) &&
		sent->PowerupActive()
		)
		{
		return false;
		} */
	}
	return true;
}
Exemplo n.º 4
0
void GotoAIEvent::Update(float /*dt*/)
{
	Sentient* pActor = GetActor();

	PathFinderMove move;
	GetPathfinder().FindNextMove( pActor->GetPosition(), _destination, _arrivalDist, move );

	if( move.LastResult == PathFinder::PFMR_PATH_FOUND)
	{
		pActor->ApplyImpulse( move.MoveDir * _moveSpeed * pActor->GetBody()->GetMass(), Vector2::Zero );
	}
	else if( move.LastResult == PathFinder::PFMR_ARRIVED )
	{
		_moveFailed = false;
		IssueCallback();
	}
	else if( move.LastResult == PathFinder::PFMR_PATH_NOT_FOUND )
	{
		_moveFailed = true;
		IssueCallback();
	}

}
Exemplo n.º 5
0
void HealthInventoryItem::Use( Event *ev )
{
	Entity      *other;
	Sentient    *sen;
	//Event			*event;
	str			sound_name;
	
	
	other = ev->GetEntity<Entity>( 1 );
	if ( !other || !other->isSubclassOf( Sentient ) )
	{
		return;
	}
	
	sen = ( Sentient * )other;
	
	GameplayManager *gpm = GameplayManager::getTheGameplayManager();
	if ( gpm->hasObject(getArchetype()) )
	{
		if ( gpm->hasFormula("HealthPotion") )
		{
			GameplayFormulaData fd(this);
			amount = gpm->calculate("HealthPotion", fd, sen->max_health);
		}
		str snd = gpm->getStringValue(getArchetype() + ".Use", "wav");
		if ( snd.length() )
		{
			int channel = CHAN_BODY;
			float volume = -1.0f;
			float mindist = -1.0f;
			if ( gpm->hasProperty(getArchetype() + ".Use","channel") )
				channel = (int)gpm->getFloatValue(getArchetype() + ".Use", "channel");
			if ( gpm->hasProperty(getArchetype() + ".Use","volume") )
				volume = (int)gpm->getFloatValue(getArchetype() + ".Use", "volume");
			if ( gpm->hasProperty(getArchetype() + ".Use","mindist") )
				mindist = (int)gpm->getFloatValue(getArchetype() + ".Use", "mindist");
			Sound(snd, channel, volume, mindist);
		}
	}
	
	sen->health += (float)amount;
	
	if ( sen->health > sen->max_health )
	{
		sen->health = sen->max_health;
	}
	
	// If we are on fire stop it
	
	sen->ProcessEvent( EV_Sentient_StopOnFire );
	
	// Spawn special effect around sentient
	
	// Uncomment if we need it
	/*sound_name = GetRandomAlias( "snd_use" );
	
	if ( sound_name )
	other->Sound( sound_name.c_str(), 0 );
	  
	event = new Event( EV_AttachModel );
	event->AddString( "models/fx_tikifx2.tik" );
	event->AddString( "Bip01 Spine" );
	// set scale
	event->AddFloat( 1.0f );
	// set targetname
	event->AddString( "regen" );
	// set detach_at_death
	event->AddInteger( 1 );
	// set remove_time
	event->AddFloat( 2.0f );
	other->ProcessEvent( event );*/
	
	PostEvent( EV_Remove, 0.0f );
}
Exemplo n.º 6
0
Item * Item::ItemPickup( Entity *other, qboolean add_to_inventory, qboolean checkautopickup )
{
	Sentient * sent;
	Item * item = NULL;
	str realname;
	
	// Query the gameplay manager and see if we should not auto-pickup this item
	if ( checkautopickup )
	{
		GameplayManager *gpm = GameplayManager::getTheGameplayManager();
		if ( gpm->hasProperty(getArchetype(), "noautopickup") )
			return NULL;
	}
	
	if ( !Pickupable( other ) )
	{
		return NULL;
	}
	
	sent = ( Sentient * )other;
	
	if ( add_to_inventory )
	{
		item = sent->giveItem( model, getAmount(), true );
		
		
		if ( !item )
			return NULL;
	}
	else
	{
		item = this;
	}
	
	//
	// make sure to copy over the coolness factor :)
	//
	item->coolitem = coolitem;
	item->cool_dialog = cool_dialog;
	item->cool_anim = cool_anim;
	item->coolitemforced = coolitemforced;
	
	//
	// let our sent know they received it
	// we put this here so we can transfer information from the original item we picked up
	//

	if ( !isSubclassOf( Weapon ) || add_to_inventory )
		sent->ReceivedItem( item );
	
	realname = GetRandomAlias( "snd_pickup" );
	if ( realname.length() > 1 )
		sent->Sound( realname, CHAN_ITEM );
	
	if ( !Removable() )
	{
		// leave the item for others to pickup
		return item;
	}
	
	look_at_me = false;
	
	CancelEventsOfType( EV_Item_DropToFloor );
	CancelEventsOfType( EV_Item_Respawn );
	CancelEventsOfType( EV_FadeOut );
	
	setSolidType( SOLID_NOT );
	
	if ( animate && animate->HasAnim( "pickup" ) )
		animate->RandomAnimate( "pickup", EV_Item_PickupDone );
	else
	{
		if ( !no_remove )
		{
			if ( _missingSkin )
			{
				ChangeSkin( _missingSkin, true );
			}
			else
			{
				hideModel();
			}
			
			if ( !Respawnable() )
				PostEvent( EV_Remove, FRAMETIME );
		}
	}
	
	if ( Respawnable() )
		PostEvent( EV_Item_Respawn, RespawnTime() );
	
	// fire off any pickup_thread's
	if ( pickup_thread.length() )
	{
		ExecuteThread( pickup_thread );
	}
	
	
	if ( item && multiplayerManager.checkFlag( MP_FLAG_INSTANT_ITEMS ) )
	{
		Event *ev;
		
		ev = new Event( EV_InventoryItem_Use );
		ev->AddEntity( other );
		
		item->ProcessEvent( ev );
	}
	
	return item;
}
Exemplo n.º 7
0
void DefaultStrategos::_CheckForInConeOfFire()
{
	Vector dir;
	Vector check;
	float relativeYaw;
	float distance;
	Sentient *teammate;
	Player *player;
	Actor *actor;

	player = NULL;
	teammate = NULL;
   
   
	// Should really loop through all teammates, but I'm most concerned about the
	// player right now.
	for ( int i = 1 ; i <= TeamMateList.NumObjects() ; i++ )
	{
		teammate = TeamMateList.ObjectAt( i );
		
		if ( !teammate || teammate->entnum == act->entnum )
			continue;
		
		dir = act->origin - teammate->origin;
		//dir = teammate->origin - act->origin;
		distance = dir.length();  
		
		if ( distance < _checkInConeDistMax )
		{
			dir = dir.toAngles();
			
			if ( teammate->isSubclassOf( Player ) )
            {
				_checkYawMin = -5.0f;
				_checkYawMax =  5.0f;
				
				
				player = (Player*)teammate;
				check = player->GetVAngles();
            }
			else
            {
				
				_checkYawMin = -5.0f;
				_checkYawMax =  5.0f;
				
				actor = (Actor*)teammate;
				check = actor->movementSubsystem->getAnimDir();
				check = check.toAngles();
            }
            
			
			relativeYaw = AngleNormalize180( AngleNormalize180(check[YAW]) - AngleNormalize180(dir[YAW]) );
			
			if ( (relativeYaw <= _checkYawMax) && (relativeYaw >= _checkYawMin ) )
            {
				act->SetActorFlag( ACTOR_FLAG_IN_CONE_OF_FIRE , true );      

				if ( teammate->isSubclassOf(Player) && distance <= 128 )
					act->SetActorFlag( ACTOR_FLAG_IN_PLAYER_CONE_OF_FIRE , true );

				return;
            }		
		}
	}
	
	act->SetActorFlag( ACTOR_FLAG_IN_CONE_OF_FIRE , false );
	act->SetActorFlag( ACTOR_FLAG_IN_PLAYER_CONE_OF_FIRE , false );
	
}