-/* $Id: ships.c,v 1.7 2014/06/27 15:28:04 mmondor Exp $ */
+/* $Id: ships.c,v 1.8 2014/06/30 03:37:35 mmondor Exp $ */
/*
* Copyright (c) 2006, 2014, Matthew Mondor
void
-ship_init(ship_t *s, int type)
+ship_reset(ship_t *s)
{
- struct shipdesc *d;
-
- DEBUG_ASSERT(s != NULL);
- DEBUG_ASSERT(type > -1 && type < SHIP_MAX);
-
- d = &ships[type];
+ struct shipdesc *d = &ships[s->type];
- s->ship = d;
- s->type = type;
s->hull = d->hull_max;
s->shield = d->shield_max;
s->fuel = d->fuel_max;
s->phaser_delay = 0.0;
s->shield_on = s->i_shield_on = 1;
s->cloak_on = s->i_cloak_on = 0;
- s->torps = 0;
- /* XXX Random position/angle for now */
+ /*
+ * XXX Random position/angle for now.
+ * Should also at least not place the ship on top of another one...
+ */
s->angle = s->i_angle = (random() % 255);
s->x = d->radius + (random() % (int)(WORLD_X_MAX - (d->radius * 2) - 1));
s->y = d->radius + (random() % (int)(WORLD_Y_MAX - (d->radius * 2) - 1));
- /*
- s->x = WORLD_X_MAX / 2;
- s->y = WORLD_Y_MAX / 2;
- */
}
void
-ship_reset(ship_t *s)
+ship_init(ship_t *s, int type)
{
- struct shipdesc *d = &ships[s->type];
+ struct shipdesc *d;
- s->hull = d->hull_max;
- s->shield = d->shield_max;
- s->fuel = d->fuel_max;
- s->thrust = s->i_thrust = 0.0;
- s->phaser_delay = 0.0;
- s->shield_on = s->i_shield_on = 1;
- s->cloak_on = s->i_cloak_on = 0;
- /* XXX Random position/angle for now */
- s->angle = s->i_angle = (random() % 255);
- s->x = d->radius + (random() % (int)(WORLD_X_MAX - (d->radius * 2) - 1));
- s->y = d->radius + (random() % (int)(WORLD_Y_MAX - (d->radius * 2) - 1));
+ DEBUG_ASSERT(s != NULL);
+ DEBUG_ASSERT(type > -1 && type < SHIP_MAX);
+
+ d = &ships[type];
+
+ s->ship = d;
+ s->type = type;
+ s->torps = 0;
+ ship_reset(s);
}
void
-/* $Id: torp.c,v 1.5 2014/06/26 03:46:37 mmondor Exp $ */
+/* $Id: torp.c,v 1.6 2014/06/30 03:37:35 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
ship_t *s = &c->ship;
int sx = s->x, sy = s->y, sr = s->ship->radius;
+ if (c->todestroy || c->toclose)
+ continue;
+
if (square_intersect(tx, ty, tr, sx, sy, sr) &&
circle_intersect(tx, ty, tr, sx, sy, sr)) {
collision_create((int)(tsd->torp_damage / 2),