Exemple #1
0
void
trade()
{
	int	tradee, i;

	trading = TRUE;
	for (i = 0; i < 2; i++) {
		trades[i].cash = 0;
		trades[i].gojf = FALSE;
		trades[i].prop_list = NULL;
	}
over:
	if (num_play == 1) {
		printf("There ain't no-one around to trade WITH!!\n");
		return;
	}
	if (num_play > 2) {
		tradee = getinp("Which player do you wish to trade with? ",
		    name_list);
		if (tradee == num_play)
			return;
		if (tradee == player) {
			printf("You can't trade with yourself!\n");
			goto over;
		}
	}
	else
		tradee = 1 - player;
	get_list(0, player);
	get_list(1, tradee);
	if (getyn("Do you wish a summary? ") == 0)
		summate();
	if (getyn("Is the trade ok? ") == 0)
		do_trade();
}
Exemple #2
0
/*
 *	Check to see if more games are desired.  If not, and game
 * came from a saved file, make sure that they don't want to restore
 * it.  Exit appropriately.
 */
void
check_more(void)
{
	On_exit = TRUE;
	if (Player[PLAYER].total >= 5000 || Player[COMP].total >= 5000)
		if (getyn(ANOTHERGAMEPROMPT))
			return;
		else {
			/*
			 * must do accounting normally done in main()
			 */
			if (Player[PLAYER].total > Player[COMP].total)
				Player[PLAYER].games++;
			else if (Player[PLAYER].total < Player[COMP].total)
				Player[COMP].games++;
			Player[COMP].total = 0;
			Player[PLAYER].total = 0;
		}
	else
		if (getyn(ANOTHERHANDPROMPT))
			return;
	if (!Saved && getyn(SAVEGAMEPROMPT))
		if (!save())
			return;
	die(0);
}
Exemple #3
0
void
user_dir_army (piece_info_t *obj, long loc)
{
	int enemy_killed;

	enemy_killed = FALSE;

	if (user_map[loc].contents == 'O') /* attacking own city */
		move_army_to_city (obj, loc);

	else if (user_map[loc].contents == 'T') /* transport full? */
		fatal (obj, loc,
	"Sorry, sir.  There is no more room on the transport.  Do you insist? ",
	"Your army jumped into the briny and drowned.");

	else if (map[loc].contents == '.') { /* going for a swim? */
		if (!getyn ( /* thanks to Craig Hansen for this next message */
	"Troops can't walk on water, sir.  Do you really want to go to sea? "))
		return;

		if (user_map[obj->loc].contents == 'T')
			info("Your army jumped into the briny and drowned.");

		else if (user_map[loc].contents == '.')
			info("Your army marched dutifully into the sea and drowned.");

		else { /* attack something at sea */
			enemy_killed = islower (user_map[loc].contents);
			attack (obj, loc);

			if (obj->hits > 0) /* ship won? */
			info("Your army regretfully drowns after its successful assault.");
		}
		if (obj->hits > 0) {
			kill_obj (obj, loc);
			if (enemy_killed) scan (comp_map, loc);
		}
	}

	else if (isupper (user_map[loc].contents)
		&& user_map[loc].contents != 'X') { /* attacking self */
		if (!getyn (
	"Sir, those are our men!  Do you really want to attack them? "))
		return;

		attack (obj, loc);
	}

	else attack (obj, loc);
}
Exemple #4
0
int
mkdirp(char *dirp, uid_t uid, gid_t gid)
{
    if (mkdir(dirp, 0755) == -1) {
        if (errno != EEXIST) {
            fprintf(stderr, "Cannot create directory '%s':%s\n",
                    dirp, strerror(errno));
            return -1;
        }
        if (getdef_bool("DUPDIROK")) {
            fprintf(stderr, "\n*** WARNING ***\n\n%s already exists. If it is being used by another user as a home\n"
                    "directory problems could result.\n\n", dirp);
            fprintf(stderr, "Ownership of %s will be changed to match the new user's.\n\n", dirp);
            if (!getyn("Use directory %s anyway? (y/N) ", dirp))
                return -1;
        } else {
            fprintf(stderr, "Directory %s already exists!\n", dirp);
            fprintf(stderr, "You are not permitted to share directories amongst users\n");
            return -1;
        }
    }
    if (chown(dirp, uid, gid) == -1) {
        fprintf(stderr, "cannot change access to home directory\n");
        rmdir(dirp);
        return -1;
    }
    return 0;
}
Exemple #5
0
/*
 *	This routine is the command level response the mortgage command.
 * it gets the list of mortgageable property and asks which are to
 * be mortgaged.
 */
mortgage() {

	reg int	prop;

	for (;;) {
		if (set_mlist() == 0) {
			if (got_houses)
				printf("You can't mortgage property with houses on it.\n");
			else
				printf("You don't have any un-mortgaged property.\n");
			return;
		}
		if (num_good == 1) {
			printf("Your only mortageable property is %s\n",names[0]);
			if (getyn("Do you want to mortgage it? ") == 0)
				m(square[0]);
			return;
		}
		prop = getinp("Which property do you want to mortgage? ",names);
		if (prop == num_good)
			return;
		m(square[prop]);
		notify(cur_p);
	}
}
Exemple #6
0
void
user_dir_ship (piece_info_t *obj, long loc)
{
	int enemy_killed;

	enemy_killed = FALSE;

	if (map[loc].contents == '*') {
		snprintf (jnkbuf, STRSIZE, "Your %s broke up on shore.",
				piece_attr[obj->type].name);

		fatal (obj, loc,
	"That's never worked before, sir.  Do you really want to try? ",
			jnkbuf);
	}

	else if (map[loc].contents == '+') { /* moving ashore? */
		if (!getyn (
	"Ships need sea to float, sir.  Do you really want to go ashore? "))
		return;

		if (user_map[loc].contents == '+')
			info("Your %s broke up on shore.", piece_attr[obj->type].name);

		else { /* attack something on shore */
			enemy_killed = islower (user_map[loc].contents);
			attack (obj, loc);

			if (obj->hits > 0) /* ship won? */
				info("Your %s breaks up after its successful assault.", piece_attr[obj->type].name);
		}
		if (obj->hits > 0) {
			kill_obj (obj, loc);
			if (enemy_killed) scan (comp_map, loc);
		}
	}

	else if (isupper (user_map[loc].contents)) { /* attacking self */
		if (!getyn (
	"Sir, those are our men!  Do you really want to attack them? "))
		return;

		attack (obj, loc);
	}

	else attack (obj, loc);
}
Exemple #7
0
static int floor_consume(int search_item, char *cons_verb)
{
	int i;
	char tempc;

    cursors();
    i = item[playerx][playery];

    /* item not there, quit
    */
    if (i != search_item)
        return( 0 );

    /* item there.  does the player want to consume it?
    */
    lprintf("\nThere is %s", objectname[i] );
    if (i==OSCROLL)
        if (scrollname[iarg[playerx][playery]][0])
            lprintf(" of%s", scrollname[iarg[playerx][playery]]);
    if (i==OPOTION)
        if (potionname[iarg[playerx][playery]][0])
            lprintf(" of%s", potionname[iarg[playerx][playery]]);
    lprintf(" here.  Do you want to %s it?", cons_verb );

    if ((tempc = getyn()) == 'n' )
        return( 0 );                /* item there, not consumed */
    else if (tempc != 'y')
        {
        lprcat(" aborted");
        return( -1 );               /* abort */
        }

    /* consume the item.
    */
    switch( i )
        {
        case OCOOKIE:
            outfortune();
            forget();
            break;
        case OBOOK:
            readbook( iarg[playerx][playery] );
            forget();
            break;
        case OPOTION:
            quaffpotion(iarg[playerx][playery], 1);
            forget();
            break;
        case OSCROLL:
            /* scrolls are tricky because of teleport.
            */
            i = iarg[playerx][playery];
            know[playerx][playery] = 0;
            item[playerx][playery] = iarg[playerx][playery] = 0 ;
            read_scroll( i );
            break;
        }
    return( 1 );
}
Exemple #8
0
void
fatal (piece_info_t *obj, long loc, char *message, char *response)
{
	if (getyn (message)) {
		info(response);
		kill_obj (obj, loc);
	}
}
Exemple #9
0
/*
 *	Routine to trap rubouts, and make sure they really want to
 * quit.
 */
