diff --git a/include/network.h b/include/network.h index 7807d24..1419b5e 100644 --- a/include/network.h +++ b/include/network.h @@ -1,8 +1,9 @@ -/* $Id: network.h,v 1.10 2004/01/22 20:55:23 stpohle Exp $ +/* $Id: network.h,v 1.11 2004/01/25 20:32:41 stpohle Exp $ * network.h file... for everything what have to do with the network stuff */ #include +#include "flyingitems.h" #ifndef _NETWORK_H_ #define _NETWORK_H_ @@ -108,6 +109,7 @@ extern void net_game_send_playermove (int p_nr, int mustsend); extern void net_game_send_bomb (int p, int b); extern void net_game_send_field (int x, int y); extern void net_game_send_special (int pl_nr, int ex_nr); +extern void net_game_send_dropitems (int pl_nr, _flyingitem **fiptr, int cnt); extern void net_game_fillsockaddr (); extern void net_game_send_ill (int p_nr); extern void net_delplayer (int pl_nr); diff --git a/include/packets.h b/include/packets.h index c77d421..2b1239d 100644 --- a/include/packets.h +++ b/include/packets.h @@ -42,12 +42,6 @@ struct pkgheader { }; -struct pkgitem { - signed char x; - signed char y; - unsigned char typ; -}; - struct pkg { struct pkgheader h; char data[0]; @@ -80,12 +74,18 @@ struct pkg_ping { }; +struct pkgdropitemelemt { + signed char x; + signed char y; + unsigned char typ; +}; + struct pkg_dropitem { struct pkgheader h; _point from; // from where the items are coming - signed char p_nr; // playernumber -1 if the server jsut dropped something + signed char pl_nr; // playernumber -1 if the server jsut dropped something unsigned char count; // number of elements - struct pkgitem items[0]; // elements + struct pkgdropitemelemt items[0]; // elements }; @@ -344,7 +344,7 @@ extern void send_ill (_net_addr *addr, int p_nr, _player *pl); extern void send_special (_net_addr *addr, int p_nr, int typ, int ex_nr); extern void send_mapinfo (_net_addr *addr); extern void send_tunneldata (_net_addr *addr, int tunnelnr, int x, int y); -extern void send_dropitems (_net_addr *addr, int pl_nr, _flyingitem **fitems); +extern void send_dropitems (_net_addr *addr, int pl_nr, _flyingitem **fitems, int cnt); extern void fwd_pkg (struct pkg *packet, _net_addr *addr); diff --git a/src/game.c b/src/game.c index 98e9413..ef24246 100644 --- a/src/game.c +++ b/src/game.c @@ -1,4 +1,4 @@ -/* $Id: game.c,v 1.70 2004/01/25 19:36:48 stpohle Exp $ +/* $Id: game.c,v 1.71 2004/01/25 20:32:45 stpohle Exp $ game.c - procedures for the game. */ #include @@ -209,12 +209,6 @@ game_loop () bman.updatestatusbar = 1; // force an update } - /* only for testing */ - if (keys[SDLK_F7] && event.type == SDL_KEYDOWN) { - /* test for a random drop */ - flitems_dropitems (bman.p_nr, players[bman.p_nr].pos, 1, 0, 0); - } - if (keys[SDLK_F9] && event.type == SDL_KEYDOWN) { /* Switch Fullscreen */ debug = !debug; diff --git a/src/network.c b/src/network.c index 5a6c040..ad3ed42 100644 --- a/src/network.c +++ b/src/network.c @@ -1,4 +1,4 @@ -/* $Id: network.c,v 1.54 2004/01/06 19:52:02 stpohle Exp $ */ +/* $Id: network.c,v 1.55 2004/01/25 20:32:45 stpohle Exp $ */ /* network routines. */ @@ -732,6 +732,20 @@ net_game_send_ill (int p_nr) }; + +/* send to all players the drop item list */ +void net_game_send_dropitems (int pl_nr, _flyingitem **fiptr, int cnt) { + int i; + + d_printf ("net_game_send_dropitems (%d): %d items droppped\n", pl_nr, cnt); + + for (i = 0; i < MAX_PLAYERS; i++) + if ((!PS_IS_aiplayer (players[i].state)) && PS_IS_netplayer (players[i].state) && i != bman.p_nr && NET_CANSEND(i)) + send_dropitems (&players[i].net.addr, pl_nr, fiptr, cnt); +}; + + + /* this routine will set up some things for the network game after this the data should be transfered to the other clients. diff --git a/src/packets.c b/src/packets.c index 8fc6eb1..e0759bb 100644 --- a/src/packets.c +++ b/src/packets.c @@ -1154,6 +1154,53 @@ 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 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); + 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); + } +}; + + + /*** *** Packettype: special *** moves/bombs... whatever will be send as we use it @@ -1444,6 +1491,9 @@ do_pkg (struct pkg *packet, _net_addr * addr) case (PKG_joingame): do_joingame ((struct pkg_joingame *) packet, addr); break; + case (PKG_dropitem): + do_dropitems ((struct pkg_dropitem *) packet, addr); + break; default: send_error (addr, "BomberClone: unknown data packet"); break;