/
area/city/
area/crypts/
area/guilds/
area/psuedowild/
area/religion/
data/documents/MPDocs/
data/html/
data/mobprogs/
data/quest/
data/world/
data/world/_utilities/
data/world/images/
design/html/
notes/
player/
#if defined(macintosh)
#include <types.h>
#else
#include <sys/types.h>
#endif
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "merc.h"
#include "interp.h"
#include "magic.h"
#include "recycle.h"
#include "tables.h"
#include "gquest.h"
#include "lookup.h"

void setup_mobiles(CHAR_DATA * mob)
{
    int hp, mana, move, i;
    
    if (mob->level <= 0)
        mob->level = 1;

    hp = 5 + dice(mob->level, 8);
    mana = 5 + dice(mob->level, 4);
    move = 5 + dice(mob->level, 5);
    
    mob->hit                = hp;
    mob->max_hit            = hp;
    mob->mana               = mana;
    mob->max_mana           = mana;
    mob->move               = move;
    mob->max_move           = move;
    
    for (i = 0; i < MAX_STATS; i++)
        mob->perm_stat[i] = dice(3, 6);

    if (IS_SET (mob->act, ACT_WARRIOR))
    {
        mob->perm_stat[STAT_STR] += 3;
        mob->perm_stat[STAT_INT] -= 1;
        mob->perm_stat[STAT_CON] += 2;
    }

    if (IS_SET (mob->act, ACT_THIEF))
    {
        mob->perm_stat[STAT_DEX] += 3;
        mob->perm_stat[STAT_INT] += 1;
        mob->perm_stat[STAT_WIS] -= 1;
    }

    if (IS_SET (mob->act, ACT_CLERIC))
    {
        mob->perm_stat[STAT_WIS] += 3;
        mob->perm_stat[STAT_DEX] -= 1;
        mob->perm_stat[STAT_STR] += 1;
    }

    if (IS_SET (mob->act, ACT_MAGE))
    {
        mob->perm_stat[STAT_INT] += 3;
        mob->perm_stat[STAT_STR] -= 1;
        mob->perm_stat[STAT_DEX] += 1;
    }
    mob->armor_class = interpolate(mob->level, 10, -10);
};

