
program rnconfig(input,output);
uses dos,crt,bbskv,bbskern,iconfig,rgoods,nanocore,nanostr,protcomm,usered,rkey;
{$M 65519,65536,655360}
{$V-}
{$I RN-STRUC.PAS}

const one=1;
			zero=0;
			BBD='Rancho Nevada';
      rawfile:array[1..44] of string[80]=(
{001} 	'; Maximum number of times a user can enter the door in one day',
							{Plays 3}
{002} 	'; Maximum number of moves a player can make in one round',
							{Moves 60}
{003} 	'; Maximum number of uses of the Audiovisual Terminals in one round',
							{AVTerm 4}
{004} 	'; Maximum number of times per round a player may enter the drinking contests',
							{Drink 3}
{005} 	'; Maximum number of levels down a player may try to start an encounter',
							{Diff 5}
{006} 	'; Percentage of default per paycheck to give employees (Default=100)',
							{Pay 300}
{007} 	'; Percentage of default experience to award employees per day (Default=100)',
							{XP 100}
{008} 	'; Percentage of the default money to give players upon level-bumping',
							{ClimbPay 100}
{009} 	'; Percentage of default R/L for sex toys to remove from opponents',
{010} 	'; Make this higher to make toys more effective, and the game will',
{011} 	'; likely speed up.',
							{MinusHP 100}
{012}   '; Percentage probability that a given employee will be a candidate for',
{013}   '; re-roll on any given maintenance cycle',
							{RobotReRoll 6}
{014}   '; Probability in percent that a player or employee in coward or paranoid',
{015}   '; mode will be cornered when you enter',
							{Corner 30}
{016}   '; Note: in the following descriptions, the acronym VKR refers to the',
{017}   '; "Virgin Killers Row" gameplay feature, a.k.a. "Hall of Fun"',
{018}   ' ',
{019}   '; Whether or not to decrement moves in the VKR/Hall of Fun',
{020}   '; YES means take 1 move for every door in the VKR, NO means VKR is free',
							{VKRMoves No}
{021}   '; Maximum number of times per round a player can use the Jacuzzis.',
{022}   '; Note: Jacuzzi usages are zeroed upon emergence from the VKR.  This is',
{023}   '; not a bug!',
							{MaxJacuzzi 3}
{024}   '; Probability (in percent) that using the Jacuzzi will give benefits (if',
{025}   '; player is eligible for such benefits - she must have less than half her',
{026}   '; Resistance/Libido points left or be at full R/L to get any benefit,',
{027}   '; otherwise the Jacuzzi has no effect.)',
							{JacuzziLuck 50}
{028}   '; Number of minutes without keyboard activity before exiting automatically',
							{Timeout 4}
{029}   '; Room to start new players in',
							{Start 1}
{030}   '; ANSI mode - either ask whether ansi is used, try to auto-detect it,',
{031}   '; or read it from the door info file.  Galacticomm sysops may have to',
{032}   '; use "detect" or "ask"...',
							{ANSI ask}
							{ANSI detect}
							{ANSI doorinfo}
{033}   '; You can define ports 1 thru 8.  The first parameter after PORT is the',
{034}   '; com port number (one-based!), followed by the hexadecimal port address,',
{035}   '; followed in turn by the IRQ.  The defaults are given here.  I do not',
{036}   '; recommend using COM5 and up with these defaults, and you should',
{037}   '; check the hardware settings for COM3 and COM4 carefully before you use',
{038}   '; this table as-is.',
							{Port 1 03F8 4}
{039}   '; Uncomment this to if you want to force the use of the internal comm',
{040}   '; driver even if you have a FOSSIL',
							{NoFossil}
{041}   '; The ROBOT GENDER, ROBOT PREFERENCE and ROBOT LASTNAME keywords govern the',
{042}   '; random generation of Employees (robots) in the player editor.',
              {Robot Gender}
							{Robot Preference}
							{Robot Lastname}
{043}   '; Number of days to keep players who have not been playing.  Set to zero',
{044}   '; or comment out to have Rancho never delete users.');
							{Delete Inactive}

var

		fnam:string[80];
		linein:string[127];
		restofline:string[127];
		arg,arg2,arg3:string[127];
		parses:array[1..16] of string[20];
		v1,v2,v3,v4,v5,v6,v7,v8,v9:integer;
		v0:word;
		tmp1,tmp2,tmp3,tmp4:string;
		comd:char;
		linenum,index2:integer;
		addressindex:integer;
		cfilename:string;



