static int fire_torp(struct shpstr *sp, struct shpstr *targ, int ntargets) { int range, erange, dam; if ((mchr[targ->shp_type].m_flags & M_SUB) && (mchr[sp->shp_type].m_flags & M_SUBT) == 0) return 0; /* need sub-torp to torpedo a sub */ erange = roundrange(torprange(sp)); range = mapdist(sp->shp_x, sp->shp_y, targ->shp_x, targ->shp_y); if (range > erange) return 0; if (!line_of_sight(NULL, sp->shp_x, sp->shp_y, targ->shp_x, targ->shp_y)) return 0; dam = shp_torp(sp, 1); putship(sp->shp_uid, sp); if (dam < 0) return 0; pr("Captain! Torpedoes sighted!\n"); if (chance(shp_torp_hitchance(sp, range))) { pr("BOOM!...\n"); if (!(mchr[targ->shp_type].m_flags & M_SUB)) { if (mchr[sp->shp_type].m_flags & M_SUB) nreport(targ->shp_own, N_TORP_SHIP, 0, 1); else nreport(targ->shp_own, N_SHIP_TORP, sp->shp_own, 1); } if (sp->shp_own != 0) wu(0, sp->shp_own, "%s @ %s torpedoed %s\n", prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own), prsub(targ)); if (ntargets > 2) dam /= ntargets / 2; shipdamage(targ, dam); putship(targ->shp_uid, targ); } else { pr("Missed!\n"); if (sp->shp_own != 0) wu(0, sp->shp_own, "%s missed %s with a torpedo at %s\n", prship(sp), prsub(targ), xyas(sp->shp_x, sp->shp_y, sp->shp_own)); } return 1; }
static void fire_dchrg(struct shpstr *sp, struct shpstr *targ, int ntargets) { int range, erange, dam; erange = roundrange(shp_fire_range(sp)); range = mapdist(sp->shp_x, sp->shp_y, targ->shp_x, targ->shp_y); if (range > erange) return; if ((mchr[(int)targ->shp_type].m_flags & M_SUB) == 0) { /* Return fire to a torpedo boat */ if (mchr[sp->shp_type].m_flags & M_SUB) return; /* sub deck gun can't return fire */ dam = shp_fire(sp); putship(sp->shp_uid, sp); if (dam < 0) return; if (ntargets > 2) dam /= ntargets / 2; pr_beep(); pr("Kaboom!!! Incoming shells!\n"); if (sp->shp_own != 0) wu(0, sp->shp_own, "%s fired at %s\n", prship(sp), prship(targ)); pr_beep(); pr("BLAM! %d damage!\n", dam); } else { /* Return fire to a submarine */ dam = shp_dchrg(sp); putship(sp->shp_uid, sp); if (dam < 0) return; if (ntargets > 2) dam /= ntargets / 2; pr("\nCAPTAIN! !!Depth charges!!...\n"); if (sp->shp_own != 0) wu(0, sp->shp_own, "%s depth charged %s\n", prship(sp), prsub(targ)); pr("click...WHAM! %d damage!\n", dam); } shipdamage(targ, dam); putship(targ->shp_uid, targ); }
int orde(void) { int sub, level; int scuttling = 0; struct nstr_item nb; struct shpstr ship; struct ichrstr *i1; coord p0x, p0y, p1x, p1y; int i; char *p, *p1, *dest; char buf1[128]; char buf[1024]; char prompt[128]; if (!snxtitem(&nb, EF_SHIP, player->argp[1], NULL)) return RET_SYN; while (!player->aborted && nxtitem(&nb, (&ship))) { if (!player->owner || ship.shp_own == 0) continue; if (opt_SAIL) { if (*ship.shp_path) { pr("Ship #%d has a \"sail\" path!\n", ship.shp_uid); continue; } } sprintf(prompt, "Ship #%d, declare, cancel, suspend, resume, level? ", ship.shp_uid); p = getstarg(player->argp[2], prompt, buf); if (player->aborted || !p || !*p) return RET_FAIL; if (!check_ship_ok(&ship)) return RET_FAIL; switch (*p) { default: pr("Bad order type!\n"); return RET_SYN; case 'c': /* clear ship fields */ ship.shp_mission = 0; ship.shp_autonav &= ~(AN_AUTONAV + AN_STANDBY + AN_LOADING); for (i = 0; i < TMAX; i++) { ship.shp_tstart[i] = I_NONE; ship.shp_tend[i] = I_NONE; ship.shp_lstart[i] = 0; ship.shp_lend[i] = 0; } break; case 's': /* suspend ship movement */ ship.shp_mission = 0; ship.shp_autonav |= AN_STANDBY; break; case 'r': /* resume ship movement */ ship.shp_mission = 0; ship.shp_autonav &= ~AN_STANDBY; break; case 'd': /* declare path */ scuttling = 0; /* Need location */ p = getstarg(player->argp[3], "Destination? ", buf); if (!p || !*p) return RET_SYN; if (!sarg_xy(p, &p0x, &p0y)) return RET_SYN; p1x = p0x; p1y = p0y; p = getstarg(player->argp[4], "Second dest? ", buf); if (!p) return RET_FAIL; if (!check_ship_ok(&ship)) return RET_FAIL; if (!*p || !strcmp(p, "-")) { pr("A one-way order has been accepted.\n"); } else if (!strncmp(p, "s", 1)) { if (!(mchr[(int)ship.shp_type].m_flags & M_TRADE)) { pr("You can't auto-scuttle that ship!\n"); return RET_SYN; } pr("A scuttle order has been accepted.\n"); scuttling = 1; } else { if (!sarg_xy(p, &p1x, &p1y)) return RET_SYN; pr("A circular order has been accepted.\n"); } /* * Set new destination and trade type fields. */ ship.shp_mission = 0; ship.shp_destx[1] = p1x; ship.shp_desty[1] = p1y; ship.shp_destx[0] = p0x; ship.shp_desty[0] = p0y; ship.shp_autonav &= ~(AN_STANDBY | AN_LOADING); ship.shp_autonav |= AN_AUTONAV; if (scuttling) ship.shp_autonav |= AN_SCUTTLE; break; /* set cargo levels on the ship */ case 'l': /* convert player->argp[3] to an integer */ sprintf(buf1, "Field (1-%d) ", TMAX); if (!getstarg(player->argp[3], buf1, buf)) return RET_SYN; if (!check_ship_ok(&ship)) return RET_FAIL; sub = atoi(buf); /* check to make sure value in within range. */ if (sub > TMAX || sub < 1) { pr("Value must range from 1 to %d\n", TMAX); return RET_FAIL; } /* to keep sub in range of our arrays subtract 1 so the new range is 0-(TMAX-1) */ sub = sub - 1;; if (ship.shp_autonav & AN_AUTONAV) { dest = getstarg(player->argp[4], "Start or end? ", buf); if (!dest) return RET_FAIL; switch (*dest) { default: pr("You must enter 'start' or 'end'\n"); return RET_SYN; case 'e': case 'E': i1 = whatitem(player->argp[5], "Commodity? "); if (!i1) return RET_FAIL; p1 = getstarg(player->argp[6], "Amount? ", buf); if (!p1) return RET_SYN; if (!check_ship_ok(&ship)) return RET_FAIL; level = atoi(p1); if (level < 0) { level = 0; /* prevent negatives. */ pr("You must use positive number! Level set to 0.\n"); } ship.shp_tstart[sub] = i1->i_uid; ship.shp_lstart[sub] = level; pr("Order set\n"); break; case 's': case 'S': i1 = whatitem(player->argp[5], "Commodity? "); if (!i1) return RET_FAIL; p1 = getstarg(player->argp[6], "Amount? ", buf); if (!p1) return RET_SYN; if (!check_ship_ok(&ship)) return RET_FAIL; level = atoi(p1); if (level < 0) { level = 0; pr("You must use positive number! Level set to 0.\n"); } ship.shp_tend[sub] = i1->i_uid; ship.shp_lend[sub] = level; pr("Order Set \n"); break; } } else pr("You need to 'declare' a ship path first, see 'info order'\n"); break; } /* end of switch (*p) */ /* * Set loading flag if ship is already in one * of the specified harbors and a cargo has been * specified. */ if (((ship.shp_x == ship.shp_destx[0]) && (ship.shp_y == ship.shp_desty[0]) && (ship.shp_lstart[0] != ' ')) || ((ship.shp_x == ship.shp_desty[1]) && (ship.shp_y == ship.shp_desty[1]) && (ship.shp_lstart[1] != ' '))) { coord tcord; i_type tcomm; short lev[TMAX]; int i; ship.shp_autonav |= AN_LOADING; /* swap variables, this keeps the load_it() procedure happy. CZ */ tcord = ship.shp_destx[0]; ship.shp_destx[0] = ship.shp_destx[1]; ship.shp_destx[1] = tcord; tcord = ship.shp_desty[0]; ship.shp_desty[0] = ship.shp_desty[1]; ship.shp_desty[1] = tcord; for (i = 0; i < TMAX; i++) { lev[i] = ship.shp_lstart[i]; ship.shp_lstart[i] = ship.shp_lend[i]; ship.shp_lend[i] = lev[i]; tcomm = ship.shp_tstart[i]; ship.shp_tstart[i] = ship.shp_tend[i]; ship.shp_tend[i] = tcomm; } } putship(ship.shp_uid, &ship); } return RET_OK; }
int torp(void) { natid vshipown; int range; int dam; int subno; int victno; int erange; double hitchance; struct shpstr vship; struct shpstr sub; struct mchrstr *sub_mcp; char *ptr; struct nstr_item nbst; char buf[1024]; int ntorping = 0; char prompt[128]; if (!snxtitem(&nbst, EF_SHIP, player->argp[1], "From ship(s)? ")) return RET_SYN; while (nxtitem(&nbst, &sub)) { if (sub.shp_own != player->cnum) continue; if ((mchr[(int)sub.shp_type].m_flags & M_TORP) == 0) continue; if (sub.shp_item[I_GUN] == 0 || sub.shp_item[I_SHELL] < SHP_TORP_SHELLS) continue; if (sub.shp_item[I_MILIT] < 1) continue; if (sub.shp_effic < 60) continue; if (sub.shp_mobil <= 0) continue; ntorping++; } pr("%d ships are eligible to torpedo\n", ntorping); snxtitem_rewind(&nbst); while (nxtitem(&nbst, &sub)) { if (!sub.shp_own) continue; if (sub.shp_own != player->cnum) { continue; } sub_mcp = &mchr[sub.shp_type]; if (!(sub_mcp->m_flags & M_TORP)) { pr("Ship # %d: A %s can't fire torpedoes!\n", sub.shp_uid, sub_mcp->m_name); continue; } if (sub.shp_item[I_GUN] == 0 || sub.shp_item[I_SHELL] < SHP_TORP_SHELLS) { pr("Ship #%d has insufficient armament\n", sub.shp_uid); continue; } if (sub.shp_item[I_MILIT] < 1) { pr("Ship #%d has insufficient crew\n", sub.shp_uid); continue; } if (sub.shp_effic < 60) { pr("Ship #%d torpedo tubes inoperative.\n", sub.shp_uid); continue; } if (sub.shp_mobil <= 0) { pr("Ship #%d has insufficient mobility\n", sub.shp_uid); continue; } subno = sub.shp_uid; sprintf(prompt, "Ship %d, target? ", sub.shp_uid); if (!(ptr = getstarg(player->argp[2], prompt, buf))) return RET_SYN; if (!check_ship_ok(&sub)) return RET_FAIL; if ((victno = atoi(ptr)) < 0) return RET_SYN; if (!getship(victno, &vship)) return RET_FAIL; if (!vship.shp_own) return RET_FAIL; vshipown = vship.shp_own; if (victno == subno) { pr("Shooting yourself, eh? How strange...\n"); continue; } if (mchr[(int)vship.shp_type].m_flags & M_SUB) { if (!(sub_mcp->m_flags & M_SUBT)) { pr("You can't torpedo a submarine!\n"); continue; } } dam = shp_torp(&sub, 1); sub.shp_mission = 0; putship(sub.shp_uid, &sub); if (CANT_HAPPEN(dam < 0)) { pr("Ship #%d has insufficient armament\n", sub.shp_uid); continue; } if (!(sub_mcp->m_flags & M_SUB)) { pr("Starting our attack run...\n"); anti_torp(sub.shp_uid, ntorping, vshipown); } getship(sub.shp_uid, &sub); if (sub.shp_own == 0) continue; erange = roundrange(torprange(&sub)); pr("Effective torpedo range is %d.0\n", erange); pr("Whooosh... "); getship(victno, &vship); vshipown = vship.shp_own; range = mapdist(sub.shp_x, sub.shp_y, vship.shp_x, vship.shp_y); hitchance = shp_torp_hitchance(&sub, range); if (range <= erange) { pr("Hitchance = %.0f%%\n", hitchance * 100); } if (range > erange) pr("Out of range\n"); else if (!line_of_sight(NULL, sub.shp_x, sub.shp_y, vship.shp_x, vship.shp_y)) { pr("BOOM!... Torpedo slams into land before reaching target.\n"); /* We only tell the victim if we were within range. */ if (vshipown != 0 && vshipown != player->cnum) wu(0, vshipown, "Torpedo sighted @ %s by %s\n", xyas(sub.shp_x, sub.shp_y, vshipown), prship(&vship)); } else if (chance(hitchance)) { pr("BOOM!...\n"); if (vshipown != 0 && vshipown != player->cnum) wu(0, vshipown, "%s in %s torpedoed %s for %d damage.\n", sub_mcp->m_flags & M_SUB ? "sub" : prship(&sub), xyas(sub.shp_x, sub.shp_y, vshipown), prship(&vship), dam); pr("Torpedo hit %s for %d damage.\n", prsub(&vship), dam); if (!(mchr[vship.shp_type].m_flags & M_SUB)) { if (mchr[sub.shp_type].m_flags & M_SUB) nreport(vshipown, N_TORP_SHIP, 0, 1); else nreport(vshipown, N_SHIP_TORP, player->cnum, 1); } shipdamage(&vship, dam); if (vship.shp_effic < SHIP_MINEFF) pr("%s sunk!\n", prsub(&vship)); if (vship.shp_rflags & RET_TORPED) retreat_ship(&vship, vshipown, 't'); putship(vship.shp_uid, &vship); } else { pr("Missed\n"); if (vshipown != 0 && vshipown != player->cnum) wu(0, vshipown, "Torpedo sighted @ %s by %s\n", xyas(sub.shp_x, sub.shp_y, vshipown), prship(&vship)); } if (sub_mcp->m_flags & M_SUB) anti_torp(sub.shp_uid, ntorping, vshipown); } return RET_OK; }
void name(int Playernum, int Governor, int APcount) { char *ch; register int i, spaces; int len; unsigned char check=0; shiptype *ship; char string[1024]; char temp[128]; racetype *Race; if(!isalnum(args[2][0]) || argn < 3) { notify(Playernum, Governor, "Illegal name format.\n"); return; } sprintf(buf, "%s", args[2]); for(i=3; i < argn; i++) { sprintf(temp, " %s", args[i]); strcat(buf, temp); } sprintf(string, "%s", buf); i=strlen(args[0]); /* make sure there are no ^'s or '/' in name, also make sure the name has at least 1 character in it */ ch = string; spaces = 0; while (*ch!='\0') { check |= ((!isalnum(*ch) && !(*ch==' ') && !(*ch=='.')) || (*ch=='/') ); ch++; if(*ch==' ') spaces++; } len = strlen(buf); if(spaces==strlen(buf)) { notify(Playernum, Governor, "Illegal name.\n"); return; } if (strlen(buf) < 1 || check) { sprintf(buf, "Illegal name %s.\n", check ? "form" : "length" ); notify(Playernum, Governor, buf); return; } if (match(args[1],"ship")) { if(Dir[Playernum-1][Governor].level == LEVEL_SHIP) { (void)getship(&ship, Dir[Playernum-1][Governor].shipno); strncpy(ship->name, buf, SHIP_NAMESIZE); putship(ship); notify(Playernum, Governor, "Name set.\n"); free(ship); return; } else { notify(Playernum, Governor, "You have to 'cs' to a ship to name it.\n"); return; } } else if (match(args[1],"class")) { if(Dir[Playernum-1][Governor].level == LEVEL_SHIP) { (void)getship(&ship, Dir[Playernum-1][Governor].shipno); if(ship->type != OTYPE_FACTORY) { notify(Playernum, Governor, "You are not at a factory!\n"); free(ship); return; } if(ship->on) { notify(Playernum, Governor, "This factory is already on line.\n"); free(ship); return; } strncpy(ship->class, buf, SHIP_NAMESIZE-1); putship(ship); notify(Playernum, Governor, "Class set.\n"); free(ship); return; } else {
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 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; }
void pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty, int cno) { struct emp_qelem *qp; struct plist *plp; int amt; struct sctstr sect; struct shpstr ship; int there; int max; int pstage; if (!ip) return; if (cno < 0) { getsect(tx, ty, §); if (!sect.sct_own) { if (sect.sct_type == SCT_WATER) pr("Your %s sink like a rock!\n", ip->i_name); else pr("Your %s vanish without a trace.\n", ip->i_name); return; } if (relations_with(sect.sct_own, player->cnum) != ALLIED) { pr("You don't own %s! Cargo jettisoned...\n", xyas(tx, ty, player->cnum)); return; } if (ip->i_uid == I_CIVIL && sect.sct_own != sect.sct_oldown) { pr("%s is occupied. Your civilians suffer from identity crisis and die.\n", xyas(tx, ty, player->cnum)); return; } there = sect.sct_item[ip->i_uid]; max = ITEM_MAX; pstage = sect.sct_pstage; } else { getship(cno, &ship); there = ship.shp_item[ip->i_uid]; max = mchr[ship.shp_type].m_item[ip->i_uid]; pstage = ship.shp_pstage; } amt = 0; for (qp = list->q_forw; qp != list; qp = qp->q_forw) { plp = (struct plist *)qp; amt += plp->load; if (plp->load && plp->pstage == PLG_INFECT && pstage == PLG_HEALTHY) pstage = PLG_EXPOSED; } there += amt; if (there > max) { pr("%d excess %s discarded\n", there - max, ip->i_name); amt -= there - max; there = max; } pr("%d %s landed safely", amt, ip->i_name); if (cno < 0) { sect.sct_item[ip->i_uid] = there; sect.sct_pstage = pstage; if (sect.sct_own != player->cnum) wu(0, sect.sct_own, "%s planes drop %d %s in %s\n", cname(player->cnum), amt, ip->i_name, xyas(tx, ty, sect.sct_own)); pr(" at %s\n", xyas(tx, ty, player->cnum)); putsect(§); } else { ship.shp_item[ip->i_uid] = there; ship.shp_pstage = pstage; if (ship.shp_own != player->cnum) wu(0, ship.shp_own, "%s planes land %d %s on carrier %d\n", cname(player->cnum), amt, ip->i_name, ship.shp_uid); pr(" on carrier #%d\n", ship.shp_uid); putship(ship.shp_uid, &ship); } }
int pln_equip(struct plist *plp, struct ichrstr *ip, char mission) { struct plchrstr *pcp; struct plnstr *pp; int load, needed; struct lndstr land; struct shpstr ship; struct sctstr sect; i_type itype; short *item; int own; int abandon_needed; pp = &plp->plane; pcp = plp->pcp; if (pp->pln_ship >= 0) { getship(pp->pln_ship, &ship); plp->pstage = ship.shp_pstage; item = ship.shp_item; own = ship.shp_own; } else if (pp->pln_land >= 0) { getland(pp->pln_land, &land); plp->pstage = land.lnd_pstage; item = land.lnd_item; own = land.lnd_own; } else { getsect(pp->pln_x, pp->pln_y, §); plp->pstage = sect.sct_pstage; item = sect.sct_item; own = sect.sct_oldown; } if (pcp->pl_fuel > item[I_PETROL]) { pr("%s not enough petrol there!\n", prplane(pp)); return -1; } item[I_PETROL] -= pcp->pl_fuel; load = pln_load(pp); itype = I_NONE; switch (mission) { case 's': /* strategic bomb */ case 'p': /* pinpoint bomb */ itype = I_SHELL; break; case 't': /* transport */ if (!(pcp->pl_flags & P_C) || !ip) break; itype = ip->i_uid; load *= 2; break; case 'm': /* mine */ if ((pcp->pl_flags & P_MINE) == 0) break; itype = I_SHELL; load *= 2; break; case 'd': /* drop */ if (!(pcp->pl_flags & P_C) || CANT_HAPPEN(!ip)) break; itype = ip->i_uid; if (pcp->pl_flags & P_V) load *= 2; break; case 'a': /* paradrop */ if (!(pcp->pl_flags & P_P)) break; itype = I_MILIT; if (pcp->pl_flags & P_V) load *= 2; break; case 'r': /* reconnaissance */ case 'e': /* escort */ load = 0; break; case 'i': /* missile interception */ if (CANT_HAPPEN(!(pcp->pl_flags & P_M) || !(pcp->pl_flags & (P_N | P_O)))) break; if (load) itype = I_SHELL; break; default: CANT_REACH(); load = 0; } if (itype != I_NONE) { needed = load / ichr[itype].i_lbs; if (needed <= 0) { pr("%s can't contribute to mission\n", prplane(pp)); return -1; } if (nuk_on_plane(pp) >= 0) { if (mission == 's' || mission == 't') needed = 0; else { pr("%s can't fly this mission" " while it is carrying a nuclear weapon", prplane(pp)); return -1; } } if (itype == I_CIVIL && pp->pln_own != own) { pr("You don't control those civilians!\n"); return -1; } #if 0 /* Supply is broken somewhere, so don't use it for now */ if (itype == I_SHELL && item[itype] < needed) item[itype] += supply_commod(plp->plane.pln_own, plp->plane.pln_x, plp->plane.pln_y, I_SHELL, needed); #endif if (pp->pln_ship >= 0 || pp->pln_land >= 0) abandon_needed = 0; else abandon_needed = !!would_abandon(§, itype, needed, NULL); if (item[itype] < needed + abandon_needed) { pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp)); return -1; } item[itype] -= needed; plp->load = needed; } if (pp->pln_ship >= 0) { if (pp->pln_own != ship.shp_own) { wu(0, ship.shp_own, "%s %s prepares for takeoff from ship %s\n", cname(pp->pln_own), prplane(pp), prship(&ship)); } putship(ship.shp_uid, &ship); } else if (pp->pln_land >= 0) { if (pp->pln_own != land.lnd_own) { wu(0, land.lnd_own, "%s %s prepares for takeoff from unit %s\n", cname(pp->pln_own), prplane(pp), prland(&land)); } putland(land.lnd_uid, &land); } else { if (pp->pln_own != sect.sct_own) { wu(0, sect.sct_own, "%s %s prepares for takeoff from %s\n", cname(pp->pln_own), prplane(pp), xyas(sect.sct_x, sect.sct_y, sect.sct_own)); } putsect(§); } return 0; }
int mobq(void) { struct shpstr ship; char *cp, *oldmq; int good, mobquota, count = 0; struct nstr_item nstr; char buf[1024]; if (!opt_SAIL) { pr("The SAIL option is not enabled, so this command is not valid.\n"); return RET_FAIL; } if (!snxtitem(&nstr, EF_SHIP, player->argp[1], NULL)) return RET_SYN; oldmq = player->argp[2]; if (oldmq) { good = sscanf(oldmq, "%d", &mobquota); if (!good) return RET_SYN; if (mobquota < 0 || mobquota > ship_mob_max) { pr("Bad mobility quota value %d.\n", mobquota); return RET_SYN; } if (mobquota + (ship_mob_scale * (float)etu_per_update) > ship_mob_max) { pr("warning: %d less than optimal\n", mobquota); } } while (nxtitem(&nstr, &ship)) { if (!player->owner) continue; if (!oldmq) pr("Ship #%d at %s. Old value %d.\n", ship.shp_uid, xyas(ship.shp_x, ship.shp_y, player->cnum), ship.shp_mobquota); cp = getstarg(player->argp[2], "mobility quota? ", buf); if (!cp) return RET_SYN; if (!check_ship_ok(&ship)) continue; good = sscanf(cp, "%d", &mobquota); if (!good) { pr("Huh?\n"); continue; } if (!oldmq) { if (mobquota < 0 || mobquota > ship_mob_max) { pr("Bad mobility quota value %d.\n", mobquota); continue; } if (mobquota + (ship_mob_scale * (float)etu_per_update) > ship_mob_max) { pr("warning: %d less than optimal\n", mobquota); } } ship.shp_mobquota = mobquota; count++; putship(ship.shp_uid, &ship); } if (count == 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", count, splur(count)); return RET_OK; }
int boar(void) { struct combat off[1]; /* boarding ship or sector */ struct combat def[1]; /* defending ship */ struct emp_qelem olist; /* boarding units */ struct emp_qelem dlist; /* defending units */ int ototal; /* total boarding strength */ int a_engineer = 0; /* boarder engineers are present */ int a_spy = 0; /* the best boarder scout */ struct shpstr ship; /* for retreating */ struct sctstr sect; struct lndstr land; struct nstr_item ni; int foundland, def_uid; natid def_own; char *p; char buf[1024]; att_combat_init(def, EF_SHIP); /* * Collect input from the boarder */ /* What are we boarding? */ p = getstarg(player->argp[1], "Victim ship #? ", buf); if (!p || (def->shp_uid = atoi(p)) < 0) return RET_SYN; /* * Ask the boarder what he wants to board with */ if (!(p = getstarg(player->argp[2], "Boarding party from? ", buf))) return RET_SYN; if (issector(p)) { att_combat_init(off, EF_SECTOR); if (!sarg_xy(p, &off->x, &off->y)) return RET_SYN; getsect(off->x, off->y, §); if (sect.sct_own != player->cnum) { pr("You don't own %s!\n", xyas(off->x, off->y, player->cnum)); return RET_SYN; } if (sect.sct_mobil <= 0) { /* Look for land units with mobility */ snxtitem_xy(&ni, EF_LAND, off->x, off->y); foundland = 0; while (nxtitem(&ni, &land)) { if (land.lnd_own != player->cnum) continue; if (land.lnd_ship >= 0 || land.lnd_land >= 0) continue; if (land.lnd_mobil <= 0) continue; /* Only land units with assault can board */ if (!(lchr[(int)land.lnd_type].l_flags & L_ASSAULT)) continue; foundland = 1; } if (!foundland) { pr("You don't have any mobility (sector or land units) in %s!\n", xyas(off->x, off->y, player->cnum)); return RET_SYN; } } } else { att_combat_init(off, EF_SHIP); if ((off->shp_uid = atoi(p)) < 0) return RET_SYN; } if (att_abort(A_BOARD, off, def)) { pr("Board aborted\n"); return RET_OK; } /* Fire at the attacking ship */ att_approach(off, def); if (att_abort(A_BOARD, off, def)) { pr("Board aborted\n"); att_empty_attack(A_BOARD, 0, def); return RET_OK; } /* Show what we're boarding */ att_show(def); /* Ask the player what he wants to board with */ att_ask_offense(A_BOARD, off, def, &olist, &a_spy, &a_engineer); if (att_abort(A_BOARD, off, def)) { pr("Board aborted\n"); att_empty_attack(A_BOARD, 0, def); return att_free_lists(&olist, NULL); } ototal = att_get_offense(A_BOARD, off, &olist, def); if (att_abort(A_BOARD, off, def)) { pr("Board aborted\n"); att_empty_attack(A_BOARD, 0, def); return att_free_lists(&olist, NULL); } /* * We have now got all the answers from the boarder. From this point * forward, we can assume that this battle is the _only_ thing * happening in the game. */ /* Get the real defense */ att_get_defense(&olist, def, &dlist, a_spy, ototal); /* * Death, carnage, and destruction. */ /* * Careful: when the fight sinks the ship, put_combat() clobbers * *def (see FIXME there). */ def_uid = def->shp_uid; def_own = def->own; if (!(att_fight(A_BOARD, off, &olist, 1.0, def, &dlist, 1.0))) { getship(def_uid, &ship); if (ship.shp_rflags & RET_BOARDED) { retreat_ship(&ship, def_own, 'u'); putship(def_uid, &ship); } } return RET_OK; }
void doship(shiptype *ship, int update) { racetype *Race; shiptype *ship2; /*ship is active */ ship->active = 1; if(!ship->owner) ship->alive = 0; if (ship->alive) { /* repair radiation */ if (ship->rad) { ship->active = 1; /* irradiated ships are immobile.. */ /* kill off some people */ /* check to see if ship is active */ if(success(ship->rad)) ship->active = 0; if(update) { ship->popn = round_rand(ship->popn * .80); ship->troops = round_rand(ship->troops * .80); if (ship->rad >= (int)REPAIR_RATE) ship->rad -= int_rand(0,(int)REPAIR_RATE); else ship->rad -= int_rand(0,(int)ship->rad); } } else ship->active = 1; if(!ship->popn && Max_crew(ship) && !ship->docked) ship->whatdest = LEVEL_UNIV; if (ship->whatorbits != LEVEL_UNIV && Stars[ship->storbits]->nova_stage>0) { /* damage ships from supernovae */ /* Maarten: modified to take into account MOVES_PER_UPDATE */ ship->damage += 5 * Stars[ship->storbits]->nova_stage / ((Armor(ship)+1) * segments); if (ship->damage >= 100) { kill_ship((int)(ship->owner), ship); return; } } if(ship->type==OTYPE_FACTORY && !ship->on) { Race = races[ship->owner-1]; ship->tech = Race->tech; } if(ship->active) Moveship(ship, update, 1, 0); ship->size = ship_size(ship); /* for debugging */ if(ship->whatorbits==LEVEL_SHIP) { (void)getship(&ship2, (int)ship->destshipno); if(ship2->owner != ship->owner) { ship2->owner = ship->owner; ship2->governor = ship->governor; putship(ship2); } free(ship2); /* just making sure */ } else if(ship->whatorbits != LEVEL_UNIV && (ship->popn || ship->type == OTYPE_PROBE)) { /* Though I have often used TWCs for exploring, I don't think it is right */ /* to be able to map out worlds with this type of junk. Either a manned ship, */ /* or a probe, which is designed for this kind of work. Maarten */ StarsInhab[ship->storbits] = 1; setbit(Stars[ship->storbits]->inhabited, ship->owner); setbit(Stars[ship->storbits]->explored, ship->owner); if(ship->whatorbits == LEVEL_PLAN) { planets[ship->storbits][ship->pnumorbits]->info[ship->owner-1].explored = 1; } } /* add ships, popn to total count to add AP's */ if(update) { Power[ship->owner-1].ships_owned++; Power[ship->owner-1].resource += ship->resource; Power[ship->owner-1].fuel += ship->fuel; Power[ship->owner-1].destruct += ship->destruct; Power[ship->owner-1].popn += ship->popn; Power[ship->owner-1].troops += ship->troops; } if (ship->whatorbits==LEVEL_UNIV) { Sdatanumships[ship->owner-1]++; Sdatapopns[ship->owner] += ship->popn; } else { starnumships[ship->storbits][ship->owner-1]++; /* add popn of ships to popn */ starpopns[ship->storbits][ship->owner-1] += ship->popn; /* set inhabited for ship */ /* only if manned or probe. Maarten */ if (ship->popn || ship->type==OTYPE_PROBE) { StarsInhab[ship->storbits] = 1; setbit(Stars[ship->storbits]->inhabited, ship->owner); setbit(Stars[ship->storbits]->explored, ship->owner); } } if (ship->active) { /* bombard the planet */ if (can_bombard(ship) && ship->bombard && ship->whatorbits==LEVEL_PLAN && ship->whatdest==LEVEL_PLAN && ship->deststar== ship->storbits && ship->destpnum== ship->pnumorbits) { /* ship bombards planet */ Stinfo[ship->storbits][ship->pnumorbits].inhab = 1; } /* repair ship by the amount of crew it has */ /* industrial complexes can repair (robot ships and offline factories can't repair) */ if(ship->damage && Repair(ship)) do_repair(ship); if(update) switch (ship->type) { /* do this stuff during updates only*/ case OTYPE_CANIST: do_canister(ship); break; case OTYPE_GREEN: do_greenhouse(ship); break; case STYPE_MIRROR: do_mirror(ship); break; case STYPE_GOD: do_god(ship); break; case OTYPE_AP: do_ap(ship); break; case OTYPE_VN: /* Von Neumann machine */ case OTYPE_BERS: if(!ship->special.mind.progenitor) ship->special.mind.progenitor = 1; do_VN(ship); break; case STYPE_OAP: do_oap(ship); break; case STYPE_HABITAT: do_habitat(ship); break; default: break; } if(ship->type==STYPE_POD) do_pod(ship); } } }
void domine(int shipno, int detonate) { int sh,sh2,i; shiptype *s, *ship; planettype *planet; racetype *r; (void)getship(&ship, shipno); if(ship->type!=STYPE_MINE || !ship->alive || !ship->owner) { free(ship); return; } /* check around and see if we should explode. */ if (ship->on || detonate) { int rad=0; double xd,yd,range; switch(ship->whatorbits) { case LEVEL_STAR: sh = Stars[ship->storbits]->ships; break; case LEVEL_PLAN: getplanet(&planet, (int)ship->storbits, (int)ship->pnumorbits); sh=planet->ships; free(planet); break; default: free(ship); return; } sh2 = sh; /* traverse the list, look for ships that are closer than the trigger radius... */ rad = 0; if(!detonate) { r = races[ship->owner-1]; while (sh && !rad) { (void)getship(&s, sh); xd = s->xpos - ship->xpos; yd = s->ypos - ship->ypos; range = sqrt(xd*xd + yd*yd); if( !isset(r->allied, s->owner) && (s->owner != ship->owner) && ( (int)range <= ship->special.trigger.radius) ) rad = 1; else sh = s->nextship; free(s); } } else rad = 1; if (rad) { sprintf(buf, "%s detonated at %s\n", Ship(ship), prin_ship_orbits(ship)); post(buf, COMBAT); notify_star((int)ship->owner, (int)ship->governor, 0, (int)ship->storbits, buf); sh = sh2 ; while (sh) { (void)getship(&s, sh); if (sh != shipno && s->alive && (s->type != OTYPE_CANIST) && (s->type!=OTYPE_GREEN)) { rad = shoot_ship_to_ship(ship, s, (int)(ship->destruct), 0, 0, long_buf, short_buf); if(rad>0) { post(short_buf, COMBAT); warn((int)s->owner, (int)s->governor, long_buf); putship(s); } } sh = s->nextship; free(s); } /* if the mine is in orbit around a planet, nuke the planet too! */ if(ship->whatorbits==LEVEL_PLAN) { /* pick a random sector to nuke */ reg int x,y,numdest; getplanet(&planet, (int)ship->storbits, (int)ship->pnumorbits); if(landed(ship)) { x = ship->land_x; y = ship->land_y; } else { x=int_rand(0, (int)planet->Maxx-1); y=int_rand(0, (int)planet->Maxy-1); } numdest=shoot_ship_to_planet(ship, planet, (int)(ship->destruct), x, y, 1, 0, LIGHT, long_buf, short_buf); putplanet(planet, (int)ship->storbits, (int)ship->pnumorbits); sprintf(telegram_buf, "%s", buf); if(numdest>0) { sprintf(buf, " - %d sectors destroyed.",numdest); strcat(telegram_buf, buf); } strcat(telegram_buf, "\n"); for(i=1; i<=Num_races; i++) if(Nuked[i-1]) warn(i, (int)Stars[ship->storbits]->governor[i-1], telegram_buf); notify((int)(ship->owner), (int)ship->governor, telegram_buf); free(planet); } kill_ship((int)(ship->owner), ship); } putship(ship); } free(ship); }
int foll(void) { struct shpstr ship; char *cp; int good, leader, count = 0; coord x, y; struct nstr_item nstr; char buf[1024]; if (!opt_SAIL) { pr("The SAIL option is not enabled, so this command is not valid.\n"); return RET_FAIL; } if (!snxtitem(&nstr, EF_SHIP, player->argp[1], NULL)) return RET_SYN; cp = getstarg(player->argp[2], "leader? ", buf); if (!cp) cp = ""; good = sscanf(cp, "%d", &leader); if (!good) return RET_SYN; getship(leader, &ship); if (relations_with(ship.shp_own, player->cnum) < FRIENDLY) { pr("That ship won't let you follow.\n"); return RET_FAIL; } x = ship.shp_x; y = ship.shp_y; while (nxtitem(&nstr, &ship)) { if (!player->owner) continue; if (ship.shp_x != x || ship.shp_y != y) { pr("Ship #%d not in same sector as #%d\n", ship.shp_uid, leader); continue; } if (ship.shp_uid == leader) { pr("Ship #%d can't follow itself!\n", leader); continue; } if ((ship.shp_autonav & AN_AUTONAV) && !(ship.shp_autonav & AN_STANDBY)) { pr("Ship #%d has other orders!\n", ship.shp_uid); continue; } count++; ship.shp_mission = 0; *ship.shp_path = 'f'; ship.shp_path[1] = 0; ship.shp_follow = leader; pr("Ship #%d follows #%d.\n", ship.shp_uid, leader); putship(ship.shp_uid, &ship); } if (count == 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", count, splur(count)); return RET_OK; }
static int supgr(void) { struct sctstr sect; struct natstr *natp; struct nstr_item ni; struct shpstr ship; struct mchrstr *mp; int n; int tlev; int avail, cost; int cash; if (!snxtitem(&ni, EF_SHIP, player->argp[2], NULL)) return RET_SYN; natp = getnatp(player->cnum); cash = natp->nat_money; tlev = (int)natp->nat_level[NAT_TLEV]; n = 0; while (nxtitem(&ni, &ship)) { if (ship.shp_own == 0) continue; getsect(ship.shp_x, ship.shp_y, §); if (sect.sct_own != player->cnum) continue; if (sect.sct_type != SCT_HARBR || sect.sct_effic < 60) continue; if (relations_with(ship.shp_own, sect.sct_own) < FRIENDLY) { pr("You are not on friendly terms with the owner of ship %d!\n", ship.shp_uid); continue; } n++; mp = &mchr[(int)ship.shp_type]; avail = (SHP_BLD_WORK(mp->m_lcm, mp->m_hcm) * UPGR_COST + 99) / 100; if (sect.sct_avail < avail) { pr("Not enough available work in %s to upgrade a %s\n", xyas(sect.sct_x, sect.sct_y, player->cnum), mp->m_name); pr(" (%d available work required)\n", avail); continue; } if (ship.shp_effic < 60) { pr("%s is too damaged to upgrade!\n", prship(&ship)); continue; } if (ship.shp_tech >= tlev) { pr("%s tech: %d, yours is only %d\n", prship(&ship), ship.shp_tech, tlev); continue; } cost = mp->m_cost * UPGR_COST / 100; if (cost + player->dolcost > cash) { pr("You don't have enough money to upgrade %s!\n", prship(&ship)); continue; } sect.sct_avail -= avail; ship.shp_effic -= UPGR_EFF; shp_set_tech(&ship, tlev); ship.shp_mission = 0; putship(ship.shp_uid, &ship); putsect(§); player->dolcost += cost; pr("%s upgraded to tech %d, at a cost of %d\n", prship(&ship), ship.shp_tech, cost); if (ship.shp_own != player->cnum) wu(0, ship.shp_own, "%s upgraded by %s to tech %d, at a cost of %d\n", prship(&ship), cname(player->cnum), ship.shp_tech, cost); } if (n == 0) { pr("No ships\n"); return RET_SYN; } return RET_OK; }
int msl_launch(struct plnstr *pp, int type, char *what, coord x, coord y, natid victim, int *sublaunchp) { struct shpstr ship; struct nukstr nuke; int sublaunch = 0; char *base, *in_or_at, *from; mpr(pp->pln_own, "Preparing to launch %s at %s %s %s%s\n", prplane(pp), cname(victim), what, type != EF_SECTOR ? "in " : "", xyas(x, y, pp->pln_own)); if (pp->pln_ship >= 0) { getship(pp->pln_ship, &ship); base = prship(&ship); in_or_at = " in "; if (mchr[(int)ship.shp_type].m_flags & M_SUB) { sublaunch = 1; from = "in hatch"; } else from = "on deck"; } else { if (pp->pln_harden > 0) { base = "missile silo"; in_or_at = " at "; from = "in silo"; } else { base = in_or_at = ""; from = "on launch pad"; } } mpr(pp->pln_own, "\tLaunching from %s%s%s\n", base, in_or_at, xyas(pp->pln_x, pp->pln_y, pp->pln_own)); CANT_HAPPEN(pp->pln_flags & PLN_LAUNCHED); pp->pln_flags |= PLN_LAUNCHED; putplane(pp->pln_uid, pp); if (chance((0.05 + (100 - pp->pln_effic) / 100.0) * (1 - techfact(pp->pln_tech, 1.0)))) { mpr(pp->pln_own, "KABOOOOM! Missile explodes %s!\n", from); if (getnuke(nuk_on_plane(pp), &nuke)) { mpr(pp->pln_own, "%s lost!\n", prnuke(&nuke)); nuke.nuk_effic = 0; putnuke(nuke.nuk_uid, &nuke); } #if 0 /* * Disabled for now, because it breaks callers that call * msl_launch() for each member of a list of planes, created * by msl_sel() or perform_mission(). Damage to the base can * damage other planes. Any copies of them in the list become * stale. When msl_launch() modifies and writes back such a * stale copy, the damage gets wiped out, triggering a seqno * oops. */ if (chance(0.33)) { struct sctstr sect; int dam; dam = pln_damage(pp, 'p', NULL) / 2; if (pp->pln_ship >= 0) { shipdamage(&ship, dam); putship(ship.shp_uid, &ship); } else { mpr(pp->pln_own, "Explosion damages %s %d%%\n", xyas(pp->pln_x, pp->pln_y, pp->pln_own), dam); getsect(pp->pln_x, pp->pln_y, §); sectdamage(§, dam); putsect(§); } } #endif return -1; } mpr(pp->pln_own, "\tSHWOOOOOSH! Missile launched!\n"); if (type != EF_PLANE) mpr(victim, "Incoming %s missile sighted at %s...\n", sublaunch ? "sub-launched" : cname(pp->pln_own), xyas(x, y, victim)); if (type == EF_SECTOR || type == EF_LAND) { if (msl_abm_intercept(pp, x, y, sublaunch)) return -1; } if (type == EF_SHIP) { if (shp_missile_defense(x, y, pp->pln_own, pln_def(pp))) { return -1; } } if (sublaunchp) *sublaunchp = sublaunch; return 0; }
void scrap(int playernum, int governor, int apcount) { planettype *planet; sectortype *sect; shiptype *s; shiptype *s2; int shipno; int nextshipno; int scrapval = 0; int destval = 0; int crewval = 0; int max_crew = 0; int xtalval = 0; int troopval = 0; int max_resource = 0; int max_mil = 0; int max_fuel = 0; int max_destruct = 0; int cost = 0; double fuelval = 0.0; racetype *race; if (argn < 2) { notify(playernum, governor, "Scrap what?\n"); return; } nextshipno = start_shiplist(playernum, governor, args[1]); race = races[playernum - 1]; if (race->Guest) { notify(playernum, governor, "Guest races cannot scrap ships\n"); return; } shipno = do_shiplist(&s, &nextshipno); while (shipno) { if (in_list(playernum, args[1], s, &nextshipno)) { #ifdef USE_VN if ((s->type == OTYPE_VN) || (s->type == OTYPE_BERS)) { notify(playernum, governor, "VNs will not scrap themselves.\n"); free(s); shipno = do_shiplist(&s, &nextshipno); continue; } #endif if (s->max_crew && !s->popn) { notify(playernum, governor, "Can't scrap that ship - no crew.\n"); free(s); shipno = do_shiplist(&s, &nextshipno); continue; } if (s->whatorbits == LEVEL_UNIV) { /* * Used to not allow scrapping at the UNIV level for * anything. However, I'm going to permit pods. This is so pod * races can clean up their messes. I'm not going to charge APs * at the UNIV scope either. -mfw */ if (s->type) { apcount = 0; } else { notify(playernum, governor, "Can't scrap at the ship's scope.\n"); free(s); shipno = do_shiplist(&s, &nextshipno); continue; } } else if (!enufAP(playernum, governor, Stars[s->storbits]->AP[playernum - 1], apcount)) { notify(playernum, governor, "Not enough APs to scrap.\n"); free(s); shipno = do_shiplist(&s, &nextshipno); continue; } /* HUTm (kse) wc's can't be scrapped inside of ship anymore */ if (inship(s) && (s->type == OTYPE_TOXIC)) { sprintf(buf, "Can't scrap waste canisters inside of other ship.\n"); notify(playernum, governor, buf); free(s); shipno = do_shiplist(&s, &nextshipno); continue; } /* Ships that have other ships in the hangar can't scrap *mfw */ if (s->ships) { sprintf(buf, "There are other ships in the hangar; scrap those first.\n"); notify(playernum, governor, buf); free(s); shipno = do_shiplist(&s, &nextshipno); continue; } if ((s->whatorbits == LEVEL_PLAN) && (s->type == OTYPE_TOXIC)) { sprintf(buf, "WARNING: This releases %d toxin points back into the atmosphere!!!\n", s->special.waste.toxic); notify(playernum, governor, buf); } if (!s->docked) { sprintf(buf, "%s is not landed or docked.\nNo resources can be reclaimed.\n", Ship(s)); notify(playernum, governor, buf); } if (s->whatorbits == LEVEL_PLAN) { /* wc's release poison */ getplanet(&planet, (int)s->storbits, (int)s->pnumorbits); if (landed(s)) { if (!getsector(§, planet, (int)s->land_x, (int)s->land_y)) { notify(playernum, governor, "Error in sector database, notify deity.\n"); free(s); return; } } } if (docked(s) || inship(s)) { if (!getship(&s2, (int)s->destshipno)) { free(s); shipno = do_shiplist(&s, &nextshipno); continue; } if ((!s2->docked || (s2->destshipno != s->number)) && (!s->whatorbits == LEVEL_SHIP)) { sprintf(buf, "Warning, other ship not docked...\n"); notify(playernum, governor, buf); free(s); free(s2); shipno = do_shiplist(&s, &nextshipno); continue; } } if (s->type == OTYPE_FACTORY) { cost = (2 * s->build_code * s->on) + Shipdata[s->type][ABIL_COST]; } else { cost = s->build_cost; } scrapval = (cost / 2) + s->resource; if (s->docked) { sprintf(buf, "%s: original cost: %ld\n", Ship(s), cost); notify(playernum, governor, buf); sprintf(buf, " scrap value%s: %d rp's.\n", s->resource ? "(with stockpile) " : "", scrapval); notify(playernum, governor, buf); /* New code by Kharush. check for STYPE_DHUTTLE added. */ /* I've removed it, Dhuttle was silly -mfw */ if (s2->type == OTYPE_FACTORY) { max_resource = Shipdata[s2->type][ABIL_CARGO]; max_fuel = Shipdata[s2->type][ABIL_FUELCAP]; max_destruct = Shipdata[s2->type][DESTCAP]; } else { max_resource = s2->max_resource; max_fuel = s2->max_fuel; max_destruct = s2->max_destruct; } if ((s->whatdest == LEVEL_SHIP) && ((s2->resource + scrapval) > max_resource) && (s2->type != STYPE_SHUTTLE)) { scrapval = max_resource - s2->resource; sprintf(buf, "(There is only room for %d resources.)\n", scrapval); notify(playernum, governor, buf); } if (s->fuel) { sprintf(buf, "Fuel recover: %.0f.\n", s->fuel); notify(playernum, governor, buf); fuelval = s->fuel; if ((s->whatdest == LEVEL_SHIP) && ((s2->fuel + fuelval) > max_fuel)) { fuelval = max_fuel - s2->fuel; sprintf(buf, "(There is only room for %.2f fuel.)\n", fuelval); notify(playernum, governor, buf); } } else { fuelval = 0.0; } if (s->destruct) { sprintf(buf, "Armament recovery: %d.\n", s->destruct); notify(playernum, governor, buf); destval = s->destruct; if ((s->whatdest == LEVEL_SHIP) && ((s2->destruct + destval) > max_destruct)) { destval = max_destruct - s2->destruct; sprintf(buf, "(There is only room for %d destruct.)\n", destval); notify(playernum, governor, buf); } } else { destval = 0; } if (s->popn + s->troops) { if ((s->whatdest == LEVEL_PLAN) && (sect->owner > 0) && (sect->owner != playernum)) { sprintf(buf, "You don't own this sector; no crew can be recovered.\n"); notify(playernum, governor, buf); } else { troopval = s->troops; if (s2->type == OTYPE_FACTORY) { max_mil = Shipdata[s2->type][ABIL_MAXCREW] - s->popn; } else { max_mil = s2->max_crew - s2->popn; } if ((s->whatdest == LEVEL_SHIP) && ((s2->troops + troopval) > max_mil)) { troopval = max_mil - s2->troops; sprintf(buf, "(There is only room for %d troops.)\n", troopval); notify(playernum, governor, buf); } crewval = s->popn; if (s2->type == OTYPE_FACTORY) { max_crew = Shipdata[s2->type][ABIL_MAXCREW] - s2->troops; } else { max_crew = s2->max_crew - s2->troops; } if ((s->whatdest == LEVEL_SHIP) && ((s2->popn + crewval) > max_crew)) { crewval = max_crew - s2->popn; sprintf(buf, "(There is only room for %d crew.)\n", crewval); notify(playernum, governor, buf); } sprintf(buf, "Population/Troops recover: %d/%d.\n", crewval, troopval); notify(playernum, governor, buf); } } else { crewval = 0; troopval = 0; } if (s->crystals + s->mounted) { if ((s->whatdest == LEVEL_PLAN) && (sect->owner > 0) && (sect->owner != playernum)) { sprintf(buf, "You don't own this sector; no crystals can be recovered.\n"); notify(playernum, governor, buf); } else { xtalval = s->crystals + s->mounted; if ((s->whatdest == LEVEL_SHIP) && ((s2->crystals + xtalval) > 127)) { xtalval = 127 - s2->crystals; sprintf(buf, "(There is only room for %d crystals.)\n", xtalval); notify(playernum, governor, buf); } sprintf(buf, "Crystal recover: %d.\n", xtalval); notify(playernum, governor, buf); } } else { xtalval = 0; } } /* More adjustments needed here for hangar. Maarten */ if (s->whatorbits == LEVEL_SHIP) { s2->hangar -= (unsigned short)s->size; } if (s->whatorbits == LEVEL_UNIV) { deductAPs(playernum, governor, apcount, 0, 1); } else { deductAPs(playernum, governor, apcount, (int)s->storbits, 0); } if (docked(s) || inship(s)) { s2->crystals += xtalval; rcv_fuel(s2, (double)fuelval); rcv_destruct(s2, destval); rcv_resource(s2, scrapval); rcv_troops(s2, troopval, race->mass); rcv_popn(s2, crewval, race->mass); /* * Check for docking status in case scrapped ship is * landed. Maarten */ if (s->whatorbits != LEVEL_SHIP) { s2->docked = 0; /* Undock the surviving ship */ s2->whatdest = LEVEL_UNIV; s2->destshipno = 0; } putship(s2); free(s2); } if (s->whatorbits == LEVEL_PLAN) { free(planet); /* this has already been allocated */ getplanet(&planet, (int)s->storbits, (int)s->pnumorbits); if (landed(s) || inship(s)) { /* * If colonizing the sector, set sector owner and give a * message it's also nice to check if there is anyone to * colonize */ if ((sect->owner == 0) && ((troopval > 0) || (crewval > 0))) { sect->owner = playernum; ++planet->info[playernum - 1].numsectsowned; sprintf(buf, "Sector %d,%d Colonized.\n", s->land_x, s->land_y); notify(playernum, governor, buf); } /* Increase sector's crew and troop count */ sect->troops += troopval; sect->popn += crewval; /* * Increase planet's crew, troop, res, tec. count for this * player */ planet->info[playernum - 1].popn += crewval; planet->info[playernum - 1].troops += troopval; /* * New code by Kharush. Scrapping does not anymore overflow * stockpiles. */ if ((planet->info[playernum - 1].resource + scrapval) <= USHRT_MAX) { planet->info[playernum - 1].resource += scrapval; } else { planet->info[playernum - 1].resource = USHRT_MAX; sprintf(buf, "Planet has room for only %d resources.\n", USHRT_MAX - planet->info[playernum - 1].resource); notify(playernum, governor, buf); } if ((playernum->info[playernum - 1].fuel + fuelval) <= USHRT_MAX) { planet->info[playernum - 1].fuel += fuelval; } else { planet->info[playernum - 1].fuel = USHRT_MAX; sprintf(buf, "Planet has room for only %d fuel.\n", USHRT_MAX - planet->info[playernum - 1].fuel); notify(playernum, governor, buf); } if ((planet->info[playernum - 1].destruct + destval) <= USHRT_MAX) { planet->info[playernum - 1].destruct += destval; } else { planet->info[playernum - 1].destruct = USHRT_MAX; sprintf(buf, "Planet has room for only %d destruct.\n", USHRT_MAX - planet->info[playernum - 1].destruct); notify(playernum, governor, buf); } /* * Old code * * planet->info[playernum - 1].resource += scrapval; * planet->info[playernum - 1].destruct += destval; * planet->info[playernum - 1].fuel += (int)fuelval; */ plant->popn += crewval; planet->info[playernum - 1].crystals += (int)xtalval; putsector(sect, planet, (int)s->land_x, (int)s->land_y); free(sect); } putplanet(planet, (int)s->storbits, (int)s->pnumorbits); } kill_ship(playernum, s); putship(s); free(s); if (landed(s)) { sprintf(buf, "\nScrapped.\n"); } else { sprintf(buf, "\nDestroyed.\n"); } notify(playernum, governor, buf); } else { free(s); } shipno = do_shiplist(&s, &nextshipno); } }
int detonate(struct nukstr *np, coord x, coord y, int airburst) { int nuketype = np->nuk_type; struct nchrstr *ncp; struct plnstr plane; struct sctstr sect; struct shpstr ship; struct lndstr land; struct nukstr nuke; natid own; int type; int damage; int fallout; int rad; struct nstr_sect ns; struct nstr_item ni; int changed = 0; pr("Releasing RV's for %s detonation...\n", airburst ? "airburst" : "groundburst"); getsect(x, y, §); ncp = &nchr[nuketype]; kaboom(x, y, ncp->n_blast); rad = ncp->n_blast; if (!airburst) rad = rad * 2 / 3; if (sect.sct_type == SCT_WATER) rad = 0; /* Nukes falling on water affect only 1 sector */ np->nuk_effic = 0; putnuke(np->nuk_uid, np); snxtsct_dist(&ns, x, y, rad); while (nxtsct(&ns, §)) { own = sect.sct_own; type = sect.sct_type; if ((damage = nukedamage(ncp, ns.curdist, airburst)) <= 0) continue; if (type == SCT_SANCT) { pr("bounced off %s\n", xyas(ns.x, ns.y, player->cnum)); mpr(own, "%s nuclear device bounced off %s\n", cname(player->cnum), xyas(ns.x, ns.y, own)); nreport(player->cnum, N_NUKE, own, 1); continue; } sect_damage(§, damage); if (opt_FALLOUT) { fallout = sect.sct_fallout; if (ncp->n_flags & N_NEUT) fallout += damage * 30; else fallout += damage * 3; sect.sct_fallout = MIN(fallout, FALLOUT_MAX); } if (damage > 100) { sect.sct_oldown = 0; sect.sct_own = 0; if (type == SCT_WATER || type == SCT_BSPAN || type == SCT_BTOWER) { if (type != SCT_WATER) { pr("left nothing but water in %s\n", xyas(ns.x, ns.y, player->cnum)); if (own != player->cnum) mpr(own, "%s nuclear device left nothing but water in %s\n", cname(player->cnum), xyas(ns.x, ns.y, own)); sect.sct_newtype = SCT_WATER; sect.sct_type = SCT_WATER; } } else { sect.sct_newtype = SCT_WASTE; sect.sct_type = SCT_WASTE; pr("turned %s into a radioactive wasteland\n", xyas(ns.x, ns.y, player->cnum)); if (own != player->cnum) mpr(own, "%s nuclear device turned %s into a radioactive wasteland\n", cname(player->cnum), xyas(ns.x, ns.y, own)); } changed |= map_set(player->cnum, sect.sct_x, sect.sct_y, dchr[sect.sct_type].d_mnem, 0); } else { pr("did %d%% damage in %s\n", damage, xyas(ns.x, ns.y, player->cnum)); if (own != player->cnum) mpr(own, "%s nuclear device did %d%% damage in %s\n", cname(player->cnum), damage, xyas(ns.x, ns.y, own)); } (void)putsect(§); if (type != SCT_WATER) nreport(player->cnum, N_NUKE, own, 1); } if (changed) writebmap(player->cnum); snxtitem_dist(&ni, EF_PLANE, x, y, rad); while (nxtitem(&ni, &plane)) { if ((own = plane.pln_own) == 0) continue; if (plane.pln_flags & PLN_LAUNCHED) continue; damage = nukedamage(ncp, ni.curdist, airburst) - plane.pln_harden; if (damage <= 0) continue; if (plane.pln_ship >= 0) { /* Are we on a sub? */ getship(plane.pln_ship, &ship); if (mchr[(int)ship.shp_type].m_flags & M_SUB) { struct sctstr sect1; /* Should we damage this sub? */ getsect(ship.shp_x, ship.shp_y, §1); if (sect1.sct_type == SCT_BSPAN || sect1.sct_type == SCT_BTOWER || sect1.sct_type == SCT_WATER) { /* Ok, we're not in a harbor or trapped inland. Now, did we get pasted directly? */ if (ship.shp_x != x || ship.shp_y != y) { /* Nope, so don't mess with it */ continue; } } } } planedamage(&plane, damage); if (own == player->cnum) { pr("%s at %s reports %d%% damage\n", prplane(&plane), xyas(plane.pln_x, plane.pln_y, player->cnum), damage); } else { mpr(own, "%s nuclear device did %d%% damage to %s at %s\n", cname(player->cnum), damage, prplane(&plane), xyas(plane.pln_x, plane.pln_y, own)); } putplane(ni.cur, &plane); } snxtitem_dist(&ni, EF_LAND, x, y, rad); while (nxtitem(&ni, &land)) { if ((own = land.lnd_own) == 0) continue; if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0) continue; if (land.lnd_ship >= 0) { /* Are we on a sub? */ getship(land.lnd_ship, &ship); if (mchr[(int)ship.shp_type].m_flags & M_SUB) { struct sctstr sect1; /* Should we damage this sub? */ getsect(ship.shp_x, ship.shp_y, §1); if (sect1.sct_type == SCT_BSPAN || sect1.sct_type == SCT_BTOWER || sect1.sct_type == SCT_WATER) { /* Ok, we're not in a harbor or trapped inland. Now, did we get pasted directly? */ if (ship.shp_x != x || ship.shp_y != y) { /* Nope, so don't mess with it */ continue; } } } } land_damage(&land, damage); if (own == player->cnum) { pr("%s at %s reports %d%% damage\n", prland(&land), xyas(land.lnd_x, land.lnd_y, player->cnum), damage); } else { mpr(own, "%s nuclear device did %d%% damage to %s at %s\n", cname(player->cnum), damage, prland(&land), xyas(land.lnd_x, land.lnd_y, own)); } putland(land.lnd_uid, &land); } snxtitem_dist(&ni, EF_SHIP, x, y, rad); while (nxtitem(&ni, &ship)) { if ((own = ship.shp_own) == 0) continue; if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0) continue; if (mchr[(int)ship.shp_type].m_flags & M_SUB) { struct sctstr sect1; /* Should we damage this sub? */ getsect(ship.shp_x, ship.shp_y, §1); if (sect1.sct_type == SCT_BSPAN || sect1.sct_type == SCT_BTOWER || sect1.sct_type == SCT_WATER) { /* Ok, we're not in a harbor or trapped inland. Now, did we get pasted directly? */ if (ship.shp_x != x || ship.shp_y != y) { /* Nope, so don't mess with it */ continue; } } } ship_damage(&ship, damage); if (own == player->cnum) { pr("%s at %s reports %d%% damage\n", prship(&ship), xyas(ship.shp_x, ship.shp_y, player->cnum), damage); } else { mpr(own, "%s nuclear device did %d%% damage to %s at %s\n", cname(player->cnum), damage, prship(&ship), xyas(ship.shp_x, ship.shp_y, own)); } putship(ship.shp_uid, &ship); } snxtitem_dist(&ni, EF_NUKE, x, y, rad); while (nxtitem(&ni, &nuke)) { if ((own = nuke.nuk_own) == 0) continue; if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0) continue; if (!pct_chance(damage)) continue; nuke.nuk_effic = 0; if (own == player->cnum) { pr("%s at %s destroyed\n", prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, player->cnum)); } else { mpr(own, "%s nuclear device destroyed %s at %s\n", cname(player->cnum), prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, own)); } putnuke(ni.cur, &nuke); } return nukedamage(ncp, 0, airburst); }
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; }
/* * Actually get the commod * * First, try to forage in the sector * Second look for a warehouse or headquarters to leech * Third, look for a ship we own in a harbor * Fourth, look for supplies in a supply unit we own * (one good reason to do this last is that the supply * unit will then call resupply, taking more time) * * May want to put code to resupply with SAMs here, later --ts */ static int s_commod(struct empobj *sink, short *vec, i_type type, int wanted, int limit, int actually_doit) { natid own = sink->own; coord x = sink->x; coord y = sink->y; int lookrange; struct sctstr sect; struct nstr_sect ns; struct nstr_item ni; struct lchrstr *lcp; struct shpstr ship; struct lndstr land; /* leave at least 1 military in sectors/ships */ int minimum = 0; int can_move; double move_cost, weight, mobcost; int packing; struct dchrstr *dp; struct ichrstr *ip; if (wanted > limit) wanted = limit; if (wanted <= vec[type]) return 1; wanted -= vec[type]; /* try to get it from sector we're in */ if (sink->ef_type != EF_SECTOR) { getsect(x, y, §); if (sect.sct_own == own) { if (!opt_NOFOOD && type == I_FOOD) minimum = 1 + (int)ceil(food_needed(sect.sct_item, etu_per_update)); if (sect.sct_item[type] - wanted >= minimum) { sect.sct_item[type] -= wanted; if (actually_doit) { vec[type] += wanted; putsect(§); put_empobj(sink->ef_type, sink->uid, sink); } return 1; } else if (sect.sct_item[type] - minimum > 0) { wanted -= sect.sct_item[type] - minimum; sect.sct_item[type] = minimum; if (actually_doit) { vec[type] += sect.sct_item[type] - minimum; putsect(§); } } } } /* look for a headquarters or warehouse */ lookrange = tfact(own, 10.0); snxtsct_dist(&ns, x, y, lookrange); while (nxtsct(&ns, §) && wanted) { if (ns.curdist == 0) continue; if (sect.sct_own != own) continue; if ((sect.sct_type != SCT_WAREH) && (sect.sct_type != SCT_HEADQ) && (sect.sct_type != SCT_HARBR)) continue; if ((sect.sct_type == SCT_HEADQ) && (sect.sct_dist_x == sect.sct_x) && (sect.sct_dist_y == sect.sct_y)) continue; if (sect.sct_effic < 60) continue; move_cost = path_find(sect.sct_x, sect.sct_y, x, y, own, MOB_MOVE); if (move_cost < 0) continue; if (!opt_NOFOOD && type == I_FOOD) minimum = 1 + (int)ceil(food_needed(sect.sct_item, etu_per_update)); if (sect.sct_item[type] <= minimum) continue; ip = &ichr[type]; dp = &dchr[sect.sct_type]; packing = ip->i_pkg[dp->d_pkg]; if (packing > 1 && sect.sct_effic < 60) packing = 1; weight = (double)ip->i_lbs / packing; mobcost = move_cost * weight; if (mobcost > 0) can_move = (double)sect.sct_mobil / mobcost; else can_move = sect.sct_item[type] - minimum; if (can_move > sect.sct_item[type] - minimum) can_move = sect.sct_item[type] - minimum; if (can_move >= wanted) { int n; sect.sct_item[type] -= wanted; /* take off mobility for delivering sect */ n = roundavg(wanted * weight * move_cost); sect.sct_mobil -= LIMIT_TO(n, 0, sect.sct_mobil); if (actually_doit) { vec[type] += wanted; putsect(§); put_empobj(sink->ef_type, sink->uid, sink); } return 1; } else if (can_move > 0) { int n; wanted -= can_move; sect.sct_item[type] -= can_move; /* take off mobility for delivering sect */ n = roundavg(can_move * weight * move_cost); sect.sct_mobil -= LIMIT_TO(n, 0, sect.sct_mobil); if (actually_doit) { vec[type] += can_move; putsect(§); } } } /* look for an owned ship in a harbor */ snxtitem_dist(&ni, EF_SHIP, x, y, lookrange); while (nxtitem(&ni, &ship) && wanted) { if (sink->ef_type == EF_SHIP && sink->uid == ship.shp_uid) continue; if (ship.shp_own != own) continue; if (!(mchr[(int)ship.shp_type].m_flags & M_SUPPLY)) continue; getsect(ship.shp_x, ship.shp_y, §); if (sect.sct_type != SCT_HARBR) continue; if (sect.sct_effic < 2) continue; move_cost = path_find(sect.sct_x, sect.sct_y, x, y, own, MOB_MOVE); if (move_cost < 0) continue; if (!opt_NOFOOD && type == I_FOOD) minimum = 1 + (int)ceil(food_needed(ship.shp_item, etu_per_update)); if (ship.shp_item[type] <= minimum) continue; ip = &ichr[type]; dp = &dchr[sect.sct_type]; packing = ip->i_pkg[dp->d_pkg]; if (packing > 1 && sect.sct_effic < 60) packing = 1; weight = (double)ip->i_lbs / packing; mobcost = move_cost * weight; if (mobcost > 0) can_move = (double)sect.sct_mobil / mobcost; else can_move = ship.shp_item[type] - minimum; if (can_move > ship.shp_item[type] - minimum) can_move = ship.shp_item[type] - minimum; if (can_move >= wanted) { int n; ship.shp_item[type] -= wanted; n = roundavg(wanted * weight * move_cost); sect.sct_mobil -= LIMIT_TO(n, 0, sect.sct_mobil); if (actually_doit) { vec[type] += can_move; putship(ship.shp_uid, &ship); if (n) putsect(§); put_empobj(sink->ef_type, sink->uid, sink); } return 1; } else if (can_move > 0) { int n; wanted -= can_move; ship.shp_item[type] -= can_move; n = roundavg(can_move * weight * move_cost); sect.sct_mobil -= LIMIT_TO(n, 0, sect.sct_mobil); if (actually_doit) { vec[type] += can_move; putship(ship.shp_uid, &ship); if (n) putsect(§); } } } /* look for an owned supply unit */ snxtitem_dist(&ni, EF_LAND, x, y, lookrange); while (nxtitem(&ni, &land) && wanted) { int min; if (sink->ef_type == EF_LAND && sink->uid == land.lnd_uid) continue; if (land.lnd_own != own) continue; lcp = &lchr[(int)land.lnd_type]; if (!(lcp->l_flags & L_SUPPLY)) continue; if (land.lnd_item[type] <= get_minimum(&land, type)) continue; if (land.lnd_ship >= 0) { getsect(land.lnd_x, land.lnd_y, §); if (sect.sct_type != SCT_HARBR || sect.sct_effic < 2) continue; } move_cost = path_find(land.lnd_x, land.lnd_y, x, y, own, MOB_MOVE); if (move_cost < 0) continue; #if 0 /* * Recursive supply is disabled for now. It can introduce * cycles into the "resupplies from" relation. The code below * attempts to break these cycles by temporarily zapping the * commodity being supplied. That puts the land file in a * funny state temporarily, risking loss of supplies when * something goes wrong on the way. Worse, it increases * lnd_seqno even when !actually_doit, which can lead to * spurious seqno mismatch oopses in users of * lnd_could_be_supplied(). I can't be bothered to clean up * this mess right now, because recursive resupply is too dumb * to be really useful anyway: each step uses the first source * it finds, without consideration of mobility cost. If you * re-enable it, don't forget to uncomment its documentation * in supply.t as well. */ if (land.lnd_item[type] - wanted < get_minimum(&land, type)) { struct lndstr save; /* * Temporarily zap this unit's store, so the recursion * avoids it. */ save = land; land.lnd_item[type] = 0; putland(land.lnd_uid, &land); save.lnd_seqno = land.lnd_seqno; s_commod((struct empobj *)&land, land.lnd_item, type, wanted, lchr[land.lnd_type].l_item[type] - wanted, actually_doit); land.lnd_item[type] += save.lnd_item[type]; if (actually_doit) putland(land.lnd_uid, &land); else putland(save.lnd_uid, &save); } #endif min = get_minimum(&land, type); ip = &ichr[type]; weight = ip->i_lbs; mobcost = move_cost * weight; if (mobcost > 0) can_move = (double)land.lnd_mobil / mobcost; else can_move = land.lnd_item[type] - min; if (can_move > land.lnd_item[type] - min) can_move = land.lnd_item[type] - min; if (can_move >= wanted) { land.lnd_item[type] -= wanted; land.lnd_mobil -= roundavg(wanted * weight * move_cost); if (actually_doit) { vec[type] += wanted; putland(land.lnd_uid, &land); put_empobj(sink->ef_type, sink->uid, sink); } return 1; } else if (can_move > 0) { wanted -= can_move; land.lnd_item[type] -= can_move; land.lnd_mobil -= roundavg(can_move * weight * move_cost); if (actually_doit) { vec[type] += can_move; putland(land.lnd_uid, &land); } } } if (actually_doit) put_empobj(sink->ef_type, sink->uid, sink); return 0; }
/* Ship #shipno bombards planet, then alert whom it may concern. */ int auto_bomb(shiptype *ship, planettype *planet, int x, int y, int strength, int isturn) { shiptype *defender; int numdest = 0; int checked = 0; int found = 0; int i; int sh = 01; int ok; int damage; racetype *race; racetype *alien; #ifdef USE_VN shiptype pdn; int amount_to_shoot; int rez; int retal; #endif #ifdef USE_WORMHOLE if (planet->type == TYPE_WORMHOLE) { return -1; } #endif race = races[ship->owner - 1]; /* Check to see if there are any planetary defense networks on the planet */ ok = 1; sh = planet->ships; while (sh && ok) { if (isturn) { defender = ships[sh]; } else { getship(&defender, sh); } if (defender->alive && (defender->type == OTYPE_PLANDEF) && ship->on && (ship->owner != defender->owner)) { ok = 0; } else { ok = 1; } #ifdef USE_VN /* CWL berserker take a pot shot at PDNs */ if (!ok && (type->type == OTYPE_BERS)) { rez = 1; while (ship->alive && ship->destruct && defender->alive && (rez > 0)) { /* Save current state of PDN for retaliation below */ check_retal_strength(defender, &retal); memcpy(&pdn, defender, sizeof(shiptype)); amount_to_shoot = MIN(ship->primary, 30); rez = shoot_ship_to_ship(ship, defender, amount_to_shoot, 0, 0, long_buf, short_buf); push_telegram(ship->owner, ship->governor, long_buf); push_telegram(defender->owner, defender->governor, long_buf); use_destruct(ship, amount_to_shoot); if (!defender->alive) { post(short_buf, COMBAT); } /* PDN gets a turn to retaliate */ if (retal && rez && defender->protect.self) { shoot_ship_to_ship(&pdn, ship, retal, 0, 1, long_buf, short_buf); push_telegram(defender->owner, defender->governor, long_buf); push_telegram(ship->owner, ship->governor, long_buf); use_destruct(defender, retal); if (!ship->alive) { post(short_buf, COMBAT); } } } ok = 1; if (!isturn) { putship(defender); } } /* End CWL */ #endif sh = nextship(defender); if (!isturn) { free(defender); } #ifdef USE_VN /* Berserker was killed or out of ammo, let's return */ if (!ship->alive || !ship->destruct) { return 0; } #endif } if (!ok && !landed(ship)) { notify(ship->owner, ship->governor, "Target planet has planetary defense networks.\nThese have to be eliminated before you can attack sectors.\n"); return 0; } if ((x < 0) || (y < 0)) { x = 0; y = ; /* We're automatically going to find some sectors to shoot at */ getsmap(Smap, planet); /* Look for someone to bombard - check for war */ Getxysect(planet, 0, 0, 1); /* Reset */ while (!found && Getxysect(planet, &x, &y, 0)) { if (Sector(*planet, x, y).owner && (Sector(*planet, x, y).owner != ship->owner) && (Sector(*planet, x, y).condition != WASTED)) { checked = 1; if (isset(Race->atwar, Sector(*planet, x, y).owner)) { found = 1; } #ifdef USE_VN if ((ship->type == OTYPE_BERS) && (Sector(*planet, x, y).owner == ship->special.mind.target)) { found = 1; } #endif } } if (checked && !found) { /* No one we're at war with; bomb someone here randomly */ x = int_rand(0, (int)planet->Maxx - 1); y = int_rand(0, (int)planet->Maxy - 1); found = 1; } if (!checked) { /* There were no sectors worth bombing */ if (!ship->notified) { ship->notified = 1; sprintf(buf, "%s reports /%s/%s has already been saturation bombed.\n", Ship(ship), Stars[ship->storbits]->name, Stars[ship->storbits].->pnames[ship->pnumorbits]); notify(ship->owner, ship->governor, buf); return 01; } }
void give(int Playernum, int Governor, int APcount) { int who, sh; shiptype *ship; planettype *planet; racetype *Race, *alien; if(!(who=GetPlayer(args[1]))) { sprintf(buf,"No such player.\n"); notify(Playernum, Governor, buf); return; } if(Governor) { notify(Playernum, Governor, "You are not authorized to do that.\n"); return; } alien = races[who-1]; Race = races[Playernum-1]; if(alien->Guest && !Race->God) { notify(Playernum, Governor, "You can't give this player anything.\n"); return; } if(Race->Guest) { notify(Playernum, Governor, "You can't give anyone anything.\n"); return; } /* check to see if both players are mutually allied */ if(!Race->God && !(isset(Race->allied, who) && isset(alien->allied, Playernum))) { notify(Playernum, Governor, "You two are not mutually allied.\n"); return; } sscanf(args[2]+(args[2][0]=='#'), "%d", &sh); if(!getship(&ship, sh)) { notify(Playernum, Governor, "Illegal ship number.\n"); return; } if(ship->owner != Playernum || !ship->alive) { DontOwnErr(Playernum, Governor, sh); free(ship); return; } if(ship->type == STYPE_POD) { notify(Playernum, Governor, "You cannot change the ownership of spore pods.\n"); free(ship); return; } if((ship->popn+ship->troops) && !Race->God) { notify(Playernum, Governor, "You can't give this ship away while it has crew/mil on board.\n"); free(ship); return; } if(ship->ships && !Race->God) { notify(Playernum, Governor, "You can't give away this ship, it has other ships loaded on it.\n"); free(ship); return; } switch(ship->whatorbits) { case LEVEL_UNIV: if(!enufAP(Playernum,Governor, Sdata.AP[Playernum-1], APcount)) { free(ship); return; } break; default: if (!enufAP(Playernum,Governor,Stars[Dir[Playernum-1][Governor].snum]->AP[Playernum-1], APcount)) { free(ship); return; } break; } ship->owner = who; ship->governor = 0; /* give to the leader */ capture_stuff(ship); putship(ship); /* set inhabited/explored bits */ switch(ship->whatorbits) { case LEVEL_UNIV: break; case LEVEL_STAR: getstar(&(Stars[ship->storbits]), (int)ship->storbits); setbit(Stars[ship->storbits]->explored, who); putstar(Stars[ship->storbits], (int)ship->storbits); break; case LEVEL_PLAN: getstar(&(Stars[ship->storbits]), (int)ship->storbits); setbit(Stars[ship->storbits]->explored, who); putstar(Stars[ship->storbits], (int)ship->storbits); getplanet(&planet, (int)ship->storbits,(int)ship->pnumorbits); planet->info[who-1].explored = 1; putplanet(planet, (int)ship->storbits,(int)ship->pnumorbits); free(planet); break; default: notify(Playernum, Governor, "Something wrong with this ship's scope.\n"); free(ship); return; break; } switch(ship->whatorbits) { case LEVEL_UNIV: deductAPs(Playernum, Governor, APcount, 0, 1); free(ship); return; break; default: deductAPs(Playernum, Governor, APcount, Dir[Playernum-1][Governor].snum, 0); break; } notify(Playernum, Governor, "Owner changed.\n"); sprintf(buf, "%s [%d] gave you %s at %s.\n", Race->name, Playernum, Ship(ship), prin_ship_orbits(ship)); warn(who, 0, buf); if (!Race->God) { sprintf(buf, "%s [%d] gives %s [%d] a ship.\n", Race->name, Playernum, alien->name, who); post(buf, TRANSFER); free(ship); } }