void
rub(int sig __unused)
{
	signal(SIGINT, SIG_IGN);
	if (getyn(REALLYPROMPT))
		die(0);
	signal(SIGINT, rub);
}
Exemple #10
0
void ahelpkey()

{
	int 	x,i,lgscr,page;
	byte	ch;

	if (vstate(0)==4) smallscr(NO);
	
	if (equipment(0)==7) {
				page =0;	
				smallscr(NO);
				}
		else	     {
				page =3;
				}

	vpage(page);
	crttim=0;
	lgscr = (tvmaxc==39) ? TRUE:FALSE;

	for (i=0; i<10; ++i) {

		helptop(page);		
		for (x=0;;++x) {
			ch=*(helpkey[i]+x);
			if (ch==0) break;
			if (ch=='_') {
				if (lgscr) rprints(foreg,page,"\n \t \t  ");
				else rputcinc(' ',0,foreg,NO,page);
				}
			else  rputcinc(ch,0,foreg,NO,page);

			if ((ch==LF) && (lgscr)) putch(LF);   /* 2nd LF */
				
		}

		curset(23,5,page);
		if (i<9) {
				rprints(foreg,page,"Do you want the next page (Y/N) ? ");
				x=getyn();
				if (x==NO) break;
				}
		else 	{
			       	rprints(foreg,page,"Hit any key to return  ");
				getkey();
				}
		}

	bright;			/* Restore page 0 */

	if (page==0) {
			if (SMALLMSK(maskp)) smallscr(NO);
			else largescr(NO);
			
			dspmsk();
			}
}
Exemple #11
0
int
check_ext(bool forcomp)
{


	if (End == 700)
		if (Play == PLAYER) {
			if (getyn(EXTENSIONPROMPT)) {
extend:
				if (!forcomp)
					End = 1000;
				return TRUE;
			}
			else {
done:
				if (!forcomp)
					Finished = TRUE;
				return FALSE;
			}
		}
		else {
			PLAY	*pp, *op;
			int	i, safe, miles;

			pp = &Player[COMP];
			op = &Player[PLAYER];
			for (safe = 0, i = 0; i < NUMSAFE; i++)
				if (pp->safety[i] != S_UNKNOWN)
					safe++;
			if (safe < 2)
				goto done;
			if (op->mileage == 0 || onecard(op)
			    || (op->can_go && op->mileage >= 500))
				goto done;
			for (miles = 0, i = 0; i < NUMSAFE; i++)
				if (op->safety[i] != S_PLAYED
				    && pp->safety[i] == S_UNKNOWN)
					miles++;
			if (miles + safe == NUMSAFE)
				goto extend;
			for (miles = 0, i = 0; i < HAND_SZ; i++)
				if ((safe = pp->hand[i]) <= C_200)
					miles += Value[safe]; 
			if (miles + (Topcard - Deck) * 3 > 1000)
				goto extend;
			goto done;
		}
	else
		goto done;
}
Exemple #12
0
/*
 * volume-del <device> <filesystem>
 */
