static void label_pirv(int index) /***************************************************/ { char label[MAXPATHL]; int offset0,offset1,ticlen; int ychar = 12; if(gb[index].lowlimit <= dfpnt || gb[index].highlimit <= dfpnt || gb[index].lowlimit >= (dfpnt+dnpnt-xcharpixels) || gb[index].highlimit >= (dfpnt+dnpnt-xcharpixels)) return; /*Charsize in pixels */ if(!showPlotBox()) offset0 = (int) (dpir_off*dispcalib) + CharSize + ychar/3; else offset0 = ychar/2; ticlen = ycharpixels/3; amove(gb[index].lowlimit, dfpnt2 - offset0 + (int) (dispcalib * vp)); rdraw(0, -ticlen); rdraw(gb[index].highlimit - gb[index].lowlimit,0); rdraw(0, ticlen); amove((gb[index].lowlimit + gb[index].highlimit) / 2, dfpnt2 - offset0 + (int) (dispcalib * vp) - ticlen); rdraw(0, -ticlen); sprintf(label,"%1.2f",lineamp[index]); offset1=0; if (!showPlotBox()) { rmove(ycharpixels/3,(-xcharpixels * (int)strlen(label) - offset1)); } else { rmove(-ycharpixels/2,(-xcharpixels * (int)strlen(label) - offset1)); } dvstring(label); }
void rmove_elbow(int step) { if ((rpos.elbow+step <= MAX_ELBOW) && (rpos.elbow+step >= MIN_ELBOW)) { rpos.elbow+=step; rmove(3,step); } else { if(rpos.elbow+step > MAX_ELBOW) { rmove(3,MAX_ELBOW-rpos.elbow); rpos.elbow=MAX_ELBOW; } if(rpos.elbow+step < MIN_ELBOW) { rmove(3,MIN_ELBOW-rpos.elbow); rpos.elbow=MIN_ELBOW; } } }
void rmove_shoulder(int step) { if ((rpos.shoulder+step <= MAX_SHOULDER) && (rpos.shoulder+step >= MIN_SHOULDER)) { rpos.shoulder+=step; rmove(2,step); } else { if(rpos.shoulder+step > MAX_SHOULDER) { rmove(2,MAX_SHOULDER-rpos.shoulder); rpos.shoulder=MAX_SHOULDER; } if(rpos.shoulder+step < MIN_SHOULDER) { rmove(2,MIN_SHOULDER-rpos.shoulder); rpos.shoulder=MIN_SHOULDER; } } }
void rmove_turnhand(int step) { if ((rpos.wrist+step <= MAX_TURNHAND) && (rpos.wrist+step >= MIN_TURNHAND)) { rpos.wrist+=step; rmove(5,step); } else { if(rpos.wrist+step > MAX_TURNHAND) { rmove(5,MAX_TURNHAND-rpos.wrist); rpos.wrist=MAX_TURNHAND; } if(rpos.wrist+step < MIN_TURNHAND) { rmove(5,MIN_TURNHAND-rpos.wrist); rpos.wrist=MIN_TURNHAND; } } }
void rmove_pitch(int step) { step/=2; if ((rpos.pitch+step <= MAX_PITCH) && (rpos.pitch+step >= MIN_PITCH)) { rpos.pitch+=step; rmove(4,step); } else { if(rpos.pitch+step > MAX_PITCH) { rmove(4,MAX_PITCH-rpos.pitch); rpos.pitch=MAX_PITCH; } if(rpos.pitch+step < MIN_PITCH) { rmove(4,MIN_PITCH-rpos.pitch); rpos.pitch=MIN_PITCH; } } }
void rmove_base(int step) { if ((rpos.base+step <= MAX_BASE) && (rpos.base+step >= MIN_BASE)) { rpos.base+=step; rmove(1,step); } else { if(rpos.base+step > MAX_BASE) { rmove(1,MAX_BASE-rpos.base); rpos.base=MAX_BASE; } if(rpos.base+step < MIN_BASE) { rmove(1,MIN_BASE-rpos.base); rpos.base=MIN_BASE; } } }
void testSuite() { hashtable table = init_hashtable(7); printf(":: Table elems: %d\n", table->p); printf(":: Inserting elements in hashtable\n"); put(&table, "toto", "hey"); put(&table, "lablab", "monk"); put(&table, "blabla", "plop"); put(&table, "toto", "ho!"); put(&table, "tops", "hahah"); put(&table, "pots", "huhuh"); displayHashTable(table); printf(":: Seeking for hello: %s\n", get(table, "hello")); printf(":: Seeking for toto: %s\n", get(table, "toto")); printf(":: Removing elem tops, toto and lablab\n"); rmove(&table, "tops"); rmove(&table, "toto"); rmove(&table, "lablab"); displayHashTable(table); printf(":: Changing hash function and adding two elems\n"); hashtable table2 = init_hashtable(7); set_hfunc(&table2, &idx_hashfunction); put(&table2, "toto", "hey"); put(&table2, "blabla", "plop"); put(&table2, "lablab", "monk"); displayHashTable(table2); printf(":: Fonction for first hashtable: %p\n", get_hfunc(table)); printf(":: Fonction for second hashtable: %p\n", get_hfunc(table2)); printf(":: Stats for first table\n"); put(&table, "lablab", "monk"); put(&table, "toto", "ho!"); put(&table, "tops", "hahah"); displayStats(get_stats(table)); printf(":: Stats for second table\n"); displayStats(get_stats(table2)); printf(":: Rehash table with 11 buckets\n"); set_hfunc(&table, &idx_hashfunction); rehash_table(&table, 11); displayHashTable(table); }
static void leader_bot(int peak_x, int peak_y, int label_x, int label_y, int ymax) /***************************************************/ { if (peak_x == label_x) { amove(peak_x,peak_y); rdraw(0,label_y - peak_y); } else { int dh,dx,dy; dx = label_x - peak_x; dy = abs(dx) / 2; dh = label_y - peak_y + (int) (3.0 * dispcalib); if (peak_y + dh + dy + (int) (3.0 * dispcalib) > ymax) dh = ymax - peak_y - dy - (int) (3.0 * dispcalib); amove(peak_x,peak_y); if (dh > 0) { rdraw(0,dh); } else if (peak_y + dy + (int) (3.0 * dispcalib) > ymax) { peak_y = ymax - dy - (int) (3.0 * dispcalib); if (peak_y < dfpnt2 + (int) (dispcalib * vp + 1.0)) { dy = dfpnt2 + (int) (dispcalib * vp + 1.0) - peak_y; if (dy < 0) dy = 0; peak_y = dfpnt2 + (int) (dispcalib * vp + 1.0); } amove(peak_x,peak_y); } rdraw(dx,dy); rdraw(0,(int) (3.0 * dispcalib)); } if (((raster == 0) || (raster > 2)) && plot) /* HP plotter */ rmove( CharSize/5,5); /* and PS */ else rmove(-CharSize/2,5); }
static int leader_top(int peak_x, int peak_y, int label_x, int ymax) /***************************************************/ { int newpeak_y; int dx,dy; int bottom; dx = label_x - peak_x; dy = abs(dx) / 2; newpeak_y = ymax - dy - (int) (3.0 * dispcalib); bottom = dfpnt2 + (int) (dispcalib * vp + 1.0); if (newpeak_y < bottom) { if (!plot) Winfoprintf("vp too large for dpf display"); return(0); } if (newpeak_y > peak_y) { amove(peak_x,peak_y); rdraw(0,newpeak_y - peak_y); } amove(peak_x,newpeak_y); rdraw(dx,dy); rdraw(0,(int) (3.0 * dispcalib)); /* re-use dx for logic */ dx = plot && ((raster == 0) || (raster > 2)); /* hpgl and postscript output */ if (dx) /* HP plotter */ rmove( CharSize/5,5); else if (plot) rmove(-CharSize/2,5); else rmove(-4*CharSize/5,5); return(1); }
void FramelessWin2::mouseMoveEvent(QMouseEvent *evt) { QPoint globalPos = evt->globalPos(); QRect rect = this->rect(); QPoint tl = mapToGlobal(rect.topLeft()); QPoint tb = mapToGlobal(rect.bottomRight()); QRect rmove(tl,tb); if ( m_pressed ) { if (m_direct == UNKOWN ) { move(evt->globalPos()-m_movePoint); } else { changeSize(rmove,globalPos); setGeometry(rmove); } } else { GetMoveDirect(globalPos); } }
void zzzcode(NODE *p, int c) { NODE *l; int pr, lr; char *ch; switch (c) { case 'A': /* swap st0 and st1 if right is evaluated second */ if ((p->n_su & DORIGHT) == 0) { if (logop(p->n_op)) printf(" fxch\n"); else printf("r"); } break; case 'C': /* remove from stack after subroutine call */ #ifdef notyet if (p->n_left->n_flags & FSTDCALL) break; #endif pr = p->n_qual; if (p->n_op == STCALL || p->n_op == USTCALL) pr += 4; if (p->n_flags & FFPPOP) printf(" fstp %%st(0)\n"); if (p->n_op == UCALL) return; /* XXX remove ZC from UCALL */ if (pr) printf(" addl $%d, %s\n", pr, rnames[ESP]); break; case 'D': /* Long long comparision */ twollcomp(p); break; case 'F': /* Structure argument */ if (p->n_stalign != 0) /* already on stack */ starg(p); break; case 'G': /* Floating point compare */ fcomp(p); break; case 'H': /* assign of longlong between regs */ rmove(DECRA(p->n_right->n_reg, 0), DECRA(p->n_left->n_reg, 0), LONGLONG); break; case 'I': /* float casts */ fcast(p); break; case 'J': /* convert unsigned long long to floating point */ ulltofp(p); break; case 'K': /* Load longlong reg into another reg */ rmove(regno(p), DECRA(p->n_reg, 0), LONGLONG); break; case 'M': /* Output sconv move, if needed */ l = getlr(p, 'L'); /* XXX fixneed: regnum */ pr = DECRA(p->n_reg, 0); lr = DECRA(l->n_reg, 0); if ((pr == AL && lr == EAX) || (pr == BL && lr == EBX) || (pr == CL && lr == ECX) || (pr == DL && lr == EDX)) ; else printf(" movb %%%cl,%s\n", rnames[lr][2], rnames[pr]); l->n_rval = l->n_reg = p->n_reg; /* XXX - not pretty */ break; case 'N': /* output extended reg name */ printf("%s", rnames[getlr(p, '1')->n_rval]); break; case 'O': /* print out emulated ops */ pr = 16; if (p->n_op == RS || p->n_op == LS) { llshft(p); break; } else if (p->n_op == MUL) { printf("\timull %%ecx, %%edx\n"); printf("\timull %%eax, %%esi\n"); printf("\taddl %%edx, %%esi\n"); printf("\tmull %%ecx\n"); printf("\taddl %%esi, %%edx\n"); break; } expand(p, INCREG, "\tpushl UR\n\tpushl AR\n"); expand(p, INCREG, "\tpushl UL\n\tpushl AL\n"); if (p->n_op == DIV && p->n_type == ULONGLONG) ch = "udiv"; else if (p->n_op == DIV) ch = "div"; else if (p->n_op == MOD && p->n_type == ULONGLONG) ch = "umod"; else if (p->n_op == MOD) ch = "mod"; else ch = 0, comperr("ZO"); #ifdef ELFABI printf("\tcall " EXPREFIX "__%sdi3%s\n\taddl $%d,%s\n", ch, (kflag ? "@PLT" : ""), pr, rnames[ESP]); #else printf("\tcall " EXPREFIX "__%sdi3\n\taddl $%d,%s\n", ch, pr, rnames[ESP]); #endif break; case 'P': /* push hidden argument on stack */ printf("\tleal -%d(%%ebp),", stkpos); adrput(stdout, getlr(p, '1')); printf("\n\tpushl "); adrput(stdout, getlr(p, '1')); putchar('\n'); break; case 'Q': /* emit struct assign */ /* * With <= 16 bytes, put out mov's, otherwise use movsb/w/l. * esi/edi/ecx are available. * XXX should not need esi/edi if not rep movsX. * XXX can save one insn if src ptr in reg. */ switch (p->n_stsize) { case 1: expand(p, INAREG, " movb (%esi),%cl\n"); expand(p, INAREG, " movb %cl,AL\n"); break; case 2: expand(p, INAREG, " movw (%esi),%cx\n"); expand(p, INAREG, " movw %cx,AL\n"); break; case 4: expand(p, INAREG, " movl (%esi),%ecx\n"); expand(p, INAREG, " movl %ecx,AL\n"); break; default: expand(p, INAREG, " leal AL,%edi\n"); if (p->n_stsize <= 16 && (p->n_stsize & 3) == 0) { printf(" movl (%%esi),%%ecx\n"); printf(" movl %%ecx,(%%edi)\n"); printf(" movl 4(%%esi),%%ecx\n"); printf(" movl %%ecx,4(%%edi)\n"); if (p->n_stsize > 8) { printf(" movl 8(%%esi),%%ecx\n"); printf(" movl %%ecx,8(%%edi)\n"); } if (p->n_stsize == 16) { printf("\tmovl 12(%%esi),%%ecx\n"); printf("\tmovl %%ecx,12(%%edi)\n"); } } else { if (p->n_stsize > 4) { printf("\tmovl $%d,%%ecx\n", p->n_stsize >> 2); printf(" rep movsl\n"); } if (p->n_stsize & 2) printf(" movsw\n"); if (p->n_stsize & 1) printf(" movsb\n"); } break; } break; case 'S': /* emit eventual move after cast from longlong */ pr = DECRA(p->n_reg, 0); lr = p->n_left->n_rval; switch (p->n_type) { case CHAR: case UCHAR: if (rnames[pr][2] == 'l' && rnames[lr][2] == 'x' && rnames[pr][1] == rnames[lr][1]) break; if (rnames[lr][2] == 'x') { printf("\tmovb %%%cl,%s\n", rnames[lr][1], rnames[pr]); break; } /* Must go via stack */ expand(p, INAREG, "\tmovl AL,A2\n"); expand(p, INBREG, "\tmovb A2,A1\n"); #ifdef notdef /* cannot use freetemp() in instruction emission */ s = BITOOR(freetemp(1)); printf("\tmovl %%e%ci,%d(%%ebp)\n", rnames[lr][1], s); printf("\tmovb %d(%%ebp),%s\n", s, rnames[pr]); #endif break; case SHORT: case USHORT: if (rnames[lr][1] == rnames[pr][2] && rnames[lr][2] == rnames[pr][3]) break; printf("\tmovw %%%c%c,%%%s\n", rnames[lr][1], rnames[lr][2], rnames[pr]+2); break; case INT: case UNSIGNED: if (rnames[lr][1] == rnames[pr][2] && rnames[lr][2] == rnames[pr][3]) break; printf("\tmovl %%e%c%c,%s\n", rnames[lr][1], rnames[lr][2], rnames[pr]); break; default: if (rnames[lr][1] == rnames[pr][2] && rnames[lr][2] == rnames[pr][3]) break; comperr("SCONV2 %s->%s", rnames[lr], rnames[pr]); break; } break; default: comperr("zzzcode %c", c); }
void zzzcode(NODE *p, int c) { struct attr *ap; NODE *l; int pr, lr; char *ch; switch (c) { case 'A': /* swap st0 and st1 if right is evaluated second */ if ((p->n_su & DORIGHT) == 0) { if (logop(p->n_op)) printf(" fxch\n"); else printf("r"); } break; case 'C': /* remove from stack after subroutine call */ #ifdef GCC_COMPAT if (attr_find(p->n_left->n_ap, GCC_ATYP_STDCALL)) break; #endif pr = p->n_qual; if (attr_find(p->n_ap, ATTR_I386_FPPOP)) printf(" fstp %%st(0)\n"); if (p->n_op == UCALL) return; /* XXX remove ZC from UCALL */ if (pr) printf(" addl $%d, %s\n", pr, rnames[ESP]); #if defined(os_openbsd) ap = attr_find(p->n_ap, ATTR_P2STRUCT); if (p->n_op == STCALL && (ap->iarg(0) == 1 || ap->iarg(0) == 2 || ap->iarg(0) == 4 || ap->iarg(0) == 8)) { /* save on stack */ printf("\tmovl %%eax,-%d(%%ebp)\n", stkpos); printf("\tmovl %%edx,-%d(%%ebp)\n", stkpos+4); printf("\tleal -%d(%%ebp),%%eax\n", stkpos); } #endif break; case 'D': /* Long long comparision */ twollcomp(p); break; case 'F': /* Structure argument */ starg(p); break; case 'G': /* Floating point compare */ fcomp(p); break; case 'H': /* assign of longlong between regs */ rmove(DECRA(p->n_right->n_reg, 0), DECRA(p->n_left->n_reg, 0), LONGLONG); break; case 'I': /* float casts */ fcast(p); break; case 'J': /* convert unsigned long long to floating point */ ulltofp(p); break; case 'K': /* Load longlong reg into another reg */ rmove(regno(p), DECRA(p->n_reg, 0), LONGLONG); break; case 'M': /* Output sconv move, if needed */ l = getlr(p, 'L'); /* XXX fixneed: regnum */ pr = DECRA(p->n_reg, 0); lr = DECRA(l->n_reg, 0); if ((pr == AL && lr == EAX) || (pr == BL && lr == EBX) || (pr == CL && lr == ECX) || (pr == DL && lr == EDX)) ; else printf(" movb %%%cl,%s\n", rnames[lr][2], rnames[pr]); l->n_rval = l->n_reg = p->n_reg; /* XXX - not pretty */ break; case 'N': /* output extended reg name */ printf("%s", rnames[getlr(p, '1')->n_rval]); break; case 'O': /* print out emulated ops */ pr = 16; if (p->n_op == RS || p->n_op == LS) { llshft(p); break; } else if (p->n_op == MUL) { printf("\timull %%ecx, %%edx\n"); printf("\timull %%eax, %%esi\n"); printf("\taddl %%edx, %%esi\n"); printf("\tmull %%ecx\n"); printf("\taddl %%esi, %%edx\n"); break; } expand(p, INCREG, "\tpushl UR\n\tpushl AR\n"); expand(p, INCREG, "\tpushl UL\n\tpushl AL\n"); if (p->n_op == DIV && p->n_type == ULONGLONG) ch = "udiv"; else if (p->n_op == DIV) ch = "div"; else if (p->n_op == MOD && p->n_type == ULONGLONG) ch = "umod"; else if (p->n_op == MOD) ch = "mod"; else ch = 0, comperr("ZO"); #ifdef ELFABI printf("\tcall " EXPREFIX "__%sdi3%s\n\taddl $%d,%s\n", ch, (kflag ? "@PLT" : ""), pr, rnames[ESP]); #else printf("\tcall " EXPREFIX "__%sdi3\n\taddl $%d,%s\n", ch, pr, rnames[ESP]); #endif break; case 'Q': /* emit struct assign */ /* * Put out some combination of movs{b,w,l} * esi/edi/ecx are available. */ expand(p, INAREG, " leal AL,%edi\n"); ap = attr_find(p->n_ap, ATTR_P2STRUCT); if (ap->iarg(0) < 32) { int i = ap->iarg(0) >> 2; while (i) { expand(p, INAREG, " movsl\n"); i--; } } else {
void zzzcode(NODE *p, int c) { struct attr *ap; NODE *l; int pr, lr; char *ch; char sv; switch (c) { case 'A': /* swap st0 and st1 if right is evaluated second */ if ((p->n_su & DORIGHT) == 0) { if (logop(p->n_op)) printf(" fxch\n"); else printf("r"); } break; case 'C': /* remove from stack after subroutine call */ #ifdef notdef if (p->n_left->n_flags & FSTDCALL) break; #endif pr = p->n_qual; if (attr_find(p->n_ap, ATTR_I86_FPPOP)) printf(" fstp st(0)\n"); if (p->n_op == UCALL) return; /* XXX remove ZC from UCALL */ if (pr) { if (pr == 2) printf(" inc sp\n inc sp\n"); else printf(" add sp,#%d\n", pr); } break; case 'D': /* Long comparision */ twollcomp(p); break; case 'F': /* Structure argument */ starg(p); break; case 'G': /* Floating point compare */ fcomp(p); break; case 'H': /* assign of long between regs */ rmove(DECRA(p->n_right->n_reg, 0), DECRA(p->n_left->n_reg, 0), LONGLONG); break; case 'I': /* float casts */ fcast(p); break; case 'J': /* convert unsigned long long to floating point */ ulltofp(p); break; case 'K': /* Load long reg into another reg */ rmove(regno(p), DECRA(p->n_reg, 0), LONGLONG); break; case 'M': /* Output sconv move, if needed */ l = getlr(p, 'L'); /* XXX fixneed: regnum */ pr = DECRA(p->n_reg, 0); lr = DECRA(l->n_reg, 0); if ((pr == AL && lr == AX) || (pr == BL && lr == BX) || (pr == CL && lr == CX) || (pr == DL && lr == DX)) ; else printf(" mov %s, %cL\n", rnames[pr], rnames[lr][1]); l->n_rval = l->n_reg = p->n_reg; /* XXX - not pretty */ break; case 'N': /* output extended reg name */ printf("%s", rnames[getlr(p, '1')->n_rval]); break; case 'O': /* print out emulated ops */ pr = 8; sv = 'l'; #if 0 if (p->n_op == RS || p->n_op == LS) { llshft(p); break; } #endif if (p->n_op != RS && p->n_op != LS) { /* For 64bit we will need to push pointers not u64 */ expand(p, INCREG, "\tpush UR\n\tpush AR\n"); expand(p, INCREG, "\tpush UL\n\tpush AL\n"); } else { /* AR is a BREG so this goes wrong.. need an AREG but putting an AREG in the table rule makes the compiler shit itself - FIXME */ expand(p, INAREG, "\tpush AR\n"); expand(p, INCREG, "\tpush UL\n\tpush AL\n"); pr = 6; } if (p->n_type == LONGLONG || p->n_type == ULONGLONG) sv = 'L'; if (p->n_op == DIV && (p->n_type == ULONG || p->n_type == ULONGLONG)) ch = "udiv"; else if (p->n_op == MUL && (p->n_type == ULONG || p->n_type == ULONGLONG)) ch = "umul"; else if (p->n_op == DIV) ch = "div"; else if (p->n_op == MUL) ch = "mul"; else if (p->n_op == MOD && (p->n_type == ULONG || p->n_type == ULONGLONG)) ch = "umod"; else if (p->n_op == MOD) ch = "mod"; else if (p->n_op == LS) ch = "ls"; else if (p->n_op == RS && (p->n_type == ULONG || p->n_type == ULONGLONG)) ch = "rs"; else if (p->n_op == RS) ch = "urs"; else ch = 0, comperr("ZO"); printf("\tcall " EXPREFIX "__%c%sdi3\n\tadd %s,#%d\n", sv, ch, rnames[SP], pr); break; case 'P': /* typeless right hand */ suppress_type = 1; break; case 'Q': /* emit struct assign */ /* * Put out some combination of movs{b,w} * si/di/cx are available. * FIXME: review es: and direction flag implications */ expand(p, INAREG, " lea al,di\n"); ap = attr_find(p->n_ap, ATTR_P2STRUCT); if (ap->iarg(0) < 32) { int i = ap->iarg(0) >> 1; while (i) { expand(p, INAREG, " movsw\n"); i--; } } else {
int fightmonster () { register int i, rr, cc, mdir = NONE, mbad = NONE, danger = 0; int melee = 0, adjacent = 0, alertmonster = 0; int wanddir = NONE, m = NONE, howmean; char mon, monc = ':', *monster; /* Check for adjacent monsters */ for (i = 0; i < mlistlen; i++) { rr = mlist[i].mrow; cc = mlist[i].mcol; if (max (abs (atrow-rr), abs (atcol-cc)) == 1) { if (mlist[i].q != ASLEEP) { if (mlist[i].q != HELD || Hp >= Hpmax || !havefood (1)) { melee = 1; if (mlist[i].q == AWAKE) alertmonster = 1; } } } } if (!melee) return (0); /* No one to fight */ /* Loop to find worst monster and tally danger & number adjacent */ for (i = 0; i < mlistlen; i++) { rr = mlist[i].mrow; cc = mlist[i].mcol; /* Monster position */ /* * If the monster is adjacent and is either awake or * we dont know yet whether he is asleep, but we havent * see any alert monsters yet. */ if (max (abs (atrow-rr), abs (atcol-cc)) == 1 && (alertmonster ? mlist[i].q == AWAKE : mlist[i].q != ASLEEP)) /* DR Utexas 26 Jan 84 */ { mon = mlist[i].chr; /* Record the monster type */ monster = monname (mon); /* Record the monster name */ danger += maxhitchar(mon); /* Add to the danger */ /* If he is adjacent, add to the adj count */ if (onrc (CANGO, rr, atcol) && onrc (CANGO, atrow, cc)) { adjacent++; howmean = isholder (monster) ? 10000 : avghit(i); /* If he is adjacent and the worst monster yet, save him */ if ((howmean > mbad) || (mdir < 0)) { wanddir = mdir = direc (rr-atrow, cc-atcol); monc = mon; m = i; mbad = howmean; } } /* If we havent yet a line of sight, check this guy out */ else if (wanddir == NONE) { wanddir = direc (rr-atrow, cc-atcol); } /* Debugging breakpoint */ dwait (D_BATTLE, "%c <%d,%d>, danger %d, worst %c(%d,%d), total %d", screen[rr][cc], rr-atrow, cc-atcol, danger, monc, mdir, mbad, adjacent); } } /* * The following variables have now been set: * * monc: The letter of the worst monster we can hit * mbad: Relative scale 0 to 26, how bad is (s)he * mdir: Which direction to him/her * danger: How many hit points can (s)he/they do this round? * wanddir: Direction of worst monster, even if we cant move to it. */ /* * Check whether the battlestations expert has a suggested action. */ monster = monname (monc); if (battlestations (m, monster, mbad, danger, adjacent ? mdir : wanddir, adjacent ? 1 : 2, alertmonster, max (1, adjacent))) { foughtmonster = DIDFIGHT; return (1); } /* * If we did not wait for him last turn, and he is not adjacent, * let him move to us (otherwise, he gets to hits us first). */ if (!lyinginwait && !adjacent) { command (T_FIGHTING, "s"); dwait (D_BATTLE, "Lying in wait..."); lyinginwait = 1; foughtmonster = DIDFIGHT; return (1); } /* If we are here but have no direction, there was a bug somewhere */ if (mdir < 0) { dwait (D_BATTLE, "Adjacent, but no direction known!"); return (0); } /* If we could die this round, tell the user about it */ if (danger >= Hp) display ("In trouble..."); /* Well, nothing better than to hit the beast! Tell dwait about it */ dwait (D_BATTLE, "Attacking %s(%d) direction %d (total danger %d)...", monster, mbad, mdir, danger); /* Record the monster type */ lastmonster = monc-'A'+1; /* Move towards the monster (this causes us to hit him) */ rmove (1, mdir, T_FIGHTING); lyinginwait = 0; foughtmonster = DIDFIGHT; return (1); }