From 89d2f4261be41f661db826d44232d42ef125dfe3 Mon Sep 17 00:00:00 2001 From: stpohle Date: Sun, 22 Jun 2003 02:03:09 +0000 Subject: [PATCH] Last Exploded bomb won't used right away if there is another free bomb. (it should fix the NO BOMB but explosion bug in multiplayergames --- src/bomb.c | 2 ++ src/bomberclone.h | 4 +++- src/player.c | 26 +++++++++++++++++++++++--- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/bomb.c b/src/bomb.c index f756e28..1ce4faf 100644 --- a/src/bomb.c +++ b/src/bomb.c @@ -64,6 +64,8 @@ bomb_explode (int p, int b, int net) if (bomb->ex_nr == -1) bomb->ex_nr = bman.last_ex_nr++; // set bomb explosion id + bman.players[p].bomb_lastex = b; + bomb->to = EXPLOSIONTIMEOUT; /* set the timeout for the fireexplosion */ bomb->state = BS_exploding; for (d = 0; d < 4; d++) { diff --git a/src/bomberclone.h b/src/bomberclone.h index 825a0ee..5667ea9 100644 --- a/src/bomberclone.h +++ b/src/bomberclone.h @@ -1,4 +1,4 @@ -/* $Id: bomberclone.h,v 1.39 2003/06/09 22:56:40 stpohle Exp $ */ +/* $Id: bomberclone.h,v 1.40 2003/06/22 02:03:09 stpohle Exp $ */ /* bomberclone.h */ #ifndef _BOMBERCLONE_H_ @@ -91,6 +91,7 @@ struct __player { signed char old_m; // to save the old state.. int bombs_n; // maximal number of bombs for the player + int bomb_lastex; // number of the bomb which explode the last time _bomb bombs[MAX_BOMBS]; // number of bombs who are ticking. int range; // range of the bombs int speed; // how fast we can go (0 = slow, 1 = normal... 3 = fastest) @@ -226,6 +227,7 @@ extern void player_clear_ilness (_player *p, int type); extern void player_ilness_loop (int pl_nr); extern void player_check_powerup (int p_nr); extern void player_set_gfx (_player *p, signed char gfx_nr); +extern int player_findfreebomb (_player *player); // for the bomb.. extern int bomb_loop (); diff --git a/src/player.c b/src/player.c index 576751e..231fdfa 100644 --- a/src/player.c +++ b/src/player.c @@ -359,10 +359,10 @@ player_drop_bomb (int pl_nr) _x, _y; _point bombs[MAX_PLAYERS * MAX_BOMBS]; - - for (i = 0; ((i < player->bombs_n) && (player->bombs[i].state != BS_off)); i++); - if (i < player->bombs_n && PS_IS_alife (player->state)) { // free bomb found + i = player_findfreebomb (player); + + if (i >= 0 && i < MAX_BOMBS && PS_IS_alife (player->state)) { // free bomb found // get the best position for the bomb. bomb = &player->bombs[i]; bomb->pos.x = player->pos.x >> 8; @@ -753,3 +753,23 @@ player_set_gfx (_player * p, signed char gfx_nr) p->state |= PSF_playing; } }; + + +/* find a free bomb */ +int player_findfreebomb (_player *player) { + int i, bombused = 0, res = -1; + + /* check every free bomb from next entry of the last + exploded bomb to the last exploded bomb */ + + for (i = player->bomb_lastex + 1; (bombused < player->bombs_n && i != player->bomb_lastex && res == -1); i++) { + if (i < 0 || i > MAX_BOMBS) // i out of range .. restart at bomb 0 + i = 0; + if (player->bombs[i].state == BS_off) + res = i; + else + bombused++; // count number of used bombs + } + + return res; +};