From: Matthew Mondor Date: Mon, 14 Jul 2014 08:26:31 +0000 (+0000) Subject: - Fix a bug where the torp radius sent to the client was not always the X-Git-Url: http://git.pulsar-zone.net/?a=commitdiff_plain;h=561444d73142965ff5ffc0a04fb755a40b30461f;p=mmondor.git - Fix a bug where the torp radius sent to the client was not always the one for the ship type - Implemented torpedo collisions, but only one torpedo is destroyed for now --- diff --git a/mmsoftware/mystic_ships/server/src/packets.c b/mmsoftware/mystic_ships/server/src/packets.c index f561a51..0362704 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.8 2014/06/30 18:45:31 mmondor Exp $ */ +/* $Id: packets.c,v 1.9 2014/07/14 08:26:31 mmondor Exp $ */ /* * Copyright (c) 2006, Matthew Mondor @@ -332,7 +332,7 @@ spacket_torp_send(client_t *c, torp_t *t) struct spacket_torp p; p.packet_type = SPACKET_TORP; - p.radius = c->ship.ship->torp_radius; + p.radius = t->client->ship.ship->torp_radius; p.x = BYTEORDER_NETWORK16(t->x); p.y = BYTEORDER_NETWORK16(t->y); diff --git a/mmsoftware/mystic_ships/server/src/torp.c b/mmsoftware/mystic_ships/server/src/torp.c index 6347363..175dcb6 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.7 2014/06/30 18:45:31 mmondor Exp $ */ +/* $Id: torp.c,v 1.8 2014/07/14 08:26:31 mmondor Exp $ */ /* * Copyright (c) 2006, Matthew Mondor @@ -95,7 +95,7 @@ torp_destroy(torp_t *t) void torps_update(void) { - torp_t *t, *next; + torp_t *t, *next, *t2; int s, r, ox, oy; for (t = (torp_t *)DLIST_TOP(&torps_list); t != NULL; t = next) { @@ -132,6 +132,34 @@ torps_update(void) continue; } + /* Torp/torp collisions, might be expensive */ + DLIST_FOREACH(&torps_list, t2) { + int tx2, ty2, tr2; + + if (t2 == t) + continue; + tx2 = t2->x; + ty2 = t2->y; + tr2 = t2->client->ship.ship->torp_radius; + if (square_intersect(tx, ty, tr, tx2, ty2, tr2) && + circle_intersect(tx, ty, tr, tx2, ty2, tr2)) { + collision_create(tr * tr2, tx, ty); + collision_create(tr * tr2, tx2, ty2); + torp_destroyed = 1; + /* + * XXX We should destroy t2, but this could + * cause a race condition, as the outer loop + * may still iterate through it. We thus + * should mark them like for clients... + */ +// torp_destroy(t2); + } + } + if (torp_destroyed) { + torp_destroy(t); + continue; + } + if (--(t->life) == 0) { torp_destroy(t); continue;