Now randomly change ship type when reset
authorMatthew Mondor <mmondor@pulsar-zone.net>
Tue, 1 Jul 2014 11:12:51 +0000 (11:12 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Tue, 1 Jul 2014 11:12:51 +0000 (11:12 +0000)
mmsoftware/mystic_ships/server/src/client.c
mmsoftware/mystic_ships/server/src/ships.c
mmsoftware/mystic_ships/server/src/ships.h

index 79602d1..f4bb56e 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: client.c,v 1.7 2014/06/30 18:45:31 mmondor Exp $ */
+/* $Id: client.c,v 1.8 2014/07/01 11:12:51 mmondor Exp $ */
 
 /*
  * Copyright (c) 2006, Matthew Mondor
@@ -101,8 +101,7 @@ client_create(int fd, struct sockaddr *saddr)
                recvq_reset(&c->recvq, c);
                (void) memcpy(&c->saddr, saddr, sizeof(struct sockaddr));
 
-               /* ship_init(&c->ship, SHIP_CA); */
-               ship_init(&c->ship, 1 - (random() % 2)); /* XXX */
+               ship_init(&c->ship);
 
                c->authenticated = c->todestroy = c->toclose = 0;
                c->writepolling = 1;
index 775378d..0bef7dc 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: ships.c,v 1.8 2014/06/30 03:37:35 mmondor Exp $ */
+/* $Id: ships.c,v 1.9 2014/07/01 11:12:51 mmondor Exp $ */
 
 /*
  * Copyright (c) 2006, 2014, Matthew Mondor
@@ -82,10 +82,15 @@ struct shipdesc ships[SHIP_MAX] = {
 
 
 
+/* Random ship, position and angle for now. */
 void
 ship_reset(ship_t *s)
 {
-       struct shipdesc *d = &ships[s->type];
+       int             type = random() % SHIP_MAX;
+       struct shipdesc *d = &ships[type];
+
+       s->ship = d;
+       s->type = type;
 
        s->hull = d->hull_max;
        s->shield = d->shield_max;
@@ -95,27 +100,16 @@ ship_reset(ship_t *s)
        s->shield_on = s->i_shield_on = 1;
        s->cloak_on = s->i_cloak_on = 0;
 
-       /*
-        * XXX Random position/angle for now.
-        * Should also at least not place the ship on top of another one...
-        */
+       /* XXX Might land on another ship and immediately explode */
        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));
 }
 
 void
-ship_init(ship_t *s, int type)
+ship_init(ship_t *s)
 {
-       struct shipdesc *d;
 
-       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);
 }
index 264876a..0c72357 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: ships.h,v 1.4 2014/06/25 15:05:47 mmondor Exp $ */
+/* $Id: ships.h,v 1.5 2014/07/01 11:12:51 mmondor Exp $ */
 
 /*
  * Copyright (c) 2006, Matthew Mondor
@@ -51,7 +51,7 @@ typedef struct ship {
 
 
 
-void                   ship_init(ship_t *, int);
+void                   ship_init(ship_t *);
 void                   ship_update(ship_t *);
 void                   ship_reset(ship_t *);
 int                    ship_hit_torp(ship_t *, shipdesc_t *);