/* * picky_inven: * Allow player to inventory a single item */ void picky_inven() { struct linked_list *item; int ch, mch; if (pack == NULL) msg("You aren't carrying anything"); else if (next(pack) == NULL) msg("a) %s", inv_name((struct object *) ldata(pack), FALSE)); else { msg(terse ? "Item: " : "Which item do you wish to inventory: "); mpos = 0; if ((mch = readchar(cw)) == ESCAPE) { msg(""); return; } for (ch = 'a', item = pack; item != NULL; item = next(item), ch++) if (ch == mch) { msg("%c) %s",ch,inv_name((struct object *) ldata(item), FALSE)); return; } if (!terse) msg("'%s' not in pack", unctrl(mch)); msg("Range is 'a' to '%c'", --ch); } }
/* * Iterate over the list of programmers given as "programmers", and * call the callback function cb for each entry found. cb is being * passed the following arguments: * . the name of the programmer (for -c) * . the descriptive text given in the config file * . the name of the config file this programmer has been defined in * . the line number of the config file this programmer has been defined at * . the "cookie" passed into walk_programmers() (opaque client data) */ void walk_programmers(LISTID programmers, walk_programmers_cb cb, void *cookie) { LNODEID ln1; PROGRAMMER * p; for (ln1 = lfirst(programmers); ln1; ln1 = lnext(ln1)) { p = ldata(ln1); cb((char *)ldata(lfirst(p->id)), p->desc, p->config_file, p->lineno, cookie); } }
/* * Compare function to sort the list of programmers */ static int sort_programmer_compare(PROGRAMMER * p1,PROGRAMMER * p2) { char* id1; char* id2; if(p1 == NULL || p2 == NULL) { return 0; } id1 = ldata(lfirst(p1->id)); id2 = ldata(lfirst(p2->id)); return strncasecmp(id1,id2,AVR_IDLEN); }
struct linked_list * get_hurl(struct thing *tp) { static struct linked_list *arrow, *bolt, *rock, *silverarrow, *fbbolt; register struct linked_list *pitem; int bow=FALSE, crossbow=FALSE, sling=FALSE, footbow=FALSE; /* Don't point to anything to begin with */ arrow = bolt = rock = silverarrow = fbbolt = NULL; for (pitem=tp->t_pack; pitem; pitem=next(pitem)) if (((struct object *) ldata(pitem))->o_type == WEAPON) switch (((struct object *) ldata(pitem))->o_which) { case BOW: bow = TRUE; break; case CROSSBOW: crossbow = TRUE; break; case SLING: sling = TRUE; break; case FOOTBOW: footbow = TRUE; break; case ROCK: rock = pitem; break; case ARROW: arrow = pitem; break; case SILVERARROW: silverarrow = pitem; break; case BOLT: bolt = pitem; break; case FBBOLT: fbbolt = pitem; break; } if (bow && silverarrow) return(silverarrow); if (crossbow && bolt) return(bolt); if (footbow && fbbolt) return(fbbolt); if (bow && arrow) return(arrow); if (sling && rock) return(rock); return(NULL); }
static int wiring_parseextparms(PROGRAMMER * pgm, LISTID extparms) { LNODEID ln; const char *extended_param; int rv = 0; void *mycookie = STK500V2PDATA(pgm)->chained_pdata; for (ln = lfirst(extparms); ln; ln = lnext(ln)) { extended_param = ldata(ln); if (strncmp(extended_param, "snooze=", strlen("snooze=")) == 0) { int newsnooze; if (sscanf(extended_param, "snooze=%i", &newsnooze) != 1 || newsnooze < 0) { avrdude_message(MSG_INFO, "%s: wiring_parseextparms(): invalid snooze time '%s'\n", progname, extended_param); rv = -1; continue; } avrdude_message(MSG_NOTICE2, "%s: wiring_parseextparms(): snooze time set to %d ms\n", progname, newsnooze); WIRINGPDATA(mycookie)->snoozetime = newsnooze; continue; } avrdude_message(MSG_INFO, "%s: wiring_parseextparms(): invalid extended parameter '%s'\n", progname, extended_param); rv = -1; } return rv; }
void fall(struct linked_list *item, int pr) { struct object *obj; struct room *rp; static coord fpos; obj = (struct object *) ldata(item); if (fallpos(&obj->o_pos, &fpos, TRUE)) { mvaddrawch(fpos.y, fpos.x, obj->o_type); obj->o_pos = fpos; if ((rp = roomin(&hero)) != NULL && !(rp->r_flags & ISDARK)) { light(&hero); mvwaddrawch(cw, hero.y, hero.x, PLAYER); } attach(lvl_obj, item); return; } if (pr) if (obj->o_type == WEAPON) /* BUGFUX: Identification trick */ msg("Your %s vanishes as it hits the ground.", w_names[obj->o_which]); else msg("%s vanishes as it hits the ground.", inv_name(obj,TRUE)); discard(item); }
/* * wield: * Pull out a certain weapon */ void wield(void) { register struct linked_list *item ; register struct object *obj, *oweapon ; oweapon = cur_weapon ; if (!dropcheck(cur_weapon)) { cur_weapon = oweapon ; return ; } cur_weapon = oweapon ; if ((item = get_item("wield", WEAPON)) == NULL) { after = FALSE ; return ; } obj = (struct object *) ldata(item) ; if (obj->o_type != WEAPON) { msg ("You can't wield that!"); return; } if (is_current(obj)) { after = FALSE ; return ; } if (terse) { addmsg("W") ; } else { addmsg("You are now w") ; } msg("ielding %s.", inv_name(obj, TRUE)) ; cur_weapon = obj ; }
void missile(int ydelta, int xdelta) { struct object *obj; struct linked_list *item, *nitem; /* * Get which thing we are hurling */ if ((item = get_item("throw", WEAPON)) == NULL) return; obj = (struct object *) ldata(item); if (!dropcheck(obj) || is_current(obj)) return; /* * Get rid of the thing. If it is a non-multiple item object, or * if it is the last thing, just drop it. Otherwise, create a new * item with a count of one. */ if (obj->o_count < 2) { detach(pack, item); inpack--; } else { obj->o_count--; if (obj->o_group == 0) inpack--; nitem = (struct linked_list *) new_item(sizeof *obj); obj = (struct object *) ldata(nitem); *obj = *((struct object *) ldata(item)); obj->o_count = 1; item = nitem; } do_motion(obj, ydelta, xdelta); /* * AHA! Here it has hit something. If it is a wall or a door, * or if it misses (combat) the mosnter, put it on the floor */ if (!ismons(CMVWINCH(mw, obj->o_pos.y, obj->o_pos.x)) || !hit_monster(unc(obj->o_pos), obj)) fall(item, TRUE); mvwaddrawch(cw, hero.y, hero.x, PLAYER); }
static int pickit2_parseextparams(struct programmer_t * pgm, LISTID extparms) { LNODEID ln; const char *extended_param; int rv = 0; for (ln = lfirst(extparms); ln; ln = lnext(ln)) { extended_param = ldata(ln); if (strncmp(extended_param, "clockrate=", strlen("clockrate=")) == 0) { int clock_rate; if (sscanf(extended_param, "clockrate=%i", &clock_rate) != 1 || clock_rate <= 0) { avrdude_message(MSG_INFO, "%s: pickit2_parseextparms(): invalid clockrate '%s'\n", progname, extended_param); rv = -1; continue; } int clock_period = MIN(1000000 / clock_rate, 255); // max period is 255 clock_rate = (int)(1000000 / (clock_period + 5e-7)); // assume highest speed is 2MHz - should probably check this avrdude_message(MSG_NOTICE2, "%s: pickit2_parseextparms(): clockrate set to 0x%02x\n", progname, clock_rate); PDATA(pgm)->clock_period = clock_period; continue; } if (strncmp(extended_param, "timeout=", strlen("timeout=")) == 0) { int timeout; if (sscanf(extended_param, "timeout=%i", &timeout) != 1 || timeout <= 0) { avrdude_message(MSG_INFO, "%s: pickit2_parseextparms(): invalid timeout '%s'\n", progname, extended_param); rv = -1; continue; } avrdude_message(MSG_NOTICE2, "%s: pickit2_parseextparms(): usb timeout set to 0x%02x\n", progname, timeout); PDATA(pgm)->transaction_timeout = timeout; continue; } avrdude_message(MSG_INFO, "%s: pickit2_parseextparms(): invalid extended parameter '%s'\n", progname, extended_param); rv = -1; } return rv; }
/* Interface - prog. */ static int usbasp_open(PROGRAMMER * pgm, char * port) { /* usb_init will be done in usbOpenDevice */ if (usbOpenDevice(&PDATA(pgm)->usbhandle, pgm->usbvid, pgm->usbvendor, pgm->usbpid, pgm->usbproduct) != 0) { /* try alternatives */ if(strcasecmp(ldata(lfirst(pgm->id)), "usbasp") == 0) { /* for id usbasp autodetect some variants */ if(strcasecmp(port, "nibobee") == 0) { fprintf(stderr, "%s: warning: Using \"-C usbasp -P nibobee\" is deprecated," "use \"-C nibobee\" instead.\n", progname); if (usbOpenDevice(&PDATA(pgm)->usbhandle, USBASP_NIBOBEE_VID, "www.nicai-systems.com", USBASP_NIBOBEE_PID, "NIBObee") != 0) { fprintf(stderr, "%s: error: could not find USB device " "\"NIBObee\" with vid=0x%x pid=0x%x\n", progname, USBASP_NIBOBEE_VID, USBASP_NIBOBEE_PID); return -1; } return 0; } /* check if device with old VID/PID is available */ if (usbOpenDevice(&PDATA(pgm)->usbhandle, USBASP_OLD_VID, "www.fischl.de", USBASP_OLD_PID, "USBasp") == 0) { /* found USBasp with old IDs */ fprintf(stderr, "%s: Warning: Found USB device \"USBasp\" with " "old VID/PID! Please update firmware of USBasp!\n", progname); return 0; } /* original USBasp is specified in config file, so no need to check it again here */ /* no alternative found => fall through to generic error message */ } fprintf(stderr, "%s: error: could not find USB device with vid=0x%x pid=0x%x", progname, pgm->usbvid, pgm->usbpid); if (pgm->usbvendor[0] != 0) { fprintf(stderr, " vendor='%s'", pgm->usbvendor); } if (pgm->usbproduct[0] != 0) { fprintf(stderr, " product='%s'", pgm->usbproduct); } fprintf(stderr,"\n"); return -1; } return 0; }
/* * fall: * Drop an item someplace around here. */ int fall(struct linked_list *item, int pr) { register struct object *obj ; register struct room *rp ; static coord fpos ; int ret; obj = (struct object *) ldata(item) ; rp = roomin(&hero); if (obj->o_flags & CANRETURN) { add_pack(item, TRUE); return TRUE; } else if (fallpos(&obj->o_pos, &fpos, TRUE)) { if (obj->o_flags & CANBURN && ntraps + 1 < MAXTRAPS + MAXTRAPS) { mvaddch(fpos.y, fpos.x, FIRETRAP); traps[ntraps].tr_type = FIRETRAP; traps[ntraps].tr_flags = ISFOUND; traps[ntraps].tr_show = FIRETRAP; traps[ntraps].tr_pos.y = fpos.y; traps[ntraps++].tr_pos.x = fpos.x; if (rp != NULL) rp->r_flags &= ~ISDARK; discard(item); ret = FALSE; } else { mvaddch(fpos.y, fpos.x, obj->o_type) ; obj->o_pos = fpos ; attach(lvl_obj, item) ; ret = TRUE; } if (rp != NULL && (!(rp->r_flags & ISDARK) || (rp->r_flags & HASFIRE))) { light(&hero) ; mvwaddch(cw, hero.y, hero.x, PLAYER) ; } return ret; } if (pr) { if (obj->o_type == WEAPON) addmsg("The %s", weaps[obj->o_which]); else addmsg(inv_name(obj, TRUE)); msg(" vanishes as it hits the ground."); } discard(item) ; return FALSE; }
struct linked_list * find_mons(int y, int x) { struct linked_list *item; struct thing *th; for (item = mlist; item != NULL; item = next(item)) { th = (struct thing *) ldata(item); if (th->t_pos.y == y && th->t_pos.x == x) return item; } return NULL; }
int pack_char(struct object *obj) { struct linked_list *item; int c; c = 'a'; for (item = pack; item != NULL; item = next(item)) if ((struct object *) ldata(item) == obj) return c; else c++; return 'z'; }
PROGRAMMER * locate_programmer(LISTID programmers, const char * configid) { LNODEID ln1, ln2; PROGRAMMER * p = NULL; const char * id; int found; found = 0; for (ln1=lfirst(programmers); ln1 && !found; ln1=lnext(ln1)) { p = ldata(ln1); for (ln2=lfirst(p->id); ln2 && !found; ln2=lnext(ln2)) { id = ldata(ln2); if (strcasecmp(configid, id) == 0) found = 1; } } if (found) return p; return NULL; }
/* ====== Config / parameters handling functions ====== */ static int buspirate_parseextparms(struct programmer_t *pgm, LISTID extparms) { LNODEID ln; const char *extended_param; char reset[10]; char *preset = reset; /* for strtok() */ int spifreq; for (ln = lfirst(extparms); ln; ln = lnext(ln)) { extended_param = ldata(ln); if (strcmp(extended_param, "ascii") == 0) { pgm->flag |= BP_FLAG_XPARM_FORCE_ASCII; continue; } if (sscanf(extended_param, "spifreq=%d", &spifreq) == 1) { if (spifreq & (~0x07)) { fprintf(stderr, "BusPirate: spifreq must be between 0 and 7.\n"); fprintf(stderr, "BusPirate: see BusPirate manual for details.\n"); return -1; } PDATA(pgm)->spifreq = spifreq; pgm->flag |= BP_FLAG_XPARM_SPIFREQ; continue; } if (sscanf(extended_param, "reset=%s", reset) == 1) { char *resetpin; while ((resetpin = strtok(preset, ","))) { preset = NULL; /* for subsequent strtok() calls */ if (strcasecmp(resetpin, "cs") == 0) PDATA(pgm)->reset |= BP_RESET_CS; else if (strcasecmp(resetpin, "aux") == 0 || strcasecmp(reset, "aux1") == 0) PDATA(pgm)->reset |= BP_RESET_AUX; else if (strcasecmp(resetpin, "aux2") == 0) PDATA(pgm)->reset |= BP_RESET_AUX2; else { fprintf(stderr, "BusPirate: reset must be either CS or AUX.\n"); return -1; } } pgm->flag |= BP_FLAG_XPARM_RESET; continue; } } return 0; }
static int ft245r_parseextparms(PROGRAMMER * pgm, LISTID extparms) { LNODEID ln; const char *extended_param; int rv = 0; for (ln = lfirst(extparms); ln; ln = lnext(ln)) { extended_param = ldata(ln); if (strncmp(extended_param, "serial=", strlen("serial=")) == 0) { if (strlen(extended_param) != (strlen("serial=") + 8)){ avrdude_message(MSG_INFO, "%s: ft245r_parseextparms(): serial has invalid length '%s'\n", progname, extended_param); rv = -1; continue; } char serial[9] = {0}; if ((sscanf(extended_param, "serial=%s", serial) != 1) && (strlen(serial) == 8)) { avrdude_message(MSG_INFO, "%s: ft245r_parseextparms(): invalid serial '%s'\n", progname, serial); rv = -1; continue; } if (verbose >= 2) { avrdude_message(MSG_INFO, "%s: ft245r_parseextparms(): serial number parsed as:\n" "%s %s\n", progname, progbuf, serial); } strcpy(pgm->usbsn, serial); continue; } avrdude_message(MSG_INFO, "%s: ft245r_parseextparms(): invalid extended parameter '%s'\n", progname, extended_param); rv = -1; } return rv; }
void CPlayerLevels::AddLevel( const FData& level, const std::string& levelId, std::list<CLevel>& levelList ) { FData value; value = level.get("PlayerId",value); if(!value.isString()) { return; } std::string playerId(value.asString()); value = level.get("PlayerName",value); std::string playerName(value.asString()); value = level.get("PlayerSource",value); std::string playerSource(value.asString()); value = level.get("Name",value); std::string name(value.asString()); value = level.get("Data",value); std::string ldata(value.asString()); value = level.get("thumb",value); std::string lthumb(value.asString()); value = level.get("RDate",value); std::string relativeDate(value.asString()); value = level.get("SDate",value); std::string date(value.asString()); value = level.get("Plays",value); int plays = value.asInt(); value = level.get("Votes",value); int votes = value.asInt(); value = level.get("Score",value); int score = value.asInt(); value = level.get("Rating",value); float rating = value.asFloat(); value = level.get("CustomData",value); CustomData customData; Json::ValueIterator it = value.begin(); for(; it != value.end(); it++) { customData.insert(std::make_pair(it.key().asString(), (*it).asString())); } levelList.push_back( CLevel(name, playerName, playerId, playerSource, ldata, lthumb, votes, plays, rating, score, date, relativeDate, customData, levelId)); }
runners() { register struct linked_list *item; register struct thing *tp; for (item = mlist; item != NULL;) { tp = (struct thing *) ldata(item); item = next(item); if (off(*tp, ISHELD) && on(*tp, ISRUN)) { if (off(*tp, ISSLOW) || tp->t_turn) if (do_chase(tp) == -1) continue; if (on(*tp, ISHASTE)) if (do_chase(tp) == -1) continue; tp->t_turn ^= TRUE; } } }
/* * runto: * Set a mosnter running after something * or stop it from running (for when it dies) */ void runto(coord *runner, coord *spot) { register struct linked_list *item; register struct thing *tp; /* * If we couldn't find him, something is funny */ if ((item = find_mons(runner->y, runner->x)) == NULL) { debug("CHASER '%s'", unctrl(winat(runner->y, runner->x))); return; } tp = (struct thing *) ldata(item); /* * Start the beastie running */ tp->t_dest = spot; turn_on(*tp, ISRUN); turn_off(*tp, ISDISGUISE); }
void runto(coord *runner, coord *spot) { struct linked_list *item; struct thing *tp; /* * If we couldn't find him, something is funny */ if ((item = find_mons(runner->y, runner->x)) == NULL) { msg("CHASER '%s'", unctrl(winat(runner->y, runner->x))); return; } tp = (struct thing *) ldata(item); /* * Start the beastie running */ tp->t_dest = spot; tp->t_flags |= ISRUN; tp->t_flags &= ~ISHELD; }
void wield() { struct linked_list *item; struct object *obj, *oweapon; oweapon = cur_weapon; if (!dropcheck(cur_weapon)) { cur_weapon = oweapon; return; } cur_weapon = oweapon; if ((item = get_item("wield", WEAPON)) == NULL) { bad: after = FALSE; return; } obj = (struct object *) ldata(item); if (obj->o_type == ARMOR) { msg("You can't wield armor"); goto bad; } if (is_current(obj)) goto bad; if (terse) addmsg("W"); else addmsg("You are now w"); msg("ielding %s", inv_name(obj, TRUE)); cur_weapon = obj; }
void ring_on(void) { register struct object *obj; register struct linked_list *item; register int ring; char buf[LINELEN]; item = get_item("put on", RING); /* * Make certain that it is somethings that we want to wear */ if (item == NULL) return; obj = (struct object *) ldata(item); if (obj->o_type != RING) { msg("You can't put that on!"); return; } /* * find out which hand to put it on */ if (is_current(obj)) return; if (cur_ring[LEFT_1] == NULL) ring = LEFT_1; else if (cur_ring[LEFT_2] == NULL) ring = LEFT_2; else if (cur_ring[LEFT_3] == NULL) ring = LEFT_3; else if (cur_ring[LEFT_4] == NULL) ring = LEFT_4; else if (cur_ring[RIGHT_1] == NULL) ring = RIGHT_1; else if (cur_ring[RIGHT_2] == NULL) ring = RIGHT_2; else if (cur_ring[RIGHT_3] == NULL) ring = RIGHT_3; else if (cur_ring[RIGHT_4] == NULL) ring = RIGHT_4; else { if (terse) msg("Wearing enough rings."); else msg("You already have on eight rings."); return; } cur_ring[ring] = obj; /* * Calculate the effect it has on the poor guy. */ switch (obj->o_which) { when R_ADDSTR: pstats.s_str += obj->o_ac; when R_ADDHIT: pstats.s_dext += obj->o_ac; when R_ADDINTEL: pstats.s_intel += obj->o_ac; when R_ADDWISDOM: pstats.s_wisdom += obj->o_ac; when R_SEEINVIS: if (off(player, PERMBLIND)) { turn_on(player, CANSEE); msg("Your eyes begin to tingle."); sight(); light(&hero); mvwaddch(cw, hero.y, hero.x, PLAYER); } when R_AGGR: aggravate(); when R_CARRYING: updpack(FALSE); when R_LEVITATION: msg("You begin to float in the air!"); when R_LIGHT: { if(roomin(&hero) != NULL) { light(&hero); mvwaddch(cw, hero.y, hero.x, PLAYER); } } } status(FALSE); if (r_know[obj->o_which] && r_guess[obj->o_which]) { free(r_guess[obj->o_which]); r_guess[obj->o_which] = NULL; } else if (!r_know[obj->o_which] && askme && (obj->o_flags & ISKNOW) == 0 && r_guess[obj->o_which] == NULL) { mpos = 0; msg(terse ? "Call it: " : "What do you want to call it? "); if (get_str(buf, msgw) == NORM) { r_guess[obj->o_which] = new(strlen(buf) + 1); strcpy(r_guess[obj->o_which], buf); }
/* * missile: * Fire a missile in a given direction */ void missile(int ydelta, int xdelta, struct linked_list *item, struct thing *tp) { register struct object *obj ; register struct linked_list *nitem ; /* * Get which thing we are hurling */ if (item == NULL) { return ; } obj = (struct object *) ldata(item) ; if (!dropcheck(obj) || is_current(obj)) { return ; } /* * Get rid of the thing. If it is a non-multiple item object, or * if it is the last thing, just drop it. Otherwise, create a new * item with a count of one. */ if (obj->o_count < 2) { detach(tp->t_pack, item) ; if (tp->t_pack == pack) { inpack-- ; freeletter(item); } } else { obj->o_count-- ; nitem = (struct linked_list *) new_item(sizeof *obj) ; obj = (struct object *) ldata(nitem) ; *obj = *((struct object *) ldata(item)) ; obj->o_count = 1 ; item = nitem ; } if (obj->o_type == ARTIFACT) has_artifact &= ~(1 << obj->o_which); if (obj->o_type == SCROLL && obj->o_which == S_SCARE) { if (obj->o_flags & ISBLESSED) obj->o_flags &= ~ISBLESSED; else obj->o_flags |= ISCURSED; } updpack (FALSE); do_motion(obj, ydelta, xdelta, tp) ; /* * AHA! Here it has hit something. If it is a wall or a door, * or if it misses (combat) the monster, put it on the floor */ if (!hit_monster(unc(obj->o_pos), obj, tp)) { if (obj->o_type == WEAPON && obj->o_which == GRENADE) { register struct room *rp; static coord fpos; msg("BOOOM!"); aggravate(); rp = roomin(&obj->o_pos); if (ntraps + 1 < MAXTRAPS + MAXTRAPS && fallpos(&obj->o_pos, &fpos, TRUE)) { mvaddch(fpos.y, fpos.x, TRAPDOOR); traps[ntraps].tr_type = TRAPDOOR; traps[ntraps].tr_flags = ISFOUND; traps[ntraps].tr_show = TRAPDOOR; traps[ntraps].tr_pos.y = fpos.y; traps[ntraps++].tr_pos.x = fpos.x; light(&hero); } discard(item); } else if (obj->o_flags & ISLOST) { if (obj->o_type == WEAPON) addmsg("The %s", weaps[obj->o_which].w_name); else addmsg(inv_name(obj, TRUE)); msg(" vanishes in a puff of greasy smoke."); discard(item); } else { if (fall(item, TRUE)) if (obj->o_flags & CANRETURN) msg("You have %s.", inv_name(obj, TRUE)); } } else if (obj->o_flags & ISOWNED) { add_pack(item, TRUE); msg("You have %s.", inv_name(obj, TRUE)); } mvwaddch(cw, hero.y, hero.x, PLAYER) ; }
/* * add_pack: * Pick up an object and add it to the pack. If the argument is non-null * use it as the linked_list pointer instead of gettting it off the ground. */ void add_pack(struct linked_list *item, int silent) { struct linked_list *ip, *lp; struct object *obj, *op; int exact, from_floor; if (item == NULL) { from_floor = TRUE; if ((item = find_obj(hero.y, hero.x)) == NULL) return; } else from_floor = FALSE; obj = (struct object *) ldata(item); /* * Link it into the pack. Search the pack for a object of similar type * if there isn't one, stuff it at the beginning, if there is, look for one * that is exactly the same and just increment the count if there is. * it that. Food is always put at the beginning for ease of access, but * is not ordered so that you can't tell good food from bad. First check * to see if there is something in thr same group and if there is then * increment the count. */ if (obj->o_group) { for (ip = pack; ip != NULL; ip = next(ip)) { op = (struct object *) ldata(ip); if (op->o_group == obj->o_group) { /* * Put it in the pack and notify the user */ op->o_count++; if (from_floor) { detach(lvl_obj, item); mvaddch(hero.y, hero.x, (roomin(&hero) == NULL ? PASSAGE : FLOOR)); } discard(item); item = ip; goto picked_up; } } } /* * Check if there is room */ if (inpack == MAXPACK-1) { msg("You can't carry anything else."); return; } /* * Check for and deal with scare monster scrolls */ if (obj->o_type == SCROLL && obj->o_which == S_SCARE) if (obj->o_flags & ISFOUND) { msg("The scroll turns to dust as you pick it up."); detach(lvl_obj, item); mvaddch(hero.y, hero.x, FLOOR); return; } else obj->o_flags |= ISFOUND; inpack++; if (from_floor) { detach(lvl_obj, item); mvaddch(hero.y, hero.x, (roomin(&hero) == NULL ? PASSAGE : FLOOR)); } /* * Search for an object of the same type */ exact = FALSE; for (ip = pack; ip != NULL; ip = next(ip)) { op = (struct object *) ldata(ip); if (obj->o_type == op->o_type) break; } if (ip == NULL) { /* * Put it at the end of the pack since it is a new type */ for (ip = pack; ip != NULL; ip = next(ip)) { op = (struct object *) ldata(ip); if (op->o_type != FOOD) break; lp = ip; } } else { /* * Search for an object which is exactly the same */ while (ip != NULL && op->o_type == obj->o_type) { if (op->o_which == obj->o_which) { exact = TRUE; break; } lp = ip; if ((ip = next(ip)) == NULL) break; op = (struct object *) ldata(ip); } } if (ip == NULL) { /* * Didn't find an exact match, just stick it here */ if (pack == NULL) pack = item; else { lp->l_next = item; item->l_prev = lp; item->l_next = NULL; } } else { /* * If we found an exact match. If it is a potion, food, or a * scroll, increase the count, otherwise put it with its clones. */ if (exact && ISMULT(obj->o_type)) { op->o_count++; discard(item); item = ip; goto picked_up; } if ((item->l_prev = prev(ip)) != NULL) item->l_prev->l_next = item; else pack = item; item->l_next = ip; ip->l_prev = item; } picked_up: /* * Notify the user */ obj = (struct object *) ldata(item); if (notify && !silent) { if (!terse) addmsg("You now have "); msg("%s (%c)", inv_name(obj, !terse), pack_char(obj)); } if (obj->o_type == AMULET) amulet = TRUE; }
/* * inventory: * list what is in the pack */ int inventory(struct linked_list *list, int type) { struct object *obj; int ch; int n_objs; char inv_temp[80]; n_objs = 0; for (ch = 'a'; list != NULL; ch++, list = next(list)) { obj = (struct object *) ldata(list); if (type && type != obj->o_type && !(type == CALLABLE && (obj->o_type == SCROLL || obj->o_type == POTION || obj->o_type == RING || obj->o_type == STICK))) continue; switch (n_objs++) { /* * For the first thing in the inventory, just save the string * in case there is only one. */ case 0: sprintf(inv_temp, "%c) %s", ch, inv_name(obj, FALSE)); break; /* * If there is more than one, clear the screen, print the * saved message and fall through to ... */ case 1: if (slow_invent) msg(inv_temp); else { wclear(hw); waddstr(hw, inv_temp); waddch(hw, '\n'); } /* * Print the line for this object */ default: if (slow_invent) msg("%c) %s", ch, inv_name(obj, FALSE)); else wprintw(hw, "%c) %s\n", ch, inv_name(obj, FALSE)); } } if (n_objs == 0) { if (terse) msg(type == 0 ? "Empty handed." : "Nothing appropriate"); else msg(type == 0 ? "You are empty handed." : "You don't have anything appropriate"); return FALSE; } if (n_objs == 1) { msg(inv_temp); return TRUE; } if (!slow_invent) { mvwaddstr(hw, LINES-1, 0, "--Press space to continue--"); draw(hw); wait_for(hw,' '); clearok(cw, TRUE); touchwin(cw); } return TRUE; }
/* * quaff: * Let the hero drink a potion */ int quaff() { struct object *obj; struct linked_list *item, *titem; struct thing *th; int wh; char buf[LINLEN]; bool bless, curse; /* * Make certain that it is somethings that we want to drink */ if ((item = get_item("quaff", POTION)) == NULL) return 0; obj = OBJPTR(item); if (obj->o_type != POTION) { msg("That's undrinkable!"); after = FALSE; return 0; } wh = obj->o_which; bless = o_on(obj, ISBLESS); curse = o_on(obj, ISCURSED); del_pack(item); /* get rid of it */ /* * Calculate the effect it has on the poor guy. */ switch(wh) { case P_CONFUSE: if (!bless) { if (pl_on(ISINVINC)) msg("You remain level-headed."); else { chg_abil(WIS,-1,TRUE); /* confuse his mind */ if (pl_off(ISHUH)) { msg("Wait, what's going on here. Huh? What? Who?"); if (pl_on(ISHUH)) lengthen(unconfuse,rnd(8)+HUHDURATION); else fuse(unconfuse,TRUE,rnd(8)+HUHDURATION); player.t_flags |= ISHUH; } } p_know[P_CONFUSE] = TRUE; } when P_POISON: if (!bless) { if (pl_off(ISINVINC) && !iswearing(R_SUSTSTR) && !iswearing(R_SUSAB)) { chg_abil(CON,-1,TRUE); chg_abil(STR,-(rnd(3)+1),TRUE); msg("You feel very sick now."); } else msg("You feel momentarily sick."); p_know[P_POISON] = TRUE; } when P_HEALING: if (!curse) { heal_self(4, TRUE); msg("You begin to feel better."); if (!iswearing(R_SLOW)) notslow(FALSE); sight(FALSE); p_know[P_HEALING] = TRUE; } when P_STRENGTH: if (!curse) { msg("You feel stronger, now. What bulging muscles!"); chg_abil(STR,1,TRUE); p_know[P_STRENGTH] = TRUE; } when P_MFIND: /* * Potion of monster detection - find all monsters */ if (mlist != NULL && !curse) { dispmons(); mpos = 0; msg("You begin to sense the presence of monsters--More--"); p_know[P_MFIND] = TRUE; wait_for(cw,' '); msg(""); /* clear line */ } else msg("You have a strange feeling for a moment, then it passes."); when P_TFIND: /* * Potion of magic detection. Show the potions and scrolls */ if (lvl_obj != NULL && !curse) { struct linked_list *mobj; struct object *tp; bool show; show = FALSE; wclear(hw); for (mobj = lvl_obj; mobj != NULL; mobj = next(mobj)) { tp = OBJPTR(mobj); if (is_magic(tp)) { show = TRUE; mvwaddch(hw, tp->o_pos.y, tp->o_pos.x, MAGIC); } } for(titem = mlist; titem != NULL; titem = next(titem)) { struct linked_list *pitem; th = THINGPTR(titem); for(pitem=th->t_pack;pitem!=NULL;pitem=next(pitem)) { if (is_magic(ldata(pitem))) { show = TRUE; mvwaddch(hw,th->t_pos.y, th->t_pos.x, MAGIC); } } } if (show) { msg("You begin to sense the presence of magic."); overlay(hw,cw); p_know[P_TFIND] = TRUE; break; } } msg("You have a strange feeling for a moment, then it passes."); when P_PARALYZE: if (!bless) { if (pl_on(ISINVINC)) msg("You feel numb for a moment."); else { msg("You can't move."); player.t_nocmd = HOLDTIME; } p_know[P_PARALYZE] = TRUE; } when P_SEEINVIS: if (!curse) { int invlen = roll(40,20); msg("This potion tastes like %s juice.", fruit); if (pl_off(CANSEE)) { player.t_flags |= CANSEE; fuse(unsee, TRUE, invlen); light(&hero); } else lengthen(unsee, invlen); sight(FALSE); } when P_RAISE: if (!curse) { msg("You suddenly feel much more skillful."); p_know[P_RAISE] = TRUE; chg_abil(DEX,1,TRUE); chg_abil(WIS,1,TRUE); chg_abil(CON,1,TRUE); raise_level(); } when P_XHEAL: if (!curse) { heal_self(8, TRUE); if (rnd(100) < 50) chg_abil(CON,1,TRUE); msg("You begin to feel much better."); p_know[P_XHEAL] = TRUE; if (!iswearing(R_SLOW)) notslow(FALSE); unconfuse(); extinguish(unconfuse); sight(FALSE); } when P_HASTE: if (!curse) { add_haste(TRUE); msg("You feel yourself moving much faster."); p_know[P_HASTE] = TRUE; } when P_INVINC: if (!curse) { int time = rnd(400) + 350; msg("You feel invincible."); if (player.t_flags & ISINVINC) lengthen(notinvinc,time); else fuse(notinvinc,TRUE,time); player.t_flags |= ISINVINC; p_know[P_INVINC] = TRUE; } when P_SMART: if (!curse) { msg("You feel more perceptive."); p_know[P_SMART] = TRUE; chg_abil(WIS,1,TRUE); } when P_RESTORE: if (!curse) { msg("Hey, this tastes great. You feel warm all over."); him->s_re = max_stats.s_re; him->s_ef = max_stats.s_re; ringabil(); /* add in rings */ updpack(); /* update weight */ p_know[P_RESTORE] = TRUE; extinguish(rchg_str); /* kill restore in from ulodyte */ } when P_BLIND: if (!bless) { if (pl_on(ISINVINC)) msg("The light dims for a moment."); else { chg_abil(WIS,-1,TRUE); msg("A cloak of darkness falls around you."); if (pl_off(ISBLIND)) { player.t_flags |= ISBLIND; fuse(sight, TRUE, rnd(400) + 450); light(&hero); } } p_know[P_BLIND] = TRUE; } when P_ETH: if (!curse) { int ethlen = roll(40,20); msg("You feel more vaporous."); if (pl_on(ISETHER)) lengthen(noteth,ethlen); else fuse(noteth,TRUE,ethlen); player.t_flags |= ISETHER; p_know[P_ETH] = TRUE; } when P_NOP: msg("This potion tastes extremely dull."); when P_DEX: if (!curse) { chg_abil(DEX,1,TRUE); /* increase dexterity */ p_know[P_DEX] = TRUE; msg("You feel much more agile."); } when P_REGEN: if (!curse) { int reglen = rnd(450) + 450; if (pl_on(ISREGEN)) lengthen(notregen, reglen); else fuse(notregen, TRUE, reglen); player.t_flags |= ISREGEN; msg("You feel yourself improved."); p_know[P_REGEN] = TRUE; } when P_DECREP: case P_SUPHERO: { int howmuch = rnd(3) + 1; if (wh == P_DECREP) { if (!bless) { if (iswearing(R_SUSAB) || pl_on(ISINVINC)) { msg("You feel momentarily woozy."); howmuch = 0; } else { msg("You feel crippled."); howmuch = -howmuch; if (!iswearing(R_SUSTSTR)) chg_abil(STR,howmuch,TRUE); } } else howmuch = 0; } else { /* potion of superhero */ if (curse) howmuch = 0; msg("You feel invigorated."); chg_abil(STR,howmuch,TRUE); } chg_abil(CON,howmuch,TRUE); chg_abil(DEX,howmuch,TRUE); chg_abil(WIS,howmuch,TRUE); /* change abilities */ p_know[wh] = TRUE; } otherwise: msg("What an odd tasting potion!"); return 0; } nochange = FALSE; if (p_know[wh] && p_guess[wh]) { free(p_guess[wh]); p_guess[wh] = NULL; } else if(!p_know[wh] && p_guess[wh] == NULL) { strcpy(buf, p_colors[wh]); msg(callit); if (get_str(buf, cw) == NORM) { p_guess[wh] = new(strlen(buf) + 1); strcpy(p_guess[wh], buf); }
/* ====== Config / parameters handling functions ====== */ static int buspirate_parseextparms(struct programmer_t *pgm, LISTID extparms) { LNODEID ln; const char *extended_param; char reset[10]; char *preset = reset; /* for strtok() */ int spifreq; int cpufreq; int serial_recv_timeout; for (ln = lfirst(extparms); ln; ln = lnext(ln)) { extended_param = ldata(ln); if (strcmp(extended_param, "ascii") == 0) { pgm->flag |= BP_FLAG_XPARM_FORCE_ASCII; continue; } if (sscanf(extended_param, "spifreq=%d", &spifreq) == 1) { if (spifreq & (~0x07)) { fprintf(stderr, "BusPirate: spifreq must be between 0 and 7.\n"); fprintf(stderr, "BusPirate: see BusPirate manual for details.\n"); return -1; } PDATA(pgm)->spifreq = spifreq; pgm->flag |= BP_FLAG_XPARM_SPIFREQ; continue; } if (sscanf(extended_param, "cpufreq=%d", &cpufreq) == 1) { /* lower limit comes from 'cpufreq > 4 * spifreq', spifreq in ascii mode is 30kHz. */ if (cpufreq < 125 || cpufreq > 4000) { fprintf(stderr, "BusPirate: cpufreq must be between 125 and 4000 kHz.\n"); fprintf(stderr, "BusPirate: see BusPirate manual for details.\n"); return -1; } PDATA(pgm)->cpufreq = cpufreq; pgm->flag |= BP_FLAG_XPARM_CPUFREQ; continue; } if (sscanf(extended_param, "reset=%s", reset) == 1) { char *resetpin; while ((resetpin = strtok(preset, ","))) { preset = NULL; /* for subsequent strtok() calls */ if (strcasecmp(resetpin, "cs") == 0) PDATA(pgm)->reset |= BP_RESET_CS; else if (strcasecmp(resetpin, "aux") == 0 || strcasecmp(reset, "aux1") == 0) PDATA(pgm)->reset |= BP_RESET_AUX; else if (strcasecmp(resetpin, "aux2") == 0) PDATA(pgm)->reset |= BP_RESET_AUX2; else { fprintf(stderr, "BusPirate: reset must be either CS or AUX.\n"); return -1; } } pgm->flag |= BP_FLAG_XPARM_RESET; continue; } if (strcmp(extended_param, "nopagedwrite") == 0) { pgm->flag |= BP_FLAG_NOPAGEDWRITE; continue; } if (sscanf(extended_param, "serial_recv_timeout=%d", &serial_recv_timeout) == 1) { if (serial_recv_timeout < 1) { fprintf(stderr, "BusPirate: serial_recv_timeout must be greater 0.\n"); return -1; } PDATA(pgm)->serial_recv_timeout = serial_recv_timeout; continue; } } return 0; }
do_rooms() { register int i; register struct room *rp; register struct linked_list *item; register struct thing *tp; register int left_out; coord top; coord bsze; coord mp; /* * bsze is the maximum room size */ bsze.x = cols()/3; bsze.y = lines()/3; /* * Clear things for a new level */ for (rp = rooms; rp < &rooms[MAXROOMS]; rp++) rp->r_goldval = rp->r_nexits = rp->r_flags = 0; /* * Put the gone rooms, if any, on the level */ left_out = rnd(4); for (i = 0; i < left_out; i++) rooms[rnd_room()].r_flags |= ISGONE; /* * dig and populate all the rooms on the level */ for (i = 0, rp = rooms; i < MAXROOMS; rp++, i++) { /* * Find upper left corner of box that this room goes in */ top.x = (i%3)*bsze.x + 1; top.y = i/3*bsze.y; if (rp->r_flags & ISGONE) { /* * Place a gone room. Make certain that there is a blank line * for passage drawing. */ do { rp->r_pos.x = top.x + rnd(bsze.x-2) + 1; rp->r_pos.y = top.y + rnd(bsze.y-2) + 1; rp->r_max.x = -cols(); rp->r_max.x = -lines(); } until(rp->r_pos.y > 0 && rp->r_pos.y < lines()-1); continue; } if (rnd(10) < level-1) rp->r_flags |= ISDARK; /* * Find a place and size for a random room */ do { rp->r_max.x = rnd(bsze.x - 4) + 4; rp->r_max.y = rnd(bsze.y - 4) + 4; rp->r_pos.x = top.x + rnd(bsze.x - rp->r_max.x); rp->r_pos.y = top.y + rnd(bsze.y - rp->r_max.y); } until (rp->r_pos.y != 0); /* * Put the gold in */ if (rnd(100) < 50 && (!amulet || level >= max_level)) { rp->r_goldval = GOLDCALC; rnd_pos(rp, &rp->r_gold); if (roomin(&rp->r_gold) != rp) endwin(), abort(); } draw_room(rp); /* * Put the monster in */ if (rnd(100) < (rp->r_goldval > 0 ? 80 : 25)) { item = new_item(sizeof *tp); tp = (struct thing *) ldata(item); do { rnd_pos(rp, &mp); } until(mvwinch(stdscr, mp.y, mp.x) == FLOOR); new_monster(item, randmonster(FALSE), &mp); /* * See if we want to give it a treasure to carry around. */ if (rnd(100) < monsters[tp->t_type-'A'].m_carry) attach(tp->t_pack, new_thing()); } }
int chase(struct thing *tp, coord *ee) { int x, y; int dist, thisdist; struct linked_list *item; struct object *obj; coord *er = &tp->t_pos; int ch; /* * If the thing is confused, let it move randomly. Invisible * Stalkers are slightly confused all of the time, and bats are * quite confused all the time */ if ((on(*tp, ISHUH) && rnd(10) < 8) || (tp->t_type == 'I' && rnd(100) < 20) || (tp->t_type == 'B' && rnd(100) < 50)) { /* * get a valid random move */ ch_ret = *rndmove(tp); dist = DISTANCE(ch_ret.y, ch_ret.x, ee->y, ee->x); /* * Small chance that it will become un-confused */ if (rnd(1000) < 50) tp->t_flags &= ~ISHUH; } /* * Otherwise, find the empty spot next to the chaser that is * closest to the chasee. */ else { int ey, ex; /* * This will eventually hold where we move to get closer * If we can't find an empty spot, we stay where we are. */ dist = DISTANCE(er->y, er->x, ee->y, ee->x); ch_ret = *er; ey = er->y + 1; ex = er->x + 1; for (x = er->x - 1; x <= ex; x++) for (y = er->y - 1; y <= ey; y++) { coord tryp; tryp.x = x; tryp.y = y; if (!diag_ok(er, &tryp)) continue; ch = winat(y, x); if (step_ok(ch)) { /* * If it is a scroll, it might be a scare monster scroll * so we need to look it up to see what type it is. */ if (ch == SCROLL) { for (item = lvl_obj; item != NULL; item = next(item)) { obj = (struct object *) ldata(item); if (y == obj->o_pos.y && x == obj->o_pos.x) break; } if (item != NULL && obj->o_which == S_SCARE) continue; } /* * If we didn't find any scrolls at this place or it * wasn't a scare scroll, then this place counts */ thisdist = DISTANCE(y, x, ee->y, ee->x); if (thisdist < dist) { ch_ret = tryp; dist = thisdist; } } } } return (dist != 0); }
static int ft245r_open(PROGRAMMER * pgm, char * port) { int rv; int devnum = -1; rv = pins_check(pgm,pin_checklist,sizeof(pin_checklist)/sizeof(pin_checklist[0]), true); if(rv) { pgm->display(pgm, progbuf); return rv; } strcpy(pgm->port, port); if (strcmp(port,DEFAULT_USB) != 0) { if (strncasecmp("ft", port, 2) == 0) { char *startptr = port + 2; char *endptr = NULL; devnum = strtol(startptr,&endptr,10); if ((startptr==endptr) || (*endptr != '\0')) { devnum = -1; } } if (devnum < 0) { avrdude_message(MSG_INFO, "%s: invalid portname '%s': use 'ft[0-9]+'\n", progname,port); return -1; } } else { devnum = 0; } handle = malloc (sizeof (struct ftdi_context)); ftdi_init(handle); LNODEID usbpid = lfirst(pgm->usbpid); int pid; if (usbpid) { pid = *(int *)(ldata(usbpid)); if (lnext(usbpid)) avrdude_message(MSG_INFO, "%s: Warning: using PID 0x%04x, ignoring remaining PIDs in list\n", progname, pid); } else { pid = USB_DEVICE_FT245; } rv = ftdi_usb_open_desc_index(handle, pgm->usbvid?pgm->usbvid:USB_VENDOR_FTDI, pid, pgm->usbproduct[0]?pgm->usbproduct:NULL, pgm->usbsn[0]?pgm->usbsn:NULL, devnum); if (rv) { avrdude_message(MSG_INFO, "can't open ftdi device %d. (%s)\n", devnum, ftdi_get_error_string(handle)); goto cleanup_no_usb; } ft245r_ddr = pgm->pin[PIN_AVR_SCK].mask[0] | pgm->pin[PIN_AVR_MOSI].mask[0] | pgm->pin[PIN_AVR_RESET].mask[0] | pgm->pin[PPI_AVR_BUFF].mask[0] | pgm->pin[PPI_AVR_VCC].mask[0] | pgm->pin[PIN_LED_ERR].mask[0] | pgm->pin[PIN_LED_RDY].mask[0] | pgm->pin[PIN_LED_PGM].mask[0] | pgm->pin[PIN_LED_VFY].mask[0]; /* set initial values for outputs, no reset everything else is off */ ft245r_out = 0; ft245r_out = SET_BITS_0(ft245r_out,pgm,PIN_AVR_RESET,1); ft245r_out = SET_BITS_0(ft245r_out,pgm,PIN_AVR_SCK,0); ft245r_out = SET_BITS_0(ft245r_out,pgm,PIN_AVR_MOSI,0); ft245r_out = SET_BITS_0(ft245r_out,pgm,PPI_AVR_BUFF,0); ft245r_out = SET_BITS_0(ft245r_out,pgm,PPI_AVR_VCC,0); ft245r_out = SET_BITS_0(ft245r_out,pgm,PIN_LED_ERR,0); ft245r_out = SET_BITS_0(ft245r_out,pgm,PIN_LED_RDY,0); ft245r_out = SET_BITS_0(ft245r_out,pgm,PIN_LED_PGM,0); ft245r_out = SET_BITS_0(ft245r_out,pgm,PIN_LED_VFY,0); rv = ftdi_set_bitmode(handle, ft245r_ddr, BITMODE_SYNCBB); // set Synchronous BitBang if (rv) { avrdude_message(MSG_INFO, "%s: Synchronous BitBangMode is not supported (%s)\n", progname, ftdi_get_error_string(handle)); goto cleanup; } rv = ft245r_set_bitclock(pgm); if (rv) { goto cleanup; } /* We start a new thread to read the output from the FTDI. This is * necessary because otherwise we'll deadlock. We cannot finish * writing because the ftdi cannot send the results because we * haven't provided a read buffer yet. */ sem_init (&buf_data, 0, 0); sem_init (&buf_space, 0, BUFSIZE); pthread_create (&readerthread, NULL, reader, handle); /* * drain any extraneous input */ ft245r_drain (pgm, 0); ft245r_send (pgm, &ft245r_out, 1); ft245r_recv (pgm, &ft245r_in, 1); return 0; cleanup: ftdi_usb_close(handle); cleanup_no_usb: ftdi_deinit (handle); free(handle); handle = NULL; return -1; }