Пример #1
0
/*
 *	readscr()		Subroutine to read a scroll one is carrying
 */
void readscr (void)
{
	int i;

	while (1) {
		if ((i = whatitem("read"))==ESC)  return;
		if (i != '.') {
			if (i=='*') 
				showread(); 
			else {
				if (iven[i-'a']==OSCROLL) { 
					read_scroll(ivenarg[i-'a']); 
					iven[i-'a']=0; 
					return; 
				}
				if (iven[i-'a']==OBOOK)   { 
					readbook(ivenarg[i-'a']);  
					iven[i-'a']=0; 
					return; 
				}
				if (iven[i-'a']==0) { 
					ydhi(i); 
					return; 
				}
			lprcat("\nThere's nothing on it to read.");  return;
			} /* end else */
		}
	}
}
Пример #2
0
/*
 *	subroutine to eat a cookie one is carrying
 */
void eatcookie (void)
{
    int i;
    char *p;

    while (1) {
	if ((i = whatitem("eat"))==ESC)  
		return;
	if (i != '.') {
	    if (i=='*') {
		showeat(); 
	    } else {
		if (iven[i-'a']==OCOOKIE) {
		    lprcat("\nThe cookie was delicious.");
		    iven[i-'a']=0;
		    if (!c[BLINDCOUNT]) {
			if ((p=fortune(fortfile))!=0) {
				lprcat("  Inside you find a scrap of paper that says:\n");
				lprcat(p);
			}
		    }
		    return;
		}
		if (iven[i-'a']==0) { ydhi(i); return; }
		lprcat("\nYou can't eat that!");  return;
	    }
	}
    }
}
Пример #3
0
/*
	function to drop an object
 */
static void
dropobj(void)
{
	int    i;
	unsigned char  *p;
	long            amt;
	p = &item[playerx][playery];
	while (1) {
		if ((i = whatitem("drop")) == '\33')
			return;
		if (i == '*')
			showstr();
		else {
			if (i == '.') {	/* drop some gold */
				if (*p) {
					lprcat("\nThere's something here already!");
					return;
				}
				lprcat("\n\n");
				cl_dn(1, 23);
				lprcat("How much gold do you drop? ");
				if ((amt = readnum((long) c[GOLD])) == 0)
					return;
				if (amt > c[GOLD]) {
					lprcat("\nYou don't have that much!");
					return;
				}
				if (amt <= 32767) {
					*p = OGOLDPILE;
					i = amt;
				} else if (amt <= 327670L) {
					*p = ODGOLD;
					i = amt / 10;
					amt = 10 * i;
				} else if (amt <= 3276700L) {
					*p = OMAXGOLD;
					i = amt / 100;
					amt = 100 * i;
				} else if (amt <= 32767000L) {
					*p = OKGOLD;
					i = amt / 1000;
					amt = 1000 * i;
				} else {
					*p = OKGOLD;
					i = 32767;
					amt = 32767000L;
				}
				c[GOLD] -= amt;
				lprintf("You drop %ld gold pieces", (long)amt);
				iarg[playerx][playery] = i;
				bottomgold();
				know[playerx][playery] = 0;
				dropflag = 1;
				return;
			}
			drop_object(i - 'a');
			return;
		}
	}
}
Пример #4
0
/*
 *	subroutine to quaff a potion one is carrying
 */
static void
quaff(void)
{
	int    i;
	while (1) {
		if ((i = whatitem("quaff")) == '\33')
			return;
		if (i != '.') {
			if (i == '*')
				showquaff();
			else {
				if (iven[i - 'a'] == OPOTION) {
					quaffpotion(ivenarg[i - 'a']);
					iven[i - 'a'] = 0;
					return;
				}
				if (iven[i - 'a'] == 0) {
					ydhi(i);
					return;
				}
				lprcat("\nYou wouldn't want to quaff that, would you? ");
				return;
			}
		}
	}
}
Пример #5
0
/*
	function to wield a weapon
 */
