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; }
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; }
int scra(void) { struct nstr_item ni; union empobj_storage item; int type, n; struct sctstr sect; struct mchrstr *mp; struct plchrstr *pp; struct lchrstr *lp; char *p; i_type i; char prompt[128]; char buf[1024]; float eff; short *mvec; int amt; if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf))) return RET_SYN; switch (*p) { case 's': type = EF_SHIP; break; case 'p': type = EF_PLANE; break; case 'l': type = EF_LAND; break; default: pr("Ships, land units, or planes only! (s, l, p)\n"); return RET_SYN; } if (!snxtitem(&ni, type, player->argp[2], NULL)) return RET_SYN; n = 0; while (nxtitem(&ni, &item)) { if (!player->owner) continue; n++; } snprintf(prompt, sizeof(prompt), "Really scrap %d %s%s [n]? ", n, ef_nameof(type), splur(n)); if (!confirm(prompt)) return RET_FAIL; snxtitem_rewind(&ni); while (nxtitem(&ni, &item)) { if (!player->owner) continue; if (opt_MARKET) { if (ontradingblock(type, &item.ship)) { pr("You cannot scrap an item on the trading block!\n"); continue; } } getsect(item.gen.x, item.gen.y, §); if (type == EF_SHIP) { if (!player->owner && relations_with(sect.sct_own, player->cnum) < FRIENDLY) { pr("%s is not in a friendly harbor!\n", prship(&item.ship)); continue; } if (sect.sct_type != SCT_HARBR || sect.sct_effic < 60) { pr("%s is not in a 60%% efficient harbor!\n", prship(&item.ship)); continue; } if (mchr[item.ship.shp_type].m_flags & M_TRADE) { pr("WARNING: You only collect money from trade ships if you \"scuttle\" them!\n"); sprintf(prompt, "Are you really sure that you want to scrap %s (n)? ", prship(&item.ship)); if (!confirm(prompt)) { pr("%s not scrapped\n", prship(&item.ship)); continue; } } } else { if (!player->owner && relations_with(sect.sct_own, player->cnum) != ALLIED) { pr("%s is not in an allied sector!\n", unit_nameof(&item.gen)); continue; } if (type == EF_PLANE && (sect.sct_type != SCT_AIRPT || sect.sct_effic < 60)) { pr("%s is not in a 60%% efficient airfield!\n", prplane(&item.plane)); continue; } } pr("%s scrapped in %s\n", unit_nameof(&item.gen), xyas(item.gen.x, item.gen.y, player->cnum)); unit_drop_cargo(&item.gen, sect.sct_own); if (type == EF_SHIP) { eff = item.ship.shp_effic / 100.0; mp = &mchr[(int)item.ship.shp_type]; for (i = I_NONE + 1; i <= I_MAX; i++) { if (load_comm_ok(§, item.ship.shp_own, i, -item.ship.shp_item[i])) sect.sct_item[i] += item.ship.shp_item[i]; } mvec = mp->m_mat; if (item.ship.shp_pstage == PLG_INFECT && sect.sct_pstage == PLG_HEALTHY) sect.sct_pstage = PLG_EXPOSED; } else if (type == EF_LAND) { eff = item.land.lnd_effic / 100.0; lp = &lchr[(int)item.land.lnd_type]; for (i = I_NONE + 1; i <= I_MAX; i++) { if (load_comm_ok(§, item.land.lnd_own, i, -item.land.lnd_item[i])) sect.sct_item[i] += item.land.lnd_item[i]; } mvec = lp->l_mat; if (item.land.lnd_pstage == PLG_INFECT && sect.sct_pstage == PLG_HEALTHY) sect.sct_pstage = PLG_EXPOSED; } else { eff = item.land.lnd_effic / 100.0; pp = &plchr[(int)item.plane.pln_type]; mvec = pp->pl_mat; } item.gen.effic = 0; put_empobj(type, item.gen.uid, &item.gen); for (i = I_NONE + 1; i <= I_MAX; i++) { if (i == I_CIVIL || i == I_MILIT || i == I_UW) amt = sect.sct_item[i] + mvec[i] * eff; else amt = sect.sct_item[i] + mvec[i] * 2 / 3 * eff; if (amt > ITEM_MAX) amt = ITEM_MAX; sect.sct_item[i] = amt; } putsect(§); } return RET_OK; }