Example #1
0
void game_cprintf(edict_t *ent, int printlevel, char *fmt, ...)
{
	va_list args;
	char buf[1024];

	va_start(args, fmt);
	vsnprintf(buf, sizeof buf, fmt, args);
	buf[sizeof buf - 1] = 0;
	va_end(args);

	if (ent == NULL)
		q2a_lua_LogMessage(buf);

	gi.cprintf(ent, printlevel, "%s", buf);
}
Example #2
0
void CheckPlayerLookTargets (void)
{
    cvar_t *show_look;
    int i;
	edict_t	*ent;
    player_state_t *ps;
	vec3_t view_origin, forward, right, distance, view_target;
	trace_t trace;

    // Set this console variable to display information about what the
    // player is looking at.  For debugging purposes.
    show_look = gi.cvar("show_look", "0", CVAR_SERVERINFO);

    // Iterate over all the active players.
    for (i=0 ; i<maxclients->value ; i++)
    {
		ent = g_edicts + 1 + i;
		if (!ent->inuse)
			continue;
        
        // Calculate the player's line of sight, beginning at view_origin
        // and extending to view_target a fair distance away.
        ps = &ent->client->ps;
        VectorAdd(ent->s.origin, ps->viewoffset, view_origin);
        AngleVectors(ps->viewangles, forward, right, NULL);
        VectorSet(distance, LOOK_DISTANCE, 0, 0);
        G_ProjectSource(view_origin, distance, forward, right, view_target);

        // Trace the player's line of sight and see what we hit.  We begin
        // the trace at view_origin, use a size zero bounding box (NULL,
        // NULL), end the trace at view_target, ignore the player 'ent', and
        // stop when we hit any of the specified object types.
        trace = gi.trace(view_origin, NULL, NULL, view_target, ent,
                         MASK_OPAQUE|CONTENTS_WINDOW|CONTENTS_MONSTER|
                         CONTENTS_DEADMONSTER);

        // If show_look is true, report what the player is currently
        // looking at for debugging purposes
        if (show_look->value && trace.ent && trace.ent->classname)
            gi.cprintf(ent, PRINT_HIGH, "Looking at: %s %x\n",
                       trace.ent->classname, trace.ent);

		// If we're looking at something new, remember it and run any
		// associated look_target.
		if (trace.ent != ent->client->looking_at)
		{
			ent->client->looking_at = trace.ent;
			if (trace.ent && trace.ent->look_target)
				G_UseTargetsByName(trace.ent, trace.ent->look_target, ent);
		}

		// Objects don't get reticles if they're too far away.
		if (trace.fraction > (1.0 * RETICLE_DISTANCE) / LOOK_DISTANCE)
			trace.ent = NULL;

		// We need to resend the reticle every frame, in case the entity
		// is moving relative to the world.
		SendReticle(trace.ent, ent);

		// If the reticle is on something new, remember it and run any
		// associated r_look_target (sound familiar?).
		if (trace.ent != ent->client->reticle_on)
		{
			ent->client->reticle_on = trace.ent;
			if (trace.ent && trace.ent->r_look_target)
				G_UseTargetsByName(trace.ent, trace.ent->r_look_target, ent);
		}
    }
}