static void
wield(void)
{
	int    i;
	while (1) {
		if ((i = whatitem("wield")) == '\33')
			return;
		if (i != '.') {
			if (i == '*')
				showwield();
			else if (iven[i - 'a'] == 0) {
				ydhi(i);
				return;
			} else if (iven[i - 'a'] == OPOTION) {
				ycwi(i);
				return;
			} else if (iven[i - 'a'] == OSCROLL) {
				ycwi(i);
				return;
			} else if ((c[SHIELD] != -1) && (iven[i - 'a'] == O2SWORD)) {
				lprcat("\nBut one arm is busy with your shield!");
				return;
			} else {
				c[WIELD] = i - 'a';
				if (iven[i - 'a'] == OLANCE)
					c[LANCEDEATH] = 1;
				else
					c[LANCEDEATH] = 0;
				bottomline();
				return;
			}
		}
	}
}
Пример #6
0
/*
    function to wear armor
 */
static void wear(void)
{
	int i;
	
    while (1)
        {
        if ((i = whatitem("wear"))=='\33')
            return;
        if (i != '.' && i != '-')
            {
            if (i=='*')
                {
                i = showwear();
                cursors();
                }
            if (i && i != '.')
                switch(iven[i-'a'])
                    {
                    case 0:
                        ydhi(i);
                        return;
                    case OLEATHER:  case OCHAIN:  case OPLATE:
                    case ORING:     case OSPLINT: case OPLATEARMOR:
                    case OSTUDLEATHER:            case OSSPLATE:
                        if (c[WEAR] != -1) { lprcat("\nYou're already wearing some armor"); return; }
                            c[WEAR]=i-'a';  bottomline(); return;
                    case OSHIELD:   if (c[SHIELD] != -1) { lprcat("\nYou are already wearing a shield"); return; }
                                if (iven[c[WIELD]]==O2SWORD) { lprcat("\nYour hands are busy with the two handed sword!"); return; }
                                c[SHIELD] = i-'a';  bottomline(); return;
                    default:    lprcat("\nYou can't wear that!");
                    };
            }
        }
}
Пример #7
0
/*
 * threshold <COMM> <SECTS> <THRESH>
 */
int
thre(void)
{
    struct sctstr sect;
    struct nstr_sect nstr;
    int val;
    struct ichrstr *ip;
    char *p;
    int thresh;
    i_type type;
    char prompt[128];
    char buf[128];

    if (!(ip = whatitem(player->argp[1], "What commodity? ")))
	return RET_SYN;
    if (!snxtsct(&nstr, player->argp[2]))
	return RET_SYN;
    type = ip->i_uid;
    while (nxtsct(&nstr, &sect)) {
	if (!player->owner)
	    continue;
	val = sect.sct_dist[type];
	if (val > 0)
	    sprintf(prompt, "%s %s  old threshold %d new? ",
		    xyas(nstr.x, nstr.y, player->cnum),
		    dchr[sect.sct_type].d_name, val);
	else
	    sprintf(prompt, "%s %s  threshold? ",
		    xyas(nstr.x, nstr.y, player->cnum),
		    dchr[sect.sct_type].d_name);
	if (!(p = getstarg(player->argp[3], prompt, buf)))
	    return RET_FAIL;
	if (!*p)
	    continue;
	if (!check_sect_ok(&sect))
	    return RET_FAIL;
	thresh = atoi(p);
	if (thresh < 0)
	    return RET_FAIL;
	if (thresh > ITEM_MAX)
	    thresh = ITEM_MAX;
	if ((val > 0) && (val == thresh)) {
	    pr("%s threshold unchanged (left at %d)\n",
	       xyas(nstr.x, nstr.y, player->cnum), val);
	    continue;
	}
	if (val > 0 && player->argp[3] && *player->argp[3])
	    pr("%s old threshold %d\n",
	       xyas(nstr.x, nstr.y, player->cnum), val);
	sect.sct_dist[type] = thresh;
	putsect(&sect);
    }
    return RET_OK;
}
Пример #8
0
/*
	function to wield a weapon
 */
