int trade_getitem(struct trdstr *tp, union empobj_storage *tgp) { if (!ef_read(tp->trd_type, tp->trd_unitid, tgp)) return 0; return 1; }
/* * Choose whether we want to accept, decline, or postpone a * loan. Put all the goodies in ltcp, and return * RET_OK if all goes well, and anything else on error. */ static int cons_choose(struct ltcomstr *ltcp) { static int lon_or_trt[] = { EF_LOAN, EF_BAD }; char *p; struct lonstr *lp; char prompt[128]; char buf[1024]; memset(ltcp, 0, sizeof(*ltcp)); p = player->argp[1] ? player->argp[1] : "loan"; ltcp->type = ef_byname_from(p, lon_or_trt); switch (ltcp->type) { case EF_LOAN: if (!opt_LOANS) { pr("Loans are not enabled.\n"); return RET_FAIL; } ltcp->name = "loan"; ltcp->Name = "Loan"; break; default: pr("You must specify \"loan\".\n"); return RET_SYN; } sprintf(prompt, "%s number? ", ltcp->Name); if ((ltcp->num = onearg(player->argp[2], prompt)) < 0) return RET_SYN; if (!ef_read(ltcp->type, ltcp->num, <cp->u) || !cons_display(ltcp)) { pr("%s #%d is not being offered to you!\n", ltcp->Name, ltcp->num); return RET_SYN; } switch (ltcp->type) { case EF_LOAN: lp = <cp->u.l; if (lp->l_status == LS_SIGNED) { pr("That loan has already been accepted!\n"); return RET_FAIL; } ltcp->proposer = lp->l_loner; ltcp->proposee = lp->l_lonee; break; } ltcp->mailee = (ltcp->proposer == player->cnum) ? ltcp->proposee : ltcp->proposer; p = getstarg(player->argp[3], "Accept, decline or postpone? ", buf); if (!p || (*p != 'a' && *p != 'd' && *p != 'p')) return RET_SYN; ltcp->op = *p; return RET_OK; }
int nxtitem(struct nstr_item *np, void *ptr) { struct empobj *gp; int selected; if (np->sel == NS_UNDEF) return 0; gp = (struct empobj *)ptr; do { if (np->sel == NS_LIST) { np->index++; if (np->index >= np->size) return 0; np->cur = np->list[np->index]; } else if (np->sel == NS_CARGO) { if (np->next < 0) return 0; np->cur = np->next; np->next = unit_cargo_next(np->type, np->next); } else { np->cur++; } if (!ef_read(np->type, np->cur, ptr)) return 0; selected = 1; switch (np->sel) { case NS_LIST: case NS_CARGO: case NS_ALL: break; case NS_DIST: if (CANT_HAPPEN(!(ef_flags(np->type) & EFF_XY))) return 0; if (!xyinrange(gp->x, gp->y, &np->range)) { selected = 0; break; } np->curdist = mapdist(gp->x, gp->y, np->cx, np->cy); if (np->curdist > np->dist) selected = 0; break; case NS_AREA: if (CANT_HAPPEN(!(ef_flags(np->type) & EFF_XY))) return 0; if (!xyinrange(gp->x, gp->y, &np->range)) selected = 0; break; case NS_XY: if (CANT_HAPPEN(!(ef_flags(np->type) & EFF_XY))) return 0; if (xnorm(gp->x) != np->cx || ynorm(gp->y) != np->cy) selected = 0; break; case NS_GROUP: if (CANT_HAPPEN(!(ef_flags(np->type) & EFF_GROUP))) return 0; if (np->group != gp->group) selected = 0; break; default: CANT_REACH(); return 0; } if (selected && np->ncond) { /* nstr_exec is expensive, so we do it last */ if (!nstr_exec(np->cond, np->ncond, ptr)) selected = 0; } } while (!selected); return 1; }
static int verify_row(int type, int row) { struct castr *ca = ef_cadef(type); struct empobj *row_ref; int i, j, n; struct valstr val; int ret_val = 0; int flags = ef_flags(type); if (flags & EFF_MEM) row_ref = ef_ptr(type, row); else { row_ref = malloc(empfile[type].size); ef_read(type, row, row_ref); } if ((flags & EFF_TYPED) && !EF_IS_VIEW(type)) { if (row_ref->ef_type != type || row_ref->uid != row) { verify_fail(type, row, NULL, 0, "header corrupt"); ret_val = -1; } } if (!empobj_in_use(type, row_ref)) goto out; for (i = 0; ca[i].ca_name; ++i) { if (ca[i].ca_get) continue; /* virtual */ n = CA_ARRAY_LEN(&ca[i]); j = 0; do { if (ca[i].ca_table == EF_BAD) continue; nstr_mksymval(&val, &ca[i], j); nstr_eval(&val, 0, row_ref, NSC_NOTYPE); if (CANT_HAPPEN(val.val_type != NSC_LONG)) { ret_val = -1; continue; } if (ca[i].ca_table == type && i == 0) { /* uid */ if (val.val_as.lng != row) { verify_fail(type, row, &ca[i], j, "value is %ld instead of %d", val.val_as.lng, row); ret_val = -1; } } else { if (verify_tabref(type, row, &ca[i], j, val.val_as.lng) < 0) ret_val = -1; } } while (++j < n); } out: if (!(flags & EFF_MEM)) free(row_ref); return ret_val; }