UNIT SpellExec;
INTERFACE
USES
{$L-}
{$U-}
   {$LOAD MQOTP.dumpfile}
       Memtypes, QuickDraw, OSIntf, ToolIntf, PackIntf,
	 {$LOAD Globals.dumpfile}
   {$U Globals.p}  Globals;
	 {$LOAD}
{$U+}
{$SETC DebugFlg:=TRUE}

PROCEDURE MindMagic(who1,who2,Verb: Integer);

IMPLEMENTATION
{$S SpellExec}
{********************************************************************************}
PROCEDURE MindMagic;
CONST
  BaseX = 170;
  BaseY = 24;
VAR
  i,j,k,x,y,z,MPower:	 Integer;
  MagicPat:    ARRAY[1..8] OF Pattern;
  MagicRgn,TempRgn,ChrisRgn:    RgnHandle;
  TestRect:    Rect;
  WeirdMap:    ARRAY[1..8] OF BitMap;
  WeirdBits:   ARRAY[1..8] OF ARRAY[1..64] OF Integer;
BEGIN
  MPower:=MindPowr[who1]-MindPowr[who2];
  x:=MindPowr[who1]-1;
  IF x<0 THEN x:=0;
  MindPowr[who1]:=x;
  IF who1=Player THEN
    BEGIN {do graphics for the spell}
      ClearRoom;
      x:=ScrnX2+20; y:=ScrnY2+66;
      FOR i:=1 TO 3 DO
        BEGIN
          PlotWord(Sentence[Player,i],x,y);
          x:=x+40;
        END;
      StuffHex(@MagicPat[1],'2250880522508805');
      StuffHex(@MagicPat[2],'1128448211284482');
      StuffHex(@MagicPat[3],'8814224188142241');
      StuffHex(@MagicPat[4],'440A11A0440A11A0');
      StuffHex(@MagicPat[5],'2205885022058850');
      StuffHex(@MagicPat[6],'1182442811824428');
      StuffHex(@MagicPat[7],'8841221488412214');
      StuffHex(@MagicPat[8],'44A0110A44A0110A');

      TempRgn:=NewRgn;
      OpenRgn;
      MoveTo(ScrnX2+60,ScrnY2+65);
      CASE Verb OF
        4: BEGIN
             Move(6,15);
             Line(5,0); Line(11,-11); Line(0,19); Line(5,4); Line(-9,0); Line(0,-13);
             Line(-4,4); Line(0,5); Line(-8,-8);
           END;
        5: BEGIN
             Move(8,8);
             Line(1,0); Line(5,5); Line(0,-8); Line(3,0); Line(0,7); Line(4,-4);
             Line(2,0); Line(0,1); Line(-5,5); Line(8,0); Line(0,3); Line(-8,0);
             Line(5,5); Line(0,1); Line(-2,0); Line(-4,-4); Line(0,7); Line(-3,0);
             Line(0,-8); Line(-5,5); Line(-1,0); Line(0,-2); Line(4,-4); Line(-7,0);
             Line(0,-3); Line(7,0); Line(-4,-4); Line(0,-2);
           END;
        6: BEGIN
             SetRect(TestRect,ScrnX2+64,ScrnY2+70,ScrnX2+88,ScrnY2+94);
             FrameOval(TestRect);
             SetRect(TestRect,ScrnX2+68,ScrnY2+74,ScrnX2+84,ScrnY2+90);
             FrameOval(TestRect);
             SetRect(TestRect,ScrnX2+73,ScrnY2+79,ScrnX2+79,ScrnY2+85);
             FrameOval(TestRect);
           END;
      END;
      CloseRgn(TempRgn);
      MagicRgn:=NewRgn;
      ChrisRgn:=NewRgn;
      SetRectRgn(ChrisRgn,ScrnX2+53,ScrnY2+66,ScrnX2+99,ScrnY2+98);
      DiffRgn(ChrisRgn,TempRgn,MagicRgn);

      IF MPower>=0 THEN
        BEGIN {set up display}
          SetRect(TestRect,ScrnX2+60,ScrnY2+66,ScrnX2+92,ScrnY2+98);
          FOR i:=1 TO 8 DO
            BEGIN
              WeirdMap[i].rowBytes:=4;
              WeirdMap[i].baseAddr:=@WeirdBits[i];
              WeirdMap[i].bounds:=StdRect1;
              FillRect(TestRect,MagicPat[i]);
              CopyBits(Screenbits,WeirdMap[i],TestRect,StdRect1,srcCopy,NIL);
            END;
        END;

      FillRgn(TempRgn,black);
      SetRect(TestRect,ScrnX2+100,ScrnY2+66,ScrnX2+132,ScrnY2+98);
      IF MPower<0 THEN
        BEGIN {failure graphic}
          PenSize(3,3);
          MoveTo(ScrnX2+106,ScrnY2+58);
          Line(-6,6); Line(0,32); Line(6,6);
          PenNormal;
        END;

      IF SoundOn THEN
        BEGIN
          HLock(SpellHndl);
		  SpellPtr:=SpellHndl^;
          StartSound(SpellPtr,19980,NIL);
        END;
      
	  j:=1;
	  WHILE j<=(StoryDelay div 10) DO
       BEGIN
        FOR i:=1 TO 8 DO
         BEGIN
          FillRgn(MagicRgn,MagicPat[i]);
          IF MPower>=0 THEN CopyBits(WeirdMap[i],ScreenBits,StdRect1,TestRect,srcXOR,NIL);
          MyWait(1);
          IF SoundDone AND SoundOn THEN StartSound(SpellPtr,19980,NIL);
          IF MPower>=0 THEN CopyBits(WeirdMap[i],ScreenBits,StdRect1,TestRect,srcXOR,NIL);
        END;
	   j:=j+1;
       END;
      IF SoundON THEN BEGIN StopSound; HUnlock(SpellHndl); END;
      DisposeRgn(MagicRgn);
      DisposeRgn(TempRgn);
      DisposeRgn(ChrisRgn);

      IF MPower>=0 THEN
        BEGIN {the spell worked}
          FOR i:=1 TO SntcLeng DO Sentence[0,i]:=0;
          CASE Verb OF
            4: BEGIN {tanaga-revealer}
                 ClearRoom;
                 Sentence[0,SubjectA]:=who2;
                 Sentence[0,VerbA]:=36;
                 Sentence[0,ObjectA1]:=104+AuraCnt[1,who2,0];
                 PlotSntc(0,ScrnX2+6,ScrnY2+8,FALSE,TRUE);
                 MyWait(StoryDelay);
               END;
            5: BEGIN {katsin-revealer}
                 ClearRoom;
                 Sentence[0,SubjectA]:=who2;
                 Sentence[0,VerbA]:=37;
                 Sentence[0,ObjectA1]:=104+AuraCnt[2,who2,0];
                 PlotSntc(0,ScrnX2+6,ScrnY2+8,FALSE,TRUE);
                 MyWait(StoryDelay);
               END;
            6: BEGIN {shial-revealer}
                 ClearRoom;
                 Sentence[0,SubjectA]:=who2;
                 Sentence[0,VerbA]:=38;
                 Sentence[0,ObjectA1]:=104+AuraCnt[3,who2,0];
                 PlotSntc(0,ScrnX2+6,ScrnY2+8,FALSE,TRUE);
                 MyWait(StoryDelay);
               END;
          END; {of CASE-statement}
        END; {of spell-worked test}
	  ClearRoom;
    END; {of display test}
  IF MPower>=0 THEN AuraCnt[Verb-3,who2,who1]:=AuraCnt[Verb-3,Who2,0];
  IF who2=Player THEN
    BEGIN {display sentence indicating that he's been spelled}
	  Narrate(35,Who1);
	  ClearRoom;
	  Sentence[Who1,VerbA]:=119; {"?" spell}
	  PlotSntc(who1,ScrnX2+6,ScrnY2+8,FALSE,TRUE);
	END;
END;
{*************************************************************************}
END.