void
hammer_cmd_volume_del(char **av, int ac)
{
	struct hammer_ioc_volume ioc;
	int fd, error, retried = 0;
	const char *device, *filesystem;

	if (ac != 2) {
		fprintf(stderr, "hammer volume-del <device> <filesystem>\n");
		exit(1);
	}

	device = av[0];
	filesystem = av[1];

        fd = open(filesystem, O_RDONLY);
	if (fd < 0) {
		fprintf(stderr, "hammer volume-del: unable to access %s: %s\n",
			filesystem, strerror(errno));
		exit(1);
	}

	/*
	 * volume-del ioctl
	 */
	bzero(&ioc, sizeof(ioc));
	strncpy(ioc.device_name, device, MAXPATHLEN);
	if (ForceOpt)
		ioc.flag |= HAMMER_IOC_VOLUME_REBLOCK;
retry:
	if (ioctl(fd, HAMMERIOC_DEL_VOLUME, &ioc) < 0) {
		error = errno;
		if ((error == ENOTEMPTY) && (retried++ == 0)) {
			printf("%s is not empty, ", device);
			printf("do you want to reblock %s? [y/n] ", device);
			fflush(stdout);
			if (getyn() == 1) {
				ioc.flag |= HAMMER_IOC_VOLUME_REBLOCK;
				goto retry;
			}
		}
		fprintf(stderr, "hammer volume-del ioctl: %s\n",
			strerror(error));
		exit(1);
	}

	close(fd);
	hammer_cmd_volume_list(av + 1, ac - 1);
}
Exemple #13
0
void
user_dir_fighter (piece_info_t *obj, long loc)
{
	if (map[loc].contents == '*')
		fatal (obj, loc,
	"That's never worked before, sir.  Do you really want to try? ",
	"Your fighter was shot down.");

	else if (isupper (user_map[loc].contents)) {
		if (!getyn (
	"Sir, those are our men!  Do you really want to attack them? "))
		return;

		attack (obj, loc);
	}

	else attack (obj, loc);
}
Exemple #14
0
void main(int argc,char *argv[])
{
    char *basedir, *p;
    FILEFINDBUF3 find; HDIR dirhandle; ULONG srch_cnt;
    int newdrive, urdrive, rootdir, dotdir, dotdotdir;
    int asking=TRUE, retcode=TRUE;

    while (--argc)  {
	++argv;
	if ((argv[0][0] == '/') || (argv[0][0] == '-')) {
	    switch(toupper(argv[0][1])) {
		case 'Y': asking = FALSE; break;

#ifdef __OS2__
		case 'F': forcedel = 1; break;
#endif
		default : printf("Invalid switch - %c\n", argv[0][1]); abort();
		}
	    }
	else
	    break;
	}
    if (!argc) {
	puts("DELTREE2 v1.0\nRequired parameter missing");
	abort();
	}
    urdrive = getdisk();
#ifdef __OS2__
    DosError(FERR_DISABLEHARDERR);
#endif

    /* Process each command line parameter */
    while (argc--) {
	basedir = *argv++;
	if (asking) {
	    printf("Delete directory \"%s\" and all its subdirectories? [yn] ",
		   basedir);
	    if (!getyn())
		continue;
	    }
	setdisk(urdrive);
	srch_cnt = 1; dirhandle = HDIR_CREATE;
	findret = DosFindFirst(basedir, &dirhandle, MUST_HAVE_DIRECTORY,
			       &find, sizeof(find), &srch_cnt,
			       FIL_STANDARD);
	if (findret == 0) {
#ifndef __OS2__
	dirhandle = 1;
#endif
	    DosFindClose(dirhandle);
	    }
	else
	    continue;  /* no such directory, goto next argument */
	if (basedir[1] == ':') {
	    /* Need to change drives */
	    newdrive = toupper(basedir[0])-'A';
	    if (newdrive != urdrive) {
		setdisk(newdrive);
		if (newdrive != getdisk())
		    continue;  /* cannot switch drives, goto next argument */
	       }
	    basedir+=2;
	    }
	assert (NULL != (p=getcwd(NULL, MAXPATH)));
	dotdir = !strcmp(basedir, ".") ||
		 !strcmp(basedir, p+2);
	free(p);
	dotdotdir = !strcmp(basedir, "..");
	rootdir = (!strcmp(basedir,"\\") ||
		   !strcmp(basedir,"/"));
	printf("Deleting %s...\n", basedir);
	if (rootdir) {
	    CHDIR("\\");
	    retcode &= nextdir(FALSE);
	    }
	else if (dotdir) {
	    retcode &= nextdir(FALSE);
	    }
	else if (dotdotdir) {
	    CHDIR("..");
	    retcode &= nextdir(FALSE);
	    }
	else {
	    if (CHDIR(basedir))
		continue /* cannot change directory - goto next argument */;
	    retcode &= nextdir(FALSE);
	    CHDIR("..");
#ifndef DBG
	    retcode &= (0 == DosDeleteDir(basedir));
#endif
	    }
	/* goto next argument */
	}
    setdisk(urdrive);
    exit(retcode ? 0 : 1);
    }
