// NOTE: we must check if(mtmp->mimic) before calling this routine void seemimic(struct monst *mtmp) { mtmp->mimic = 0; mtmp->mappearance = 0; unpmon(mtmp); pmon(mtmp); }
void rloc(struct monst *mtmp) { int tx, ty; char ch = mtmp->data->mlet; #ifndef NOWORM if (ch == 'w' && mtmp->mx) /* do not relocate worms */ return; #endif /* NOWORM */ do { tx = rn1(COLNO - 3, 2); ty = rn2(ROWNO); } while (!goodpos(tx, ty)); mtmp->mx = tx; mtmp->my = ty; if (u.ustuck == mtmp) { if (u.uswallow) { u.ux = tx; u.uy = ty; docrt(); } else u.ustuck = 0; } pmon(mtmp); }
/* NOTE: we must check if (mtmp->mimic) before calling this routine */ void see_mimic(monst_t *mtmp) // was seemimic { mtmp->bitflags &= ~M_IS_MIMIC; // mtmp->mimic = 0; mtmp->mappearance = 0; // hmmm unpmon(mtmp); pmon(mtmp); }
/* Make monster mtmp next to you (if possible) */ void mnexto(struct monst *mtmp) { coord mm; mm = enexto(u.ux, u.uy); mtmp->mx = mm.x; mtmp->my = mm.y; pmon(mtmp); }
/* make md run through the cave */ void mdrush(struct monst *md, boolean away) { int uroom = inroom(u.ux, u.uy); if (uroom >= 0) { int tmp = rooms[uroom].fdoor; int cnt = rooms[uroom].doorct; int fx = u.ux, fy = u.uy; while (cnt--) { if (dist(fx, fy) < dist(doors[tmp].x, doors[tmp].y)) { fx = doors[tmp].x; fy = doors[tmp].y; } tmp++; } tmp_at(-1, md->data->mlet); /* open call */ if (away) { /* interchange origin and destination */ unpmon(md); tmp = fx; fx = md->mx; md->mx = tmp; tmp = fy; fy = md->my; md->my = tmp; } while (fx != md->mx || fy != md->my) { int dx, dy, nfx = fx, nfy = fy, d1, d2; tmp_at(fx, fy); d1 = DIST(fx, fy, md->mx, md->my); for (dx = -1; dx <= 1; dx++) for (dy = -1; dy <= 1; dy++) if (dx || dy) { d2 = DIST(fx + dx, fy + dy, md->mx, md->my); if (d2 < d1) { d1 = d2; nfx = fx + dx; nfy = fy + dy; } } if (nfx != fx || nfy != fy) { fx = nfx; fy = nfy; } else { if (!away) { md->mx = fx; md->my = fy; } break; } } tmp_at(-1, -1); /* close call */ } if (!away) pmon(md); }
void rloc(struct monst *mtmp) { int tx, ty; do { tx = rn1(COLNO - 3, 2); ty = rn2(ROWNO); } while (!goodpos(tx, ty)); mtmp->mx = tx; mtmp->my = ty; pmon(mtmp); }
void justswld(struct monst *mtmp, char *name) { mtmp->mx = u.ux; mtmp->my = u.uy; u.ustuck = mtmp; pmon(mtmp); kludge("%s swallows you!", name); more(); seeoff(1); u.uswallow = 1; swallowed(); }
static void clonewiz(struct monst *mtmp) { struct monst *mtmp2; if ((mtmp2 = makemon(PM_WIZARD, mtmp->mx, mtmp->my))) { flags.no_of_wizards = 2; unpmon(mtmp2); mtmp2->mappearance = wizapp[rn2(sizeof(wizapp)-1)]; pmon(mtmp); } }
/* * Make a chameleon look like a new monster * returns 1 if the monster actuall changed */ int newcham(struct monst *mtmp, struct permonst *mdat) { int mhp; int hpn; int hpd; /* Still the same monster */ if(mdat == mtmp->data) { return 0; } #ifndef NOWORM /* Throw tail away */ if(mtmp->wormno) { wormdead(mtmp); } #endif hpn = mtmp->mhp; hpd = mtmp->data->mlevel * 8; if(hpd == 0) { hpd = 4; } mtmp->data = mdat; mhp = mdat->mlevel * 8; /* New hp: same fraction of max as before */ mtmp->mhp = 2 + ((hpn * mhp) / hpd); hpn = mtmp->orig_hp; mtmp->orig_hp = 2 + ((hpn * mhp) / hpd); if(mdat->mlet == 'I') { mtmp->minvis = 1; } else { mtmp->minvis = 0; } #ifndef NOWORM if((mdat->mlet == 'w') && (getwn(mtmp) != 0)) { initworm(mtmp); } #endif /* Necessary for 'I' and to force pmon */ unpmon(mtmp); pmon(mtmp); return 1; }
int wiz_hit(struct monst *mtmp) { /* if we have stolen or found the amulet, we disappear */ if(mtmp->minvent && mtmp->minvent->olet == AMULET_SYM && mtmp->minvent->spe == 0) { /* vanish -- very primitive */ fall_down(mtmp); return(1); } /* if it is lying around someplace, we teleport to it */ if(!carrying(AMULET_OF_YENDOR)) { struct obj *otmp; for(otmp = fobj; otmp; otmp = otmp->nobj) if(otmp->olet == AMULET_SYM && !otmp->spe) { if((u.ux != otmp->ox || u.uy != otmp->oy) && !m_at(otmp->ox, otmp->oy)) { /* teleport to it and pick it up */ mtmp->mx = otmp->ox; mtmp->my = otmp->oy; freeobj(otmp); mpickobj(mtmp, otmp); pmon(mtmp); return(0); } goto hithim; } return(0); /* we don't know where it is */ } hithim: if(rn2(2)) { /* hit - perhaps steal */ /* if hit 1/20 chance of stealing amulet & vanish - amulet is on level 26 again. */ if(hitu(mtmp, d(mtmp->data->damn,mtmp->data->damd)) && !rn2(20) && stealamulet(mtmp)) ; } else inrange(mtmp); /* try magic */ return(0); }
void rloc(struct monst *mtmp) { int tx; int ty; char ch = mtmp->data->mlet; #ifndef NOWORM if((ch == 'w') && (mtmp->mx)) { /* Do not relocate worms */ return; } #endif tx = rn1(COLNO - 3, 2); ty = rn2(ROWNO); while(goodpos(tx, ty) == 0) { tx = rn1(COLNO - 3, 2); ty = rn2(ROWNO); } mtmp->mx = tx; mtmp->my = ty; if(u.ustuck == mtmp) { if(u.uswallow != 0) { u.ux = tx; u.uy = ty; docrt(); } else { u.ustuck = 0; } } pmon(mtmp); }
int gd_move() { int x,y,dx,dy,gx,gy,nx,ny,typ; struct fakecorridor *fcp; struct rm *crm; if(!guard || gdlevel != dlevel){ impossible("Where is the guard?"); return(2); /* died */ } if(u.ugold || goldincorridor()) return(0); /* didnt move */ if(dist(guard->mx,guard->my) > 1 || EGD->gddone) { restfakecorr(); return(0); /* didnt move */ } x = guard->mx; y = guard->my; /* look around (hor & vert only) for accessible places */ for(nx = x-1; nx <= x+1; nx++) for(ny = y-1; ny <= y+1; ny++) { if(nx == x || ny == y) if(nx != x || ny != y) if(isok(nx,ny)) if(!IS_WALL(typ = (crm = &levl[nx][ny])->typ) && typ != POOL) { int i; for(i = EGD->fcbeg; i < EGD->fcend; i++) if(EGD->fakecorr[i].fx == nx && EGD->fakecorr[i].fy == ny) goto nextnxy; if((i = inroom(nx,ny)) >= 0 && rooms[i].rtype == VAULT) goto nextnxy; /* seems we found a good place to leave him alone */ EGD->gddone = 1; if(ACCESSIBLE(typ)) goto newpos; crm->typ = (typ == SCORR) ? CORR : DOOR; goto proceed; } nextnxy: ; } nx = x; ny = y; gx = EGD->gdx; gy = EGD->gdy; dx = (gx > x) ? 1 : (gx < x) ? -1 : 0; dy = (gy > y) ? 1 : (gy < y) ? -1 : 0; if(abs(gx-x) >= abs(gy-y)) nx += dx; else ny += dy; while((typ = (crm = &levl[nx][ny])->typ) != 0) { /* in view of the above we must have IS_WALL(typ) or typ == POOL */ /* must be a wall here */ if(isok(nx+nx-x,ny+ny-y) && typ != POOL && ZAP_POS(levl[nx+nx-x][ny+ny-y].typ)){ crm->typ = DOOR; goto proceed; } if(dy && nx != x) { nx = x; ny = y+dy; continue; } if(dx && ny != y) { ny = y; nx = x+dx; dy = 0; continue; } /* I don't like this, but ... */ crm->typ = DOOR; goto proceed; } crm->typ = CORR; proceed: if(cansee(nx,ny)) { mnewsym(nx,ny); prl(nx,ny); } fcp = &(EGD->fakecorr[EGD->fcend]); if(EGD->fcend++ == FCSIZ) panic("fakecorr overflow"); fcp->fx = nx; fcp->fy = ny; fcp->ftyp = typ; newpos: if(EGD->gddone) nx = ny = 0; guard->mx = nx; guard->my = ny; pmon(guard); restfakecorr(); return(1); }
void invault() { int tmp = inroom(u.ux, u.uy); if(tmp < 0 || rooms[tmp].rtype != VAULT) { u.uinvault = 0; return; } if(++u.uinvault % 50 == 0 && (!guard || gdlevel != dlevel)) { char buf[BUFSZ]; int x,y,dd,gx,gy; /* first find the goal for the guard */ for(dd = 1; (dd < ROWNO || dd < COLNO); dd++) { for(y = u.uy-dd; y <= u.uy+dd; y++) { if(y < 0 || y > ROWNO-1) continue; for(x = u.ux-dd; x <= u.ux+dd; x++) { if(y != u.uy-dd && y != u.uy+dd && x != u.ux-dd) x = u.ux+dd; if(x < 0 || x > COLNO-1) continue; if(levl[x][y].typ == CORR) goto fnd; } } } impossible("Not a single corridor on this level??"); tele(); return; fnd: gx = x; gy = y; /* next find a good place for a door in the wall */ x = u.ux; y = u.uy; while(levl[x][y].typ == ROOM) { int dx,dy; dx = (gx > x) ? 1 : (gx < x) ? -1 : 0; dy = (gy > y) ? 1 : (gy < y) ? -1 : 0; if(abs(gx-x) >= abs(gy-y)) x += dx; else y += dy; } /* make something interesting happen */ if(!(guard = makemon(&pm_guard,x,y))) return; guard->isgd = guard->mpeaceful = 1; EGD->gddone = 0; gdlevel = dlevel; if(!cansee(guard->mx, guard->my)) { mondead(guard); guard = 0; return; } pline("Suddenly one of the Vault's guards enters!"); pmon(guard); do { pline("\"Hello stranger, who are you?\" - "); getlin(buf); } while (!letter(buf[0])); if(!strcmp(buf, "Croesus") || !strcmp(buf, "Kroisos")) { pline("\"Oh, yes - of course. Sorry to have disturbed you.\""); mondead(guard); guard = 0; return; } clrlin(); pline("\"I don't know you.\""); if(!u.ugold) pline("\"Please follow me.\""); else { pline("\"Most likely all that gold was stolen from this vault.\""); pline("\"Please drop your gold (say d$ ) and follow me.\""); } EGD->gdx = gx; EGD->gdy = gy; EGD->fcbeg = 0; EGD->fakecorr[0].fx = x; EGD->fakecorr[0].fy = y; EGD->fakecorr[0].ftyp = levl[x][y].typ; levl[x][y].typ = DOOR; EGD->fcend = 1; } }
static int parse_options(int argc, char *argv[]) { int c; int opt_index = -1; gn_error rc; /* Every option should be in this array. */ static struct option long_options[] = { /* FIXME: these comments are nice, but they would be more useful as docs for the user */ /* Display usage. */ { "help", optional_argument, NULL, OPT_HELP }, /* Display version and build information. */ { "version", no_argument, NULL, OPT_VERSION }, /* Monitor mode */ { "monitor", optional_argument, NULL, OPT_MONITOR }, /* Alternate config file location */ { "config", required_argument, NULL, OPT_CONFIGFILE }, /* Alternate phone section from the config */ { "phone", required_argument, NULL, OPT_CONFIGMODEL }, /* Get Security Code */ { "getsecuritycode", no_argument, NULL, OPT_GETSECURITYCODE }, /* Enter Security Code mode */ { "entersecuritycode", required_argument, NULL, OPT_ENTERSECURITYCODE }, /* Get Security Code status */ { "getsecuritycodestatus", no_argument, NULL, OPT_GETSECURITYCODESTATUS }, /* Change Security Code */ { "changesecuritycode", required_argument, NULL, OPT_CHANGESECURITYCODE }, /* Set date and time */ { "setdatetime", optional_argument, NULL, OPT_SETDATETIME }, /* Get date and time mode */ { "getdatetime", no_argument, NULL, OPT_GETDATETIME }, /* Set alarm */ { "setalarm", optional_argument, NULL, OPT_SETALARM }, /* Get alarm */ { "getalarm", no_argument, NULL, OPT_GETALARM }, /* Voice call mode */ { "dialvoice", required_argument, NULL, OPT_DIALVOICE }, /* Answer the incoming call */ { "answercall", required_argument, NULL, OPT_ANSWERCALL }, /* Hangup call */ { "hangup", required_argument, NULL, OPT_HANGUP }, /* Get ToDo note mode */ { "gettodo", required_argument, NULL, OPT_GETTODO }, /* Write ToDo note mode */ { "writetodo", required_argument, NULL, OPT_WRITETODO }, /* Delete all ToDo notes mode */ { "deletealltodos", no_argument, NULL, OPT_DELETEALLTODOS }, /* Get calendar note mode */ { "getcalendarnote", required_argument, NULL, OPT_GETCALENDARNOTE }, /* Write calendar note mode */ { "writecalendarnote", required_argument, NULL, OPT_WRITECALENDARNOTE }, /* Delete calendar note mode */ { "deletecalendarnote", required_argument, NULL, OPT_DELCALENDARNOTE }, /* Get display status mode */ { "getdisplaystatus", no_argument, NULL, OPT_GETDISPLAYSTATUS }, /* Get memory mode */ { "getphonebook", required_argument, NULL, OPT_GETPHONEBOOK }, /* Write phonebook (memory) mode */ { "writephonebook", optional_argument, NULL, OPT_WRITEPHONEBOOK }, /* Delete phonebook entry from memory mode */ { "deletephonebook", required_argument, NULL, OPT_DELETEPHONEBOOK }, /* Get speed dial mode */ { "getspeeddial", required_argument, NULL, OPT_GETSPEEDDIAL }, /* Set speed dial mode */ { "setspeeddial", required_argument, NULL, OPT_SETSPEEDDIAL }, /* Create SMS folder mode */ { "createsmsfolder", required_argument, NULL, OPT_CREATESMSFOLDER }, /* Delete SMS folder mode */ { "deletesmsfolder", required_argument, NULL, OPT_DELETESMSFOLDER }, /* Show SMS folder names and its attributes */ { "showsmsfolderstatus",no_argument, NULL, OPT_SHOWSMSFOLDERSTATUS }, /* Get SMS message mode */ { "getsms", required_argument, NULL, OPT_GETSMS }, /* Delete SMS message mode */ { "deletesms", required_argument, NULL, OPT_DELETESMS }, /* Send SMS message mode */ { "sendsms", required_argument, NULL, OPT_SENDSMS }, /* Ssve SMS message mode */ { "savesms", optional_argument, NULL, OPT_SAVESMS }, /* Send logo as SMS message mode */ { "sendlogo", required_argument, NULL, OPT_SENDLOGO }, /* Send ringtone as SMS message */ { "sendringtone", required_argument, NULL, OPT_SENDRINGTONE }, /* Get ringtone */ { "getringtone", required_argument, NULL, OPT_GETRINGTONE }, /* Set ringtone */ { "setringtone", required_argument, NULL, OPT_SETRINGTONE }, /* Play ringtone */ { "playringtone", required_argument, NULL, OPT_PLAYRINGTONE }, /* Convert ringtone */ { "ringtoneconvert", required_argument, NULL, OPT_RINGTONECONVERT }, /* Get list of the ringtones */ { "getringtonelist", no_argument, NULL, OPT_GETRINGTONELIST }, /* Delete ringtones */ { "deleteringtone", required_argument, NULL, OPT_DELETERINGTONE }, /* Get SMS center number mode */ { "getsmsc", optional_argument, NULL, OPT_GETSMSC }, /* Set SMS center number mode */ { "setsmsc", no_argument, NULL, OPT_SETSMSC }, /* For development purposes: run in passive monitoring mode */ { "pmon", no_argument, NULL, OPT_PMON }, /* NetMonitor mode */ { "netmonitor", required_argument, NULL, OPT_NETMONITOR }, /* Identify */ { "identify", no_argument, NULL, OPT_IDENTIFY }, /* Send DTMF sequence */ { "senddtmf", required_argument, NULL, OPT_SENDDTMF }, /* Resets the phone */ { "reset", required_argument, NULL, OPT_RESET }, /* Set logo */ { "setlogo", required_argument, NULL, OPT_SETLOGO }, /* Get logo */ { "getlogo", required_argument, NULL, OPT_GETLOGO }, /* View logo */ { "viewlogo", required_argument, NULL, OPT_VIEWLOGO }, /* Show profile */ { "getprofile", optional_argument, NULL, OPT_GETPROFILE }, /* Set profile */ { "setprofile", no_argument, NULL, OPT_SETPROFILE }, /* Get the active profile */ { "getactiveprofile", no_argument, NULL, OPT_GETACTIVEPROFILE }, /* Set the active profile */ { "setactiveprofile", required_argument, NULL, OPT_SETACTIVEPROFILE }, /* Show texts from phone's display */ { "displayoutput", no_argument, NULL, OPT_DISPLAYOUTPUT }, /* Simulate pressing the keys */ { "keysequence", no_argument, NULL, OPT_KEYPRESS }, /* Simulate pressing the keys */ { "enterchar", no_argument, NULL, OPT_ENTERCHAR }, /* Divert calls */ { "divert", no_argument, NULL, OPT_DIVERT }, /* SMS reader */ { "smsreader", no_argument, NULL, OPT_SMSREADER }, /* For development purposes: insert you function calls here */ { "foogle", no_argument, NULL, OPT_FOOGLE }, /* Get WAP bookmark */ { "getwapbookmark", required_argument, NULL, OPT_GETWAPBOOKMARK }, /* Write WAP bookmark */ { "writewapbookmark", required_argument, NULL, OPT_WRITEWAPBOOKMARK }, /* Delete WAP bookmark */ { "deletewapbookmark", required_argument, NULL, OPT_DELETEWAPBOOKMARK }, /* Get WAP setting */ { "getwapsetting", required_argument, NULL, OPT_GETWAPSETTING }, /* Write WAP setting */ { "writewapsetting", no_argument, NULL, OPT_WRITEWAPSETTING }, /* Activate WAP setting */ { "activatewapsetting", required_argument, NULL, OPT_ACTIVATEWAPSETTING }, /* List GSM networks */ { "listnetworks", no_argument, NULL, OPT_LISTNETWORKS }, /* Get network info */ { "getnetworkinfo", no_argument, NULL, OPT_GETNETWORKINFO }, /* Get (sim)lock info */ { "getlocksinfo", no_argument, NULL, OPT_GETLOCKSINFO }, /* Get file list */ { "getfilelist", required_argument, NULL, OPT_GETFILELIST }, /* Get file details by id */ { "getfiledetailsbyid", optional_argument, NULL, OPT_GETFILEDETAILSBYID }, /* Get file id */ { "getfileid", required_argument, NULL, OPT_GETFILEID }, /* Get file */ { "getfile", required_argument, NULL, OPT_GETFILE }, /* Get file by id */ { "getfilebyid", required_argument, NULL, OPT_GETFILEBYID }, /* Get all files */ { "getallfiles", required_argument, NULL, OPT_GETALLFILES }, /* Put a file */ { "putfile", required_argument, NULL, OPT_PUTFILE }, /* Delete a file */ { "deletefile", required_argument, NULL, OPT_DELETEFILE }, /* Delete a file by id */ { "deletefilebyid", required_argument, NULL, OPT_DELETEFILEBYID }, /* Shell like interface */ { "shell", no_argument, NULL, OPT_SHELL }, /* Get MMS message mode */ { "getmms", required_argument, NULL, OPT_GETMMS }, /* Delete MMS message mode */ { "deletemms", required_argument, NULL, OPT_DELETEMMS }, /* Check if the phone responds */ { "ping", no_argument, NULL, OPT_PING }, { 0, 0, 0, 0 }, }; /* Every command which requires arguments should have an appropriate entry in this array. */ static struct gnokii_arg_len gals[] = { { OPT_HELP, 1, 100, 0 }, { OPT_CONFIGFILE, 1, 100, 0 }, { OPT_CONFIGMODEL, 1, 100, 0 }, { OPT_ENTERSECURITYCODE, 1, 100, 0 }, { OPT_CHANGESECURITYCODE,1, 1, 0 }, { OPT_SETDATETIME, 0, 5, 0 }, { OPT_SETALARM, 0, 2, 0 }, { OPT_DIALVOICE, 1, 1, 0 }, { OPT_ANSWERCALL, 1, 1, 0 }, { OPT_HANGUP, 1, 1, 0 }, { OPT_GETTODO, 1, 3, 0 }, { OPT_WRITETODO, 2, 3, 0 }, { OPT_GETCALENDARNOTE, 1, 3, 0 }, { OPT_WRITECALENDARNOTE, 2, 3, 0 }, { OPT_DELCALENDARNOTE, 1, 2, 0 }, { OPT_GETPHONEBOOK, 2, 4, 0 }, { OPT_WRITEPHONEBOOK, 0, 10, 0 }, { OPT_DELETEPHONEBOOK, 2, 3, 0 }, { OPT_GETSPEEDDIAL, 1, 1, 0 }, { OPT_SETSPEEDDIAL, 3, 3, 0 }, { OPT_CREATESMSFOLDER, 1, 1, 0 }, { OPT_DELETESMSFOLDER, 1, 1, 0 }, { OPT_GETSMS, 2, 6, 0 }, { OPT_DELETESMS, 2, 3, 0 }, { OPT_SENDSMS, 1, 10, 0 }, { OPT_SAVESMS, 0, 12, 0 }, { OPT_SENDLOGO, 3, 4, GAL_XOR }, { OPT_SENDRINGTONE, 2, 2, 0 }, { OPT_GETSMSC, 0, 3, 0 }, { OPT_GETWELCOMENOTE, 1, 1, 0 }, { OPT_SETWELCOMENOTE, 1, 1, 0 }, { OPT_NETMONITOR, 1, 1, 0 }, { OPT_SENDDTMF, 1, 1, 0 }, { OPT_SETLOGO, 1, 4, 0 }, { OPT_GETLOGO, 1, 4, 0 }, { OPT_VIEWLOGO, 1, 1, 0 }, { OPT_GETRINGTONE, 1, 3, 0 }, { OPT_SETRINGTONE, 1, 5, 0 }, { OPT_PLAYRINGTONE, 1, 3, 0 }, { OPT_RINGTONECONVERT, 2, 2, 0 }, { OPT_DELETERINGTONE, 1, 2, 0 }, { OPT_RESET, 0, 1, 0 }, { OPT_GETPROFILE, 0, 3, 0 }, { OPT_SETACTIVEPROFILE, 1, 1, 0 }, { OPT_DIVERT, 6, 10, 0 }, { OPT_GETWAPBOOKMARK, 1, 1, 0 }, { OPT_WRITEWAPBOOKMARK, 2, 2, 0 }, { OPT_DELETEWAPBOOKMARK, 1, 1, 0 }, { OPT_GETWAPSETTING, 1, 2, 0 }, { OPT_ACTIVATEWAPSETTING,1, 1, 0 }, { OPT_MONITOR, 0, 1, 0 }, { OPT_GETFILELIST, 1, 1, 0 }, { OPT_GETFILEDETAILSBYID,0, 1, 0 }, { OPT_GETFILEID, 1, 1, 0 }, { OPT_GETFILE, 1, 2, 0 }, { OPT_GETFILEBYID, 1, 2, 0 }, { OPT_GETALLFILES, 1, 1, 0 }, { OPT_PUTFILE, 2, 2, 0 }, { OPT_DELETEFILE, 1, 1, 0 }, { OPT_DELETEFILEBYID, 1, 1, 0 }, { OPT_SHELL, 0, 0, 0 }, { OPT_GETMMS, 2, 6, 0 }, { OPT_DELETEMMS, 2, 3, 0 }, { OPT_FOOGLE, 0, 0, 0 }, { OPT_PING, 0, 0, 0 }, { 0, 0, 0, 0 }, }; /* Handle command line arguments. * -c equals to --config * -p equals to --phone */ c = getopt_long(argc, argv, "c:p:", long_options, &opt_index); switch (c) { /* No argument given - we should display usage. */ case -1: return usage(stderr, -1, NULL); /* First, error conditions */ case '?': case ':': /* --shell command does not set argv[0] */ if (argv[0]) fprintf(stderr, _("Use '%s --help' for usage information.\n"), argv[0]); else fprintf(stderr, _("Use '--help' for usage information.\n")); return 1; /* Then, options with no arguments */ case OPT_VERSION: version(); return 0; /* That's a bit ugly... */ case 'c': c = OPT_CONFIGFILE; opt_index = 0; break; case 'p': c = OPT_CONFIGMODEL; opt_index = 1; break; } /* We have to build an array of the arguments which will be passed to the functions. Please note that every text after the --command will be passed as arguments. A syntax like gnokii --cmd1 args --cmd2 args will not work as expected; instead args --cmd2 args is passed as a parameter. */ if (checkargs(c, gals, argc, long_options[opt_index].has_arg)) { return usage(stderr, -1, NULL); } /* Other options that do not need initialization */ switch (c) { case OPT_CONFIGFILE: if (configfile) return usage(stderr, -1, NULL); configfile = optarg; return parse_options(argc, argv); case OPT_CONFIGMODEL: if (configmodel) return usage(stderr, -1, NULL); configmodel = optarg; return parse_options(argc, argv); case OPT_HELP: return usage(stdout, argc, argv); case OPT_VIEWLOGO: return viewlogo(optarg); case OPT_LISTNETWORKS: list_gsm_networks(); return GN_ERR_NONE; case OPT_RINGTONECONVERT: return ringtoneconvert(argc, argv); } /* Initialise the code for the GSM interface. */ if (c != OPT_FOOGLE && state == NULL && businit()) return -1; switch (c) { /* Monitoring options */ case OPT_MONITOR: rc = monitormode(argc, argv, data, state); break; case OPT_GETDISPLAYSTATUS: rc = getdisplaystatus(data, state); break; case OPT_DISPLAYOUTPUT: rc = displayoutput(data, state); break; case OPT_NETMONITOR: rc = netmonitor(optarg, data, state); break; /* SMS options */ case OPT_SENDSMS: rc = sendsms(argc, argv, data, state); break; case OPT_SAVESMS: rc = savesms(argc, argv, data, state); break; case OPT_GETSMS: rc = getsms(argc, argv, data, state); break; case OPT_DELETESMS: rc = deletesms(argc, argv, data, state); break; case OPT_GETSMSC: rc = getsmsc(argc, argv, data, state); break; case OPT_SETSMSC: rc = setsmsc(data, state); break; case OPT_CREATESMSFOLDER: rc = createsmsfolder(optarg, data, state); break; case OPT_DELETESMSFOLDER: rc = deletesmsfolder(optarg, data, state); break; case OPT_SHOWSMSFOLDERSTATUS: rc = showsmsfolderstatus(data, state); break; case OPT_SMSREADER: rc = smsreader(data, state); break; /* Phonebook options */ case OPT_GETPHONEBOOK: rc = getphonebook(argc, argv, data, state); break; case OPT_WRITEPHONEBOOK: rc = writephonebook(argc, argv, data, state); break; case OPT_DELETEPHONEBOOK: rc = deletephonebook(argc, argv, data, state); break; /* Calendar options */ case OPT_GETCALENDARNOTE: rc = getcalendarnote(argc, argv, data, state); break; case OPT_WRITECALENDARNOTE: rc = writecalendarnote(argc, argv, data, state); break; case OPT_DELCALENDARNOTE: rc = deletecalendarnote(argc, argv, data, state); break; /* ToDo options */ case OPT_GETTODO: rc = gettodo(argc, argv, data, state); break; case OPT_WRITETODO: rc = writetodo(argc, argv, data, state); break; case OPT_DELETEALLTODOS: rc = deletealltodos(data, state); break; /* Dialling and call handling options */ case OPT_GETSPEEDDIAL: rc = getspeeddial(optarg, data, state); break; case OPT_SETSPEEDDIAL: rc = setspeeddial(argv, data, state); break; case OPT_DIALVOICE: rc = dialvoice(optarg, data, state); break; case OPT_SENDDTMF: rc = senddtmf(optarg, data, state); break; case OPT_ANSWERCALL: rc = answercall(optarg, data, state); break; case OPT_HANGUP: rc = hangup(optarg, data, state); break; case OPT_DIVERT: rc = divert(argc, argv, data, state); break; /* Profile options */ case OPT_GETPROFILE: rc = getprofile(argc, argv, data, state); break; case OPT_SETPROFILE: rc = setprofile(data, state); break; case OPT_GETACTIVEPROFILE: rc = getactiveprofile(data, state); break; case OPT_SETACTIVEPROFILE: rc = setactiveprofile(argc, argv, data, state); break; /* Phone settings options */ case OPT_RESET: rc = reset(optarg, data, state); break; case OPT_GETDATETIME: rc = getdatetime(data, state); break; case OPT_SETDATETIME: rc = setdatetime(argc, argv, data, state); break; case OPT_GETALARM: rc = getalarm(data, state); break; case OPT_SETALARM: rc = setalarm(argc, argv, data, state); break; /* WAP options */ case OPT_GETWAPBOOKMARK: rc = getwapbookmark(optarg, data, state); break; case OPT_WRITEWAPBOOKMARK: rc = writewapbookmark(argc, argv, data, state); break; case OPT_DELETEWAPBOOKMARK: rc = deletewapbookmark(optarg, data, state); break; case OPT_GETWAPSETTING: rc = getwapsetting(argc, argv, data, state); break; case OPT_WRITEWAPSETTING: rc = writewapsetting(data, state); break; case OPT_ACTIVATEWAPSETTING: rc = activatewapsetting(optarg, data, state); break; /* Logo options */ case OPT_SENDLOGO: rc = sendlogo(argc, argv, data, state); break; case OPT_SETLOGO: rc = setlogo(argc, argv, data, state); break; case OPT_GETLOGO: rc = getlogo(argc, argv, data, state); break; /* Ringtone options */ case OPT_SENDRINGTONE: rc = sendringtone(argc, argv, data, state); break; case OPT_GETRINGTONE: rc = getringtone(argc, argv, data, state); break; case OPT_SETRINGTONE: rc = setringtone(argc, argv, data, state); break; case OPT_PLAYRINGTONE: rc = playringtone(argc, argv, data, state); break; case OPT_GETRINGTONELIST: rc = getringtonelist(data, state); break; case OPT_DELETERINGTONE: rc = deleteringtone(argc, argv, data, state); break; /* Security options */ case OPT_IDENTIFY: rc = identify(state); break; case OPT_GETLOCKSINFO: rc = getlocksinfo(data, state); break; case OPT_GETSECURITYCODE: rc = getsecuritycode(data, state); break; case OPT_ENTERSECURITYCODE: rc = entersecuritycode(optarg, data, state); if (rc == GN_ERR_NONE && optind < argc) return parse_options(argc, argv); break; case OPT_GETSECURITYCODESTATUS: rc = getsecuritycodestatus(data, state); break; case OPT_CHANGESECURITYCODE: rc = changesecuritycode(optarg, data, state); break; /* File options */ case OPT_GETFILELIST: rc = getfilelist(optarg, data, state); break; case OPT_GETFILEDETAILSBYID: rc = getfiledetailsbyid(argc, argv, data, state); break; case OPT_GETFILEID: rc = getfileid(optarg, data, state); break; case OPT_GETFILE: rc = getfile(argc, argv, data, state); break; case OPT_GETFILEBYID: rc = getfilebyid(argc, argv, data, state); break; case OPT_GETALLFILES: rc = getallfiles(optarg, data, state); break; case OPT_PUTFILE: rc = putfile(argc, argv, data, state); break; case OPT_DELETEFILE: rc = deletefile(optarg, data, state); break; case OPT_DELETEFILEBYID: rc = deletefilebyid(optarg, data, state); break; /* Misc options */ case OPT_PMON: rc = pmon(data, state); break; case OPT_KEYPRESS: rc = presskeysequence(data, state); break; case OPT_ENTERCHAR: rc = enterchar(data, state); break; case OPT_GETNETWORKINFO: rc = getnetworkinfo(data, state); break; case OPT_SHELL: rc = shell(data, state); break; case OPT_PING: rc = ping(data, state); break; #ifndef WIN32 case OPT_FOOGLE: rc = foogle(argc, argv); break; #endif /* MMS options */ case OPT_GETMMS: rc = getmms(argc, argv, data, state); break; case OPT_DELETEMMS: rc = deletemms(argc, argv, data, state); break; default: rc = GN_ERR_FAILED; fprintf(stderr, _("Unknown option: %d\n"), c); break; } return rc; }
/* return 0 (no move), 1 (move) or 2 (dead) */ int dog_move(struct monst *mtmp, int after) { int nx, ny, omx, omy, appr, nearer, j; int udist, chi, i, whappr; struct monst *mtmp2; struct permonst *mdat = mtmp->data; struct edog *edog = EDOG(mtmp); struct obj *obj; struct trap *trap; xchar cnt, chcnt, nix, niy; schar dogroom, uroom; xchar gx, gy, gtyp, otyp; /* current goal */ coord poss[9]; int info[9]; #define GDIST(x,y) ((x-gx)*(x-gx) + (y-gy)*(y-gy)) #define DDIST(x,y) ((x-omx)*(x-omx) + (y-omy)*(y-omy)) if(moves <= edog->eattime) return(0); /* dog is still eating */ omx = mtmp->mx; omy = mtmp->my; whappr = (moves - EDOG(mtmp)->whistletime < 5); if(moves > edog->hungrytime + 500 && !mtmp->mconf){ mtmp->mconf = 1; mtmp->mhpmax /= 3; if(mtmp->mhp > mtmp->mhpmax) mtmp->mhp = mtmp->mhpmax; if(cansee(omx,omy)) pline("%s is confused from hunger.", Monnam(mtmp)); else pline("You feel worried about %s.", monnam(mtmp)); } else if(moves > edog->hungrytime + 750 || mtmp->mhp < 1){ if(cansee(omx,omy)) pline("%s dies from hunger.", Monnam(mtmp)); else pline("You have a sad feeling for a moment, then it passes."); mondied(mtmp); return(2); } dogroom = inroom(omx,omy); uroom = inroom(u.ux,u.uy); udist = dist(omx,omy); /* maybe we tamed him while being swallowed --jgm */ if(!udist) return(0); /* if we are carrying sth then we drop it (perhaps near @) */ /* Note: if apport == 1 then our behaviour is independent of udist */ if(mtmp->minvent){ if(!rn2(udist) || !rn2((int) edog->apport)) if(rn2(10) < edog->apport){ relobj(mtmp, (int) mtmp->minvis); if(edog->apport > 1) edog->apport--; edog->dropdist = udist; /* hpscdi!jon */ edog->droptime = moves; } } else { if ((obj = o_at(omx,omy))) if(!strchr("0_", obj->olet)){ if((otyp = dogfood(obj)) <= CADAVER){ nix = omx; niy = omy; goto eatobj; } if (obj->owt < 10*mtmp->data->mlevel) if (rn2(20) < edog->apport+3) if (rn2(udist) || !rn2((int) edog->apport)){ freeobj(obj); unpobj(obj); /* if(levl[omx][omy].scrsym == obj->olet) newsym(omx,omy); */ mpickobj(mtmp,obj); } } } /* first we look for food */ gtyp = UNDEF; /* no goal as yet */ gx = gy = 0; for(obj = fobj; obj; obj = obj->nobj) { otyp = dogfood(obj); if(otyp > gtyp || otyp == UNDEF) continue; if(inroom(obj->ox,obj->oy) != dogroom) continue; if(otyp < MANFOOD && (dogroom >= 0 || DDIST(obj->ox,obj->oy) < 10)) { if(otyp < gtyp || (otyp == gtyp && DDIST(obj->ox,obj->oy) < DDIST(gx,gy))){ gx = obj->ox; gy = obj->oy; gtyp = otyp; } } else if(gtyp == UNDEF && dogroom >= 0 && uroom == dogroom && !mtmp->minvent && edog->apport > rn2(8)){ gx = obj->ox; gy = obj->oy; gtyp = APPORT; } } if(gtyp == UNDEF || (gtyp != DOGFOOD && gtyp != APPORT && moves < edog->hungrytime)){ if(dogroom < 0 || dogroom == uroom){ gx = u.ux; gy = u.uy; #ifndef QUEST } else { int tmp = rooms[(int)dogroom].fdoor; cnt = rooms[(int)dogroom].doorct; gx = gy = FAR; /* random, far away */ while(cnt--){ if(dist(gx,gy) > dist(doors[tmp].x, doors[tmp].y)){ gx = doors[tmp].x; gy = doors[tmp].y; } tmp++; } /* here gx == FAR e.g. when dog is in a vault */ if(gx == FAR || (gx == omx && gy == omy)){ gx = u.ux; gy = u.uy; } #endif /* QUEST */ } appr = (udist >= 9) ? 1 : (mtmp->mflee) ? -1 : 0; if(after && udist <= 4 && gx == u.ux && gy == u.uy) return(0); if(udist > 1){ if (!IS_ROOM(levl[(int)u.ux][(int)u.uy].typ) || !rn2(4) || whappr || (mtmp->minvent && rn2((int) edog->apport))) appr = 1; } /* if you have dog food he'll follow you more closely */ if (appr == 0) { obj = invent; while(obj){ if(obj->otyp == TRIPE_RATION){ appr = 1; break; } obj = obj->nobj; } } } else appr = 1; /* gtyp != UNDEF */ if(mtmp->mconf) appr = 0; if(gx == u.ux && gy == u.uy && (dogroom != uroom || dogroom < 0)){ coord *cp; cp = gettrack(omx,omy); if(cp){ gx = cp->x; gy = cp->y; } } nix = omx; niy = omy; cnt = mfndpos(mtmp,poss,info,ALLOW_M | ALLOW_TRAPS); chcnt = 0; chi = -1; for(i=0; i<cnt; i++){ nx = poss[i].x; ny = poss[i].y; if(info[i] & ALLOW_M){ mtmp2 = m_at(nx,ny); if(mtmp2->data->mlevel >= mdat->mlevel+2 || mtmp2->data->mlet == 'c') continue; if(after) return(0); /* hit only once each move */ if(hitmm(mtmp, mtmp2) == 1 && rn2(4) && mtmp2->mlstmv != moves && hitmm(mtmp2,mtmp) == 2) return(2); return(0); } /* dog avoids traps */ /* but perhaps we have to pass a trap in order to follow @ */ if((info[i] & ALLOW_TRAPS) && (trap = t_at(nx,ny))){ if(!trap->tseen && rn2(40)) continue; if(rn2(10)) continue; } /* dog eschewes cursed objects */ /* but likes dog food */ obj = fobj; while(obj){ if(obj->ox != nx || obj->oy != ny) goto nextobj; if(obj->cursed) goto nxti; if(obj->olet == FOOD_SYM && (otyp = dogfood(obj)) < MANFOOD && (otyp < ACCFOOD || edog->hungrytime <= moves)){ /* Note: our dog likes the food so much that he might eat it even when it conceals a cursed object */ nix = nx; niy = ny; chi = i; eatobj: edog->eattime = moves + obj->quan * objects[obj->otyp].oc_delay; if(edog->hungrytime < moves) edog->hungrytime = moves; edog->hungrytime += 5*obj->quan * objects[obj->otyp].nutrition; mtmp->mconf = 0; if(cansee(nix,niy)) pline("%s ate %s.", Monnam(mtmp), doname(obj)); /* perhaps this was a reward */ if(otyp != CADAVER) edog->apport += 200/(edog->dropdist+moves-edog->droptime); delobj(obj); goto newdogpos; } nextobj: obj = obj->nobj; } for(j=0; j<MTSZ && j<cnt-1; j++) if(nx == mtmp->mtrack[j].x && ny == mtmp->mtrack[j].y) if(rn2(4*(cnt-j))) goto nxti; /* Some stupid C compilers cannot compute the whole expression at once. */ nearer = GDIST(nx,ny); nearer -= GDIST(nix,niy); nearer *= appr; if((nearer == 0 && !rn2(++chcnt)) || nearer<0 || (nearer > 0 && !whappr && ((omx == nix && omy == niy && !rn2(3)) || !rn2(12)) )){ nix = nx; niy = ny; if(nearer < 0) chcnt = 0; chi = i; } nxti: ; } newdogpos: if(nix != omx || niy != omy){ if(info[chi] & ALLOW_U){ (void) hitu(mtmp, d(mdat->damn, mdat->damd)+1); return(0); } mtmp->mx = nix; mtmp->my = niy; for(j=MTSZ-1; j>0; j--) mtmp->mtrack[j] = mtmp->mtrack[j-1]; mtmp->mtrack[0].x = omx; mtmp->mtrack[0].y = omy; } if(mintrap(mtmp) == 2) /* he died */ return(2); pmon(mtmp); return(1); }
void potionhit(struct monst *mon, struct obj *obj) { char *botlnam = bottlenames[rn2(SIZE(bottlenames))]; boolean uclose, isyou = (mon == &youmonst); if(isyou) { uclose = TRUE; pline("The %s crashes on your head and breaks into shivers.", botlnam); losehp(rnd(2), "thrown potion"); } else { uclose = (dist(mon->mx,mon->my) < 3); /* perhaps 'E' and 'a' have no head? */ pline("The %s crashes on %s's head and breaks into shivers.", botlnam, monnam(mon)); if(rn2(5) && mon->mhp > 1) mon->mhp--; } pline("The %s evaporates.", xname(obj)); if(!isyou && !rn2(3)) switch(obj->otyp) { case POT_RESTORE_STRENGTH: case POT_GAIN_STRENGTH: case POT_HEALING: case POT_EXTRA_HEALING: if(mon->mhp < mon->mhpmax) { mon->mhp = mon->mhpmax; pline("%s looks sound and hale again!", Monnam(mon)); } break; case POT_SICKNESS: if(mon->mhpmax > 3) mon->mhpmax /= 2; if(mon->mhp > 2) mon->mhp /= 2; break; case POT_CONFUSION: case POT_BOOZE: mon->mconf = 1; break; case POT_INVISIBILITY: unpmon(mon); mon->minvis = 1; pmon(mon); break; case POT_PARALYSIS: mon->mfroz = 1; break; case POT_SPEED: mon->mspeed = MFAST; break; case POT_BLINDNESS: mon->mblinded |= 64 + rn2(64); break; /* case POT_GAIN_LEVEL: case POT_LEVITATION: case POT_FRUIT_JUICE: case POT_MONSTER_DETECTION: case POT_OBJECT_DETECTION: break; */ } if(uclose && rn2(5)) potionbreathe(obj); obfree(obj, Null(obj)); }
/* * shk_move: return 1: he moved 0: he didnt -1: let m_move do it */ int shk_move(struct monst *shkp) { struct monst *mtmp; struct permonst *mdat = shkp->data; xchar gx, gy, omx, omy, nx, ny, nix, niy; schar appr, i; int udist; int z; schar shkroom, chi, chcnt, cnt; boolean uondoor = 0, satdoor, avoid = 0, badinv; coord poss[9]; int info[9]; struct obj *ib = NULL; omx = shkp->mx; omy = shkp->my; if ((udist = dist(omx, omy)) < 3) { if (ANGRY(shkp)) { hitu(shkp, d(mdat->damn, mdat->damd) + 1); return (0); } if (ESHK(shkp)->following) { if (strncmp(ESHK(shkp)->customer, plname, PL_NSIZ)) { pline("Hello %s! I was looking for %s.", plname, ESHK(shkp)->customer); ESHK(shkp)->following = 0; return (0); } if (!ESHK(shkp)->robbed) { /* impossible? */ ESHK(shkp)->following = 0; return (0); } if (moves > followmsg + 4) { pline("Hello %s! Didn't you forget to pay?", plname); followmsg = moves; } if (udist < 2) return (0); } } shkroom = inroom(omx, omy); appr = 1; gx = ESHK(shkp)->shk.x; gy = ESHK(shkp)->shk.y; satdoor = (gx == omx && gy == omy); if (ESHK(shkp)->following || ((z = holetime()) >= 0 && z * z <= udist)) { gx = u.ux; gy = u.uy; if (shkroom < 0 || shkroom != inroom(u.ux, u.uy)) if (udist > 4) return (-1); /* leave it to m_move */ } else if (ANGRY(shkp)) { long saveBlind = Blind; Blind = 0; if (shkp->mcansee && !Invis && cansee(omx, omy)) { gx = u.ux; gy = u.uy; } Blind = saveBlind; avoid = FALSE; } else { #define GDIST(x, y) ((x - gx) * (x - gx) + (y - gy) * (y - gy)) if (Invis) avoid = FALSE; else { uondoor = (u.ux == ESHK(shkp)->shd.x && u.uy == ESHK(shkp)->shd.y); if (uondoor) { if (ESHK(shkp)->billct) pline("Hello %s! Will you please pay before leaving?", plname); badinv = (carrying(PICK_AXE) || carrying(ICE_BOX)); if (satdoor && badinv) return (0); avoid = !badinv; } else { avoid = (u.uinshop && dist(gx, gy) > 8); badinv = FALSE; } if (((!ESHK(shkp)->robbed && !ESHK(shkp)->billct) || avoid) && GDIST(omx, omy) < 3) { if (!badinv && !online(omx, omy)) return (0); if (satdoor) appr = gx = gy = 0; } } } if (omx == gx && omy == gy) return (0); if (shkp->mconf) { avoid = FALSE; appr = 0; } nix = omx; niy = omy; cnt = mfndpos(shkp, poss, info, ALLOW_SSM); if (avoid && uondoor) { /* perhaps we cannot avoid him */ for (i = 0; i < cnt; i++) if (!(info[i] & NOTONL)) goto notonl_ok; avoid = FALSE; notonl_ok: ; } chi = -1; chcnt = 0; for (i = 0; i < cnt; i++) { nx = poss[i].x; ny = poss[i].y; if (levl[nx][ny].typ == ROOM || shkroom != ESHK(shkp)->shoproom || ESHK(shkp)->following) { #ifdef STUPID /* cater for stupid compilers */ int zz; #endif /* STUPID */ if (uondoor && (ib = sobj_at(ICE_BOX, nx, ny))) { nix = nx; niy = ny; chi = i; break; } if (avoid && (info[i] & NOTONL)) continue; if ((!appr && !rn2(++chcnt)) || #ifdef STUPID (appr && (zz = GDIST(nix, niy)) && zz > GDIST(nx, ny)) #else (appr && GDIST(nx, ny) < GDIST(nix, niy)) #endif /* STUPID */ ) { nix = nx; niy = ny; chi = i; } } } if (nix != omx || niy != omy) { if (info[chi] & ALLOW_M) { mtmp = m_at(nix, niy); if (hitmm(shkp, mtmp) == 1 && rn2(3) && hitmm(mtmp, shkp) == 2) return (2); return (0); } else if (info[chi] & ALLOW_U) { hitu(shkp, d(mdat->damn, mdat->damd) + 1); return (0); } shkp->mx = nix; shkp->my = niy; pmon(shkp); if (ib) { freeobj(ib); mpickobj(shkp, ib); } return (1); } return (0); }
/* weptyp: uwep->otyp or 0 */ void cutworm(struct monst *mtmp, xchar x, xchar y, uchar weptyp) { struct wseg *wtmp, *wtmp2; struct monst *mtmp2; int tmp, tmp2; if (mtmp->mx == x && mtmp->my == y) /* hit headon */ return; /* cutting goes best with axe or sword */ tmp = rnd(20); if (weptyp == LONG_SWORD || weptyp == TWO_HANDED_SWORD || weptyp == AXE) tmp += 5; if (tmp < 12) return; /* if tail then worm just loses a tail segment */ tmp = mtmp->wormno; wtmp = wsegs[tmp]; if (wtmp->wx == x && wtmp->wy == y) { wsegs[tmp] = wtmp->nseg; remseg(wtmp); return; } /* cut the worm in two halves */ mtmp2 = newmonst(0); *mtmp2 = *mtmp; mtmp2->mxlth = mtmp2->mnamelth = 0; /* sometimes the tail end dies */ if (rn2(3) || !getwn(mtmp2)) { monfree(mtmp2); tmp2 = 0; } else { tmp2 = mtmp2->wormno; wsegs[tmp2] = wsegs[tmp]; wgrowtime[tmp2] = 0; } do { if (wtmp->nseg->wx == x && wtmp->nseg->wy == y) { if (tmp2) wheads[tmp2] = wtmp; wsegs[tmp] = wtmp->nseg->nseg; remseg(wtmp->nseg); wtmp->nseg = 0; if (tmp2) { pline("You cut the worm in half."); mtmp2->mhpmax = mtmp2->mhp = d(mtmp2->data->mlevel, 8); mtmp2->mx = wtmp->wx; mtmp2->my = wtmp->wy; mtmp2->nmon = fmon; fmon = mtmp2; pmon(mtmp2); } else { pline("You cut off part of the worm's tail."); remseg(wtmp); } mtmp->mhp /= 2; return; } wtmp2 = wtmp->nseg; if (!tmp2) remseg(wtmp); wtmp = wtmp2; } while (wtmp->nseg); panic("Cannot find worm segment"); }
// NOTE: To hit "you" with a potion p, call "potionhit(NULL, p)". no "youmonst" void potionhit(monst_t *mon, obj_t *obj) { Char *botlnam = bottlenames[rund(MAX_BOTTLES)]; Boolean uclose; // , isyou = (mon==NULL); if (!mon) { uclose = true; StrPrintF(ScratchBuffer, "The %s crashes on your head and breaks into shivers.", botlnam); message(ScratchBuffer); losehp(rnd(2), "thrown potion"); } else { uclose = (dist(mon->mx,mon->my) < 3); /* perhaps 'E' and 'a' have no head? */ StrPrintF(ScratchBuffer, "The %s crashes on %s's head and breaks into shivers.", botlnam, monnam(mon)); message(ScratchBuffer); if (rund(5) && mon->mhp > 1) mon->mhp--; } StrPrintF(ScratchBuffer, "The %s evaporates.", xname(obj)); message(ScratchBuffer); if (mon && !rund(3)) { switch(obj->otype) { case POT_RESTORE_STRENGTH: case POT_GAIN_STRENGTH: case POT_HEALING: case POT_EXTRA_HEALING: if (mon->mhp < mon->mhpmax) { mon->mhp = mon->mhpmax; StrPrintF(ScratchBuffer, "%s looks sound and hale again!", Monnam(mon)); message(ScratchBuffer); } break; case POT_SICKNESS: if (mon->mhpmax > 3) mon->mhpmax /= 2; if (mon->mhp > 2) mon->mhp /= 2; break; case POT_CONFUSION: case POT_BOOZE: mon->bitflags |= M_IS_CONFUSED; // mon->mconf = 1; break; case POT_INVISIBILITY: unpmon(mon); mon->bitflags |= M_IS_INVISIBLE; // mon->minvis = 1; pmon(mon); break; case POT_PARALYSIS: mon->bitflags |= M_IS_FROZEN; // mon->mfroz = 1; break; case POT_SPEED: mon->mspeed = MFAST; break; case POT_BLINDNESS: mon->mcansee_and_blinded |= 64 + rund(64); // "|="? "=" to turn off SEE? break; /* case POT_GAIN_LEVEL: case POT_LEVITATION: case POT_FRUIT_JUICE: case POT_MONSTER_DETECTION: case POT_OBJECT_DETECTION: break; */ default: break; } } if (uclose && rund(5)) potionbreathe(obj); free_obj(obj, NULL); }
/* * shk_move: return 1: he moved 0: he didnt -1: let m_move do it * (what about "return 2" ??? */ Short shk_move(monst_t *shkp) { monst_t *mtmp; permonst_t *mdat = shkp->data; UChar gx,gy,omx,omy,nx,ny,nix,niy; Int8 appr,i; Short udist; Short z; Int8 shkroom,chi,chcnt,cnt; Boolean uondoor=false, satdoor, avoid=false, badinv; coord poss[9]; Short info[9]; obj_t *ib = NULL; omx = shkp->mx; omy = shkp->my; if ((udist = dist(omx,omy)) < 3) { if (ANGRY(shkp)) { hit_you(shkp, dice(mdat->damn, mdat->damd)+1); return 0; } if (ESHK(shkp)->following) { if (StrNCompare(ESHK(shkp)->customer, plname, PL_NSIZ)) { StrPrintF(ScratchBuffer, "Hello %s! I was looking for %s.", plname, ESHK(shkp)->customer); message(ScratchBuffer); ESHK(shkp)->following = false; return 0; } if (!ESHK(shkp)->robbed) { /* impossible? */ ESHK(shkp)->following = false; return 0; } if (moves > followmsg+4) { StrPrintF(ScratchBuffer, "Hello %s! Didn't you forget to pay?", plname); message(ScratchBuffer); followmsg = moves; } if (udist < 2) return 0; } } shkroom = inroom(omx,omy); appr = 1; gx = ESHK(shkp)->shk.x; gy = ESHK(shkp)->shk.y; satdoor = (gx == omx && gy == omy); if (ESHK(shkp)->following || ((z = holetime()) >= 0 && z*z <= udist)){ gx = you.ux; gy = you.uy; if (shkroom < 0 || shkroom != inroom(you.ux,you.uy)) if (udist > 4) return -1; /* leave it to m_move */ } else if (ANGRY(shkp)) { Long saveBlind = Blind; Blind = 0; if ((shkp->mcansee_and_blinded & M_CAN_SEE) && !Invis && cansee(omx,omy)) { gx = you.ux; gy = you.uy; } Blind = saveBlind; avoid = false; } else { #define GDIST(x,y) ((x-gx)*(x-gx)+(y-gy)*(y-gy)) if (Invis) avoid = false; else { uondoor = (you.ux == ESHK(shkp)->shd.x && you.uy == ESHK(shkp)->shd.y); if (uondoor) { if (ESHK(shkp)->billct) { StrPrintF(ScratchBuffer, "Hello %s! Will you please pay before leaving?", plname); message(ScratchBuffer); } badinv = (carrying(PICK_AXE) || carrying(ICE_BOX)); if (satdoor && badinv) return 0; avoid = !badinv; } else { avoid = (you.uinshop && dist(gx,gy) > 8); badinv = false; } if (((!ESHK(shkp)->robbed && !ESHK(shkp)->billct) || avoid) && GDIST(omx,omy) < 3) { if (!badinv && !online(omx,omy)) return 0; if (satdoor) appr = gx = gy = 0; } } } if (omx == gx && omy == gy) return 0; if (shkp->bitflags & M_IS_CONFUSED) { avoid = false; appr = 0; } nix = omx; niy = omy; cnt = mfindpos(shkp,poss,info,ALLOW_SSM); if (avoid && uondoor) { /* perhaps we cannot avoid him */ for (i=0; i<cnt; i++) if (!(info[i] & NOTONL)) goto notonl_ok; avoid = false; notonl_ok: ; } chi = -1; chcnt = 0; for (i = 0 ; i < cnt ; i++) { nx = poss[i].x; ny = poss[i].y; if (get_cell_type(floor_info[nx][ny]) == ROOM || shkroom != ESHK(shkp)->shoproom || ESHK(shkp)->following) { #ifdef STUPID /* cater for stupid compilers */ Short zz; #endif STUPID if (uondoor && (ib = sobj_at(ICE_BOX, nx, ny))) { nix = nx; niy = ny; chi = i; break; } if (avoid && (info[i] & NOTONL)) continue; if ((!appr && !rund(++chcnt)) || #ifdef STUPID (appr && (zz = GDIST(nix,niy)) && zz > GDIST(nx,ny)) #else (appr && GDIST(nx,ny) < GDIST(nix,niy)) #endif STUPID ) { nix = nx; niy = ny; chi = i; } } } if (nix != omx || niy != omy) { if (info[chi] & ALLOW_M){ mtmp = mon_at(nix,niy); if (hitmm(shkp,mtmp) == 1 && rund(3) && hitmm(mtmp,shkp) == 2) return 2; return 0; } else if (info[chi] & ALLOW_U){ hit_you(shkp, dice(mdat->damn, mdat->damd)+1); return 0; } shkp->mx = nix; shkp->my = niy; pmon(shkp); if (ib) { unlink_obj(ib);//freeobj mpickobj(shkp, ib); } return 1; } return 0; }
int m_move(struct monst *mtmp, int after) { struct monst *mtmp2; int nx = 0; int ny = 0; int omx; int omy; int appr; int nearer; int cnt; int i; int j; xchar gx; xchar gy; xchar nix; xchar niy; xchar chcnt; schar chi; boolean likegold = 0; boolean likegems = 0; boolean likeobjs = 0; /* Not strictly necessary: chi >= 0 will do */ schar mmoved = 0; coord poss[9]; int info[9]; if(mtmp->mtrapped != 0) { i = mintrap(mtmp); if(i == 2) { /* He died */ return 2; } if(i == 1) { /* Still in trap so didn't move */ return 0; } } if((mtmp->mhide != 0) && (o_at(mtmp->mx, mtmp->my) != NULL) && (rn2(10) != 0)) { /* Do not leave hiding place */ return 0; } /* My dog gets a special treatment */ if(mtmp->mtame != 0) { return dog_move(mtmp, after); } /* Likewise for shopkeeper */ if(mtmp->isshk != 0) { mmoved = shk_move(); if(mmoved == 1) { if(mintrap(mtmp) == 2) { /* He died */ return 2; } if(likegold != 0) { mpickgold(mtmp); } if(likegems != 0) { mpickgems(mtmp); } if(mtmp->mhide != 0) { mtmp->mundetected = 1; } } return mmoved; } /* And for the guard */ if(mtmp->isgd != 0) { mmoved = gd_move(); if(mmoved == 1) { if(mintrap(mtmp) == 2) { /* He died */ return 2; } if(likegold != 0) { mpickgold(mtmp); } if(likegems != 0) { mpickgems(mtmp); } if(mtmp->mhide != 0) { mtmp->mundetected = 1; } } return mmoved; } if((mtmp->data->mlet == 't') && (rn2(5) == 0)) { if(rn2(2) != 0) { mnexto(mtmp); } else { rloc(mtmp); } mmoved = 1; if(mmoved == 1) { if(mintrap(mtmp) == 2) { /* He died */ return 2; } if(likegold != 0) { mpickgold(mtmp); } if(likegems != 0) { mpickgems(mtmp); } if(mtmp->mhide != 0) { mtmp->mundetected = 1; } } return mmoved; } if((mtmp->data->mlet == 'D') && (mtmp->mcan == 0)) { inrange(mtmp); } if((Blind == 0) && (Confusion == 0) && (mtmp->data->mlet == 'U') && (mtmp->mcan == 0) && (cansee(mtmp->mx, mtmp->my) != 0) && (rn2(5) != 0)) { pline("%s's gaze has confused you!", Monnam(mtmp)); if(rn2(5) != 0) { mtmp->mcan = 1; } /* Timeout */ Confusion = d(3, 4); } if((mtmp->mflee == 0) && (u.uswallow != 0) && (u.ustuck != mtmp)) { return 1; } appr = 1; if(mtmp->mflee != 0) { appr = -1; } if((mtmp->mconf != 0) || (Invis != 0) || (mtmp->mcansee == 0) || ((index("Biy", mtmp->data->mlet) != 0) && (rn2(3) == 0))) { appr = 0; } omx = mtmp->mx; omy = mtmp->my; gx = u.ux; gy = u.uy; if((mtmp->data->mlet == 'L') && (appr == 1) && (mtmp->mgold > u.ugold)) { appr = -1; } #ifdef TRACK /* * Random criterion for 'smell' * should use mtmp->msmell */ if(('a' <= mtmp->data->mlet) && (mtmp->data->mlet <= 'z')) { coord *cp; schar mroom; mroom = inroom(omx, omy); if((mroom < 0) || (mroom != inroom(u.ux, u.uy))) { cp = gettrack(omx, omy); if(cp != 0) { gx = cp->x; gy = cp->y; } } } #endif /* Look for gold or jewels nearby */ if(index("LOD", mtmp->data->mlet) != NULL) { likegold = 1; } else { likegold = 0; } if(index("ODu", mtmp->data->mlet) != NULL) { likegems = 1; } else { likegems = 0; } likeobjs = mtmp->mhide; #define SRCHRADIUS 25 /* Not too far away */ xchar mind = SRCHRADIUS; int dd; if(likegold != 0) { struct gen *gold; for(gold = fgold; gold != NULL; gold = gold->ngen) { dd = DIST(omx, omy, gold->gx, gold->gy); if(dd < mind) { mind = dd; gx = gold->gx; gy = gold->gy; } } } if((likegems != 0) || (likeobjs != 0)) { struct obj *otmp; for(otmp = fobj; otmp != NULL; otmp = otmp->nobj) { if((likeobjs != 0) || (otmp->olet == GEM_SYM)) { if((mtmp->data->mlet != 'u') || (objects[otmp->otyp].g_val != 0)) { dd = DIST(omx, omy, otmp->ox, otmp->oy); if(dd < mind) { mind = dd; gx = otmp->ox; gy = otmp->oy; } } } } } if((mind < SRCHRADIUS) && (appr == -1)) { if(dist(omx, omy) < 10) { gx = u.ux; gy = u.uy; } else { appr = 1; } } nix = omx; niy = omy; if(mtmp->data->mlet == 'u') { cnt = mfndpos(mtmp, poss, info, NOTONL); } else { if(index(" VWZ", mtmp->data->mlet) != 0) { cnt = mfndpos(mtmp, poss, info, NOGARLIC); } else { cnt = mfndpos(mtmp, poss, info, ALLOW_TRAPS); } } /* ALLOW_ROCK for some monsters? */ chcnt = 0; chi = -1; for(i = 0; i < cnt; ++i) { nx = poss[i].x; nx = poss[i].y; for(j = 0; (j < MTSZ) && (j < (cnt - 1)); ++j) { if((nx == mtmp->mtrack[j].x) && (ny == mtmp->mtrack[j].y)) { if(rn2(4 * (cnt - j)) == 0) { #ifdef STUPID /* Some stupid compilers thing that is is too complicated */ int d1 = DIST(nx, ny, gx, gy); int d2 = DIST(nix, niy, gx, gy); if(d1 < d2) { nearer = 1; } else { nearer = 0; } #else if(DIST(nx, ny, gx, gy) < DIST(nix, niy, gx, gy)) { nearer = 1; } else { nearer = 0; } #endif if(((appr == 1) && (nearer != 0)) || ((appr == -1) && (nearer == 0)) || (mmoved == 0)) { nix = nx; niy = ny; chi = i; mmoved = 1; } else { if(appr == 0) { if(rn2(chcnt) == 0) { ++chcnt; nix = nx; niy = ny; chi = i; mmoved = 1; } else { ++chcnt; } } } } } } } if(mmoved != 0) { if((info[(int)chi] & ALLOW_M) != 0) { mtmp2 = m_at(nix, niy); if((hitmm(mtmp, mtmp2) == 1) && (rn2(4) != 0) && (hitmm(mtmp2, mtmp) == 2)) { return 2; } return 0; } if((info[(int)chi] & ALLOW_U) != 0) { hitu(mtmp, d(mtmp->data->damn, mtmp->data->damd) + 1); return 0; } mtmp->mx = nix; mtmp->my = niy; for(j = MTSZ - 1; j > 0; --j) { mtmp->mtrack[j] = mtmp->mtrack[j - 1]; } mtmp->mtrack[0].x = omx; mtmp->mtrack[0].y = omy; #ifndef NOWORM if(mtmp->wormno != 0) { worm_move(mtmp); } #endif } else { if((mtmp->data->mlet == 'u') && (rn2(2) != 0)) { rloc(mtmp); return 0; } #ifndef NOWORM if(mtmp->wormno != 0) { worm_nomove(mtmp); } #endif } if(mmoved == 1) { if(mintrap(mtmp) == 2) { /* He died */ return 2; } if(likegold != 0) { mpickgold(mtmp); } if(likegems != 0) { mpickgems(mtmp); } if(mtmp->mhide != 0) { mtmp->mundetected = 1; } } pmon(mtmp); return mmoved; }
/* * mhitu: monster hits you * returns 1 if monster dies (e.g. 'y', 'F'), 0 otherwise */ bool mhitu(struct monst *mtmp) { struct permonst *mdat = mtmp->data; int tmp, ctmp; nomul(0); /* If swallowed, can only be affected by hissers and by u.ustuck */ if (u.uswallow) { if (mtmp != u.ustuck) { if (mdat->mlet == 'c' && !rn2(13)) { pline("Outside, you hear %s's hissing!", monnam(mtmp)); pline("%s gets turned to stone!", Monnam(u.ustuck)); pline("And the same fate befalls you."); done_in_by(mtmp); /* "notreached": not return(1); */ } return (0); } switch (mdat->mlet) { /* now mtmp == u.ustuck */ case ',': youswld(mtmp, (u.uac > 0) ? u.uac + 4 : 4, 5, "The trapper"); break; case '\'': youswld(mtmp, rnd(6), 7, "The lurker above"); break; case 'P': youswld(mtmp, d(2, 4), 12, "The purple worm"); break; default: /* This is not impossible! */ pline("The mysterious monster totally digests you."); u.uhp = 0; } if (u.uhp < 1) done_in_by(mtmp); return (0); } if (mdat->mlet == 'c' && Stoned) return (0); /* make eels visible the moment they hit/miss us */ if (mdat->mlet == ';' && mtmp->minvis && cansee(mtmp->mx, mtmp->my)) { mtmp->minvis = 0; pmon(mtmp); } if (!strchr("1&DuxynNF", mdat->mlet)) tmp = hitu(mtmp, d(mdat->damn, mdat->damd)); else tmp = 0; if (strchr(UNDEAD, mdat->mlet) && midnight()) tmp += hitu(mtmp, d(mdat->damn, mdat->damd)); ctmp = tmp && !mtmp->mcan && (!uarm || objects[uarm->otyp].a_can < rnd(3) || !rn2(50)); switch (mdat->mlet) { case '1': if (wiz_hit(mtmp)) /* he disappeared */ return (1); break; case '&': if (!mtmp->cham && !mtmp->mcan && !rn2(13)) { makemon(PM_DEMON, u.ux, u.uy); } else { hitu(mtmp, d(2, 6)); hitu(mtmp, d(2, 6)); hitu(mtmp, rnd(3)); hitu(mtmp, rnd(3)); hitu(mtmp, rn1(4, 2)); } break; case ',': if (tmp) justswld(mtmp, "The trapper"); break; case '\'': if (tmp) justswld(mtmp, "The lurker above"); break; case ';': if (ctmp) { if (!u.ustuck && !rn2(10)) { pline("%s swings itself around you!", Monnam(mtmp)); u.ustuck = mtmp; } else if (u.ustuck == mtmp && levl[mtmp->mx][mtmp->my].typ == POOL) { pline("%s drowns you ...", Monnam(mtmp)); done("drowned"); } } break; case 'A': if (ctmp && rn2(2)) { if (Poison_resistance) pline("The sting doesn't seem to affect you."); else { pline("You feel weaker!"); losestr(1); } } break; case 'C': hitu(mtmp, rnd(6)); break; case 'c': if (!rn2(5)) { pline("You hear %s's hissing!", monnam(mtmp)); if (ctmp || !rn2(20) || (flags.moonphase == NEW_MOON && !carrying(DEAD_LIZARD))) Stoned = 5; } break; case 'D': if (rn2(6) || mtmp->mcan) { hitu(mtmp, d(3, 10)); hitu(mtmp, rnd(8)); hitu(mtmp, rnd(8)); break; } kludge("%s breathes fire!", "The dragon"); buzz(-1, mtmp->mx, mtmp->my, u.ux - mtmp->mx, u.uy - mtmp->my); break; case 'd': hitu(mtmp, d(2, (flags.moonphase == FULL_MOON) ? 3 : 4)); break; case 'e': hitu(mtmp, d(3, 6)); break; case 'F': if (mtmp->mcan) break; kludge("%s explodes!", "The freezing sphere"); if (Cold_resistance) pline("You don't seem affected by it."); else { xchar dn; if (17 - (u.ulevel / 2) > rnd(20)) { pline("You get blasted!"); dn = 6; } else { pline("You duck the blast..."); dn = 3; } losehp_m(d(dn, 6), mtmp); } mondead(mtmp); return (1); case 'g': if (ctmp && multi >= 0 && !rn2(3)) { kludge("You are frozen by %ss juices", "the cube'"); nomul(-rnd(10)); } break; case 'h': if (ctmp && multi >= 0 && !rn2(5)) { nomul(-rnd(10)); kludge("You are put to sleep by %ss bite!", "the homunculus'"); } break; case 'j': tmp = hitu(mtmp, rnd(3)); tmp &= hitu(mtmp, rnd(3)); if (tmp) { hitu(mtmp, rnd(4)); hitu(mtmp, rnd(4)); } break; case 'k': if ((hitu(mtmp, rnd(4)) || !rn2(3)) && ctmp) poisoned("bee's sting", mdat->mname); break; case 'L': if (tmp) stealgold(mtmp); break; case 'N': if (mtmp->mcan && !Blind) { pline("%s tries to seduce you, but you seem not interested.", Amonnam(mtmp, "plain")); if (rn2(3)) rloc(mtmp); } else if (steal(mtmp)) { rloc(mtmp); mtmp->mflee = 1; } break; case 'n': if (!uwep && !uarm && !uarmh && !uarms && !uarmg) { pline("%s hits! (I hope you don't mind)", Monnam(mtmp)); u.uhp += rnd(7); if (!rn2(7)) u.uhpmax++; if (u.uhp > u.uhpmax) u.uhp = u.uhpmax; flags.botl = 1; if (!rn2(50)) rloc(mtmp); } else { hitu(mtmp, d(2, 6)); hitu(mtmp, d(2, 6)); } break; case 'o': tmp = hitu(mtmp, rnd(6)); if (hitu(mtmp, rnd(6)) && tmp && /* hits with both paws */ !u.ustuck && rn2(2)) { u.ustuck = mtmp; kludge("%s has grabbed you!", "The owlbear"); u.uhp -= d(2, 8); } else if (u.ustuck == mtmp) { u.uhp -= d(2, 8); pline("You are being crushed."); } break; case 'P': if (ctmp && !rn2(4)) justswld(mtmp, "The purple worm"); else hitu(mtmp, d(2, 4)); break; case 'Q': hitu(mtmp, rnd(2)); hitu(mtmp, rnd(2)); break; case 'R': if (tmp && uarmh && !uarmh->rustfree && (int)uarmh->spe >= -1) { pline("Your helmet rusts!"); uarmh->spe--; } else if (ctmp && uarm && !uarm->rustfree && /* Mike Newton */ uarm->otyp < STUDDED_LEATHER_ARMOR && (int)uarm->spe >= -1) { pline("Your armor rusts!"); uarm->spe--; } break; case 'S': if (ctmp && !rn2(8)) poisoned("snake's bite", mdat->mname); break; case 's': if (tmp && !rn2(8)) poisoned("scorpion's sting", mdat->mname); hitu(mtmp, rnd(8)); hitu(mtmp, rnd(8)); break; case 'T': hitu(mtmp, rnd(6)); hitu(mtmp, rnd(6)); break; case 't': if (!rn2(5)) rloc(mtmp); break; case 'u': mtmp->mflee = 1; break; case 'U': hitu(mtmp, d(3, 4)); hitu(mtmp, d(3, 4)); break; case 'v': if (ctmp && !u.ustuck) u.ustuck = mtmp; break; case 'V': if (tmp) u.uhp -= 4; if (ctmp) losexp(); break; case 'W': if (ctmp) losexp(); break; #ifndef NOWORM case 'w': if (tmp) wormhit(mtmp); #endif /* NOWORM */ break; case 'X': hitu(mtmp, rnd(5)); hitu(mtmp, rnd(5)); hitu(mtmp, rnd(5)); break; case 'x': { long side = rn2(2) ? RIGHT_SIDE : LEFT_SIDE; pline("%s pricks in your %s leg!", Monnam(mtmp), (side == RIGHT_SIDE) ? "right" : "left"); set_wounded_legs(side, rnd(50)); losehp_m(2, mtmp); break; } case 'y': if (mtmp->mcan) break; mondead(mtmp); if (!Blind) { pline("You are blinded by a blast of light!"); Blind = d(4, 12); seeoff(0); } return (1); case 'Y': hitu(mtmp, rnd(6)); break; } if (u.uhp < 1) done_in_by(mtmp); return (0); }