From: Matthew Mondor Date: Wed, 25 Jun 2014 15:05:47 +0000 (+0000) Subject: - Better collision detonations X-Git-Url: http://git.pulsar-zone.net/?a=commitdiff_plain;h=cc08bb2b8c256531b3cc470280e13e3843d641f0;p=mmondor.git - Better collision detonations - When a ship dies it is reset, rather than being rejected by the server --- diff --git a/mmsoftware/mystic_ships/client/src/conf.h b/mmsoftware/mystic_ships/client/src/conf.h index 7838a4e..758b9b9 100644 --- a/mmsoftware/mystic_ships/client/src/conf.h +++ b/mmsoftware/mystic_ships/client/src/conf.h @@ -1,4 +1,4 @@ -/* $Id: conf.h,v 1.4 2014/06/25 14:25:42 mmondor Exp $ */ +/* $Id: conf.h,v 1.5 2014/06/25 15:05:47 mmondor Exp $ */ /* * Copyright (c) 2006, Matthew Mondor @@ -14,8 +14,7 @@ * Various hardcoded configuration parameters. */ -//#define SERVER_HOST "mmondor.pulsar-zone.net" -#define SERVER_HOST "192.168.1.15" +#define SERVER_HOST "mmondor.pulsar-zone.net" #define SERVER_PORT 7777 #define CLIENT_VERSION 1 diff --git a/mmsoftware/mystic_ships/server/src/collision.c b/mmsoftware/mystic_ships/server/src/collision.c index c76e1ff..a3e0888 100644 --- a/mmsoftware/mystic_ships/server/src/collision.c +++ b/mmsoftware/mystic_ships/server/src/collision.c @@ -1,4 +1,4 @@ -/* $Id: collision.c,v 1.1 2014/06/25 14:25:42 mmondor Exp $ */ +/* $Id: collision.c,v 1.2 2014/06/25 15:05:47 mmondor Exp $ */ /* * Copyright (c) 2006, 2014, Matthew Mondor @@ -44,6 +44,7 @@ collision_create(int radius, int x, int y) c->radius = radius; c->x = x; c->y = y; + c->ttl = 8 + (random() % radius); DLIST_APPEND(&collisions_list, (node_t *)c); } else syslog(LOG_NOTICE, @@ -51,15 +52,22 @@ collision_create(int radius, int x, int y) } void -collision_reset(void) +collisions_update(void) { collision_t *c, *next; for (c = (collision_t *)DLIST_TOP(&collisions_list); c != NULL; c = next) { next = DLIST_NEXT((node_t *)c); - (void) pool_free((pnode_t *)c); + + if (--(c->ttl) <= 0) { + DLIST_UNLINK(&collisions_list, (node_t *)c); + (void) pool_free((pnode_t *)c); + continue; + } + c->radius += (-6 + (random() % 8)); + c->x += (-4 + (random() % 8)); + c->y += (-4 + (random() % 8)); } - DLIST_INIT(&collisions_list); } diff --git a/mmsoftware/mystic_ships/server/src/collision.h b/mmsoftware/mystic_ships/server/src/collision.h index db2846a..6efe369 100644 --- a/mmsoftware/mystic_ships/server/src/collision.h +++ b/mmsoftware/mystic_ships/server/src/collision.h @@ -1,4 +1,4 @@ -/* $Id: collision.h,v 1.1 2014/06/25 14:25:42 mmondor Exp $ */ +/* $Id: collision.h,v 1.2 2014/06/25 15:05:47 mmondor Exp $ */ /* * Copyright (c) 2006, 2014, Matthew Mondor @@ -20,13 +20,14 @@ typedef struct collision { pnode_t pnode; int radius; int x, y; + int ttl; } collision_t; void collision_init(void); void collision_create(int, int, int); -void collision_reset(void); +void collisions_update(void); diff --git a/mmsoftware/mystic_ships/server/src/packets.c b/mmsoftware/mystic_ships/server/src/packets.c index 5eb78ee..14d0de8 100644 --- a/mmsoftware/mystic_ships/server/src/packets.c +++ b/mmsoftware/mystic_ships/server/src/packets.c @@ -1,4 +1,4 @@ -/* $Id: packets.c,v 1.5 2014/06/25 14:25:42 mmondor Exp $ */ +/* $Id: packets.c,v 1.6 2014/06/25 15:05:47 mmondor Exp $ */ /* * Copyright (c) 2006, Matthew Mondor @@ -120,17 +120,13 @@ packets_update(void) if (square_intersect(x1, y1, r1, x2, y2, r2) && circle_intersect(x1, y1, r1, x2, y2, r2)) { - /* XXX - * - If a ship dies, don't kill the - * client; delay and reset instead - */ collision_create((int)(r1 + r2), x1, y1); collision_create((int)(r1 + r2), x2, y2); if (ship_hit_ship(s1, s2)) { - client_destroy_mark(c); - client_destroy_mark(c2); + ship_reset(&c->ship); + ship_reset(&c2->ship); } break; } @@ -196,6 +192,7 @@ k: } torps_update(); + collisions_update(); /* XXX Send all ships, torps and collisions to all clients for now */ DLIST_FOREACH(&clients_list, c) { @@ -248,8 +245,6 @@ k: (void) sendq_zflush(&c->sendq, NULL, NULL); (void) sendq_flush(&c->sendq, -1); } - /* Collisions are only sent once */ - collision_reset(); } int diff --git a/mmsoftware/mystic_ships/server/src/ships.c b/mmsoftware/mystic_ships/server/src/ships.c index cb44114..75170ca 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.5 2014/06/25 14:25:42 mmondor Exp $ */ +/* $Id: ships.c,v 1.6 2014/06/25 15:05:47 mmondor Exp $ */ /* * Copyright (c) 2006, 2014, Matthew Mondor @@ -114,6 +114,24 @@ ship_init(ship_t *s, int type) } void +ship_reset(ship_t *s) +{ + struct shipdesc *d = &ships[s->type]; + + 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)); +} + +void ship_update(ship_t *s) { double d; diff --git a/mmsoftware/mystic_ships/server/src/ships.h b/mmsoftware/mystic_ships/server/src/ships.h index 862b956..264876a 100644 --- a/mmsoftware/mystic_ships/server/src/ships.h +++ b/mmsoftware/mystic_ships/server/src/ships.h @@ -1,4 +1,4 @@ -/* $Id: ships.h,v 1.3 2014/06/25 12:53:14 mmondor Exp $ */ +/* $Id: ships.h,v 1.4 2014/06/25 15:05:47 mmondor Exp $ */ /* * Copyright (c) 2006, Matthew Mondor @@ -53,6 +53,7 @@ typedef struct ship { void ship_init(ship_t *, int); void ship_update(ship_t *); +void ship_reset(ship_t *); int ship_hit_torp(ship_t *, shipdesc_t *); int ship_hit_ship(ship_t *, ship_t *); diff --git a/mmsoftware/mystic_ships/server/src/torp.c b/mmsoftware/mystic_ships/server/src/torp.c index 53c9079..553a930 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.3 2014/06/25 14:25:42 mmondor Exp $ */ +/* $Id: torp.c,v 1.4 2014/06/25 15:05:47 mmondor Exp $ */ /* * Copyright (c) 2006, Matthew Mondor @@ -114,14 +114,12 @@ torps_update(void) if (square_intersect(tx, ty, tr, sx, sy, sr) && circle_intersect(tx, ty, tr, sx, sy, sr)) { - /* XXX - * - If ship dies, don't kill client but - * instead: delay, reset, continue - */ collision_create((int)(tsd->torp_damage / 5), tx, ty); - if (ship_hit_torp(s, tsd)) - client_destroy_mark(c); + if (ship_hit_torp(s, tsd)) { + collision_create(sr, sx, sy); + ship_reset(&c->ship); + } torp_destroyed = 1; continue; }