static void twoargs(char *str, int *arg1, int *arg2, int def, int min, int max) { char *p = str; p = onearg(p, '=', arg1, def, min, max); p = onearg(p, ',', arg2, *arg1, min, max); if (*p) fatal("malformed argument `%s'", str); }
/* * 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; }
static int nargs(char *str, int *buf, int n, int def, int min, int max) { char *p = str; int i = 0, del = '='; while (n--) { if (*p) i++; p = onearg(p, del, buf++, def, min, max); del = ','; } if (*p) fatal("malformed argument `%s'", str); return i; }
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 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 assa(void) { struct combat off[1]; /* assaulting ship */ struct combat def[1]; /* defending sector */ int fort_sup, ship_sup, land_sup, plane_sup; struct emp_qelem olist; /* assaulting units */ struct emp_qelem dlist; /* defending units */ int ototal; /* total assaulting strength */ int a_engineer = 0; /* assaulter engineers are present */ int a_spy = 0; /* the best assaulter scout */ double osupport = 1.0; /* assault support */ double dsupport = 1.0; /* defense support */ char *p; char buf[1024]; int n; int ourtotal; struct emp_qelem *qp, *next; struct ulist *llp; int rel; att_combat_init(off, EF_SHIP); att_combat_init(def, EF_SECTOR); /* * Collect input from the assaulter */ /* What are we assaulting? */ if (!(p = getstarg(player->argp[1], "Sector : ", buf))) return RET_SYN; if (!sarg_xy(p, &def->x, &def->y)) return RET_SYN; if (att_abort(A_ASSAULT, NULL, def)) return RET_FAIL; /* * Ask the assaulter what he wants to assault with */ if ((off->shp_uid = onearg(player->argp[2], "Assault from ship # ")) < 0) { pr("You may only assault from one ship!\n"); return RET_FAIL; } if (att_abort(A_ASSAULT, off, def)) { pr("Assault aborted\n"); return RET_OK; } /* Show what we're assaulting */ att_show(def); /* Ask about offensive support */ att_ask_support(3, &fort_sup, &ship_sup, &land_sup, &plane_sup); if (att_abort(A_ASSAULT, off, def)) { att_empty_attack(A_ASSAULT, 0, def); return RET_OK; } /* Ask the player what he wants to assault with */ att_ask_offense(A_ASSAULT, off, def, &olist, &a_spy, &a_engineer); if (att_abort(A_ASSAULT, off, def)) { pr("Assault aborted\n"); att_empty_attack(A_ASSAULT, 0, def); return att_free_lists(&olist, NULL); } /* If we're assaulting our own sector, end here */ if (def->own == player->cnum) { if (off->troops) pr("You reinforce %s with %d troops\n", xyas(def->x, def->y, player->cnum), off->troops); if (off->troops || !QEMPTY(&olist)) att_move_in_off(A_ASSAULT, off, &olist, def); return RET_OK; } ototal = att_get_offense(A_ASSAULT, off, &olist, def); if (att_abort(A_ASSAULT, off, def)) { pr("Assault aborted\n"); att_empty_attack(A_ASSAULT, 0, def); return att_free_lists(&olist, NULL); } /* * We have now got all the answers from the assaulter. From this point * forward, we can assume that this battle is the _only_ thing * happening in the game. */ /* First, we check to see if the only thing we have are spies * assaulting. If so, we try to sneak them on land. If they * make it, the defenders don't see a thing. If they fail, well, * the spies die, and the defenders see them. */ ourtotal = 0; for (n = 0; n <= off->last; n++) { if (off[n].type == EF_BAD) continue; ourtotal += off[n].troops * att_combat_eff(off + n); } for (qp = olist.q_forw; qp != &olist; qp = next) { next = qp->q_forw; llp = (struct ulist *)qp; if (lchr[(int)llp->unit.land.lnd_type].l_flags & L_SPY) continue; ourtotal++; } /* If no attacking forces (i.e. we got here with only spies) * then try to sneak on-land. */ if (!ourtotal) { pr("Trying to sneak on shore...\n"); for (qp = olist.q_forw; qp != &olist; qp = next) { next = qp->q_forw; llp = (struct ulist *)qp; rel = relations_with(def->own, player->cnum); if (chance(0.10) || rel == ALLIED || !def->own) { pr("%s made it on shore safely.\n", prland(&llp->unit.land)); llp->unit.land.lnd_x = def->x; llp->unit.land.lnd_y = def->y; llp->unit.land.lnd_ship = -1; putland(llp->unit.land.lnd_uid, &llp->unit.land); } else { pr("%s was spotted", prland(&llp->unit.land)); if (rel <= HOSTILE) { wu(0, def->own, "%s spy shot and killed in %s.\n", cname(player->cnum), xyas(def->x, def->y, def->own)); pr(" and was killed in the attempt.\n"); llp->unit.land.lnd_effic = 0; putland(llp->unit.land.lnd_uid, &llp->unit.land); lnd_put_one(llp); } else { wu(0, def->own, "%s spy spotted in %s.\n", cname(player->cnum), xyas(def->x, def->y, def->own)); pr(" but made it ok.\n"); llp->unit.land.lnd_x = def->x; llp->unit.land.lnd_y = def->y; llp->unit.land.lnd_ship = -1; putland(llp->unit.land.lnd_uid, &llp->unit.land); } } } return RET_OK; } /* Get the real defense */ att_get_defense(&olist, def, &dlist, a_spy, ototal); /* Get assaulter and defender support */ att_get_support(A_ASSAULT, fort_sup, ship_sup, land_sup, plane_sup, &olist, off, &dlist, def, &osupport, &dsupport, a_engineer); if (att_abort(A_ASSAULT, off, def)) { pr("Assault aborted\n"); att_empty_attack(A_ASSAULT, 0, def); return att_free_lists(&olist, &dlist); } /* * Death, carnage, and destruction. */ att_fight(A_ASSAULT, off, &olist, osupport, def, &dlist, dsupport); return RET_OK; }