# It's the new 'say' sub for Sam and Max 2, so we can put voice bubbles on the screen.

var samtalkX = 0;
var samtalkY = 0;
var whichSize = 0;
var theScale = 0;

sub Say (character, string) {
      whichSize = stringLength (string);
      samtalkX = getObjectX (character);
      theScale = 100;
      theScale *= getCharacterScale (character);

     if (character == sam) {theScale *= 280;}
     else if (character == max) {theScale *= 170;}
     else if (character == fbiguy) {theScale *= 300;}
     else if (character == janitor) {theScale *= 270;}
     else if (character == littlegirl) {theScale *= 230;}
     else if (character == police) {theScale *=120;}

      theScale /= 10000;
      samtalkY = getObjectY (character);
      samtalkY -= theScale;

        addCharacter (bubbletail, samtalkX, samtalkY, costume (anim ('iface/mouse.duc', 7), NULL, NULL));
        setCharacterExtra (bubbletail, FIXEDSIZE + FRONT + NOZBUFFER + NOLIGHTMAP);

    if (whichSize < 5) { if (samtalkX < 50) samtalkX = 45; }
    else if (whichSize < 10) { if (samtalkX < 100) samtalkX = 90; }
    else if (whichSize < 20) { if (samtalkX < 173) samtalkX = 160; }
    else if (whichSize < 30) { if (samtalkX < 250) samtalkX = 240; }
    else { if (samtalkX < 250) samtalkX = 240; }

    if (thisRoom == 0) {
     if (whichSize < 5) { if (samtalkX > 750) samtalkX = 760; }
     else if (whichSize < 10) { if (samtalkX > 700) samtalkX = 710; }
     else if (whichSize < 20) { if (samtalkX > 627) samtalkX = 635; }
     else if (whichSize < 30) { if (samtalkX > 550) samtalkX = 560; }
     else { if (samtalkX > 550) samtalkX = 560; }

     if (whichSize < 30) { if (samtalkY < 51) samtalkY = 51; }
     else if (whichSize < 60) { if (samtalkY < 89) samtalkY = 89; }
     else if (whichSize < 90) { if (samtalkY < 119) samtalkY = 119; }
     else if (whichSize < 120) { if (samtalkY < 154) samtalkY = 154;}
     else { if (samtalkY < 249) samtalkY = 249; }
    }
    else {
     var a = getObjectX (sam);
     if (thisRoom == 1) {
      if (a > 400) {
          if (samtalkX < a - 245) {
              if (whichSize < 5) { 
                     samtalkX = a - 400;
                     samtalkX += 49;
              }
              else if (whichSize < 10) { 
                     samtalkX = a - 400;
                     samtalkX += 94;
              }
              else if (whichSize < 20) {
                     samtalkX = a - 400;
                     samtalkX += 167;
              }
              else if (whichSize < 30) {
                     samtalkX = a - 400;
                     samtalkX += 245;
              }
              else {
                     samtalkX = a - 400;
                     samtalkX += 245;
              }
       }
       else if (samtalkX > a + 245) {
              if (whichSize < 5) { 
                     samtalkX = a + 400;
                     samtalkX -= 49;
              }
              else if (whichSize < 10) { 
                     samtalkX = a + 400;
                     samtalkX -= 94;
              }
              else if (whichSize < 20) {
                     samtalkX = a + 400;
                     samtalkX -= 167;
              }
              else if (whichSize < 30) {
                     samtalkX = a + 400;
                     samtalkX -= 245;
              }
              else {
                     samtalkX = a + 400;
                     samtalkX -= 245;
              }
            }
         } 
      }
   }
      if (whichSize < 5) {
        addCharacter (voicebubble, samtalkX, samtalkY, costume (anim ('iface/mouse.duc', 15), NULL, NULL));
        setCharacterExtra (voicebubble, FIXEDSIZE + FRONT + NOZBUFFER + NOLIGHTMAP);
      }
      else if (whichSize < 10) {
        addCharacter (voicebubble, samtalkX, samtalkY, costume (anim ('iface/mouse.duc', 14), NULL, NULL));
        setCharacterExtra (voicebubble, FIXEDSIZE + FRONT + NOZBUFFER + NOLIGHTMAP);
      }
      else if (whichSize < 20) {
        addCharacter (voicebubble, samtalkX, samtalkY, costume (anim ('iface/mouse.duc', 13), NULL, NULL));
        setCharacterExtra (voicebubble, FIXEDSIZE + FRONT + NOZBUFFER + NOLIGHTMAP);
      }
      else if (whichSize < 30) {
        addCharacter (voicebubble, samtalkX, samtalkY, costume (anim ('iface/mouse.duc', 8), NULL, NULL));
        setCharacterExtra (voicebubble, FIXEDSIZE + FRONT + NOZBUFFER + NOLIGHTMAP);
      }
      else if (whichSize < 60) {
        addCharacter (voicebubble, samtalkX, samtalkY, costume (anim ('iface/mouse.duc', 9), NULL, NULL));
        setCharacterExtra (voicebubble, FIXEDSIZE + FRONT + NOZBUFFER + NOLIGHTMAP);
      }
      else if (whichSize < 90) {
        addCharacter (voicebubble, samtalkX, samtalkY, costume (anim ('iface/mouse.duc', 10), NULL, NULL));
        setCharacterExtra (voicebubble, FIXEDSIZE + FRONT + NOZBUFFER + NOLIGHTMAP);
      }
      else if (whichSize < 120) {
        addCharacter (voicebubble, samtalkX, samtalkY, costume (anim ('iface/mouse.duc', 11), NULL, NULL));
        setCharacterExtra (voicebubble, FIXEDSIZE + FRONT + NOZBUFFER + NOLIGHTMAP);
      }
      else {
        addCharacter (voicebubble, samtalkX, samtalkY, costume (anim ('iface/mouse.duc', 12), NULL, NULL));
        setCharacterExtra (voicebubble, FIXEDSIZE + FRONT + NOZBUFFER + NOLIGHTMAP);
      }
        say (character, string);
        removeCharacter (bubbletail);
        removeCharacter (voicebubble);
}

objectType bubbletail ("") {}
objectType voicebubble ("") {}