static void unit_list(struct emp_qelem *unit_list) { struct emp_qelem *qp; struct emp_qelem *next; struct ulist *ulp; int type, npln, nch, nxl; struct empobj *unit; struct lndstr *lnd; struct shpstr *shp; if (CANT_HAPPEN(QEMPTY(unit_list))) return; qp = unit_list->q_back; ulp = (struct ulist *)qp; type = ulp->unit.gen.ef_type; if (CANT_HAPPEN(type != EF_LAND && type != EF_SHIP)) return; if (type == EF_LAND) pr("lnd# land type x,y a eff mil sh gun xl ln mu tech retr\n"); else pr("shp# ship type x,y fl eff mil sh gun pn he xl ln mob tech\n"); for (; qp != unit_list; qp = next) { next = qp->q_back; ulp = (struct ulist *)qp; lnd = &ulp->unit.land; shp = &ulp->unit.ship; unit = &ulp->unit.gen; if (CANT_HAPPEN(type != unit->ef_type)) continue; pr("%4d ", unit->uid); pr("%-16.16s ", empobj_chr_name(unit)); prxy("%4d,%-4d ", unit->x, unit->y); pr("%1.1s", &unit->group); pr("%4d%%", unit->effic); if (type == EF_LAND) { pr("%4d", lnd->lnd_item[I_MILIT]); pr("%4d", lnd->lnd_item[I_SHELL]); pr("%4d", lnd->lnd_item[I_GUN]); pr("%3d%3d", lnd_nxlight(lnd), lnd_nland(lnd)); } else { pr("%4d", shp->shp_item[I_MILIT]); pr("%4d", shp->shp_item[I_SHELL]); pr("%4d", shp->shp_item[I_GUN]); npln = shp_nplane(shp, &nch, &nxl, NULL); pr("%3d%3d%3d", npln - nch - nxl, nch, nxl); pr("%3d", shp_nland(shp)); } pr("%4d", unit->mobil); pr("%4d", unit->tech); if (type == EF_LAND) { pr("%4d%%", lnd->lnd_retreat); } pr("\n"); } }
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 tend_land(struct shpstr *tenderp, char *units) { struct nstr_item lni; struct nstr_item targets; struct shpstr target; struct lndstr land; char buf[1024]; if (!snxtitem(&lni, EF_LAND, units, NULL)) return RET_SYN; while (nxtitem(&lni, &land)) { if (!player->owner) continue; if (land.lnd_ship != tenderp->shp_uid) { pr("%s is not on %s!\n", prland(&land), prship(tenderp)); continue; } if (!(lchr[(int)land.lnd_type].l_flags & L_ASSAULT)) { pr("%s does not have \"assault\" capability and can't be tended\n", prland(&land)); continue; } if (!snxtitem(&targets, EF_SHIP, player->argp[4], "Ship to be tended? ")) return RET_FAIL; if (!check_ship_ok(tenderp) || !check_land_ok(&land)) return RET_SYN; while (nxtitem(&targets, &target)) { if (!player->owner && relations_with(target.shp_own, player->cnum) < FRIENDLY) continue; if (target.shp_uid == tenderp->shp_uid) continue; if (tenderp->shp_x != target.shp_x || tenderp->shp_y != target.shp_y) continue; /* Fit unit on ship */ getship(target.shp_uid, &target); if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) && (!((mchr[(int)target.shp_type].m_flags & M_SUPPLY) && (!(mchr[(int)target.shp_type].m_flags & M_SUB))))) { pr("You can only load light units onto ships,\n" "unless the ship is a non-sub supply ship\n" "%s not tended\n", prland(&land)); continue; } if ((mchr[(int)target.shp_type].m_flags & M_SUB) && (lchr[(int)land.lnd_type].l_flags & L_SPY) && !mchr[(int)target.shp_type].m_nland) { if (shp_nland(&target) > 1) { pr("%s doesn't have room for more than two spy units!\n", prship(&target)); continue; } } else if (shp_nland(&target) >= mchr[target.shp_type].m_nland) { if (mchr[(int)target.shp_type].m_nland) pr("%s doesn't have room for any more land units!\n", prship(&target)); else pr("%s doesn't carry land units!\n", prship(&target)); continue; } pr("%s transferred from %s to %s\n", prland(&land), prship(tenderp), prship(&target)); sprintf(buf, "loaded on your %s at %s", prship(&target), xyas(target.shp_x, target.shp_y, target.shp_own)); gift(target.shp_own, player->cnum, &land, buf); land.lnd_ship = target.shp_uid; land.lnd_harden = 0; putland(land.lnd_uid, &land); expose_ship(tenderp, &target); putship(target.shp_uid, &target); putship(tenderp->shp_uid, tenderp); } } return 0; }
int sdump(void) { int nships; struct nstr_item ni; struct shpstr ship; int field[128]; struct natstr *np; int n, i, npln, nch, nxl; time_t now; if (!snxtitem(&ni, EF_SHIP, player->argp[1], NULL)) return RET_SYN; prdate(); if (!player->argp[2]) { for (n = 1; n <= 34; n++) field[n - 1] = n; field[n - 1] = 0; } else { n = 2; i = 0; while (player->argp[n]) { if (!strcmp("type", player->argp[n])) { field[i++] = 1; } else if (!strcmp("x", player->argp[n])) { field[i++] = 2; } else if (!strcmp("y", player->argp[n])) { field[i++] = 3; } else if (!strcmp("flt", player->argp[n])) { field[i++] = 4; } else if (!strcmp("eff", player->argp[n])) { field[i++] = 5; } else if (!strcmp("civ", player->argp[n])) { field[i++] = 6; } else if (!strcmp("mil", player->argp[n])) { field[i++] = 7; } else if (!strcmp("uw", player->argp[n])) { field[i++] = 8; } else if (!strcmp("food", player->argp[n])) { field[i++] = 9; } else if (!strcmp("pln", player->argp[n])) { field[i++] = 10; } else if (!strcmp("he", player->argp[n])) { field[i++] = 11; } else if (!strcmp("xl", player->argp[n])) { field[i++] = 12; } else if (!strcmp("land", player->argp[n])) { field[i++] = 13; } else if (!strcmp("mob", player->argp[n])) { field[i++] = 14; } else if (!strcmp("fuel", player->argp[n])) { field[i++] = 15; } else if (!strcmp("tech", player->argp[n])) { field[i++] = 16; } else if (!strcmp("shell", player->argp[n])) { field[i++] = 17; } else if (!strcmp("gun", player->argp[n])) { field[i++] = 18; } else if (!strcmp("petrol", player->argp[n])) { field[i++] = 19; } else if (!strcmp("iron", player->argp[n])) { field[i++] = 20; } else if (!strcmp("dust", player->argp[n])) { field[i++] = 21; } else if (!strcmp("bar", player->argp[n])) { field[i++] = 22; } else if (!strcmp("oil", player->argp[n])) { field[i++] = 23; } else if (!strcmp("lcm", player->argp[n])) { field[i++] = 24; } else if (!strcmp("hcm", player->argp[n])) { field[i++] = 25; } else if (!strcmp("rad", player->argp[n])) { field[i++] = 26; } else if (!strcmp("def", player->argp[n])) { field[i++] = 27; } else if (!strcmp("spd", player->argp[n])) { field[i++] = 28; } else if (!strcmp("vis", player->argp[n])) { field[i++] = 29; } else if (!strcmp("rng", player->argp[n])) { field[i++] = 30; } else if (!strcmp("fir", player->argp[n])) { field[i++] = 31; } else if (!strcmp("origx", player->argp[n])) { field[i++] = 32; } else if (!strcmp("origy", player->argp[n])) { field[i++] = 33; } else if (!strcmp("name", player->argp[n])) { field[i++] = 34; } else { pr("Unrecognized field %s\n", player->argp[n]); } if (n++ > 100) { pr("Too many fields\n"); return RET_FAIL; } } field[i] = 0; } if (player->god) pr(" "); time(&now); pr("DUMP SHIPS %ld\n", (long)now); if (player->god) pr("own "); pr("id"); n = 0; while (field[n]) { switch (field[n]) { case 1: pr(" type"); break; case 2: pr(" x"); break; case 3: pr(" y"); break; case 4: pr(" flt"); break; case 5: pr(" eff"); break; case 6: pr(" civ"); break; case 7: pr(" mil"); break; case 8: pr(" uw"); break; case 9: pr(" food"); break; case 10: pr(" pln"); break; case 11: pr(" he"); break; case 12: pr(" xl"); break; case 13: pr(" land"); break; case 14: pr(" mob"); break; case 15: pr(" fuel"); break; case 16: pr(" tech"); break; case 17: pr(" shell"); break; case 18: pr(" gun"); break; case 19: pr(" petrol"); break; case 20: pr(" iron"); break; case 21: pr(" dust"); break; case 22: pr(" bar"); break; case 23: pr(" oil"); break; case 24: pr(" lcm"); break; case 25: pr(" hcm"); break; case 26: pr(" rad"); break; case 27: pr(" def"); break; case 28: pr(" spd"); break; case 29: pr(" vis"); break; case 30: pr(" rng"); break; case 31: pr(" fir"); break; case 32: pr(" origx"); break; case 33: pr(" origy"); break; case 34: pr(" name"); break; } n++; } pr("\n"); nships = 0; np = getnatp(player->cnum); while (nxtitem(&ni, &ship)) { if (!player->owner || ship.shp_own == 0) continue; nships++; npln = shp_nplane(&ship, &nch, &nxl, NULL); if (player->god) pr("%d ", ship.shp_own); pr("%d", ni.cur); n = 0; while (field[n]) { switch (field[n++]) { case 1: pr(" %.4s", mchr[(int)ship.shp_type].m_name); break; case 2: pr(" %d", xrel(np, ship.shp_x)); break; case 3: pr(" %d", yrel(np, ship.shp_y)); break; case 4: pr(" %c", ship.shp_fleet ? ship.shp_fleet : '~'); break; case 5: pr(" %d", ship.shp_effic); break; case 6: pr(" %d", ship.shp_item[I_CIVIL]); break; case 7: pr(" %d", ship.shp_item[I_MILIT]); break; case 8: pr(" %d", ship.shp_item[I_UW]); break; case 9: pr(" %d", ship.shp_item[I_FOOD]); break; case 10: pr(" %d", npln - nch - nxl); break; case 11: pr(" %d", nch); break; case 12: pr(" %d", nxl); break; case 13: pr(" %d", shp_nland(&ship)); break; case 14: pr(" %d", ship.shp_mobil); break; case 15: pr(" 0"); break; case 16: pr(" %d", ship.shp_tech); break; case 17: pr(" %d", ship.shp_item[I_SHELL]); break; case 18: pr(" %d", ship.shp_item[I_GUN]); break; case 19: pr(" %d", ship.shp_item[I_PETROL]); break; case 20: pr(" %d", ship.shp_item[I_IRON]); break; case 21: pr(" %d", ship.shp_item[I_DUST]); break; case 22: pr(" %d", ship.shp_item[I_BAR]); break; case 23: pr(" %d", ship.shp_item[I_OIL]); break; case 24: pr(" %d", ship.shp_item[I_LCM]); break; case 25: pr(" %d", ship.shp_item[I_HCM]); break; case 26: pr(" %d", ship.shp_item[I_RAD]); break; case 27: pr(" %d", shp_armor(&ship)); break; case 28: pr(" %d", shp_speed(&ship)); break; case 29: pr(" %d", shp_visib(&ship)); break; case 30: pr(" %d", shp_frnge(&ship)); break; case 31: pr(" %d", shp_glim(&ship)); break; case 32: /* * Disclosing construction site allows pirates to find * harbors. Disclose it only to the original owner * and to deities. Else dump illegal coordinates * 1,0 */ if (ship.shp_own == ship.shp_orig_own || player->god) pr(" %d", xrel(np, ship.shp_orig_x)); else pr(" 1"); break; case 33: /* see case 32 */ if (ship.shp_own == ship.shp_orig_own || player->god) pr(" %d", yrel(np, ship.shp_orig_y)); else pr(" 0"); break; case 34: pr(" %c%s%c", '"', ship.shp_name, '"'); break; } } pr("\n"); } if (nships == 0) { if (player->argp[1]) pr("%s: No ship(s)\n", player->argp[1]); else pr("%s: No ship(s)\n", ""); return RET_FAIL; } else pr("%d ship%s\n", nships, splur(nships)); return RET_OK; }