!
! Jimmy's Script.  Derived from the adventurer script, but modified to
! to handle the one character.
!
! DESCRIPTION:  Jimmy is a young Dwarf.  He lives near a small town 
! and works at Joe's pub.  He is the player's friend and want's to
! go have some fun.  His TEXT block shows the following keywords:
!
!  0 : Hello   Hi! What are you up to? Going on a trip?                
!  1 : Default Have I shown you my weapons?  I'm dying to use them!    
!  2 : Weapons In the chest over there.. Let's go do something..       
!  3 : Join    What are we waiting for.. Let's get the weapons..       
!  4 : Chest   I keep the weapons in the chest.  We could get them!    
!  5 : Get     If we go on a quest, we should get them.                
!  6 : Quest   You know.. Go kill some monsters or something..         
!  7 : King    I heard he was missing!  That might be a worthy quest!  
!  8 : Queen   We could go talk to her in the Castle!                  
!  9 : Castle  Where the King and the Queen live!                      
! 10 : Trip    You're not thinking of leaving without me, are you?     
! 11 : AdventurIt's a good time of the year to go look for adventure!  
! 12 : Job     Joe can find another bus boy.  Let's go questing!       
! 13 : Joe     You know I work at Joe's Pub during the summer!         
! 14 : Pub     Yes!                                                    
! 15 : Ship    I don't have one, but the Queen might lend us one!      
!
! - V0 is TRUE when we've talked before.
! - V1 is TRUE if we've JOINED the group
!
! (c) DC Software, 1992
!

!------------------------------------------------------------------------!
:@TALK ! START HERE WHEN YOU 'TALK' TO THIS CHARACTER !
!------------------------------------------------------------------------!

! First, say hello.. !

  if npc.picture >= 0 then
    viewpcx(npc);
  endif;

  if NPC.V0 > 0 then
    ! We've spoken before, so don't give the standard greeting..
    writeln( "Hello again!  I thought you were gone.." );
  else
    ! First time we talk, so give the standard greeting..
    if not dotext( "Hello" ) then
      ! If the text block didn't have one, the following would be used..
      writeln( "Hello ", player.name, ". What are you up to?" );
    endif;
  endif;
  NPC.V0 = 1; ! This variable indicates we've talked before (see above)

:CHAT
  L3 = getstr("Name","Job","Join","Bye");
  if L3 = -1 goto CSTOP; 

! Handle JOIN differently..
  if L3 = 2 then 
    if group.size = 6 then
      writeln( "Hey! Your party is full! There's no place for me!" );
      goto CHAT;
    endif;
    if npc.level > player.level + 4 then
      ! Normal behaviour would be to decline until adventurer has more
      ! experience, but Jimmy is a friend, so it doesn't apply
      writeln( "Ok.  But you are inexperienced, so let me handle the tough" );
      writeln( "problems.  You'd better take the better armor too.." );
    endif;
    if npc.level < player.level - 6 then
      ! Normal behaviour would be to decline because the adventurer
      ! has too much experience.  Encounters tend to be more serious
      ! and inexperienced members get killed easily.  Again, since
      ! Jimmy is a friend, we wave the restriction..
      writeln( "You mean it?!  I don't have a lot of experience, but I learn" );
      writeln( "very fast..  Thanks!" );
    endif;
    if NOT dotext( "join" ) then
      writeln( "What are we waiting for.. Let's get the weapons!" );
    endif;
    ! Now we might do some animation, so we restore the graphics !
    ! to allow the player to see it !
    if npc.picture >= 0 then
      paint(window); ! Assumes the picture fits in the window !
    endif;

    ! If were at the original location, and haven't joined yet.. !
    if npc.v1 = FALSE and npc.x = 3 and npc.y = 7 then
      L1 = 1; ! walk to the right.. !
      for L0 = 1 to 4 do
        gosub MOVEJIMMY;
      endfor;
      L2 = 0;
      L1 = find( object, "Jimmy's Chest", CHEST );
      if success then
        object.index = L1;
        writeln( "I have ", $object.value, " saved from my summer job.." );
        inc( group.gold, object.value );
        vanish(object);
        pause(1); ! Use PAUSE instead of WAIT !
      else
        writeln( "I could have sworn I had some money in here.." );
        inc(L2);
      endif;
      L1 = find( object, "Chain Mail", armor );
      if success then
        object.index = L1;
        writeln( "This Chain Mail is worn, but functional!" );
        move( object, npc ); pause(1); ! Use PAUSE instead of WAIT !
      else
        writeln( "My chain mail is missing..  Hmm.." );
        inc(L2);
      endif;
      L1 = find( object, "Dwarf's Axe", weapon );
      if success then
        object.index = L1;
        writeln( "This Axe belonged to my brother..  It's heavy!" );
        move( object, npc ); pause(1); ! Use PAUSE instead of WAIT !
      else
        writeln( "Where did I put that Axe?" );
        inc(L2);
      endif;
      if L2 > 0 then
        if L2 = 3 then
          writeln( "I assume you already got my stuff" );
        else
          writeln( "Some of my stuff is missing, I assume you got it?" );
        endif;
        pause(1); ! Use PAUSE instead of WAIT !
      endif;
      L1 = -1; ! Walk to the left.. !
      for L0 = 1 to 4 do
        gosub MOVEJIMMY;
      endfor;
      npc.v1 = TRUE;
    endif;
    JOIN; 
    STOP; ! We are done.. !

:MOVEJIMMY ! Subroutine to move jimmy left or right..
    if group.y = npc.y and group.x = npc.x + L1 then
      group.x = npc.x; ! Trade places with the group !
    endif;
    inc( npc.x, L1 );
    pause(1); ! Use PAUSE instead of WAIT !
    return;

  endif; ! End of JOIN !

! First, see if the keyword typed is in the character's text block !
  if dotext( S0 ) then
    if L3 = 3 goto XSTOP;
    goto CHAT;
  endif;

! It didn't, so try the predefined ones..
  on L3 goto CNAME, CJOB, CHAT, CSTOP;

! Nope, try a 'DEFAULT' line
  if not dotext( "DEFAULT" ) then
    writeln( "I don't know anything about that!" );
  endif;
  goto CHAT;

:CNAME
  writeln( "My name is ", NPC.name, "." );
  GOTO CHAT;

:CJOB
  writeln( "I am a ", npc.type );
  GOTO CHAT;

:CSTOP
  writeln( "Nice talking to you.." );
  goto XSTOP;

! Feel free to expand on this list.. !

!-----------------------------------------------------------------!
! All STOPs now lead here so the screen can be restored if needed !
!-----------------------------------------------------------------!
:XSTOP
  if npc.picture >= 0 then
    paint(window); ! Assumes the picture fits in the window !
  endif;
  STOP;


