.\" @(#)tmac.vgrind 1.7 88/02/08 SMI; from UCB 4.3 beta
'ss 23
'ds _ \d\(mi\u
'ps 9p
'vs 10p
'ds - \(mi
'ds / \\h'\\w' 'u-\\w'/'u'/
'ds /* \\h'\\w' 'u-\\w'/'u'/*
'bd B 3
'bd S B 3
'nr cm 0
'nf
'de vH
'ev 2
'if t 'if !\nv 'tl '\-\-''\-\-'
'ft 1
'sp .35i
'tl '\s14\f3\\*(=F\fP\s0'\\*(=H'\f3\s14\\*(=F\fP\s0'
'sp .25i
'ft 1
\f2\s12\h'\\n(.lu-\w'\\*(=f'u'\\*(=f\fP\s0\h'|0u'
.sp .05i
'ev
'ds =G \\*(=F
..
'de vF
'ev 2
'sp .35i
'tl '\f2\\*(=M''Page % of \\*(=G\fP'
'bp
'ev
'ft 1
'if \\n(cm=1 'ft 2
..
'de ()
'pn 1
..
'de +C
'nr cm 1
'ft 2
'ds +K
'ds -K
..
'de -C
'nr cm 0
'ft 1
'ds +K \f3
'ds -K \fP
..
'+C
'-C
'am +C
'ne 3
..
'de FN
\f2\s14\h'\\n(.lu-\w'\\$1'u'\\$1\fP\s0\h'|0u'\c
.if \\nx .tm \\$1 \\*(=F \\n%
'ds =f \&...\\$1
..
'de FC
.if \\nx .tm \\$1 \\*(=F \\n%
'ds =f \&...\\$1
..
'de -F
'rm =f
..
'ft 1
'lg 0
'-F
/*****************************************************************************\
* spider.c - An example XTank player.					      *
* 									      *
* Note the use of the All structure to simulate global variables, and the use *
* of set_cleanup_func().						      *
\*****************************************************************************/

#include <xtanklib.h>
#include <math.h>

static void main();		/* forward reference */

Prog_desc spider_prog = {
    "spider",
    "Red_tie",
    "Waits for an enemy to appear, then charges in guns blazing.",
    "Robert Potter (after Terry Donahue)",
    PLAYS_COMBAT | DOES_SHOOT,
    2,
    main
};

/* all my global data */
typedef struct {
    Location myloc;		/* where I am */
    Boolean have_target;	/* whether I have someone to attack */
    Vehicle_info target;	/* who I'm going to attack */
} All;

static void look_around(allp)
    All *allp;
{
    get_location(&allp->myloc);	/* find out where I am */
    allp->have_target = get_closest_enemy(&allp->target);
}

static void do_something(allp)
    All *allp;
{
    /* If a bad guy's around, attack him */
    if (allp->have_target) {
	int dx, dy;

	/* Find out where he is with respect to me */
	dx = allp->target.loc.x - allp->myloc.x;
	dy = allp->target.loc.y - allp->myloc.y;

	aim_all_turrets(dx, dy);
	fire_all_weapons();	/* blast him */

	turn_vehicle(ATAN2(dy, dx));
	set_rel_drive(9.0);	/* give chase */
    } else {
	set_rel_drive(0.0);	/* wait for next victim */
    }
}

static void cleanup(allp)
    All *allp;
{
    /* free all dynamically allocated memory */
    free((char *)allp);
}

static void main()
{
    All *allp;

    /* allocate the All structure dynamically, to save stack space */
    allp = (All *) calloc(1, sizeof(*allp));

    /* arrange for the All structure to get free()ed when I die */
    set_cleanup_func(cleanup, (void *) allp);

    while (1) {
	look_around(allp);
	do_something(allp);
	done();
    }
}
'-F
.()
.bp
