From 8a8afdf56e8c6bad4a4601bad78289050d272e2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Tue, 11 Aug 2009 19:09:59 +0200 Subject: [PATCH] remove limit of detonating bombs --- bomber.h | 1 - game.c | 85 +++++++++++++++++++++++++++----------------------------- list.c | 15 +++++----- list.h | 9 +++++- 4 files changed, 57 insertions(+), 53 deletions(-) diff --git a/bomber.h b/bomber.h index b14bfe7..265c1a3 100644 --- a/bomber.h +++ b/bomber.h @@ -220,7 +220,6 @@ enum tile_types { #define MAXSETS 8 #define MAXSPRITES 256 #define MAXDAMAGES 512 -#define MAXBOMBSDETONATED 32 extern char exitflag; diff --git a/game.c b/game.c index 45617f6..8558d70 100644 --- a/game.c +++ b/game.c @@ -15,11 +15,7 @@ static listhead activebombs; static listhead activedecays; static listhead activebonus; static listhead activegeneric; - -static bomb *detonated[MAXBOMBSDETONATED]; -static int detonateput=0; -static int detonatetake=0; - +static listhead detonatebombs; static listhead activeflames; static listhead activeplayers; @@ -124,14 +120,13 @@ static void initgame() { gameframe=0; allocthings(); initheader(&activebombs); + initheader(&detonatebombs); initheader(&activeflames); initheader(&activedecays); initheader(&activebonus); initheader(&activeplayers); initheader(&activegeneric); - detonateput=detonatetake=0; - p=bonuschances; bonustotal=0; for(;;) { @@ -226,37 +221,6 @@ static void dropbomb(player *pl,int px,int py,int type){ bmb->owner=pl; } -static void adddetonate(bomb *bmb) { - if(bmb->type==BOMB_OFF) return; - - bmb->type=BOMB_OFF; - field[bmb->py][bmb->px]=FIELD_EXPLODING; - info[bmb->py][bmb->px]=0; - detonated[detonateput++]=bmb; - detonateput%=MAXBOMBSDETONATED; -} - -static void processbombs() { - bomb *bmb, *next; - - foreach_list_safe(&activebombs, bmb, next) { - ++(bmb->figcount); - ++bmb->timer; - switch(bmb->type) { - case BOMB_NORMAL: - if (bmb->timer == BOMBLIFE) - adddetonate(bmb); - break; - case BOMB_CONTROLLED: - if (bmb->timer == BOMB_CONTROLLED_LIFE) { - bmb->timer = 0; - bmb->type = BOMB_NORMAL; - } - break; - } - } -} - static void adddecay(int px,int py) { brickdecay *bd; int xpos,ypos; @@ -316,6 +280,38 @@ static void deletebonus(bonustile *bonus) { delink(bonus); } +static void adddetonate(bomb *bmb) { + if (bmb->type==BOMB_OFF) return; + + bmb->type = BOMB_OFF; + field[bmb->py][bmb->px] = FIELD_EXPLODING; + info[bmb->py][bmb->px] = 0; + + removeitem(bmb); + addtail(&detonatebombs, bmb); +} + +static void processbombs() { + bomb *bmb, *next; + + foreach_list_safe(&activebombs, bmb, next) { + ++(bmb->figcount); + ++bmb->timer; + switch(bmb->type) { + case BOMB_NORMAL: + if (bmb->timer == BOMBLIFE) + adddetonate(bmb); + break; + case BOMB_CONTROLLED: + if (bmb->timer == BOMB_CONTROLLED_LIFE) { + bmb->timer = 0; + bmb->type = BOMB_NORMAL; + } + break; + } + } +} + static void flameshaft(player *owner,int px,int py,int dx,int dy,int power) { int there; bomb *bmb; @@ -370,12 +366,13 @@ static void detonatebomb(bomb *bmb) { } static void dodetonations(void) { - int i=0; + int i = 0; + bomb *bmb; - while(detonatetake!=detonateput) { + while (!list_empty(&detonatebombs)) { + bmb = (bomb*) detonatebombs.next; ++i; - detonatebomb(detonated[detonatetake]); - detonatetake=(detonatetake+1) % MAXBOMBSDETONATED; + detonatebomb(bmb); } if(i) playsound((myrand()&1) ? 0 : 4); } @@ -477,9 +474,9 @@ static void drawplayers() { } static void detonatecontrolled(player *pl) { - bomb *bmb; + bomb *bmb, *next; - foreach_list_fast(&activebombs, bmb) { + foreach_list_safe(&activebombs, bmb, next) { if(bmb->owner==pl && bmb->type==BOMB_CONTROLLED) adddetonate(bmb); } diff --git a/list.c b/list.c index f10b0fb..186ef3d 100644 --- a/list.c +++ b/list.c @@ -34,9 +34,7 @@ void *allocentry(void) { return entry; } -static void freeentry(void *_entry) { - listhead *entry = _entry; - +void _freeentry(listhead *entry) { entry->next = free_things; entry->prev = NULL; free_things = entry; @@ -49,13 +47,16 @@ void _addtail(listhead *head, listhead *entry) { head->prev = entry; } +void _removeitem(listhead *entry) { + entry->next->prev = entry->prev; + entry->prev->next = entry->next; +} + listhead* delinkhead(listhead *entry) { listhead *result = entry->prev; - entry->next->prev = entry->prev; - entry->prev->next = entry->next; - - freeentry(entry); + _removeitem(entry); + _freeentry(entry); return result; } diff --git a/list.h b/list.h index dc1336e..f6ad7ea 100644 --- a/list.h +++ b/list.h @@ -3,11 +3,17 @@ void allocthings(void); void *allocentry(void); +void _freeentry(listhead *entry); +#define freeentry(entry) _freeentry(&(entry->list)); void _addtail(listhead *header, listhead *entry); #define addtail(head, entry) _addtail(head, &(entry->list)); -/* returns previous entry */ +/* remove entry from list */ +void _removeitem(listhead *entry); +#define removeitem(entry) _removeitem(&(entry->list)); + +/* returns previous entry, deletes entry */ listhead* delinkhead(listhead *entry); #define delink(entry) delinkhead(&(entry->list)); @@ -22,5 +28,6 @@ void initheader(listhead *head); #define foreach_list_safe(head, item, next) \ for (item = (void*) (head)->next, next = (void*) ((listhead*)item)->next; (listhead*) item != (head); item = next, next = (void*) ((listhead*)item)->next) +#define list_empty(head) ((head) == (head)->next) #endif