Exemple #1
0
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");
    }
}
Exemple #2
0
static void
starv_sects(char *range)
{
    struct nstr_sect nstr;
    struct sctstr sect;
    int nsect = 0;
    int s, save;

    if (!snxtsct(&nstr, range))
        return;
    while (nxtsct(&nstr, &sect)) {
        if (!player->owner)
            continue;
        if (sect.sct_type == SCT_SANCT)
            continue;

        /*
         * Check for starvation.  Suppress complaints about tiny
         * population without food by adding 1f just for the check.
         * That's okay because growfood() will grow at least that much
         * anyway.
         */
        save = sect.sct_item[I_FOOD];
        if (sect.sct_item[I_FOOD] == 0)
            sect.sct_item[I_FOOD] = 1;
        s = famine_victims(sect.sct_item, etu_per_update);
        sect.sct_item[I_FOOD] = save;
        if (s == 0)
            continue;

        if (nsect++ == 0)
            sect_hdr();
        if (player->god)
            pr("%3d ", sect.sct_own);
        prxy("%4d,%-4d", nstr.x, nstr.y);
        pr(" %c", dchr[sect.sct_type].d_mnem);
        pr(" %c", sect.sct_own != sect.sct_oldown ? '*' : ' ');
        if (sect.sct_newtype != sect.sct_type)
            pr("%c", dchr[sect.sct_newtype].d_mnem);
        else
            pr(" ");
        pr("%4d%%", sect.sct_effic);
        starv_people(sect.sct_item, s);
    }
    if (nsect == 0) {
        if (player->argp[1])
            pr("%s: No sector(s)\n", player->argp[1]);
        else
            pr("%s: No sector(s)\n", "");
        return;
    } else
        pr("%d sector%s\n", nsect, splur(nsect));
    return;
}
Exemple #3
0
int
nuke(void)
{
    int nnukes, noff;
    struct nstr_item nstr;
    struct nukstr nuk;
    struct plnstr plane;

    if (!snxtitem(&nstr, EF_NUKE, player->argp[1], NULL))
	return RET_SYN;
    nnukes = noff = 0;
    while (nxtitem(&nstr, &nuk)) {
	if (!player->owner || nuk.nuk_own == 0)
	    continue;
	if (nnukes++ == 0) {
	    if (player->god)
		pr("own ");
	    pr("   # nuke type              x,y    s   eff tech carry burst\n");
	}
	if (nuk.nuk_off)
	    noff++;
	if (player->god)
	    pr("%-3d ", nuk.nuk_own);
	pr("%4d %-19.19s ", nstr.cur, nchr[(int)nuk.nuk_type].n_name);
	prxy("%4d,%-4d", nuk.nuk_x, nuk.nuk_y);
	pr(" %1.1s %c%3d%% %4d",
	   &nuk.nuk_stockpile, nuk.nuk_off ? '!' : ' ', nuk.nuk_effic,
	   nuk.nuk_tech);
	if (nuk.nuk_plane >= 0) {
	    getplane(nuk.nuk_plane, &plane);
	    pr("%5dP %s",
	       nuk.nuk_plane,
	       plane.pln_flags & PLN_AIRBURST ? "  air" : "ground");
	}
	pr("\n");
    }

    if (nnukes == 0) {
	if (player->argp[1])
	    pr("%s: No nuke(s)\n", player->argp[1]);
	else
	    pr("%s: No nuke(s)\n", "");
	return RET_FAIL;
    } else {
	pr("%d nuke%s", nnukes, splur(nnukes));
	if (noff)
	    pr(", %d stopped (eff marked with !)", noff);
	pr("\n");
    }

    return RET_OK;
}
Exemple #4
0
int
ndump(void)
{
    struct nstr_item nstr;
    struct nukstr nuk;
    time_t now;
    int nnukes;

    if (!snxtitem(&nstr, EF_NUKE, player->argp[1], NULL))
	return RET_SYN;
    prdate();
    if (player->god)
	pr("   ");
    time(&now);
    pr("DUMP NUKES %ld\n", (long)now);
    if (player->god)
	pr("own ");
    pr("id x y num type\n");
    nnukes = 0;
    while (nxtitem(&nstr, &nuk)) {
	if (!player->god && !player->owner)
	    continue;
	if (nuk.nuk_own == 0)
	    continue;
	nnukes++;
	if (player->god)
	    pr("%d ", nuk.nuk_own);
	pr("%d ", nuk.nuk_uid);
	prxy("%d %d", nuk.nuk_x, nuk.nuk_y);
	pr(" %d", 1);
	pr(" %.5s", nchr[(int)nuk.nuk_type].n_name);
	pr("\n");
    }
    if (nnukes == 0) {
	if (player->argp[1])
	    pr("%s: No nuke(s)\n", player->argp[1]);
	else
	    pr("%s: No nuke(s)\n", "");
	return RET_FAIL;
    } else
	pr("%d nuke%s\n", nnukes, splur(nnukes));

    return RET_OK;
}
Exemple #5
0
int
lsta(void)
{
    int nunits;
    struct nstr_item ni;
    struct lndstr land;
    struct lchrstr *lcp;

    if (!snxtitem(&ni, EF_LAND, player->argp[1], NULL))
	return RET_SYN;

    nunits = 0;
    while (nxtitem(&ni, &land)) {
	if (!player->owner || land.lnd_own == 0)
	    continue;
	lcp = lchr + land.lnd_type;
	if (nunits++ == 0) {
	    pr("     %16.16s                                 s  v  s  r  r  a  f  a  a\n", "");
	    pr("     %16.16s                                 p  i  p  a  n  c  i  m  a\n", "");
	    pr("lnd# %16.16s    x,y    eff tech att def vul  d  s  y  d  g  c  r  m  f\n", "unit-type");
	}
	pr("%4d %-16.16s ", land.lnd_uid, lcp->l_name);
	prxy("%4d,%-4d", land.lnd_x, land.lnd_y);
	pr(" %3d%% %3d %1.1f %1.1f %3d ",
	   land.lnd_effic, land.lnd_tech, lnd_att(&land), lnd_def(&land),
	   lnd_vul(&land));
	pr("%2d %2d %2d %2d ",
	   lnd_spd(&land), lnd_vis(&land), lcp->l_spy, lcp->l_rad);
	pr("%2d %2d %2d %2d %2d ",
	   lnd_frg(&land), lnd_acc(&land), lnd_dam(&land),
	   lcp->l_ammo, lnd_aaf(&land));
	pr("\n");
    }
    if (nunits == 0) {
	if (player->argp[1])
	    pr("%s: No unit(s)\n", player->argp[1]);
	else
	    pr("%s: No unit(s)\n", "");
	return RET_FAIL;
    } else
	pr("%d unit%s\n", nunits, splur(nunits));
    return RET_OK;
}
Exemple #6
0
int
cens(void)
{
    struct sctstr sect;
    int nsect;
    int n;
    struct nstr_sect nstr;
    char dirstr[20];

    if (!snxtsct(&nstr, player->argp[1]))
	return RET_SYN;
    prdate();
    for (n = 1; n <= 6; n++)
	dirstr[n] = dirch[n];
    dirstr[0] = '.';
    dirstr[7] = '$';
    dirstr[8] = '\0';
    nsect = 0;
    while (nxtsct(&nstr, &sect)) {
	if (!player->owner)
	    continue;
	if (nsect++ == 0)
	    cens_hdr();
	if (player->god)
	    pr("%3d ", sect.sct_own);
	prxy("%4d,%-4d", nstr.x, nstr.y);
	pr(" %c", dchr[sect.sct_type].d_mnem);
	if (sect.sct_newtype != sect.sct_type)
	    pr("%c", dchr[sect.sct_newtype].d_mnem);
	else
	    pr(" ");
	pr("%4d%%", sect.sct_effic);
	if (sect.sct_off)
	    pr(" no ");
	else
	    pr("    ");
	pr("%4d", sect.sct_mobil);

	pr(" %c", dirstr[sect.sct_del[I_UW] & 0x7]);
	pr("%c", dirstr[sect.sct_del[I_FOOD] & 0x7]);

	n = sect.sct_dist[I_UW] % 1000;
	pr(" %c", n == 0 ? '.' : '0' + (n / 100));
	n = sect.sct_dist[I_FOOD] % 1000;
	pr("%c ", n == 0 ? '.' : '0' + (n / 100));
	if (sect.sct_own != sect.sct_oldown)
	    pr("%3d",  sect.sct_oldown);
	else
	    pr("   ");

	pr("%5d", sect.sct_item[I_CIVIL]);
	pr("%5d", sect.sct_item[I_MILIT]);
	pr("%5d", sect.sct_item[I_UW]);
	pr("%5d", sect.sct_item[I_FOOD]);
	pr("%4d%%", sect.sct_work);
	pr("%5d", sect.sct_avail);
	if (!player->god) {
	    if (sect.sct_terr)
		pr("%4d", sect.sct_terr);
	    else
		pr("    ");
	}
	pr("%5d", opt_FALLOUT ? sect.sct_fallout : 0);
	if (sect.sct_coastal)
	    pr("%4d", sect.sct_coastal);
	pr("\n");
    }
    if (nsect == 0) {
	if (player->argp[1])
	    pr("%s: No sector(s)\n", player->argp[1]);
	else
	    pr("%s: No sector(s)\n", "");
	return RET_FAIL;
    } else
	pr("%d sector%s\n", nsect, splur(nsect));
    return 0;
}
Exemple #7
0
int
payo(void)
{
    struct sctstr sect;
    int nships;
    struct nstr_item ni;
    struct shpstr ship;
    struct mchrstr *mp;
    int dist;
    float cash = 0.0;

    if (!snxtitem(&ni, EF_SHIP, player->argp[1], NULL))
	return RET_SYN;

    nships = 0;
    while (nxtitem(&ni, &ship)) {
	if (!player->owner || ship.shp_own == 0)
	    continue;
	mp = &mchr[(int)ship.shp_type];

	if (!(mp->m_flags & M_TRADE))
	    continue;

	if (nships++ == 0) {
	    if (player->god)
		pr("own ");
	    pr("shp#     ship type  orig x,y       x,y    dist $$\n");
	}
	if (player->god)
	    pr("%3d ", ship.shp_own);
	pr("%4d ", ni.cur);
	pr("%-16.16s ", mchr[(int)ship.shp_type].m_name);
	if (ship.shp_own != ship.shp_orig_own && !player->god) {
	    /* Don't disclose construction site to pirates! */
	    pr("    ?     ");
	    prxy("%4d,%-4d ", ship.shp_x, ship.shp_y);
	    pr("   ? $  ?\n");
	    continue;
	}
	prxy("%4d,%-4d ", ship.shp_orig_x, ship.shp_orig_y);
	prxy("%4d,%-4d ", ship.shp_x, ship.shp_y);

	getsect(ship.shp_x, ship.shp_y, &sect);

	dist = mapdist(ship.shp_x, ship.shp_y,
		       ship.shp_orig_x, ship.shp_orig_y);
	pr("%4d ", dist);

	if (dist < trade_1_dist)
	    cash = 0;
	else if (dist < trade_2_dist)
	    cash = 1.0 + trade_1 * dist;
	else if (dist < trade_3_dist)
	    cash = 1.0 + trade_2 * dist;
	else
	    cash = 1.0 + trade_3 * dist;

	cash *= mp->m_cost;
	cash *= ship.shp_effic / 100.0;

	if (sect.sct_own && (sect.sct_own != ship.shp_own))
	    cash *= (1.0 + trade_ally_bonus);
	pr("$%6.2f\n", cash);
    }
    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;
}
Exemple #8
0
int
sorde(void)
{
    int nships = 0;
    int len, updates;
    double c;
    struct nstr_item nb;
    struct shpstr ship;

    if (!snxtitem(&nb, EF_SHIP, player->argp[1], NULL))
	return RET_SYN;
    while (nxtitem(&nb, (&ship))) {
	if (!player->owner || ship.shp_own == 0)
	    continue;
	if (!(ship.shp_autonav & AN_AUTONAV)
	    && (!opt_SAIL || !ship.shp_path[0]))
	    continue;

	if (!nships) {		/* 1st ship, print banner */
	    if (player->god)
		pr("own ");
	    pr("shp#     ship type       x,y      start      end   "
	       " len  eta\n");
	}
	nships++;
	if (player->god)
	    pr("%3d ", ship.shp_own);
	pr("%4d", nb.cur);
	pr(" %-16.16s", mchr[(int)ship.shp_type].m_name);
	prxy(" %4d,%-4d", ship.shp_x, ship.shp_y);

	if (ship.shp_autonav & AN_AUTONAV) {
	    /* Destination 1 */
	    prxy(" %4d,%-4d", ship.shp_destx[1], ship.shp_desty[1]);

	    /* Destination 2 */
	    if ((ship.shp_destx[1] != ship.shp_destx[0])
		|| (ship.shp_desty[1] != ship.shp_desty[0])) {
		prxy(" %4d,%-4d", ship.shp_destx[0], ship.shp_desty[0]);
	    } else
		pr("          ");

	    if (ship.shp_autonav & AN_STANDBY)
		pr(" suspended");
	    else if (ship.shp_autonav & AN_LOADING)
		pr(" loading");
	    else {
		/* ETA calculation */
		c = path_find(ship.shp_x, ship.shp_y,
			      ship.shp_destx[0], ship.shp_desty[0],
			      ship.shp_own, MOB_SAIL);
		if (c < 0)
		    pr(" no route possible");
		else if (c == 0)
		    pr(" has arrived");
		else {
		    /* distance to destination */
		    len = (int)c;
		    updates = eta_calc(&ship, len);
		    pr(" %3d %4d", len, updates);
		}
	    }
	    if (ship.shp_autonav & AN_SCUTTLE)
		pr(" (scuttling)");
	    pr("\n");
	} else
	    pr(" has a sail path\n");

	if (ship.shp_name[0] != 0) {
	    if (player->god)
		pr("    ");
	    pr("       %s\n", ship.shp_name);
	}
    }
    if (!nships) {
	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;
}
Exemple #9
0
int
cuto(void)
{
    struct sctstr sect;
    int nsect;
    int n;
    struct nstr_sect nstr;
    char dirstr[12];

    if (!snxtsct(&nstr, player->argp[1]))
	return RET_SYN;
    prdate();
    (void)strcpy(dirstr, ".      $");
    for (n = 1; n <= 6; n++)
	dirstr[n] = dirch[n];
    nsect = 0;
    while (nxtsct(&nstr, &sect)) {
	if (!player->owner)
	    continue;
	if (nsect++ == 0) {
	    pr("DELIVERY CUTOFF LEVELS\n");
	    if (player->god)
		pr("own");
	    pr("   sect   cmufsgpidbolhr civ mil  uw food sh gun pet irn dst bar oil lcm hcm rad\n");
	}
	if (player->god)
	    pr("%3d", sect.sct_own);
	prxy("%3d,%-3d", nstr.x, nstr.y); /* FIXME too narrow */
	pr(" %c ", dchr[sect.sct_type].d_mnem);
	pr("%c", dirstr[sect.sct_del[I_CIVIL] & 0x7]);
	pr("%c", dirstr[sect.sct_del[I_MILIT] & 0x7]);
	pr("%c", dirstr[sect.sct_del[I_UW] & 0x7]);
	pr("%c", dirstr[sect.sct_del[I_FOOD] & 0x7]);
	pr("%c", dirstr[sect.sct_del[I_SHELL] & 0x7]);
	pr("%c", dirstr[sect.sct_del[I_GUN] & 0x7]);
	pr("%c", dirstr[sect.sct_del[I_PETROL] & 0x7]);
	pr("%c", dirstr[sect.sct_del[I_IRON] & 0x7]);
	pr("%c", dirstr[sect.sct_del[I_DUST] & 0x7]);
	pr("%c", dirstr[sect.sct_del[I_BAR] & 0x7]);
	pr("%c", dirstr[sect.sct_del[I_OIL] & 0x7]);
	pr("%c", dirstr[sect.sct_del[I_LCM] & 0x7]);
	pr("%c", dirstr[sect.sct_del[I_HCM] & 0x7]);
	pr("%c", dirstr[sect.sct_del[I_RAD] & 0x7]);
	pr("%4d", sect.sct_del[I_CIVIL] & ~0x7);
	pr("%4d", sect.sct_del[I_MILIT] & ~0x7);
	pr("%4d", sect.sct_del[I_UW] & ~0x7);
	pr("%4d", sect.sct_del[I_FOOD] & ~0x7);
	pr("%4d", sect.sct_del[I_SHELL] & ~0x7);
	pr("%4d", sect.sct_del[I_GUN] & ~0x7);
	pr("%4d", sect.sct_del[I_PETROL] & ~0x7);
	pr("%4d", sect.sct_del[I_IRON] & ~0x7);
	pr("%4d", sect.sct_del[I_DUST] & ~0x7);
	pr("%4d", sect.sct_del[I_BAR] & ~0x7);
	pr("%4d", sect.sct_del[I_OIL] & ~0x7);
	pr("%4d", sect.sct_del[I_LCM] & ~0x7);
	pr("%4d", sect.sct_del[I_HCM] & ~0x7);
	pr("%4d", sect.sct_del[I_RAD] & ~0x7);
	pr("\n");
    }
    if (nsect == 0) {
	if (player->argp[1])
	    pr("%s: No sector(s)\n", player->argp[1]);
	else
	    pr("%s: No sector(s)\n", "");
	return RET_FAIL;
    } else
	pr("%d sector%s\n", nsect, splur(nsect));
    return RET_OK;
}
Exemple #10
0
int
newe(void)
{
    struct natstr *natp;
    struct sctstr sect;
    struct nstr_sect nstr;
    double work, lcms, hcms;
    int nsect;
    int civs = 0;
    int uws = 0;
    int bwork;
    int twork;
    int type;
    int eff;
    int maxpop;

    if (!snxtsct(&nstr, player->argp[1]))
	return RET_SYN;
    player->simulation = 1;
    prdate();
    nsect = 0;
    while (nxtsct(&nstr, &sect)) {
	if (!player->owner)
	    continue;
	if (!sect.sct_off) {
	    civs = (1.0 + obrate * etu_per_update) * sect.sct_item[I_CIVIL];
	    uws = (1.0 + uwbrate * etu_per_update) * sect.sct_item[I_UW];
	    natp = getnatp(sect.sct_own);
	    maxpop = max_pop(natp->nat_level[NAT_RLEV], &sect);
	    work = new_work(&sect,
			    total_work(sect.sct_work, etu_per_update,
				       civs, sect.sct_item[I_MILIT], uws,
				       maxpop));
	    bwork = work / 2;

	    type = sect.sct_type;
	    eff = sect.sct_effic;
	    if (sect.sct_newtype != type) {
		twork = (eff + 3) / 4;
		if (twork > bwork) {
		    twork = bwork;
		}
		bwork -= twork;
		eff -= twork * 4;
		if (eff <= 0) {
		    type = sect.sct_newtype;
		    eff = 0;
		}

		twork = 100 - eff;
		if (twork > bwork) {
		    twork = bwork;
		}
		if (dchr[type].d_lcms > 0) {
		    lcms = sect.sct_item[I_LCM];
		    lcms = (int)(lcms / dchr[type].d_lcms);
		    if (twork > lcms)
			twork = lcms;
		}
		if (dchr[type].d_hcms > 0) {
		    hcms = sect.sct_item[I_HCM];
		    hcms = (int)(hcms / dchr[type].d_hcms);
		    if (twork > hcms)
			twork = hcms;
		}
		eff += twork;
	    } else if (eff < 100) {
		twork = 100 - eff;
		if (twork > bwork) {
		    twork = bwork;
		}
		if (dchr[type].d_lcms > 0) {
		    lcms = sect.sct_item[I_LCM];
		    lcms = (int)(lcms / dchr[type].d_lcms);
		    if (twork > lcms)
			twork = lcms;
		}
		if (dchr[type].d_hcms > 0) {
		    hcms = sect.sct_item[I_HCM];
		    hcms = (int)(hcms / dchr[type].d_hcms);
		    if (twork > hcms)
			twork = hcms;
		}
		eff += twork;
	    }
	} else {
	    eff = sect.sct_effic;
	    type = sect.sct_type;
	}
	if (nsect++ == 0) {
	    pr("EFFICIENCY SIMULATION\n");
	    pr("   sect  des    projected eff\n");
	}
	prxy("%4d,%-4d", nstr.x, nstr.y);
	pr(" %c", dchr[type].d_mnem);
	pr("    %3d%%\n", eff);
    }
    player->simulation = 0;
    if (nsect == 0) {
	if (player->argp[1])
	    pr("%s: No sector(s)\n", player->argp[1]);
	else
	    pr("%s: No sector(s)\n", "");
	return RET_FAIL;
    } else
	pr("%d sector%s\n", nsect, splur(nsect));
    return RET_OK;
}