procedure nothing;
begin
end;

procedure parse;
var index:integer;
begin
	fillchar(parses,sizeof(PARSES),chr(0));
(*	fillchar(days,sizeof(DAYS),chr(0));
	fillchar(months,sizeof(MONTHS),chr(0)); *)
	while (copy(linein,one,one)=' ') do delete (linein,one,one); {This gets rid of leading spaces}
	index2:=one;
	repeat
		begin
			index:=one; {reset the counter}
			while ((copy(linein,index,one)<>' ') and (index <= length(linein))) do index:=index+one; {Seek out space}
			parses[index2]:=copy(linein,one,(index-one)); {When it finds space the length of the first string is index-1}
			delete(linein,one,index); {Get rid of that part of the input string; it's now in parse1}
			while (copy(linein,one,one)=' ') do delete (linein,one,one); {This gets rid of leading spaces}
			if index2=1 then restofline:=linein;
			inc(index2);
		end
	until((index2>16) or (length(linein)<1));
end; {Procedure Parse}

procedure saveout(filename:String);
var f:text;
		i:integer;
begin
	if exist(filename) then nuke(filename);
	assign(f,filename);
	rewrite(f);

	writeln(f,';');
  writeln(f,'; Rancho Nevada (C) 1992,1997 Whirlwind Software');
	writeln(f,'; RANCHO.CFG - The general configuration file.');
	writeln(f,';');
	writeln(f,'');
	writeln(f,rawfile[1]);	writeln(f,''); writeln(f,'Plays          ',config.maxplays); writeln(f,'');
	writeln(f,rawfile[2]);	writeln(f,''); writeln(f,'Moves          ',config.maxmoves); writeln(f,'');
	writeln(f,rawfile[3]);	writeln(f,''); writeln(f,'AVTerm         ',config.maxschool); writeln(f,'');
	writeln(f,rawfile[4]);	writeln(f,''); writeln(f,'Drink          ',config.maxjoust); writeln(f,'');
	writeln(f,rawfile[5]);	writeln(f,''); writeln(f,'Diff           ',config.maxdiff); writeln(f,'');
	writeln(f,rawfile[6]);	writeln(f,''); writeln(f,'Pay            ',config.robotpaypercent); writeln(f,'');
	writeln(f,rawfile[7]);	writeln(f,''); writeln(f,'XP             ',config.robotxppercent); writeln(f,'');
	writeln(f,rawfile[8]);	writeln(f,''); writeln(f,'ClimbPay       ',config.bumppay); writeln(f,'');
	writeln(f,rawfile[9]);
	writeln(f,rawfile[10]);
	writeln(f,rawfile[11]); writeln(f,''); writeln(f,'MinusHP        ',config.minushp); writeln(f,'');
  writeln(f,rawfile[12]);
  writeln(f,rawfile[13]); writeln(f,''); writeln(f,'RobotReroll    ',config.robotreroll); writeln(f,'');
  writeln(f,rawfile[14]);
  writeln(f,rawfile[15]); writeln(f,''); writeln(f,'Corner         ',config.corner); writeln(f,'');
  writeln(f,rawfile[16]);
  writeln(f,rawfile[17]);
  writeln(f,rawfile[18]);
  writeln(f,rawfile[19]);
  writeln(f,rawfile[20]); writeln(f,''); write(f,'VKRMoves       ');
		if config.vkrmove then writeln(f,'Yes') else writeln(f,'No');
		writeln(f,'');
  writeln(f,rawfile[21]);
  writeln(f,rawfile[22]);
  writeln(f,rawfile[23]); writeln(f,''); writeln(f,'MaxJacuzzi     ',config.maxjacuzzi); writeln(f,'');
  writeln(f,rawfile[24]);
  writeln(f,rawfile[25]);
  writeln(f,rawfile[26]);
  writeln(f,rawfile[27]); writeln(f,''); writeln(f,'JacuzziLuck    ',config.jacuzziluck); writeln(f,'');
  writeln(f,rawfile[28]); writeln(f,''); writeln(f,'Timeout        ',config.timeout); writeln(f,'');
  writeln(f,rawfile[29]); writeln(f,''); writeln(f,'Start          ',config.startroom); writeln(f,'');
  writeln(f,rawfile[30]);
  writeln(f,rawfile[31]);
  writeln(f,rawfile[32]); writeln(f,'');
		if not(config.ansimode=0) then write(f,'; '); writeln(f,'ANSi  DoorInfo');
		if not(config.ansimode=1) then write(f,'; '); writeln(f,'ANSi  Ask');
		if not(config.ansimode=2) then write(f,'; '); writeln(f,'ANSi  Detect');
		writeln(f,'');
  writeln(f,rawfile[33]);
  writeln(f,rawfile[34]);
  writeln(f,rawfile[35]);
  writeln(f,rawfile[36]);
  writeln(f,rawfile[37]);
  writeln(f,rawfile[38]); writeln(f,'');
		for i:=0 to protcomm.maxphysport do
			begin
				writeln(f,'Port ',i+1,' ',hexw(protcomm.porttable[i].base),' ',protcomm.porttable[i].irq);
			end;
		writeln(f,'');
  writeln(f,rawfile[39]);
  writeln(f,rawfile[40]); writeln(f,''); if not(config.nofossil) then write(f,'; ');
		writeln(f,'NoFOSSIL'); writeln(f,'');
  writeln(f,rawfile[41]);
  writeln(f,rawfile[42]); writeln(f,'');
		if not(config.robotgender=0) then write(f,'; '); writeln(f,'Robot Gender Female');
		if not(config.robotgender=1) then write(f,'; '); writeln(f,'Robot Gender Male');
		if not(config.robotgender=2) then write(f,'; '); writeln(f,'Robot Gender Both');
		writeln(f,'');
		if not(config.robotpreference=0) then write(f,'; '); writeln(f,'Robot Preference Bisexual');
		if not(config.robotpreference=1) then write(f,'; '); writeln(f,'Robot Preference Random');
		if not(config.robotpreference=2) then write(f,'; '); writeln(f,'Robot Preference Straight');
		if not(config.robotpreference=3) then write(f,'; '); writeln(f,'Robot Preference Gay');
		writeln(f,'');
		if not(config.robotlastname=0) then write(f,'; '); writeln(f,'Robot LastName On');
		if not(config.robotlastname=1) then write(f,'; '); writeln(f,'Robot Lastname Off');
		writeln(f,'');
  writeln(f,rawfile[43]);
  writeln(f,rawfile[44]); writeln(f,''); writeln(f,'Delete Inactive ',config.nukedays); writeln(f,'');

	flush(f);
	close(f);
end;

procedure guilt;
begin
	gotoxy(10,22);
	if
		registree
	then
    wln('`NThank you for registering Rancho Nevada!')
	else
		begin
			gotoxy(1,22);
      wln('`J         Please register Rancho Nevada!  It''s only `P$15`J!');
      wln('`B         Visit http://vvv.com/~~tommy on the Web for the latest version!');
      wln('`B         Call Tommy''s Holiday Camp BBS - +1 250 361 4549');
		end;
end;

procedure quitsave;
var t2:char;
begin
	writeln; yndefault:=true;
	gotoxy(1,22); clreol;
	gotoxy(1,23); clreol;
	gotoxy(1,24); clreol;
	gotoxy(10,21); clreol;
  w('`LSave Changes? `K(Y/n) ');
	t2:=upcase(yn);
	if
		t2='Y'
	then
		saveout('RANCHO.CFG');
end;

procedure gitit(var x:longint);
var tstr:string[6];
begin
	gotoxy(12,21); clreol;
  wln('`GEnter`M to keep `G'+int2str(x)); clreol;
  w('           `LEnter new value now: `P`e     ');
	tstr:=getln(5);
	textattr:=white; clreol;
	if tstr='' then exit;
	x:=str2int(tstr);
end;

procedure dhelp(start,finish:integer);
var i:integer; tstr:String;
begin
  textattr:=white;
  wln('');
	for i:=start to finish do begin tstr:=copy(rawfile[i],3,127); wln(tstr); end;
  wln('');
  w('`<Any Key`>');
	repeat until keypressed; tch:=readkey;
end;

procedure confhelp;
var tch:char;
begin
  GOTOXY(1,20); CLREOL;
  GOTOXY(1,21); CLREOL;
	gotoxy(1,22); clreol;
	gotoxy(1,23); clreol;
	gotoxy(1,24); clreol;
  gotoxy(1,19); clreol;
  w('`JHit the number/letter of the option you need help with `ž');
  get('?123456789ABCDEFGHIJKL'#27); tch:=upcase(ctmp);
  wln('`('+tch+'`)');
	case tch of
		'1': dhelp(1,1);
		'2': dhelp(2,2);
		'3': dhelp(3,3);
		'4': dhelp(4,4);
		'5': dhelp(5,5);
		'6': dhelp(6,6);
		'7': dhelp(7,7);
		'8': dhelp(8,8);
		'9': dhelp(9,11);
    'A': dhelp(12,13);
    'B': dhelp(14,15);
    'C': dhelp(19,20);
    'D': dhelp(21,23);
    'E': dhelp(24,27);
    'F': dhelp(28,28);
    'G': dhelp(29,29);
    'H': dhelp(30,32);
    'I': dhelp(41,42);
    'J': dhelp(41,42);
    'K': dhelp(41,42);
    'L': dhelp(43,44);
	end;
end;


procedure configedit;
var i:integer; j,l:longint; s:String;
		tch:char;
label _comenu;
begin
_comenu:
	clrscr;
	guilt;
	gotoxy(1,1);
	writeln;
  wln('                     `<  Game Options Setup  `>');
	wln('');
  wln('  `{1`}`NDaily Plays:      `O'+int2str(config.maxplays));
  wln('  `{2`}`NMoves/Round:      `O'+int2str(config.maxmoves));
  wln('  `{3`}`NAV Term Uses:     `O'+int2str(config.maxschool));
  wln('  `{4`}`NDrinks/Round:     `O'+int2str(config.maxjoust));
  wln('  `{5`}`NMax LevelDiff:    `O'+int2str(config.maxdiff));
  wln('  `{6`}`NPay Robots %:     `O'+int2str(config.robotpaypercent)+'`N%');
  wln('  `{7`}`NXP Robots %:      `O'+int2str(config.robotxppercent)+'`N%');
  wln('  `{8`}`NLevel Pay:        `O'+int2str(config.bumppay));
  wln('  `{9`}`NMinus R/L %:      `O'+int2str(config.minushp)+'`N%');
  wln('  `{A`}`NRobot Reroll %:   `O'+int2str(config.robotreroll)+'`N%');
  wln('  `{B`}`NCornered %:       `O'+int2str(config.corner)+'`N%');
	window(40,1,80,25); gotoxy(1,4);
    w('  `{C`}`NVKR Uses Moves:   `O'); if config.vkrmove then writeln('Yes') else writeln('No');
  wln('  `{D`}`NMax Jacuzzi Uses: `O'+int2str(config.maxjacuzzi));
  wln('  `{E`}`NJacuzzi Luck:     `O'+int2str(config.jacuzziluck));
  wln('  `{F`}`NKeyboard Timeout: `O'+int2str(config.timeout)+' `Nmin.');
  wln('  `{G`}`NStarting Room:    `O'+int2str(config.startroom));
    w('  `{H`}`NANSi Colour:      `O');
			case config.ansimode of
				0: wln('DoorInfo');
				1: wln('Ask User');
				2: wln('Detect');
			end;
    w('  `{I`}`NRobot Gender:     `O');
			case config.robotgender of
				0: wln('Female');
				1: wln('Male');
				2: wln('Both');
			end;
    w('  `{J`}`NRobot Preference: `O');
			case config.robotpreference of
				0: wln('Bisexual');
				1: wln('Random');
				2: wln('Straight');
				3: wln('Gay');
			end;
    w('  `{K`}`NRobot LastNames:  `O');
			case config.robotlastname of
				0: wln('On');
				1: wln('Off');
			end;

  wln('  `{L`}`NDelete Inactive:  `O'+int2str(config.nukedays)+'`N days');
	window(1,1,80,25);
	gotoxy(1,18);
	wln(''); clreol;
  wln('           `(?`)`N for help `{Q`}`M to Quit');
    w('           `OWhich? `ž');
	get('?123456789ABCDEFGHIJKLMNPRSTQ'#27); tch:=upcase(ctmp);
	case tch of
		'Q',#27: exit;
		'?': confhelp;
		'1': begin l:=config.maxplays; gitit(l); config.maxplays:=l; end;
		'2': begin l:=config.maxmoves; gitit(l); config.maxmoves:=l; end;
		'3': begin l:=config.maxschool; gitit(l); config.maxschool:=l; end;
		'4': begin l:=config.maxjoust; gitit(l); config.maxjoust:=l; end;
		'5': begin l:=config.maxdiff; gitit(l); config.maxdiff:=l; end;
		'6': begin l:=config.robotpaypercent; gitit(l); config.robotpaypercent:=l; end;
		'7': begin l:=config.robotxppercent; gitit(l); config.robotxppercent:=l; end;
		'8': begin l:=config.bumppay; gitit(l); config.bumppay:=l; end;
		'9': begin l:=config.minushp; gitit(l); config.minushp:=l; end;
    'A': begin l:=config.robotreroll; gitit(l); config.robotreroll:=l; end;
    'B': begin l:=config.corner; gitit(l); config.corner:=l; end;
    'C': config.vkrmove:=not(config.vkrmove);
    'D': begin l:=config.maxjacuzzi; gitit(l); config.maxjacuzzi:=l; end;
    'E': begin l:=config.jacuzziluck; gitit(l); config.jacuzziluck:=l; end;
    'F': begin l:=config.timeout; gitit(l); config.timeout:=l; end;
    'G': begin l:=config.startroom; gitit(l); config.startroom:=l; end;
    'H': begin inc(config.ansimode); config.ansimode:=config.ansimode mod 3; end;
    'I': begin inc(config.robotgender); config.robotgender:=config.robotgender mod 3; end;
    'J': begin inc(config.robotpreference); config.robotpreference:=config.robotpreference mod 4; end;
    'K': begin inc(config.robotlastname); config.robotlastname:=config.robotlastname mod 2; end;
    'L': begin l:=config.nukedays; gitit(l); config.nukedays:=l; end;
	end;
	goto _comenu;
end;

procedure setupcomports;
var i:integer; j:longint; s:String;
		tch:char;
label _cmenu;
begin
_cmenu:
	clrscr;
	guilt;
	gotoxy(1,1);
	writeln;	writeln;	writeln;
  wln('                         `<  Comm Port Setup  `>');
	wln('');
  w('               `{U`} `NUse FOSSIL: `O');
	if config.nofossil then writeln('No') else writeln('Yes');
	wln('');
  wln('                      `JAddress     IRQ');
  wln('        `BÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ');
	for i:=0 to protcomm.maxphysport do
    wln('          `FPort `N'+int2str(i+1)
       +'   `{'+int2str(i+1)
       +'`} `O'+hexw(protcomm.porttable[i].base)
       +'    `{'+chr(65+i)
       +'`} `L'+int2str(protcomm.porttable[i].irq));
	wln(''); clreol;
  wln('           `OQ`M to Quit');
    w('           `OWhich? `ž');
	get('12345678abcdefghqu'#27);
	tch:=upcase(ctmp);
	case tch of
		'1'..'8': begin
								i:=ord(tch)-49;
								gotoxy(10,22); clreol;
                w('Port '+int2str(i+1)+' address: `e    `a`1');
								gotoxy(26,22); textattr:=white+16*blue;
								s:=getln(4);
								j:=hex2long(s);
								protcomm.porttable[i].base:=j;
								textattr:=white; clreol;
							end;
		'A'..'H': begin
								i:=ord(tch)-65;
								gotoxy(10,22); clreol;
                w('Port '+int2str(i+1)+' IRQ: `e  `a`1');
								gotoxy(22,22); textattr:=white+16*blue;
								s:=getln(2);
								j:=str2int(s);
								protcomm.porttable[i].irq:=j;
								textattr:=white; clreol;
							end;
		'Q',#27: exit;
		'U': config.nofossil:=not(config.nofossil);
	end;
	goto _cmenu;
end;

procedure mainmenu;
var tch:char;
label _re;
begin
_re:
	clrscr;
	guilt;
	gotoxy(1,1);
	writeln;	writeln;	writeln;	writeln;
  wln('`P                    `< `ARN `> Rancho Nevada Config `< `ARN `>');
  wln('                             `Bfor version 5.0');
  wln('          `ICopyright 1997 Whirlwind Software - All Rights Reserved');
	wln('');
	wln('');
	wln('');
  wln('           `{ P `}`L Player Editor');
	wln('');
  wln('           `{ C `}`L Config Editor');
	wln('');
  wln('           `{ S `}`L Set up Com Ports');
	wln('');
  wln('           `{ Q `}`L Quit This Program');
	wln('');
    w('           `OWhich? `ž');
	get('pcsq'); tch:=upcase(ctmp);
	case tch of
		'P': begin edituser(1); end;
		'C': configedit;
		'S': setupcomports;
		'Q': begin quitsave; exit; end;
	end;
	window(1,1,80,25);
	goto _re;
end;

begin
	localansi:=true; ansi:=true;
	buildconfig; registree:=checkkey;
	mainmenu;
end.

