コード例 #1
0
/**
 * G_PickRandomTargetFor
 * Selects a random entity from among the targets
 */
gentity_t *G_PickRandomTargetFor( gentity_t *self )
{
	int       targetIndex;
	gentity_t *foundTarget = nullptr;
	int       totalChoiceCount = 0;
	gentity_t *choices[ MAX_GENTITIES ];

	//collects the targets
	while( ( foundTarget = G_IterateTargets( foundTarget, &targetIndex, self ) ) != nullptr )
		choices[ totalChoiceCount++ ] = foundTarget;

	if ( !totalChoiceCount )
	{
		if ( g_debugEntities.integer > -1 )
		{
			G_Printf( S_WARNING "none of the following targets could be resolved for Entity %s:", etos(self));
			G_PrintEntityNameList( self );
		}
		return nullptr;
	}

	//return a random one from among the choices
	return choices[ rand() / ( RAND_MAX / totalChoiceCount + 1 ) ];
}
コード例 #2
0
/*
===================
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" );
}