Exemple #15
0
void
hammer_cmd_pseudofs_destroy(char **av, int ac)
{
	struct hammer_ioc_pseudofs_rw pfs;
	char *linkpath;
	int fd;
	int i;

	if (ac == 0)
		pseudofs_usage(1);
	fd = getpfs(&pfs, av[0]);

	if (pfs.pfs_id == HAMMER_ROOT_PFSID) {
		fprintf(stderr, "You cannot destroy PFS#0\n");
		exit(1);
	}
	printf("You have requested that PFS#%d (%s) be destroyed\n",
		pfs.pfs_id, pfs.ondisk->label);
	printf("This will irrevocably destroy all data on this PFS!!!!!\n");
	printf("Do you really want to do this? [y/n] ");
	fflush(stdout);
	if (getyn() == 0) {
		fprintf(stderr, "No action taken on PFS#%d\n", pfs.pfs_id);
		exit(1);
	}

	if (hammer_is_pfs_master(pfs.ondisk)) {
		printf("This PFS is currently setup as a MASTER!\n");
		printf("Are you absolutely sure you want to destroy it? [y/n] ");
		fflush(stdout);
		if (getyn() == 0) {
			fprintf(stderr, "No action taken on PFS#%d\n",
				pfs.pfs_id);
			exit(1);
		}
	}

	printf("Destroying PFS#%d (%s)", pfs.pfs_id, pfs.ondisk->label);
	if (DebugOpt) {
		printf("\n");
	} else {
		printf(" in");
		for (i = 5; i; --i) {
			printf(" %d", i);
			fflush(stdout);
			sleep(1);
		}
		printf(".. starting destruction pass\n");
	}

	/*
	 * Remove the softlink on success.
	 */
	if (ioctl(fd, HAMMERIOC_RMR_PSEUDOFS, &pfs) == 0) {
		printf("pfs-destroy of PFS#%d succeeded!\n", pfs.pfs_id);
		linkpath = getlink(av[0]);
		if (linkpath) {
			if (remove(linkpath) < 0) {
				fprintf(stderr,
					"Unable to remove softlink %s: %s\n",
					linkpath, strerror(errno));
					/* exit status 0 anyway */
			}
			free(linkpath);
		}
	} else {
		printf("pfs-destroy of PFS#%d failed: %s\n",
			pfs.pfs_id, strerror(errno));
	}
	relpfs(fd, &pfs);
}
Exemple #16
0
void
hammer_cmd_pseudofs_destroy(char **av, int ac)
{
	struct hammer_ioc_pseudofs_rw pfs;
	struct stat st;
	int fd;
	int i;

	if (ac == 0)
		pseudofs_usage(1);
	bzero(&pfs, sizeof(pfs));
	fd = getpfs(&pfs, av[0]);

	if (pfs.pfs_id == 0) {
		fprintf(stderr, "You cannot destroy PFS#0\n");
		exit(1);
	}
	printf("You have requested that PFS#%d (%s) be destroyed\n",
		pfs.pfs_id, pfs.ondisk->label);
	printf("This will irrevocably destroy all data on this PFS!!!!!\n");
	printf("Do you really want to do this? ");
	fflush(stdout);
	if (getyn() == 0) {
		fprintf(stderr, "No action taken on PFS#%d\n", pfs.pfs_id);
		exit(1);
	}

	if ((pfs.ondisk->mirror_flags & HAMMER_PFSD_SLAVE) == 0) {
		printf("This PFS is currently setup as a MASTER!\n");
		printf("Are you absolutely sure you want to destroy it? ");
		fflush(stdout);
		if (getyn() == 0) {
			fprintf(stderr, "No action taken on PFS#%d\n",
				pfs.pfs_id);
			exit(1);
		}
	}

	printf("Destroying PFS #%d (%s) in ", pfs.pfs_id, pfs.ondisk->label);
	for (i = 5; i; --i) {
		printf(" %d", i);
		fflush(stdout);
		sleep(1);
	}
	printf(".. starting destruction pass\n");
	fflush(stdout);

	/*
	 * Set the sync_beg_tid and sync_end_tid's to 1, once we start the
	 * RMR the PFS is basically destroyed even if someone ^C's it.
	 */
	pfs.ondisk->mirror_flags |= HAMMER_PFSD_SLAVE;
	pfs.ondisk->reserved01 = -1;
	pfs.ondisk->sync_beg_tid = 1;
	pfs.ondisk->sync_end_tid = 1;

	if (ioctl(fd, HAMMERIOC_SET_PSEUDOFS, &pfs) < 0) {
		fprintf(stderr, "Unable to update the PFS configuration: %s\n",
			strerror(errno));
		exit(1);
	}

	/*
	 * Ok, do it.  Remove the softlink on success.
	 */
	if (ioctl(fd, HAMMERIOC_RMR_PSEUDOFS, &pfs) == 0) {
		printf("pfs-destroy of PFS#%d succeeded!\n", pfs.pfs_id);
		if (lstat(av[0], &st) == 0 && S_ISLNK(st.st_mode)) {
			if (remove(av[0]) < 0) {
				fprintf(stderr, "Unable to remove softlink: %s "
					"(but the PFS has been destroyed)\n",
					av[0]);
				/* exit status 0 anyway */
			}
		}
	} else {
		printf("pfs-destroy of PFS#%d failed: %s\n",
			pfs.pfs_id, strerror(errno));
	}
}
Exemple #17
0
save() {

	reg char	*sp;
	reg int		outf;
	reg time_t	*tp;
	char		buf[80];
	time_t		tme;
	STAT		junk;

	tp = &tme;
	if (Fromfile && getyn(SAMEFILEPROMPT))
		strcpy(buf, Fromfile);
	else {
over:
		prompt(FILEPROMPT);
		leaveok(Board, FALSE);
		refresh();
		sp = buf;
		while ((*sp = readch()) != '\n') {
			if (*sp == killchar())
				goto over;
			else if (*sp == erasechar()) {
				if (--sp < buf)
					sp = buf;
				else {
					addch('\b');
					/*
					 * if the previous char was a control
					 * char, cover up two characters.
					 */
					if (*sp < ' ')
						addch('\b');
					clrtoeol();
				}
			}
			else
				addstr(unctrl(*sp++));
			refresh();
		}
		*sp = '\0';
		leaveok(Board, TRUE);
	}

	/*
	 * check for existing files, and confirm overwrite if needed
	 */

	if (sp == buf || (!Fromfile && stat(buf, &junk) > -1
	    && getyn(OVERWRITEFILEPROMPT) == FALSE))
		return FALSE;

	if ((outf = creat(buf, 0644)) < 0) {
		error(strerror(errno));
		return FALSE;
	}
	mvwaddstr(Score, ERR_Y, ERR_X, buf);
	wrefresh(Score);
	time(tp);			/* get current time		*/
	strcpy(buf, ctime(tp));
	for (sp = buf; *sp != '\n'; sp++)
		continue;
	*sp = '\0';
	varpush(outf, write);
	close(outf);
	wprintw(Score, " [%s]", buf);
	wclrtoeol(Score);
	wrefresh(Score);
	return TRUE;
}
Exemple #18
0
save() {

	reg char	*sp;
	reg int		outf;
	reg TIME	*tp;
	char		buf[80];
	TIME		tme;
	STAT		junk;

	tp = &tme;
	if (Fromfile && getyn("Same file? "))
		strcpy(buf, Fromfile);
	else {
over:
		mvaddstr(MOVE_Y, MOVE_X, "file: ");
		clrtoeol();
		leaveok(Board, FALSE);
		refresh();
		sp = buf;
		while ((*sp = readch()) != '\n') {
			if (*sp == _tty.sg_kill)
				goto over;
			else if (*sp == _tty.sg_erase) {
				if (--sp < buf)
					sp = buf;
				else {
					addch('\b');
					/*
					 * if the previous char was a control
					 * char, cover up two characters.
					 */
					if (*sp < ' ')
						addch('\b');
					clrtoeol();
				}
			}
			else
				addstr(unctrl(*sp++));
			refresh();
		}
		*sp = '\0';
		leaveok(Board, TRUE);
	}

	/*
	 * check for existing files, and confirm overwrite if needed
	 */

	if (sp == buf || (!Fromfile && stat(buf, &junk) > -1
	    && getyn("Overwrite File? ") == FALSE))
		return FALSE;

	if ((outf = creat(buf, 0644)) < 0) {
		error(sys_errlist[errno]);
		return FALSE;
	}
	mvwaddstr(Score, ERR_Y, ERR_X, buf);
	wrefresh(Score);
	time(tp);			/* get current time		*/
	strcpy(buf, ctime(tp));
	for (sp = buf; *sp != '\n'; sp++)
		continue;
	*sp = '\0';
	varpush(outf, write);
	close(outf);
	wprintw(Score, " [%s]", buf);
	wclrtoeol(Score);
	wrefresh(Score);
	return TRUE;
}
Exemple #19
0
int
PLP_page( )
{
int lvp, first;
char attr[NAMEMAXLEN], *line, *lineval;

char buf[512], devval[20];
char *outfilename, *mapfilename, *titledet, *pagetitle, *url;
int stat, nt, align, nlines, maxlen, landscapemode, dobackground, dopagebox, pagesizegiven, clickmap_enabled_here, tight, map;
double adjx, adjy, scalex, scaley, sx, sy;

TDH_errprog( "pl proc page" );

/* initialize */
landscapemode = PLS.landscape; /* from command line */
titledet = "";
outfilename = "";
mapfilename = "";
pagetitle = "";
dobackground = 1;
dopagebox = 1;
if( GL_member( PLS.device, "gesf" )) dopagebox = 0; /* bounding box shouldn't include entire page for gif , eps */
if( PLS.device == 'e' ) dobackground = 0; 
pagesizegiven = 0;
strcpy( devval, "" );
scalex = scaley = 1.0;
clickmap_enabled_here = 0;

/* get attributes.. */
first = 1;
while( 1 ) {
        line = getnextattr( first, attr, &lvp );
        if( line == NULL ) break;
        first = 0;
        lineval = &line[lvp];


	/* if an attribute is given on command line, it overrides anything here.. */
	if( GL_slmember( attr, PLS.cmdlineparms )) continue;
	if( strcmp( attr, "landscape" )==0 && GL_slmember( "portrait", PLS.cmdlineparms )) continue;
	if( strcmp( attr, "outfilename" )==0 && GL_slmember( "o", PLS.cmdlineparms )) continue;

	if( strcmp( attr, "landscape" )==0 ) landscapemode = getyn( lineval );
	else if( strcmp( attr, "title" )==0 ) pagetitle = getmultiline( lineval, "get" ); 
	else if( strcmp( attr, "titledetails" )==0 ) titledet = lineval;
	else if( strcmp( attr, "color" )==0 ) tokncpy( Estandard_color, lineval, COLORLEN );
	else if( strcmp( attr, "scale" )==0 ) { 
		nt = sscanf( lineval, "%lf %lf", &scalex, &scaley ); 
		if( nt == 1 ) scaley = scalex; 
		}
	else if( strcmp( attr, "backgroundcolor" )==0 ) {
		tokncpy( Estandard_bkcolor, lineval, COLORLEN );
		Ebackcolor( Estandard_bkcolor );
		dobackground = 1; /* added scg 9/27/99 */
		}
	else if( strcmp( attr, "linewidth" )==0 ) Estandard_lwscale = ftokncpy( lineval );
	else if( strcmp( attr, "textsize" )==0 ) Estandard_textsize = itokncpy( lineval );
	else if( strcmp( attr, "font" )==0 ) tokncpy( Estandard_font, lineval, FONTLEN );
	else if( strcmp( attr, "dobackground" )==0 ) dobackground = getyn( lineval );
	else if( strcmp( attr, "dopagebox" )==0 ) dopagebox = getyn( lineval );
	else if( strcmp( attr, "tightcrop" )==0 ) { tight = getyn( lineval ); Etightbb( tight ); }
	else if( strncmp( attr, "crop", 4 )==0 ) {
		double cropx1, cropy1, cropx2, cropy2;
		nt = sscanf( lineval, "%lf %lf %lf %lf", &cropx1, &cropy1, &cropx2, &cropy2 );
		if( nt != 4 ) Eerr( 2707, "usage: crop x1 y1 x2 y2 OR croprel left bottom right top", "" );
		else {
			if( PLS.usingcm ) { cropx1 /= 2.54; cropy1 /= 2.54; cropx2 /= 2.54; cropy2 /= 2.54; }
			if( strcmp( attr, "croprel" )==0 ) Especifycrop( 2, cropx1, cropy1, cropx2, cropy2 ); /* relative to tight */
			else Especifycrop( 1, cropx1, cropy1, cropx2, cropy2 ); /* absolute */
			}
		}

	else if( strcmp( attr, "pixsize" ) ==0 ) {  /* added scg 1/9/08 */
		int reqwidth, reqheight;
		nt = sscanf( lineval, "%d %d", &reqwidth, &reqheight );
		if( nt != 2 ) Eerr( 57233, "pixsize ignored.. it requires width and height (in pixels)", "" );
#ifndef NOGD
        	PLGG_setimpixsize( reqwidth, reqheight );
#endif
        	if( PLS.device != 'g' ) Eerr( 24795, "pixsize ignored.. it's only applicable when generating png/gif/jpeg images", "" ); 
		}

	else if( strcmp( attr, "pagesize" )==0 ) {
		getcoords( "pagesize", lineval, &(PLS.winw), &(PLS.winh) );
		pagesizegiven = 1;
		}
	else if( strcmp( attr, "outfilename" )==0 ) {
		outfilename = lineval;
		if( strlen( outfilename ) > MAXPATH-1 ) { PLS.skipout = 1; return( Eerr( 57932, "outfilename too long", "" ) ); }  
		}
	else if( strncmp( attr, "mapfile", 7 )==0 ) {
		mapfilename = lineval;
		if( strlen( mapfilename ) > MAXPATH-1 ) { Eerr( 57932, "mapfile name too long", "" ); mapfilename = ""; }
		}

	else if( strcmp( attr, "clickmapdefault" )==0 ) { 
		url = lineval;
		if( strlen( url ) > MAXURL-1 ) Eerr( 57933, "clickmapdefault url too long", "" );
		else clickmap_setdefaulturl( url ); 
		}

	else if( strcmp( attr, "map" )==0 ) { map = getyn( lineval ); if( map ) { PLS.clickmap = 1; clickmap_enabled_here = 1; }}
	else if( strcmp( attr, "csmap" )==0 ){ map = getyn( lineval ); if( map ) { PLS.clickmap = 2; clickmap_enabled_here = 1; }} 
	else if( strcmp( attr, "outlabel" )==0 ) Esetoutlabel( lineval );
	else Eerr( 1, "page attribute not recognized", attr );
	}



/* -------------------------- */
/* Page break logic.. */
/* -------------------------- */
if( PLS.npages == 0 ) {

	/* following 3 lines moved here from above - also replicated below.  scg 10/31/00 */
	if( scalex != 1.0 || scaley != 1.0 ) Esetglobalscale( scalex, scaley );
	Egetglobalscale( &sx, &sy );
	if( pagesizegiven ) Esetsize( PLS.winw * sx, PLS.winh * sy, PLS.winx, PLS.winy );
	else if( landscapemode && !PLS.winsizegiven ) Esetsize( 11.0, 8.5, PLS.winx, PLS.winy ); /* landscape */

	/* clickmap (must come before init for eg. svg - scg 2/7/05) */
	if( clickmap_enabled_here ) {
		if( mapfilename[0] == '\0' ) {
        		if( PLS.clickmap == 2 ) strcpy( PLS.mapfile, "stdout" );  /* csmap defaults to stdout..  scg 8/26/04  */
        		else if( PLS.outfile[0] != '\0' ) makeoutfilename( PLS.outfile, PLS.mapfile, 'm', 1);
        		else strcpy( PLS.mapfile, "unnamed.map" );
        		}
		PL_clickmap_init();
#ifndef NOSVG
		/* must update this now too.. scg 2/7/05  */
		if( PLS.device == 's' ) PLGS_setparms( PLS.debug, PLS.tmpname, PLS.clickmap );
#endif
		}
	else if( mapfilename[0] != '\0' ) strcpy( PLS.mapfile, mapfilename ); /* PPP */

	/* initialize and give specified output file name .. */
	if( outfilename[0] != '\0' ) Esetoutfilename( outfilename );
	stat = Einit( PLS.device );
	if( stat ) { PLS.skipout = 1; return( stat ); }

	/* set paper orientation */
	if( landscapemode ) Epaper( 1 );

	}


else if( PLS.npages > 0 ) {

	if( GL_member( PLS.device, "gesf" )) {

		/* finish up current page before moving on to next one.. */
		Eshow();
		stat = Eendoffile();
		if( stat ) return( stat );

		/* now set file name for next page.. */
		if( outfilename[0] != '\0' ) Esetoutfilename( outfilename );
		else	{
			makeoutfilename( PLS.outfile, buf, PLS.device, (PLS.npages)+1 );
			if( PLS.debug ) fprintf( PLS.diagfp, "Setting output file name to %s\n", PLS.outfile );
			Esetoutfilename( buf );
			}

		if( PLS.clickmap ) {
			/* initialize a new click map file.. */
			if( mapfilename[0] != '\0' ) strcpy( PLS.mapfile, mapfilename );
			else makeoutfilename( PLS.outfile, PLS.mapfile, 'm', (PLS.npages)+1 );
			PL_clickmap_init();

			}


		/* perhaps set global scaling and/or page size for next page.. */
		/* following 3 lines copied here from above - scg 10/31/00 */
		if( scalex != 1.0 || scaley != 1.0 ) Esetglobalscale( scalex, scaley );
		Egetglobalscale( &sx, &sy ); 
		if( pagesizegiven ) Esetsize( PLS.winw * sx, PLS.winh * sy, PLS.winx, PLS.winy );
		else if( landscapemode && !PLS.winsizegiven ) Esetsize( 11.0, 8.5, PLS.winx, PLS.winy ); /* landscape */

		/* initialize next page.. */
		stat = Einit( PLS.device );
		if( stat ) return( stat );
		}

	else if ( PLS.device == 'x' ) PL_do_x_button( "More.." );

	else if ( GL_member( PLS.device, "pc" ) ) {
		Eprint();
		if( landscapemode ) Epaper( 1 ); /* added scg 2/29/00 */
		Elinetype( 0, 0.6, 1.0 );   /* added scg 9/20/99 */
		}
	}
(PLS.npages)++;


/* -------------------------- */
/* now do other work.. */
/* -------------------------- */


/* do background.. */
/* if( dopagebox ) Ecblock( 0.0, 0.0, EWinx, EWiny, Ecurbkcolor, 0 ); */ /* does update bb */
if( dopagebox ) Ecblock( 0.0, 0.0, PLS.winw, PLS.winh, Ecurbkcolor, 0 ); /* does update bb */
else if( dobackground ) {
	/* EPS color=transparent - best to do nothing.. */
        if( PLS.device == 'e' && strcmp( Ecurbkcolor, "transparent" )==0 ) ;

        else Eclr(); /* doesn't update bb */
	}

if( pagetitle[0] != '\0' ) {
	textdet( "titledetails", titledet, &align, &adjx, &adjy, 3, "B", 1.0 );
	if( align == '?' ) align = 'C';
	measuretext( pagetitle, &nlines, &maxlen );
	if( align == 'L' ) Emov( 1.0 + adjx, (PLS.winh-0.8) + adjy );
	else if ( align == 'C' ) Emov( (PLS.winw / 2.0 ) + adjx, (PLS.winh-0.8) + adjy );
	else if( align == 'R' ) Emov( (PLS.winw-1.0) + adjx, (PLS.winh-0.8) + adjy );
	Edotext( pagetitle, align );
	}

return( 0 );
}
Exemple #20
0
int
PLP_pie()
{
char attr[NAMEMAXLEN], *line, *lineval;
int lvp, first;

char *labels, *outlinedetails, *lablinedetails, *labelmode, *mapurl, *maplabel, *textdetails;
char *pctfmt, *labelback, *lblfmtstring, *expandedurl, *expandedlabel, *color1;

char buf[256], color[MAXSLICE][40], lbl[256], pctstr[80];
int j, align, df, lblfld, ncolors, nexpl, ibb, colorfield, nlines;
int maxlen, irow, ilabmode, labelbackoutline, exactcolorfield, wraplen;
double expl[MAXSLICE];
double adjx, adjy, cx, cy, radius, theta, total, ux, uy, stop, starttheta, sin(), cos();
double fval, x, y, oldx, oldy, stheta, lblfarout, boxwid, boxhi, labx, laby, dval;

TDH_errprog( "pl proc pie" );


/* initialize */
labels = ""; outlinedetails = ""; lablinedetails = ""; textdetails = ""; mapurl = ""; maplabel = ""; 
labelback = ""; lblfmtstring = "";
ncolors = 0; labelbackoutline = 0; wraplen = 0; nexpl = 0; 

theta = 0.0;
cx = cy = -1.0;
radius = -1.0;
labelmode = "legend";
starttheta = 90.0 * TORAD;
total = 0.0;
lblfarout = 0.0;
pctfmt = "%.1f";
lblfld = -1;
colorfield = -1;
exactcolorfield = -1;

/* get attributes.. */
first = 1;
while( 1 ) {
	line = getnextattr( first, attr, &lvp );
	if( line == NULL ) break;
	first = 0;
	lineval = &line[lvp];

	if( strcmp( attr, "datafield" )==0 ) df = fref( lineval ) -1 ;
	else if( strcmp( attr, "center" )==0 ) getcoords( "center", lineval, &cx, &cy );
	else if( strcmp( attr, "radius" )==0 ) Elenex( lineval, X, &radius ); 
	else if( strcmp( attr, "firstslice" )==0 ) starttheta = ((360-ftokncpy( lineval )) * TORAD ) + 90.0 * TORAD;
	else if( strcmp( attr, "total" )==0 ) total = ftokncpy( lineval );
	else if( strcmp( attr, "clickmapurl" )==0 ) mapurl = lineval;
	else if( strcmp( attr, "clickmaplabel" )==0 ) maplabel = lineval;
        else if( strcmp( attr, "clickmaplabeltext" )==0 ) maplabel = getmultiline( lineval, "get" );
	else if( strcmp( attr, "colors" )==0 ) {
		int i, ix;
		for( i = 0, ix = 0; i < MAXSLICE; i++ ) {
			strcpy( color[i], GL_getok( lineval, &ix ) );
			if( color[i][0] == '\0' ) break;
			}
		ncolors = i;
		}
	else if( strcmp( attr, "labels" )==0 ) labels = getmultiline( lineval, "get" );
	else if( strcmp( attr, "labelfield" )==0 ) lblfld = fref( lineval ) - 1;
	else if( strcmp( attr, "labelfmtstring" )==0 ) lblfmtstring = lineval;
	else if( strcmp( attr, "colorfield" )==0 ) colorfield = fref( lineval ) - 1;
	else if( strcmp( attr, "exactcolorfield" )==0 ) exactcolorfield = fref( lineval ) - 1;
	else if( strcmp( attr, "outlinedetails" )==0 ) outlinedetails = lineval;
	else if( strcmp( attr, "lablinedetails" )==0 ) lablinedetails = lineval;
	else if( strcmp( attr, "textdetails" )==0 ) textdetails = lineval;
	else if( strcmp( attr, "labelmode" )==0 ) labelmode = lineval;
	else if( strcmp( attr, "labelfarout" )==0 ) lblfarout = ftokncpy( lineval );
	else if( strcmp( attr, "labelback" )==0 ) labelback = lineval;
	else if( strcmp( attr, "labelbackoutline" )==0 ) labelbackoutline = getyn( lineval );
	else if( strcmp( attr, "pctformat" )==0 ) pctfmt = lineval;
	else if( strcmp( attr, "explode" )==0 ) {
		int i, ix;
		for( i = 0, ix = 0; i < MAXSLICE; i++ ) {
			strcpy( buf, GL_getok( lineval, &ix ));
			if( buf[0] == '\0' ) break;
			else expl[i] = atof( buf );
			}
		nexpl = i;
		}
	else if( strcmp( attr, "wraplen" )==0 ) wraplen = itokncpy( lineval );
	else Eerr( 1, "attribute not recognized", attr );
	}



/* overrides and degenerate cases */
/* -------------------------- */

if( Nrecords < 1 ) return( Eerr( 17, "No data has been read yet w/ proc getdata", "" ) );
if( df < 0 || df >= Nfields ) return( Eerr( 2840, "invalid datafield", "" ) );
if( cx < 0.0 || cy < 0.0 ) return( Eerr( 2841, "invalid center", "" ) );
if( radius < 0.0 || radius > 5.0 ) return( Eerr( 2842, "invalid radius", "" ) );


if( lblfarout < 0.001 && strncmp( labelmode, "label", 5 )==0 ) lblfarout = 0.67;
if( lblfarout < 0.001 && strncmp( labelmode, "line", 4 )==0 ) lblfarout = 1.3;

if( labelbackoutline && labelback[0] == '\0' ) labelback = Ecurbkcolor;


/* now do the plotting work.. */
/* -------------------------- */

/* compute total.. */
if( total <= 0.0 ) {
	total = 0.0;
	for( irow = 0; irow < Nrecords; irow++ ) {
		total += atof( da( irow, df ) );
		}
	}

ibb = 0;

if( strncmp( labelmode, "legend", 6 )==0 ) ilabmode = LEGEND;
else if( strncmp( labelmode, "labelonly", 5 ) ==0 ) ilabmode = LABEL;
else if( strncmp( labelmode, "line+label", 4 ) ==0 ) ilabmode = LINELABEL;
else ilabmode = 0;


for( j = 0; j < 2; j++ ) { /* first time - colors; 2nd time, lines */
	theta = starttheta + 6.28319;
	if( j == 1 ) {
		/* set line details for outline.. */
		linedet( "outlinedetails", outlinedetails, 0.5 );
		}
	for( irow = 0; irow < Nrecords; irow++ ) {
		/* take val as % of total and convert to rads */
		dval = atof( da( irow, df ) );
		if( dval == 0.0 ) continue; /* prevent slice attempt on degenerate case - scg 7/21/03 */
		fval = ( dval / total ) * 6.28319; 
		stop = theta - fval;

		/* find (ux,uy), the point at the wedge of the slice, normalized to 0,0 center.. */
		if( nexpl <= 0 ) { /* don't explode any slices */
			ux = 0.0; 
			uy = 0.0;
			}
		else if( irow >= nexpl ) { /* explode slice according to last explode value */
			ux = (expl[nexpl-1]*radius) * cos( theta+(fval/-2.0) );
			uy = (expl[nexpl-1]*radius) * sin( theta+(fval/-2.0) );
			}
		else if( irow < nexpl ) { /* explode slice according to explode value [i] */
			ux = (expl[irow]*radius) * cos( theta+(fval/-2.0) );
			uy = (expl[irow]*radius) * sin( theta+(fval/-2.0) );
			}
			
		first = 1;
		stheta = theta;
		if( j == 1 && strncmp( outlinedetails, "no", 2 )==0 ) /* break; */ goto DOLAB;  /* changed again, scg 4/29/05 */
		for( ; theta > stop; theta -= 0.03 ) {
			if( theta - stop < 0.03 ) theta = stop;
			x = cx + (radius * cos( theta ));
			y = cy + (radius * sin( theta ));
			if( j == 0 ) {
				if( first ) { 
					first = 0; oldx = x; oldy = y; 
					Emov( cx+ux, cy+uy );
					Epath( x+ux, y+uy );
					continue; 
					}

				Epath( x+ux, y+uy ); 
				oldx = x; oldy = y;
				}
			else if( j == 1 ) {
				if( first ) { Emov( cx+ux, cy+uy ); Elin( x+ux, y+uy ); first = 0; }
				Elin( x+ux, y+uy );
				}
			}
		if( j == 1 ) Elin( cx+ux, cy+uy ); 

		color1 = "";
		if( j == 0 ) {
			Epath( cx+ux, cy+uy );

			if( colorfield >=0 ) {  
                		color1 = PL_get_legent( da( irow, colorfield ) );
				Ecolorfill( color1 );
                		}

			else if( exactcolorfield >= 0 ) {
				color1 = da( irow, exactcolorfield );
				Ecolorfill( color1 );
				}
			else if( strcmp( color[0], "auto" )==0 ) {
				color1 = Eicolor( irow );
				Ecolorfill( color1 );
				}
			else if( irow < ncolors ) Ecolorfill( color[irow] );
			else if( ncolors > 0 ) Ecolorfill( color[ncolors-1] );
			else Ecolorfill( "0.8" );
			}

		/* labeling */  /* if doing legend, handle this during j == 0 because color is available;
				   otherwise do labeling during j == 1 to avoid color fill obliterating labels.. */
		DOLAB:
		if( ( j == 0 && ilabmode == LEGEND ) || ( j == 1 && ilabmode != 0 ) ) {
			strcpy( lbl, "");

			sprintf( pctstr, pctfmt, (atof( da( irow, df ) ) / total)*100.0 );
			if( PLS.bignumspacer ) rewritenums( pctstr ); /* added 4/5/03 */

			if( lblfld >= 0 ) strcpy( lbl, da( irow, lblfld ) );
			else if( labels != "" ) GL_getseg( lbl, labels, &ibb, "\n" );
			else if( lblfmtstring[0] != '\0' ) { /* added scg 8/20/04 */
				strcpy( buf, lblfmtstring );
				GL_varsub( buf, "@PCT", pctstr );
				do_subst( lbl, buf, irow, NORMAL );
				}

			GL_varsub( lbl, "@PCT", pctstr );
			convertnl( lbl );

			/* allow @field substitutions into url */
			if( PLS.clickmap && ( mapurl != "" || maplabel != "" )) {
				expandedurl = PL_bigbuf;
				expandedlabel = &PL_bigbuf[2000];
				do_subst( expandedurl, mapurl, irow, URL_ENCODED );
				do_subst( expandedlabel, maplabel, irow, NORMAL );
				}

			/* if( ilabmode == LEGEND )  */ /* changed 7/14/03 scg */
			if( j == 0 && ilabmode == LEGEND ) { 
				if( color1[0] != '\0' ) PL_add_legent( LEGEND_COLOR, lbl, "", color1, "", "" );
				else PL_add_legent( LEGEND_COLOR, lbl, "", color[irow], "", "" );
				}

			else if( j == 1 && ilabmode == LABEL ) {
				double htheta;
				double x1, y1, x2, y2;
				int centerit = 0;
				htheta = stop + ((stheta - stop) / 2.0 );
				x = cx + ( (radius * lblfarout) * cos( htheta ) );
				y = cy + ( (radius * lblfarout) * sin( htheta ) );
				if( wraplen ) GL_wraptext( lbl, wraplen ); /* added scg 8/16/05 */
				measuretext( lbl, &nlines, &maxlen );
				labx = x+ux;
				laby = y+uy;
				boxhi = nlines * Ecurtextheight;
				boxwid = (maxlen * Ecurtextwidth);
				
				if( (htheta >= 7.7 && htheta <= 8.2 ) || (htheta >= 4.5 && htheta <= 5.0 )) centerit = 1;
				if( centerit ) { x1 = labx-(boxwid/2.0); x2 = labx+(boxwid/2.0); }
				else if( x < cx ) { x1 = labx - boxwid; x2 = labx; }
				else { x1 = labx; x2 = labx + boxwid; }
				y1 = laby-boxhi; y2 = laby;

				if( labelback != "" ) Ecblock( x1-0.1, y1+(Ecurtextheight*0.6), x2+0.1, y2+Ecurtextheight, labelback, labelbackoutline );

				textdet( "textdetails", textdetails, &align, &adjx, &adjy, -2,"R", 1.0 );
				Emov( labx, laby );
				if( !centerit && x < cx ) Erightjust( lbl );
				else if( !centerit && x >= cx ) Etext( lbl );
				else Ecentext( lbl );
				if( PLS.clickmap && ( mapurl != "" || maplabel != "" )) 
					clickmap_entry( 'r', expandedurl, 0, x1, y1+Ecurtextheight, x2, y2+Ecurtextheight, 1, 0, expandedlabel );
				linedet( "linedetails", outlinedetails, 0.5 ); /* restore */
				}

			/* else if( ilabmode == LINELABEL )  */ /* changed 7/14/03 scg */
			else if( j == 1 && ilabmode == LINELABEL ) {
				double htheta, px, py, w, z;

				if( wraplen ) GL_wraptext( lbl, wraplen ); /* added scg 8/16/05 */
				measuretext( lbl, &nlines, &maxlen );
				boxwid = maxlen * Ecurtextwidth;
				boxhi = nlines * Ecurtextheight;

				w = radius * lblfarout;
				if( w < (1.1 * radius) ) z = lblfarout;
				else z = 1.1;

				htheta = stop + ((stheta - stop) / 2.0 );
				px = cx + ( (radius * 0.9 ) * cos( htheta ) );
				py = cy + ( (radius * 0.9 ) * sin( htheta ) );
		
				x = cx + ( (radius * z ) * cos( htheta ) );
				y = cy + ( (radius * z ) * sin( htheta ) );

				linedet( "lablinedetails", lablinedetails, 0.5 ); 
				Emov( px+ux, py+uy );
				Elin( x+ux, y+uy );
				if( x+ux < cx ) {
					Elin( (cx+ux)-w, y+uy );
					textdet( "textdetails", textdetails, &align, &adjx, &adjy, -2,"R", 1.0 );
					labx = ((cx+ux)-w)-0.1;
					laby = y+uy;
					if( labelback[0] != '\0' ) 
						Ecblock( labx-boxwid-0.1, laby-boxhi+(Ecurtextheight*0.6), 
							labx+0.1, laby+Ecurtextheight, labelback, labelbackoutline );

					Emov( labx, laby );
					Erightjust( lbl );
					if( PLS.clickmap && ( mapurl != "" || maplabel != "" ))
						clickmap_entry( 'r', expandedurl, 0, labx-boxwid, laby-boxhi+Ecurtextheight, 
							labx, laby+Ecurtextheight, 1, 0, expandedlabel );
						
					}
				else 	{
					Elin( (cx+ux)+w, y+uy );
					textdet( "textdetails", textdetails, &align, &adjx, &adjy, -2,"R", 1.0 );
					labx = cx+ux+w+0.1;
					laby = y+uy;
					if( labelback[0] != '\0' ) 
						Ecblock( labx-0.1, laby-boxhi+(Ecurtextheight*0.6), 
							labx+boxwid+0.1, laby+Ecurtextheight, labelback, labelbackoutline );
					Emov( labx, laby );
					Etext( lbl );
					if( PLS.clickmap && ( mapurl != "" || maplabel != "" ))
						clickmap_entry( 'r', expandedurl, 0, labx, laby-boxhi+Ecurtextheight, 
							labx+boxwid, laby+Ecurtextheight, 1, 0, expandedlabel );

					}
				linedet( "outlinedetails", outlinedetails, 0.5 ); /* restore */
				}
			}


		theta = stop;
		}
	}

return( 0 );
}
Exemple #21
0
/*
 *	This routine lets a player resign
 */