void wield (void)	
{
	int i;

	while (1) {
		if ((i = whatitem("wield"))==ESC)  return;
		if (i != '.') {
			if (i=='*') showwield();
			else if (i=='-') {
				c[WIELD]=-1;
				lprcat("\nYou unwield your weapon.");
				bottomline();
				return;
			}
			else if (iven[i-'a']==0) { ydhi(i); return; }
			else if (iven[i-'a']==OPOTION) { ycwi(i); return; }
			else if (iven[i-'a']==OSCROLL) { ycwi(i); return; }
			else if ((c[SHIELD]!= -1) && (iven[i-'a']==O2SWORD)) {
				lprcat("\nBut one arm is busy with your shield!");
				return; 
			}
			else if (i-'a'==c[WEAR] || i-'a'==c[SHIELD]) {
				lprintf("\nYou can't wield your %s while you're wearing it!",
						(i-'a'==c[WEAR]) ? "armor" : "shield");
				return;
			}
			else  {
				c[WIELD]=i-'a';
				lprintf("\nYou wield %s", objectname[iven[i-'a']]);
				if (ivenarg[i-'a']>0) lprintf (" +%d", (long)ivenarg[i-'a']);
				if (ivenarg[i-'a']<0) lprintf (" %d", (long)ivenarg[i-'a']);
				lprc('.');
				if (iven[i-'a'] == OLANCE) c[LANCEDEATH]=1; 
				else c[LANCEDEATH]=0;  
				bottomline();
				return; 
			}
		}
	}
}
Пример #9
0
/*
	function to drop an object
 */
