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);
@ -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);
@ -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 ***");
@ -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);
} }
}; };
@ -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,7 +1162,9 @@ 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;
@ -1181,12 +1187,15 @@ void send_dropitems (_net_addr *addr, int pl_nr, _flyingitem **fitems, int cnt)
}; };
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