int oly_parse(struct command *c, char *s) { c->a = 0; c->b = 0; c->c = 0; c->d = 0; c->e = 0; c->f = 0; c->g = 0; c->h = 0; if (!oly_parse_cmd(c, s)) return FALSE; switch (min(ilist_len(c->parse), 9)) { case 9: c->h = parse_arg(c->who, c->parse[8]); case 8: c->g = parse_arg(c->who, c->parse[7]); case 7: c->f = parse_arg(c->who, c->parse[6]); case 6: c->e = parse_arg(c->who, c->parse[5]); case 5: c->d = parse_arg(c->who, c->parse[4]); case 4: c->c = parse_arg(c->who, c->parse[3]); case 3: c->b = parse_arg(c->who, c->parse[2]); case 2: c->a = parse_arg(c->who, c->parse[1]); } return TRUE; }
void cmd_shift(struct command *c) { if (ilist_len(c->parse) > 1) { /* * Deleted argument need not be freed, since it's just a * pointer into another string. It was never allocated * itself. */ ilist_delete((ilist *) & c->parse, 1); } c->a = c->b; c->b = c->c; c->c = c->d; c->d = c->e; c->e = c->f; c->f = c->g; c->g = c->h; if (numargs(c) >= 8) c->h = parse_arg(c->who, c->parse[8]); else c->h = 0; }
void remove_from_here_list(int loc, int who) { assert(in_here_list(loc, who)); ilist_rem_value(&(rp_loc_info(loc)->here_list), who); /* * Mon Apr 20 18:08:44 1998 -- Scott Turner * * Thanks to Rich's nice encapsulation, this is the only * place we have to worry about someone being the last person * out of a subloc...so here's where we reset the fees. * * Anyway, that's plan :-). * */ if (!ilist_len(rp_loc_info(loc)->here_list) && rp_subloc(loc)) { rp_subloc(loc)->control.weight = 0; rp_subloc(loc)->control.nobles = 0; rp_subloc(loc)->control.men = 0; rp_subloc(loc)->control2.weight = 0; rp_subloc(loc)->control2.nobles = 0; rp_subloc(loc)->control2.men = 0; }; assert(!in_here_list(loc, who)); }
void immediate_commands() { struct command *c; char buf[LEN]; char *line; printf("Olympia immediate mode\n"); immediate = gm_player; out(immediate, "You are now %s.", box_name(immediate)); init_locs_touched(); show_day = TRUE; while (1) { c = p_command(immediate); c->who = immediate; c->wait = 0; printf("%d> ", immediate); fflush(stdout); if ((line = getlin(stdin)) == NULL) break; strcpy(buf, line); if (!oly_parse(c, buf)) { printf("Unrecognized command.\n"); continue; } if (c->fuzzy) out(immediate, "(assuming you meant '%s')", cmd_tbl[c->cmd].name); c->pri = cmd_tbl[c->cmd].pri; c->wait = cmd_tbl[c->cmd].time; c->poll = cmd_tbl[c->cmd].poll; c->days_executing = 0; c->state = STATE_LOAD; do_command(c); while (c->state == STATE_RUN) { evening = 1; finish_command(c); evening = 0; olytime_increment(&sysclock); } if (ilist_len(trades_to_check) > 0) check_validated_trades(); /* show_day = FALSE; */ } putchar('\n'); }
char * display_with(int who) { if (rp_loc_info(who) && ilist_len(rp_loc_info(who)->here_list) > 0) return ", accompanied~by:"; return ""; }
int oly_parse_cmd(struct command *c, char *s) { c->cmd = 0; c->fuzzy = FALSE; c->use_skill = 0; while (iswhite(*s)) s++; remove_comment(s); remove_ctrl_chars(s); if (c->line) my_free(c->line); c->line = str_save(s); if (*s == '&') { c->conditional = 1; s++; } else if (*s == '?') { c->conditional = 2; s++; } else c->conditional = 0; if (c->parsed_line) my_free(c->parsed_line); c->parsed_line = str_save(s); c->parse = parse_line(c->parse, c->parsed_line); if (ilist_len(c->parse) > 0) { int i; i = find_command(c->parse[0]); if (i > 0) { c->cmd = i; if (fuzzy_find) c->fuzzy = TRUE; } else return FALSE; } return TRUE; }
int location_direction(int where, int dir) { struct entity_loc *p; dir--; p = rp_loc(where); if (p == NULL || dir >= ilist_len(p->prov_dest)) return 0; return p->prov_dest[dir]; }
static void add_here(int who, ilist *l) { int i; struct loc_info *p; assert(valid_box(who)); ilist_append(l, who); p = rp_loc_info(who); assert(p != NULL); for (i = 0; i < ilist_len(p->here_list); i++) add_here(p->here_list[i], l); }
void all_here(int who, ilist *l) { int i; struct loc_info *p; assert(valid_box(who)); ilist_clear(l); p = rp_loc_info(who); if (p == NULL) return; for (i = 0; i < ilist_len(p->here_list); i++) add_here(p->here_list[i], l); }
void all_stack(int who, ilist *l) { int i; struct loc_info *p; assert(valid_box(who)); ilist_clear(l); ilist_append(l, who); p = rp_loc_info(who); if (p == NULL) return; for (i = 0; i < ilist_len(p->here_list); i++) if (kind(p->here_list[i]) == T_char) add_char_here(p->here_list[i], l); }
int v_bird_spy(struct command *c) { int targ = c->a; int where = subloc(c->who); struct exit_view *v; if (!has_holy_symbol(c->who)) { wout(c->who, "A holy symbol is required to bird spy."); return FALSE; }; if (!has_piety(c->who, skill_piety(c->use_skill))) { wout(c->who, "You don't have the piety required to use that prayer."); return FALSE; }; if (is_ship(where)) where = loc(where); if (numargs(c) < 1) { wout(c->who, "Specify what location the bird should spy on."); return FALSE; } if (!is_loc_or_ship(c->a)) { v = parse_exit_dir(c, where, sout("use %d", sk_bird_spy)); if (v == NULL) return FALSE; targ = v->destination; } if (province(targ) != province(c->who)) { struct exit_view **l; int i; int okay = FALSE; l = exits_from_loc(c->who, where); for (i = 0; i < ilist_len(l); i++) if (l[i]->destination == targ) okay = TRUE; if (!okay) { wout(c->who, "The location to be spied upon must be " "a sublocation in the same province or a " "neighboring location."); return FALSE; } } c->d = targ; return TRUE; }
void fix_gates() { int where; struct exit_view **l; int set_one; int i; int dest; int m; clear_temps(T_loc); loop_province(where) { if (!in_hades(where) && !in_clouds(where) && !in_faery(where)) continue; if (!province_gate_here(where)) continue; fprintf(stderr, "Gate in %s\n", box_name(where)); l = exits_from_loc_nsew(0, where); for (i = 0; i < ilist_len(l); i++) { if (loc_depth(l[i]->destination) != LOC_province) continue; if (!province_gate_here(l[i]->destination)) { bx[l[i]->destination]->temp = 1; } } } next_province; m = 1; do { set_one = FALSE; loop_province(where) { if (!in_hades(where) && !in_clouds(where) && !in_faery(where)) continue; if (province_gate_here(where) || bx[where]->temp != m) continue; l = exits_from_loc_nsew(0, where); for (i = 0; i < ilist_len(l); i++) { dest = l[i]->destination; if (loc_depth(dest) != LOC_province) continue; if (!province_gate_here(dest) && bx[dest]->temp == 0) { bx[dest]->temp = m + 1; set_one = TRUE; } } } next_province; m++; } while (set_one); loop_province(where) { if (!in_hades(where) && !in_clouds(where) && !in_faery(where)) continue; if (!province_gate_here(where) && bx[where]->temp < 1) fprintf(stderr, "error on %d\n", where); } next_province; loop_province(where) { if (!in_hades(where) && !in_clouds(where) && !in_faery(where)) continue; p_loc(where)->dist_from_gate = bx[where]->temp; } next_province; }