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

procedure winstory;
procedure encore(var playerwon:boolean);
procedure encore2(var playerwon:boolean);
procedure donefuck(playerwon:boolean);
procedure donefuck2(playerwon:boolean);
procedure online_attack(u2num:integer; var playerwon:boolean);
procedure online_defend(u2num:integer);
procedure encore_online(u2num:integer; var playerwon:boolean);
procedure encore2_online(u2num:integer; var playerwon:boolean);
function  awaitusync:string;

var onlineencounter:boolean;

implementation

uses Dos,CRT,bbskv,bbskern,engine2,rgoods,ranchlin,message1,iconfig,
     toyinfo,winner,miscplay,miscpl2,miscpl3,miscpl4,miscpl5,sys_msg;

function adjust(hp:longint):longint;
var tmp,tmp2:longint;
begin
  tmp:=hp div 2;
  tmp2:=random(tmp);
  adjust:=hp-tmp2;
end;

procedure isend(s:string);
var i:integer;
begin
  for i:=1 to length(s) do
    if
      (s[i]=#96) and (s[i+1]='Y')
    then
      begin
        delete(s,i,2);
        insert('`L'+user2.name+'`G',s,i);
      end;
  dumbwrap(s);
end;

procedure isendln(s:string);
begin
  isend(s);
  sendln('');
end;

procedure cookie(cookiename:string; mode:byte);
  function checkknown(cookiename:string):integer;
  var cookiefile:text;
      tempstr:string;
      count:integer;
      count2:integer;
  begin
    count:=-1;
    cookiename:=upcasestr(cookiename);
    if
      exist(cookiename)
    then
      begin
        assign(cookiefile,cookiename);
        reset(cookiefile);
        readln(cookiefile,tempstr);
        close(cookiefile);
        val(tempstr,count,count2);
     end;
     checkknown:=count;
  end;
var cookiefile:text;
    tempstr:string[80];
    count:integer;
    count2:integer;
    lincount: integer;
    rnd:integer;
begin
  yndefault:=no;
  changecolour('G');
  cookiename:=upcasestr(cookiename);
  if
    not(exist(cookiename)) then exit;

  count:=checkknown(cookiename);
  if
    count>=0
  then
    begin
      assign(cookiefile,cookiename);
      if
        count=0
      then
        begin
          reset(cookiefile);
          repeat
            readln(cookiefile,tempstr);
            if
              tempstr='###'
            then
              inc(count);
          until eof(cookiefile);
          close(cookiefile);
        end;
        rnd:=random(count)+1;
        reset(cookiefile);
        count2:=0;
        repeat
          readln(cookiefile,tempstr);
          if
            tempstr='###'
          then
            inc(count2);
        until count2=rnd;
        tempstr:='';
        abort:=false;
        while ((tempstr<>'###') and (not(eof(cookiefile)))) and (not abort) do
        begin
          readln(cookiefile,tempstr);
          if tempstr<>'###' then isend(tempstr);
        end;
        close(cookiefile);
    end;
end;

procedure winstory;
begin
  sendln('`,`L');
  if lostcarrier then begin nocarrier; quitnow:=true; exit; end;
  changecolour('K');
  anykey;
  if lostcarrier then begin nocarrier; quitnow:=true; exit; end;
  sendln('');
  if (user.gender=male) and (user2.gender=male) then cookie('STORYMM.DAT',0);
  if (user.gender=male) and (user2.gender=female) then cookie('STORYMF.DAT',0);
  if (user.gender=female) and (user2.gender=male) then cookie('STORYFM.DAT',0);
  if (user.gender=female) and (user2.gender=female) then cookie('STORYFF.DAT',0);
  sendln(crlf);
  if lostcarrier then begin nocarrier; quitnow:=true; exit; end;
  anykey;
  if lostcarrier then begin nocarrier; quitnow:=true; exit; end;
  send('`,`L');
end;

procedure encore(var playerwon:boolean);  {Player tries to seduce NPC}
var
    amt:longint;
    tch:char;
    surprise,done:boolean;
    minushp:longint;
    action:integer;
    tmpxp:comp;
    diff:integer;
    etmp:extended;
begin
  onlineencounter:=false;
  if lostcarrier then begin nocarrier; quitnow:=true; exit; end;
  disease:=false;
  abortedfuck:=false;
  spellpriv[11]:=false;
  spellpriv[12]:=false;
  begin
    {Insert the actual mechanical combat code here}
    surprise:=false;
    if
      (user.condoms<6)
    and
      (user.condoms>0)
    then
      begin
        parameter[1]:=i2sc(user.condoms);
        sysmsg(180);
      end;
    if
      (user.gender<>female) or (user2.gender<>female) {no condom for FF encounters}
    then
      begin
        if
          user.condoms=0
        then
          begin
            sysmsg(181);
            distemp:=random(100);
            if
              distemp<20
            then
              disease:=true;
          end
        else
          begin
            dec(user.condoms);
          end;
      end;
    if user.skill>=user2.skill then surprise:=true;
    if
      surprise
    then
      sysmsg(182)
    else
      begin
        parameter[1]:=user2.name;
        sysmsg(183);
      end;
    done:=false;
    if lostcarrier then begin nocarrier; quitnow:=true; exit; end;
    repeat
      if lostcarrier then begin nocarrier; quitnow:=true; exit; end;
      begin
        if user.hp<0 then user.hp:=0;
        parameter[1]:=i2sc(user.hp);
        parameter[2]:=user2.name;
        parameter[3]:=i2sc(user2.hp);
        sysmsg(184);
      updatesbar;
      if surprise then
      begin
        changecolour('L');
        updatesbar;
        spellpriv[5]:=false;
        spellpriv[11]:=false;
        spellpriv[12]:=false;
        if
          invkr
        then
          begin
            spellpriv[1]:=true;
            spellpriv[2]:=true;
            spellpriv[3]:=false;
            spellpriv[4]:=true;
            spellpriv[7]:=true;
            spellpriv[8]:=false;
            spellpriv[9]:=true;
            spellpriv[10]:=true;
          end
        else
          begin
            spellpriv[1]:=false;
            spellpriv[2]:=false;
            spellpriv[3]:=true;
            spellpriv[4]:=false;
            spellpriv[7]:=false;
            spellpriv[8]:=true;
            spellpriv[9]:=true;
            spellpriv[10]:=true;
          end;

        repeat
          if lostcarrier then begin nocarrier; quitnow:=true; exit; end;
          giveupturn:=false;
          sysmsg(185);
          get(#13'rug?');
          if ctmp=#13 then ctmp:='G';
          if lostcarrier then begin nocarrier; quitnow:=true; exit; end;
          case upcase(ctmp) of
            '?' : begin
                    sysmsg(186);
                    if
                      ansi
                    then
                      sendtext('SEXHELP.ANS')
                    else
                      sendtext('SEXHELP.ASC');
                  end;
            'U' : begin
                    sysmsg(187);
                    usespecial;
                    if abortedfuck or quitnow then exit;
                  end;
            'R' : begin
                    sysmsg(188);
                    surprise:=false;
                    if
                      invkr
                    then
                      sysmsg(189)
                    else
                      if
                        (margin(user.skill*2,user2.skill,100))
                      then
                        begin
                          sysmsg(190);
                          abortedfuck:=true;
                          exit;
                        end
                      else
                        begin
                          parameter[1]:=user2.name;
                          sysmsg(191);
                        end;
                    end;
            #13,'G' : sysmsg(192);
          end; {case}
      until (upcase(ctmp)='G') or quitnow or giveupturn or lostcarrier;
      if lostcarrier then begin nocarrier; quitnow:=true; exit; end;
      end;
        {Attacker's Move}
        if
          ((surprise) and (not done) and (not giveupturn))
        then
          begin
            giveupturn:=false;
            etmp:=(user2.armor*(user2.stamina-9)); if etmp<1 then etmp:=1;
            etmp:=raisepower(etmp,0.5);
            ltmp:=round(etmp);
            if ltmp=0 then ltmp:=1;
            minushp:=user.weapon; minushp:=minushp*minushp;
            minushp:=longint(((((minushp div 6)+1)*user.stamina) div (ltmp))*config.minushp div 100);
            minushp:=longint(minushp shr 1);
{            if invkr then minushp:=minushp*3;}
            minushp:=adjust(minushp); {Introduce a random element into the hit value}
            inc(minushp);
            case random(30) of
              0:
                              begin
                                minushp:=longint(minushp*3);
                                sendln(crlf+'`M *** `O ULTRA MOVE! `M***');
                              end;
              1..3:
                              begin
                                minushp:=longint(minushp*2);
                                sendln(crlf+'`M *** `O SUPER MOVE! `M***');
                              end;
            end;
            if (user.weapon=9999) then minushp:=user2.hp+1;
            if
              not(margin(user.skill*3,user2.skill,200))
            then       {Attacker's skill is far too low}
              begin
                parameter[1]:=mixedcase(getgen(user2.gender,1));
                parameter[2]:=user2.name;
                sysmsg(193);
              end
            else
              begin
                user2.hp:=user2.hp-minushp;
                if user2.hp<1 then begin done:=true; playerwon:=true; end;
                action:=random(25)+1;
                parameter[1]:=g_sysmsg(193+action);
                parameter[2]:=getgen(user2.gender,3);
                parameter[3]:=weaponname(user.weapon);
                parameter[4]:=i2sc(minushp);
                parameter[5]:=user2.name;
                sysmsg(219);
              end;
          end; {End of attacker's move}
      if user2.hp<1 then begin done:=true; playerwon:=true; end;
      begin
        {defender's Move}
        if
          not(done)
        then
          begin
            surprise:=true;
            etmp:=(user.armor*(user.stamina-9));  if etmp<1 then etmp:=1;
            etmp:=raisepower(etmp,0.5);
            ltmp:=round(etmp);
            if ltmp=0 then ltmp:=1;
            minushp:=user2.weapon; minushp:=longint(minushp*minushp);
            minushp:=longint(((((minushp div 6)+1)*user2.stamina) div (ltmp))*config.minushp div 100);
            minushp:=longint(minushp shr 1);
{            if invkr then minushp:=minushp shr 1; }
            minushp:=adjust(minushp); {Introduce a random element into the hit value}
            inc(minushp);
            case random(30) of
              0:
                              begin
                                minushp:=longint(minushp*3);
                                sendln(crlf+'`F *** `N ULTRA MOVE! `F***');
                              end;
              1:
                              begin
                                minushp:=longint(minushp*2);
                                sendln(crlf+'`F *** `N SUPER MOVE! `F***');
                              end;
            end;
            if (user2.armor=9999) then minushp:=user.hp+1;
            if
              not(margin(user2.skill*3,user.skill,200))
            then       {Defender's skill is far too low}
              begin
                parameter[1]:=getgen(user2.gender,2);
                parameter[2]:=user2.name;
                sysmsg(220);
              end
            else
              begin
                user.hp:=user.hp-minushp;
                if user.hp<1 then begin done:=true; playerwon:=false; end;
                action:=random(25)+1;
                parameter[1]:=getgen(user2.gender,6);
                parameter[2]:=getgen(user2.gender,2);
                parameter[3]:=armorname(user2.armor);
                parameter[4]:=i2sc(minushp);
                parameter[5]:=user2.name;
                parameter[6]:=weaponname(user2.weapon);
                parameter[7]:=g_sysmsg(221+action);
                sysmsg(221);
              end;
              updatesbar;
          end; {End of defender's move}

      end;


      end; {repeat}
    until done or quitnow or lostcarrier;
    if lostcarrier then begin nocarrier; quitnow:=true; exit; end;
  end;
end;

procedure encore2(var playerwon:boolean); {Player defends virtue against NPC}
var
    amt:longint;
    tch:char;
    surprise,done:boolean;
    minushp:longint;
    action:integer;
    tmpxp:comp;
    diff:integer;
    etmp:extended;
begin
  onlineencounter:=false;
  if lostcarrier then begin nocarrier; quitnow:=true; exit; end;
  disease:=false;
  abortedfuck:=false;
  begin
    {Insert the actual mechanical combat code here}
    surprise:=false;
    disease:=false;
    if user.skill>=user2.skill then surprise:=true;
    if
      surprise
    then
      sysmsg(247)
    else
      begin
        parameter[1]:=user2.name;
        sysmsg(248);
      end;
    done:=false;
    if lostcarrier then begin nocarrier; quitnow:=true; exit; end;
    repeat
      if lostcarrier then begin nocarrier; quitnow:=true; exit; end;
      begin
        if user.hp<0 then user.hp:=0;
        parameter[1]:=i2sc(user.hp);
        parameter[2]:=user2.name;
        parameter[3]:=i2sc(user2.hp);
        sysmsg(249);
      updatesbar;
      if surprise then
      begin
        changecolour('L');
        updatesbar;
        repeat
          if lostcarrier then begin nocarrier; quitnow:=true; exit; end;
          giveupturn:=false;
          parameter[1]:=user2.name;
          sysmsg(250);
          get(#13're?');
          if ctmp=#13 then ctmp:='E';
          if lostcarrier then begin nocarrier; quitnow:=true; exit; end;
          case upcase(ctmp) of
            '?' : begin
                    sysmsg(186);
                    if
                      ansi
                    then
                      sendtext('SEXHELP2.ANS')
                    else
                      sendtext('SEXHELP2.ASC');
                  end;
            'R' : begin
                    sysmsg(188);
                    surprise:=false;
                    if
                      (margin(user.skill*2,user2.skill,100))
                    then
                      begin
                        sysmsg(251);
                        abortedfuck:=true;
                        exit;
                      end
                    else
                      begin
                        parameter[1]:=user2.name;
                        sysmsg(252);
                      end;
                  end;
            'E' : sysmsg(253);
          end; {case}
      until (upcase(ctmp)='E') or quitnow or giveupturn or lostcarrier;
      end;
        {Defender's Move} {Was attacker's in ENCORE}
        if
          ((surprise) and (not done) and (not giveupturn))
        then
          begin
            surprise:=true;
            etmp:=(user2.weapon*(user2.stamina-9)); if etmp<1 then etmp:=1;
            etmp:=raisepower(etmp,0.5);
            ltmp:=round(etmp);
            if ltmp=0 then ltmp:=1;

            minushp:=user.armor; minushp:=minushp*minushp;
            minushp:=longint(((((minushp div 6)+1)*user.stamina) div (ltmp)));
            minushp:=longint(minushp shr 1);
{            if invkr then minushp:=minushp*3; }
            minushp:=adjust(minushp); {Introduce a random element into the hit value}
            inc(minushp);
            case random(30) of
              0:
                              begin
                                minushp:=longint(minushp*3);
                                sendln(crlf+'`M *** `O ULTRA MOVE! `M***');
                              end;
              1..3:
                              begin
                                minushp:=longint(minushp*2);
                                sendln(crlf+'`M *** `O SUPER MOVE! `M***');
                              end;
            end;
            if (user.armor=9999) then minushp:=user2.hp+1;
            if
              not(margin(user.skill*3,user2.skill,200))
            then       {Your skill is far too low}
              begin
                parameter[1]:=user2.name;
                sysmsg(254);
              end
            else
              begin
                user2.hp:=user2.hp-minushp;
                if user.hp<1 then begin done:=true; playerwon:=false; end;
                action:=random(25)+1;
                parameter[1]:=armorname(user.armor);
                parameter[2]:=i2sc(minushp);
                parameter[4]:=weaponname(user.weapon);
                parameter[5]:=user2.name;
                parameter[3]:=g_sysmsg(255+action);
                sysmsg(255);
              end;
              updatesbar;
          end; {End of defender's move}
      if user2.hp<1 then begin done:=true; playerwon:=true; end;
      begin
        {Attacker's Move} {Was defender's in ENCORE}
        if
          not(done)
        then
          begin
            surprise:=true;
            giveupturn:=false;
            etmp:=(user.armor*(user.stamina-9)); if etmp<1 then etmp:=1;
            etmp:=raisepower(etmp,0.5);
            ltmp:=round(etmp);
            if ltmp=0 then ltmp:=1;
            minushp:=user2.weapon; minushp:=minushp*minushp;
            minushp:=longint(((((minushp div 6)+1)*user2.stamina) div (ltmp))*config.minushp div 100);
{            minushp:=longint(minushp shr 1); }
            minushp:=adjust(minushp); {Introduce a random element into the hit value}
            inc(minushp);
            case random(30) of
              0:
                              begin
                                minushp:=longint(minushp*3);
                                sendln(crlf+'`F *** `N ULTRA MOVE! `F***');
                              end;
              1..2:
                              begin
                                minushp:=longint(minushp*2);
                                sendln(crlf+'`F *** `N SUPER MOVE! `F***');
                              end;
            end;
            if (user2.weapon=9999) then minushp:=user.hp+1;
            if
              not(margin(user.skill*3,user2.skill,200))
            then       {Attacker's skill is far too low}
              begin
                parameter[1]:=user2.name;
                sysmsg(281);
              end
            else
              begin
                user.hp:=user.hp-minushp;
                if user.hp<1 then begin done:=true; playerwon:=false; end;
                action:=random(25)+1;
                parameter[1]:=mixedcase(getgen(user2.gender,6));
                parameter[2]:=g_sysmsg(282+action);
                parameter[3]:=getgen(user2.gender,2);
                parameter[4]:=weaponname(user2.weapon);
                parameter[5]:=i2sc(minushp);
                parameter[6]:=user2.name;
                sysmsg(282);
              end;
          end; {End of defender's move}
        end;
      end; {repeat}
    until done or quitnow or lostcarrier;
  end;
  if lostcarrier then begin nocarrier; quitnow:=true; exit; end;
end;

procedure donefuck(playerwon:boolean);
var tch:char;
    tmpxp:comp;
    action:integer;
begin
  if lostcarrier then begin nocarrier; quitnow:=true; exit; end;
            if
              playerwon
            then
              begin  {Player won - seduced non-playing character}
                updatesbar;
                user2.recovering:=true;
                if
                  not(user2.robot)
                then
                  begin
                    parameter[1]:=user.name;
                    parameter[2]:=user2.name;
                    log(g_sysmsg(308));
                  end;
                parameter[1]:=user2.name;
                sysmsg(309);
                parameter[1]:=user.name;
                tempevent.name:=user2.name;
                tempevent.txt:=g_sysmsg(310);
                winstory;
                user2.xp:=user2.xp*0.9;
                if
                  user2.weapon>user.weapon
                then
                  begin
                    parameter[1]:=weaponname(user2.weapon);
                    tempevent.txt:=tempevent.txt+g_sysmsg(311);
                    parameter[1]:=getgen(user2.gender,2);
                    parameter[2]:=user2.name;
                    parameter[3]:=weaponname(user2.weapon);
                    sysmsg(312);
                    itemswaptemp:=user.weapon;
                    user.weapon:=user2.weapon;
                    user2.weapon:=itemswaptemp;
                    newsbar;
                  end;
                if
                  user2.armor>user.armor
                then
                  begin
                    parameter[1]:=armorname(user2.armor);
                    tempevent.txt:=tempevent.txt+g_sysmsg(313);
                    parameter[1]:=getgen(user2.gender,2);
                    parameter[2]:=user2.name;
                    parameter[3]:=armorname(user2.armor);
                    sysmsg(314);
                    itemswaptemp:=user.armor;
                    user.armor:=user2.armor;
                    user2.armor:=itemswaptemp;
                    newsbar;
                  end;
                parameter[1]:=c2sc(user2.gp);
                sysmsg(315);
                if
                  (user2.gp>0)
                then
                  begin
                    parameter[1]:=getgen(user.gender,6);
                    tempevent.txt:=tempevent.txt+g_sysmsg(316);
                  end;
                tmpxp:=(user2.xp/2)+(random*(user2.xp)/2);
                parameter[1]:=c2sc(tmpxp);
                sysmsg(317);
                user.gp:=user.gp+abs(user2.gp); user2.gp:=0;
                if not(invkr) then awardxp(user,tmpxp) else user.xp:=user.xp+tmpxp;
                if not(user2.robot) then addevent(tempevent);
                updatesbar;
                if not(invkr) and not(user2.robot) then
                begin
                  parameter[1]:=user2.name;
                  sysmsg(318);
                  yndefault:=false;
                  tch:=yn;
                  if lostcarrier then begin nocarrier; quitnow:=true; exit; end;
                  if
                  tch='Y'
                  then
                    begin
                      parameter[1]:=user.name;
                      parameter[2]:=user2.name;
                      sysmsg(319);
                      quoted:=false;
                      send2robot:=user2.robot;
                      entermsg(user.name,user2.name,quoted);
                    end;
                end;
              end;
            if
              not(playerwon)
            then
              begin  {Player lost - was repelled by non-playing character}
                user.xp:=user.xp*0.9;
                getoutvkr:=true;
                if
                  true
                then
                  begin
                    parameter[1]:=user.name;
                    parameter[2]:=user2.name;
                    log(g_sysmsg(320));
                  end;
                tempevent.name:=user2.name;
                parameter[1]:=user.name;
                tempevent.txt:=g_sysmsg(321);
                parameter[1]:=user2.name;
                parameter[2]:=getgen(user2.gender,3);
                sysmsg(322);
                parameter[1]:=c2sc(user.gp);
                parameter[2]:=c2sc(user.xp/4);
                tempevent.txt:=tempevent.txt+g_sysmsg(323);
                verbbump:=false;
                if
                  user2.robot
                then
                  awardxp(user2,user.xp)
                else
                  user2.xp:=user2.xp+(user.xp/2)+(random*(user2.xp)/2);
                verbbump:=true;
                parameter[1]:=getgen(user2.gender,6);
                parameter[2]:=getgen(user2.gender,8);
                parameter[3]:=c2sc(user.gp);
                parameter[4]:=user2.name;
                sysmsg(324);
                if user2.gp<0 then user2.gp:=0;
                user2.gp:=user2.gp+user.gp;
                user.gp:=0;
                newsbar;
                if
                  user2.weapon<user.weapon
                then
                  begin
                    parameter[1]:=getgen(user.gender,2);
                    parameter[2]:=weaponname(user.weapon);
                    parameter[3]:=user.name;
                    tempevent.txt:=tempevent.txt+g_sysmsg(325);
                    parameter[1]:=getgen(user2.gender,6);
                    parameter[2]:=weaponname(user.weapon);
                    parameter[3]:=user2.name;
                    sysmsg(326);
                    itemswaptemp:=user.weapon;
                    user.weapon:=user2.weapon;
                    user2.weapon:=itemswaptemp;
                    newsbar;
                  end;
                if
                  user2.armor<user.armor
                then
                  begin
                    parameter[1]:=getgen(user.gender,2);
                    parameter[2]:=armorname(user2.armor);
                    parameter[3]:=user.name;
                    tempevent.txt:=tempevent.txt+g_sysmsg(327);
                    parameter[1]:=getgen(user2.gender,6);
                    parameter[2]:=armorname(user.armor);
                    parameter[3]:=user2.name;
                    sysmsg(328);
                    itemswaptemp:=user.armor;
                    user.armor:=user2.armor;
                    user2.armor:=itemswaptemp;
                    newsbar;
                  end;
                if not(user2.robot) then addevent(tempevent);
              end;
(*              if user.condoms=0 then disease:=(random(4)=0) else disease:=false;*)
              if
                disease
              then
                begin
                  updatesbar;
                  fillchar(tempevent,sizeof(tempevent),#00);
                  action:=random(10)+1;
                  parameter[1]:=user.name;
                  parameter[2]:=g_sysmsg(329+action);
                  tempevent.name:=user2.name;
                  tempevent.txt:=g_sysmsg(329);
                  if not(user2.robot) then addevent(tempevent);

                  user.maxhp:=(user.maxhp*80) div 100;
                  parameter[1]:=i2sc(user.maxhp);
                  g_sysmsg(340);
                  handlevd;
                end;
end;

procedure donefuck2(playerwon:boolean);
var tch:char;
    action:integer;
    tmpxp:comp;
begin
  anykey;
  if
    not playerwon
  then
    begin  {jumping character won!}
      updatesbar;
      parameter[1]:=user2.name;
      parameter[2]:=user.name;
      log(g_sysmsg(341)); {User2 seduced and had wild sex with User}

      parameter[1]:=user.name;
      parameter[2]:=user2.name;
      sysmsg(342); {You lost all your resistance!}

      tempevent.name:=user2.name;
      parameter[1]:=user.name;      {This log tells User2 she seduced User}
      tempevent.txt:=g_sysmsg(343); {log:You seduced and had wild sex with User}
      winstory;
      tmpxp:=user.xp*config.loserxp;
      tmpxp:=tmpxp/100;
      user.xp:=user.xp+tmpxp;
      if
        user.weapon>user2.weapon
      then
        begin
          parameter[1]:=getgen(user.gender,2);
          parameter[2]:=weaponname(user2.weapon);
          parameter[3]:=user.name;
          tempevent.txt:=tempevent.txt+g_sysmsg(344);
          parameter[1]:=weaponname(user.weapon);
          sysmsg(345);
          itemswaptemp:=user.weapon;
          user.weapon:=user2.weapon;
          user2.weapon:=itemswaptemp;
          newsbar;
        end;
      if
        user.armor>user2.armor
      then
        begin
          parameter[1]:=getgen(user.gender,2);
          parameter[2]:=armorname(user.armor);
          parameter[3]:=user.name;
          tempevent.txt:=tempevent.txt+g_sysmsg(346);

          parameter[1]:=armorname(user.armor);
          parameter[2]:=user2.name;
          sysmsg(347);

          itemswaptemp:=user.armor;
          user.armor:=user2.armor;
          user2.armor:=itemswaptemp;
          newsbar;
        end;
      parameter[1]:=user2.name;
      sysmsg(348);
      if
        (user.gp>0)
      then
        begin
          parameter[1]:=getgen(user.gender,2);
          parameter[2]:=c2sc(user.gp);
          parameter[3]:=user.name;
          tempevent.txt:=tempevent.txt+g_sysmsg(349);
        end;
      tmpxp:=(user2.xp/2)+(random*(user2.xp)/2);
      if user2.gp<0 then user2.gp:=0;
      user2.gp:=user2.gp+user.gp; user.gp:=0;
      user2.xp:=user2.xp+tmpxp;
      if not(user2.robot) then addevent(tempevent);
      updatesbar;
      sendln('`D');
    end;
  if
    playerwon
  then
    begin  {Player defended her virtue - jumping character lost!}
      tmpxp:=user2.xp*config.loserxp;
      tmpxp:=tmpxp/100;
      user2.xp:=user2.xp+tmpxp;
      parameter[1]:=user2.name;
      parameter[2]:=user.name;
      if not invkr then log(g_sysmsg(350)); {User2 failed miserably getting off with User}
      tempevent.name:=user2.name;
      parameter[1]:=user.name;
      tempevent.txt:=tempevent.txt+g_sysmsg(351);

      parameter[1]:=user2.name;
      parameter[2]:=getgen(user2.gender,3);
      sysmsg(352);


      tempevent.txt:=tempevent.txt+g_sysmsg(353);
      user.xp:=user.xp+(user2.xp/2)+(random*(user2.xp)/2);

      parameter[1]:=user2.name;
      parameter[2]:=getgen(user2.gender,8);
      parameter[3]:=c2sc(user2.gp);
      sysmsg(354);

      user.gp:=user.gp+user2.gp;
      user2.gp:=0;
      newsbar;
      if
        user2.weapon>user.weapon
      then
        begin
          parameter[1]:=getgen(user.gender,6);
          parameter[2]:=weaponname(user2.weapon);
          parameter[3]:=user.name;
          tempevent.txt:=tempevent.txt+g_sysmsg(355);

          parameter[1]:=getgen(user2.gender,2);
          {parm 2 is carried from above}
          parameter[3]:=user2.name;
          sysmsg(356);

          itemswaptemp:=user.weapon;
          user.weapon:=user2.weapon;
          user2.weapon:=itemswaptemp;
          newsbar;
        end;
      if
        user2.armor>user.armor
      then
        begin
          parameter[1]:=getgen(user.gender,6);
          parameter[2]:=armorname(user2.armor);
          parameter[3]:=user.name;
          tempevent.txt:=tempevent.txt+g_sysmsg(357);

          parameter[1]:=getgen(user2.gender,2);
          parameter[2]:=armorname(user2.armor);
          parameter[3]:=user2.name;
          sysmsg(358);
          itemswaptemp:=user.armor;
          user.armor:=user2.armor;
          user2.armor:=itemswaptemp;
          newsbar;
        end;
      if not(user2.robot) then addevent(tempevent);
    end;
    disease:=false;
end;


var periodpos:integer; {note external position of this variable - it is
                        actually global to the unit}
    periodsec:longint;
procedure periods;
var l:longint;
begin
  l:=sec70; if l=periodsec then exit;
  periodsec:=l;
  inc(periodpos);
  if periodpos>32 then periodpos:=1;
  if periodpos in [1..16] then send('.');
  if periodpos in [17..32] then if wherex>1 then send(#8#32#8);
  totallines:=0;
end;

function awaitusync:string;
var tch:char;
begin
  parameter[1]:=user2.name; parameter[2]:=getgen(user2.gender,2); sysmsg(761);
  periodpos:=0;
  awaitusync:='';
  repeat
    if checkcontrol then begin awaitusync:=controlstring; exit; end;
    if
      charwaiting
    then
      begin
        tch:=upcase(getchr);
        if tch='Q' then begin awaitusync:='USYNC_QUIT'; exit; end;
      end;
    periods;
  until quitnow or lostcarrier;
  awaitusync:='USYNC_QUIT';
end;

function awaitdefense:string;
var tch:char;
label _exit1;
begin
  parameter[1]:=user2.name; parameter[2]:=getgen(user2.gender,2); sysmsg(759);
  periodpos:=0;
  awaitdefense:='';
  repeat
    if checkcontrol then begin awaitdefense:=controlstring; goto _exit1; end;
    if
      charwaiting
    then
      begin
        tch:=upcase(getchr);
        if tch='Q' then begin awaitdefense:='ATTACKER_RAN'; goto _exit1; end;
      end;
    periods;
  until quitnow or lostcarrier;
  awaitdefense:='ATTACKER_QUIT';
_exit1:
end;

function awaitattack:string;
var tch:char;
label _exit2;
begin
  parameter[1]:=user2.name; parameter[2]:=getgen(user2.gender,2); sysmsg(759);
  periodpos:=0;
  awaitattack:='';
  repeat
    if checkcontrol then begin awaitattack:=controlstring; goto _exit2; end;
    if
      charwaiting
    then
      begin
        tch:=upcase(getchr);
        if tch='Q' then begin awaitattack:='DEFENDER_RAN'; goto _exit2; end;
      end;
    periods;
  until quitnow or lostcarrier;
  awaitattack:='DEFENDER_QUIT';
_exit2:
end;

procedure encore_online(u2num:integer; var playerwon:boolean);  {Player tries to seduce NPC}
var
    amt:longint;
    tch:char;
    surprise,done:boolean;
    minushp:longint;
    action:integer;
    tmpxp:comp;
    diff:integer;
    etmp:extended;
    defensecode:string[20];
    defenseparm:longint;
    crap:integer;
begin
  iran:=true; onlineencounter:=true;
  if lostcarrier then begin control(u2num,'ATTACKER_QUIT'); nocarrier; quitnow:=true; abortedfuck:=true; exit; end;
  disease:=false;
  abortedfuck:=false;
  spellpriv[11]:=false;
  spellpriv[12]:=false;
  begin
    {Insert the actual mechanical combat code here}
    surprise:=false;
    if
      (user.condoms<6)
    and
      (user.condoms>0)
    then
      begin
        parameter[1]:=i2sc(user.condoms);
        sysmsg(180);
      end;
    if
      user.condoms=0
    then
      begin
        sysmsg(181);
        distemp:=random(100);
        if
          distemp<20
        then
          disease:=true;
      end
    else
      begin
        dec(user.condoms);
      end;
    if user.skill>=user2.skill then surprise:=true;
    if
      surprise
    then
      sysmsg(182)
    else
      begin
        parameter[1]:=user2.name;
        sysmsg(183);
      end;
    done:=false;
    if lostcarrier then begin control(u2num,'ATTACKER_QUIT'); nocarrier; quitnow:=true; abortedfuck:=true; exit; end;
    repeat
      if lostcarrier then begin control(u2num,'ATTACKER_QUIT'); nocarrier; quitnow:=true; abortedfuck:=true; exit; end;
      begin
        if user.hp<0 then user.hp:=0;
        parameter[1]:=i2sc(user.hp);
        parameter[2]:=user2.name;
        parameter[3]:=i2sc(user2.hp);
        sysmsg(184);
      updatesbar;
      if surprise then
      begin
        changecolour('L');
        updatesbar;
        spellpriv[5]:=false;
        spellpriv[11]:=false;
        spellpriv[12]:=false;
        if
          invkr
        then
          begin
            spellpriv[1]:=true;
            spellpriv[2]:=true;
            spellpriv[3]:=false;
            spellpriv[4]:=true;
            spellpriv[7]:=true;
            spellpriv[8]:=false;
            spellpriv[9]:=true;
            spellpriv[10]:=true;
          end
        else
          begin
            spellpriv[1]:=false;
            spellpriv[2]:=false;
            spellpriv[3]:=true;
            spellpriv[4]:=false;
            spellpriv[7]:=false;
            spellpriv[8]:=true;
            spellpriv[9]:=true;
            spellpriv[10]:=true;
          end;

        repeat
          if lostcarrier then begin control(u2num,'ATTACKER_QUIT'); nocarrier; quitnow:=true; abortedfuck:=true; exit; end;
          giveupturn:=false;
          sysmsg(185);
          ctmp:=#00; controlstring:='';
          get(#13'rug?');
          if ctmp=#13 then ctmp:='G';
          linein:=controlstring; parse;
          defensecode:=upcasestr(parses[1]);
          val(parses[2],defenseparm,crap);
          if defensecode='DEFENDER_RAN' then begin abortedfuck:=true; iran:=false; exit end;
          if defensecode='DEFENDER_QUIT' then begin abortedfuck:=true; iran:=false; exit end;
          if lostcarrier then begin control(u2num,'ATTACKER_QUIT'); nocarrier; quitnow:=true; abortedfuck:=true; exit; end;
          case upcase(ctmp) of
            '?' : begin
                    sysmsg(186);
                    if
                      ansi
                    then
                      sendtext('SEXHELP.ANS')
                    else
                      sendtext('SEXHELP.ASC');
                  end;
            'U' : begin
                    sysmsg(187);
                    usespecial;
                    if abortedfuck or quitnow then exit;
                  end;
            'R' : begin
                    sysmsg(188);
                    surprise:=false;
                    if
                      invkr
                    then
                      sysmsg(189)
                    else
                      if
                        (margin(user.skill*2,user2.skill,100))
                      then
                        begin
                          sysmsg(190);
                          abortedfuck:=true;
                          control(u2num,'ATTACKER_RAN');
                          exit;
                        end
                      else
                        begin
                          parameter[1]:=user2.name;
                          sysmsg(191);
                        end;
                    end;
            'G' : sysmsg(192);
          end; {case}
      until (upcase(ctmp)='G') or quitnow or giveupturn or lostcarrier;
      if lostcarrier then begin control(u2num,'ATTACKER_QUIT'); nocarrier; quitnow:=true; abortedfuck:=true; exit; end;
      end;
        {Attacker's Move}
        if
          ((surprise) and (not done) and (not giveupturn))
        then
          begin
            giveupturn:=false;
            etmp:=(user2.armor*(user2.stamina-9)); if etmp<1 then etmp:=1;
            etmp:=raisepower(etmp,0.5);
            ltmp:=round(etmp);
            if ltmp=0 then ltmp:=1;
            minushp:=user.weapon; minushp:=minushp*minushp;
            minushp:=longint(((((minushp div 6)+1)*user.stamina) div (ltmp))*config.minushp div 100);
            minushp:=longint(minushp shr 1);
{            if invkr then minushp:=minushp*3; }
            minushp:=adjust(minushp); {Introduce a random element into the hit value}
            inc(minushp);
            if (user.weapon=9999) then minushp:=user2.hp+1;
            if
              not(margin(user.skill*3,user2.skill,200))
            then       {Attacker's skill is far too low}
              begin
                parameter[1]:=mixedcase(getgen(user2.gender,1));
                parameter[2]:=user2.name;
                sysmsg(193);
                control(u2num,'ATTACKER_MISSED');
              end
            else
              begin
                user2.hp:=user2.hp-minushp;
                if user2.hp<1 then begin done:=true; playerwon:=true; end;
                action:=random(25)+1;
                parameter[1]:=g_sysmsg(193+action);
                parameter[2]:=getgen(user2.gender,3);
                parameter[3]:=weaponname(user.weapon);
                parameter[4]:=i2sc(minushp);
                parameter[5]:=user2.name;
                sysmsg(219);
                control(u2num,'ATTACKER_HIT '+int2str(minushp));
              end;
          end; {End of attacker's move}
      if user2.hp<1 then begin done:=true; playerwon:=true; end;
      begin
        {defender's Move}
        if
          not(done)
        then
          begin
            surprise:=true;
            linein:=awaitdefense; parse;
            defensecode:=upcasestr(parses[1]);
            val(parses[2],defenseparm,crap);

            if defensecode='ATTACKER_RAN' then begin control(u2num,'ATTACKER_RAN'); abortedfuck:=true; exit; end;
            if defensecode='DEFENDER_RAN' then begin abortedfuck:=true; iran:=false; exit end;
            if defensecode='DEFENDER_QUIT' then begin abortedfuck:=true; iran:=false; exit end;
            if defensecode='DEFENDER_SPELL' then begin end;
            if defensecode='DEFENDER_HIT' then
              begin
                minushp:=defenseparm;
                user.hp:=user.hp-minushp;
                if user.hp<1 then begin done:=true; playerwon:=false; end;
                action:=random(25)+1;
                parameter[1]:=getgen(user2.gender,6);
                parameter[2]:=getgen(user2.gender,2);
                parameter[3]:=armorname(user2.armor);
                parameter[4]:=i2sc(minushp);
                parameter[5]:=user2.name;
                parameter[6]:=weaponname(user2.weapon);
                parameter[7]:=g_sysmsg(221+action);
                sysmsg(221);
              end;
            if defensecode='DEFENDER_MISSED' then
              begin
                parameter[1]:=getgen(user2.gender,2);
                parameter[2]:=user2.name;
                sysmsg(220);
              end;

              updatesbar;
          end; {End of defender's move}

      end;


      end; {repeat}
    until done or quitnow or lostcarrier;
    if done then iran:=false;
    if lostcarrier then begin nocarrier; quitnow:=true; exit; end;
  end;
end;

procedure encore2_online(u2num:integer; var playerwon:boolean); {Player defends virtue against NPC}
var
    amt:longint;
    tch:char;
    surprise,done:boolean;
    minushp:longint;
    action:integer;
    tmpxp:comp;
    diff:integer;
    etmp:extended;
    defensecode:string[20];
    defenseparm:longint;
    crap:integer;
begin
  iran:=true; onlineencounter:=true;
  if lostcarrier then begin control(u2num,'DEFENDER_QUIT'); nocarrier; quitnow:=true; abortedfuck:=true; exit; end;
  disease:=false;
  abortedfuck:=false;
  begin
    {Insert the actual mechanical combat code here}
    surprise:=false;
    disease:=false;
    if user.skill>user2.skill then surprise:=true;
    if
      surprise
    then
      sysmsg(247)
    else
      begin
        parameter[1]:=user2.name;
        sysmsg(248);
      end;
    done:=false;
    if lostcarrier then begin control(u2num,'DEFENDER_QUIT'); nocarrier; quitnow:=true; abortedfuck:=true; exit; end;
    repeat
      if lostcarrier then begin control(u2num,'DEFENDER_QUIT'); nocarrier; quitnow:=true; abortedfuck:=true; exit; end;
      begin
        if user.hp<0 then user.hp:=0;
        parameter[1]:=i2sc(user.hp);
        parameter[2]:=user2.name;
        parameter[3]:=i2sc(user2.hp);
        sysmsg(249);
      updatesbar;
      if surprise then
      begin
        changecolour('L');
        updatesbar;
        repeat
          if lostcarrier then begin control(u2num,'DEFENDER_QUIT'); nocarrier; quitnow:=true; abortedfuck:=true; exit; end;
          giveupturn:=false;
          parameter[1]:=user2.name;
          sysmsg(250);
          controlstring:=''; ctmp:=#00;
          get(#13're?');
          if ctmp=#13 then ctmp:='E';
          linein:=controlstring; parse;
          defensecode:=upcasestr(parses[1]);
          val(parses[2],defenseparm,crap);
          if defensecode='ATTACKER_RAN' then begin abortedfuck:=true; iran:=false; exit end;
          if defensecode='ATTACKER_QUIT' then begin abortedfuck:=true; iran:=false; exit end;
          if lostcarrier then begin control(u2num,'DEFENDER_QUIT'); nocarrier; quitnow:=true; abortedfuck:=true; exit; end;
          case upcase(ctmp) of
            '?' : begin
                    sysmsg(186);
                    if
                      ansi
                    then
                      sendtext('SEXHELP2.ANS')
                    else
                      sendtext('SEXHELP2.ASC');
                  end;
            'R' : begin
                    sysmsg(188);
                    surprise:=false;
                    if
                      (margin(user.skill*2,user2.skill,100))
                    then
                      begin
                        sysmsg(251);
                        control(u2num,'DEFENDER_RAN');
                        abortedfuck:=true;
                        exit;
                      end
                    else
                      begin
                        parameter[1]:=user2.name;
                        sysmsg(252);
                      end;
                  end;
            'E' : sysmsg(253);
          end; {case}
      until (upcase(ctmp)='E') or quitnow or giveupturn or lostcarrier;
      end;
        {Defender's Move} {Was attacker's in ENCORE}
        if
          ((surprise) and (not done) and (not giveupturn))
        then
          begin
            surprise:=true;
            etmp:=(user2.weapon*(user2.stamina-9)); if etmp<1 then etmp:=1;
            etmp:=raisepower(etmp,0.5);
            ltmp:=round(etmp);
            if ltmp=0 then ltmp:=1;

            minushp:=user.armor; minushp:=minushp*minushp;
            minushp:=longint(((((minushp div 6)+1)*user.stamina) div (ltmp))*config.minushp div 100);
            minushp:=longint(minushp shr 1);
{            if invkr then minushp:=minushp*3; }
            minushp:=adjust(minushp); {Introduce a random element into the hit value}
            inc(minushp);
            if (user.armor=9999) then minushp:=user2.hp+1;
            if
              not(margin(user.skill*3,user2.skill,200))
            then       {Your skill is far too low}
              begin
                parameter[1]:=user2.name;
                sysmsg(254);
                control(u2num,'DEFENDER_MISSED');
              end
            else
              begin
                user2.hp:=user2.hp-minushp;
                if user.hp<1 then begin done:=true; playerwon:=false; end;
                action:=random(25)+1;
                parameter[1]:=armorname(user.armor);
                parameter[2]:=i2sc(minushp);
                parameter[4]:=weaponname(user.weapon);
                parameter[5]:=user2.name;
                parameter[3]:=g_sysmsg(255+action);
                sysmsg(255);
                control(u2num,'DEFENDER_HIT '+int2str(minushp));
              end;
              updatesbar;
          end; {End of defender's move}
      if user2.hp<1 then begin done:=true; playerwon:=true; end;
      begin
        {Attacker's Move} {Was defender's in ENCORE}
        if
          not(done)
        then
          begin
            surprise:=true;
            giveupturn:=false;

            linein:=awaitattack; parse;
            defensecode:=upcasestr(parses[1]);
            val(parses[2],defenseparm,crap);

            if defensecode='DEFENDER_RAN' then begin control(u2num,'DEFENDER_RAN'); abortedfuck:=true; exit; end;
            if defensecode='ATTACKER_RAN' then begin abortedfuck:=true; iran:=false; exit end;
            if defensecode='ATTACKER_QUIT' then begin abortedfuck:=true; iran:=false; exit end;
            if defensecode='ATTACKER_SPELL' then begin end;
            if defensecode='ATTACKER_HIT' then
              begin
                minushp:=defenseparm;
                user.hp:=user.hp-minushp;
                if user.hp<1 then begin done:=true; playerwon:=false; end;
                action:=random(25)+1;
                parameter[1]:=mixedcase(getgen(user2.gender,6));
                parameter[2]:=g_sysmsg(282+action);
                parameter[3]:=getgen(user2.gender,2);
                parameter[4]:=weaponname(user2.weapon);
                parameter[5]:=i2sc(minushp);
                parameter[6]:=user2.name;
                sysmsg(282);
              end;
            if defensecode='ATTACKER_MISSED' then
              begin
                parameter[1]:=user2.name;
                sysmsg(281);
              end;

          end; {End of defender's move}
        end;
      end; {repeat}
    until done or quitnow or lostcarrier;
    if done then iran:=false;
  end;
  if lostcarrier then begin nocarrier; quitnow:=true; exit; end;
end;

procedure online_attack(u2num:integer; var playerwon:boolean);
begin
  abortedfuck:=true;
  if isinvkr(u2num) then begin sysmsg(718); exit; end;
  abortedfuck:=false;
  writeuser(user.name,user);
  writeuserlog;
  ctmp:=#00;
  control(u2num,'SYNCUSERLOG '+int2str(thisusernumber));       {Request userlog sync}
  if awaitusync<>'USYNC_ACK' then begin abortedfuck:=true; iran:=false; exit; end;
  readuserlog;
  user2:=userlog^[u2num]; user2.hp:=user2.maxhp;
  parameter[1]:=user2.name; parameter[2]:=getgen(user2.gender,2);
  sysmsg(762);
  sysmsg(757);
  control(u2num,'ICHALLENGEYOU '+int2str(thisusernumber));  {Send challenge}
  encore_online(u2num,playerwon);
  if
    abortedfuck
  then
    if
      not iran
    then
      begin
        parameter[1]:=user2.name;
        parameter[2]:=getgen(user2.gender,2);
        sysmsg(760);
      end;
  writeuser(user.name,user);
  ctmp:=#00;
end;

procedure online_defend(u2num:integer);
var playerwon:boolean;
begin
  ctmp:=#00;
  playerwon:=true;
  readuserlog;
  user2:=userlog^[u2num];
  parameter[1]:=user2.name; sysmsg(758);
  user.hp:=user.maxhp;
  encore2_online(u2num,playerwon);
  sendln('');
  if
    not(abortedfuck)
  then
    donefuck2(playerwon)
  else
    if
      not iran
    then
      begin
        parameter[1]:=user2.name;
        parameter[2]:=getgen(user2.gender,2);
        sysmsg(760);
      end;
  writeuser(user.name,user);
  ctmp:=#00;
end;

begin
  onlineencounter:=false;
end.
