-/* $Id: conf.h,v 1.3 2014/06/21 17:16:32 mmondor Exp $ */
+/* $Id: conf.h,v 1.4 2014/06/25 14:25:42 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
* Various hardcoded configuration parameters.
*/
-#define SERVER_HOST "mmondor.pulsar-zone.net"
+//#define SERVER_HOST "mmondor.pulsar-zone.net"
+#define SERVER_HOST "192.168.1.15"
#define SERVER_PORT 7777
#define CLIENT_VERSION 1
-/* $Id: main.c,v 1.7 2014/06/25 12:53:13 mmondor Exp $ */
+/* $Id: main.c,v 1.8 2014/06/25 14:25:42 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
0x7f + (rand() % 0x80));
}
+void
+collision_draw(int x, int y, int r)
+{
+
+ /* XXX Should be fancier */
+ filledCircleRGBA(screen_surface, x, y, r, 0xff, 0xff, 0xff, 0xa0);
+}
+
static SDL_Surface *
bmp_load_key(const uint8_t *data, size_t size)
{
-/* $Id: main.h,v 1.3 2014/06/25 12:53:13 mmondor Exp $ */
+/* $Id: main.h,v 1.4 2014/06/25 14:25:42 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
void frame_switch(void);
void ship_draw(int, int, int, int, int, double, uint8_t);
void torp_draw(int, int, int);
+void collision_draw(int, int, int);
-/* $Id: packets.c,v 1.3 2014/06/25 12:53:13 mmondor Exp $ */
+/* $Id: packets.c,v 1.4 2014/06/25 14:25:42 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
static int
spacket_collision_handler(uint16_t *ptr)
{
- /*struct spacket_collision *p = (struct spacket_collision *)ptr;*/
+ struct spacket_collision *p = (struct spacket_collision *)ptr;
- /* XXX */
+ p->x = BYTEORDER_HOST16(p->x);
+ p->y = BYTEORDER_HOST16(p->y);
+
+ collision_draw(p->x, p->y, p->radius);
return 0;
}
-/* $Id: packets_common.h,v 1.4 2014/06/25 12:53:13 mmondor Exp $ */
+/* $Id: packets_common.h,v 1.5 2014/06/25 14:25:42 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
/* Collision/detonation update to client */
struct spacket_collision {
int8_t packet_type;
- int8_t collision_type;
- int16_t object1_id, object2_id;
+ int8_t radius;
+ int16_t x, y;
} __attribute__((__packed__));
struct svpacket_message {
-# $Id: GNUmakefile,v 1.2 2014/06/19 18:22:03 mmondor Exp $
+# $Id: GNUmakefile,v 1.3 2014/06/25 14:25:42 mmondor Exp $
MMLIB_PATH := ../../mmlib
MMLIBS := $(addprefix $(MMLIB_PATH)/,mmpool.o mmarch.o)
LIBS := -lc -lm -lz
OBJS := $(addprefix src/,main.o trigonometry.o net.o kqueue.o sendq.o recvq.o \
- packets.o daemon.o client.o ships.o torp.o enc.o) \
+ packets.o daemon.o client.o ships.o torp.o collision.o enc.o) \
$(addprefix ../common/,hmac_sha1.o hmac_rmd160.o sha1.o rmd160.o \
mmenc.o)
CFLAGS += -Wall -g
--- /dev/null
+/* $Id: collision.c,v 1.1 2014/06/25 14:25:42 mmondor Exp $ */
+
+/*
+ * Copyright (c) 2006, 2014, Matthew Mondor
+ * ALL RIGHTS RESERVED.
+ */
+
+
+
+#include <stdlib.h>
+#include <syslog.h>
+
+#include <mmlog.h>
+
+#include <collision.h>
+#include <client.h>
+
+
+
+list_t collisions_list;
+static pool_t collisions_pool;
+
+
+void
+collision_init(void)
+{
+
+ DLIST_INIT(&collisions_list);
+ if (!pool_init(&collisions_pool, "collisions_pool", malloc, free,
+ NULL, NULL, sizeof(collision_t), 65536 / sizeof(collision_t), 1,
+ 0)) {
+ syslog(LOG_NOTICE, "collision_init() - pool_init()");
+ exit(EXIT_FAILURE);
+ }
+}
+
+void
+collision_create(int radius, int x, int y)
+{
+ collision_t *c;
+
+ if ((c = (collision_t *)pool_alloc(&collisions_pool, FALSE))
+ != NULL) {
+ c->radius = radius;
+ c->x = x;
+ c->y = y;
+ DLIST_APPEND(&collisions_list, (node_t *)c);
+ } else
+ syslog(LOG_NOTICE,
+ "collision_create() - pool_alloc(collisions_pool)");
+}
+
+void
+collision_reset(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);
+ }
+ DLIST_INIT(&collisions_list);
+}
+
--- /dev/null
+/* $Id: collision.h,v 1.1 2014/06/25 14:25:42 mmondor Exp $ */
+
+/*
+ * Copyright (c) 2006, 2014, Matthew Mondor
+ * ALL RIGHTS RESERVED.
+ */
+
+
+
+#ifndef _COLLISION_H_
+#define _COLLISION_H_
+
+
+
+#include <client.h>
+
+
+
+typedef struct collision {
+ pnode_t pnode;
+ int radius;
+ int x, y;
+} collision_t;
+
+
+
+void collision_init(void);
+void collision_create(int, int, int);
+void collision_reset(void);
+
+
+
+extern list_t collisions_list;
+
+
+
+#endif
-/* $Id: main.c,v 1.1 2006/12/31 08:32:40 mmondor Exp $ */
+/* $Id: main.c,v 1.2 2014/06/25 14:25:42 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
#include <packets_common.h>
#include <packets.h>
#include <torp.h>
+#include <collision.h>
#include <client.h>
#include <enc.h>
#include <conf.h>
net_init();
trigonometry_init();
torp_init();
+ collision_init();
noncerand_init();
kqueue_addlisten(listen_fd);
kqueue_addsignal(SIGTERM);
-/* $Id: packets.c,v 1.4 2014/06/25 12:53:14 mmondor Exp $ */
+/* $Id: packets.c,v 1.5 2014/06/25 14:25:42 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
#include <enc.h>
#include <ships.h>
#include <torp.h>
+#include <collision.h>
#include <sendq.h>
#include <hmac.h>
#include <conf.h>
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);
torps_update();
- /* XXX Send all ships and all torps to all clients for now */
+ /* XXX Send all ships, torps and collisions to all clients for now */
DLIST_FOREACH(&clients_list, c) {
client_t *c2;
torp_t *t;
+ collision_t *col;
if (!c->authenticated)
continue;
}
DLIST_FOREACH(&clients_list, c2) {
-
if (!c2->authenticated)
continue;
-
if (!c2->ship.cloak_on || c2 == c) {
if (spacket_ship_send(c, (uint8_t)c2->fd,
&c2->ship) == -1)
break;
}
+ DLIST_FOREACH(&collisions_list, col) {
+ if (spacket_collision_send(c, col) == -1)
+ break;
+ }
+
if (spacket_eof_send(c) == -1)
break;
(void) sendq_zflush(&c->sendq, NULL, NULL);
(void) sendq_flush(&c->sendq, -1);
}
+ /* Collisions are only sent once */
+ collision_reset();
}
int
return client_write(c, (uint8_t *)&p, sizeof(p), 1);
}
+int
+spacket_collision_send(client_t *c, collision_t *col)
+{
+ struct spacket_collision p;
+
+ p.packet_type = SPACKET_COLLISION;
+ p.radius = col->radius;
+ p.x = BYTEORDER_NETWORK16(col->x);
+ p.y = BYTEORDER_NETWORK16(col->y);
+
+ return client_write(c, (uint8_t *)&p, sizeof(p), 1);
+}
+
static int
cpacket_auth_handler(client_t *c, uint16_t *ptr)
-/* $Id: packets.h,v 1.2 2014/06/25 12:53:14 mmondor Exp $ */
+/* $Id: packets.h,v 1.3 2014/06/25 14:25:42 mmondor Exp $ */
/*
* Copyright (c) Matthew Mondor
#include <packets_common.h>
#include <ships.h>
#include <torp.h>
+#include <collision.h>
int spacket_ship_send(client_t *, uint8_t, ship_t *);
int spacket_shipinfo_send(client_t *);
int spacket_torp_send(client_t *, torp_t *);
+int spacket_collision_send(client_t *, collision_t *);
-/* $Id: ships.c,v 1.4 2014/06/25 12:53:14 mmondor Exp $ */
+/* $Id: ships.c,v 1.5 2014/06/25 14:25:42 mmondor Exp $ */
/*
* Copyright (c) 2006, 2014, Matthew Mondor
80/*2.0*/, /* Turn thrust */
1.0, /* Turn cost */
200.0, /* Torp cost */
- 20.0, /* Torp damage */
- 2.0, /* Torp radius */
+ 35.0, /* Torp damage */
+ 3.0, /* Torp radius */
10.0, /* Torp speed */
- 40, /* Torp life */
+ 50, /* Torp life */
90.0, /* Phaser cost */
90.0, /* Phaser damage */
5.0, /* Phaser recharge */
2.0, /* Hull regen */
50.0, /* Shield max */
5.0, /* Shield cost */
- 3.0, /* Shield regen */
+ 2.0, /* Shield regen */
25.0, /* Cloak cost */
5000.0, /* Fuel max */
50.0, /* Fuel regen */
9.0, /* Thrust max */
0.60, /* Thrust acc */
- 0.60, /* Thrust dec */
+ 0.80, /* Thrust dec */
2.0, /* Thrust acc cost */
2.0, /* Thrust dec cost */
1.0, /* Thrust cost */
0.5, /* Turn cost */
90.0, /* Torp cost */
30.0, /* Torp damage */
- 3.0, /* Torp radius */
+ 2.0, /* Torp radius */
12.0, /* Torp speed */
- 60, /* Torp life */
+ 40, /* Torp life */
90.0, /* Phaser cost */
90.0, /* Phaser damage */
5.0, /* Phaser recharge */
-/* $Id: torp.c,v 1.2 2014/06/21 17:16:32 mmondor Exp $ */
+/* $Id: torp.c,v 1.3 2014/06/25 14:25:42 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
#include <trigonometry.h>
#include <client.h>
#include <ships.h>
+#include <collision.h>
#include <conf.h>
s->torps++;
DLIST_APPEND(&torps_list, (node_t *)t);
} else
- syslog(LOG_NOTICE, "torp_create() - pool_alloc(torps_list)");
+ syslog(LOG_NOTICE, "torp_create() - pool_alloc(torps_pool)");
}
/*
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);
torp_destroyed = 1;
-/* $Id: torp.h,v 1.1 2006/12/31 08:32:40 mmondor Exp $ */
+/* $Id: torp.h,v 1.2 2014/06/25 14:25:42 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
-list_t torps_list;
+extern list_t torps_list;