Esempio n. 1
0
/**
 * @brief "activator" should be set to the entity that initiated the firing.
 * Search for (string)targetname in all entities that
 * match (string)self.target and call their .use function
 */
void G_UseTargets(gentity_t *ent, gentity_t *activator)
{
	gentity_t *t;
	int       hash;

	if (!ent)
	{
		return;
	}

	if (!ent->target)
	{
		return;
	}

	t    = NULL;
	hash = BG_StringHashValue(ent->target);
	while ((t = G_FindByTargetnameFast(t, ent->target, hash)) != NULL)
	{
		if (t == ent)
		{
			G_Printf(S_COLOR_YELLOW "WARNING G_UseTargets: Entity used itself.\n");
		}
		else
		{
			if (t->use)
			{
				//G_Printf ("ent->classname %s ent->targetname %s t->targetname %s t->s.number %d\n", ent->classname, ent->targetname, t->targetname, t->s.number);

				t->flags |= (ent->flags & FL_KICKACTIVATE);   // If 'ent' was kicked to activate, pass this along to it's targets.
				                                              //		It may become handy to put a "KICKABLE" flag in ents so that it knows whether to pass this along or not
				                                              //		Right now, the only situation where it would be weird would be an invisible_user that is a 'button' near
				                                              //		a rotating door that it triggers.  Kick the switch and the door next to it flies open.

				t->flags |= (ent->flags & FL_SOFTACTIVATE);   // likewise for soft activation

				if (activator &&
				    ((Q_stricmp(t->classname, "func_door") == 0) ||
				     (Q_stricmp(t->classname, "func_door_rotating") == 0)
				    )
				    )
				{
					// check door usage rules before allowing any entity to trigger a door open
					G_TryDoor(t, ent, activator);         // (door,other,activator)
				}
				else
				{
					G_UseEntity(t, ent, activator);
				}
			}
		}
		if (!ent->inuse)
		{
			G_Printf(S_COLOR_YELLOW "WARNING G_UseTargets: entity was removed while using targets\n");
			return;
		}
	}
}
Esempio n. 2
0
/*
==============================
G_UseTargets

"activator" should be set to the entity that initiated the firing.

Search for (string)targetname in all entities that
match (string)self.target and call their .use function

==============================
*/
void G_UseTargets( gentity_t *ent, gentity_t *activator ) {
	gentity_t       *t;

	if ( !ent ) {
		return;
	}

	if ( ent->targetShaderName && ent->targetShaderNewName ) {
		float f = level.time * 0.001;
		AddRemap( ent->targetShaderName, ent->targetShaderNewName, f );
		trap_SetConfigstring( CS_SHADERSTATE, BuildShaderStateConfig() );
	}

	if ( !ent->target ) {
		return;
	}

	t = NULL;
	while ( ( t = G_Find( t, FOFS( targetname ), ent->target ) ) != NULL ) {
		if ( t == ent ) {
			G_Printf( "WARNING: Entity used itself.\n" );
		} else {
			if ( t->use ) {
				//G_Printf ("ent->classname %s ent->targetname %s t->targetname %s t->s.number %d\n", ent->classname, ent->targetname, t->targetname, t->s.number);

				t->flags |= ( ent->flags & FL_KICKACTIVATE ); // (SA) If 'ent' was kicked to activate, pass this along to it's targets.
				//		It may become handy to put a "KICKABLE" flag in ents so that it knows whether to pass this along or not
				//		Right now, the only situation where it would be weird would be an invisible_user that is a 'button' near
				//		a rotating door that it triggers.  Kick the switch and the door next to it flies open.

				t->flags |= ( ent->flags & FL_SOFTACTIVATE ); // (SA) likewise for soft activation

				if (    activator &&
					(   ( Q_stricmp( t->classname, "func_door" ) == 0 ) ||
					( Q_stricmp( t->classname, "func_door_rotating" ) == 0 )
					)
					) {
						// check door usage rules before allowing any entity to trigger a door open
						G_TryDoor( t, ent, activator );       // (door,other,activator)
				} else {
					t->use( t, ent, activator );
				}
			}
		}
		if ( !ent->inuse ) {
			G_Printf( "entity was removed while using targets\n" );
			return;
		}
	}
}