#include #include "def.h" #include "monster.h" #include "main.h" #include "sprite.h" #include "digger.h" #include "drawing.h" #include "bags.h" #include "sound.h" #include "scores.h" #include "record.h" struct monster { Sint4 x,y,h,v,xr,yr,dir,hdir,t,hnt,death,bag,dtime,stime,chase; bool flag,nob,alive; } mondat[6]; Sint4 nextmonster=0,totalmonsters=0,maxmononscr=0,nextmontime=0,mongaptime=0; Sint4 chase=0; bool unbonusflag=FALSE; void createmonster(void); void monai(Sint4 mon); void mondie(Sint4 mon); bool fieldclear(Sint4 dir,Sint4 x,Sint4 y); void squashmonster(Sint4 mon,Sint4 death,Sint4 bag); Sint4 nmononscr(void); void initmonsters(void) { Sint4 i; for (i=0;i0) nextmontime--; else { if (nextmonster10-levof10()) { if (mondat[i].nob) { mondat[i].nob=FALSE; mondat[i].hnt=0; } } if (mondat[i].alive) if (mondat[i].t==0) { monai(i); if (randno(15-levof10())==0) /* Need to split for determinism */ if (mondat[i].nob && mondat[i].alive) monai(i); } else mondat[i].t--; else mondie(i); } } void createmonster(void) { Sint4 i; for (i=0;i30+(levof10()<<1)) if (!mondat[mon].nob) { mondat[mon].hnt=0; mondat[mon].nob=TRUE; } /* Set up monster direction properties to chase Digger */ dig=mondat[mon].chase; if (!digalive(dig)) dig=(diggers-1)-dig; if (abs(diggery(dig)-mondat[mon].y)>abs(diggerx(dig)-mondat[mon].x)) { if (diggery(dig)1) removebags(clfirst,clcoll); /* Hobbins eat bags */ } /* Increase hobbin cross counter */ if (mondat[mon].nob && clfirst[2]!=-1 && isalive()) mondat[mon].hnt++; /* See if bags push monster back */ if (!push) { mondat[mon].x=monox; mondat[mon].y=monoy; drawmon(mon,mondat[mon].nob,mondat[mon].hdir,mondat[mon].x,mondat[mon].y); incpenalty(); if (mondat[mon].nob) /* The other way to create hobbin: stuck on h-bag */ mondat[mon].hnt++; if ((mondat[mon].dir==DIR_UP || mondat[mon].dir==DIR_DOWN) && mondat[mon].nob) mondat[mon].dir=reversedir(mondat[mon].dir); /* If vertical, give up */ } /* Collision with Digger */ if (clfirst[4]!=-1 && isalive()) if (bonusmode) { killmon(mon); i=clfirst[4]; while (i!=-1) { if (digalive(i-FIRSTDIGGER+curplayer)) sceatm(i-FIRSTDIGGER+curplayer); i=clcoll[i]; } soundeatm(); /* Collision in bonus mode */ } else { i=clfirst[4]; while (i!=-1) { if (digalive(i-FIRSTDIGGER+curplayer)) killdigger(i-FIRSTDIGGER+curplayer,3,0); /* Kill Digger */ i=clcoll[i]; } } /* Update co-ordinates */ mondat[mon].h=(mondat[mon].x-12)/20; mondat[mon].v=(mondat[mon].y-18)/18; mondat[mon].xr=(mondat[mon].x-12)%20; mondat[mon].yr=(mondat[mon].y-18)%18; } void mondie(Sint4 mon) { switch (mondat[mon].death) { case 1: if (bagy(mondat[mon].bag)+6>mondat[mon].y) mondat[mon].y=bagy(mondat[mon].bag); drawmondie(mon,mondat[mon].nob,mondat[mon].hdir,mondat[mon].x, mondat[mon].y); incpenalty(); if (getbagdir(mondat[mon].bag)==-1) { mondat[mon].dtime=1; mondat[mon].death=4; } break; case 4: if (mondat[mon].dtime!=0) mondat[mon].dtime--; else { killmon(mon); if (diggers==2) scorekill2(); else scorekill(curplayer); } } } bool fieldclear(Sint4 dir,Sint4 x,Sint4 y) { switch (dir) { case DIR_RIGHT: if (x<14) if ((getfield(x+1,y)&0x2000)==0) if ((getfield(x+1,y)&1)==0 || (getfield(x,y)&0x10)==0) return TRUE; break; case DIR_UP: if (y>0) if ((getfield(x,y-1)&0x2000)==0) if ((getfield(x,y-1)&0x800)==0 || (getfield(x,y)&0x40)==0) return TRUE; break; case DIR_LEFT: if (x>0) if ((getfield(x-1,y)&0x2000)==0) if ((getfield(x-1,y)&0x10)==0 || (getfield(x,y)&1)==0) return TRUE; break; case DIR_DOWN: if (y<9) if ((getfield(x,y+1)&0x2000)==0) if ((getfield(x,y+1)&0x40)==0 || (getfield(x,y)&0x800)==0) return TRUE; } return FALSE; } void checkmonscared(Sint4 h) { Sint4 m; for (m=0;m=bagy(bag)) squashmonster(m,1,bag); next=clcoll[next]; } } Sint4 killmonsters(int *clfirst,int *clcoll) { int next=clfirst[2],m,n=0; while (next!=-1) { m=next-FIRSTMONSTER; killmon(m); n++; next=clcoll[next]; } return n; } void squashmonster(Sint4 mon,Sint4 death,Sint4 bag) { mondat[mon].alive=FALSE; mondat[mon].death=death; mondat[mon].bag=bag; } Sint4 monleft(void) { return nmononscr()+totalmonsters-nextmonster; } Sint4 nmononscr(void) { Sint4 i,n=0; for (i=0;iMONSTERS) n=MONSTERS; for (m=1;m