void dropobj (void)
{
	int i, pitflag=0;
	char *p;
	long amt;

	p = &item[playerx][playery];
	while (1) {
		if ((i = whatitem("drop"))==ESC)  
			return;
		if (i=='*') 
			showstr(); 
		else {
			/* drop some gold */
			if (i=='.')	{
				if (*p == OPIT) pitflag=1;
				if (*p && !pitflag) { 
				lprcat("\nThere's something here already!"); 
						return; 
				}
				lprcat("\n\n");
				cl_dn(1,23);
				lprcat("How much gold do you drop? ");
				if ((amt=readnum((long)c[GOLD])) <= 0) return;
				if (amt>c[GOLD]) { 
					lprcat("\nYou don't have that much!"); 
					return; 
				}
				if (amt<=32767) { 
					*p=OGOLDPILE; 
					i=(int)amt; 
				}
				else if (amt<=327670L) { 
					*p=ODGOLD; 
					i=(int)amt/10; 
					amt = 10L*i; 
				}
				else if (amt<=3276700L) { 
					*p=OMAXGOLD; 
					i=(int)amt/100; 
					amt = 100L*i; 
				}
				else if (amt<=32767000L) { 
					*p=OKGOLD; 
					i=(int)amt/1000; 
					amt = 1000L*i; 
				}
				else { 
					*p=OKGOLD; 
					i=(int)32767; 
					amt = 32767000L; 
				}
				c[GOLD] -= amt; 
				lprintf("You drop %d gold piece%s.",(long)amt,(amt==1)?"":"s");
				if (pitflag) {
					*p = OPIT;
					lprcat("\nThe gold disappears down the pit.");
				} else
					iarg[playerx][playery]=i; 
				bottomgold();
				know[playerx][playery]=0; 
				dropflag=1;  
				return;
			}
			drop_object(i-'a');
			return;
		}
	}
}
Пример #10
0
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;
}
Пример #11
0
static void consume(int search_item, char *prompt, int (*showfunc)())
{
	int i;

    while (1)
        {
        if ((i = whatitem( prompt )) == '\33')
            return;
        if (i != '.' && i != '-')
            {
            if (i == '*')
                {
                i = showfunc();
                cursors();
                }
            if (i && i != '.')
                {
                switch (iven[i-'a'])
                    {
                    case OSCROLL:
                        if ( search_item != OSCROLL )
                            {
                            lprintf("\nYou can't %s that.", prompt );
                            return;
                            }
                        read_scroll( ivenarg[i-'a'] );
                        break;
                    case OBOOK:
                        if ( search_item != OSCROLL )
                            {
                            lprintf("\nYou can't %s that.", prompt );
                            return;
                            }
                        readbook( ivenarg[i-'a'] );
                        break;
                    case OCOOKIE:
                        if ( search_item != OCOOKIE )
                            {
                            lprintf("\nYou can't %s that.", prompt );
                            return;
                            }
                        outfortune();
                        break;
                    case OPOTION:
                        if ( search_item != OPOTION )
                            {
                            lprintf("\nYou can't %s that.", prompt );
                            return;
                            }
                        quaffpotion( ivenarg[i-'a'], TRUE );
                        break;
                    case 0:
                        ydhi(i);
                        return;
                    default:
                        lprintf("\nYou can't %s that.", prompt );
                        return;
                    }
                iven[i-'a'] = 0;
                return;
                }
            }
        }
}
Пример #12
0
int
fly(void)
{
    coord tx, ty;
    coord ax, ay;
    int ap_to_target;
    struct ichrstr *ip;
    char flightpath[MAX_PATH_LEN];
    int cno;
    struct nstr_item ni_bomb;
    struct nstr_item ni_esc;
    union empobj_storage target;
    struct emp_qelem bomb_list;
    struct emp_qelem esc_list;
    int wantflags;
    struct sctstr ap_sect;
    char buf[1024];

    wantflags = 0;
    if (get_planes(&ni_bomb, &ni_esc, player->argp[1], player->argp[2]) < 0)
	return RET_SYN;
    if (!get_assembly_point(player->argp[3], &ap_sect, buf))
	return RET_SYN;
    ax = ap_sect.sct_x;
    ay = ap_sect.sct_y;
    if (!getpath(flightpath, player->argp[4], ax, ay, 0, 0, MOB_FLY))
	return RET_SYN;
    tx = ax;
    ty = ay;
    (void)pathtoxy(flightpath, &tx, &ty, fcost);
    pr("Ending sector is %s\n", xyas(tx, ty, player->cnum));
    ip = whatitem(player->argp[5], "transport what? ");
    if (player->aborted)
	return RET_SYN;

    if (pln_where_to_land(tx, ty, &target, &wantflags) < 0)
	return RET_SYN;
    cno = target.gen.ef_type == EF_SHIP ? target.gen.uid : -1;

    if (ip && ip->i_uid == I_CIVIL) {
	if (target.gen.own != player->cnum) {
	    pr("Your civilians refuse to board a flight abroad!\n");
	    return RET_FAIL;
	}
	if (target.gen.ef_type == EF_SECTOR
	    && target.sect.sct_own != target.sect.sct_oldown) {
	    pr("Can't fly civilians into occupied sectors.\n");
	    return RET_FAIL;
	}
    }

    ap_to_target = strlen(flightpath);
    pr("range to target is %d\n", ap_to_target);
    /*
     * select planes within range
     */
    pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target, 1,
	    wantflags, P_M | P_O);
    pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target, 1,
	    wantflags | P_ESC | P_F, P_M | P_O);
    if (cno >= 0
	&& !pln_can_land_on_carrier(&bomb_list, &esc_list, &target.ship)) {
	pr("Not enough room on ship #%d!\n", cno);
	return RET_FAIL;
    }
    /*
     * now arm and equip the bombers, transports, whatever.
     */
    pln_arm(&bomb_list, ap_to_target, 't', ip);
    if (QEMPTY(&bomb_list)) {
	pr("No planes could be equipped for the mission.\n");
	return RET_FAIL;
    }
    pln_arm(&esc_list, ap_to_target, 'e', NULL);
    ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, 0);
    if (QEMPTY(&bomb_list)) {
	pr("No planes got through fighter defenses\n");
    } else {
	pln_dropoff(&bomb_list, ip, tx, ty, cno);
	pln_newlanding(&bomb_list, tx, ty, cno);
	pln_newlanding(&esc_list, tx, ty, cno);
    }
    pln_put(&bomb_list);
    pln_put(&esc_list);
    return RET_OK;
}
Пример #13
0
/*
 * function to wield a weapon
 */
