-# $Id: GNUmakefile,v 1.2 2014/06/19 18:22:03 mmondor Exp $
+# $Id: GNUmakefile,v 1.3 2014/06/21 17:16:32 mmondor Exp $
CC := cc
RM := rm
Z_CFLAGS := -I/usr/local/include
Z_LDFLAGS := -lz
+LDFLAGS += -lm
+
# OS dependent settings follow
OS := $(shell $(UNAME) -s)
ifneq (,$(findstring CYGWIN,$(OS)))
# GL_LDFLAGS := -lopengl32 -lglu32
else
# unix
- CFLAGS += -I/usr/include -I/usr/pkg/include -I/usr/X11R6/include
- LDFLAGS += -L/usr/lib -L/usr/pkg/lib -L/usr/X11R6/lib
+ CFLAGS += -I/usr/include -I/usr/pkg/include -I/usr/X11R7/include
+ LDFLAGS += -L/usr/lib -L/usr/pkg/lib -L/usr/X11R7/lib
# GL_CFLAGS :=
# GL_LDFLAGS := -lGL -lGLU
endif
#CFLAGS += $(SDL_CFLAGS) $(GL_CFLAGS)
#LDFLAGS += $(SDL_LDFLAGS) $(GL_LDFLAGS)
CFLAGS += $(SDL_CFLAGS) $(Z_CFLAGS)
-LDFLAGS += $(SDL_LDFLAGS) $(Z_LDFLAGS)
+LDFLAGS += $(SDL_LDFLAGS) $(Z_LDFLAGS) -lm
all: $(BIN)
$(BIN): $(OBJS) $(RAWOBJS)
$(CC) -o $@ $(OBJS) $(RAWOBJS) $(LDFLAGS)
+# $(CC) -o $@ -static $(OBJS) $(RAWOBJS) $(LDFLAGS) -lc -lm -lossaudio -L/usr/X11R7/lib/X11/locale/lib/common/ -lxlibi18n -lximcp -lxlcDef -lxlcUTF8Load -lxlocale -lxomGeneric -lX11 -lxcb -lXau -lXdmcp -lXext -lXrandr -lXrender -lusbhid -lpthread -lSDL -lSDL_image -lSDL_mixer -lSDL_net -lSDL_gfx -lz
$(STRIP) -s -w -R .comment -R .ident -R .debug* $@*
clean:
-/* $Id: conf.h,v 1.2 2014/06/19 18:22:03 mmondor Exp $ */
+/* $Id: conf.h,v 1.3 2014/06/21 17:16:32 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
* Various hardcoded configuration parameters.
*/
-#define SERVER_HOST "192.168.1.15"
-/*#define SERVER_HOST "tms-play.pulsar-zone.net"*/
-
+#define SERVER_HOST "mmondor.pulsar-zone.net"
#define SERVER_PORT 7777
#define CLIENT_VERSION 1
-/* $Id: main.c,v 1.2 2014/06/19 19:53:34 mmondor Exp $ */
+/* $Id: main.c,v 1.3 2014/06/21 17:16:32 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
* We should display a "connecting to server" or such message to the
* user during this time.
*/
+ font_blit_string(font, 16, 16,
+ "Connecting to server, press [SPACE] to abort.",
+ 0x00, 0xff, 0x00, 0xff);
{
struct msg_connect *cmsg;
}
void
-ship_draw(int id, int x, int y, double angle, uint8_t flags)
+ship_draw(int id, int x, int y, int radius, double angle, uint8_t flags)
{
char str[8];
filledCircleRGBA(screen_surface, x, y, 25,
0x00, 0x00, 0x00, 0x80);
if ((flags & SHIPF_SHIELD) != 0) {
- aacircleRGBA(screen_surface, x, y, 25,
+ aacircleRGBA(screen_surface, x, y, radius,
0xf0, 0xf0, 0x20, 0xb0);
- filledCircleRGBA(screen_surface, x, y, 25,
+ filledCircleRGBA(screen_surface, x, y, radius,
0x20, 0x50, 0xf0, 0x50);
}
- x -= 24;
- y -= 24;
+ x -= radius;
+ y -= radius;
(void) snprintf(str, 8, "%d", id);
font_blit_string(font, x, y, str, 0x00, 0x00, 0x00, 0xff);
font_blit_string(font, x + 1, y + 1, str, 0xff, 0xff, 0xff, 0xff);
-/* $Id: main.h,v 1.1 2006/12/31 08:32:39 mmondor Exp $ */
+/* $Id: main.h,v 1.2 2014/06/21 17:16:32 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
void frame_switch(void);
-void ship_draw(int, int, int, double, uint8_t);
+void ship_draw(int, int, int, int, double, uint8_t);
void torp_draw(int, int, int);
-/* $Id: packets.c,v 1.1 2006/12/31 08:32:39 mmondor Exp $ */
+/* $Id: packets.c,v 1.2 2014/06/21 17:16:32 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
p->x = BYTEORDER_HOST16(p->x);
p->y = BYTEORDER_HOST16(p->y);
- ship_draw(p->id, p->x, p->y, p->angle, p->flags);
+ ship_draw(p->id, p->x, p->y, p->radius, p->angle, p->flags);
return 0;
}
-/* $Id: packets_common.h,v 1.2 2014/06/19 18:22:03 mmondor Exp $ */
+/* $Id: packets_common.h,v 1.3 2014/06/21 17:16:32 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
int8_t flags;
int16_t id;
int16_t x, y;
+ uint8_t radius;
uint8_t angle;
} __attribute__((__packed__));
-/* $Id: packets.c,v 1.2 2014/06/19 18:22:03 mmondor Exp $ */
+/* $Id: packets.c,v 1.3 2014/06/21 17:16:32 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
void
packets_update(void)
{
- client_t *c, *next;
+ client_t *c, *next, *c2, *next2;
uint8_t *data;
size_t size, off, len;
if (c->todestroy || c->toclose)
continue;
+ /* Check for ship/ship collisions */
+ for (c2 = (client_t *)DLIST_TOP(&clients_list); c2 != NULL;
+ c2 = next2) {
+ next2 = DLIST_NEXT((node_t *)c2);
+ if (c2 != c) {
+ ship_t *s1 = &c->ship, *s2 = &c2->ship;
+ int x1 = s1->x, y1 = s1->y,
+ r1 = s1->ship->radius,
+ x2 = s2->x, y2 = s2->y,
+ r2 = s2->ship->radius;
+
+ if (square_intersect(x1, y1, r1, x2, y2, r2) &&
+ circle_intersect(x1, y1, r1, x2, y2, r2)) {
+ if (ship_hit_ship(s1, s2)) {
+ client_destroy_mark(c);
+ client_destroy_mark(c2);
+ }
+ break;
+ }
+ }
+ }
+ if (c->todestroy)
+ continue;
+
/* Reset ping request throttling flag */
c->askedping = 0;
p.id = BYTEORDER_NETWORK16(id);
p.x = BYTEORDER_NETWORK16(s->x);
p.y = BYTEORDER_NETWORK16(s->y);
+ p.radius = (uint8_t)s->ship->radius;
p.angle = (uint8_t)s->angle;
return client_write(c, (uint8_t *)&p, sizeof(p), 1);
-/* $Id: ships.c,v 1.1 2006/12/31 08:32:40 mmondor Exp $ */
+/* $Id: ships.c,v 1.2 2014/06/21 17:16:32 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
1.0, /* Hull regen */
100.0, /* Shield max */
10.0, /* Shield cost */
- 3.0, /* Shield regen */
+ 2.0, /* Shield regen */
50.0, /* Cloak cost */
10000.0, /* Fuel max */
30.0, /* Fuel regen */
6.0, /* Thrust cost */
80/*2.0*/, /* Turn thrust */
0.5, /* Turn cost */
- 100.0, /* Torp cost */
- 90.0, /* Torp damage */
+ 200.0, /* Torp cost */
+ 20.0, /* Torp damage */
2.0, /* Torp radius */
11.0, /* Torp speed */
60, /* Torp life */
1.0, /* Turn thrust */
0.5, /* Turn cost */
90.0, /* Torp cost */
- 90.0, /* Torp damage */
+ 20.0, /* Torp damage */
3.0, /* Torp radius */
12.0, /* Torp speed */
60, /* Torp life */
i = ((int)s->thrust) + 1;
s->x = VECTOR_X(s->x, s->angle, i);
s->y = VECTOR_Y(s->y, s->angle, i);
- /* XXX Observe world limits and block/bounce */
+ /* Observe world limits and block/bounce */
+ /* XXX Should use ship radius trigonometrically */
if (s->x < r || s->x > WORLD_X_MAX - r - 1 ||
s->y < r || s->y > WORLD_Y_MAX - r - 1) {
s->x = ox;
} else
s->cloak_on = 0;
}
+
+int
+ship_hit_torp(ship_t *s, shipdesc_t *tsd)
+{
+
+ /* XXX */
+ if (s->shield_on) {
+ s->shield -= tsd->torp_damage;
+ if (s->shield <= 0) {
+ s->hull += s->shield;
+ s->shield = 0.0;
+ s->shield_on = 0;
+ } else
+ return 0;
+ } else
+ s->hull -= tsd->torp_damage;
+ if (s->hull <= 0) {
+ s->hull = 0.0;
+ return 1;
+ }
+
+ return 0;
+}
+
+int
+ship_hit_ship(ship_t *s1, ship_t *s2)
+{
+
+ if (s1->cloak_on || s2->cloak_on)
+ return 0;
+
+ /* XXX */
+
+ return 1;
+}
+
-/* $Id: ships.h,v 1.1 2006/12/31 08:32:40 mmondor Exp $ */
+/* $Id: ships.h,v 1.2 2014/06/21 17:16:32 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
SHIP_MAX
};
-struct shipdesc {
+typedef struct shipdesc {
double radius;
double weight;
double hull_max, hull_regen;
int torp_life;
double phaser_cost, phaser_damage, phaser_recharge,
phaser_radius;
-};
+} shipdesc_t;
typedef struct ship {
- struct shipdesc *ship;
+ shipdesc_t *ship;
double hull;
double shield;
double fuel;
void ship_init(ship_t *, int);
void ship_update(ship_t *);
-
+int ship_hit_torp(ship_t *, shipdesc_t *);
+int ship_hit_ship(ship_t *, ship_t *);
extern struct shipdesc ships[SHIP_MAX];
-/* $Id: torp.c,v 1.1 2006/12/31 08:32:40 mmondor Exp $ */
+/* $Id: torp.c,v 1.2 2014/06/21 17:16:32 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
#include <torp.h>
#include <trigonometry.h>
+#include <client.h>
+#include <ships.h>
#include <conf.h>
void
torp_create(client_t *c, int angle)
{
- torp_t *t;
+ torp_t *t;
+ ship_t *s = &c->ship;
+ shipdesc_t *sd = s->ship;
- if (c->ship.torps > 15)
+ if (s->cloak_on)
+ return;
+ if (s->torps > 15)
return;
- if (c->ship.fuel < c->ship.ship->torp_cost)
+ if (s->fuel < sd->torp_cost)
return;
- c->ship.fuel -= c->ship.ship->torp_cost;
+ s->fuel -= sd->torp_cost;
if ((t = (torp_t *)pool_alloc(&torps_pool, FALSE)) != NULL) {
- int r = c->ship.ship->torp_radius;
+ int tr = sd->torp_radius,
+ sr = sd->radius + sd->torp_speed + 5;
t->client = c;
- t->life = t->client->ship.ship->torp_life;
+ t->life = sd->torp_life;
t->angle = angle;
- t->x = VECTOR_X(c->ship.x, angle, c->ship.ship->radius);
- t->y = VECTOR_Y(c->ship.y, angle, c->ship.ship->radius);
- if (t->x < r)
- t->x = r;
- if (t->y < r)
- t->y = r;
- if (t->x > WORLD_X_MAX - 1 - r)
- t->x = WORLD_X_MAX - 1 - r;
- if (t->y > WORLD_Y_MAX - 1 - r)
- t->x = WORLD_Y_MAX - 1 - r;
- c->ship.torps++;
+ t->x = VECTOR_X(s->x, angle, sr + tr);
+ t->y = VECTOR_Y(s->y, angle, sr + tr);
+ if (t->x < tr)
+ t->x = tr;
+ if (t->y < tr)
+ t->y = tr;
+ if (t->x > WORLD_X_MAX - 1 - tr)
+ t->x = WORLD_X_MAX - 1 - tr;
+ if (t->y > WORLD_Y_MAX - 1 - tr)
+ t->x = WORLD_Y_MAX - 1 - tr;
+ s->torps++;
DLIST_APPEND(&torps_list, (node_t *)t);
} else
syslog(LOG_NOTICE, "torp_create() - pool_alloc(torps_list)");
for (t = (torp_t *)DLIST_TOP(&torps_list); t != NULL; t = next) {
next = DLIST_NEXT((node_t *)t);
+ client_t *c, *cnext;
+ shipdesc_t *tsd = t->client->ship.ship;
+ int tx = t->x, ty = t->y,
+ tr = tsd->torp_radius,
+ torp_destroyed = 0;
+
+ /* Verify for torp/ship collisions */
+ for (c = (client_t *)DLIST_TOP(&clients_list); c != NULL; c = cnext) {
+ cnext = DLIST_NEXT((node_t *)c);
+ ship_t *s = &c->ship;
+ int sx = s->x, sy = s->y, sr = s->ship->radius;
+
+ if (square_intersect(tx, ty, tr, sx, sy, sr) &&
+ circle_intersect(tx, ty, tr, sx, sy, sr)) {
+ if (ship_hit_torp(s, tsd))
+ client_destroy_mark(c);
+ torp_destroyed = 1;
+ continue;
+ }
+ }
+ if (torp_destroyed) {
+ torp_destroy(t);
+ continue;
+ }
if (--(t->life) == 0) {
torp_destroy(t);
ox = t->x;
oy = t->y;
- s = t->client->ship.ship->torp_speed;
- r = t->client->ship.ship->torp_radius;
+ s = tsd->torp_speed;
+ r = tsd->torp_radius;
t->x = VECTOR_X(t->x, t->angle, s);
t->y = VECTOR_Y(t->y, t->angle, s);
t->x += (-4 + (random() % 8));
-/* $Id: trigonometry.c,v 1.1 2006/12/31 08:32:40 mmondor Exp $ */
+/* $Id: trigonometry.c,v 1.2 2014/06/21 17:16:32 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
#include <math.h>
+#include <stdlib.h>
#include <mmlog.h>
* Should we be told via another parameter the relative angle of
* the object we had collision with? Or the direction?
*/
+ /*
return ((angle + 128) & 0xff);
+ */
+ /* XXX Debugging */
+ return (random() % 256);
+}
+
+inline int
+square_intersect(int x1, int y1, int r1, int x2, int y2, int r2)
+{
+
+ return (x1 + r1 >= x2 - r2 && x1 - r1 <= x2 + r2 &&
+ y1 + r1 >= y2 - r2 && y1 - r1 <= y2 + r2);
}
+
+inline int
+circle_intersect(int x1, int y1, int r1, int x2, int y2, int r2)
+{
+ int dx = x2 - x1, dy = y2 - y1,
+ ms = (dx * dx) + (dy * dy), /* sqrt(dx * dx + dy * dy) */
+ mr = r1 + r2;
+
+ return (ms < mr * mr); /* ms < r1 + r2 */
+}
+
-/* $Id: trigonometry.h,v 1.1 2006/12/31 08:32:40 mmondor Exp $ */
+/* $Id: trigonometry.h,v 1.2 2014/06/21 17:16:32 mmondor Exp $ */
/*
* Copyright (c) 2006, Matthew Mondor
void trigonometry_init(void);
int angle_bounce(int);
-
-
+inline int square_intersect(int, int, int, int, int, int);
+inline int circle_intersect(int, int, int, int, int, int);
extern double sin_table[256], cos_table[256];