void
resign(void)
{
	int i, new_own;
	OWN *op;
	SQUARE *sqp;

	if (cur_p->money <= 0) {
		switch (board[cur_p->loc].type) {
		  case UTIL:
		  case RR:
		  case PRPTY:
			new_own = board[cur_p->loc].owner;
			/* If you ran out of money by buying current location */
			if (new_own == player)
				new_own = num_play;
			break;
		  default:		/* Chance, taxes, etc */
			new_own = num_play;
			break;
		}
		if (new_own == num_play)
			printf("You would resign to the bank\n");
		else
			printf("You would resign to %s\n", name_list[new_own]);
	}
	else if (num_play == 1) {
		new_own = num_play;
		printf("You would resign to the bank\n");
	}
	else {
		name_list[num_play] = "bank";
		do {
			new_own = getinp("Who do you wish to resign to? ",
			    name_list);
			if (new_own == player)
				printf("You can't resign to yourself!!\n");
		} while (new_own == player);
		name_list[num_play] = "done";
	}
	if (getyn("Do you really want to resign? ") != 0)
		return;
	if (num_play == 1) {
		printf("Then NOBODY wins (not even YOU!)\n");
		exit(0);
	}
	if (new_own < num_play) {	/* resign to player		*/
		printf("resigning to player\n");
		trades[0].trader = new_own;
		trades[0].cash = trades[0].gojf = 0;
		trades[0].prop_list = NULL;
		trades[1].trader = player;
		trades[1].cash = cur_p->money > 0 ? cur_p->money : 0;
		trades[1].gojf = cur_p->num_gojf;
		trades[1].prop_list = cur_p->own_list;
		do_trade();
	}
	else {				/* resign to bank		*/
		printf("resigning to bank\n");
		for (op = cur_p->own_list; op; op = op->next) {
			sqp = op->sqr;
			sqp->owner = -1;
			sqp->desc->morg = FALSE;
			if (sqp->type == PRPTY) {
				is_not_monop(sqp->desc->mon_desc);
				sqp->desc->houses = 0;
			}
		}
		if (cur_p->num_gojf)
			ret_card(cur_p);
	}
	free(play[player].name);
	for (i = player; i < num_play; i++) {
		name_list[i] = name_list[i+1];
		if (i + 1 < num_play)
			play[i] = play[i+1];
	}
	name_list[num_play--] = NULL;
	for (i = 0; i < N_SQRS; i++)
		if (board[i].owner > player)
			--board[i].owner;
	player = player == 0 ? num_play - 1 : player - 1;
	next_play();
	if (num_play < 2) {
		printf("\nThen %s WINS!!!!!\n", play[0].name);
		printhold(0);
		printf("That's a grand worth of $%d.\n",
			play[0].money+prop_worth(&play[0]));
		exit(0);
	}
}