flying items added

origin
stpohle 22 years ago
parent 78215d8046
commit 05a6f1e911

@ -0,0 +1,26 @@
/* $id:$ */
#ifndef _FLYINGITEMS_H_
#define _FLYINGITEMS_H_
/* maximum number of items which are saved in the list */
#define FLITEMS_MAXITEMS 250
struct __flyingitem {
_pointf pos; // current position
_pointf from; // position from where the items comes
_pointf to; // position to where it is going
float step; // step 0.0 is start 1.0 is end position
unsigned char type; // type
struct __flyingitem *next;
} typedef _flyingitem;
extern void flitems_loop ();
extern _flyingitem *flitems_findfree ();
extern void flitems_dropitems (int p_nr, _pointf from, int cnt_speed, int cnt_bombs, int cnt_range);
extern void flitems_draw (_flyingitem *flitem);
extern _flyingitem *flitems_additem (_pointf from, _point to, signed char type);
extern void flitems_reset ();
extern _point flitems_randompos (int p_nr);
#endif

@ -0,0 +1,187 @@
/* $Id: flyingitems.c,v 1.1 2004/01/25 23:02:20 stpohle Exp $ */
#include "bomberclone.h"
#include "flyingitems.h"
_flyingitem flitems [FLITEMS_MAXITEMS];
_flyingitem *flitems_first = NULL;
/* find first free entry */
_flyingitem *flitems_findfree () {
int i;
for (i = 0; i < FLITEMS_MAXITEMS; i++)
if (flitems[i].type == FT_nothing) break;
if (i < FLITEMS_MAXITEMS)
return &flitems[i];
else
return NULL;
};
/* reset all items */
void flitems_reset () {
int i;
for (i = 0; i < FLITEMS_MAXITEMS; i++) {
flitems[i].type = FT_nothing;
flitems[i].next = NULL;
}
flitems_first = NULL;
};
void flitems_loop () {
_flyingitem *flitem = flitems_first;
_flyingitem **old = &flitems_first; // pointer of the preview next pointer
for (; flitem != NULL; flitem = flitem->next) {
flitem->step += (2*timediff);
if (flitem->type == FT_nothing || flitem->step >= 1.0f) {
/* finished delete element and put it on the right place */
if (map.field[(int)flitem->to.x][(int)flitem->to.y].type == FT_nothing)
map.field[(int)flitem->to.x][(int)flitem->to.y].type = flitem->type;
else
map.field[(int)flitem->to.x][(int)flitem->to.y].special = flitem->type;
stonelist_add ((int)flitem->to.x, (int)flitem->to.y);
*old = flitem->next; /* set the preview next pointer to the next element */
flitem->type = FT_nothing;
flitem->next = NULL;
}
else { /* still moving draw item */
stonelist_add (floorf (flitem->pos.x), floorf (flitem->pos.y));
stonelist_add (floorf (flitem->pos.x), floorf (flitem->pos.y)+1);
stonelist_add (floorf (flitem->pos.x)+1, floorf (flitem->pos.y));
stonelist_add (floorf (flitem->pos.x)+1, floorf (flitem->pos.y)+1);
flitem->pos.x = (1.0f - flitem->step) * (flitem->from.x - flitem->to.x) + flitem->to.x;
flitem->pos.y = (1.0f - flitem->step) * (flitem->from.y - flitem->to.y) + flitem->to.y;
flitems_draw (flitem);
old = &flitem->next;
}
}
};
/* add this item into the drop list */
_flyingitem *flitems_additem (_pointf from, _point to, signed char type) {
_flyingitem *flitem = flitems_findfree ();
if (flitem == NULL || type == FT_nothing) {
d_fatal ("flitems_additem: couldn't get any free flyitem \n");
return NULL;
}
/* set the pointers */
flitem->next = flitems_first;
flitems_first = flitem;
flitem->from = from;
flitem->to.x = (float) to.x;
flitem->to.y = (float) to.y;
flitem->step = 0.0f;
flitem->type = type;
flitem->pos = from;
return flitem;
};
/* give us a good position on the field */
_point flitems_randompos (int p_nr) {
int radius = 2, try = 0, maxtry = 0, check;
_point to = { -1, -1 };
do {
/* check that we won't end up in a infinite loop */
try++;
maxtry++;
if (try > 10) {
radius++;
try = 0;
}
/* get a random position */
if (p_nr == -1) { /* get a position on the field */
to.x = s_random (map.size.x -2) + 1;
to.y = s_random (map.size.y -2) + 1;
}
else { /* get a good position for the
* destination of the element */
to.x = s_random (radius*2 + 1) - radius + (int) players[p_nr].pos.x;
to.y = s_random (radius*2 + 1) - radius + (int) players[p_nr].pos.y;
}
/* check if the field is good */
check = (to.x > 0 && to.y > 0 && to.x < map.size.x-1 && to.y < map.size.y-1 &&
(map.field[to.x][to.y].type == FT_nothing
|| (map.field[to.x][to.y].type == FT_stone && map.field[to.x][to.y].special == FT_nothing)));
} while ( !check && maxtry > 200);
if (!check) {
to.x = -1;
to.y = -1;
}
return to;
};
/* a player dropped these items */
void flitems_dropitems (int p_nr, _pointf from, int cnt_speed, int cnt_bombs, int cnt_range) {
int i, lpos = 0;
_point to;
_flyingitem *fiptr[MAX_BOMBS+MAX_RANGE+50];
for (i = 0; i < cnt_speed; i++) {
to = flitems_randompos (p_nr);
if (to.x != -1)
fiptr[lpos++] = flitems_additem (from, to, FT_shoe);
}
for (i = 0; i < cnt_bombs; i++) {
to = flitems_randompos (p_nr);
if (to.x != -1)
fiptr[lpos++] = flitems_additem (from, to, FT_bomb);
}
for (i = 0; i < cnt_range; i++) {
to = flitems_randompos (p_nr);
if (to.x != -1)
fiptr[lpos++] = flitems_additem (from , to, FT_fire);
}
fiptr[lpos] = NULL;
if (GT_MP)
net_game_send_dropitems (p_nr, fiptr, lpos);
};
void flitems_draw (_flyingitem *flitem) {
SDL_Rect src, dest;
SDL_Surface *srci;
if (flitem == NULL || (flitem->type != FT_shoe && flitem->type != FT_fire && flitem->type != FT_bomb))
return;
src.w = dest.w = gfx.block.x;
src.h = dest.h = gfx.block.y;
src.x = 0;
src.y = 0;
dest.x = gfx.offset.x + (gfx.block.x * flitem->pos.x);
dest.y = gfx.offset.y + (gfx.block.y * flitem->pos.y);
srci = gfx.field[flitem->type].image;
gfx_blit (gfx.powerup[0].image, &src, gfx.screen, &dest, (((int)flitems->pos.y + 1.0)*256) + 255);
gfx_blit (srci, &src, gfx.screen, &dest, (((int)flitems->pos.y + 1.0)*256) + 256);
};

