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 *** client sends this to the server if he want's to join
***/ ***/
void void
do_joingame (struct pkg_joingame *p_jg, _net_addr * addr) { do_joingame (struct pkg_joingame *p_jg, _net_addr * addr)
{
_player *pl; _player *pl;
int i, int i,
vma, vma,
@ -83,8 +84,7 @@ do_joingame (struct pkg_joingame *p_jg, _net_addr * addr) {
vsu; vsu;
char text[255]; char text[255];
d_printf d_printf ("do_joingame (From:%s:%s Player(name:%s)\n", addr->host, addr->port, p_jg->name);
("do_joingame (From:%s:%s Player(name:%s)\n", addr->host, addr->port, p_jg->name);
sscanf (VERSION, "%d.%d.%d", &vma, &vmi, &vsu); sscanf (VERSION, "%d.%d.%d", &vma, &vmi, &vsu);
@ -99,7 +99,7 @@ do_joingame (struct pkg_joingame *p_jg, _net_addr * addr) {
return; 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) { if (GS_WAITRUNNING && GT_MP_PTPM) {
/* find free player slot */ /* find free player slot */
if (addr->pl_nr == -1) if (addr->pl_nr == -1)
@ -145,8 +145,11 @@ do_joingame (struct pkg_joingame *p_jg, _net_addr * addr) {
/* Send all connected players the new PlayerID */ /* Send all connected players the new PlayerID */
for (i = 0; i < MAX_PLAYERS; i++) for (i = 0; i < MAX_PLAYERS; i++)
if (i != bman.p_servnr && i != pl->net.addr.pl_nr && PS_IS_netplayer (players[i].state)) if (i != bman.p_servnr && i != pl->net.addr.pl_nr
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); && 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) { else if (GS_WAITRUNNING) {
@ -166,14 +169,14 @@ do_joingame (struct pkg_joingame *p_jg, _net_addr * addr) {
void void
send_joingame (_net_addr * addr, char *name) { send_joingame (_net_addr * addr, char *name)
{
struct pkg_joingame p_jg; struct pkg_joingame p_jg;
int vmi, int vmi,
vma, vma,
vsu; vsu;
d_printf ("send_joingame SendTo: %s:%s (Name:%16s)\n", addr->host, d_printf ("send_joingame SendTo: %s:%s (Name:%16s)\n", addr->host, addr->port, name);
addr->port, name);
sscanf (VERSION, "%d.%d.%d", &vma, &vmi, &vsu); sscanf (VERSION, "%d.%d.%d", &vma, &vmi, &vsu);
@ -189,7 +192,7 @@ send_joingame (_net_addr * addr, char *name) {
p_jg.netflags = 0; p_jg.netflags = 0;
strncpy (p_jg.name, bman.playername, LEN_PLAYERNAME); strncpy (p_jg.name, bman.playername, LEN_PLAYERNAME);
send_pkg ((struct pkg *)&p_jg, addr); send_pkg ((struct pkg *) &p_jg, addr);
}; };
@ -245,7 +248,8 @@ do_playerid (struct pkg_playerid *p_id, _net_addr * addr)
/* send the whole playerlist to the client to update the playerlist */ /* 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) { else if (p_id->pl_nr == -1 && addr->pl_nr >= 0 && addr->pl_nr < MAX_PLAYERS) {
for (i = 0; i < MAX_PLAYERS; i++) 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_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 ***"); d_playerdetail ("*** PLAYER List ***");
@ -430,7 +434,7 @@ send_field (_net_addr * addr, int x, int y, _field * field)
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
f_dat.ex[i].count = map.field[x][y].ex[i].count; 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.ex[i].frame = (int) map.field[x][y].ex[i].frame;
} }
f_dat.type = map.field[x][y].type; f_dat.type = map.field[x][y].type;
f_dat.mixframe = map.field[x][y].mixframe; f_dat.mixframe = map.field[x][y].mixframe;
@ -469,8 +473,7 @@ do_field (struct pkg_field *f_dat, _net_addr * addr)
bman.last_ex_nr = NTOH32 (f_dat->ex_nr); bman.last_ex_nr = NTOH32 (f_dat->ex_nr);
d_printf ("do_field (%d,%d) ex_nr = %d, special = %d, type = %d\n", 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->x, f_dat->y, NTOH32 (f_dat->ex_nr), f_dat->special, f_dat->type);
f_dat->special, f_dat->type);
}; };
@ -631,7 +634,8 @@ do_playerdata (struct pkg_playerdata *p_dat, _net_addr * addr)
void void
do_ill (struct pkg_ill *ill, _net_addr * addr) do_ill (struct pkg_ill *ill, _net_addr * addr)
{ {
int i, old_to; int i,
old_to;
if (addr->pl_nr == -1) if (addr->pl_nr == -1)
return; return;
@ -647,7 +651,8 @@ do_ill (struct pkg_ill *ill, _net_addr * addr)
player_clear_ilness (&players[ill->pl_nr], i); player_clear_ilness (&players[ill->pl_nr], i);
else if (players[ill->pl_nr].ill[i].to > 0.0f && old_to <= 0.0f) 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); 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); 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);
} }
}; };
@ -686,7 +691,7 @@ send_playermove (_net_addr * addr, int p_nr, _player * pl)
p_dat.m = pl->m; p_dat.m = pl->m;
p_dat.d = pl->d; p_dat.d = pl->d;
p_dat.p_nr = p_nr; 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)); p_dat.tunnelto = HTON16 (FTOI16 (pl->tunnelto));
send_pkg ((struct pkg *) &p_dat, addr); send_pkg ((struct pkg *) &p_dat, addr);
@ -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 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", 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)); b_dat->b_nr, NTOH32 (b_dat->ex_nr));
bomb = &players[b_dat->p_nr].bombs[b_dat->b_nr]; bomb = &players[b_dat->p_nr].bombs[b_dat->b_nr];
@ -751,11 +756,11 @@ do_bombdata (struct pkg_bombdata *b_dat, _net_addr * addr)
d_printf ("do_bombdata WARNING : bomb explosion haven't finished\n"); d_printf ("do_bombdata WARNING : bomb explosion haven't finished\n");
if (bomb->state != BS_off) { // handle push & kick special 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, bomb->pos.y);
stonelist_add (bomb->pos.x+1, 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, bomb->pos.y + 1);
stonelist_add (bomb->pos.x+1, 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)) if (bomb->state == BS_off && (b_dat->state == BS_ticking || b_dat->state == BS_trigger))
@ -770,7 +775,7 @@ do_bombdata (struct pkg_bombdata *b_dat, _net_addr * addr)
to make sure the timeout won't be resetted to make sure the timeout won't be resetted
by an old network packet */ 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->r = b_dat->r;
bomb->ex_nr = NTOH32 (b_dat->ex_nr); bomb->ex_nr = NTOH32 (b_dat->ex_nr);
@ -862,7 +867,7 @@ send_tunneldata (_net_addr * addr, int tunnelnr, int x, int y)
*** Packettype: quit *** Packettype: quit
***/ ***/
void void
send_quit (_net_addr * addr, char *plhost, char * plport) send_quit (_net_addr * addr, char *plhost, char *plport)
{ {
struct pkg_quit q_dat; struct pkg_quit q_dat;
@ -984,7 +989,7 @@ do_fieldline (struct pkg_fieldline *f_dat, _net_addr * addr)
if (addr->pl_nr == -1) if (addr->pl_nr == -1)
return; 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 */ /* 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"); d_printf ("do_fieldline: the data we have got are not from the server\n");
return; return;
@ -1100,8 +1105,7 @@ send_playerstatus (_net_addr * addr, int pl_nr, int net_istep, int status)
void void
do_chat (struct pkg_chat *chat_pkg, _net_addr * addr) do_chat (struct pkg_chat *chat_pkg, _net_addr * addr)
{ {
d_printf ("do_chat (%s:%s) %d Text:%s\n", addr->host, d_printf ("do_chat (%s:%s) %d Text:%s\n", addr->host, addr->port, addr->pl_nr, chat_pkg->text);
addr->port, addr->pl_nr, chat_pkg->text);
chat_addline (chat_pkg->text); chat_addline (chat_pkg->text);
}; };
@ -1158,13 +1162,15 @@ do_pkgack (struct pkg_pkgack *p_ack, _net_addr * addr)
*** Packettype: dropitems *** Packettype: dropitems
*** send a generated list of drop items *** send a generated list of drop items
***/ ***/
void send_dropitems (_net_addr *addr, int pl_nr, _flyingitem **fitems, int cnt) { 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 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 struct pkg_dropitem *dipkg = (struct pkg_dropitem *) outdata; // set the pointer to outdata
int i; int i;
dipkg->h.typ = PKG_dropitem; dipkg->h.typ = PKG_dropitem;
dipkg->h.len = HTON16 (sizeof (struct pkg_dropitem) + cnt*sizeof (struct pkgdropitemelemt)); dipkg->h.len = HTON16 (sizeof (struct pkg_dropitem) + cnt * sizeof (struct pkgdropitemelemt));
dipkg->h.flags = PKGF_ackreq; dipkg->h.flags = PKGF_ackreq;
dipkg->pl_nr = pl_nr; dipkg->pl_nr = pl_nr;
dipkg->from.x = HTON16 (FTOI16 (players[pl_nr].pos.x)); dipkg->from.x = HTON16 (FTOI16 (players[pl_nr].pos.x));
@ -1172,21 +1178,24 @@ void send_dropitems (_net_addr *addr, int pl_nr, _flyingitem **fitems, int cnt)
dipkg->count = cnt; dipkg->count = cnt;
for (i = 0; (i < cnt && fitems[i] != NULL); i++) { for (i = 0; (i < cnt && fitems[i] != NULL); i++) {
dipkg->items[i].x = (int)fitems[i]->to.x; dipkg->items[i].x = (int) fitems[i]->to.x;
dipkg->items[i].y = (int)fitems[i]->to.y; dipkg->items[i].y = (int) fitems[i]->to.y;
dipkg->items[i].typ = (int)fitems[i]->type; dipkg->items[i].typ = (int) fitems[i]->type;
} }
send_pkg ((struct pkg*)dipkg, addr); send_pkg ((struct pkg *) dipkg, addr);
}; };
void do_dropitems (struct pkg_dropitem *di_pkg, _net_addr *addr) { void
do_dropitems (struct pkg_dropitem *di_pkg, _net_addr * addr)
{
int i; int i;
_pointf from; _pointf from;
_point to; _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) if (addr->pl_nr == -1)
return; return;
from.x = I16TOF (NTOH16 (di_pkg->from.x)); from.x = I16TOF (NTOH16 (di_pkg->from.x));

Loading…
Cancel
Save