static void wield(void)
{
	int i;

	while (TRUE) {
		
		i = whatitem("wield (- for nothing)");
		if (i == '\33') return;
		
		
		if (i != '.') {
            
			if (i == '*') {
				
				i = showwield();
				cursors();
			}
		
			if ( i == '-' ) {
				
				c[WIELD] = -1 ;
				bottomline();
				
				return;
			}
			
			if (!i || i == '.') {
		
				continue;
			}

			if (iven[i-'a']==0) { 
					
				ydhi(i);
				return;
					
			} else if (iven[i - 'a'] == OPOTION) { 
					
				ycwi(i); 
				return;
					
			} else if (iven[i-'a'] == OSCROLL) {
					
				ycwi(i);
				return;
					
			} else if (c[SHIELD] != -1 &&
				iven[i-'a'] == O2SWORD) {
						
				lprcat("\nBut one arm is busy with your shield!");
				return;
						
			} else {
			
				c[WIELD]= i - 'a';
					
				if (iven[i - 'a'] == OLANCE) {
						
					c[LANCEDEATH]=1;
						
				} else {
						
					c[LANCEDEATH]=0;
				}
					
				bottomline();
				return;
			}
		}
	}
}
Пример #14
0
int
rout(void)
{
    struct ichrstr *ip;
    struct nstr_sect ns;
    struct natstr *natp;
    struct sctstr sect;
    struct nscstr cond[NS_NCOND];
    int ncond;
    struct range relrange;
    int row;
    int y;
    int ry;
    i_type i_del;
    int dir;
    char *p;
    /* Note this is not re-entrant anyway, so we keep the buffers
       around */
    static char *mapbuf = NULL;
    static char **map = NULL;
    int i;

    if (!(ip = whatitem(player->argp[1], "What item? ")))
	return RET_SYN;
    i_del = ip->i_uid;;
    if (!snxtsct(&ns, player->argp[2]))
	return RET_SYN;
    if (!mapbuf)
	mapbuf = malloc(WORLD_Y * MAPWIDTH(3));
    if (!map) {
	map = malloc(WORLD_Y * sizeof(char *));
	if (map && mapbuf) {
	    for (i = 0; i < WORLD_Y; i++)
		map[i] = &mapbuf[MAPWIDTH(3) * i];
	} else if (map) {
	    free(map);
	    map = NULL;
	}
    }
    if (!mapbuf || !map) {
	pr("Memory error, tell the deity.\n");
	logerror("malloc failed in rout\n");
	return RET_FAIL;
    }
    ncond = ns.ncond;
    memcpy(cond, ns.cond, sizeof(struct nscstr) * ncond);
    ns.ncond = 0;

    natp = getnatp(player->cnum);
    xyrelrange(natp, &ns.range, &relrange);
    blankfill(mapbuf, &ns.range, 3);
    border(&relrange, "     ", " ");

    while (nxtsct(&ns, &sect)) {
	if (!player->owner)
	    continue;
	p = &map[ns.dy][ns.dx * 2];
	dir = sect.sct_del[i_del] & 0x7;
	if (dir && nstr_exec(cond, ncond, &sect))
	    memcpy(p, routech[dir], 3);
	p[1] = dchr[sect.sct_type].d_mnem;
    }
    for (row = 0, y = ns.range.ly; row < ns.range.height; y++, row++) {
	ry = yrel(natp, y);
	pr("%4d %s %-4d\n", ry, map[row], ry);
	if (y >= WORLD_Y)
	    y -= WORLD_Y;
    }
    border(&relrange, "     ", " ");
    return RET_OK;
}
Пример #15
0
/*
 * format: buy <COMMODITY>
 *
 */
