/* ============================== G_FireAllTargetsOf "activator" should be set to the entity that initiated the firing. For all t in the entities, where t.targetnames[i] matches ent.targets[j] for any (i,j) pairs, call the t.use function. ============================== */ void G_EventFireEntity( gentity_t *self, gentity_t *activator, gentityCallEvent_t eventType ) { gentity_t *currentTarget = nullptr; int targetIndex; gentityCall_t call; call.activator = activator; while( ( currentTarget = G_IterateCallEndpoints( currentTarget, &targetIndex, self ) ) != nullptr ) { if( eventType && self->calltargets[ targetIndex ].eventType != eventType ) { continue; } call.caller = self; //reset the caller in case there have been nested calls call.definition = &self->calltargets[ targetIndex ]; G_CallEntity(currentTarget, &call); if ( !self->inuse ) { G_Printf( S_WARNING "entity was removed while using targets\n" ); return; } } }
/* ============================== G_FireAllTargetsOf "activator" should be set to the entity that initiated the firing. For all t in the entities, where t.targetnames[i] matches ent.targets[j] for any (i,j) pairs, call the t.use function. ============================== */ void G_EventFireEntity( gentity_t *self, gentity_t *activator, gentityCallEvent_t eventType ) { gentity_t *currentTarget = NULL; int targetIndex; gentityCall_t call; call.activator = activator; if ( self->shaderKey && self->shaderReplacement ) { G_SetShaderRemap( self->shaderKey, self->shaderReplacement, level.time * 0.001 ); trap_SetConfigstring( CS_SHADERSTATE, BuildShaderStateConfig() ); } while( ( currentTarget = G_IterateCallEndpoints( currentTarget, &targetIndex, self ) ) != NULL ) { if( eventType && self->calltargets[ targetIndex ].eventType != eventType ) { continue; } call.caller = self; //reset the caller in case there have been nested calls call.definition = &self->calltargets[ targetIndex ]; G_CallEntity(currentTarget, &call); if ( !self->inuse ) { G_Printf( S_WARNING "entity was removed while using targets\n" ); return; } } }
void G_FireEntityRandomly( gentity_t *entity, gentity_t *activator ) { int targetIndex; gentity_t *possibleTarget = nullptr; int totalChoiceCount = 0; gentityCall_t call; gentityTargetChoice_t choices[ MAX_GENTITIES ]; gentityTargetChoice_t *selectedChoice; //collects the targets while( ( possibleTarget = G_IterateCallEndpoints( possibleTarget, &targetIndex, entity ) ) != nullptr ) { choices[ totalChoiceCount ].recipient = possibleTarget; choices[ totalChoiceCount ].callDefinition = &entity->calltargets[targetIndex]; totalChoiceCount++; } if ( totalChoiceCount == 0 ) return; //return a random one from among the choices selectedChoice = &choices[ rand() / ( RAND_MAX / totalChoiceCount + 1 ) ]; call.definition = selectedChoice->callDefinition; call.caller = entity; call.activator = activator; G_CallEntity( selectedChoice->recipient, &call ); }
/* =================== Svcmd_EntityShow_f =================== */ void Svcmd_EntityShow_f() { int entityNum; int lastTargetIndex, targetIndex; gentity_t *selection; gentity_t *possibleTarget = nullptr; char argument[ 6 ]; if (trap_Argc() != 2) { G_Printf("usage: entityShow <entityId>\n"); return; } trap_Argv( 1, argument, sizeof( argument ) ); entityNum = atoi( argument ); if (entityNum >= level.num_entities || entityNum < MAX_CLIENTS) { G_Printf("entityId %d is out of range\n", entityNum); return; } selection = &g_entities[entityNum]; if (!selection->inuse) { G_Printf("entity slot %d is unused/free\n", entityNum); return; } G_Printf( "⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼\n" ); G_Printf( "^5#%3i^*: %16s", entityNum, Com_EntityTypeName( selection->s.eType ) ); if (IS_NON_NULL_VEC3(selection->s.origin)) { G_Printf("%26s", vtos( selection->s.origin ) ); } G_Printf( "\n⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼\n" ); G_Printf( "Classname: ^5%s^*\n", selection->classname ); G_Printf( "Capabilities:%s%s%s%s%s%s%s\n\n", selection->act ? " acts" : "", selection->think ? " thinks" : "", selection->pain ? " pains" : "", selection->die ? " dies" : "", selection->reset ? " resets" : "", selection->touch ? " touchable" : "", selection->use ? " usable" : ""); if (selection->names[0]) { G_Printf( "Names: "); G_PrintEntityNameList( selection ); } G_Printf("State: %s\n", selection->enabled ? "enabled" : "disabled"); if (selection->groupName) { G_Printf("Member of Group: %s%s\n", selection->groupName, !selection->groupMaster ? " [master]" : ""); } G_Printf( "\n"); if(selection->targetCount) { G_Printf( "Aims at\n"); while ((possibleTarget = G_IterateTargets(possibleTarget, &targetIndex, selection)) != nullptr ) { G_Printf(" • %s %s\n", etos( possibleTarget ), vtos( possibleTarget->s.origin)); } G_Printf( "\n"); } if(selection->callTargetCount) { lastTargetIndex = -1; while ((possibleTarget = G_IterateCallEndpoints(possibleTarget, &targetIndex, selection)) != nullptr ) { if(lastTargetIndex != targetIndex) { G_Printf("Calls %s \"%s:%s\"\n", selection->calltargets[ targetIndex ].event ? selection->calltargets[ targetIndex ].event : "onUnknown", selection->calltargets[ targetIndex ].name, selection->calltargets[ targetIndex ].action ? selection->calltargets[ targetIndex ].action : "default"); lastTargetIndex = targetIndex; } G_Printf(" • %s", etos(possibleTarget)); if(possibleTarget->names[1]) { G_Printf(" using \"%s\" ∈ ", selection->calltargets[ targetIndex ].name); G_PrintEntityNameList( possibleTarget ); } G_Printf("\n"); } } G_Printf( "\n" ); }