From: bwoodall@bilbo.qualcomm.com (Bill Woodall)
Subject: Re: Programs
Reply-To: bwoodall@bilbo.qualcomm.com (Bill Woodall)
Organization: Qualcomm Eng. Dept.
Date: Thu, 20 Aug 1992 14:48:29 GMT

In article <OKES.92Aug20113403@solb1.essex.ac.uk>, okes@solb1.essex.ac.uk (Oke
S) writes:
|> In article <1992Aug15.013510.1852@latcs1.lat.oz.au> barton@latcs4.lat.oz.au
|> (The DayDreamer) writes:
|> 
|> > If there is sufficient interest I can post a little program that I wrote,
|> which
|> > aims weapons and replenishes... this make life a little easier on the
|> driver
|> > and increases the reload time for weapons as they get turned on and off
|> > automatically by the program...

Here is a little one taken from warrior that we use on and off here          

.....................Bill,
 
============================================================
	Man's capacity to learn is not fixed in any ordinary
sense.  It is not fixed in terms of the responses it will
produce;  it is not fixed in terms of absolute level of
knowledge it will achive. - 
============================================================

<<<<<<<<<<<<<<<<<<<<<<CUT HERE>>>>>>>>>>>>>>>>>>>>>>
/*****************************************************************************\
* spotr.c - an Xtank assistant						      *
*                                                                             *
\*****************************************************************************/

#include <stdio.h>
#include "xtank.h"
#include "xtanklib.h"
#include "vehicle.h"

static void main();

Prog_desc spotr_prog = {
	"spotr",
	"BASE",
	"Move your turrets",
	"Bill Woodall (bwoodall@qualcomm.com)",
	PLAYS_COMBAT | USES_TEAMS,
	0,
	main
};


static void main()
{
	Location	mloc;
	Settings_info	si;
	Vehicle_info	veh[MAX_VEHICLES], self;
	Weapon_info	w;
	int		dx, dy, etx, ety, esx, esy, mtx, mty, dist, min_dist;
	int		i, mx_ammo_spd, mx_ammo_rnge, sq_ammo_spd, num_vec, vsave; 
	int		vt, temp, a, b, c, t, attempt, Gotarget;

	turn_vehicle(0.0);
	aim_all_turrets(50,0);
	set_rel_drive(9.0);

	get_settings(&si);

	mx_ammo_spd = mx_ammo_rnge = 0;
	for (i = num_weapons() -1; i >= 0; --i) {
	    get_weapon(i, &w);
	    if (w.ammo_speed > mx_ammo_spd)
		mx_ammo_spd = w.ammo_speed;
	    if (w.range > mx_ammo_rnge)
		mx_ammo_rnge = w.range;
	}
	sq_ammo_spd = mx_ammo_spd * mx_ammo_spd;
	sq_ammo_spd = 900;

	while (1)
	{
	    get_self(&self);
	    get_location(&mloc);
	    mtx = mloc.grid_x * BOX_WIDTH + mloc.box_x;
	    mty = mloc.grid_y * BOX_HEIGHT + mloc.box_y;

	    min_dist = 1000000;
	    get_vehicles(&num_vec, veh);
	    Gotarget = 0;
	    for (i=0; i < num_vec; i++) {
		if (veh[i].team != self.team || self.team == NEUTRAL) {
		    Gotarget = 1;
		    dx = (veh[i].loc.grid_x * BOX_WIDTH + veh[i].loc.box_x) - mtx;
		    dy = (veh[i].loc.grid_y * BOX_HEIGHT + veh[i].loc.box_y) - mty;
		    dist = dx * dx + dy * dy;
		    if (dist < min_dist) {
		      min_dist = dist;
		      vsave = i;
		    }
		}
	    }
	    if (Gotarget != 0) {			/* from warrior	*/
		etx = veh[vsave].loc.grid_x * BOX_WIDTH + veh[vsave].loc.box_x;
		ety = veh[vsave].loc.grid_y * BOX_HEIGHT + veh[vsave].loc.box_y;
		if (si.rel_shoot) {
		    esx = veh[vsave].xspeed - self.xspeed;
		    esy = veh[vsave].yspeed - self.yspeed;
		}
		else {
		    esx = veh[vsave].xspeed;
		    esy = veh[vsave].yspeed;
		}
		vt = (int) sqrt((double) (esx*esx + esy*esy));
		a = vt*vt - sq_ammo_spd;
		dx = etx - mtx;
		dy = ety - mty;
		b = (dx * esx + dy * esy) << 1;
		c = dx * dx + dy * dy;
		temp = b * b - (a * c << 2);
		if ((temp < 0) || (a >= 0)) {
		    t = 1;
		}
		else {
		    temp = (int) (sqrt((double) temp));
		    t = ((-b -temp) / a) >> 1;
		    dx += t * esx;
		    dy += t * esy;
		    aim_all_turrets(dx, dy);
	  	}
	    }
	    done();			/* wait for start of next turn */
	}
}
Newsgroups: rec.games.xtank.play