int
buy(void)
{
    struct sctstr sect;
    struct natstr *natp;
    struct comstr comm;
    struct comstr comt;
    struct trdstr tmpt;
    struct ichrstr *ip;
    int qty;
    int o, n;
    coord x, y;
    char *p;
    float bid;
    time_t now;
    double tally;
    double canspend;
    char buf[1024];

    if (!opt_MARKET) {
	pr("The market is disabled.\n");
	return RET_FAIL;
    }
    natp = getnatp(player->cnum);
    ip = whatitem(player->argp[1], "Commodity you want to buy: ");
    if (!ip)
	return RET_SYN;
    display_mark(ip->i_uid, 0);
    pr("\n");
    p = getstarg(player->argp[2], "Which lot are you bidding on: ", buf);
    if (!p)
	return RET_SYN;
    if (*p == 0)
	return RET_SYN;
    o = atoi(p);
    if (o < 0)
	return RET_SYN;
    if (!getcomm(o, &comm) || comm.com_owner == 0) {
	pr("Invalid lot number.\n");
	return RET_OK;
    }
    if (comm.com_type != ip->i_uid) {
	pr("That lot is not of the type you specified.\n");
	return RET_OK;
    }
    if (comm.com_owner == player->cnum) {
	pr("You can't bid on your own lot.\n");
	return RET_OK;
    }
    if (!(p = getstarg(player->argp[3], "How much per unit: ", buf)))
	return RET_SYN;
    bid = atof(p);
    if (bid <= 0)
	return RET_FAIL;
    if (natp->nat_money < bid * comm.com_amount * buytax) {
	pr("This purchase would cost %.2f, %.2f more than you have.\n",
	   bid * comm.com_amount * buytax,
	   bid * comm.com_amount * buytax - natp->nat_money);
	return RET_FAIL;
    }
/*  check to see if all of the bids that this player has out plus this new bid
    would make him go broke.  Ken, I ought to skin you alive for making me code
    this part up.*/
    tally = 0.0;
    for (n = 0; gettrade(n, &tmpt); n++) {
	if (tmpt.trd_maxbidder == player->cnum &&
	    tmpt.trd_unitid >= 0 && tmpt.trd_owner != player->cnum) {
	    tally += tmpt.trd_price * tradetax;
	}
    }
    for (n = 0; getcomm(n, &comt); n++) {
	if (comt.com_maxbidder == player->cnum &&
	    comt.com_owner != 0 && comt.com_owner != player->cnum) {
	    tally += comt.com_price * comt.com_amount * buytax;
	}
    }
    canspend = natp->nat_money - tally;
    check_comm_ok(&comm);
    if (bid * comm.com_amount * buytax > canspend) {
	pr("You have overextended yourself in the market\n");
	pr("You can not bid on the current items at that price.\n");
	return RET_OK;
    }
    if (!(p = getstarg(player->argp[4], "destination sector : ", buf)))
	return RET_SYN;
    if (!sarg_xy(p, &x, &y))
	return RET_SYN;
    if (!getsect(x, y, &sect)) {
	pr("Could not access sector");
	return RET_FAIL;
    }
    if ((sect.sct_type != SCT_WAREH && sect.sct_type != SCT_HARBR) ||
	sect.sct_own != player->cnum) {
	pr("The destination sector is not one of your warehouses.\n");
	return RET_FAIL;
    }
    if (sect.sct_effic < 60) {
	pr("That sector is under construction.\n");
	return RET_FAIL;
    }
    n = sect.sct_item[ip->i_uid];
    qty = comm.com_amount;
    if (qty + n > ITEM_MAX) {
	pr("That sector cannot hold %d more %s. It currently holds %d.\n",
	   qty, ip->i_name, n);
	return RET_FAIL;
    }
    if (bid * comm.com_amount > natp->nat_money) {
	pr("You don't have that much to spend!\n");
	return RET_FAIL;
    }
    if (!check_comm_ok(&comm))
	return RET_FAIL;
    if (bid > 0.04 + comm.com_price) {
	comm.com_price = bid;
	time(&now);
	if (comm.com_markettime + MARK_DELAY - now < minutes(5) &&
	    comm.com_maxbidder != player->cnum)
	    comm.com_markettime = now + minutes(5) - MARK_DELAY;
	comm.com_maxbidder = player->cnum;
	comm.com_x = x;
	comm.com_y = y;
	putcomm(o, &comm);
	pr("Your bid is being considered.\n");
    } else {
	pr("Your bid wasn't high enough (you need to bid at least $0.05 higher\n");
	pr("than the last bid.\n");
	return RET_OK;
    }

    check_market();

    return RET_OK;
}
Пример #16
0
/*
	function to wear armor
 */