@ -75,7 +75,8 @@ do_error (struct pkg_error *data, _net_addr * addr)
*** client sends this to the server if he want's to join
***/
void
do_joingame (struct pkg_joingame *p_jg, _net_addr * addr) {
do_joingame (struct pkg_joingame *p_jg, _net_addr * addr)
{
_player *pl;
int i,
vma,
@ -83,8 +84,7 @@ do_joingame (struct pkg_joingame *p_jg, _net_addr * addr) {
vsu;
char text[255];
d_printf
("do_joingame (From:%s:%s Player(name:%s)\n", addr->host, addr->port, p_jg->name);
d_printf ("do_joingame (From:%s:%s Player(name:%s)\n", addr->host, addr->port, p_jg->name);
sscanf (VERSION, "%d.%d.%d", &vma, &vmi, &vsu);
@ -93,13 +93,13 @@ do_joingame (struct pkg_joingame *p_jg, _net_addr * addr) {
send_error (addr, text);
return;
}
if (GT_MP_PTPS) {
if (GT_MP_PTPS) {
sprintf (text, "Sorry this is a client and not a server.");
send_error (addr, text);
return;
}
/* find a free place for the player and add the player to the game*/
}
/* find a free place for the player and add the player to the game */
if (GS_WAITRUNNING && GT_MP_PTPM) {
/* find free player slot */
if (addr->pl_nr == -1)
@ -141,12 +141,15 @@ do_joingame (struct pkg_joingame *p_jg, _net_addr * addr) {
send_mapinfo (addr);
send_servermode (addr, i);
addr->pl_nr = i;
/* Send all connected players the new PlayerID */
for (i = 0; i < MAX_PLAYERS; i++)
if (i != bman.p_servnr && i != pl->net.addr.pl_nr && PS_IS_netplayer (players[i].state))
send_playerid (&players[i].net.addr, pl->name, pl->net.addr.host, pl->net.addr.port, pl->net.addr.pl_nr, pl->gfx_nr, pl->net.flags);
addr->pl_nr = i;
/* Send all connected players the new PlayerID */
for (i = 0; i < MAX_PLAYERS; i++)
if (i != bman.p_servnr && i != pl->net.addr.pl_nr
&& PS_IS_netplayer (players[i].state))
send_playerid (&players[i].net.addr, pl->name, pl->net.addr.host,
pl->net.addr.port, pl->net.addr.pl_nr, pl->gfx_nr,
pl->net.flags);
}
else if (GS_WAITRUNNING) {
@ -160,21 +163,21 @@ do_joingame (struct pkg_joingame *p_jg, _net_addr * addr) {
}
}
d_playerdetail ("*** PLAYER List ***");
d_playerdetail ("*** PLAYER List ***");
bman.updatestatusbar = 1;
};
void
send_joingame (_net_addr * addr, char *name) {
struct pkg_joingame p_jg;
send_joingame (_net_addr * addr, char *name)
{
struct pkg_joingame p_jg;
int vmi,
vma,
vsu;
d_printf ("send_joingame SendTo: %s:%s (Name:%16s)\n", addr->host,
addr->port, name);
d_printf ("send_joingame SendTo: %s:%s (Name:%16s)\n", addr->host, addr->port, name);
sscanf (VERSION, "%d.%d.%d", &vma, &vmi, &vsu);
p_jg.h.typ = PKG_joingame;
@ -183,13 +186,13 @@ send_joingame (_net_addr * addr, char *name) {
p_jg.ver_sub = vsu;
p_jg.ver_major = vma;
p_jg.ver_minor = vmi;
if (bman.firewall)
p_jg.netflags = NETF_firewall;
else
p_jg.netflags = 0;
strncpy (p_jg.name, bman.playername, LEN_PLAYERNAME);
send_pkg ((struct pkg *)&p_jg, addr);
if (bman.firewall)
p_jg.netflags = NETF_firewall;
else
p_jg.netflags = 0;
strncpy (p_jg.name, bman.playername, LEN_PLAYERNAME);
send_pkg ((struct pkg *) &p_jg, addr);
};
@ -236,18 +239,19 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
pl->points = NTOH16 (p_id->points);
pl->wins = NTOH16 (p_id->wins);
}
/* Send all connected players the new PlayerID */
if (GS_WAITRUNNING && addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS)
net_change_playerid (addr->pl_nr, (GT_MP_PTPM));
/* Send all connected players the new PlayerID */
if (GS_WAITRUNNING && addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS)
net_change_playerid (addr->pl_nr, (GT_MP_PTPM));
}
/* send the whole playerlist to the client to update the playerlist */
else if (p_id->pl_nr == -1 && addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS) {
for (i = 0; i < MAX_PLAYERS; i++)
send_playerid (addr, players[i].name, players[i].net.addr.host,
players[i].net.addr.port, i, players[i].gfx_nr, players[i].net.flags);
}
/* send the whole playerlist to the client to update the playerlist */
else if (p_id->pl_nr == -1 && addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS) {
for (i = 0; i < MAX_PLAYERS; i++)
send_playerid (addr, players[i].name, players[i].net.addr.host,players[i].net.addr.port, i, players[i].gfx_nr, players[i].net.flags);
}
d_playerdetail ("*** PLAYER List ***");
bman.updatestatusbar = 1;
};
@ -270,11 +274,11 @@ send_playerid (_net_addr * addr, char *name, char *pladdr, char *plport,
p_id.h.flags = PKGF_ackreq;
p_id.h.len = HTON16 (sizeof (struct pkg_playerid));
if (name != NULL)
strncpy (p_id.name, name, LEN_PLAYERNAME);
else
p_id.name[0] = 0;
if (name != NULL)
strncpy (p_id.name, name, LEN_PLAYERNAME);
else
p_id.name[0] = 0;
if (pladdr == NULL)
p_id.host[0] = 0;
else
@ -313,46 +317,46 @@ do_servermode (struct pkg_servermode *s_mod, _net_addr * addr)
d_printf ("do_servermode (%s:%s) state = %d\n", addr->host, addr->port, s_mod->state);
/* if we just have connected the bman.p_nr is still -1, so we handle the
servermode packet still alittle diffrent */
if (bman.p_nr == -1) {
d_printf (" Server gave us: p_nr: %d, p_servnr: %d\n", s_mod->p_nr, s_mod->p_servnr);
/* set the p_servnr to the playerslot which is the server */
if (bman.p_servnr != s_mod->p_servnr) {
bman.p_servnr = s_mod->p_servnr;
memcpy (&players[bman.p_servnr].net, &players[0].net, sizeof (_net_player));
}
/* set now the new p_nr number */
if (s_mod->p_nr >= 0 && s_mod->p_nr < MAX_PLAYERS && bman.p_nr == -1) {
bman.p_nr = s_mod->p_nr;
players[bman.p_nr].state &= (0xFF - PSF_net);
strncpy (players[s_mod->p_nr].name, bman.playername, LEN_PLAYERNAME);
}
/* send playerid with p_nr -1 so we get the whole playerlist */
send_playerid (addr, NULL, NULL, NULL, -1, -1, 0);
}
/* the server changed */
if (bman.p_servnr != s_mod->p_servnr) {
// menu_displaymessage ("Server Quit", "FIXME: Server Quit the game and code is not finished");
}
/* do the normal update */
/* if we just have connected the bman.p_nr is still -1, so we handle the
servermode packet still alittle diffrent */
if (bman.p_nr == -1) {
d_printf (" Server gave us: p_nr: %d, p_servnr: %d\n", s_mod->p_nr, s_mod->p_servnr);
/* set the p_servnr to the playerslot which is the server */
if (bman.p_servnr != s_mod->p_servnr) {
bman.p_servnr = s_mod->p_servnr;
memcpy (&players[bman.p_servnr].net, &players[0].net, sizeof (_net_player));
}
/* set now the new p_nr number */
if (s_mod->p_nr >= 0 && s_mod->p_nr < MAX_PLAYERS && bman.p_nr == -1) {
bman.p_nr = s_mod->p_nr;
players[bman.p_nr].state &= (0xFF - PSF_net);
strncpy (players[s_mod->p_nr].name, bman.playername, LEN_PLAYERNAME);
}
/* send playerid with p_nr -1 so we get the whole playerlist */
send_playerid (addr, NULL, NULL, NULL, -1, -1, 0);
}
/* the server changed */
if (bman.p_servnr != s_mod->p_servnr) {
// menu_displaymessage ("Server Quit", "FIXME: Server Quit the game and code is not finished");
}
/* do the normal update */
if (GT_MP_PTPS) {
bman.state = s_mod->state;
bman.gametype = s_mod->gametype;
map.state = s_mod->mapstate;
bman.state = s_mod->state;
bman.gametype = s_mod->gametype;
map.state = s_mod->mapstate;
bman.players_nr_s = s_mod->players;
bman.lastwinner = s_mod->last_winner;
bman.players_nr_s = s_mod->players;
bman.lastwinner = s_mod->last_winner;
map.size.x = s_mod->fieldsize_x;
map.size.y = s_mod->fieldsize_y;
strncpy (map.tileset, s_mod->tileset, LEN_TILESETNAME);
strncpy (map.tileset, s_mod->tileset, LEN_TILESETNAME);
}
bman.updatestatusbar = 1;
@ -363,7 +367,7 @@ void
send_servermode (_net_addr * addr, int pl_nr)
{
struct pkg_servermode s_mod;
s_mod.h.typ = PKG_servermode;
s_mod.h.len = HTON16 (sizeof (struct pkg_servermode));
s_mod.h.flags = PKGF_ackreq;
@ -377,31 +381,31 @@ send_servermode (_net_addr * addr, int pl_nr)
s_mod.players = bman.players_nr_s;
s_mod.maxplayer = bman.maxplayer;
s_mod.p_nr = pl_nr;
s_mod.p_servnr = bman.p_servnr;
s_mod.p_servnr = bman.p_servnr;
s_mod.last_winner = bman.lastwinner;
s_mod.fieldsize_x = map.size.x;
s_mod.fieldsize_y = map.size.y;
strncpy (s_mod.tileset, map.tileset, LEN_TILESETNAME);
switch (s_mod.state) {
case (GS_startup):
d_printf ("Send ServerMode : startup\n");
break;
case (GS_ready):
d_printf ("Send ServerMode : ready\n");
break;
case (GS_running):
d_printf ("Send ServerMode : running\n");
break;
case (GS_quit):
d_printf ("Send ServerMode : quit\n");
break;
case (GS_wait):
d_printf ("Send ServerMode : wait\n");
break;
case (GS_update):
d_printf ("Send ServerMode : wait\n");
break;
}
switch (s_mod.state) {
case (GS_startup):
d_printf ("Send ServerMode : startup\n");
break;
case (GS_ready):
d_printf ("Send ServerMode : ready\n");
break;
case (GS_running):
d_printf ("Send ServerMode : running\n");
break;
case (GS_quit):
d_printf ("Send ServerMode : quit\n");
break;
case (GS_wait):
d_printf ("Send ServerMode : wait\n");
break;
case (GS_update):
d_printf ("Send ServerMode : wait\n");
break;
}
send_pkg ((struct pkg *) &s_mod, addr);
};
@ -414,8 +418,8 @@ void
send_field (_net_addr * addr, int x, int y, _field * field)
{
struct pkg_field f_dat;
int i;
int i;
d_printf ("send_field [%d,%d]\n", x, y);
f_dat.h.typ = PKG_field;
@ -428,16 +432,16 @@ send_field (_net_addr * addr, int x, int y, _field * field)
if (x < 0 || x >= map.size.x || y < 0 || y >= map.size.y)
return;
for (i = 0; i < 4; i++) {
f_dat.ex[i].count = map.field[x][y].ex[i].count;
f_dat.ex[i].frame = (int)map.field[x][y].ex[i].frame;
}
f_dat.type = map.field[x][y].type;
f_dat.mixframe = map.field[x][y].mixframe;
f_dat.special = map.field[x][y].special;
f_dat.frame = HTON16 (FTOI16 (map.field[x][y].frame));
f_dat.ex_nr = HTON32 (map.field[x][y].ex_nr);
for (i = 0; i < 4; i++) {
f_dat.ex[i].count = map.field[x][y].ex[i].count;
f_dat.ex[i].frame = (int) map.field[x][y].ex[i].frame;
}
f_dat.type = map.field[x][y].type;
f_dat.mixframe = map.field[x][y].mixframe;
f_dat.special = map.field[x][y].special;
f_dat.frame = HTON16 (FTOI16 (map.field[x][y].frame));
f_dat.ex_nr = HTON32 (map.field[x][y].ex_nr);
send_pkg ((struct pkg *) &f_dat, addr);
};
@ -445,21 +449,21 @@ send_field (_net_addr * addr, int x, int y, _field * field)
void
do_field (struct pkg_field *f_dat, _net_addr * addr)
{
int i;
int i;
if (addr->pl_nr == -1)
return;
if (f_dat->x < map.size.x && f_dat->y < map.size.y) {
/* convert the fielddata */
map.field[f_dat->x][f_dat->y].type = f_dat->type;
map.field[f_dat->x][f_dat->y].mixframe = f_dat->mixframe;
map.field[f_dat->x][f_dat->y].special = f_dat->special;
for (i = 0; i < 4; i++) {
map.field[f_dat->x][f_dat->y].ex[i].count = f_dat->ex[i].count;
map.field[f_dat->x][f_dat->y].ex[i].frame = f_dat->ex[i].frame;
}
map.field[f_dat->x][f_dat->y].frame = I16TOF (NTOH16 (f_dat->frame));
map.field[f_dat->x][f_dat->y].type = f_dat->type;
map.field[f_dat->x][f_dat->y].mixframe = f_dat->mixframe;
map.field[f_dat->x][f_dat->y].special = f_dat->special;
for (i = 0; i < 4; i++) {
map.field[f_dat->x][f_dat->y].ex[i].count = f_dat->ex[i].count;
map.field[f_dat->x][f_dat->y].ex[i].frame = f_dat->ex[i].frame;
}
map.field[f_dat->x][f_dat->y].frame = I16TOF (NTOH16 (f_dat->frame));
map.field[f_dat->x][f_dat->y].ex_nr = NTOH32 (f_dat->ex_nr);
}
if (bman.state == GS_running)
@ -469,8 +473,7 @@ do_field (struct pkg_field *f_dat, _net_addr * addr)
bman.last_ex_nr = NTOH32 (f_dat->ex_nr);
d_printf ("do_field (%d,%d) ex_nr = %d, special = %d, type = %d\n",
f_dat->x, f_dat->y, NTOH32 (f_dat->ex_nr),
f_dat->special, f_dat->type);
f_dat->x, f_dat->y, NTOH32 (f_dat->ex_nr), f_dat->special, f_dat->type);
};
@ -524,7 +527,7 @@ send_ping (_net_addr * addr, int data, unsigned char typ)
players[addr->pl_nr].net.pingack);
players[addr->pl_nr].net.timestamp = timestamp; /* we need to set it here, so we can check
for the timeout again */
for the timeout again */
};
@ -610,7 +613,7 @@ do_playerdata (struct pkg_playerdata *p_dat, _net_addr * addr)
/* set the state of the player */
if (p_dat->p_nr != bman.p_nr && PS_IS_used (pl->state))
pl->state |= PSF_net;
pl->state |= PSF_net;
else
pl->state &= (0xff - PSF_net);
@ -631,7 +634,8 @@ do_playerdata (struct pkg_playerdata *p_dat, _net_addr * addr)
void
do_ill (struct pkg_ill *ill, _net_addr * addr)
{
int i, old_to;
int i,
old_to;
if (addr->pl_nr == -1)
return;
@ -641,14 +645,15 @@ do_ill (struct pkg_ill *ill, _net_addr * addr)
return;
for (i = 0; i < PI_max; i++) {
old_to = players[ill->pl_nr].ill[i].to;
old_to = players[ill->pl_nr].ill[i].to;
players[ill->pl_nr].ill[i].to = I32TOF (NTOH32 (ill->to[i]));
if (players[ill->pl_nr].ill[i].to <= 0.0f && old_to > 0.0f)
player_clear_ilness (&players[ill->pl_nr], i);
else if (players[ill->pl_nr].ill[i].to > 0.0f && old_to <= 0.0f)
player_set_ilness (&players[ill->pl_nr], i, players[ill->pl_nr].ill[i].to);
d_printf (" to[%d]:%f dataf:%f datai:%d\n",i, players[ill->pl_nr].ill[i].to, players[ill->pl_nr].ill[i].dataf, players[ill->pl_nr].ill[i].datai);
}
if (players[ill->pl_nr].ill[i].to <= 0.0f && old_to > 0.0f)
player_clear_ilness (&players[ill->pl_nr], i);
else if (players[ill->pl_nr].ill[i].to > 0.0f && old_to <= 0.0f)
player_set_ilness (&players[ill->pl_nr], i, players[ill->pl_nr].ill[i].to);
d_printf (" to[%d]:%f dataf:%f datai:%d\n", i, players[ill->pl_nr].ill[i].to,
players[ill->pl_nr].ill[i].dataf, players[ill->pl_nr].ill[i].datai);
}
};
void
@ -686,7 +691,7 @@ send_playermove (_net_addr * addr, int p_nr, _player * pl)
p_dat.m = pl->m;
p_dat.d = pl->d;
p_dat.p_nr = p_nr;
p_dat.speed = HTON16 (FTOI16(pl->speed));
p_dat.speed = HTON16 (FTOI16 (pl->speed));
p_dat.tunnelto = HTON16 (FTOI16 (pl->tunnelto));
send_pkg ((struct pkg *) &p_dat, addr);
@ -724,7 +729,7 @@ void
do_bombdata (struct pkg_bombdata *b_dat, _net_addr * addr)
{
_bomb *bomb;
if (addr->pl_nr == -1)
return;
@ -737,7 +742,7 @@ do_bombdata (struct pkg_bombdata *b_dat, _net_addr * addr)
return; // if there was a bomb let it explose don't delete the bomb
d_printf ("do_bombdata [%f,%f] Player: %d Bomb: %d, ex_nr:%d\n",
I16TOF(NTOH16 (b_dat->x)), I16TOF(NTOH16 (b_dat->y)), b_dat->p_nr,
I16TOF (NTOH16 (b_dat->x)), I16TOF (NTOH16 (b_dat->y)), b_dat->p_nr,
b_dat->b_nr, NTOH32 (b_dat->ex_nr));
bomb = &players[b_dat->p_nr].bombs[b_dat->b_nr];
@ -751,17 +756,17 @@ do_bombdata (struct pkg_bombdata *b_dat, _net_addr * addr)
d_printf ("do_bombdata WARNING : bomb explosion haven't finished\n");
if (bomb->state != BS_off) { // handle push & kick special
map.bfield[(int)bomb->pos.x][(int)bomb->pos.y] = 0; //remove bomb at old location
map.bfield[(int) bomb->pos.x][(int) bomb->pos.y] = 0; //remove bomb at old location
stonelist_add (bomb->pos.x, bomb->pos.y);
stonelist_add (bomb->pos.x+1, bomb->pos.y);
stonelist_add (bomb->pos.x, bomb->pos.y+1);
stonelist_add (bomb->pos.x+1, bomb->pos.y+1);
stonelist_add (bomb->pos.x + 1, bomb->pos.y);
stonelist_add (bomb->pos.x, bomb->pos.y + 1);
stonelist_add (bomb->pos.x + 1, bomb->pos.y + 1);
}
if (bomb->state == BS_off && (b_dat->state == BS_ticking || b_dat->state == BS_trigger))
snd_play (SND_bombdrop);
/* convert position back to float */
/* convert position back to float */
bomb->pos.x = I16TOF (NTOH16 (b_dat->x));
bomb->pos.y = I16TOF (NTOH16 (b_dat->y));
@ -770,7 +775,7 @@ do_bombdata (struct pkg_bombdata *b_dat, _net_addr * addr)
to make sure the timeout won't be resetted
by an old network packet */
map.bfield[(int)bomb->pos.x][(int)bomb->pos.y] = 1; // keep the bfield up to date
map.bfield[(int) bomb->pos.x][(int) bomb->pos.y] = 1; // keep the bfield up to date
bomb->r = b_dat->r;
bomb->ex_nr = NTOH32 (b_dat->ex_nr);
@ -830,10 +835,10 @@ do_tunneldata (struct pkg_tunneldata *tun_pkg, _net_addr * addr)
players[addr->pl_nr].net.net_istep = 3;
}
else if (addr->pl_nr == bman.p_servnr && tun_pkg->tunnel_nr < GAME_MAX_TUNNELS) {
map.tunnel[tun_pkg->tunnel_nr].x = NTOH16 (tun_pkg->target.x);
map.tunnel[tun_pkg->tunnel_nr].x = NTOH16 (tun_pkg->target.x);
map.tunnel[tun_pkg->tunnel_nr].y = NTOH16 (tun_pkg->target.y);
players[bman.p_nr].net.net_status = tun_pkg->tunnel_nr;
}
}
};
/* send a tunneldata request (x && y == -1) or send tunneldata */
@ -862,7 +867,7 @@ send_tunneldata (_net_addr * addr, int tunnelnr, int x, int y)
*** Packettype: quit
***/
void
send_quit (_net_addr * addr, char *plhost, char * plport)
send_quit (_net_addr * addr, char *plhost, char *plport)
{
struct pkg_quit q_dat;
@ -968,8 +973,8 @@ send_fieldline (_net_addr * addr, int line)
map.field[i][line].ex_nr = 0;
for (j = 0; j < 4; j++) {
map.field[i][line].ex[j].frame = 0.0f;
map.field[i][line].ex[j].count = 0;
}
map.field[i][line].ex[j].count = 0;
}
}
send_pkg ((struct pkg *) &f_dat, addr);
};
@ -984,7 +989,7 @@ do_fieldline (struct pkg_fieldline *f_dat, _net_addr * addr)
if (addr->pl_nr == -1)
return;
if (addr->pl_nr != bman.p_servnr ) {
if (addr->pl_nr != bman.p_servnr) {
/* the data we have got are not from the server */
d_printf ("do_fieldline: the data we have got are not from the server\n");
return;
@ -1004,8 +1009,8 @@ do_fieldline (struct pkg_fieldline *f_dat, _net_addr * addr)
map.field[i][f_dat->line].frame = 0.0f;
for (d = 0; d < 4; d++) {
map.field[i][f_dat->line].ex[d].frame = 0.0f;
map.field[i][f_dat->line].ex[d].count = 0;
}
map.field[i][f_dat->line].ex[d].count = 0;
}
}
};
@ -1017,7 +1022,7 @@ void
send_getplayerdata (_net_addr * addr, int pl)
{
struct pkg_getplayerdata gp_dat;
gp_dat.h.typ = PKG_getplayerdata;
gp_dat.h.len = HTON16 (sizeof (struct pkg_getplayerdata));
gp_dat.pl_nr = pl;
@ -1100,8 +1105,7 @@ send_playerstatus (_net_addr * addr, int pl_nr, int net_istep, int status)
void
do_chat (struct pkg_chat *chat_pkg, _net_addr * addr)
{
d_printf ("do_chat (%s:%s) %d Text:%s\n", addr->host,
addr->port, addr->pl_nr, chat_pkg->text);
d_printf ("do_chat (%s:%s) %d Text:%s\n", addr->host, addr->port, addr->pl_nr, chat_pkg->text);
chat_addline (chat_pkg->text);
};
@ -1158,45 +1162,50 @@ do_pkgack (struct pkg_pkgack *p_ack, _net_addr * addr)
*** Packettype: dropitems
*** send a generated list of drop items
***/
void send_dropitems (_net_addr *addr, int pl_nr, _flyingitem **fitems, int cnt) {
char outdata[BUF_SIZE]; // this should be enough memory for the outgoin data
struct pkg_dropitem *dipkg = (struct pkg_dropitem *) outdata; // set the pointer to outdata
int i;
dipkg->h.typ = PKG_dropitem;
dipkg->h.len = HTON16 (sizeof (struct pkg_dropitem) + cnt*sizeof (struct pkgdropitemelemt));
dipkg->h.flags = PKGF_ackreq;
dipkg->pl_nr = pl_nr;
dipkg->from.x = HTON16 (FTOI16 (players[pl_nr].pos.x));
dipkg->from.y = HTON16 (FTOI16 (players[pl_nr].pos.y));
dipkg->count = cnt;
for (i = 0; (i < cnt && fitems[i] != NULL); i++) {
dipkg->items[i].x = (int)fitems[i]->to.x;
dipkg->items[i].y = (int)fitems[i]->to.y;
dipkg->items[i].typ = (int)fitems[i]->type;
}
send_pkg ((struct pkg*)dipkg, addr);
void
send_dropitems (_net_addr * addr, int pl_nr, _flyingitem ** fitems, int cnt)
{
char outdata[BUF_SIZE]; // this should be enough memory for the outgoin data
struct pkg_dropitem *dipkg = (struct pkg_dropitem *) outdata; // set the pointer to outdata
int i;
dipkg->h.typ = PKG_dropitem;
dipkg->h.len = HTON16 (sizeof (struct pkg_dropitem) + cnt * sizeof (struct pkgdropitemelemt));
dipkg->h.flags = PKGF_ackreq;
dipkg->pl_nr = pl_nr;
dipkg->from.x = HTON16 (FTOI16 (players[pl_nr].pos.x));
dipkg->from.y = HTON16 (FTOI16 (players[pl_nr].pos.y));
dipkg->count = cnt;
for (i = 0; (i < cnt && fitems[i] != NULL); i++) {
dipkg->items[i].x = (int) fitems[i]->to.x;
dipkg->items[i].y = (int) fitems[i]->to.y;
dipkg->items[i].typ = (int) fitems[i]->type;
}
send_pkg ((struct pkg *) dipkg, addr);
};
void do_dropitems (struct pkg_dropitem *di_pkg, _net_addr *addr) {
int i;
_pointf from;
_point to;
void
do_dropitems (struct pkg_dropitem *di_pkg, _net_addr * addr)
{
int i;
_pointf from;
_point to;
d_printf ("do_dropitems from:%d (pl_nr %d, cnt %d)\n", addr->pl_nr, di_pkg->pl_nr, di_pkg->count);
d_printf ("do_dropitems from:%d (pl_nr %d, cnt %d)\n", addr->pl_nr, di_pkg->pl_nr,
di_pkg->count);
if (addr->pl_nr == -1)
return;
from.x = I16TOF (NTOH16 (di_pkg->from.x));
from.y = I16TOF (NTOH16 (di_pkg->from.y));
for (i = 0; i < di_pkg->count; i++) {
to.x = di_pkg->items[i].x;
to.y = di_pkg->items[i].y;
flitems_additem (from, to, di_pkg->items[i].typ);
}
from.x = I16TOF (NTOH16 (di_pkg->from.x));
from.y = I16TOF (NTOH16 (di_pkg->from.y));
for (i = 0; i < di_pkg->count; i++) {
to.x = di_pkg->items[i].x;
to.y = di_pkg->items[i].y;
flitems_additem (from, to, di_pkg->items[i].typ);
}
};
@ -1261,18 +1270,18 @@ send_mapinfo (_net_addr * addr)
map_pkg.sp_trigger = map.sp_trigger;
map_pkg.sp_row = map.sp_row;
map_pkg.sp_push = map.sp_push;
map_pkg.start_bombs = bman.start_bombs;
map_pkg.start_range = bman.start_range;
sprintf (map_pkg.start_speed, "%6f", bman.start_speed);
sprintf (map_pkg.bomb_tickingtime, "%6f", bman.bomb_tickingtime);
map_pkg.start_bombs = bman.start_bombs;
map_pkg.start_range = bman.start_range;
sprintf (map_pkg.start_speed, "%6f", bman.start_speed);
sprintf (map_pkg.bomb_tickingtime, "%6f", bman.bomb_tickingtime);
if (map.random_tileset)
map_pkg.tileset[0] = 0;
else
strcpy (map_pkg.tileset, map.tileset);
map_pkg.map_selection = map.map_selection;
strcpy (map_pkg.mapname, map.map);
d_printf ("send_mapinfo: Tileset: %s\n", map.tileset);
d_printf ("send_mapinfo: Tileset: %s\n", map.tileset);
send_pkg ((struct pkg *) &map_pkg, addr);
};
@ -1306,11 +1315,11 @@ do_mapinfo (struct pkg_mapinfo *map_pkg, _net_addr * addr)
map.sp_trigger = map_pkg->sp_trigger;
map.sp_push = map_pkg->sp_push;
map.sp_row = map_pkg->sp_row;
bman.start_bombs = map_pkg->start_bombs;
bman.start_range = map_pkg->start_range;
sscanf (map_pkg->start_speed, "%f", &bman.start_speed);
sscanf (map_pkg->bomb_tickingtime, "%f", &bman.bomb_tickingtime);
bman.start_bombs = map_pkg->start_bombs;
bman.start_range = map_pkg->start_range;
sscanf (map_pkg->start_speed, "%f", &bman.start_speed);
sscanf (map_pkg->bomb_tickingtime, "%f", &bman.bomb_tickingtime);
};
@ -1349,10 +1358,10 @@ inpkg_check (unsigned char typ, short int id, _net_addr * addr)
void
send_pkg (struct pkg *packet, _net_addr * addr)
{
/* if the packet would be send to the ai player so ignore it */
if (PS_IS_aiplayer (players[addr->pl_nr].state))
return;
/* if the packet would be send to the ai player so ignore it */
if (PS_IS_aiplayer (players[addr->pl_nr].state))
return;
packet->h.id = HTON16 (pkg_lastid++);
if (bman.net_ai_family != PF_INET)
packet->h.flags = packet->h.flags | PKGF_ipv6;
@ -1396,7 +1405,7 @@ int
do_pkg (struct pkg *packet, _net_addr * addr)
{
if (((packet->h.flags & PKGF_ipv6) == 0 && bman.net_ai_family != PF_INET)
|| ((packet->h.flags & PKGF_ipv6) != 0 && bman.net_ai_family == PF_INET)) {
|| ((packet->h.flags & PKGF_ipv6) != 0 && bman.net_ai_family == PF_INET)) {
d_printf ("do_pkg: packet comes from the wrong network type\n");
return 0;
}

Loading…
Cancel
Save