2010-06-25 16:15:09 -06:00
|
|
|
#include "ctanks.h"
|
2024-12-04 18:40:53 -07:00
|
|
|
#include <math.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2010-06-25 16:15:09 -06:00
|
|
|
|
2010-07-06 13:53:17 -06:00
|
|
|
/* Debugging help */
|
2024-12-04 18:40:53 -07:00
|
|
|
#define DUMPf(fmt, args...) \
|
|
|
|
fprintf(stderr, "%s:%s:%d " fmt "\n", __FILE__, __FUNCTION__, __LINE__, \
|
|
|
|
##args)
|
2010-07-06 13:53:17 -06:00
|
|
|
#define DUMP() DUMPf("")
|
|
|
|
#define DUMP_d(v) DUMPf("%s = %d", #v, v)
|
|
|
|
#define DUMP_x(v) DUMPf("%s = 0x%x", #v, v)
|
|
|
|
#define DUMP_s(v) DUMPf("%s = %s", #v, v)
|
|
|
|
#define DUMP_c(v) DUMPf("%s = %c", #v, v)
|
|
|
|
#define DUMP_f(v) DUMPf("%s = %f", #v, v)
|
2010-07-14 15:21:20 -06:00
|
|
|
#define DUMP_p(v) DUMPf("%s = %p", #v, v)
|
2010-07-06 13:53:17 -06:00
|
|
|
#define DUMP_xy(v) DUMPf("%s = (%f, %f)", #v, v[0], v[1]);
|
2024-12-04 18:40:53 -07:00
|
|
|
#define DUMP_angle(v) DUMPf("%s = %.3fτ", #v, (v / TAU));
|
2010-07-06 13:53:17 -06:00
|
|
|
|
|
|
|
#define sq(x) ((x) * (x))
|
|
|
|
|
2024-12-04 18:40:53 -07:00
|
|
|
void tank_init(struct tank *tank, tank_run_func *run, void *udata) {
|
2010-06-25 16:15:09 -06:00
|
|
|
memset(tank, 0, sizeof(*tank));
|
|
|
|
tank->run = run;
|
|
|
|
tank->udata = udata;
|
|
|
|
}
|
|
|
|
|
2024-12-04 18:40:53 -07:00
|
|
|
int tank_fire_ready(struct tank *tank) { return (!tank->turret.recharge); }
|
2010-06-25 16:15:09 -06:00
|
|
|
|
2024-12-04 18:40:53 -07:00
|
|
|
void tank_fire(struct tank *tank) {
|
2010-06-25 16:15:09 -06:00
|
|
|
tank->turret.firing = tank_fire_ready(tank);
|
|
|
|
}
|
|
|
|
|
2024-12-04 18:40:53 -07:00
|
|
|
void tank_set_speed(struct tank *tank, float left, float right) {
|
2010-07-14 15:21:20 -06:00
|
|
|
tank->speed.desired[0] = min(max(left, -100), 100);
|
|
|
|
tank->speed.desired[1] = min(max(right, -100), 100);
|
2010-06-25 16:15:09 -06:00
|
|
|
}
|
|
|
|
|
2024-12-04 18:40:53 -07:00
|
|
|
float tank_get_turret(struct tank *tank) { return tank->turret.current; }
|
2010-06-25 16:15:09 -06:00
|
|
|
|
2024-12-04 18:40:53 -07:00
|
|
|
void tank_set_turret(struct tank *tank, float angle) {
|
2010-07-22 15:23:45 -06:00
|
|
|
tank->turret.desired = fmodf(angle, TAU);
|
2010-06-25 16:15:09 -06:00
|
|
|
}
|
|
|
|
|
2024-12-04 18:40:53 -07:00
|
|
|
int tank_get_sensor(struct tank *tank, int sensor_num) {
|
2010-06-28 17:12:20 -06:00
|
|
|
if ((sensor_num < 0) || (sensor_num > TANK_MAX_SENSORS)) {
|
2010-06-25 16:15:09 -06:00
|
|
|
return 0;
|
|
|
|
}
|
2010-07-06 13:53:17 -06:00
|
|
|
return tank->sensors[sensor_num].triggered;
|
2010-06-25 16:15:09 -06:00
|
|
|
}
|
|
|
|
|
2024-12-04 18:40:53 -07:00
|
|
|
void tank_set_led(struct tank *tank, int active) { tank->led = active; }
|
2010-06-25 16:15:09 -06:00
|
|
|
|
2024-12-04 18:40:53 -07:00
|
|
|
static void rotate_point(float angle, float point[2]) {
|
2010-06-28 17:12:20 -06:00
|
|
|
float cos_, sin_;
|
|
|
|
float new[2];
|
|
|
|
|
2010-07-06 13:53:17 -06:00
|
|
|
cos_ = cosf(angle);
|
|
|
|
sin_ = sinf(angle);
|
2010-06-28 17:12:20 -06:00
|
|
|
|
2024-12-04 18:40:53 -07:00
|
|
|
new[0] = point[0] * cos_ - point[1] * sin_;
|
|
|
|
new[1] = point[0] * sin_ + point[1] * cos_;
|
2010-07-06 13:53:17 -06:00
|
|
|
|
|
|
|
point[0] = new[0];
|
|
|
|
point[1] = new[1];
|
2010-06-28 17:12:20 -06:00
|
|
|
}
|
|
|
|
|
2024-12-04 18:40:53 -07:00
|
|
|
static void tanks_fire_cannon(struct tanks_game *game, struct tank *this,
|
|
|
|
struct tank *that, float vector[2], float dist2) {
|
2010-07-14 15:21:20 -06:00
|
|
|
float theta = this->angle + this->turret.current;
|
|
|
|
float rpos[2];
|
2010-06-25 16:15:09 -06:00
|
|
|
|
2024-12-04 18:40:53 -07:00
|
|
|
/* If someone's a crater, this is easy (unless we were just killed by the
|
|
|
|
other one, in which case we have to check the other direction) */
|
2014-07-26 05:48:04 -06:00
|
|
|
if ((this->killer && this->killer != that) || that->killer) {
|
2010-07-14 15:21:20 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Did they collide? */
|
2014-07-26 05:48:04 -06:00
|
|
|
if ((!this->killer) && dist2 < TANK_COLLISION_ADJ2) {
|
2010-07-14 15:21:20 -06:00
|
|
|
this->killer = that;
|
|
|
|
this->cause_death = "collision";
|
|
|
|
|
|
|
|
that->killer = this;
|
|
|
|
that->cause_death = "collision";
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No need to check if it's not even firing */
|
2024-12-04 18:40:53 -07:00
|
|
|
if (!this->turret.firing) {
|
2010-07-14 15:21:20 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Also no need to check if it's outside cannon range */
|
|
|
|
if (dist2 > TANK_CANNON_ADJ2) {
|
|
|
|
return;
|
2010-06-28 17:12:20 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Did this shoot that? Rotate point by turret degrees, and if |y| <
|
|
|
|
TANK_RADIUS, we have a hit. */
|
2010-07-14 15:21:20 -06:00
|
|
|
rpos[0] = vector[0];
|
|
|
|
rpos[1] = vector[1];
|
|
|
|
rotate_point(-theta, rpos);
|
2010-07-21 15:54:46 -06:00
|
|
|
if ((rpos[0] > 0) && (fabsf(rpos[1]) < TANK_RADIUS)) {
|
2010-07-14 15:21:20 -06:00
|
|
|
that->killer = this;
|
|
|
|
that->cause_death = "shot";
|
|
|
|
}
|
|
|
|
}
|
2010-06-28 17:12:20 -06:00
|
|
|
|
2024-12-04 18:40:53 -07:00
|
|
|
static void tanks_sensor_calc(struct tanks_game *game, struct tank *this,
|
|
|
|
struct tank *that, float vector[2], float dist2) {
|
|
|
|
int i;
|
2010-07-14 15:21:20 -06:00
|
|
|
|
|
|
|
/* If someone's a crater, this is easy */
|
|
|
|
if (this->killer || that->killer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If they're not inside the max sensor, just skip it */
|
|
|
|
if (dist2 > TANK_SENSOR_ADJ2) {
|
|
|
|
return;
|
2010-06-28 17:12:20 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate sensors */
|
2010-07-06 13:53:17 -06:00
|
|
|
for (i = 0; i < TANK_MAX_SENSORS; i += 1) {
|
|
|
|
float theta;
|
2010-06-28 17:12:20 -06:00
|
|
|
float rpos[2];
|
|
|
|
float m_r, m_s;
|
|
|
|
|
2010-07-14 15:21:20 -06:00
|
|
|
if (0 == this->sensors[i].range) {
|
|
|
|
/* Sensor doesn't exist */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-06-28 17:12:20 -06:00
|
|
|
/* No need to re-check this sensor if it's already firing */
|
2010-07-06 13:53:17 -06:00
|
|
|
if (this->sensors[i].triggered) {
|
2010-06-28 17:12:20 -06:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the tank is out of range, don't bother */
|
2010-07-06 13:53:17 -06:00
|
|
|
if (dist2 > sq(this->sensors[i].range + TANK_RADIUS)) {
|
2010-06-28 17:12:20 -06:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* What is the angle of our sensor? */
|
2010-07-06 13:53:17 -06:00
|
|
|
theta = this->angle + this->sensors[i].angle;
|
|
|
|
if (this->sensors[i].turret) {
|
2010-06-28 17:12:20 -06:00
|
|
|
theta += this->turret.current;
|
|
|
|
}
|
|
|
|
|
2010-07-14 15:21:20 -06:00
|
|
|
/* Rotate their position by theta */
|
|
|
|
rpos[0] = vector[0];
|
|
|
|
rpos[1] = vector[1];
|
2010-07-06 13:53:17 -06:00
|
|
|
rotate_point(-theta, rpos);
|
2010-06-28 17:12:20 -06:00
|
|
|
|
2010-07-06 13:53:17 -06:00
|
|
|
/* Sensor is symmetrical, we can consider only top quadrants */
|
2010-06-28 17:12:20 -06:00
|
|
|
rpos[1] = fabsf(rpos[1]);
|
|
|
|
|
2010-07-06 13:53:17 -06:00
|
|
|
/* Compute inverse slopes to tank and of our sensor */
|
|
|
|
m_s = 1 / tanf(this->sensors[i].width / 2);
|
|
|
|
m_r = rpos[0] / rpos[1];
|
2010-06-28 17:12:20 -06:00
|
|
|
|
2010-07-06 13:53:17 -06:00
|
|
|
/* If our inverse slope is less than theirs, they're inside the arc */
|
2010-06-28 17:12:20 -06:00
|
|
|
if (m_r >= m_s) {
|
2010-07-06 13:53:17 -06:00
|
|
|
this->sensors[i].triggered = 1;
|
2010-06-28 17:12:20 -06:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now check if the edge of the arc intersects the tank. Do this
|
|
|
|
just like with firing. */
|
2010-07-06 13:53:17 -06:00
|
|
|
rotate_point(this->sensors[i].width / -2, rpos);
|
2010-07-21 15:54:46 -06:00
|
|
|
if ((rpos[0] > 0) && (fabsf(rpos[1]) < TANK_RADIUS)) {
|
2010-07-06 13:53:17 -06:00
|
|
|
this->sensors[i].triggered = 1;
|
2010-06-28 17:12:20 -06:00
|
|
|
}
|
2010-06-25 16:15:09 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-04 18:40:53 -07:00
|
|
|
void compute_vector(struct tanks_game *game, float vector[2], float *dist2,
|
|
|
|
struct tank *this, struct tank *that) {
|
|
|
|
int i;
|
2010-06-25 16:15:09 -06:00
|
|
|
|
|
|
|
/* Establish shortest vector from center of this to center of that,
|
|
|
|
* taking wrapping into account */
|
|
|
|
for (i = 0; i < 2; i += 1) {
|
2010-06-28 17:12:20 -06:00
|
|
|
float halfsize = game->size[i] / 2;
|
2010-06-25 16:15:09 -06:00
|
|
|
|
2010-07-14 15:21:20 -06:00
|
|
|
vector[i] = that->position[i] - this->position[i];
|
|
|
|
if (vector[i] > halfsize) {
|
|
|
|
vector[i] = vector[i] - game->size[i];
|
2024-12-04 18:40:53 -07:00
|
|
|
} else if (vector[i] < -halfsize) {
|
2010-07-14 15:21:20 -06:00
|
|
|
vector[i] = game->size[i] + vector[i];
|
|
|
|
}
|
2010-06-25 16:15:09 -06:00
|
|
|
}
|
2010-07-06 13:53:17 -06:00
|
|
|
|
2010-06-25 16:15:09 -06:00
|
|
|
/* Compute distance^2 for range comparisons */
|
2010-07-14 15:21:20 -06:00
|
|
|
*dist2 = sq(vector[0]) + sq(vector[1]);
|
2010-06-28 17:12:20 -06:00
|
|
|
}
|
2010-06-25 16:15:09 -06:00
|
|
|
|
2024-12-04 18:40:53 -07:00
|
|
|
void tanks_move_tank(struct tanks_game *game, struct tank *tank) {
|
|
|
|
int i;
|
2010-07-06 13:53:17 -06:00
|
|
|
float movement;
|
|
|
|
float angle;
|
2024-12-04 18:40:53 -07:00
|
|
|
int dir = 1;
|
2010-07-06 13:53:17 -06:00
|
|
|
|
|
|
|
/* Rotate the turret */
|
|
|
|
{
|
2024-12-04 18:40:53 -07:00
|
|
|
float rot_angle; /* Quickest way there */
|
2010-07-06 13:53:17 -06:00
|
|
|
|
|
|
|
/* Constrain rot_angle to between -PI and PI */
|
|
|
|
rot_angle = tank->turret.desired - tank->turret.current;
|
|
|
|
while (rot_angle < 0) {
|
2010-07-22 15:23:45 -06:00
|
|
|
rot_angle += TAU;
|
2010-07-06 13:53:17 -06:00
|
|
|
}
|
2010-07-22 15:23:45 -06:00
|
|
|
rot_angle = fmodf(PI + rot_angle, TAU) - PI;
|
2010-07-06 13:53:17 -06:00
|
|
|
|
|
|
|
rot_angle = min(TANK_MAX_TURRET_ROT, rot_angle);
|
|
|
|
rot_angle = max(-TANK_MAX_TURRET_ROT, rot_angle);
|
2010-07-22 15:23:45 -06:00
|
|
|
tank->turret.current = fmodf(tank->turret.current + rot_angle, TAU);
|
2010-07-06 13:53:17 -06:00
|
|
|
}
|
2010-06-28 17:12:20 -06:00
|
|
|
|
|
|
|
/* Fakey acceleration */
|
2010-06-25 16:15:09 -06:00
|
|
|
for (i = 0; i < 2; i += 1) {
|
2010-06-28 17:12:20 -06:00
|
|
|
if (tank->speed.current[i] == tank->speed.desired[i]) {
|
|
|
|
/* Do nothing */
|
|
|
|
} else if (tank->speed.current[i] < tank->speed.desired[i]) {
|
2024-12-04 18:40:53 -07:00
|
|
|
tank->speed.current[i] =
|
|
|
|
min(tank->speed.current[i] + TANK_MAX_ACCEL, tank->speed.desired[i]);
|
2010-06-28 17:12:20 -06:00
|
|
|
} else {
|
2024-12-04 18:40:53 -07:00
|
|
|
tank->speed.current[i] =
|
|
|
|
max(tank->speed.current[i] - TANK_MAX_ACCEL, tank->speed.desired[i]);
|
2010-06-28 17:12:20 -06:00
|
|
|
}
|
2010-06-25 16:15:09 -06:00
|
|
|
}
|
|
|
|
|
2010-06-28 17:12:20 -06:00
|
|
|
/* The simple case */
|
|
|
|
if (tank->speed.current[0] == tank->speed.current[1]) {
|
2010-07-06 13:53:17 -06:00
|
|
|
movement = tank->speed.current[0] * (TANK_TOP_SPEED / 100.0);
|
2024-12-04 18:40:53 -07:00
|
|
|
angle = 0;
|
2010-06-28 17:12:20 -06:00
|
|
|
} else {
|
|
|
|
/* pflarr's original comment:
|
|
|
|
*
|
2010-07-06 13:53:17 -06:00
|
|
|
* The tank drives around in a circle of radius r, which is some
|
2010-06-28 17:12:20 -06:00
|
|
|
* offset on a line perpendicular to the tank. The distance it
|
|
|
|
* travels around the circle varies with the speed of each tread,
|
|
|
|
* and is such that each side of the tank moves an equal angle
|
|
|
|
* around the circle.
|
|
|
|
*
|
|
|
|
* Sounds good to me. pflarr's calculations here are fantastico,
|
|
|
|
* there's nothing whatsoever to change. */
|
|
|
|
float friction;
|
|
|
|
float v[2];
|
|
|
|
float So, Si;
|
2010-07-06 13:53:17 -06:00
|
|
|
float r;
|
|
|
|
float theta;
|
2010-06-25 16:15:09 -06:00
|
|
|
|
2010-06-28 17:12:20 -06:00
|
|
|
/* The first thing Paul's code does is find "friction", which seems
|
|
|
|
to be a penalty for having the treads go in opposite directions.
|
|
|
|
This probably plays hell with precisely-planned tanks, which I
|
|
|
|
find very ha ha. */
|
2024-12-04 18:40:53 -07:00
|
|
|
friction = TANK_FRICTION *
|
|
|
|
(fabsf(tank->speed.current[0] - tank->speed.current[1]) / 200);
|
2010-07-06 13:53:17 -06:00
|
|
|
v[0] = tank->speed.current[0] * (1 - friction) * (TANK_TOP_SPEED / 100.0);
|
|
|
|
v[1] = tank->speed.current[1] * (1 - friction) * (TANK_TOP_SPEED / 100.0);
|
2010-06-28 17:12:20 -06:00
|
|
|
|
|
|
|
/* Outside and inside speeds */
|
2010-07-22 15:19:52 -06:00
|
|
|
if (fabsf(v[0]) > abs(v[1])) {
|
|
|
|
Si = v[1];
|
|
|
|
So = v[0];
|
|
|
|
dir = 1;
|
|
|
|
} else {
|
|
|
|
Si = v[0];
|
|
|
|
So = v[1];
|
|
|
|
dir = -1;
|
|
|
|
}
|
2010-06-28 17:12:20 -06:00
|
|
|
|
|
|
|
/* Radius of circle to outside tread (use similar triangles) */
|
2010-07-06 13:53:17 -06:00
|
|
|
r = So * (TANK_RADIUS * 2) / (So - Si);
|
2010-06-25 16:15:09 -06:00
|
|
|
|
2010-06-28 17:12:20 -06:00
|
|
|
/* pflarr:
|
|
|
|
|
|
|
|
The fraction of the circle traveled is equal to the speed
|
|
|
|
of the outer tread over the circumference of the circle:
|
2010-07-22 15:23:45 -06:00
|
|
|
Ft = So/(tau*r)
|
2010-06-28 17:12:20 -06:00
|
|
|
The angle traveled is:
|
2010-07-22 15:23:45 -06:00
|
|
|
theta = Ft * tau
|
2010-06-28 17:12:20 -06:00
|
|
|
This reduces to a simple
|
|
|
|
theta = So/r
|
|
|
|
We multiply it by dir to adjust for the direction of rotation
|
|
|
|
*/
|
2024-12-04 18:40:53 -07:00
|
|
|
theta = So / r * dir;
|
2010-06-28 17:12:20 -06:00
|
|
|
|
2010-07-06 13:53:17 -06:00
|
|
|
movement = r * tanf(theta);
|
2010-06-28 17:12:20 -06:00
|
|
|
angle = theta;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now move the tank */
|
2010-07-22 15:23:45 -06:00
|
|
|
tank->angle = fmodf(tank->angle + angle + TAU, TAU);
|
2010-07-06 13:53:17 -06:00
|
|
|
{
|
|
|
|
float m[2];
|
|
|
|
|
2010-07-14 15:21:20 -06:00
|
|
|
m[0] = cosf(tank->angle) * movement * dir;
|
|
|
|
m[1] = sinf(tank->angle) * movement * dir;
|
2010-07-06 13:53:17 -06:00
|
|
|
|
|
|
|
for (i = 0; i < 2; i += 1) {
|
2024-12-04 18:40:53 -07:00
|
|
|
tank->position[i] =
|
|
|
|
fmodf(tank->position[i] + m[i] + game->size[i], game->size[i]);
|
2010-07-06 13:53:17 -06:00
|
|
|
}
|
2010-06-25 16:15:09 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-04 18:40:53 -07:00
|
|
|
void tanks_run_turn(struct tanks_game *game, struct tank *tanks, int ntanks) {
|
|
|
|
int i, j;
|
2010-07-14 15:21:20 -06:00
|
|
|
float vector[2];
|
2024-12-04 18:40:53 -07:00
|
|
|
float dist2; /* distance squared */
|
2010-06-25 16:15:09 -06:00
|
|
|
|
2010-07-14 15:21:20 -06:00
|
|
|
/* It takes (at least) two to tank-o */
|
|
|
|
if (ntanks < 2) {
|
|
|
|
return;
|
2010-07-06 13:53:17 -06:00
|
|
|
}
|
|
|
|
|
2010-07-14 15:21:20 -06:00
|
|
|
/* Charge cannons and reset sensors */
|
2010-07-06 13:53:17 -06:00
|
|
|
for (i = 0; i < ntanks; i += 1) {
|
2010-07-14 15:21:20 -06:00
|
|
|
if (tanks[i].turret.firing) {
|
|
|
|
tanks[i].turret.firing = 0;
|
|
|
|
tanks[i].turret.recharge = TANK_CANNON_RECHARGE;
|
|
|
|
}
|
2024-12-04 18:40:53 -07:00
|
|
|
if (tanks[i].killer)
|
|
|
|
continue;
|
2010-07-14 15:21:20 -06:00
|
|
|
if (tanks[i].turret.recharge) {
|
|
|
|
tanks[i].turret.recharge -= 1;
|
|
|
|
}
|
2010-07-06 13:53:17 -06:00
|
|
|
for (j = 0; j < TANK_MAX_SENSORS; j += 1) {
|
|
|
|
tanks[i].sensors[j].triggered = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-14 15:21:20 -06:00
|
|
|
/* Move tanks */
|
|
|
|
for (i = 0; i < ntanks; i += 1) {
|
2024-12-04 18:40:53 -07:00
|
|
|
if (tanks[i].killer)
|
|
|
|
continue;
|
2010-07-14 15:21:20 -06:00
|
|
|
tanks_move_tank(game, &(tanks[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Probe sensors */
|
2010-07-06 13:53:17 -06:00
|
|
|
for (i = 0; i < ntanks; i += 1) {
|
2024-12-04 18:40:53 -07:00
|
|
|
if (tanks[i].killer)
|
|
|
|
continue;
|
2010-07-14 15:21:20 -06:00
|
|
|
for (j = i + 1; j < ntanks; j += 1) {
|
|
|
|
struct tank *this = &tanks[i];
|
|
|
|
struct tank *that = &tanks[j];
|
|
|
|
|
|
|
|
compute_vector(game, vector, &dist2, this, that);
|
|
|
|
tanks_sensor_calc(game, this, that, vector, dist2);
|
|
|
|
vector[0] = -vector[0];
|
|
|
|
vector[1] = -vector[1];
|
|
|
|
tanks_sensor_calc(game, that, this, vector, dist2);
|
2010-07-06 13:53:17 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-14 15:21:20 -06:00
|
|
|
/* Run programs */
|
|
|
|
for (i = 0; i < ntanks; i += 1) {
|
2024-12-04 18:40:53 -07:00
|
|
|
if (tanks[i].killer)
|
|
|
|
continue;
|
2010-07-14 15:21:20 -06:00
|
|
|
tanks[i].run(&tanks[i], tanks[i].udata);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fire cannons and check for crashes */
|
2010-06-25 16:15:09 -06:00
|
|
|
for (i = 0; i < ntanks; i += 1) {
|
2024-12-04 18:40:53 -07:00
|
|
|
if (tanks[i].killer)
|
|
|
|
continue;
|
2010-06-28 17:12:20 -06:00
|
|
|
for (j = i + 1; j < ntanks; j += 1) {
|
2010-07-14 15:21:20 -06:00
|
|
|
struct tank *this = &tanks[i];
|
|
|
|
struct tank *that = &tanks[j];
|
|
|
|
|
|
|
|
compute_vector(game, vector, &dist2, this, that);
|
|
|
|
tanks_fire_cannon(game, this, that, vector, dist2);
|
|
|
|
vector[0] = -vector[0];
|
|
|
|
vector[1] = -vector[1];
|
|
|
|
tanks_fire_cannon(game, that, this, vector, dist2);
|
2010-06-25 16:15:09 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|