void tagline_to_char(const char *text, CHAR_DATA *ch)
{
    /* If it's an empty string, save some time. */
    if (strlen(text) <= 0)   { return; }

    char output[MAX_STRING_LENGTH];
    char tagline[MAX_STRING_LENGTH];
    char buf[MAX_STRING_LENGTH];
    char arg[256];
    char arg2[256];
    int value;

    bool bGo = FALSE;

    const char *desc;
    char *p_output = output;
    char *common;

    for (desc = text; *desc; desc++)
      {
       /* Reset. */
       bGo      = FALSE;
       value    = 0;

       if (*desc != '[')
         {  *p_output = *desc;
            *++p_output = '\0';
            continue;  }

       if (*++desc != '#')
         {  *p_output = *--desc;
            *++p_output = '\0';
            continue;  }

       /* Skip beginning '[#'. */
       ++desc;

       /* Read in the tag. */
       common = buf;
       while(*desc != ':')
         {
          if (*desc == '\0')
            { logf("Error: tag has no parser ':'. Room: %d.", ch->in_room->vnum);
              *common = *desc; break; }
          *common = *desc;
          *++common = '\0';
          ++desc;
         }

       /* Skip the colon and space ': '. */
       desc += 2;

       /* Read in the description. */
       common = tagline;
       while (*desc != ']')
         {
          if (*desc == '\0')
            { logf("Error: tag has no ending ']'. Room: %d.", ch->in_room->vnum);
              *common = *desc; break; }
          *common = *desc;
          *++common = '\0';
          ++desc;
         }

       /* Separate the arguments. */
       common = buf;
       common = one_argument(common, arg);
       common = one_argument(common, arg2);
       if (is_number(common)) { value = atoi(common); }
       else if (strlen(common) > 0)
         { logf("Tag in room %d is odd: %s %s %s.", ch->in_room->vnum, arg, arg2, common); }

       /*======[  Cases  ]======*/
       switch (UPPER(arg[0]))
         {
          case 'A':
            if (!str_cmp(arg, "age"))
              {
               if (value < 0) { bGo = FALSE; }
               else
                 { switch (arg2[0])
                     { case '>': if (get_age(ch) > value)    { bGo = TRUE; }; break;
                       case '<': if (get_age(ch) < value)    { bGo = TRUE; }; break;
                       case '=': if (get_age(ch) == value)   { bGo = TRUE; }; break;
                       default: bGo = FALSE; break; }
                 }
              }
            else if (!str_cmp(arg, "align") || !str_cmp(arg, "alignment"))
              {
               if (!str_cmp(arg2, "good") && (ch->alignment > 250))
                 { bGo = TRUE; }
               else if (!str_cmp(arg2, "evil") && (ch->alignment < -250))
                 { bGo = TRUE; }
               else if (!str_cmp(arg2, "nuetral") &&
                    ((ch->alignment < 250) && (ch->alignment > -250)) )
                 { bGo = TRUE; }
              }
            break;

          case 'C':
            if (!str_cmp(arg, "con"))
              { switch (arg2[0])
                  { case '>': if (get_curr_stat(ch, STAT_CON) > value)  { bGo = TRUE; }; break;
                    case '<': if (get_curr_stat(ch, STAT_CON) < value)  { bGo = TRUE; }; break;
                    case '=': if (get_curr_stat(ch, STAT_CON) == value) { bGo = TRUE; }; break;
                    default: bGo = FALSE; break; }  }
            else if (!str_cmp(arg, "class"))
              {  if (class_lookup(arg2) == ch->class)               { bGo = TRUE; }  }
            break;

          case 'D':
            if (!str_cmp(arg, "dex"))
              { switch (arg2[0])
                  { case '>': if (get_curr_stat(ch, STAT_DEX) > value)  { bGo = TRUE; }; break;
                    case '<': if (get_curr_stat(ch, STAT_DEX) < value)  { bGo = TRUE; }; break;
                    case '=': if (get_curr_stat(ch, STAT_DEX) == value) { bGo = TRUE; }; break;
                    default: bGo = FALSE; break; }  }
            else if (!str_cmp(arg, "day"))
              { switch (arg2[0])
                  { case '>': if (time_info.day > value)  { bGo = TRUE; }; break;
                    case '<': if (time_info.day < value)  { bGo = TRUE; }; break;
                    case '=': if (time_info.day == value) { bGo = TRUE; }; break;
                    default: bGo = FALSE; break; }  }
            break;

          case 'G':
            if (!str_cmp(arg, "gold"))
              {
               if (value < 0) { bGo = FALSE; }
               else
                 { switch (arg2[0])
                     { case '>': if (ch->gold > value)    { bGo = TRUE; }; break;
                       case '<': if (ch->gold < value)    { bGo = TRUE; }; break;
                       case '=': if (ch->gold == value)   { bGo = TRUE; }; break;
                       default: bGo = FALSE; break; }
                 }
              }
            break;

          case 'I':
            if (!str_cmp(arg, "int"))
              { switch (arg2[0])
                  { case '>': if (get_curr_stat(ch, STAT_INT) > value)  { bGo = TRUE; }; break;
                    case '<': if (get_curr_stat(ch, STAT_INT) < value)  { bGo = TRUE; }; break;
                    case '=': if (get_curr_stat(ch, STAT_INT) == value) { bGo = TRUE; }; break;
                    default: bGo = FALSE; break; }  }
            break;

          case 'L':
            if (!str_cmp(arg, "level"))
              {
               if (value < 1) { bGo = FALSE; }
               else
                 { switch (arg2[0])
                     { case '>': if (ch->level > value)    { bGo = TRUE; }; break;
                       case '<': if (ch->level < value)    { bGo = TRUE; }; break;
                       case '=': if (ch->level == value)   { bGo = TRUE; }; break;
                       default: bGo = FALSE; break; }
                 }
              }
            break;

          case 'M':
            if (!str_cmp(arg, "month"))
              {
               if (value < 1) { bGo = FALSE; }
               else
                 { switch (arg2[0])
                     { case '>': if (time_info.month > value)    { bGo = TRUE; }; break;
                       case '<': if (time_info.month < value)    { bGo = TRUE; }; break;
                       case '=': if (time_info.month == value)   { bGo = TRUE; }; break;
                       default: bGo = FALSE; break; }
                 }
              }
            break;

          case 'N':
            if (!str_cmp(arg, "name"))
              {
               bGo = TRUE;
               char p_name[128];
               common = buf;
               char *t = tagline;
               char *n;

               while (*t != '\0')
                 {
                  if (*t != '$')
                    {
                     *common = *t;
                     *++common = '\0';
                     ++t;
                     continue;
                    }

                  sprintf(p_name, "%s", ch->name);
                  n = p_name;

                  while (*n != '\0')
                    {
                     *common = *n;
                     *++common = '\0';
                     ++n;
                    }

                  ++t;
                 }

               sprintf(tagline, "%s", buf);
              }
            break;

          case 'R':
            if (!str_cmp(arg, "race"))
              {  if (race_lookup(arg2) == ch->race)           { bGo = TRUE; }  }
            break;

          case 'S':
            if (!str_cmp(arg, "sex"))
              {  if (sex_lookup(arg2) == ch->sex)           { bGo = TRUE; } }
            else if (!str_cmp(arg, "silver"))
              {
               if (value < 0) { bGo = FALSE; }
               else
                 { switch (arg2[0])
                     { case '>': if (ch->silver > value)    { bGo = TRUE; }; break;
                       case '<': if (ch->silver < value)    { bGo = TRUE; }; break;
                       case '=': if (ch->silver == value)   { bGo = TRUE; }; break;
                       default: bGo = FALSE; break; }
                 }
              }
            else if (!str_cmp(arg, "str"))
              { switch (arg2[0])
                  { case '>': if (get_curr_stat(ch, STAT_STR) > value)  { bGo = TRUE; }; break;
                    case '<': if (get_curr_stat(ch, STAT_STR) < value)  { bGo = TRUE; }; break;
                    case '=': if (get_curr_stat(ch, STAT_STR) == value) { bGo = TRUE; }; break;
                    default: bGo = FALSE; break; }  }
            else if (!str_cmp(arg, "sun"))
              {
               if (!str_cmp(arg2, "sunrise") && (weather_info.sunlight == SUN_RISE))
                 { bGo = TRUE; }
               else if (!str_cmp(arg2, "sunset") && (weather_info.sunlight == SUN_SET))
                 { bGo = TRUE; }
               else if (!str_cmp(arg2, "day") && (weather_info.sunlight == SUN_LIGHT))
                 { bGo = TRUE; }
               else if (!str_cmp(arg2, "night") && (weather_info.sunlight == SUN_DARK))
                 { bGo = TRUE; }
              }
            break;

          case 'T':
            if (!str_cmp(arg, "time"))
              {
               if (value < 0 || value > 24)
                 { bGo = FALSE; }
               else
                 { switch (arg2[0])
                     { case '>': if (time_info.hour > value)    { bGo = TRUE; }; break;
                       case '<': if (time_info.hour < value)    { bGo = TRUE; }; break;
                       case '=': if (time_info.hour == value)   { bGo = TRUE; }; break;
                       default: bGo = FALSE; break; }
                 }
              }
            break;

          case 'W':
            if (!str_cmp(arg, "wis"))
              { switch (arg2[0])
                  { case '>': if (get_curr_stat(ch, STAT_WIS) > value)  { bGo = TRUE; }; break;
                    case '<': if (get_curr_stat(ch, STAT_WIS) < value)  { bGo = TRUE; }; break;
                    case '=': if (get_curr_stat(ch, STAT_WIS) == value) { bGo = TRUE; }; break;
                    default: bGo = FALSE; break; }  }
            else if (!str_cmp(arg, "weather"))
              {
               if (!str_cmp(arg2, "sunny") && (weather_info.sky == SKY_CLOUDLESS))
                 { bGo = TRUE; }
               else if (!str_cmp(arg2, "cloudy") && (weather_info.sky == SKY_CLOUDY))
                 { bGo = TRUE; }
               else if (!str_cmp(arg2, "rainy") && (weather_info.sky == SKY_RAINING))
                 { bGo = TRUE; }
               else if (!str_cmp(arg2, "lightning") && (weather_info.sky == SKY_LIGHTNING))
                 { bGo = TRUE; }
              }
            break;

          default:
            bGo = FALSE;
            break;
         }
       /*======[End Cases]======*/


       /* Copy in the tagline. */
       if (bGo == TRUE)
         {
          common = tagline;
          while (*common != '\0')
            {
             if (strlen(output) >= (MAX_STRING_LENGTH - 1)) {  break;  }

             *p_output = *common;
             ++common;
             *++p_output = '\0';
            }
         }
      }
   /* ^=--> End of for. */

    /* Send the whole thing to the player. */
       common = str_dup(strdup(output));
       common = format_string(common);
       send_to_char(common, ch);
       free_string(common);

 return;
}