void wear (void)
{
	int i;

	while (1) {
		if ((i = whatitem("wear"))==ESC)  return;
		if (i != '.') {
			if (i=='*') showwear(); else
			switch(iven[i-'a']) {
				case 0:  
					ydhi(i); 
					return;
				case OLEATHER:  
				case OCHAIN:  
				case OPLATE:	
				case OSTUDLEATHER:
				case ORING:		
				case OSPLINT:	
				case OPLATEARMOR:	
				case OELVENCHAIN:
				case OSSPLATE:
					if (c[WEAR] != -1) { 
						lprcat("\nYou are already wearing some armor.");
				    	return; 
					}
					c[WEAR]=i-'a';
					if (c[WIELD] == i-'a') c[WIELD] = -1;
					lprintf("\nYou put on your %s", objectname[iven[i-'a']]);
					if (ivenarg[i-'a']>0)
						lprintf (" +%d", (long)ivenarg[i-'a']);
					if (ivenarg[i-'a']<0)
						lprintf (" %d", (long)ivenarg[i-'a']);
					lprc('.');
					bottomline(); 
					return;

				case OSHIELD:	
					if (c[SHIELD] != -1) { 
						lprcat("\nYou are already wearing a shield.");
						return; 
					}
					if (iven[c[WIELD]]==O2SWORD) {
						lprcat("\nYour hands are busy with the two handed "
							   "sword!");
						return; 
					}
					c[SHIELD] = i-'a';
					if (c[WIELD] == i-'a') c[WIELD] = -1;
					lprcat("\nYou put on your shield");
					if (ivenarg[i-'a']>0)
						lprintf (" +%d", (long)ivenarg[i-'a']);
					if (ivenarg[i-'a']<0) 
						lprintf (" %d", (long)ivenarg[i-'a']);
					lprc('.');
					bottomline(); 
					return;

			   default: lprcat("\nYou can't wear that!");
			};
		}
	}
}
Пример #17
0
int
drop(void)
{
    coord tx, ty;
    coord ax, ay;
    int ap_to_target;
    struct ichrstr *ip;
    char flightpath[MAX_PATH_LEN];
    struct nstr_item ni_bomb;
    struct nstr_item ni_esc;
    struct sctstr target;
    struct emp_qelem bomb_list;
    struct emp_qelem esc_list;
    int wantflags;
    struct sctstr ap_sect;
    char buf[1024];

    if (get_planes(&ni_bomb, &ni_esc, player->argp[1], player->argp[2]) < 0)
	return RET_SYN;
    if (!get_assembly_point(player->argp[3], &ap_sect, buf))
	return RET_SYN;
    ax = ap_sect.sct_x;
    ay = ap_sect.sct_y;
    if (!getpath(flightpath, player->argp[4], ax, ay, 0, 0, MOB_FLY))
	return RET_SYN;
    tx = ax;
    ty = ay;
    (void)pathtoxy(flightpath, &tx, &ty, fcost);
    pr("target is %s\n", xyas(tx, ty, player->cnum));
    if (!(ip = whatitem(player->argp[5], "Drop off what? ")))
	return RET_SYN;
    getsect(tx, ty, &target);

    if (relations_with(target.sct_own, player->cnum) == ALLIED) {
	/* own or allied sector: cargo drop */
	if (ip->i_uid == I_CIVIL) {
	    if (target.sct_own != player->cnum) {
		pr("Your civilians refuse to board a flight abroad!\n");
		return RET_FAIL;
	    }
	    if (target.sct_own != target.sct_oldown) {
		pr("Can't drop civilians into occupied sectors.\n");
		return RET_FAIL;
	    }
	}
	wantflags = P_C;
    } else {
	/* into the unknown... */
	if (ip->i_uid != I_SHELL) {
	    pr("You don't own %s!\n", xyas(tx, ty, player->cnum));
	    return RET_FAIL;
	}
	/* mine drop */
	wantflags = P_MINE;
    }

    ap_to_target = strlen(flightpath);
    if (flightpath[ap_to_target - 1] == 'h')
	ap_to_target--;
    pr("range to target is %d\n", ap_to_target);
    /*
     * select planes within range
     */
    pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target, 2,
	    wantflags, P_M | P_O);
    pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target, 2,
	    P_ESC | P_F, P_M | P_O);
    /*
     * now arm and equip the bombers, transports, whatever.
     */
    pln_arm(&bomb_list, 2 * ap_to_target,
	    wantflags & P_MINE ? 'm' : 'd',
	    ip);
    if (QEMPTY(&bomb_list)) {
	pr("No planes could be equipped for the mission.\n");
	return RET_FAIL;
    }
    pln_arm(&esc_list, 2 * ap_to_target, 'e', NULL);
    ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, 0);
    if (QEMPTY(&bomb_list)) {
	pr("No planes got through fighter defenses\n");
    } else {
	if (wantflags & P_MINE)
	    pln_mine(&bomb_list, tx, ty);
	else
	    pln_dropoff(&bomb_list, ip, tx, ty, -1);
    }
    pln_put(&bomb_list);
    pln_put(&esc_list);
    return RET_OK;
}