- Make sure that collisions are only checked for active clients
authorMatthew Mondor <mmondor@pulsar-zone.net>
Mon, 30 Jun 2014 03:37:35 +0000 (03:37 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Mon, 30 Jun 2014 03:37:35 +0000 (03:37 +0000)
- Use common ship reset code

mmsoftware/mystic_ships/server/src/ships.c
mmsoftware/mystic_ships/server/src/torp.c

index 2a2f502..775378d 100644 (file)
@@ -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
index 5ea5bb2..c08d8f1 100644 (file)
@@ -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),