-/* $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
* 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
-/* $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
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,
}
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);
}
-/* $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
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);
-/* $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
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;
}
}
torps_update();
+ collisions_update();
/* XXX Send all ships, torps and collisions to all clients for now */
DLIST_FOREACH(&clients_list, c) {
(void) sendq_zflush(&c->sendq, NULL, NULL);
(void) sendq_flush(&c->sendq, -1);
}
- /* Collisions are only sent once */
- collision_reset();
}
int
-/* $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
}
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;
-/* $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
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 *);
-/* $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
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;
}