Beispiel #1
0
int
supp(void)
{
    int nunits;
    struct nstr_item ni;
    struct lndstr land;

    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;
	nunits++;
	if (lnd_supply_all(&land))
	    pr("%s has supplies\n", prland(&land));
	else
	    pr("%s is out of supply\n", prland(&land));
    }
    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;
}
Beispiel #2
0
static int
load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
	       int load_unload, int *nunitsp)
{
    struct nstr_item ni;
    struct lndstr land;
    int loaded = 0;
    char *p;
    char prompt[512];
    char buf[1024];

    if (load_unload == LOAD
	&& lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
	if (noisy) {
	    if (lchr[lp->lnd_type].l_nland)
		pr("%s doesn't have room for any more land units!\n",
		   prland(lp));
	    else
		pr("%s cannot carry land units!\n", prland(lp));
	}
	return 0;
    }
    sprintf(prompt, "Land unit(s) to %s %s? ",
	    load_unload == LOAD ? "load onto" : "unload from", prland(lp));
    p = getstarg(player->argp[3], prompt, buf);
    if (!p)
	return RET_SYN;
    if (!snxtitem(&ni, EF_LAND, p, NULL))
	return RET_SYN;

    if (!still_ok_land(sectp, lp))
	return RET_SYN;

    if (noisy && p && *p)
	noisy = isdigit(*p);

    while (nxtitem(&ni, &land)) {
	if (!player->owner)
	    continue;

	if (load_unload == LOAD) {
	    if (land.lnd_ship > -1) {
		if (noisy)
		    pr("%s is already on ship #%d!\n",
		       prland(&land), land.lnd_ship);
		continue;
	    }
	    if (land.lnd_land > -1) {
		if (noisy)
		    pr("%s is already on land #%d!\n",
		       prland(&land), land.lnd_land);
		continue;
	    }
	    if (lnd_first_on_land(&land) >= 0) {
		if (noisy)
		    pr("%s cannot be loaded since it is carrying units\n",
		       prland(&land));
		continue;
	    }
	    if (land.lnd_uid == lp->lnd_uid) {
		if (noisy)
		    pr("%s can't be loaded onto itself!\n", prland(&land));
		continue;
	    }
	    if (lchr[(int)land.lnd_type].l_flags & (L_HEAVY | L_TRAIN)) {
		if (noisy)
		    pr("%s is too heavy to load.\n", prland(&land));
		continue;
	    }
	}

	/* Unit sanity done */
	/* Find the right ship */
	if (load_unload == UNLOAD) {
	    if (land.lnd_land != lp->lnd_uid)
		continue;
	    if (land.lnd_ship > -1)
		continue;
	} else if (lp->lnd_x != land.lnd_x || lp->lnd_y != land.lnd_y)
	    continue;

	/* Fit unit on ship */
	if (load_unload == LOAD) {
	    if (lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
		if (noisy) {
		    if (lchr[lp->lnd_type].l_nland)
			pr("%s doesn't have room for any more land units!\n",
			   prland(lp));
		    else
			pr("%s cannot carry land units!\n", prland(lp));
		}
		break;
	    }
	    sprintf(buf, "loaded on your %s at %s",
		    prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
	    gift(lp->lnd_own, player->cnum, &land, buf);
	    land.lnd_land = lp->lnd_uid;
	    land.lnd_harden = 0;
	    putland(land.lnd_uid, &land);
#if 0
	   /* FIXME same issue as in load_land_ship() */
	    if (!lnd_supply_all(&land))
		pr("WARNING: %s is out of supply!\n", prland(&land));
#else
	    if (!lnd_in_supply(&land))
		pr("WARNING: %s is out of supply!\n", prland(&land));
#endif
	} else {
	    sprintf(buf, "unloaded in your %s at %s",
		    dchr[sectp->sct_type].d_name,
		    xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
	    gift(sectp->sct_own, player->cnum, &land, buf);
	    land.lnd_land = -1;
	    putland(land.lnd_uid, &land);
	}
	pr("%s %s %s at %s.\n",
	   prland(&land),
	   (load_unload == UNLOAD) ?
	   "unloaded from" : "loaded onto",
	   prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
	loaded = 1;
    }
    *nunitsp += loaded;
    return 0;
}
Beispiel #3
0
static int
load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
	       int load_unload, int *nshipsp)
{
    struct nstr_item ni;
    struct lndstr land;
    int loaded = 0;
    char *p;
    char prompt[512];
    char buf[1024];
    int load_spy = 0;

    if (load_unload == LOAD) {
	if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
	    (mchr[(int)sp->shp_type].m_nland == 0)) {
	    if (shp_nland(sp) >= 2) {
		pr("Non-land unit carrying subs can only carry up to two spy units.\n");
		return 0;
	    }
	    /* Eh, let 'em load a spy only */
	    load_spy = 1;
	}
	if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
	    if (noisy) {
		if (mchr[(int)sp->shp_type].m_nland)
		    pr("%s doesn't have room for any more land units!\n",
		       prship(sp));
		else
		    pr("%s cannot carry land units!\n", prship(sp));
	    }
	    return 0;
	}
    }
    sprintf(prompt, "Land unit(s) to %s %s? ",
	    load_unload == LOAD ? "load onto" : "unload from", prship(sp));
    p = getstarg(player->argp[3], prompt, buf);
    if (!p)
	return RET_SYN;
    if (!snxtitem(&ni, EF_LAND, p, NULL))
	return RET_SYN;

    if (!still_ok_ship(sectp, sp))
	return RET_SYN;

    if (noisy && p && *p)
	noisy = isdigit(*p);

    while (nxtitem(&ni, &land)) {
	if (!player->owner)
	    continue;

	if (load_unload == LOAD) {
	    if (land.lnd_ship > -1) {
		if (noisy)
		    pr("%s is already on ship #%d!\n",
		       prland(&land), land.lnd_ship);
		continue;
	    }
	    if (land.lnd_land > -1) {
		if (noisy)
		    pr("%s is already on land #%d!\n",
		       prland(&land), land.lnd_land);
		continue;
	    }
	    if (lnd_first_on_land(&land) >= 0) {
		if (noisy)
		    pr("%s cannot be loaded since it is carrying units\n",
		       prland(&land));
		continue;
	    }
	    if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
		if (noisy)
		    pr("%s is too heavy to load.\n", prland(&land));
		continue;
	    }
	    if (load_spy && !(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
		if (noisy)
		    pr("Subs can only carry spy units.\n");
		continue;
	    }
	}

	/* Unit sanity done */
	/* Find the right ship */
	if (load_unload == UNLOAD) {
	    if (land.lnd_ship != sp->shp_uid)
		continue;
	    if (land.lnd_land > -1)
		continue;
	} else if (sp->shp_x != land.lnd_x || sp->shp_y != land.lnd_y)
	    continue;

	if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) &&
	    (!((mchr[(int)sp->shp_type].m_flags & M_SUPPLY) &&
	       (!(mchr[(int)sp->shp_type].m_flags & M_SUB))))) {
	    if (noisy) {
		pr("You can only load light units onto ships,\n");
		pr("unless the ship is a non-sub supply ship\n");
		pr("%s not loaded\n", prland(&land));
	    }
	    continue;
	}
	/* Fit unit on ship */
	if (load_unload == LOAD) {
	    /* We have to check again, since it may have changed */
	    if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
		(mchr[(int)sp->shp_type].m_nland == 0)) {
		if (shp_nland(sp) >= 2) {
		    pr("Non-land unit carrying subs can only carry up to two spy units.\n");
		    return 0;
		}
		/* Eh, let 'em load a spy only */
		load_spy = 1;
	    }
	    if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
		if (noisy) {
		    if (mchr[(int)sp->shp_type].m_nland)
			pr("%s doesn't have room for any more land units!\n",
			   prship(sp));
		    else
			pr("%s cannot carry land units!\n", prship(sp));
		}
		return 0;
	    }
	    sprintf(buf, "loaded on your %s at %s",
		    prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
	    gift(sp->shp_own, player->cnum, &land, buf);
	    land.lnd_ship = sp->shp_uid;
	    land.lnd_harden = 0;
	    putland(land.lnd_uid, &land);
#if 0
	   /*
	    * FIXME if this supplies from the sector, the putsect in
	    * load() / lload() duplicates those supplies, causing a
	    * seqno mismatch
	    */
	    if (!lnd_supply_all(&land))
		pr("WARNING: %s is out of supply!\n", prland(&land));
#else
	    if (!lnd_in_supply(&land))
		pr("WARNING: %s is out of supply!\n", prland(&land));
#endif
	} else {
	    sprintf(buf, "unloaded in your %s at %s",
		    dchr[sectp->sct_type].d_name,
		    xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));

	    /* Spies are unloaded quietly, others aren't */
	    if (!(lchr[(int)land.lnd_type].l_flags & L_SPY))
		gift(sectp->sct_own, player->cnum, &land, buf);
	    land.lnd_ship = -1;
	    putland(land.lnd_uid, &land);
	}
	pr("%s %s %s at %s.\n",
	   prland(&land),
	   (load_unload == UNLOAD) ?
	   "unloaded from" : "loaded onto",
	   prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
	loaded = 1;
    }
    *nshipsp += loaded;
    return 0;
}