From e5a133239a7caab8377edfcfe7b976d2e0636b67 Mon Sep 17 00:00:00 2001 From: Matthew Mondor Date: Mon, 30 Jun 2014 03:37:35 +0000 Subject: [PATCH] - Make sure that collisions are only checked for active clients - Use common ship reset code --- mmsoftware/mystic_ships/server/src/ships.c | 47 ++++++++++++------------------ mmsoftware/mystic_ships/server/src/torp.c | 5 +++- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/mmsoftware/mystic_ships/server/src/ships.c b/mmsoftware/mystic_ships/server/src/ships.c index 2a2f502..775378d 100644 --- a/mmsoftware/mystic_ships/server/src/ships.c +++ b/mmsoftware/mystic_ships/server/src/ships.c @@ -1,4 +1,4 @@ -/* $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 @@ -83,17 +83,10 @@ struct shipdesc ships[SHIP_MAX] = { 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; @@ -101,34 +94,30 @@ ship_init(ship_t *s, int type) 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 diff --git a/mmsoftware/mystic_ships/server/src/torp.c b/mmsoftware/mystic_ships/server/src/torp.c index 5ea5bb2..c08d8f1 100644 --- a/mmsoftware/mystic_ships/server/src/torp.c +++ b/mmsoftware/mystic_ships/server/src/torp.c @@ -1,4 +1,4 @@ -/* $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 @@ -112,6 +112,9 @@ torps_update(void) 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), -- 2.9.0