/* * format: skywatch [<SECTS>] */ int skyw(void) { struct sctstr sect; struct nstr_sect nstr; struct sky *skyp; struct sky *list[TSIZE]; int i, n; int vrange, see; int x, y, dx, dy, dxmax; int nsat = 0; double tech; struct nstr_item ni; if (!snxtsct(&nstr, player->argp[1])) return RET_SYN; for (i = 0; i < TSIZE; i++) list[i] = NULL; skyp = malloc(sizeof(*skyp)); snxtitem_all(&ni, EF_PLANE); while (nxtitem(&ni, &skyp->s_sat)) { if (!skyp->s_sat.pln_own) continue; if (!pln_is_in_orbit(&skyp->s_sat)) continue; getsect(skyp->s_sat.pln_x, skyp->s_sat.pln_y, §); n = scthash(skyp->s_sat.pln_x, skyp->s_sat.pln_y, TSIZE); skyp->s_spotted = 0; skyp->s_next = list[n]; list[n] = skyp; skyp = malloc(sizeof(*skyp)); nsat++; } /* get that last one! */ free(skyp); pr("- = [ Skywatch report for %s ] = -\n", cname(player->cnum)); pr(" Country Satellite Location\n"); tech = tfact(player->cnum, 1.0); while (nxtsct(&nstr, §) && nsat) { if (sect.sct_own != player->cnum) continue; see = sect.sct_type == SCT_RADAR ? 14 : 4; vrange = (int)(sect.sct_effic / 100.0 * see * tech); if (vrange < 1) vrange = 1; for (dy = -vrange; dy <= vrange; dy++) { y = ynorm(sect.sct_y + dy); dxmax = 2 * vrange - abs(dy); for (dx = -dxmax; dx <= dxmax; dx += 2) { x = xnorm(sect.sct_x + dx); n = scthash(x, y, TSIZE); if (!list[n]) continue; nsat -= showsat(&list[n], x, y); } } } /* free up the sky structs calloc'ed above */ for (i = 0; i < TSIZE; i++) { while (NULL != (skyp = list[i])) { list[i] = skyp->s_next; free(skyp); } } return RET_OK; }
/* * format: coastwatch [<SECTS>] */ int coas(void) { struct sctstr sect; struct nstr_sect nstr; struct coast *cp; struct coast *list[TSIZE]; int i, n; int vrange, see; int x, y, dx, dy, dxmax; int nship = 0; double tech; struct nstr_item ni; if (!snxtsct(&nstr, player->argp[1])) return RET_SYN; for (i = 0; i < TSIZE; i++) list[i] = NULL; cp = malloc(sizeof(*cp)); snxtitem_all(&ni, EF_SHIP); while (nxtitem(&ni, &cp->c_shp)) { if (cp->c_shp.shp_own == 0 || cp->c_shp.shp_own == player->cnum) continue; /* * don't bother putting subs in the table... * unless they're in a sector you own (harbor or such) */ getsect(cp->c_shp.shp_x, cp->c_shp.shp_y, §); if ((mchr[(int)cp->c_shp.shp_type].m_flags & M_SUB) && (sect.sct_own != player->cnum)) continue; n = scthash(cp->c_shp.shp_x, cp->c_shp.shp_y, TSIZE); cp->c_spotted = 0; cp->c_number = i; cp->c_next = list[n]; list[n] = cp; cp = malloc(sizeof(*cp)); nship++; } /* get that last one! */ free(cp); pr("- = [ Coastwatch report for %s ] = -\n", cname(player->cnum)); pr(" Country Ship Location\n"); tech = tfact(player->cnum, 1.0); while (nxtsct(&nstr, §) && nship) { if (sect.sct_own != player->cnum) continue; see = sect.sct_type == SCT_RADAR ? 14 : 4; vrange = (int)(sect.sct_effic / 100.0 * see * tech); if (vrange < 1) vrange = 1; for (dy = -vrange; dy <= vrange; dy++) { y = ynorm(sect.sct_y + dy); dxmax = 2 * vrange - abs(dy); for (dx = -dxmax; dx <= dxmax; dx += 2) { x = xnorm(sect.sct_x + dx); n = scthash(x, y, TSIZE); if (!list[n]) continue; nship -= showship(&list[n], x, y); } } } /* free up the coast structs calloc'ed above */ for (i = 0; i < TSIZE; i++) { while (NULL != (cp = list[i])) { list[i] = cp->c_next; free(cp); } } return RET_OK; }