unit winner;
{$O+,F+}
{$E+}
{$N+}
interface

procedure purgeusers;
procedure youwin;
function center80(s:string):string;

implementation

uses dos,crt,bbskv,bbskern,engine2,rgoods,sys_msg;

function center80(s:string):string;
var i,j:integer; t:string;
begin
  i:=36-(length(strip_embed(s+' ')) div 2);
  t:=''; for j:=1 to i do t:=t+' '; center80:=t+s;
end;

procedure purgeusers;
var f1,f2:file of userrec;
    tu:userrec;
    tmp:byte;
    tname:string;
    tgender:t_gender;
    torientation:t_orientation;
    i2,
    index:integer;

begin
  for i2:=1 to maxuser do
  begin
    tu:=userlog^[i2];
    fillchar(tu.spell,sizeof(tu.spell),#00);
    tu.room:=1;
    tu.tori:=false;
    tu.lastvkr:=20;
    tu.xp:=100;
    tu.level:=1;
    tu.skill:=10;
    tu.stamina:=10;
    tu.knowledge:=10;
    tu.talent:=10;
    tu.jwins:=0;
    tu.jlosses:=0;
    tu.jls:=0;
    tu.jws:=0;
    tu.gp:=500;
    tu.bankgp:=500;
    tu.hp:=10;
    tu.maxhp:=10;
    tu.coord:=10;
    tu.maxcoord:=10;
    tu.armor:=1;
    tu.weapon:=1;
    tu.playstotal:=0;
    tu.playstoday:=0;
(*    tu.lastplayed:=ds1970; *)
    tu.robotfactor:=random(128);
    tmp:=random(100);
    if tmp<10 then tu.robotfactor:=tu.robotfactor+128;
    tu.recovering:=false;
    tu.givenvd:=false;
    userlog^[i2]:=tu;
  end;
  user:=userlog^[thisusernumber];
  writeuserlog;
end;

procedure youwin;
var f:text;
    g:file of eventrec;
    s:string;
begin
  youwon:=true;
  s:=center80('`K*** `P'+user.name+' `K***')+crlf+'   '+
     center80('`Jhas beaten Rancho Nevada co-owner')+crlf+'   '+
     center80('`L'+user2.name)+crlf+'   '+
     center80('`Jand won the game!');
  log(s);
  assign(f,'RANCHO.TOP');
  rewrite(f);
  writeln(f,upcasestr(user.name));
  close(f);
  if
    ansi
  then
    sendtext('YOUWIN.ANS')
  else
    sendtext('YOUWIN.ASC');
  purgeusers;

  log(g_sysmsg(711));
  sendln('');
  anykey;
  nukefile(evtname);
  nukefile(msgname);
  sysmsg(712);
  textattr:=lightgray; WIndow(1,1,80,4); clrscr;
  Window(1,24,80,25); ClrScr; Window(1,1,80,25); GotoXY(1,25);
  youwon:=true; shutdown;
end;

begin
end.
