int testing_cmd(void) { char *p; char buf[1024]; p = getstarg(player->argp[1], "? ", buf); if (!p) return RET_SYN; if (!strcmp(p, "added")) { p = getstarg(player->argp[2], "number? ", buf); if (!p || !*p) return RET_SYN; test_suite_prng_seed -= strtol(p, NULL, 10); p = getstarg(player->argp[3], "BTUs? ", buf); if (!p || !*p) return RET_SYN; player->btused -= strtol(p, NULL, 10); p = getstarg(player->argp[4], "money? ", buf); if (!p) return RET_SYN; player->dolcost -= strtod(p, NULL); return RET_OK; } return RET_SYN; }
int reje(void) { static char *what[] = { "teles", "annos", "loans" }; char *p; enum rej_comm rej; int do_undo; struct natstr nat; struct nstr_item ni; char buf[1024]; if (!(p = getstarg(player->argp[1], "reject or accept? ", buf))) return RET_SYN; switch (*p) { case 'r': do_undo = 1; break; case 'a': do_undo = 0; break; default: pr("That's not one of the choices!\n"); return RET_SYN; } p = getstarg(player->argp[2], "mail, loans, or announcements? ", buf); if (!p) return RET_SYN; switch (*p) { case 'a': rej = REJ_ANNO; break; case 'l': rej = REJ_LOAN; break; case 'm': rej = REJ_TELE; break; default: pr("That's not one of the choices!\n"); return RET_SYN; } if (!snxtitem(&ni, EF_NATION, player->argp[3], NULL)) return RET_SYN; while (nxtitem(&ni, &nat)) { if (nat.nat_stat == STAT_GOD) { pr("You may not reject/accept stuff from %s\n" "because they are a deity.\n", nat.nat_cnam); continue; } if (nat.nat_stat == STAT_UNUSED) continue; pr("%s %s from %s\n", (do_undo == 1 ? "Rejecting" : "Accepting"), what[rej], nat.nat_cnam); setrej(player->cnum, (natid)ni.cur, do_undo, rej); } return RET_OK; }
/* Extended dump command */ int xdump(void) { char *p; char buf[1024]; struct xdstr xd; struct natstr *natp; int type; int meta = 0; p = getstarg(player->argp[1], "Table name, or meta? ", buf); if (p && strcmp(p, "meta") == 0) { meta = 1; p = getstarg(player->argp[2], "Table name? ", buf); } if (!p || !*p) return RET_SYN; xdinit(&xd, player->cnum, 0, 0, pr); natp = getnatp(player->cnum); type = isdigit(p[0]) ? atoi(p) : ef_byname(p); if (type < 0 || type >= EF_MAX) return RET_SYN; if (meta) return xdmeta(&xd, type); if ((EF_IS_GAME_STATE(type) || EF_IS_VIEW(type)) && !(natp->nat_stat == STAT_ACTIVE || player->god)) { pr("Access to table %s denied\n", ef_nameof(type)); return RET_FAIL; } return xditem(&xd, type, player->argp[2]); }
/* * Get assembly point argument. * If INPUT is not empty, use it, else prompt for more input using PROMPT. * If this yields a valid assembly point, read it into *AP_SECT and * return AP_SECT. * Else complain and return NULL. * *AP_SECT and BUF[1024] may be modified in either case. */ struct sctstr * get_assembly_point(char *input, struct sctstr *ap_sect, char *buf) { char *p; coord x, y; struct nstr_item ni; struct shpstr ship; p = getstarg(input, "assembly point? ", buf); if (!p || *p == 0) return NULL; if (!sarg_xy(p, &x, &y) || !getsect(x, y, ap_sect)) return NULL; /* over own or allied sector is fine */ if (relations_with(ap_sect->sct_own, player->cnum) == ALLIED) return ap_sect; /* over own or allied ship is fine */ snxtitem_xy(&ni, EF_SHIP, x, y); while (nxtitem(&ni, &ship)) { if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0) continue; if (relations_with(ship.shp_own, player->cnum) == ALLIED) return ap_sect; } pr("Assembly point not owned by you or an ally!\n"); return NULL; }
/* * Get nation argument. * If @arg is not empty, use it * Else prompt for input using @prompt. * If no input is provided, return NULL. * If the argument identifies a country, return its getnatp() value. * Else complain and return NULL. * Caution: this function doesn't care for lack of contact. */ struct natstr * natargp(char *arg, char *prompt) { char buf[1024]; int n; struct natstr *np; arg = getstarg(arg, prompt, buf); if (!arg || !*arg) return NULL; if (isdigit(*arg)) n = atoi(arg); else { n = cnumb(arg); if (n == M_NOTUNIQUE) { pr("Country '%s' is ambiguous\n", arg); return NULL; } } np = getnatp(n); if (!np || np->nat_stat == STAT_UNUSED) { pr("Country '%s' doesn't exist.\n", arg); return NULL; } return np; }
int range(void) { struct nstr_item np; struct plnstr plane; int i, rmax; char *p; char buf[1024]; if (!snxtitem(&np, EF_PLANE, player->argp[1], NULL)) return RET_SYN; while (nxtitem(&np, &plane)) { if (!player->owner || plane.pln_own == 0) continue; p = getstarg(player->argp[2], "New range? ", buf); if (!p) return RET_FAIL; if (!check_plane_ok(&plane)) return RET_SYN; if ((i = atoi(p)) < 0) continue; rmax = pln_range_max(&plane); plane.pln_range = MIN(rmax, i); pr("Plane %d range changed to %d\n", plane.pln_uid, plane.pln_range); putplane(plane.pln_uid, &plane); } return RET_OK; }
int mark(void) { char buf[1024]; char *p; struct ichrstr *ip; if (!opt_MARKET) { pr("The market is disabled.\n"); return RET_FAIL; } if (player->argp[1]) { p = getstarg(player->argp[1], "What commodity (or 'all')? ", buf); if (!p) return RET_SYN; if (!strcmp(p, "all")) return display_mark(I_NONE, 0); else { ip = item_by_name(p); if (!ip) return RET_SYN; return display_mark(ip->i_uid, 0); } } return display_mark(I_NONE, 1); }
int wing(void) { struct plnstr plane; int count; char *cp; char c; struct nstr_item nstr; char buf[1024]; if (!(cp = getstarg(player->argp[1], "wing? ", buf))) return RET_SYN; c = *cp; if (!isalpha(c) && c != '~') { pr("Specify wing, (1 alpha char or '~')\n"); return RET_SYN; } if (c == '~') c = 0; if (!snxtitem(&nstr, EF_PLANE, player->argp[2], NULL)) return RET_SYN; count = 0; while (nxtitem(&nstr, &plane)) { if (plane.pln_own != player->cnum) continue; if (plane.pln_wing == c) continue; plane.pln_wing = c; putplane(plane.pln_uid, &plane); count++; } pr("%d plane%s added to wing `%1.1s'\n", count, splur(count), &c); return RET_OK; }
int shark(void) { int arg; time_t now; char *p; struct lonstr loan; struct natstr *natp; struct natstr *oldie; double owed; int payment; char buf[1024]; if (!opt_LOANS) { pr("Loans are not enabled.\n"); return RET_FAIL; } p = getstarg(player->argp[1], "Transfer which loan #: ", buf); if (!p) return RET_SYN; if (*p == 0) return RET_SYN; arg = atoi(p); if (arg < 0) return RET_SYN; /* Check if it's a valid loan to shark. That means, is it a valid loan, not owed to this player, with a valid duration and it's been signed. */ if (!getloan(arg, &loan) || (loan.l_loner == player->cnum) || (loan.l_ldur == 0) || (loan.l_status != LS_SIGNED)) { pr("Invalid loan\n"); return RET_FAIL; } /* If we got here, we check to see if it's been defaulted on. */ owed = loan_owed(&loan, time(&now)); if (now <= loan.l_duedate) { pr("There has been no default on loan %d\n", arg); return RET_FAIL; } pr("That loan is worth $%.2f.\n", owed); natp = getnatp(player->cnum); payment = (int)ceil(owed * (1.0 + loan.l_irate / 100.0)); if (payment > natp->nat_money - 100.0) { pr("You do not have enough to cover that loan\n"); return RET_FAIL; } else { wu(0, loan.l_lonee, "%s bought loan #%d. You now owe him!\n", cname(player->cnum), arg); wu(0, loan.l_loner, "%s bought loan #%d out from under you for %d\n", cname(player->cnum), arg, payment); pr("You now own loan #%d. Go break some legs.\n", arg); } oldie = getnatp(loan.l_loner); oldie->nat_money += payment; player->dolcost += payment; loan.l_loner = player->cnum; putloan(arg, &loan); return RET_OK; }
static int load_comm_land(struct sctstr *sectp, struct lndstr *lp, struct ichrstr *ich, int load_unload, int *nunitsp) { i_type item = ich->i_uid; struct lchrstr *lcp = &lchr[(int)lp->lnd_type]; int land_amt, sect_amt, move_amt; char prompt[512]; char *p; char buf[1024]; sprintf(prompt, "Number of %s to %s %s at %s? ", ich->i_name, (load_unload == UNLOAD) ? "unload from" : "load onto", prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum)); p = getstarg(player->argp[3], prompt, buf); if (!p || !*p) return RET_SYN; if (!still_ok_land(sectp, lp)) return RET_SYN; land_amt = lp->lnd_item[item]; sect_amt = sectp->sct_item[item]; move_amt = move_amount(sect_amt, land_amt, lcp->l_item[item], load_unload, atoi(p)); if (!load_comm_ok(sectp, lp->lnd_own, item, move_amt)) return RET_OK; sectp->sct_item[item] = sect_amt - move_amt; lp->lnd_item[item] = land_amt + move_amt; /* Did we put mils onto this unit? If so, reset the fortification */ if (item == I_MILIT && move_amt > 0) lp->lnd_harden = 0; if (move_amt >= 0) { pr("%d %s loaded onto %s at %s\n", move_amt, ich->i_name, prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum)); if (lp->lnd_own != player->cnum) { wu(0, lp->lnd_own, "%s loaded %d %s onto %s at %s\n", cname(player->cnum), move_amt, ich->i_name, prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own)); } } else { pr("%d %s unloaded from %s at %s\n", -move_amt, ich->i_name, prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum)); if (sectp->sct_own != player->cnum) { wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n", cname(player->cnum), -move_amt, ich->i_name, prland(lp), xyas(lp->lnd_x, lp->lnd_y, sectp->sct_own)); } } ++*nunitsp; return 0; }
static int load_comm_ship(struct sctstr *sectp, struct shpstr *sp, struct ichrstr *ich, int load_unload, int *nshipsp) { i_type item = ich->i_uid; struct mchrstr *mcp = &mchr[(int)sp->shp_type]; int ship_amt, sect_amt, move_amt; char prompt[512]; char *p; char buf[1024]; sprintf(prompt, "Number of %s to %s %s at %s? ", ich->i_name, (load_unload == UNLOAD) ? "unload from" : "load onto", prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum)); p = getstarg(player->argp[3], prompt, buf); if (!p || !*p) return RET_SYN; if (!still_ok_ship(sectp, sp)) return RET_SYN; ship_amt = sp->shp_item[item]; sect_amt = sectp->sct_item[item]; move_amt = move_amount(sect_amt, ship_amt, mcp->m_item[item], load_unload, atoi(p)); if (!load_comm_ok(sectp, sp->shp_own, item, move_amt)) return RET_OK; if (!abandon_askyn(sectp, item, move_amt, NULL)) return RET_FAIL; if (!still_ok_ship(sectp, sp)) return RET_SYN; sectp->sct_item[item] = sect_amt - move_amt; sp->shp_item[item] = ship_amt + move_amt; if (move_amt >= 0) { pr("%d %s loaded onto %s at %s\n", move_amt, ich->i_name, prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum)); if (sp->shp_own != player->cnum) { wu(0, sp->shp_own, "%s loaded %d %s onto %s at %s\n", cname(player->cnum), move_amt, ich->i_name, prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own)); } } else { pr("%d %s unloaded from %s at %s\n", -move_amt, ich->i_name, prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum)); if (sectp->sct_own != player->cnum) { wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n", cname(player->cnum), -move_amt, ich->i_name, prship(sp), xyas(sp->shp_x, sp->shp_y, sectp->sct_own)); } } ++*nshipsp; return 0; }
/* * threshold <COMM> <SECTS> <THRESH> */ int thre(void) { struct sctstr sect; struct nstr_sect nstr; int val; struct ichrstr *ip; char *p; int thresh; i_type type; char prompt[128]; char buf[128]; if (!(ip = whatitem(player->argp[1], "What commodity? "))) return RET_SYN; if (!snxtsct(&nstr, player->argp[2])) return RET_SYN; type = ip->i_uid; while (nxtsct(&nstr, §)) { if (!player->owner) continue; val = sect.sct_dist[type]; if (val > 0) sprintf(prompt, "%s %s old threshold %d new? ", xyas(nstr.x, nstr.y, player->cnum), dchr[sect.sct_type].d_name, val); else sprintf(prompt, "%s %s threshold? ", xyas(nstr.x, nstr.y, player->cnum), dchr[sect.sct_type].d_name); if (!(p = getstarg(player->argp[3], prompt, buf))) return RET_FAIL; if (!*p) continue; if (!check_sect_ok(§)) return RET_FAIL; thresh = atoi(p); if (thresh < 0) return RET_FAIL; if (thresh > ITEM_MAX) thresh = ITEM_MAX; if ((val > 0) && (val == thresh)) { pr("%s threshold unchanged (left at %d)\n", xyas(nstr.x, nstr.y, player->cnum), val); continue; } if (val > 0 && player->argp[3] && *player->argp[3]) pr("%s old threshold %d\n", xyas(nstr.x, nstr.y, player->cnum), val); sect.sct_dist[type] = thresh; putsect(§); } return RET_OK; }
/* * 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; }
/* * Get item type argument. * If @input is not empty, use it. * Else prompt for more input using @prompt. * Return item characteristics on success, else NULL. */ struct ichrstr * whatitem(char *input, char *prompt) { char *p; struct ichrstr *ip; char buf[1024]; p = getstarg(input, prompt, buf); if (!p || !*p) return NULL; ip = item_by_name(p); if (!ip) pr("Unrecognized item \"%c\"\n", *p); return ip; }
int orig(void) { char *p; coord x, y; char buf[1024]; int cnum; struct natstr *np; p = getstarg(player->argp[1], "New origin (sector or country) : ", buf); if (!p || !*p) return RET_SYN; if (!isalpha(*p) && strchr(p, ',')) { /* sector */ if (!sarg_xy(p, &x, &y)) { pr("Bad sector designation.\n"); return RET_SYN; } } else if (*p == '~') { /* reset */ if (!player->god) { pr("Only deities can reset their origin.\n"); return RET_FAIL; } x = y = 0; } else { /* country */ cnum = natarg(p, NULL); if (!(np = getnatp(cnum))) return RET_SYN; if (!player->god && relations_with(cnum, player->cnum) != ALLIED) { pr("Country %s is not allied with you!\n", np->nat_cnam); return RET_FAIL; } x = np->nat_xorg; y = np->nat_yorg; } pr("Origin at %s (old system) is now at 0,0 (new system).\n", xyas(x, y, player->cnum)); np = getnatp(player->cnum); np->nat_xorg = x; np->nat_yorg = y; putnat(np); return RET_OK; }
int shut(void) { int shutdown_minutes; int shutdown_was_pending; char buf[1024]; char *p; shutdown_minutes = onearg(player->argp[1], "Time until shutdown in minutes (-1 to abort shutdown sequence)? "); if (player->aborted) return RET_SYN; if (!updates_disabled()) { p = getstarg(player->argp[2], "Disable update [y]? ", buf); if (!p) return RET_SYN; if (*p != 'n') disa(); } shutdown_was_pending = shutdown_initiate(shutdown_minutes); if (shutdown_was_pending < 0) return RET_FAIL; if (shutdown_minutes >= 0) { if (shutdown_was_pending) pr("The shutdown time has been changed to %d minutes!\n", shutdown_minutes); else pr("Shutdown sequence begun.\n"); } else { if (shutdown_was_pending) pr("The server shutdown has been cancelled!\n"); else { pr("No shutdown to abort\n"); return RET_FAIL; } } return RET_OK; }
int upgr(void) { char *p; char buf[1024]; if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf))) return RET_SYN; switch (*p) { case 's': case 'S': return supgr(); case 'p': case 'P': return pupgr(); case 'l': case 'L': return lupgr(); default: break; } pr("Ships, land units or planes only!\n"); return RET_SYN; }
static int load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy, int load_unload, int *nunitsp) { struct nstr_item ni; struct plnstr pln; int loaded = 0; char *p; char prompt[512]; char buf[1024]; struct lchrstr *lcp = lchr + lp->lnd_type; if (!lcp->l_nxlight) { if (noisy) pr("%s cannot carry extra-light planes.\n", prland(lp)); return 0; } if (load_unload == LOAD && lnd_nxlight(lp) >= lcp->l_nxlight) { if (noisy) pr("%s doesn't have room for any more extra-light planes\n", prland(lp)); return 0; } sprintf(prompt, "Plane(s) to %s %s? ", load_unload == LOAD ? "load onto" : "unload from", prland(lp)); p = getstarg(player->argp[3], prompt, buf); if (!p) return RET_SYN; if (!snxtitem(&ni, EF_PLANE, p, NULL)) return RET_SYN; if (!still_ok_land(sectp, lp)) return RET_SYN; if (noisy && p && *p) noisy = isdigit(*p); while (nxtitem(&ni, &pln)) { if (!player->owner) continue; if (!(plchr[(int)pln.pln_type].pl_flags & P_E)) { if (noisy) pr("You can only load xlight planes onto units.\n"); continue; } if (load_unload == LOAD && pln.pln_ship > -1) { if (noisy) pr("%s is already on ship #%d!\n", prplane(&pln), pln.pln_ship); continue; } if (load_unload == LOAD && pln.pln_land > -1) { if (noisy) pr("%s is already on unit #%d!\n", prplane(&pln), pln.pln_land); continue; } if (pln.pln_harden != 0) { if (noisy) pr("%s has been hardened and can't be loaded\n", prplane(&pln)); continue; } /* Plane sanity done */ /* Find the right unit */ if (load_unload == UNLOAD) { if (pln.pln_land != lp->lnd_uid) continue; } else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y) continue; /* Fit plane on unit */ if (load_unload == LOAD) { if (!put_plane_on_land(&pln, lp)) { if (noisy) pr("Can't put plane %d on this unit!\n", pln.pln_uid); continue; } sprintf(buf, "loaded on %s at %s", prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own)); gift(lp->lnd_own, player->cnum, &pln, buf); putplane(pln.pln_uid, &pln); } else { pln.pln_land = -1; sprintf(buf, "unloaded at your sector at %s", xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own)); gift(sectp->sct_own, player->cnum, &pln, buf); putplane(pln.pln_uid, &pln); } pr("%s %s %s at %s.\n", prplane(&pln), (load_unload == UNLOAD) ? "unloaded from" : "loaded onto", prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum)); loaded = 1; } *nunitsp += loaded; return 0; }
int load(void) { int noisy; int load_unload; int type; struct nstr_item nbst; struct ichrstr *ich; int nships; struct sctstr sect; struct shpstr ship; int retval; char *p; char buf[1024]; p = getstarg(player->argp[1], "What commodity (or 'plane' or 'land')? ", buf); if (!p || !*p) return RET_SYN; if (!strncmp(p, "plane", 5)) type = EF_PLANE; else if (!strncmp(p, "land", 4)) type = EF_LAND; else if (NULL != (ich = item_by_name(p))) type = EF_SECTOR; else { pr("Can't load '%s'\n", p); return RET_SYN; } p = getstarg(player->argp[2], "Ship(s): ", buf); if (!p || !*p) return RET_SYN; noisy = isdigit(*p); if (!snxtitem(&nbst, EF_SHIP, p, NULL)) return RET_SYN; load_unload = **player->argp == 'l' ? LOAD : UNLOAD; nships = 0; while (nxtitem(&nbst, &ship)) { if (!ship.shp_own) continue; if (!player->owner) { if (load_unload == UNLOAD || !noisy) continue; if (relations_with(ship.shp_own, player->cnum) < FRIENDLY) continue; } if (!getsect(ship.shp_x, ship.shp_y, §)) /* XXX */ continue; if (!sect.sct_own) continue; if (!player->owner) { if (ship.shp_own != player->cnum) continue; if (!sect_has_dock(§)) continue; if (load_unload == LOAD) { if (noisy) pr("You don't own %s\n", xyas(sect.sct_x, sect.sct_y, player->cnum)); continue; } } if (!sect_has_dock(§)) { if (noisy) pr("Sector %s is not a harbor or canal.\n", xyas(sect.sct_x, sect.sct_y, player->cnum)); continue; } if (load_unload == UNLOAD && !player->owner && relations_with(sect.sct_own, player->cnum) < FRIENDLY) { if (noisy) pr("You can't unload into an unfriendly %s\n", dchr[sect.sct_type].d_name); continue; } if (sect.sct_effic < 2) { if (noisy) pr("The %s at %s is not 2%% efficient yet.\n", dchr[sect.sct_type].d_name, xyas(sect.sct_x, sect.sct_y, player->cnum)); continue; } if (opt_MARKET) { if (ontradingblock(EF_SHIP, &ship)) { pr("You cannot load/unload an item on the trading block!\n"); continue; } } switch (type) { case EF_PLANE: retval = load_plane_ship(§, &ship, noisy, load_unload, &nships); if (retval != 0) return retval; break; case EF_LAND: retval = load_land_ship(§, &ship, noisy, load_unload, &nships); if (retval != 0) return retval; break; case EF_SECTOR: retval = load_comm_ship(§, &ship, ich, load_unload, &nships); if (retval != 0) return retval; } /* load/unload plague */ if (sect.sct_pstage == PLG_INFECT && ship.shp_pstage == PLG_HEALTHY) ship.shp_pstage = PLG_EXPOSED; if (ship.shp_pstage == PLG_INFECT && sect.sct_pstage == PLG_HEALTHY) sect.sct_pstage = PLG_EXPOSED; putsect(§); putship(ship.shp_uid, &ship); } if (!nships) pr("No ships affected\n"); else pr("%d ship%s %sloaded\n", nships, splur(nships), load_unload == UNLOAD ? "un" : ""); return RET_OK; }
static int load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy, int load_unload, int *nshipsp) { struct nstr_item ni; struct lndstr land; int loaded = 0; char *p; char prompt[512]; char buf[1024]; int load_spy = 0; if (load_unload == LOAD) { if ((mchr[(int)sp->shp_type].m_flags & M_SUB) && (mchr[(int)sp->shp_type].m_nland == 0)) { if (shp_nland(sp) >= 2) { pr("Non-land unit carrying subs can only carry up to two spy units.\n"); return 0; } /* Eh, let 'em load a spy only */ load_spy = 1; } if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) { if (noisy) { if (mchr[(int)sp->shp_type].m_nland) pr("%s doesn't have room for any more land units!\n", prship(sp)); else pr("%s cannot carry land units!\n", prship(sp)); } return 0; } } sprintf(prompt, "Land unit(s) to %s %s? ", load_unload == LOAD ? "load onto" : "unload from", prship(sp)); p = getstarg(player->argp[3], prompt, buf); if (!p) return RET_SYN; if (!snxtitem(&ni, EF_LAND, p, NULL)) return RET_SYN; if (!still_ok_ship(sectp, sp)) return RET_SYN; if (noisy && p && *p) noisy = isdigit(*p); while (nxtitem(&ni, &land)) { if (!player->owner) continue; if (load_unload == LOAD) { if (land.lnd_ship > -1) { if (noisy) pr("%s is already on ship #%d!\n", prland(&land), land.lnd_ship); continue; } if (land.lnd_land > -1) { if (noisy) pr("%s is already on land #%d!\n", prland(&land), land.lnd_land); continue; } if (lnd_first_on_land(&land) >= 0) { if (noisy) pr("%s cannot be loaded since it is carrying units\n", prland(&land)); continue; } if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) { if (noisy) pr("%s is too heavy to load.\n", prland(&land)); continue; } if (load_spy && !(lchr[(int)land.lnd_type].l_flags & L_SPY)) { if (noisy) pr("Subs can only carry spy units.\n"); continue; } } /* Unit sanity done */ /* Find the right ship */ if (load_unload == UNLOAD) { if (land.lnd_ship != sp->shp_uid) continue; if (land.lnd_land > -1) continue; } else if (sp->shp_x != land.lnd_x || sp->shp_y != land.lnd_y) continue; if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) && (!((mchr[(int)sp->shp_type].m_flags & M_SUPPLY) && (!(mchr[(int)sp->shp_type].m_flags & M_SUB))))) { if (noisy) { pr("You can only load light units onto ships,\n"); pr("unless the ship is a non-sub supply ship\n"); pr("%s not loaded\n", prland(&land)); } continue; } /* Fit unit on ship */ if (load_unload == LOAD) { /* We have to check again, since it may have changed */ if ((mchr[(int)sp->shp_type].m_flags & M_SUB) && (mchr[(int)sp->shp_type].m_nland == 0)) { if (shp_nland(sp) >= 2) { pr("Non-land unit carrying subs can only carry up to two spy units.\n"); return 0; } /* Eh, let 'em load a spy only */ load_spy = 1; } if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) { if (noisy) { if (mchr[(int)sp->shp_type].m_nland) pr("%s doesn't have room for any more land units!\n", prship(sp)); else pr("%s cannot carry land units!\n", prship(sp)); } return 0; } sprintf(buf, "loaded on your %s at %s", prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own)); gift(sp->shp_own, player->cnum, &land, buf); land.lnd_ship = sp->shp_uid; land.lnd_harden = 0; putland(land.lnd_uid, &land); #if 0 /* * FIXME if this supplies from the sector, the putsect in * load() / lload() duplicates those supplies, causing a * seqno mismatch */ if (!lnd_supply_all(&land)) pr("WARNING: %s is out of supply!\n", prland(&land)); #else if (!lnd_in_supply(&land)) pr("WARNING: %s is out of supply!\n", prland(&land)); #endif } else { sprintf(buf, "unloaded in your %s at %s", dchr[sectp->sct_type].d_name, xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own)); /* Spies are unloaded quietly, others aren't */ if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) gift(sectp->sct_own, player->cnum, &land, buf); land.lnd_ship = -1; putland(land.lnd_uid, &land); } pr("%s %s %s at %s.\n", prland(&land), (load_unload == UNLOAD) ? "unloaded from" : "loaded onto", prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum)); loaded = 1; } *nshipsp += loaded; return 0; }
static int load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy, int load_unload, int *nshipsp) { struct nstr_item ni; struct plnstr pln; int loaded = 0; char buf[1024]; char *p; char prompt[512]; struct mchrstr *mcp = mchr + sp->shp_type; if (mcp->m_nplanes + mcp->m_nchoppers + mcp->m_nxlight == 0) { if (noisy) pr("%s cannot carry planes\n", prship(sp)); return 0; } if (load_unload == LOAD && shp_nplane(sp, NULL, NULL, NULL) >= mcp->m_nchoppers + mcp->m_nxlight + mcp->m_nplanes) { if (noisy) pr("%s doesn't have room for any more planes\n", prship(sp)); return 0; } sprintf(prompt, "Plane(s) to %s %s? ", load_unload == LOAD ? "load onto" : "unload from", prship(sp)); p = getstarg(player->argp[3], prompt, buf); if (!p) return RET_SYN; if (!snxtitem(&ni, EF_PLANE, p, NULL)) return RET_SYN; if (!still_ok_ship(sectp, sp)) return RET_SYN; if (noisy && p && *p) noisy = isdigit(*p); while (nxtitem(&ni, &pln)) { if (!player->owner) continue; if (!(plchr[(int)pln.pln_type].pl_flags & P_L) && !(plchr[(int)pln.pln_type].pl_flags & P_E) && !(plchr[(int)pln.pln_type].pl_flags & P_K) && !(plchr[(int)pln.pln_type].pl_flags & P_M) ) { if (noisy) pr("You can only load light planes, helos, xtra-light, or missiles onto ships.\n"); continue; } if (load_unload == LOAD && pln.pln_ship > -1) { if (noisy) pr("%s is already on ship #%d!\n", prplane(&pln), pln.pln_ship); continue; } if (load_unload == LOAD && pln.pln_land > -1) { if (noisy) pr("%s is already on land unit #%d!\n", prplane(&pln), pln.pln_land); continue; } if (pln.pln_harden != 0) { if (noisy) pr("%s has been hardened and can't be loaded\n", prplane(&pln)); continue; } if (load_unload == UNLOAD) { if (pln.pln_ship != sp->shp_uid) continue; } else if (sp->shp_x != pln.pln_x || sp->shp_y != pln.pln_y) continue; if (!could_be_on_ship(&pln, sp)) { if (noisy) { if (plchr[(int)pln.pln_type].pl_flags & P_K) p = "choppers"; else if (plchr[(int)pln.pln_type].pl_flags & P_E) p = "extra light planes"; else if (plchr[(int)pln.pln_type].pl_flags & P_M) p = "missiles"; else p = "planes"; pr("%s cannot carry %s.\n", prship(sp), p); } continue; } /* Fit plane on ship */ if (load_unload == LOAD) { if (!put_plane_on_ship(&pln, sp)) { if (noisy) pr("Can't put plane %d on this ship!\n", pln.pln_uid); continue; } sprintf(buf, "loaded on your %s at %s", prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own)); gift(sp->shp_own, player->cnum, &pln, buf); putplane(pln.pln_uid, &pln); } else { pln.pln_ship = -1; sprintf(buf, "unloaded in your %s at %s", dchr[sectp->sct_type].d_name, xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own)); gift(sectp->sct_own, player->cnum, &pln, buf); putplane(pln.pln_uid, &pln); } pr("%s %s %s at %s.\n", prplane(&pln), (load_unload == UNLOAD) ? "unloaded from" : "loaded onto", prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum)); loaded = 1; } *nshipsp += loaded; return 0; }
int lload(void) { int noisy; int load_unload; int type; struct nstr_item nbst; struct ichrstr *ich; int nunits; struct sctstr sect; struct lndstr land; int retval; char *p; char buf[1024]; p = getstarg(player->argp[1], "What commodity (or 'plane' or 'land')? ", buf); if (!p || !*p) return RET_SYN; if (!strncmp(p, "plane", 5)) type = EF_PLANE; else if (!strncmp(p, "land", 4)) type = EF_LAND; else if (NULL != (ich = item_by_name(p))) type = EF_SECTOR; else { pr("Can't load '%s'\n", p); return RET_SYN; } p = getstarg(player->argp[2], "Unit(s): ", buf); if (!p || !*p) return RET_SYN; noisy = isdigit(*p); if (!snxtitem(&nbst, EF_LAND, p, NULL)) return RET_SYN; load_unload = player->argp[0][1] == 'l' ? LOAD : UNLOAD; nunits = 0; while (nxtitem(&nbst, &land)) { if (land.lnd_own == 0) continue; if (!player->owner) { if (load_unload == UNLOAD || !noisy) continue; if (relations_with(land.lnd_own, player->cnum) != ALLIED) continue; } if (!getsect(land.lnd_x, land.lnd_y, §)) /* XXX */ continue; if (!player->owner) { if (land.lnd_own != player->cnum) continue; if (load_unload == LOAD) { if (noisy) pr("Sector %s is not yours.\n", xyas(sect.sct_x, sect.sct_y, player->cnum)); continue; } if (relations_with(sect.sct_own, player->cnum) != ALLIED) { pr("Sector %s is not yours.\n", xyas(sect.sct_x, sect.sct_y, player->cnum)); continue; } } if (opt_MARKET) { if (ontradingblock(EF_LAND, &land)) { pr("You cannot load/unload an item on the trading block!\n"); continue; } } switch (type) { case EF_LAND: retval = load_land_land(§, &land, noisy, load_unload, &nunits); if (retval != 0) return retval; break; case EF_PLANE: retval = load_plane_land(§, &land, noisy, load_unload, &nunits); if (retval != 0) return retval; break; case EF_SECTOR: retval = load_comm_land(§, &land, ich, load_unload, &nunits); if (retval != 0) return retval; } /* load/unload plague */ if (sect.sct_pstage == PLG_INFECT && land.lnd_pstage == PLG_HEALTHY) land.lnd_pstage = PLG_EXPOSED; if (land.lnd_pstage == PLG_INFECT && sect.sct_pstage == PLG_HEALTHY) sect.sct_pstage = PLG_EXPOSED; putsect(§); putland(land.lnd_uid, &land); } if (nunits == 0) pr("No units affected\n"); else pr("%d unit%s %sloaded\n", nunits, splur(nunits), load_unload == UNLOAD ? "un" : ""); return RET_OK; }
/* * format: set <type> <SHIP/NUKE> <PRICE> */ int set(void) { static int ef_saleable[] = { EF_SHIP, EF_PLANE, EF_LAND, EF_NUKE, EF_BAD }; char *p; int type; int price; char prompt[80]; struct trdstr trade; struct nstr_item ni; struct nstr_item ni_trade; union empobj_storage item; struct sctstr sect; int freeslot; int foundslot; int id; time_t now; char buf[1024]; if (!opt_MARKET) { pr("The market is disabled.\n"); return RET_FAIL; } check_market(); check_trade(); p = getstarg(player->argp[1], "Ship, plane, land unit or nuke? ", buf); if (!p) return RET_SYN; if ((type = ef_byname_from(p, ef_saleable)) < 0) { pr("You can sell only ships, planes, land units or nukes\n"); return RET_SYN; } if (!snxtitem(&ni, type, player->argp[2], NULL)) return RET_SYN; while (nxtitem(&ni, &item)) { if (!player->owner && !player->god) continue; getsect(item.gen.x, item.gen.y, §); if (!military_control(§)) { pr("Military control required to sell goods.\n"); return RET_FAIL; } trade.trd_type = type; sprintf(prompt, "%s #%d; price? ", trade_nameof(&trade, &item.gen), ni.cur); if (!(p = getstarg(player->argp[3], prompt, buf))) return RET_FAIL; if (!check_obj_ok(&item.gen)) return RET_FAIL; if ((price = atoi(p)) < 0) continue; foundslot = -1; freeslot = -1; snxtitem_all(&ni_trade, EF_TRADE); while (nxtitem(&ni_trade, &trade)) { if (trade.trd_owner == 0) freeslot = ni_trade.cur; if (trade.trd_unitid == ni.cur && trade.trd_type == type) { foundslot = ni_trade.cur; break; } } if (price <= 0) { if (foundslot >= 0) { pr("%s #%d (lot #%d) removed from trading\n", trade_nameof(&trade, &item.gen), ni.cur, foundslot); trade.trd_owner = 0; puttrade(ni_trade.cur, &trade); } } else { if (trade_has_unsalable_cargo(&item.gen, 1)) return RET_FAIL; if (foundslot >= 0) id = foundslot; else if (freeslot >= 0) id = freeslot; else id = ni_trade.cur; ef_blank(EF_TRADE, id, &trade); trade.trd_x = 1; trade.trd_y = 0; trade.trd_type = type; trade.trd_owner = player->cnum; trade.trd_unitid = ni.cur; trade.trd_price = price; (void)time(&now); trade.trd_markettime = now; trade.trd_maxbidder = player->cnum; puttrade(id, &trade); pr("%s #%d (lot #%d) price %s to $%d\n", trade_nameof(&trade, &item.gen), ni.cur, id, foundslot >= 0 ? "reset" : "set", price); } } return RET_OK; }
int tend(void) { struct nstr_item targets; struct nstr_item tenders; struct shpstr tender; struct shpstr target; struct ichrstr *ip; struct mchrstr *vbase; int amt; int retval; int ontender; int ontarget; int maxtender; int maxtarget; int transfer; int total; int type; char *p; char prompt[512]; char buf[1024]; p = getstarg(player->argp[1], "Tend what commodity (or 'land')? ", buf); if (!p || !*p) return RET_SYN; if (!strncmp(p, "land", 4)) type = EF_LAND; else if (NULL != (ip = item_by_name(p))) type = EF_SECTOR; else { pr("Can't tend '%s'\n", p); return RET_SYN; } if (!snxtitem(&tenders, EF_SHIP, player->argp[2], "Tender(s)? ")) return RET_SYN; while (nxtitem(&tenders, &tender)) { if (!player->owner) continue; if (type == EF_LAND) { sprintf(prompt, "Land unit(s) to tend from %s? ", prship(&tender)); p = getstarg(player->argp[3], prompt, buf); if (!p) return RET_FAIL; if (!*p) continue; if (!check_ship_ok(&tender)) return RET_SYN; if (0 != (retval = tend_land(&tender, p))) return retval; continue; } sprintf(prompt, "Number of %s to tend from %s? ", ip->i_name, prship(&tender)); p = getstarg(player->argp[3], prompt, buf); if (!p) return RET_FAIL; if (!*p) continue; if (!check_ship_ok(&tender)) return RET_SYN; if (!(amt = atoi(p))) { pr("Amount must be non-zero!\n"); return RET_SYN; } ontender = tender.shp_item[ip->i_uid]; if (ontender == 0 && amt > 0) { pr("No %s on %s\n", ip->i_name, prship(&tender)); return RET_FAIL; } vbase = &mchr[(int)tender.shp_type]; maxtender = vbase->m_item[ip->i_uid]; if (maxtender == 0) { pr("A %s cannot hold any %s\n", mchr[(int)tender.shp_type].m_name, ip->i_name); break; } if (!snxtitem(&targets, EF_SHIP, player->argp[4], "Ships to be tended? ")) return RET_FAIL; if (!check_ship_ok(&tender)) return RET_SYN; total = 0; while (nxtitem(&targets, &target)) { if (!player->owner && relations_with(target.shp_own, player->cnum) < FRIENDLY) continue; if (target.shp_uid == tender.shp_uid) continue; if (tender.shp_x != target.shp_x || tender.shp_y != target.shp_y) continue; if (ip->i_uid == I_CIVIL && tender.shp_own != target.shp_own) continue; ontarget = target.shp_item[ip->i_uid]; vbase = &mchr[(int)target.shp_type]; maxtarget = vbase->m_item[ip->i_uid]; if (amt < 0) { /* take from target and give to tender */ if (!player->owner) continue; if (ontarget == 0) { pr("No %s on %s\n", ip->i_name, prship(&target)); continue; } transfer = MIN(ontarget, -amt); transfer = MIN(maxtender - ontender, transfer); if (transfer == 0) continue; target.shp_item[ip->i_uid] = ontarget - transfer; ontender += transfer; total += transfer; } else { /* give to target from tender */ transfer = MIN(ontender, amt); transfer = MIN(transfer, maxtarget - ontarget); if (transfer == 0) continue; target.shp_item[ip->i_uid] = ontarget + transfer; ontender -= transfer; total += transfer; if (transfer && target.shp_own != player->cnum) { wu(0, target.shp_own, "%s tended %d %s to %s\n", cname(player->cnum), total, ip->i_name, prship(&target)); } } expose_ship(&tender, &target); putship(target.shp_uid, &target); if (amt > 0 && ontender == 0) { pr("%s out of %s\n", prship(&tender), ip->i_name); break; } } pr("%d total %s transferred %s %s\n", total, ip->i_name, (amt > 0) ? "off of" : "to", prship(&tender)); tender.shp_item[ip->i_uid] = ontender; tender.shp_mission = 0; putship(tender.shp_uid, &tender); } return RET_OK; }
int work(void) { int nunits; struct nstr_item ni; struct sctstr sect; struct lndstr land; int work_amt, eff_amt, w; char *p; char buf[1024]; double cost; struct natstr *natp = getnatp(player->cnum); if (!snxtitem(&ni, EF_LAND, player->argp[1], NULL)) return RET_SYN; p = getstarg(player->argp[2], "Amount: ", buf); if (!p || !*p) return RET_SYN; work_amt = atoi(p); if ((work_amt < 0) || (work_amt > land_mob_max)) { pr("Mobility used must be from 0 to %d\n", land_mob_max); return RET_FAIL; } nunits = 0; while (nxtitem(&ni, &land)) { if (!player->owner || land.lnd_own == 0) continue; if (!(lchr[(int)land.lnd_type].l_flags & L_ENGINEER)) continue; if (land.lnd_mobil <= 0) { pr("%s has no mobility!\n", prland(&land)); continue; } getsect(land.lnd_x, land.lnd_y, §); if (sect.sct_effic >= 100 && sect.sct_type == sect.sct_newtype) { pr("Nothing to do for %s in %s\n", prland(&land), xyas(sect.sct_x, sect.sct_y, player->cnum)); continue; } eff_amt = MIN(land.lnd_mobil, work_amt); w = (eff_amt * land.lnd_effic) / 600; if (w < 1) { pr("%s doesn't work enough to change efficiency (try increasing amount)\n", prland(&land)); continue; } cost = 0.0; w = buildeff(§, w, &cost); if (w == 0) { pr("%s can't change efficiency in %s\n", prland(&land), xyas(land.lnd_x, land.lnd_y, player->cnum)); continue; } if (player->dolcost + cost > natp->nat_money) { pr("You can't afford to work that much in %s!\n", xyas(land.lnd_x, land.lnd_y, player->cnum)); break; } player->dolcost += cost; land.lnd_mission = 0; land.lnd_mobil -= roundavg(w * 600.0 / land.lnd_effic); nunits++; pr("%s %s efficiency at %s to %d\n", prland(&land), sect.sct_type == sect.sct_newtype ? "raised" : "lowered", xyas(land.lnd_x, land.lnd_y, player->cnum), sect.sct_effic); putland(land.lnd_uid, &land); putsect(§); } if (nunits == 0) { if (player->argp[1]) pr("%s: No unit(s)\n", player->argp[1]); else pr("%s: No unit(s)\n", ""); return RET_FAIL; } else pr("%d unit%s\n", nunits, splur(nunits)); return RET_OK; }
static int load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy, int load_unload, int *nunitsp) { struct nstr_item ni; struct lndstr land; int loaded = 0; char *p; char prompt[512]; char buf[1024]; if (load_unload == LOAD && lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) { if (noisy) { if (lchr[lp->lnd_type].l_nland) pr("%s doesn't have room for any more land units!\n", prland(lp)); else pr("%s cannot carry land units!\n", prland(lp)); } return 0; } sprintf(prompt, "Land unit(s) to %s %s? ", load_unload == LOAD ? "load onto" : "unload from", prland(lp)); p = getstarg(player->argp[3], prompt, buf); if (!p) return RET_SYN; if (!snxtitem(&ni, EF_LAND, p, NULL)) return RET_SYN; if (!still_ok_land(sectp, lp)) return RET_SYN; if (noisy && p && *p) noisy = isdigit(*p); while (nxtitem(&ni, &land)) { if (!player->owner) continue; if (load_unload == LOAD) { if (land.lnd_ship > -1) { if (noisy) pr("%s is already on ship #%d!\n", prland(&land), land.lnd_ship); continue; } if (land.lnd_land > -1) { if (noisy) pr("%s is already on land #%d!\n", prland(&land), land.lnd_land); continue; } if (lnd_first_on_land(&land) >= 0) { if (noisy) pr("%s cannot be loaded since it is carrying units\n", prland(&land)); continue; } if (land.lnd_uid == lp->lnd_uid) { if (noisy) pr("%s can't be loaded onto itself!\n", prland(&land)); continue; } if (lchr[(int)land.lnd_type].l_flags & (L_HEAVY | L_TRAIN)) { if (noisy) pr("%s is too heavy to load.\n", prland(&land)); continue; } } /* Unit sanity done */ /* Find the right ship */ if (load_unload == UNLOAD) { if (land.lnd_land != lp->lnd_uid) continue; if (land.lnd_ship > -1) continue; } else if (lp->lnd_x != land.lnd_x || lp->lnd_y != land.lnd_y) continue; /* Fit unit on ship */ if (load_unload == LOAD) { if (lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) { if (noisy) { if (lchr[lp->lnd_type].l_nland) pr("%s doesn't have room for any more land units!\n", prland(lp)); else pr("%s cannot carry land units!\n", prland(lp)); } break; } sprintf(buf, "loaded on your %s at %s", prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own)); gift(lp->lnd_own, player->cnum, &land, buf); land.lnd_land = lp->lnd_uid; land.lnd_harden = 0; putland(land.lnd_uid, &land); #if 0 /* FIXME same issue as in load_land_ship() */ if (!lnd_supply_all(&land)) pr("WARNING: %s is out of supply!\n", prland(&land)); #else if (!lnd_in_supply(&land)) pr("WARNING: %s is out of supply!\n", prland(&land)); #endif } else { sprintf(buf, "unloaded in your %s at %s", dchr[sectp->sct_type].d_name, xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own)); gift(sectp->sct_own, player->cnum, &land, buf); land.lnd_land = -1; putland(land.lnd_uid, &land); } pr("%s %s %s at %s.\n", prland(&land), (load_unload == UNLOAD) ? "unloaded from" : "loaded onto", prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum)); loaded = 1; } *nunitsp += loaded; return 0; }
int repa(void) { struct lonstr loan; struct natstr *natp; struct natstr *loaner; int loan_num; int payment; int newdue; char *cp; time_t now; char buf[1024]; if (!opt_LOANS) { pr("Loans are not enabled.\n"); return RET_FAIL; } natp = getnatp(player->cnum); cp = getstarg(player->argp[1], "Repay loan #? ", buf); if (!cp) return RET_SYN; loan_num = atoi(cp); if (loan_num < 0) return RET_SYN; if (!getloan(loan_num, &loan) || loan.l_lonee != player->cnum || loan.l_status != LS_SIGNED) { pr("You don't owe anything on that loan.\n"); return RET_FAIL; } if (!(cp = getstarg(player->argp[2], "amount? ", buf))) return RET_SYN; if (!check_loan_ok(&loan)) return RET_FAIL; payment = atoi(cp); if (payment <= 0) return RET_SYN; newdue = (int)ceil(loan_owed(&loan, time(&now)) - payment); if (newdue < 0) { pr("You don't owe that much.\n"); return RET_FAIL; } if (natp->nat_money < payment) { pr("You only have $%d.\n", natp->nat_money); return RET_FAIL; } player->dolcost += payment; loaner = getnatp(loan.l_loner); loaner->nat_money += payment; putnat(loaner); loan.l_lastpay = now; if (newdue == 0) { wu(0, loan.l_loner, "Country #%d paid off loan #%d with $%d\n", player->cnum, loan_num, payment); nreport(player->cnum, N_REPAY_LOAN, loan.l_loner, 1); loan.l_status = LS_FREE; loan.l_ldur = 0; pr("Congratulations, you've paid off the loan!\n"); } else { wu(0, loan.l_loner, "Country #%d paid $%d on loan %d\n", player->cnum, payment, loan_num); loan.l_amtdue = newdue; loan.l_amtpaid += payment; } if (!putloan(loan_num, &loan)) { logerror("repa: can't write loan"); pr("Can't save loan; get help!\n"); return RET_FAIL; } return RET_OK; }
int coll(void) { int arg; time_t now; char *p; struct lonstr loan; struct sctstr sect; struct natstr *lonee_np; coord x, y; double owed; double pay; char buf[1024]; if (!opt_LOANS) { pr("Loans are not enabled.\n"); return RET_FAIL; } if ((arg = onearg(player->argp[1], "Collect on loan # ")) < 0) return RET_SYN; /* Check if it's a valid loan. That means, is it a valid loan, owed to this player, with a valid duration and it's been signed. */ if (!getloan(arg, &loan) || (loan.l_loner != player->cnum) || (loan.l_ldur == 0) || (loan.l_status != LS_SIGNED)) { pr("You aren't owed anything on that loan...\n"); return RET_FAIL; } /* If we got here, we check to see if it's been defaulted on. We already know it's owed to this player. */ owed = loan_owed(&loan, time(&now)); if (now <= loan.l_duedate) { pr("There has been no default on loan %d\n", arg); return RET_FAIL; } lonee_np = getnatp(loan.l_lonee); pr("You are owed $%.2f on that loan.\n", owed); p = getstarg(player->argp[2], "What sector do you wish to confiscate? ", buf); if (!p) return RET_SYN; if (!check_loan_ok(&loan)) return RET_FAIL; if (!sarg_xy(p, &x, &y) || !getsect(x, y, §)) return RET_SYN; if (!neigh(x, y, player->cnum)) { pr("You are not adjacent to %s\n", xyas(x, y, player->cnum)); return RET_FAIL; } if (sect.sct_own != loan.l_lonee) { pr("%s is not owned by %s.\n", xyas(x, y, player->cnum), cname(loan.l_lonee)); return RET_FAIL; } pay = appraise_sect(§); if (pay > owed * 1.2) { pr("That sector (and its contents) is valued at more than %.2f.\n", owed); return RET_FAIL; } if (!influx(lonee_np) && sect.sct_x == lonee_np->nat_xcap && sect.sct_y == lonee_np->nat_ycap) { pr("%s's capital cannot be confiscated.\n", cname(loan.l_lonee)); return RET_FAIL; } pr("That sector (and its contents) is valued at $%.2f\n", pay); sect.sct_item[I_MILIT] = 1; /* FIXME now where did this guy come from? */ /* * Used to call takeover() here a long time ago, but that does * unwanted things, like generate che. */ sect.sct_own = player->cnum; memset(sect.sct_dist, 0, sizeof(sect.sct_dist)); memset(sect.sct_del, 0, sizeof(sect.sct_del)); sect.sct_off = 1; sect.sct_dist_x = sect.sct_x; sect.sct_dist_y = sect.sct_y; putsect(§); nreport(player->cnum, N_SEIZE_SECT, loan.l_lonee, 1); owed = loan_owed(&loan, time(&now)); if (pay >= owed) { loan.l_status = LS_FREE; loan.l_ldur = 0; nreport(loan.l_lonee, N_REPAY_LOAN, player->cnum, 1); wu(0, loan.l_lonee, "%s seized %s to satisfy loan #%d\n", cname(player->cnum), xyas(sect.sct_x, sect.sct_y, loan.l_lonee), arg); pr("That loan is now considered repaid.\n"); } else { (void)time(&loan.l_lastpay); owed -= pay; loan.l_amtdue = (int)owed; pay += loan.l_amtpaid; loan.l_amtpaid = (int)pay; wu(0, loan.l_lonee, "%s seized %s in partial payment of loan %d.\n", cname(player->cnum), xyas(sect.sct_x, sect.sct_y, loan.l_lonee), arg); pr("You are still owed $%.2f on loan %d.\n", owed, arg); } putloan(arg, &loan); return RET_OK; }
int chan(void) { char *p; int charge; int btucost; char buf[1024]; struct natstr *us; p = getstarg(player->argp[1], "country name or representative? ", buf); if (!p) return RET_SYN; us = getnatp(player->cnum); switch (*p) { case 'n': case 'c': charge = 0; btucost = 0; if (us->nat_stat == STAT_ACTIVE) { if (opt_BLITZ == 0) { if (us->nat_btu < 254) { pr("You need 254 btus to change your country name!\n"); return RET_FAIL; } pr("This command costs 254 BTU's and 10%% of your money.\n"); if (!confirm("Are you sure you want to do this? ")) return RET_FAIL; btucost = 254; if (us->nat_money <= 0) charge = 0; else charge = us->nat_money / 10; } } p = getstarg(player->argp[2], "New country name -- ", buf); if (!p) return RET_SYN; if (!check_nat_name(p, player->cnum)) return RET_FAIL; player->dolcost += charge; player->btused += btucost; strcpy(us->nat_cnam, p); putnat(us); nreport(player->cnum, N_NAME_CHNG, 0, 1); break; case 'p': case 'r': pr("(note: these are stored in plain text.)\n"); p = getstarg(player->argp[2], "New representative name -- ", buf); if (!p) return RET_SYN; p[sizeof(us->nat_pnam) - 1] = 0; strcpy(us->nat_pnam, p); putnat(us); break; default: pr("Only \"country\" or \"representative\" can change.\n"); return RET_SYN; } return RET_OK; }
int show(void) { char *p; void (*cfunc)(int); void (*sfunc)(int); void (*bfunc)(int); struct natstr *natp; int tlev; char buf[1024]; int rlev; again: p = getstarg(player->argp[1], "Show what ('?' to list options)? ", buf); if (!p || !*p) return RET_SYN; if (*p == '?') { pr("bridge, item, land, news, nuke, plane, sect, ship, product, tower, updates\n"); goto again; } natp = getnatp(player->cnum); rlev = (int)(1.25 * natp->nat_level[NAT_RLEV]); if (!player->argp[3]) { tlev = (int)(1.25 * natp->nat_level[NAT_TLEV]); if (player->god) tlev = 1000; } else { tlev = (int)atoi(player->argp[3]); if (tlev > (int)(1.25 * natp->nat_level[NAT_TLEV]) && !player->god) tlev = (int)(1.25 * natp->nat_level[NAT_TLEV]); } if (player->god) rlev = 1000; switch (*p) { case 'b': show_bridge(99999); return RET_OK; case 't': show_tower(99999); return RET_OK; case 'i': show_item(99999); return RET_OK; case 'n': if (*(p + 1) == 'e') { show_news(99999); return RET_OK; } if (drnuke_const > MIN_DRNUKE_CONST) tlev = ((rlev / drnuke_const) > tlev ? tlev : (rlev / drnuke_const)); bfunc = show_nuke_build; cfunc = show_nuke_capab; sfunc = show_nuke_stats; break; case 'l': bfunc = show_land_build; sfunc = show_land_stats; cfunc = show_land_capab; break; case 'p': if (p[1] == 'r') { show_product(99999); return RET_OK; } bfunc = show_plane_build; sfunc = show_plane_stats; cfunc = show_plane_capab; break; case 's': if (*(p + 1) == 'e') { bfunc = show_sect_build; sfunc = show_sect_stats; cfunc = show_sect_capab; } else { bfunc = show_ship_build; sfunc = show_ship_stats; cfunc = show_ship_capab; } break; case 'u': show_updates(player->argp[2] ? atoi(player->argp[2]) : 8); return RET_OK; default: return RET_SYN; } p = getstarg(player->argp[2], "Build, stats, or capability data (b,s,c)? ", buf); if (!p || !*p) return RET_SYN; pr("Printing for tech level '%d'\n", tlev); if (*p == 'B' || *p == 'b') bfunc(tlev); else if (*p == 'C' || *p == 'c') cfunc(tlev); else if (*p == 'S' || *p == 's') sfunc(tlev); else return RET_SYN; return RET_OK; }