Example #1
0
/* This function takes the character string in ch->pnote and
 *  creates rooms laid out in the appropriate configuration.
 */
void map_to_rooms( CHAR_DATA * ch, MAP_INDEX_DATA * m_index )
{
   struct map_stuff map[49][78]; /* size of edit buffer */
   const char *newmap;
   int row, col, i, n, x, y, tvnum, proto_vnum = 0;
   int newx, newy;
   const char *l;
   char c;
   ROOM_INDEX_DATA *newrm;
   MAP_INDEX_DATA *map_index = NULL, *tmp;
   EXIT_DATA *xit;   /* these are for exits */
   bool getroomnext = FALSE;

   if( !ch->pnote )
   {
      bug( "%s: ch->pnote==NULL!", __FUNCTION__ );
      return;
   }

   /*
    * Make sure format is right 
    */
   newmap = check_map( ch->pnote->text );
   STRFREE( ch->pnote->text );
   ch->pnote->text = STRALLOC( newmap );

   n = 0;
   row = col = 0;

   /*
    * Check to make sure map_index exists.  
    * If not, then make a new one.
    */
   if( !m_index )
   {
      /*
       * Make a new vnum 
       */
      for( i = ch->pcdata->area->low_r_vnum; i <= ch->pcdata->area->hi_r_vnum; i++ )
      {
         if( ( tmp = get_map_index( i ) ) == NULL )
         {
            map_index = make_new_map_index( i );
            break;
         }
      }
   }
   else
      map_index = m_index;

   /*
    *  
    */
   if( !map_index )
   {
      send_to_char( "Couldn't find or make a map_index for you!\r\n", ch );
      bug( "%s", "map_to_rooms: Couldn't find or make a map_index\r\n" );
      /*
       * do something. return failed or somesuch 
       */
      return;
   }

   for( x = 0; x < 49; x++ )
   {
      for( y = 0; y < 78; y++ )
      {
         map[x][y].vnum = 0;
         map[x][y].proto_vnum = 0;
         map[x][y].exits = 0;
         map[x][y].index = 0;
      }
   }

   l = ch->pnote->text;
   do
   {
      c = l[0];
      switch ( c )
      {
         case '\n':
            break;
         case '\r':
            col = 0;
            row++;
            break;
      }
      if( c != ' ' && c != '-' && c != '|' && c != '=' && c != '\\' && c != '/' && c != '^'
          && c != ':' && c != '[' && c != ']' && c != '^' && !getroomnext )
      {
         l++;
         continue;
      }
      if( getroomnext )
      {
         n++;
         /*
          * Actual room info 
          */
         map[row][col].vnum = add_new_room_to_map( ch, c );
         map_index->map_of_vnums[row][col] = map[row][col].vnum;
         map[row][col].proto_vnum = proto_vnum;
         getroomnext = FALSE;
      }
      else
      {
         map_index->map_of_vnums[row][col] = 0;
         map[row][col].vnum = 0;
         map[row][col].exits = 0;
      }
      map[row][col].code = c;
      /*
       * Handle rooms 
       */
      if( c == '[' )
         getroomnext = TRUE;
      col++;
      l++;
   }
   while( c != '\0' );

   for( y = 0; y < ( row + 1 ); y++ )
   {  /* rows */
      for( x = 0; x < 78; x++ )
      {  /* cols (78, i think) */

         if( map[y][x].vnum == 0 )
            continue;

         newrm = get_room_index( map[y][x].vnum );
         /*
          * Continue if no newrm 
          */
         if( !newrm )
            continue;

         /*
          * Check up 
          */
         if( y > 1 )
         {
            newx = x;
            newy = y;
            newy--;
            while( newy >= 0 && ( map[newy][x].code == '^' ) )
               newy--;

            /*
             * dont link it to itself 
             */
            if( map[y][x].vnum == map[newy][x].vnum )
               break;
            if( ( tvnum = map[newy][x].vnum ) != 0 )
            {
               xit = make_exit( newrm, get_room_index( tvnum ), DIR_UP );
               xit->keyword = STRALLOC( "" );
               xit->description = STRALLOC( "" );
               xit->key = -1;
               xit->exit_info = 0;
            }
         }

         /*
          * Check down 
          */
         if( y < 48 )
         {
            newx = x;
            newy = y;
            newy++;
            while( newy <= 48 && ( map[newy][x].code == '^' ) )
               newy++;
            /*
             * dont link it to itself 
             */
            if( map[y][x].vnum == map[newy][x].vnum )
               break;
            if( ( tvnum = map[newy][x].vnum ) != 0 )
            {
               xit = make_exit( newrm, get_room_index( tvnum ), DIR_DOWN );
               xit->keyword = STRALLOC( "" );
               xit->description = STRALLOC( "" );
               xit->key = -1;
               xit->exit_info = 0;
            }
         }

         /*
          * Check north 
          */
         if( y > 1 )
         {
            newx = x;
            newy = y;
            newy--;
            while( newy >= 0 && ( map[newy][x].code == '|' || map[newy][x].code == ':' || map[newy][x].code == '=' ) )
               newy--;
            /*
             * dont link it to itself 
             */
            if( map[y][x].vnum == map[newy][x].vnum )
               break;
            if( ( tvnum = map[newy][x].vnum ) != 0 )
            {
               xit = make_exit( newrm, get_room_index( tvnum ), DIR_NORTH );
               xit->keyword = STRALLOC( "" );
               xit->description = STRALLOC( "" );
               xit->key = -1;
               if( map[newy + 1][x].code == ':' || map[newy + 1][x].code == '=' )
               {
                  SET_BIT( xit->exit_info, EX_ISDOOR );
                  SET_BIT( xit->exit_info, EX_CLOSED );
               }
               else
                  xit->exit_info = 0;
            }
         }

         /*
          * Check south 
          */
         if( y < 48 )
         {
            newx = x;
            newy = y;
            newy++;
            while( newy <= 48 && ( map[newy][x].code == '|' || map[newy][x].code == ':' || map[newy][x].code == '=' ) )
               newy++;
            /*
             * dont link it to itself 
             */
            if( map[y][x].vnum == map[newy][x].vnum )
               break;
            if( ( tvnum = map[newy][x].vnum ) != 0 )
            {
               xit = make_exit( newrm, get_room_index( tvnum ), DIR_SOUTH );
               xit->keyword = STRALLOC( "" );
               xit->description = STRALLOC( "" );
               xit->key = -1;
               if( map[newy - 1][x].code == ':' || map[newy - 1][x].code == '=' )
               {
                  SET_BIT( xit->exit_info, EX_ISDOOR );
                  SET_BIT( xit->exit_info, EX_CLOSED );
               }
               else
                  xit->exit_info = 0;
            }
         }

         /*
          * Check east 
          */
         if( x < 79 )
         {
            newx = x;
            newy = y;
            newx++;
            while( newx <= 79 && ( map[y][newx].code == '-' || map[y][newx].code == ':' || map[y][newx].code == '='
                                   || map[y][newx].code == '[' || map[y][newx].code == ']' ) )
               newx++;
            /*
             * dont link it to itself 
             */
            if( map[y][x].vnum == map[y][newx].vnum )
               break;
            if( ( tvnum = map[y][newx].vnum ) != 0 )
            {
               xit = make_exit( newrm, get_room_index( tvnum ), DIR_EAST );
               xit->keyword = STRALLOC( "" );
               xit->description = STRALLOC( "" );
               xit->key = -1;
               if( map[y][newx - 2].code == ':' || map[y][newx - 2].code == '=' )
               {
                  SET_BIT( xit->exit_info, EX_ISDOOR );
                  SET_BIT( xit->exit_info, EX_CLOSED );
               }
               else
                  xit->exit_info = 0;
            }
         }

         /*
          * Check west 
          */
         if( x > 1 )
         {
            newx = x;
            newy = y;
            newx--;
            while( newx >= 0 && ( map[y][newx].code == '-' || map[y][newx].code == ':' || map[y][newx].code == '='
                                  || map[y][newx].code == '[' || map[y][newx].code == ']' ) )
               newx--;
            /*
             * dont link it to itself 
             */
            if( map[y][x].vnum == map[y][newx].vnum )
               break;
            if( ( tvnum = map[y][newx].vnum ) != 0 )
            {
               xit = make_exit( newrm, get_room_index( tvnum ), DIR_WEST );
               xit->keyword = STRALLOC( "" );
               xit->description = STRALLOC( "" );
               xit->key = -1;
               if( map[y][newx + 2].code == ':' || map[y][newx + 2].code == '=' )
               {
                  SET_BIT( xit->exit_info, EX_ISDOOR );
                  SET_BIT( xit->exit_info, EX_CLOSED );
               }
               else
                  xit->exit_info = 0;
            }
         }

         /*
          * Check southeast 
          */
         if( y < 48 && x < 79 )
         {
            newx = x;
            newy = y;
            newx += 2;
            newy++;
            while( newx <= 79 && newy <= 48 && ( map[newy][newx].code == '\\' || map[newy][newx].code == ':'
                                                 || map[newy][newx].code == '=' ) )
            {
               newx++;
               newy++;
            }
            if( map[newy][newx].code == '[' )
               newx++;
            /*
             * dont link it to itself 
             */
            if( map[y][x].vnum == map[newy][newx].vnum )
               break;
            if( ( tvnum = map[newy][newx].vnum ) != 0 )
            {
               xit = make_exit( newrm, get_room_index( tvnum ), DIR_SOUTHEAST );
               xit->keyword = STRALLOC( "" );
               xit->description = STRALLOC( "" );
               xit->key = -1;
               xit->exit_info = 0;
            }
         }

         /*
          * Check northeast 
          */
         if( y > 1 && x < 79 )
         {
            newx = x;
            newy = y;
            newx += 2;
            newy--;
            while( newx >= 0 && newy <= 48 && ( map[newy][newx].code == '/' || map[newy][newx].code == ':'
                                                || map[newy][newx].code == '=' ) )
            {
               newx++;
               newy--;
            }
            if( map[newy][newx].code == '[' )
               newx++;

            /*
             * dont link it to itself 
             */
            if( map[y][x].vnum == map[newy][newx].vnum )
               break;
            if( ( tvnum = map[newy][newx].vnum ) != 0 )
            {
               xit = make_exit( newrm, get_room_index( tvnum ), DIR_NORTHEAST );
               xit->keyword = STRALLOC( "" );
               xit->description = STRALLOC( "" );
               xit->key = -1;
               xit->exit_info = 0;
            }
         }

         /*
          * Check northwest 
          */
         if( y > 1 && x > 1 )
         {
            newx = x;
            newy = y;
            newx -= 2;
            newy--;
            while( newx >= 0 && newy >= 0 && ( map[newy][newx].code == '\\' || map[newy][newx].code == ':'
                                               || map[newy][newx].code == '=' ) )
            {
               newx--;
               newy--;
            }
            if( map[newy][newx].code == ']' )
               newx--;
            /*
             * dont link it to itself 
             */
            if( map[y][x].vnum == map[newy][newx].vnum )
               break;
            if( ( tvnum = map[newy][newx].vnum ) != 0 )
            {
               xit = make_exit( newrm, get_room_index( tvnum ), DIR_NORTHWEST );
               xit->keyword = STRALLOC( "" );
               xit->description = STRALLOC( "" );
               xit->key = -1;
               xit->exit_info = 0;
            }
         }

         /*
          * Check southwest 
          */
         if( y < 48 && x > 1 )
         {
            newx = x;
            newy = y;
            newx -= 2;
            newy++;
            while( newx >= 0 && newy <= 48 && ( map[newy][newx].code == '/' || map[newy][newx].code == ':'
                                                || map[newy][newx].code == '=' ) )
            {
               newx--;
               newy++;
            }
            if( map[newy][newx].code == ']' )
               newx--;
            /*
             * dont link it to itself 
             */
            if( map[y][x].vnum == map[newy][newx].vnum )
               break;
            if( ( tvnum = map[newy][newx].vnum ) != 0 )
            {
               xit = make_exit( newrm, get_room_index( tvnum ), DIR_SOUTHWEST );
               xit->keyword = STRALLOC( "" );
               xit->description = STRALLOC( "" );
               xit->key = -1;
               xit->exit_info = 0;
            }
         }
      }
   }
}
Example #2
0
int main(int argc, char *argv[])
{
  int err= 0; /* return code */

  char *outfile    = (char *)0;      /* --output-file       */
  char *errfile    = (char *)0;      /* --error-file        */
  char *headerfile = (char *)0;      /* --texi-header-file  */
  char *yank_type  = "*";            /* --yank-type         */
  char *body_env   = "smallexample"; /* -B<environment>     */

  int page_width         = 80;       /* --page-width        */
  int tabsize            = 8;        /* --tab-size          */
  int tabs_to_spaces     = 0;        /* --tabs-to-spaces    */
  int output_type        = 1;        /* --output-type       */
  int table_of_contents  = 0;        /* --table-of-contents */
  int sort_entries       = 1;        /* --preserve-order    */
  int texi_flags         = TEXI_CREATE_HEADER | TEXI_PARSE_REFERENCES | TEXI_ITEMIZE_REFERENCES;
  int adoc_flags         = ADOC_FORM_FEEDS;
  int warn_mask          = WARN_NORMAL;
  int scanner_flags      = 0;        /* --indented-comments */
                                     /* --unindent-bodytext */
  int minimum_indentation = -1;      /* --reindent-bodytext */

  /* handles for the macro tables */

  int texi_macros = 0;
  int body_macros = 0;

#ifdef _DCC /* Dice */
  expand_args(argc,argv, &argc,&argv);
#endif /* _DCC */

  /* filenames on MS-DOG systems look very ugly: all uppercase and
   * backslashes.  Perform some cosmetics */

#ifdef __MSDOS__
  whoami= "adoc";

#else
  whoami= argv[0];

#endif /*__MSDOS__*/


  /* set the debugging defaults */
  D(bug_init(0,stdout));

  /* initialize the default error stream */
  ferr= stderr;

  if(err == 0)
  {
    /* prepare the texinfo macro table */
    texi_macros= mactab_new( 4+10 );

    if(!texi_macros)
      err= 1;
  }

  if(err == 0)
  {
    /* prepare the body-text macro table */
    body_macros= mactab_new( 2 );

    if(!body_macros)
      err= 2;
  }

  if(err)
    echo("error %d creating macro tables -- not enough memory?", err);

  else

  /* BEGIN scanning command line arguments */

  while( (--argc > 0) && (err <= 0) )
  {
    char *arg= *++argv;

#ifdef DEBUG
    if(argc > 1)  { D(bug("examining command line argument `%s' ( `%s', ... ) [%d]", argv[0], argv[1], argc-1)); }
    else          { D(bug("examining command line argument `%s' ( ) [%d]", argv[0], argc-1)); }
#endif /* DEBUG */

    if(*arg=='-')
    {
      /* remember the original command-line option string */
      char *opt= arg;

      if(arg[1]=='-')
        arg= convert_args(*argv);

      switch(*++arg)
      {

/*-0*/  case '0':
          output_type= 0;
          break;

/*-1*/  case '1':
          output_type= 1;
          break;

/*-2*/  case '2':
          output_type= 2;
          tabs_to_spaces= 1;
          minimum_indentation= 0;
          break;

/*-b*/  case 'b':
          texi_flags |= TEXI_TABLE_FUNCTIONS;
          break;

/*-B*/  case 'B':
          if(arg[1]) ++arg;
          else arg= (--argc > 0) ? *(++argv) : (char *)0;

          if(arg && *arg)
          {
            body_env= arg;
          }
          else
          {
            echo("missing texinfo body text environment after %s option",opt);
            err= 1;
          }
          break;

/*-c*/  case 'c':
          err= mactab_add(body_macros, "\\*", "/*", "*\\", "*/", (char *)0);

          if(err)
            echo("error %d adding comment convertion macros",err);
          break;

/*-d*/  case 'd':

#ifdef DEBUG

          if(arg[1]) { D(bug_level= atoi( &(arg[1]) )); }
          else       { D(bug_level= 1); }

#else /* !DEBUG */
          echo("not compiled w/ -DDEBUG.  No debug information available -- Sorry");
          /* no error */

#endif /* DEBUG */

          break;


/*-D*/  case 'D':
          if(arg[1] && --argc > 0)
          {
            char *lhs= &arg[1];
            char *rhs= *(++argv);

            err= mactab_add(texi_macros, lhs, rhs, (char *)0);

            if(err)
              echo("error adding texinfo macro `%s' = `%s'", lhs, rhs);
          }
          else
          {
            echo("missing macro %s after `%s' option",(arg[1] ? "value":"name"),opt);
            err= 1;
          }
          break;

/*-E*/  case 'E':
          if(arg[1]) ++arg;
          else arg= (--argc > 0) ? *(++argv) : (char *)0;

          if(arg && *arg)
          {
            if(errfile)
            {
              echo("warning: option `%s' has already been seen", opt);
              D(bug("%s \"%s\" superseeds -E \"%s\"", opt, arg, errfile));
            }

            /*errfile= strcmp(arg,"-") ? arg : (char *)0;*/
            errfile= arg;
          }
          else /* !(arg && *arg) */
          {
            echo("missing filename after `%s' option", opt);
            err= 1;
          }
          break;

/*-f*/  case 'f':
          if(arg[1])
          {
            while(*++arg) switch(*arg)
            {
              case 'f':
                adoc_flags |= ADOC_FORM_FEEDS;
                texi_flags |= TEXI_FUNCTION_NEWPAGE;
                break;

              default:
                echo("unknown paging option: `%s'",opt);
                break;
            }
          }
          else /* !arg[1] */
          {
            adoc_flags &= ~ADOC_FORM_FEEDS;
            texi_flags &= ~TEXI_FUNCTION_NEWPAGE;
          }
          break;

/*-g*/  case 'g':
          if(arg[1])
          {
            while(*++arg) switch(*arg)
            {
              case 's':
                texi_flags |= TEXI_GROUP_SECTIONS;
                break;

              default:
                echo("unknown grouping option: `%s'",opt);
                err= 1;
                break;
            }
          }
          else texi_flags &= ~TEXI_GROUP_SECTIONS;
          break;

/*-H*/  case 'H':
          if(arg[1]) ++arg;
          else arg= (--argc > 0) ? *(++argv) : (char *)0;

          if(arg && *arg)
          {
            if(headerfile)
            {
              echo("warning: option `%s' has already been seen", opt);
              D(bug("%s \"%s\" superseeds -H \"%s\"", opt, arg, headerfile));
            }

            headerfile= arg;
          }
          else /* !(arg && *arg) */
          {
            echo("missing texinfo header filename after `%s' option", opt);
            err= 1;
          }
          break;

/*-h*/  case 'h':
          printf("usage: %s [options] [-o outfile] [@ listfile] [infiles...]\n\n", whoami);
          display_args( arg[1] ? atoi(&arg[1]) : 3 );
          err= -1;    /* negative means exit w/o error */
          break;

/*-I*/  case 'I':
          table_of_contents= 1;
          break;

/*-i*/  case 'i':
          yank_type= "i";
          break;

/*-j*/  case 'j':
          if(arg[1]) ++arg;
          else arg= (--argc > 0) ? *(++argv) : (char *)0;

          if(arg && *arg)
          {
            if( (minimum_indentation= atoi(arg)) < 0 )
            {
              echo("illegal indentation: %d  (must be >= 0)", minimum_indentation);
              err= 1;
            }
          }
          else /* !(arg && *arg) */
          {
            echo("missing indentation after `%s' option", opt);
            err= 1;
          }
          break;

/*-l*/  case 'l':
          if(arg[1]) ++arg;
          else arg= (--argc > 0) ? *(++argv) : (char *)0;

          if(arg && *arg)
          {
            page_width= atoi(arg);

            if(page_width < 1)
            {
              echo("illegal page width: `%s'  (must be > 0)", arg);
              err= 1;
            }
          }
          else /* !(arg && *arg) */
          {
            echo("missing page width after `%s' option", opt);
            err= 1;
          }
          break;

/*-M*/  case 'M':
          if(arg[1] && --argc > 0)
          {
            char *lhs= &arg[1];
            char *rhs= *(++argv);

            err= mactab_add(body_macros, lhs, rhs, (char *)0);

            if(err)
              echo("error adding body macro `%s' -> `%s'", lhs, rhs);
          }
          else
          {
            echo("missing macro %s after `%s' option",(arg[1] ? "value":"name"),opt);
            err= 1;
          }
          break;

/*-n*/  case 'n':
          output_type= 0;
          break;

/*-o*/  case 'o':
          if(arg[1]) ++arg;
          else arg= (--argc > 0) ? *(++argv) : (char *)0;

          if(arg && *arg)
          {
            if(outfile)
              echo("warning: option `%s' has already been seen", opt);

            outfile= arg;
          }
          else /* !(arg && *arg) */
          {
            echo("missing filename after `%s' option", opt);
            err= 1;
          }
          break;

/*-p*/  case 'p':
          sort_entries= arg[1] ? 1:0;
          break;

/*-q*/  case 'q':
          break;

/*-T*/  case 'T':
          if(arg[1]) ++arg;
          else arg= (--argc > 0) ? *(++argv) : (char *)0;

          if(arg && *arg)
          {
            tabs_to_spaces= 1;
            tabsize= atoi(arg);

            if(tabsize < 1)
            {
              echo("illegal tab step: `%d'  (must be >= 1)", tabsize);
              err= 1;
            }
          }
          else /* !(arg && *arg) */
          {
            echo("missing tab size after `%s' option", opt);
            err= 1;
          }
          break;

/*-t*/  case 't':
          tabs_to_spaces= arg[1] ? atoi(&arg[1]) : 1;
          break;

/*-U*/  case 'U':
          if(arg[1]) ++arg;
          else arg= (--argc > 0) ? *(++argv) : (char *)0;

          if(arg && *arg)
          {
            mactab_remove(texi_macros, arg, (char *)0);
            mactab_remove(body_macros, arg, (char *)0);
          }

          else /* !(arg && *arg) */
          {
            echo("missing macro after `%s' option", opt);
            err= 1;
          }
          break;

/*-u*/  case 'u':
          if(arg[1])
          {
            scanner_flags &= ~SCANNER_UNINDENT_BODYTEXT;
            minimum_indentation= -1;
          }
          else scanner_flags |= SCANNER_UNINDENT_BODYTEXT;
          break;

/*-v*/  case 'v':
          printf("ADOC Version " VERSION " (compiled " __DATE__ ", " __TIME__ ")\n"
                 "(c)Copyright 1995 by Tobias Ferber,  All Rights Reserved\n" );
          err= -1;
          break;

/*-W*/  case 'W':
          if(arg[1])
          {
            ++arg;

            if( isdigit(*arg) )
              warn_mask |= atoi(arg);

            else switch( strarg(arg, "none",       /* 1 */
                                     "arnings",    /* 2 */
                                     "keywords",   /* 3 */
                                     "absence",    /* 4 */
                                     "untitled",   /* 5 */
                                     "all", "") )  /* 6 */
            {
              case 1:   warn_mask  = WARN_NONE;                 break;
              case 2:   warn_mask |= WARN_NORMAL;               break;
              case 3:   warn_mask |= WARN_UNKNOWN_KEYWORDS;     break;
              case 4:   warn_mask |= WARN_MISSING_KEYWORDS;     break;
              case 5:   warn_mask |= WARN_UNTITLED_SECTION;     break;
              case 6:   warn_mask |= WARN_ALL;                  break;

              default:
                echo("unknown warning method: `%s'",opt);
                err= 1;
                break;
            }
          }
          else warn_mask= WARN_NONE;
          break;

/*-x*/  case 'x':
          if(arg[1])
          {
            switch( strarg(++arg, "off",        /* 1 */
                                  "on",         /* 2 */
                                  "itemize",    /* 3 */
                                  "", "") )     /* 4 */
            {
              case 1:   texi_flags &= ~TEXI_PARSE_REFERENCES;
                        texi_flags &= ~TEXI_ITEMIZE_REFERENCES;   break;

              case 2:   texi_flags |=  TEXI_PARSE_REFERENCES;
                        texi_flags &= ~TEXI_ITEMIZE_REFERENCES;   break;

              case 3:   texi_flags |=  TEXI_PARSE_REFERENCES;
                        texi_flags |=  TEXI_ITEMIZE_REFERENCES;   break;

              default:
                echo("unknown reference handlig option: `%s'",opt);
                err= 1;
                break;
            }
          }
          else texi_flags &= ~(TEXI_PARSE_REFERENCES | TEXI_ITEMIZE_REFERENCES);
          break;


/*-Y*/  case 'Y':
          if(arg[1]) scanner_flags &= ~SCANNER_ALLOW_INDENTED_COMMENTS;
          else       scanner_flags |=  SCANNER_ALLOW_INDENTED_COMMENTS;
          break;

/*-y*/  case 'y':
          if(arg[1]) ++arg;
          else arg= (--argc > 0) ? *(++argv) : (char *)0L;

          if(arg && *arg)
            yank_type= arg;

          else /* !(arg && *arg) */
          {
            echo("missing comment type string after `%s' option", opt);
            err= 1;
          }
          break;

/*-z*/  case 'z':
          texi_flags &= ~TEXI_CREATE_HEADER;
          break;

/*-Z*/  case 'Z':
          if(arg[1]) texi_flags &= ~TEXI_NO_INDEX;
          else       texi_flags |=  TEXI_NO_INDEX;
          break;

          /*
           *  The following options are ignored for compatibility
           *  with Bill Koester's original version `autodoc' which
           *  is part of C=ommodore's Native Developer Kit (NDK).
           */

/*-C*/  case 'C':
/*-F*/  case 'F':
/*-s*/  case 's':
/*-a*/  case 'a':
/*-r*/  case 'r':
/*-w*/  case 'w':
          echo("warning: option `%s' ignored for compatibility", opt);
          break;

/*- */  case '\0':
          if( (err= flist_addfile("")) )
             echo("out of memory... hmmmmmmmmmpf!");
           break;

/*??*/  default:
          echo("unrecognized option `%s'", opt);
          err= 1;
          break;
      }
    }
    else if(*arg=='@')
    {
      if(arg[1]) ++arg;
      else arg= (--argc > 0) ? *(++argv) : (char *)0L;

      if(arg && *arg)
      {
        if( (err= flist_from_file(arg)) )
          echo("out of memory... aaarrrrrrgggggghh!");
      }
      else /* !(arg && *arg) */
      {
        echo("missing filename after `%s'", *argv);
        err= 1;
      }
    }
    else /* *arg != '@' */
    {
      if(arg && *arg)
      {
        if( (err= flist_addfile(arg)) )
          echo("out of memory... aaaiiiiiieeeeeeeee!");
      }
      else echo("internal problem parsing command line arguments: arg is empty");
    }
  }
  /* END scanning command line arguments */
  D(bug("command line argument parsing done"));

  if(err == 0)
  {
    /* prepare the error stream */

    if(errfile && *errfile)
    {
      D(bug("opening error stream `%s'",errfile));

      if( !(ferr= fopen(errfile,"w")) )
      {
        echo("could not write error messages to `%s'",errfile);
        err= __LINE__;
      }
    }
    /*else ferr is initialized to stderr */

    /* if no filename is given then read from stdin */

    if( !flist_getname() )
      flist_addfile("");


    /* read the input files (the scanner takes them from the flist queue) */

    D(bug("reading autodocs of type `%s'", yank_type));

    if(err == 0)
      err= read_source(yank_type, warn_mask, scanner_flags);

    if(err < 0)
      err= -err;  /* I/O error */

    D(bug("disposing file list"));
    flist_dispose();

    /*
     */

    if( (err == 0) && (minimum_indentation >= 0) )
    {
      if( (err= funindent(minimum_indentation, tabsize)) )
        echo("error %d reworking body text indentation -- not enough memory?",err);

      /* funindent() already performed that conversion */
      else tabs_to_spaces= 0;
    }


    if( (err == 0) && (output_type > 0) )
    {
      FILE *fout;

      /* prepare the output file */

      if(outfile && *outfile)
      {
        D(bug("opening output stream `%s'",outfile));

        if(!(fout= fopen(outfile,"w")) )
        {
          echo("could not write to `%s'",outfile);
          err= __LINE__;
        }
      }
      else fout= stdout;


      if( fout && (err==0) )
      {
        if(sort_entries)
        {
          D(bug("sorting entries"));
          funsort();
        }

        switch(output_type)
        {
          case 1: /* --autodoc */

            if(table_of_contents)
            {
              D(bug("writing table of contents"));
              err= gen_autodoc_toc(fout);
            }
            if(err == 0)
            {
              D(bug("writing autodocs"));
              err= gen_autodoc( fout, page_width, tabs_to_spaces ? tabsize : 0, adoc_flags, mactab(body_macros) );
            }
            break;

          case 2: /* --texinfo */
            if(texi_flags & TEXI_CREATE_HEADER)
            {
              D(bug("creating texinfo header"));
              err= gen_texinfo_header( fout, headerfile, mactab(texi_macros) );
            }

            if(err == 0)
            {
              D(bug("adding texinfo body macros"));
              err= mactab_add( body_macros,  "@",        "@@",
                                             "{",        "@{",
                                             "}",        "@}",
                                          /* "...",      "@dots{}", */
                                          /* "TeX",      "@TeX{}",  */
                                             "e.g. ",    "e.g.@: ",
                                             "E.g. ",    "E.g.@: ",
                                             "i.e. ",    "i.e.@: ",
                                             "I.e. ",    "I.e.@: ",   (char *)0 );
            }

            if(err == 0)
            {
              D(bug("creating texinfo output"));
              err+= gen_texinfo( fout, tabs_to_spaces ? tabsize : 0, texi_flags, body_env, mactab(body_macros) );
            }

            if(err)
              echo("error creating texinfo output");
            break;

          default: /* --dry-run */
            break;
        }
      }

      if(fout && (fout != stdout))
        fclose(fout);
    }

    D(bug("disposing libfun entries"));
    funfree();
  }

#ifdef DEBUG
  mactab_debug(bug_stream);
#endif

  D(bug("disposing macro tables"));
  mactab_dispose(body_macros);
  mactab_dispose(texi_macros);

  /*
  */

  if(err > 0)
  {
    echo("[%s] *** Error %d", (outfile && *outfile) ? outfile : "stdout", err);
    fprintf(ferr,"%s terminated abnormally (error %d)\n", whoami, err);
  }

  D(bug("closing I/O streams"));

  if( ferr && (ferr != stderr) && (ferr != stdout) )
    fclose(ferr);

  D(bug("exiting adoc returning %d (%s)", (err>0) ? 1:0, (err>0) ? "error":"success" ));
  D(bug_exit());

#ifdef DEBUG

  if(bug_stream && (bug_stream != stdout))
    fclose(bug_stream);

#endif /*DEBUG*/

  return (err > 0) ? 1:0;
}
Example #3
0
#include <proto/battclock.h>
#include <proto/exec.h>
#include <proto/utility.h>
#include <utility/date.h>


AROS_LH1(void, WriteBattClock,
         AROS_LHA(ULONG, time, D0),
         struct BattClockBase *, BattClockBase, 3, Battclock)
{
    AROS_LIBFUNC_INIT
        
    SYSTEMTIME tm;
    struct ClockData date;
    
    D(bug("[Battclock] WriteBattClock()\n"));
    
    Amiga2Date(time, &date);

    tm.wYear	  = date.year;
    tm.wMonth	  = date.month;
    tm.wDay	  = date.mday;
    tm.wHour	  = date.hour;
    tm.wMinute    = date.min;
    tm.wSecond    = date.sec;
    /* Day of week is just informative and can be ignored */

    Forbid();
    BattClockBase->KernelIFace->SetSystemTime(&tm);
    Permit();
Example #4
0
int main(int argc, char **argv)
{
    struct MsgPort *myport;
    char PortName[255];
    dll_tMessage *msg;
    int expunge=0L;
    int opencount=0L;

    bug("[DynFile] %s('%s')\n", __PRETTY_FUNCTION__, argv[0]);

    /*
     * If an argument was passed, use it as the port name,
     * otherwise use the program name
     */
    if (argc>1)
    {
        char *argPort = argv[1];

        if (argPort[0] == '"')
            strncpy(PortName, &argPort[1], strlen(argPort) - 2);
        else
            strcpy(PortName, argPort);
    }
    else
    {
        strcpy(PortName, argv[0]);
    }

    bug("[DynFile] %s: Portname '%s'\n", __PRETTY_FUNCTION__, PortName);
    /*
     * Process symbol import table
     */
    if(!dllImportSymbols())
        exit(0L);

    bug("[DynFile] %s: symbols imported\n", __PRETTY_FUNCTION__);

    /*
     * Call DLL specific constructor
     */
    if(!DLL_Init())
        exit(0L);

    bug("[DynFile] %s: initialised\n", __PRETTY_FUNCTION__);

    /*
     * Create a (public) message port
     */
    myport = CreatePort(PortName,0);
    if (!myport)
        exit(0l);

    bug("[DynFile] %s: port @ 0x%p\n", __PRETTY_FUNCTION__, myport);

    /*
    ** Loop until DLL expunges (that is if a CloseMessage leads to opencount==0)
    ** and no pending Messages are left
    */
    while((msg=(dll_tMessage *)GetMsg(myport))||(!expunge))
    {
        if (msg)
        {
            switch(msg->dllMessageType)
            {
            case DLLMTYPE_Open:
                    bug("[DynFile] %s: DLLMTYPE_Open\n", __PRETTY_FUNCTION__);
                    /*
                     * Stack type checking should go here. Might be ommited for strictly
                     * private DLLs, or when stack frame compatibility can be 100% assured.
                     * FIXME: Not handled for now
                     */
                    opencount++;
                    if(opencount>0)
                            expunge=0L;
                    msg->dllMessageData.dllOpen.ErrorCode=DLLERR_NoError;
                    break;

            case DLLMTYPE_Close:
                    bug("[DynFile] %s: DLLMTYPE_Close\n", __PRETTY_FUNCTION__);
                    opencount--;
                    if(opencount<=0L)    // <0 ????
                            expunge=1L;
                    break;

            case DLLMTYPE_SymbolQuery:
                    bug("[DynFile] %s: DLLMTYPE_SymbolQuery\n", __PRETTY_FUNCTION__);
                    dllExportSymbol(&msg->dllMessageData.dllSymbolQuery);
                    //printf("Symbol Query for %s : %p\n",msg->dllMessageData.dllSymbolQuery.SymbolName,
                    //                                    *msg->dllMessageData.dllSymbolQuery.SymbolPointer);
                    break;

            case DLLMTYPE_Kill:
                    bug("[DynFile] %s: DLLMTYPE_Kill\n", __PRETTY_FUNCTION__);
                    expunge=1L;
                    break;
            }

            /*
             * Send the message back
             */
            ReplyMsg((struct Message *)msg);
        }

        /*
         * Wait for messages to pop up
         * Note that if the DLL is expunged it doesn't wait anymore,
         * but it still processes all pending messages (including open messages
         * which can disable the expunge flag).
         * FIXME: Is this multithread safe ??
         */
        if(!expunge)
            WaitPort(myport);
    }

    /*
     * Delete public port
     */
    DeletePort(myport);

    /*
     * Call DLL specific destructor
     */
    DLL_DeInit();

    return 0L;
}
Example #5
0
VOID x11clipboard_handle_commands(struct x11_staticdata *xsd)
{
    struct Message *msg;
    
    if (xsd->hostclipboardmsg) return;
    
    D(bug("X11CLIPBOARD: handle_commands\n"));
    while((msg = GetMsg(xsd->hostclipboardmp)))
    {
	char cmd = REQ_CMD(msg);
	BOOL  async = FALSE;

	REQ_SUCCESS(msg) = FALSE;

	if (cmd == 'R')
	{
    	    D(bug("X11CLIPBOARD: handle_commands - READ\n"));

	    if ((xsd->hostclipboard_readstate == HOSTCLIPBOARDSTATE_IDLE))
	    {
		LOCK_X11
		XCALL(XConvertSelection, xsd->display,
		    	    	  xsd->clipboard_atom,
				  XA_STRING,
				  xsd->clipboard_property_atom,
				  xsd->dummy_window_for_creating_pixmaps,
				  CurrentTime);

		UNLOCK_X11

		xsd->hostclipboard_readstate = HOSTCLIPBOARDSTATE_READ;
    	    	async = TRUE;
	    }
	}
    	else if (cmd == 'W')
	{
	    unsigned char *srcbuffer = (unsigned char *)REQ_PARAM(msg);
	    ULONG   	   size = strlen(srcbuffer);
	    unsigned char *newbuffer;

    	    D(bug("X11CLIPBOARD: handle_commands: WRITE\n"));
	    
	    newbuffer = AllocVec(size, MEMF_ANY);
	    if (newbuffer)
	    {
	    	memcpy(newbuffer, srcbuffer, size);
		
		if (xsd->hostclipboard_writebuffer)
		{
	    	    FreeVec(xsd->hostclipboard_writebuffer);
		}
		
	    	xsd->hostclipboard_writebuffer = newbuffer;
		xsd->hostclipboard_writebuffer_size = size;
		
		LOCK_X11
		XCALL(XSetSelectionOwner, xsd->display, xsd->clipboard_atom,
		    	    	   xsd->dummy_window_for_creating_pixmaps, xsd->x_time);
		UNLOCK_X11
		
		REQ_SUCCESS(msg) = TRUE;
		REQ_RETVAL(msg) = NULL;
	    }
	    else
	    {
	    	REQ_SUCCESS(msg) = FALSE;
		REQ_RETVAL(msg) = NULL;
	    }
	}
	
	if (async)
	{
	    xsd->hostclipboardmsg = msg;
	    break;
	}

	ReplyMsg(msg);
    }    
}
Example #6
0
void do_mpforce( CHAR_DATA *ch, char *argument )
{
    char arg[ MAX_INPUT_LENGTH ];

    if ( !IS_NPC( ch ) )
    {
	send_to_char( C_DEFAULT, "Huh?\n\r", ch );
	return;
    }

    if ( IS_AFFECTED( ch, AFF_CHARM ) )
    {
        return;
    }

    argument = one_argument( argument, arg );

    if ( arg[0] == '\0' || argument[0] == '\0' )
    {
	bug( "Mpforce - Bad syntax: vnum %d.", ch->pIndexData->vnum );
	return;
    }

    if ( !str_cmp( arg, "all" ) )
    {
        CHAR_DATA *vch;
        CHAR_DATA *vch_next;

	for ( vch = char_list; vch != NULL; vch = vch_next )
	{
	    vch_next = vch->next;

	    if ( vch->in_room == ch->in_room
		&& (get_trust( vch ) < get_trust( ch ) || ch->level <
L_DEI || IS_NPC(ch)) 
		&& can_see( ch, vch ) )
	    {
		interpret( vch, argument );
	    }
	}
    }
    else
    {
	CHAR_DATA *victim;

	if ( ( victim = get_char_room( ch, arg ) ) == NULL )
	{
	    bug( "Mpforce - No such victim: vnum %d.",
	  	ch->pIndexData->vnum );
	    return;
	}

	if ( victim == ch )
    	{
	    bug( "Mpforce - Forcing oneself: vnum %d.",
	    	ch->pIndexData->vnum );
	    return;
	}
        if ((get_trust( victim ) < L_DEI) || IS_NPC(victim)  )
	interpret( victim, argument );
        
    }

    return;
}
Example #7
0
void write_interpret( CHAR_DATA * ch, char *argument )
{

    BUF_DATA_STRUCT *buf_data;
    char *buf;
    int curlen;


    for ( buf_data = first_buf; buf_data != NULL; buf_data = buf_data->next )
    {
        if ( buf_data->ch == ch )
            break;
    }

    if ( buf_data == NULL )
    {
        bugf( "Call to write_interpret when not writing (char=%s)\r\n", ch->name.c_str() );
        ch->position = POS_STANDING;
        return;
    }

    buf = buf_data->buf;


    /*
     * Check to see if text was a command or simply addition
     */
    if ( argument[0] != '.' )
    {
        curlen = strlen( buf );
        if ( curlen > MAX_STRING_LENGTH - 240 )
        {
            send_to_char( "String to long, cannot add new line.\r\n", ch );
            return;
        }
        for ( buf = buf + curlen; *argument != '\0'; )
            *( buf++ ) = *( argument++ );
        *( buf++ ) = '\n';
        *( buf++ ) = '\r';
        *buf = '\0';
        return;
    }

    /*
     * We have a command.
     */
    /*
     * Commands are .help .save .preview .- .clear .lines
     */
    argument++;
    if ( argument[0] == '\0' || !str_prefix(argument, "save") || !str_prefix(argument, "quit") )
    {
        bool save;
        char **dest;

        if ( !str_prefix(argument, "quit") )
            save = false;
        else
            save = true;

        dest = buf_data->dest;
        ch = buf_data->ch;

        /*
         * Save routine.
         */

        if ( save )
        {
            /*
             * Check that dest still points to buf (to check for corruption)
             */
            if ( *dest != buf )
            {
                bug( "write_interpret: Original destination has been overwritten.", 0 );
                send_to_char( "Cannot save, string pointer been modified.\r\n", ch );
            }
            else
            {
                FILE *fp = NULL;
                if ( ch->pcdata->header != &str_empty[0] ) /* File passed from helpedit */
                {
                    if ( (fp = file_open(ch->pcdata->header, "w")) == NULL )
                    {
                        send_to_char("Something is broken in write_interpret saving to file.\r\n", ch);
                        file_close(fp);
                        return;
                    }
                }
                *dest = str_dup( buf );
                if ( ( buf_data->returnfunc ) != NULL )
                    ( *buf_data->returnfunc ) ( buf_data->returnparm, dest, ch, TRUE );
                if ( ch->pcdata->header != &str_empty[0] ) /* File passed from helpedit */
                {
                    fprintf(fp, "%s", buf);
                    file_close(fp);
                }
            }
        }
        else
        {
            *dest = &str_empty[0];
            if ( ( buf_data->returnfunc ) != NULL )
                ( *buf_data->returnfunc ) ( buf_data->returnparm, dest, ch, FALSE );
        }

        /*
         * Re-use memory.
         */
        dispose( buf_data->buf, MAX_STRING_LENGTH );

        UNLINK( buf_data, first_buf, last_buf, next, prev );

        /*
         * Re-set char
         */
        ch->position = buf_data->old_char_pos;

        delete buf_data;

        return;
    }


    if ( !str_prefix(argument, "help") )
    {
        /*
         * Help
         */
        ch = buf_data->ch;

        send_to_char( "Normal type will be appended to the string, line by line.\r\n", ch );
        send_to_char( ".help     or .h :  displays this help.\r\n", ch );
        send_to_char( ".save     or .  :  saves and exits the editor.\r\n", ch );
        send_to_char( ".preview  or .p :  display a preview of the text.\r\n", ch );
        send_to_char( ".-[num]   or .- :  deletes [num] lines from the end, or just one line\r\n", ch );
        send_to_char( ".clear          :  deletes whole text.\r\n", ch );
        send_to_char( ".quit     or .q :  quits without saving.\r\n", ch );
        send_to_char( ".format   or .f :  formats text for 80 chars.\r\n", ch );
        send_to_char( ".replace  or .r :  replaces word with string.\r\n", ch );
        send_to_char( "	       (usage) :  .r <word> <string>.  If no string, arg1 deleted.\r\n", ch );
        return;
    }

    if ( !str_prefix(argument, "replace") )
    {
        /*
         * Mag:  I bet you take one look at this, and change it :) -S-
         */

        char arg1[MAX_STRING_LENGTH];
        char arg2[MAX_STRING_LENGTH];
        char word[MAX_STRING_LENGTH];
        char new_buf[MAX_STRING_LENGTH];
        char pBuf;
        int pos;
        int npos;
        int wpos;
        int buf_length;
        int foo;
        int i;
        char *src;

        argument = one_argument( argument + 1, arg1 );  /* Skip the R */
        strcpy( arg2, argument );

        if ( arg1[0] == '\0' )
        {
            send_to_char( "No arg1 supplied for replace command.\r\n", ch );
            return;
        }

        new_buf[0] = '\0';
        buf_length = strlen( buf );
        pos = 0;
        npos = 0;
        wpos = 0;
        word[0] = '\0';

        for ( ;; )
        {
            pBuf = buf[pos];

            if ( pBuf == '\0' || pos > buf_length )
                break;

            if ( pBuf == ' ' )
            {
                new_buf[npos] = ' ';
                pos++;
                npos++;
                continue;
            }

            if ( !isgraph( pBuf ) )
            {
                new_buf[npos] = pBuf;
                pos++;
                npos++;
                continue;
            }

            wpos = 0;
            for ( ;; )
            {
                if ( !isgraph( pBuf ) )
                    break;

                word[wpos] = pBuf;
                pos++;
                wpos++;
                pBuf = buf[pos];
            }
            word[wpos] = '\0';

            if ( !str_cmp( word, arg1 ) )
            {
                if ( arg2[0] != '\0' )
                    for ( foo = 0; arg2[foo] != '\0'; foo++ )
                    {
                        new_buf[npos] = arg2[foo];
                        npos++;
                    }
                else
                {
                    /*
                     * Do nothing (much).
                     */
                    if ( npos > 0 )
                        npos--;
                    send_to_char( "Arg1 deleted.\r\n", ch );
                }
            }
            else
            {
                for ( foo = 0; word[foo] != '\0'; foo++ )
                {
                    new_buf[npos] = word[foo];
                    npos++;
                }
            }
        }

        /*
         * -gulp-  Copy new_buf into message structure...
         */

        src = buf;
        for ( i = 0; i < npos; i++ )
            *( src++ ) = new_buf[i];
        *( src ) = '\0';


        return;
    }



    if ( !str_prefix(argument, "preview") )
    {
        send_to_char( buf, ch );
        return;
    }

    if ( argument[0] == '-' )
    {
        int num;
        int a;

        argument++;
        if ( argument[0] == '\0' )
            num = 2;
        else
            num = atoi( argument ) + 1;

        if ( num <= 0 )
            return;

        for ( a = strlen( buf ); a >= 0; a-- )
        {
            if ( buf[a] == '\n' )
            {
                num--;
                if ( num == 0 )
                    break;
            }
        }

        if ( a == 0 )
        {
            send_to_char( "Tried to delete too many lines.\r\n", buf_data->ch );
            return;
        }

        a++;
        if ( buf[a] == '\r' )
            a++;
        send_to_char( "Deleted:\r\n", buf_data->ch );
        send_to_char( buf + a, buf_data->ch );

        buf[a] = '\0';
        return;
    }

    if ( !str_prefix(argument, "format") )
    {
        char *src;
        char dest[MAX_STRING_LENGTH];
        int col;
        char *srcspc;
        int destspc;
        char c;
        int n, i;
        int lastcol;

        /*
         * Format text
         */
        /*
         * Go through line by line, doing word wrapping
         */

        lastcol = 79;

        col = 0;
        n = 0;
        srcspc = NULL;
        destspc = 0;

        for ( src = buf; *src != '\0'; )
        {
            c = *( src++ );
            switch ( c )
            {
                case '\n': /* Convert /n/r into one space */
                    if ( ( *src == '\r' ) && ( *( src + 1 ) == '\n' ) && ( *( src + 2 ) == '\r' ) )
                    {
                        /*
                         * Do not convert paragraph endings.
                         */
                        dest[n++] = c; /* \n */
                        dest[n++] = *( src++ ); /* \r */
                        dest[n++] = *( src++ ); /* \n */
                        dest[n++] = *( src++ ); /* \r */
                        col = 0;
                        srcspc = NULL;
                        destspc = 0;
                        break;
                    }

                    /*
                     * Also if there is a space on the next line, don't merge.
                     */
                    if ( ( *src == '\r' ) && ( *( src + 1 ) == ' ' ) )
                    {
                        dest[n++] = c; /* \n */
                        dest[n++] = *( src++ ); /* \r */
                        col = 0;
                        srcspc = NULL;
                        destspc = 0;
                        break;
                    }


                    /*
                     * Otherwise convert to a space
                     */
                    /*
                     * Get rid of spaces at end of a line.
                     */
                    if ( n > 0 )
                    {
                        while ( dest[--n] == ' ' );
                        n++;
                    }
                    dest[n++] = ' ';
                    col++;

                    srcspc = src - 1;
                    destspc = n - 1;
                    break;
                case '\r':
                    break;

                case '\t': /* Tab */
                    col += 7;
                case '.':  /* Punctuation */
                case ' ':
                case ',':
                case ';':
                case '?':
                case '!':
                case ')':
                    srcspc = src - 1;
                    destspc = n - 1;
                case '-':
                    if ( srcspc == NULL )
                    {
                        srcspc = src - 1; /* Only use a dash if necessary */
                        destspc = n - 1;
                    }
                case '@': /* Color */
                    dest[n++] = c;
                    break;
                default:
                    if ( dest[n - 1] == '@' ) /* We're a color code */
                    {
                        dest[n++] = c;
                        break;
                    }
                    dest[n++] = c;
                    col++;
                    break;
            }

            if ( col >= lastcol )
            {
                /*
                 * Need to do a line break
                 */
                if ( srcspc == NULL )
                {
                    /*
                     * there were no breakable characters on the line.
                     */
                    dest[n++] = '\n';
                    dest[n++] = '\r';
                }
                else
                {
                    n = destspc;   /* n now points to a breakable char. */
                    src = srcspc;
                    while ( dest[n] == ' ' || dest[n] == '\n' )
                    {
                        n--;
                    }

                    src++;
                    n++;
                    if ( *src == '\r' )
                        src++;
                    while ( *src == ' ' )
                        src++;
                    /*
                     * src now points to the new line to be put in dest.
                     */
                    dest[n++] = '\n';
                    dest[n++] = '\r';
                    col = 0;
                    srcspc = NULL;
                    destspc = 0;
                }
            }
        }

        /*
         * Get rid of spaces at end, and add a newline.
         */

        while ( dest[--n] == ' ' );
        n++;
        dest[n++] = '\n';
        dest[n++] = '\r';

        /*
         * Copy from dest back into buffer
         */

        src = buf;
        for ( i = 0; i < n; i++ )
            *( src++ ) = dest[i];
        *( src ) = '\0';

        return;
    }

    if ( !str_cmp( argument, "clear" ) )
    {
        buf[0] = '\0';
        send_to_char( "Done.\r\n", buf_data->ch );
        return;
    }

    send_to_char( "Command not known, type .help for help.\r\n", buf_data->ch );
    return;
}
Example #8
0
FRAME *DoComposite( FRAME *dest, FRAME *src, struct gFixRectMessage *gfr,
                    MethodID how, WORD mixratio, BOOL tile, struct PPTBase *PPTBase )
{
    WORD row, col;
    WORD dcomps = dest->pix->components,
         scomps = src->pix->components;
    WORD dest_has_alpha = 0, src_has_alpha = 0;
    WORD top, bottom, left, right;

    D(bug("Doing the composite.  gfr = %d,%d,%d,%d\n",
           gfr->x, gfr->y, gfr->dim.Width, gfr->dim.Height));

    /*
     *  Initialize
     */

    if( src->pix->colorspace == CS_ARGB )
        src_has_alpha = 1;

    if( dest->pix->colorspace == CS_ARGB )
        dest_has_alpha = 1;

    if( tile ) {
        top = dest->selbox.MinY;
        left = dest->selbox.MinX;
        bottom = dest->selbox.MaxY;
        right = dest->selbox.MaxX;
    } else {
        top = gfr->y;
        bottom = gfr->y + gfr->dim.Height;
        left = gfr->x;
        right = gfr->x + gfr->dim.Width;
    }

    InitProgress( dest, "Compositing...", top, bottom );

    for( row = top; row < bottom; row++ ) {
        ROWPTR scp, dcp;
        WORD srow;

        srow = (row - gfr->y) % gfr->dim.Height;
        if( srow < 0 && tile ) srow += gfr->dim.Height;

        scp = GetPixelRow(src,  srow);
        dcp = GetPixelRow(dest, row);

        if( !dcp ) continue; /* Skip all areas that are outside */

        if( Progress(dest, row) )
            return NULL;

        for( col = left; col < right; col++ ) {
            LONG a, tr,tg,tb;
            UBYTE *s, *d;
            WORD scol;

            /*
             *  Sanitation check.  Let's not overwrite innocent
             *  memory.
             */

            if( col < 0 || col >= dest->pix->width ) continue;

            scol = ( col - gfr->x ) % gfr->dim.Width;
            if( scol < 0 && tile ) scol += gfr->dim.Width;

            if( src_has_alpha )
                a = (LONG)scp[scomps*scol];

            d = &dcp[dcomps*col+dest_has_alpha];
            s = &scp[scomps*scol+src_has_alpha];

            tr = *(d+0);
            tg = *(d+1);
            tb = *(d+2);

            switch( how ) {
                case Direct:
                    tr = *s; tg = *(s+1); tb = *(s+2);
                    break;

                case Minimum:
                    if( VECTOR_LEN(tr, tg, tb) > VECTOR_LEN(*s, *(s+1), *(s+2)) ) {
                        tr = *s; tg = *(s+1); tb = *(s+2);
                    }
                    break;

                case Maximum:
                    if( VECTOR_LEN(tr, tg, tb) < VECTOR_LEN(*s, *(s+1), *(s+2)) ) {
                        tr = *s; tg = *(s+1); tb = *(s+2);
                    }
                    break;

                case Mix:
                    tr = (mixratio * (*s) + (255-mixratio) * tr ) / 255;
                    tg = (mixratio * (*(s+1)) + (255-mixratio) * tg ) / 255;
                    tb = (mixratio * (*(s+2)) + (255-mixratio) * tb ) / 255;
                    break;

                case TransparentBlack:
                    if( *s || *(s+1) || *(s+2) ) {
                        tr = *s; tg = *(s+1); tb = *(s+2);
                    }
                    break;

                case Add:
                    tr = CLAMP_UP(*(s+0) + tr, 255);
                    tg = CLAMP_UP(*(s+1) + tg, 255);
                    tb = CLAMP_UP(*(s+2) + tb, 255);
                    break;

                case Subtract:
                    tr = CLAMP_DOWN( tr - *(s+0), 0 );
                    tg = CLAMP_DOWN( tg - *(s+1), 0 );
                    tb = CLAMP_DOWN( tb - *(s+2), 0 );
                    break;

                case Multiply:
                    tr = (tr * *(s+0)) / 256;
                    tg = (tg * *(s+1)) / 256;
                    tb = (tb * *(s+2)) / 256;
                    break;
            }

            if( src_has_alpha ) {
                tr = ((255-a) * tr + a * *(d+0) ) /256;
                tg = ((255-a) * tg + a * *(d+1) ) /256;
                tb = ((255-a) * tb + a * *(d+2) ) /256;
            }

            *d     = tr;
            if( dest->pix->colorspace != CS_GRAYLEVEL ) {
                *(d+1) = tg;
                *(d+2) = tb;
            }

#if 0
            for( pix = 0; pix < colors; pix++ ) {
                UBYTE s,d;
                LONG  t;

                d = dcp[dcomps*col+pix+dest_has_alpha];
                s = scp[scomps*(col-gfr->x)+pix+src_has_alpha];
                t = (LONG)d;

                switch(how) {
                    case Direct:
                        t = s;
                        break;

                    case Minimum:
                        if( d > s ) t = s;
                        break;

                    case Maximum:
                        if( d < s ) t = s;
                        break;

                    case Mix:
                        t = (mixratio*s + (255-mixratio)*d)/255;
                        break;

                    case TransparentBlack:
                        if( s != 0 ) t = s;
                        break;

                    case Add:
                        t = d+s;
                        if( t > 255 ) t = 255;
                        break;

                    case Subtract:
                        t = d-s;
                        if( t < 0 ) t = 0;
                        break;

                    case Multiply:
                        t = ((LONG)d * (LONG)s) / 256;
                        break;

                }

                if( src_has_alpha )
                    t = ((255-a) * t + a*d)/255;

                dcp[dcomps*col+pix+dest_has_alpha] = (UBYTE)t;
            }
#endif
        }
        PutPixelRow(dest,row,dcp);
    }

    FinishProgress(dest);

    return dest;
}
Example #9
0
EFFECTEXEC(frame,tags,PPTBase,EffectBase)
{
    ULONG sig, rc, *args;
    BOOL quit = FALSE, reallyrexx = FALSE;
    FRAME *newframe = NULL, *with = NULL;
    struct gFixRectMessage gfr = {0};
    ULONG fc, wc;
    struct Values *av;

    D(bug(MYNAME": Exec()\n"));

    /*
     *  Defaults
     */
    v.ratio = 128;
    v.method = Direct;
    v.bounds.Top = v.bounds.Left = ~0;
    v.bounds.Width = 200; v.bounds.Height = 100;
    v.tile = FALSE;

    if( av = GetOptions(MYNAME) ) {
        v = *av;
    }

    /*
     *  Copy to local variables
     */

    BGUIBase        = PPTBase->lb_BGUI;
    IntuitionBase   = (struct IntuitionBase *)PPTBase->lb_Intuition;
    DOSBase         = PPTBase->lb_DOS;
    SysBase         = PPTBase->lb_Sys;

    /*
     *  Parse AREXX message, which has to exist.
     *  BUG: If necessary, should wait for D&D from the main window.
     *  BUG: Should make sanity checks!
     */

    args = (ULONG *) TagData( PPTX_RexxArgs, tags );

    if( args ) {

        /* WITH */
        if( args[0] ) {
            with = FindFrame( (ID) PEEKL(args[0]) );
            if(!with) {
                SetErrorMsg(frame,"Unknown frame ID for WITH parameter");
                return NULL;
            }
        }

        /* TOP */
        if( args[1] ) {
            gfr.y = (WORD) PEEKL(args[1]);
            reallyrexx = TRUE;
        }

        /* LEFT */
        if( args[2] ) {
            gfr.x = (WORD) PEEKL(args[2]);
            reallyrexx = TRUE;
        }

        /* METHOD */
        if( args[3] ) {
            int i;

            for( i = 0; method_labels[i]; i++ ) {
                if(stricmp( method_labels[i], (char *)args[3] ) == 0 ) {
                    v.method = i;
                    reallyrexx = TRUE;
                    break;
                }
            }
        }

        /* RATIO */
        if( v.method == Mix ) {
            if( args[4] ) {
                v.ratio = PEEKL( args[4] );
            } else {
                SetErrorCode(frame,PERR_INVALIDARGS);
            }
        }

        /* TILE */
        if( args[5] ) {
            v.tile = TRUE;
        } else {
            v.tile = FALSE;
        }

    } else {
        SetErrorMsg(frame,"Image compositing can be used with Drag&Drop (or REXX) only");
        return NULL;
    }

    /*
     *  Make some sanity checks
     */

    if( frame->pix->width < with->pix->width ||
        frame->pix->height < with->pix->height ) {
            SetErrorMsg(frame,"You cannot composite a larger picture on a smaller one!");
            return NULL;
        }

    fc = frame->pix->colorspace;
    wc = with->pix->colorspace;

    if( ! (wc == fc || (fc == CS_ARGB && wc == CS_RGB) || (fc == CS_RGB && wc == CS_ARGB ))) {
        SetErrorMsg(frame, "Only images of the same color space can be composited");
        return NULL;
    }

    gfr.dim.Left   = 0;
    gfr.dim.Top    = 0;
    gfr.dim.Height = with->pix->height;
    gfr.dim.Width  = with->pix->width;

    /*
     *  Open window and start parsing
     */

    if( reallyrexx == FALSE ) {
        if( GimmeWindow(frame, with, PPTBase) ) {
            ULONG sigmask, gimask = 0L;

            GetAttr( WINDOW_SigMask, Win, &sigmask );

            StartInput(frame, GINP_FIXED_RECT, (struct PPTMessage *) &gfr);

            gimask = (1 << PPTBase->mport->mp_SigBit);

            while( !quit ) {
                sig = Wait( sigmask|gimask|SIGBREAKF_CTRL_C|SIGBREAKF_CTRL_F );

                if( sig & SIGBREAKF_CTRL_C ) {
                    D(bug("BREAK!\n"));
                    SetErrorCode( frame, PERR_BREAK );
                    quit = TRUE;
                    break;
                }

                if( sig & SIGBREAKF_CTRL_F ) {
                    WindowToFront(win);
                    ActivateWindow(win);
                }

                if( sig & gimask ) {
                    struct gFixRectMessage *pmsg;

                    if(pmsg = (struct gFixRectMessage *)GetMsg( PPTBase->mport )) {
                        if( pmsg->msg.code == PPTMSG_FIXED_RECT ) {
                            D(bug("User picked a point @ (%d,%d)\n",pmsg->x, pmsg->y));
                            gfr.x = pmsg->x; gfr.y = pmsg->y;
                            // SetGadgetAttrs( ( struct Gadget *)OKButton, win, NULL, GA_Disabled, FALSE );
                        }
                        ReplyMsg( (struct Message *)pmsg );
                    }
                }

                if( sig & sigmask ) {
                    while( (rc = HandleEvent( Win )) != WMHI_NOMORE ) {
                        ULONG t;

                        switch(rc) {
                            case GID_OK:
                                GetAttr( CYC_Active, Method, (ULONG *)&v.method );
                                GetAttr( SLIDER_Level, Ratio, &v.ratio );

                                /*
                                 *  Save the window attributes for later retrieval.
                                 */

                                GetAttr( WINDOW_Bounds, Win, (ULONG *) &v.bounds );
                                GetAttr( GA_Selected, Tile, &t );

                                StopInput( frame );
                                v.tile = (BOOL) t;

                                WindowClose(Win);
                                newframe = DoComposite( frame, with, &gfr, v.method,
                                                        (WORD) v.ratio, v.tile, PPTBase );
                                quit = TRUE;
                                break;

                            case GID_CANCEL:
                                quit = TRUE;
                                StopInput( frame );
                                break;
                        }
                    }
                }
            }
        }
    } else {
        /* gfr is already set up */
        newframe = DoComposite( frame, with, &gfr,
                                v.method, (WORD) v.ratio, v.tile,
                                PPTBase );
    }

    if(Win) DisposeObject(Win);

    if( newframe ) {
        PutOptions( MYNAME, &v, sizeof(struct Values) );
    }

    D(bug("Returning %08X...\n",newframe));
    return newframe;
}
Example #10
0
///////// I/O FUNCTIONS //////////////
void read_kingdoms(void)
{
	KINGDOM_DATA *kingdom = 0;
	FILE *fp;
	char buf[MAX_STRING_LENGTH];
	char *word;
	bool end = FALSE;
	long i = 0;

	fclose(fpReserve);

	if((fp = fopen(KINGDOM_FILE, "r")) == 0)
	{
		log_string("Error opening kingdom.txt for reading");
		fpReserve = fopen(NULL_FILE, "r");
		return;
	}

	while(!end)
	{
		word = fread_word(fp);

		switch (UPPER(word[0]))
		{
		case 'A':
			KEY("Assists", kingdom->assists, fread_number(fp));
			break;

		case 'E':
			if(!str_cmp(word, "End"))
			{
				end = TRUE;
				break;
			}
			break;

		case 'K':
			if(!str_cmp(word, "KingdomID"))
			{
				kingdom = create_kingdom();
				kingdom->id = fread_number(fp);
				continue;
			}
			break;

		case 'L':
			KEY("Leader", kingdom->leader, fread_string(fp));
			break;

		case 'M':
			KEY("Members", kingdom->members, fread_string(fp));
			break;

		case 'N':
			KEY("Name", kingdom->name, fread_string(fp));
			KEY("Noansiname", kingdom->noansiname, fread_string(fp));
			break;

		case 'P':
			KEY("Pks", kingdom->pks, fread_number(fp));
			KEY("Pds", kingdom->pds, fread_number(fp));
			KEY("Points", kingdom->points, fread_number(fp));
			break;

		case 'R':
			KEY("Realpoints", kingdom->realpoints, fread_number(fp));
			KEY("Recall", kingdom->recall, fread_number(fp));
			break;

		case 'T':
			KEY("Trustees", kingdom->trustees, fread_string(fp));

			if(!str_cmp(word, "Treaties"))
			{
				i = fread_number(fp);
				if(i > 0)
				{
					kingdom->treaties = malloc(sizeof(long) * (i+1));
					memset(kingdom->treaties,1,sizeof(long) * (i+1));
					kingdom->treaties[i] = 0;
					for(i = 0; kingdom->treaties[i]; i++)
						kingdom->treaties[i] = fread_number(fp);
				}
				else
				{
					kingdom->treaties = malloc(sizeof(long) * 1);
					kingdom->treaties[0] = 0;
				}
				break;
			}
			break;

		case 'U':
			KEY("Upkeep", kingdom->upkeep, fread_number(fp));
			break;

		case 'W':
			if(!str_cmp(word, "Wars"))
			{
				i = fread_number(fp);
				if(i > 0)
				{
					kingdom->wars = malloc(sizeof(long) * (i+1));
					memset(kingdom->wars,1,sizeof(long) * (i+1));
					kingdom->wars[i] = 0;
					for(i = 0; kingdom->wars[i]; i++)
						kingdom->wars[i] = fread_number(fp);
				}
				else
				{
					kingdom->wars = malloc(sizeof(long) * 1);
					kingdom->wars[0] = 0;
				}
				break;
			}
			break;

		default:
			sprintf(buf, "Bad word while reading kingdom.txt -> %s", word);
			bug(buf, 0);
			exit(1);
		}
	}

	fclose(fp);
	fpReserve = fopen(NULL_FILE, "r");
	update_kingdoms();
}
Example #11
0
void  sl811hs_sim_Write(struct sl811hs_sim *ss, int a0, UBYTE val)
{
    UBYTE mask;
    BOOL update = FALSE;

    if (a0 == 0) {
        ss->ss_Addr = val;
    } else {
        D(bug("%s: %02x = %02x\n",  __func__, ss->ss_Addr, val));
        if (ss->ss_Addr == SL811HS_INTSTATUS) {
            ss->ss_Reg[ss->ss_Addr] &= ~val;
        } else {
            ss->ss_Reg[ss->ss_Addr] = val;
        }
        if (ss->ss_Addr == SL811HS_INTSTATUS ||
            ss->ss_Addr == SL811HS_HOSTCTRL+0 ||
            ss->ss_Addr == SL811HS_HOSTCTRL+8)
            update = TRUE;
        ss->ss_Addr++;
    }

    if (!update)
        return;

    /* Perform any updates at this time */

    /* If not in USB reset, update the external device simulations
     */
    if (!(ss->ss_Reg[SL811HS_CONTROL1] & SL811HS_CONTROL1_USB_RESET)) {
        int i;
        for (i = 0; i < 16; i+=8) {
            D(bug("%s: Update USB%c state\n", __func__, i ? 'B' : 'A'));
            UBYTE hc = ss->ss_Reg[SL811HS_HOSTCTRL+i];
            BOOL isEnabled = (hc & SL811HS_HOSTCTRL_ENABLE) ? TRUE : FALSE;
            BOOL isArmed = (hc & SL811HS_HOSTCTRL_ARM) ? TRUE : FALSE;

            if (isArmed & isEnabled) {
                UBYTE buff[256];
                UBYTE ctl = ss->ss_Reg[SL811HS_HOSTCTRL+i];
                int ep  = SL811HS_HOSTID_EP_of(ss->ss_Reg[SL811HS_HOSTID+i]);
                UBYTE pid = SL811HS_HOSTID_PID_of(ss->ss_Reg[SL811HS_HOSTID+i]);
                buff[0] = ss->ss_Reg[SL811HS_HOSTDEVICEADDR] | ((ep & 1) << 7);
                buff[1] = ((ep & 0xe) << 4) | 0;    /* CRC5 is ignored */
                D(bug("%s: Send USB%c command %02x %02x\n", __func__, i ? 'B' : 'A', buff[0], buff[1]));
                usbsim_Out(ss->ss_Port, pid, buff, 2);
                switch (pid) {
                case PID_SETUP:
                case PID_OUT:
                    usbsim_Out(ss->ss_Port, (ctl & SL811HS_HOSTCTRL_DATA) ? PID_DATA1 : PID_DATA0, &ss->ss_Reg[ss->ss_Reg[SL811HS_HOSTBASE]], ss->ss_Reg[SL811HS_HOSTLEN]);
                    usbsim_In(ss->ss_Port, &pid, NULL, 0);
                    switch (pid) {
                    case PID_ACK:
                        ss->ss_HostStatus[i/8] = SL811HS_HOSTSTATUS_ACK;
                        break;
                    case PID_NAK:
                        ss->ss_HostStatus[i/8] = SL811HS_HOSTSTATUS_NAK;
                        break;
                    case PID_STALL:
                        ss->ss_HostStatus[i/8] = SL811HS_HOSTSTATUS_STALL;
                        break;
                    default:
                        ss->ss_HostStatus[i/8] = SL811HS_HOSTSTATUS_ERROR;
                    }
                    break;
                case PID_IN:
                    ss->ss_HostStatus[i/8] = 0;
                    usbsim_In(ss->ss_Port, &pid, &ss->ss_Reg[ss->ss_Reg[SL811HS_HOSTBASE]], ss->ss_Reg[SL811HS_HOSTLEN]);
                    switch (pid) {
                    case PID_DATA0:
                    case PID_DATA1:
                        ss->ss_HostStatus[i/8] |= SL811HS_HOSTSTATUS_ACK;
                        if (pid == PID_DATA1)
                            ss->ss_HostStatus[i/8] |= SL811HS_HOSTSTATUS_SEQ;
                        usbsim_Out(ss->ss_Port, PID_ACK, NULL, 0);
                        break;
                    case PID_STALL:
                        ss->ss_HostStatus[i/8] |= SL811HS_HOSTSTATUS_STALL;
                        break;
                    case PID_NAK:
                        ss->ss_HostStatus[i/8] |= SL811HS_HOSTSTATUS_NAK;
                        break;
                    }
                    break;
                default:
                    D(bug("%s: What what? I didn't expect a PID=0x%x\n", __func__, pid));
                    ss->ss_HostStatus[i/8] = SL811HS_HOSTSTATUS_ERROR;
                }

                ss->ss_Reg[SL811HS_HOSTCTRL+i] &= ~SL811HS_HOSTCTRL_ARM;
                ss->ss_Reg[SL811HS_INTSTATUS] |= (i == 0) ? SL811HS_INTMASK_USB_A : SL811HS_INTMASK_USB_B;
            }
        }
    } else {
        int i;
        usbsim_Reset(ss->ss_Port);
        for (i = 0; i < 2; i++) {
            D(bug("%s: Reset USB%c state\n", __func__, i ? 'B' : 'A'));
            ss->ss_HostStatus[i] = 0;
        }
    }

    /* Signals any pending interrupts */
    mask = ((ss->ss_Reg[SL811HS_CONTROL1] & SL811HS_CONTROL1_SUSPEND) ? SL811HS_INTMASK_DETECT : 0) |
           SL811HS_INTMASK_CHANGED |
           
           ((ss->ss_Reg[SL811HS_CONTROL1] & SL811HS_CONTROL1_SOF_ENABLE) ? SL811HS_INTMASK_SOF_TIMER : 0) |
           SL811HS_INTMASK_USB_B |
           SL811HS_INTMASK_USB_A;

    if (!ss->ss_InIrq) {
        ss->ss_InIrq = TRUE;
        D(bug("%s: Call interrupt? IS=%02x, IE=%02x, IM=%02x = %02x\n", __func__, ss->ss_Reg[SL811HS_INTSTATUS], ss->ss_Reg[SL811HS_INTENABLE], mask, (ss->ss_Reg[SL811HS_INTSTATUS] & ss->ss_Reg[SL811HS_INTENABLE]) & mask));
        while ((ss->ss_Reg[SL811HS_INTSTATUS] & ss->ss_Reg[SL811HS_INTENABLE]) & mask) {
            D(bug("%s: Call interrupt! IS=%02x, IE=%02x, IM=%02x = %02x\n", __func__, ss->ss_Reg[SL811HS_INTSTATUS], ss->ss_Reg[SL811HS_INTENABLE], mask, (ss->ss_Reg[SL811HS_INTSTATUS] & ss->ss_Reg[SL811HS_INTENABLE]) & mask));
            AROS_INTC3(ss->ss_Interrupt->is_Code, ss->ss_Interrupt->is_Data, (1 << 6), (APTR)0xdff000);
        }
        ss->ss_InIrq = FALSE;
    } else {
        D(bug("%s: In IRQ\n", __func__));
    }
}
Example #12
0
/* Replaces violence_update */
void ev_violence( void *data )
{
   char_data *ch = ( char_data * ) data;

   if( !ch )
   {
      bug( "%s: nullptr ch pointer!", __func__ );
      return;
   }
   char_data *victim = ch->who_fighting(  );

   if( !victim || !ch->in_room || !ch->name || ( ch->in_room != victim->in_room ) )
   {
      ch->stop_fighting( true );
      return;
   }

   if( ch->char_died(  ) )
   {
      ch->stop_fighting( true );
      return;
   }

   /*
    * Let the battle begin! 
    */
   if( ch->has_aflag( AFF_PARALYSIS ) )
   {
      add_event( 2, ev_violence, ch );
      return;
   }

   ch_ret retcode = rNONE;

   if( ch->in_room->flags.test( ROOM_SAFE ) )
   {
      log_printf( "%s: %s fighting %s in a SAFE room.", __func__, ch->name, victim->name );
      ch->stop_fighting( true );
   }
   else if( ch->IS_AWAKE(  ) && ch->in_room == victim->in_room )
      retcode = multi_hit( ch, victim, TYPE_UNDEFINED );
   else
      ch->stop_fighting( false );

   if( ch->char_died(  ) )
      return;

   if( retcode == rCHAR_DIED || !( victim = ch->who_fighting(  ) ) )
      return;

   /*
    *  Mob triggers
    *  -- Added some victim death checks, because it IS possible.. -- Alty
    */
   rprog_rfight_trigger( ch );
   if( ch->char_died(  ) || victim->char_died(  ) )
      return;

   mprog_hitprcnt_trigger( ch, victim );
   if( ch->char_died(  ) || victim->char_died(  ) )
      return;

   mprog_fight_trigger( ch, victim );
   if( ch->char_died(  ) || victim->char_died(  ) )
      return;

   /*
    * NPC special attack flags - Thoric
    */
   int attacktype = -2, cnt = -2;
   if( ch->isnpc(  ) )
   {
      if( ch->has_attacks(  ) )
      {
         attacktype = -1;
         if( 30 + ( ch->level / 4 ) >= number_percent(  ) )
         {
            cnt = 0;
            for( ;; )
            {
               if( cnt++ > 10 )
               {
                  attacktype = -1;
                  break;
               }
               attacktype = number_range( 7, MAX_ATTACK_TYPE - 1 );
               if( ch->has_attack( attacktype ) )
                  break;
            }
            switch ( attacktype )
            {
               default:
                  break;

               case ATCK_BASH:
                  interpret( ch, "bash" );
                  retcode = global_retcode;
                  break;

               case ATCK_STUN:
                  interpret( ch, "stun" );
                  retcode = global_retcode;
                  break;

               case ATCK_GOUGE:
                  interpret( ch, "gouge" );
                  retcode = global_retcode;
                  break;

               case ATCK_AGE:
                  do_ageattack( ch, "" );
                  retcode = global_retcode;
                  break;

               case ATCK_DRAIN:
                  retcode = spell_energy_drain( skill_lookup( "energy drain" ), ch->level, ch, victim );
                  break;

               case ATCK_FIREBREATH:
                  retcode = spell_fire_breath( skill_lookup( "fire breath" ), ch->level, ch, victim );
                  break;

               case ATCK_FROSTBREATH:
                  retcode = spell_frost_breath( skill_lookup( "frost breath" ), ch->level, ch, victim );
                  break;

               case ATCK_ACIDBREATH:
                  retcode = spell_acid_breath( skill_lookup( "acid breath" ), ch->level, ch, victim );
                  break;

               case ATCK_LIGHTNBREATH:
                  retcode = spell_lightning_breath( skill_lookup( "lightning breath" ), ch->level, ch, victim );
                  break;

               case ATCK_GASBREATH:
                  retcode = spell_gas_breath( skill_lookup( "gas breath" ), ch->level, ch, victim );
                  break;

               case ATCK_SPIRALBLAST:
                  retcode = spell_spiral_blast( skill_lookup( "spiral blast" ), ch->level, ch, victim );
                  break;

               case ATCK_POISON:
                  retcode = spell_smaug( gsn_poison, ch->level, ch, victim );
                  break;

               case ATCK_NASTYPOISON:
                  retcode = spell_smaug( gsn_poison, ch->level, ch, victim );
                  break;

               case ATCK_GAZE:
                  break;

               case ATCK_BLINDNESS:
                  retcode = spell_smaug( skill_lookup( "blindness" ), ch->level, ch, victim );
                  break;

               case ATCK_CAUSESERIOUS:
                  retcode = spell_smaug( skill_lookup( "cause serious" ), ch->level, ch, victim );
                  break;

               case ATCK_EARTHQUAKE:
                  retcode = spell_smaug( skill_lookup( "earthquake" ), ch->level, ch, victim );
                  break;

               case ATCK_CAUSECRITICAL:
                  retcode = spell_smaug( skill_lookup( "cause critical" ), ch->level, ch, victim );
                  break;

               case ATCK_CURSE:
                  retcode = spell_smaug( skill_lookup( "curse" ), ch->level, ch, victim );
                  break;

               case ATCK_FLAMESTRIKE:
                  retcode = spell_smaug( skill_lookup( "flamestrike" ), ch->level, ch, victim );
                  break;

               case ATCK_HARM:
                  retcode = spell_smaug( skill_lookup( "harm" ), ch->level, ch, victim );
                  break;

               case ATCK_FIREBALL:
                  retcode = spell_smaug( skill_lookup( "fireball" ), ch->level, ch, victim );
                  break;

               case ATCK_COLORSPRAY:
                  retcode = spell_smaug( skill_lookup( "colour spray" ), ch->level, ch, victim );
                  break;

               case ATCK_WEAKEN:
                  retcode = spell_smaug( skill_lookup( "weaken" ), ch->level, ch, victim );
                  break;
            }
            if( attacktype != -1 && ( retcode == rCHAR_DIED || ch->char_died(  ) ) )
               return;
         }
      }

      /*
       * NPC special defense flags - Thoric
       */
      if( ch->has_defenses(  ) )
      {
         /*
          * Fix for character not here bugs --Shaddai 
          */
         if( ch->char_died( ) || victim->char_died( ) )
            return;

         attacktype = -1;
         if( 50 + ( ch->level / 4 ) > number_percent(  ) )
         {
            cnt = 0;
            for( ;; )
            {
               if( cnt++ > 10 )
               {
                  attacktype = -1;
                  break;
               }
               attacktype = number_range( 2, MAX_DEFENSE_TYPE - 1 );
               if( ch->has_defense( attacktype ) )
                  break;
            }

            switch ( attacktype )
            {
               default:
                  break;

               case DFND_CURELIGHT:
                  act( AT_MAGIC, "$n mutters a few incantations...and looks a little better.", ch, nullptr, nullptr, TO_ROOM );
                  retcode = spell_smaug( skill_lookup( "cure light" ), ch->level, ch, ch );
                  break;

               case DFND_CURESERIOUS:
                  act( AT_MAGIC, "$n mutters a few incantations...and looks a bit better.", ch, nullptr, nullptr, TO_ROOM );
                  retcode = spell_smaug( skill_lookup( "cure serious" ), ch->level, ch, ch );
                  break;

               case DFND_CURECRITICAL:
                  act( AT_MAGIC, "$n mutters a few incantations...and looks healthier.", ch, nullptr, nullptr, TO_ROOM );
                  retcode = spell_smaug( skill_lookup( "cure critical" ), ch->level, ch, ch );
                  break;

               case DFND_HEAL:
                  act( AT_MAGIC, "$n mutters a few incantations...and looks much healthier.", ch, nullptr, nullptr, TO_ROOM );
                  retcode = spell_smaug( skill_lookup( "heal" ), ch->level, ch, ch );
                  break;

               case DFND_DISPELMAGIC:
                  if( !victim->affects.empty(  ) )
                  {
                     act( AT_MAGIC, "$n utters an incantation...", ch, nullptr, nullptr, TO_ROOM );
                     retcode = spell_dispel_magic( skill_lookup( "dispel magic" ), ch->level, ch, victim );
                  }
                  break;

               case DFND_DISPELEVIL:
                  act( AT_MAGIC, "$n utters an incantation...", ch, nullptr, nullptr, TO_ROOM );
                  retcode = spell_dispel_evil( skill_lookup( "dispel evil" ), ch->level, ch, victim );
                  break;

               case DFND_FIRESHIELD:
                  if( !ch->has_aflag( AFF_FIRESHIELD ) )
                  {
                     act( AT_MAGIC, "$n utters a few incantations...", ch, nullptr, nullptr, TO_ROOM );
                     retcode = spell_smaug( skill_lookup( "fireshield" ), ch->level, ch, ch );
                  }
                  else
                     retcode = rNONE;
                  break;

               case DFND_SHOCKSHIELD:
                  if( !ch->has_aflag( AFF_SHOCKSHIELD ) )
                  {
                     act( AT_MAGIC, "$n utters a few incantations...", ch, nullptr, nullptr, TO_ROOM );
                     retcode = spell_smaug( skill_lookup( "shockshield" ), ch->level, ch, ch );
                  }
                  else
                     retcode = rNONE;
                  break;

               case DFND_SANCTUARY:
                  if( !ch->has_aflag( AFF_SANCTUARY ) )
                  {
                     act( AT_MAGIC, "$n utters a few incantations...", ch, nullptr, nullptr, TO_ROOM );
                     retcode = spell_smaug( skill_lookup( "sanctuary" ), ch->level, ch, ch );
                  }
                  else
                     retcode = rNONE;
                  break;
            }
            if( attacktype != -1 && ( retcode == rCHAR_DIED || ch->char_died(  ) ) )
               return;
         }
      }
   }

   // Attack values reset - past here they mean nothing and I'm on a bughunt dammit!
   attacktype = -2;
   cnt = -2;
   retcode = -2;

   /*
    * Fun for the whole family!
    */
   list < char_data * >::iterator ich;
   for( ich = ch->in_room->people.begin(  ); ich != ch->in_room->people.end(  ); )
   {
      char_data *rch = *ich;
      ++ich;

      if( ch->in_room != rch->in_room )
         break;

      if( rch->IS_AWAKE(  ) && !rch->fighting )
      {
         /*
          * PC's auto-assist others in their group.
          */
         if( !ch->isnpc(  ) || ch->has_aflag( AFF_CHARM ) || ch->has_actflag( ACT_PET ) )
         {
            if( rch->isnpc(  ) && ( rch->has_aflag( AFF_CHARM ) || rch->is_pet(  ) ) )
            {
               multi_hit( rch, victim, TYPE_UNDEFINED );
               continue;
            }
            if( is_same_group( ch, rch ) && rch->has_pcflag( PCFLAG_AUTOASSIST ) )
            {
               multi_hit( rch, victim, TYPE_UNDEFINED );
               continue;
            }
         }

         /*
          * NPC's assist NPC's of same type or 12.5% chance regardless.
          */
         if( !rch->is_pet(  ) && !rch->has_aflag( AFF_CHARM ) && !rch->has_actflag( ACT_NOASSIST ) )
         {
            if( ch->char_died(  ) )
               break;
            if( rch->pIndexData == ch->pIndexData || number_bits( 3 ) == 0 )
            {
               list < char_data * >::iterator ich2;
               char_data *target = nullptr;
               int number = 0;

               for( ich2 = ch->in_room->people.begin(  ); ich2 != ch->in_room->people.end(  ); ++ich2 )
               {
                  char_data *vch = *ich2;

                  if( rch->can_see( vch, false ) && is_same_group( vch, victim ) && number_range( 0, number ) == 0 )
                  {
                     if( vch->mount && vch->mount == rch )
                        target = nullptr;
                     else
                     {
                        target = vch;
                        ++number;
                     }
                  }
               }
               if( target )
                  multi_hit( rch, target, TYPE_UNDEFINED );
            }
         }
      }
   }

   /*
    * If we are both still here lets get together and do it again some time :) 
    */
   if( ch && victim && victim->position != POS_DEAD && ch->position != POS_DEAD )
      add_event( 2, ev_violence, ch );
}
Example #13
0
/* Replaces auction_update */
void ev_auction( void *data )
{
   room_index *aucvault;

   if( !auction->item )
      return;

   switch ( ++auction->going )   /* increase the going state */
   {
      default:
      case 1: /* going once */
      case 2: /* going twice */
      {
         talk_auction( "%s: going %s for %d.", auction->item->short_descr, ( ( auction->going == 1 ) ? "once" : "twice" ), auction->bet );

         add_event( sysdata->auctionseconds, ev_auction, nullptr );
      }
         break;

      case 3: /* SOLD! */
         if( !auction->buyer && auction->bet )
         {
            bug( "%s: Auction code reached SOLD, with nullptr buyer, but %d gold bid", __func__, auction->bet );
            auction->bet = 0;
         }
         if( auction->bet > 0 && auction->buyer != auction->seller )
         {
            obj_data *obj = auction->item;

            aucvault = get_room_index( auction->seller->in_room->vnum + 1 );

            talk_auction( "%s sold to %s for %d gold.", auction->item->short_descr,
                          auction->buyer->isnpc(  )? auction->buyer->short_descr : auction->buyer->name, auction->bet );

            if( auction->item->buyer ) /* Set final buyer for item - Samson 6-23-99 */
            {
               STRFREE( auction->item->buyer );
               auction->item->buyer = STRALLOC( auction->buyer->name );
            }

            auction->item->bid = auction->bet;  /* Set final bid for item - Samson 6-23-99 */

            /*
             * Stop it from listing on house lists - Samson 11-1-99 
             */
            auction->item->extra_flags.reset( ITEM_AUCTION );

            /*
             * Reset the 1 year timer on the item - Samson 11-1-99 
             */
            auction->item->day = time_info.day;
            auction->item->month = time_info.month;
            auction->item->year = time_info.year + 1;

            auction->item->to_room( aucvault, auction->seller );
            save_aucvault( auction->seller, auction->seller->short_descr );

            add_sale( auction->seller->short_descr, obj->seller, auction->buyer->name, obj->short_descr, obj->bid, false );

            auction->item = nullptr;   /* reset item */
            obj = nullptr;
         }
         else  /* not sold */
         {
            aucvault = get_room_index( auction->seller->in_room->vnum + 1 );

            talk_auction( "No bids received for %s - removed from auction.\r\n", auction->item->short_descr );
            talk_auction( "%s has been returned to the auction house.\r\n", auction->item->short_descr );

            auction->item->to_room( aucvault, auction->seller );
            save_aucvault( auction->seller, auction->seller->short_descr );
         }  /* else */
         auction->item = nullptr;   /* clear auction */
   }  /* switch */
}
Example #14
0
/*  SYNOPSIS */

/*  LOCATION */
	struct KernelBase *, KernelBase, 11, Kernel)

/*  FUNCTION

    INPUTS

    RESULT

    NOTES

    EXAMPLE

    BUGS

    SEE ALSO

    INTERNALS

******************************************************************************/
{
    AROS_LIBFUNC_INIT

    D(bug("[Kernel] KrnGetBootInfo()\n"));
    return BootMsg;

    AROS_LIBFUNC_EXIT
}
Example #15
0
void do_mppurge( CHAR_DATA *ch, char *argument )
{
    char       arg[ MAX_INPUT_LENGTH ];
    CHAR_DATA *victim;
    OBJ_DATA  *obj;

    if ( !IS_NPC( ch ) )
    {
        send_to_char( C_DEFAULT, "Huh?\n\r", ch );
	return;
    }

    if ( IS_AFFECTED( ch, AFF_CHARM ) )
    {
        return;
    }

    one_argument( argument, arg );

    if ( arg[0] == '\0' )
    {
        /* 'purge' */
        CHAR_DATA *vnext;
        OBJ_DATA  *obj_next;

	for ( victim = ch->in_room->people; victim != NULL; victim = vnext )
	{
	  vnext = victim->next_in_room;
	  if ( IS_NPC( victim ) && victim != ch )
	    extract_char( victim, TRUE );
	}

	for ( obj = ch->in_room->contents; obj != NULL; obj = obj_next )
	{
	  obj_next = obj->next_content;
	  extract_obj( obj );
	}

	return;
    }

    if ( ( victim = get_char_room( ch, arg ) ) == NULL )
    {
	if ( ( obj = get_obj_here( ch, arg ) ) )
	{
	    extract_obj( obj );
	}
	else
	{
	    bug( "Mppurge - Bad argument: vnum %d.", ch->pIndexData->vnum );
	}
	return;
    }

    if ( !IS_NPC( victim ) )
    {
	bug( "Mppurge - Purging a PC: vnum %d.", ch->pIndexData->vnum );
	return;
    }

    extract_char( victim, TRUE );
    return;
}
Example #16
0
void do_crusade(CHAR_DATA *ch, char *argument)
{
    DESCRIPTOR_DATA* d;
    CHAR_DATA *questman;
    CHAR_DATA *boss;
    char buf  [MAX_STRING_LENGTH];
    char arg1 [MAX_INPUT_LENGTH];
    char arg2 [MAX_INPUT_LENGTH];

    argument = one_argument(argument, arg1);
    argument = one_argument(argument, arg2);

    if (arg1[0] == '\0')
    {
        send_to_char(AT_WHITE, "CRUSADE commands: POINTS INFO TIME REQUEST COMPLETE LIST BUY ADVANCE.\n\r",ch);
        send_to_char(AT_WHITE, "For more information, type 'HELP CRUSADE'.\n\r",ch);
        return;
    }

    if (!str_cmp(arg1, "time"))
    {
	if (IS_SET(ch->act2, PLR_RELQUEST))
	{
		sprintf(buf, "You have %d minutes left on your crusade!\n\r", ch->rcountdown);
	} else
	{
		if (ch->rnextquest > 0)
		{
			sprintf(buf, "You have %d minutes left before your next crusade!\n\r", ch->rnextquest);
		} else
		{
			strcpy(buf, "You are free to do a crusade right now!\n\r");
		}
	}
	send_to_char(AT_WHITE, buf, ch);
	return;
    } else if (!str_cmp(arg1, "points"))
    {
	sprintf(buf, "You have %d relgion points.\n\r", ch->rquestpoints);
	send_to_char(AT_WHITE, buf, ch);
	return;
    } else if (!str_cmp(arg1, "info"))
    {
	OBJ_INDEX_DATA* oinfo;
	MOB_INDEX_DATA* minfo;

	if (!IS_SET(ch->act2, PLR_RELQUEST))
	{
		send_to_char(AT_WHITE, "You are not on a crusade!\n\r", ch);
		return;
	}

	if (ch->rquestobj[ch->relquest_level]==0 && ch->rquestmob[ch->relquest_level]==0)
	{
		if (ch->in_room->vnum <= REL_VNUM_UPPER && ch->in_room->vnum >= REL_VNUM_LOWER)
		{
			send_to_char(AT_WHITE, "You are almost finished your crusade.\n\rFind the portal to the next level!\n\r", ch);
			return;
		} else
		{
			send_to_char(AT_WHITE, "You are almost finished your crusade!\n\rFind your DEITY and COMPLETE you quest!\n\r",ch);
			return;
		}
	} 

	if (ch->rquestmob[ch->relquest_level])
	{
		if (ch->rquestmob[ch->relquest_level] == -1)
		{
			send_to_char(AT_WHITE, "You are almost done your crusade!\n\rFind the boss and ADVANCE!\n\r", ch);
			return;
		} else
		{
			minfo = get_mob_index( ch->rquestmob[ch->relquest_level] );
			sprintf(buf, "You are on a crusade to slay the dreaded %s!\n\r", minfo->short_descr);
		}
   	} else
	{
		oinfo = get_obj_index( ch->rquestobj[ch->relquest_level] );
		sprintf(buf, "You are on a crusade to retrieve the fabled %s!\n\r", oinfo->short_descr);
	}
	send_to_char(AT_WHITE, buf, ch);
	return; 
    }

    for ( questman = ch->in_room->people; questman != NULL; questman = questman->next_in_room)
    {
        if (!IS_NPC(questman)) continue;
        if (IS_SET(questman->act, ACT_IS_DEITY)) break;
    }

    for (boss = ch->in_room->people; boss; boss = boss->next_in_room)
    {
	if (!IS_NPC(boss)) continue;
	if (IS_SET(boss->act, ACT_RELBOSS)) break;
    }


    if (!str_cmp(arg1, "request"))
    {
        int member_count = 0;
	CHAR_DATA* group[MAX_GROUP];

  	if (questman==NULL)
        {
   		send_to_char(AT_WHITE, "Your deity is not here!\n\r", ch);
    	  	return;
        }


        if (IS_SET(ch->act2, PLR_RELQUEST))
	{
		send_to_char(AT_WHITE, "You are already ON a crusade!\n\r",ch);
		return;
	}
	if (relquest)
	{
		send_to_char(AT_WHITE, "The gods have already set a crusade to be finished!\n\r",ch);
		return;
	}
	if (ch->master)
	{
	    send_to_char(AT_WHITE, "Only your group leader can ask for a crusade!\n\r", ch);
	    return;
	}
	if (ch->alignment > -500 && ch->alignment < 500) /* || (ch->religion == TIME_AND_FATE */
	{
	    send_to_char(AT_WHITE, "You are neutral. You cannot go upon a crusade!\n\r",ch);
	    return;
	}
	if (ch->leader)
	{
	    send_to_char(AT_WHITE, "Only the leader of your group can request a crusade!\n\r", ch);
	    return;
	}
	for ( d = descriptor_list; d; d = d->next )
        {
	    RELIGION_DATA* rd = NULL;
	    CHAR_DATA* gch = NULL;

	    if ( d->connected != CON_PLAYING )
        	continue;

	    gch = d->character;

	    if ( !is_same_group(gch , ch ) )
                continue;

	    if ( gch->in_room != ch->in_room )
	    {
		send_to_char(AT_WHITE, "Your must gather your party before venturing forth!\n\r", ch);
		return;
	    }

	    if ( gch->rnextquest > 0 )
	    {
		sprintf(buf, "%s must wait before doing another crusade!\n\r", gch->name);
		send_to_char(AT_WHITE, "You must wait before your next Crusade!\n\r", gch);
		send_to_char(AT_WHITE, buf, ch);
		return;
	    }
          
	    if ( gch->level < REL_QUEST_MIN )
	    {
		sprintf(buf, "%s is not high enough level to do a Crusade!\n\r", gch->name);
		send_to_char(AT_WHITE, "You are not high enough level to complete a Crusade!\n\r", gch);
		send_to_char(AT_WHITE, buf, ch);
		return;
	    }

	    rd = get_religion_index( ch->religion );
/*
Quest Restriction to Deities
Out for debug
	    if (!strstr(questman->short_descr, rd->deity ) )
	    {
	        sprintf(buf, "%s would not appreciate you devoting your crusades to %s!\n\rFind your own Deity!\n\r", rd->deity, questman->short_descr);
		send_to_char(AT_WHITE, buf, ch);
		return;
	    }
*/
	    group[member_count] = gch;
	    member_count++;
	    if (ch->alignment >= 500)
	    {
		if (gch->alignment <= -500) /* || gch->religion == EVIL */
		{
		    sprintf(buf, "Your deity will not accept %s upon your crusade!\n\r", gch->name);
		    send_to_char(AT_WHITE, buf, ch);
		    return;
		}
	    } else if (ch->alignment <= -500)
	    {
		if (gch->alignment >= 500) /* || gch->religion == GOOD */
		{
		    sprintf(buf, "Your deity will not accept %s upon your crusade!\n\r", gch->name);
		    send_to_char(AT_WHITE, buf, ch);
		    return;
		}
	    }
        }
        if (member_count < 2)
	{
	    send_to_char(AT_WHITE, "You need 2 or more heroes for a crusade!\n\r", ch);
	    return;
	}
        if (ch->alignment >= 500)
        {
 	    int levels = (((((ch->level > LEVEL_DEMIGOD) ? LEVEL_DEMIGOD : ch->level )) - REL_QUEST_MIN)/(14))+1;
	    if(rel_quest_gen(ch, ALIGN_GOOD, levels))
            {
		int qtime = number_range(15, 45);
		int curmemb;
		relquest=TRUE;
		/* Made it... let's go! */

		rel_quest_goals(ch, levels, ALIGN_GOOD);
		for ( curmemb = 0; curmemb < member_count; curmemb++)
        	{
		    int i;
		    for (i = 0; i < levels; i++)
		    {
			group[curmemb]->rquestobj[i] = ch->rquestobj[i];
			group[curmemb]->rquestmob[i] = ch->rquestmob[i];
		    }
		    group[curmemb]->relquest_level = 0;
		    group[curmemb]->rcountdown = qtime;
	    	    SET_BIT(group[curmemb]->act2, PLR_RELQUEST);
		    char_from_room(group[curmemb]);
		    char_to_room  (group[curmemb], get_room_index( REL_VNUM_UPPER ) );
		    send_to_char( AT_WHITE, "The smell of honey and sweet perfume fills your nose!\n\r", group[curmemb]);
		    interpret( group[curmemb], "look" );
		    interpret( group[curmemb], "crusade info" );
		}
	        return;

	    } else
	    {
		bug("rel_quest_gen: Failed to create quest!",0);
	    }                
	} else if (ch->alignment <= -500)
	{
	    int levels = (((((ch->level > LEVEL_DEMIGOD) ? LEVEL_DEMIGOD : ch->level )) - REL_QUEST_MIN)/( 14 ))+1;
	    if(rel_quest_gen(ch, ALIGN_EVIL, levels))
     	    {
		int qtime = number_range(15, 45);
		int curmemb;
		relquest=TRUE;

		/* Made it... let's go! */
		rel_quest_goals(ch, levels, ALIGN_EVIL);
		for ( curmemb=0; curmemb < member_count; curmemb++)
        	{
		    int i;
		    for (i = 0; i < levels; i++)
		    {
			group[curmemb]->rquestobj[i] = ch->rquestobj[i];
			group[curmemb]->rquestmob[i] = ch->rquestmob[i];
		    }
		    group[curmemb]->relquest_level = 0;
		    group[curmemb]->rcountdown = qtime;
	    	    SET_BIT(group[curmemb]->act2, PLR_RELQUEST);
		    char_from_room(group[curmemb]);
		    char_to_room  (group[curmemb], get_room_index( REL_VNUM_LOWER ) );
		    send_to_char( AT_RED, "The flames of hell singe your armor!\n\r", group[curmemb]);
		    interpret( group[curmemb], "look" );
	   	    interpret( group[curmemb], "crusade info" );
		}
	        return;
	    } else
	    {
		bug("rel_quest_gen: Failed to create quest!",0);
	    }                

	}
    } else if (!str_cmp(arg1,"complete"))
    {
    	if (questman==NULL)
    	{
   		send_to_char(AT_WHITE, "Your deity is not here!\n\r", ch);
    		return;
        }

	if (IS_SET(ch->act2, PLR_RELQUEST) && ch->rcountdown > 0)
        {
	    CHAR_DATA* gch = NULL;
	    int qp;
	    qp = number_range( ch->level/4, ch->level/2);
	    if (ch->leader || ch->master)
	    {
		send_to_char(AT_WHITE, "Only the group leader can complete a crusade!\n\r", ch);
		return;
	    }
	    for (d=descriptor_list; d; d = d->next)
	    {     
	    	if ( d->connected != CON_PLAYING )
        		continue;
		if (is_same_group(d->character, ch))
		{
			if (d->character->in_room != ch->in_room)
			{
				send_to_char(AT_WHITE, "You must gather your party before completing a crusade!\n\r", ch);
				return;
			}
		}	    	
	    }
	    // the whole party is in the room
	    for (gch=ch->in_room->people; gch; gch=gch->next_in_room)
	    {
	    	if (is_same_group(ch, gch))
		{
			int gqp = number_fuzzy(qp);
			sprintf(buf, "You have gained %d religion points for your service!\n\r", gqp);
			send_to_char(AT_WHITE, "YAY! You completed your crusade!\n\r",gch);
			gch->rquestpoints += gqp;
    			gch->rnextquest = number_range(10, 30);
    			gch->rcountdown = 0;
			send_to_char(AT_WHITE, buf, gch);
	    		REMOVE_BIT(gch->act2, PLR_RELQUEST);
		}
	    }

	    relquest=FALSE; 
	    return;
        } else
	{
	    send_to_char(AT_WHITE, "You are not on a religious crusade!\n\r",ch);
	    return;
	}
    } else if(!str_cmp(arg1, "list"))
    {
    	if (questman==NULL)
    	{
   		send_to_char(AT_WHITE, "Your deity is not here!\n\r", ch);
    		return;
    	}

	send_to_char(AT_WHITE, "Nothing to list yet.\n\r", ch);
	return;
    } else if(!str_cmp(arg1, "buy"))
    {
    	if (questman==NULL)
    	{
   		send_to_char(AT_WHITE, "Your deity is not here!\n\r", ch);
    		return;
	}

	send_to_char(AT_WHITE, "Nothing to buy quite yet.\n\r", ch);
	return;
    } else if(!str_cmp(arg1, "advance"))
    {
	DESCRIPTOR_DATA* d;

	if(!IS_SET(ch->act2, PLR_RELQUEST))
	{
		send_to_char(AT_WHITE, "You cannot advance a crusade if you are not on one!\n\r", ch);
		return;
	}
	if(ch->leader || ch->master)
	{
		send_to_char(AT_WHITE, "Only the group leader can advance a crusade!\n\r", ch);
		return;
	}
	
	if (!boss)
	{
		send_to_char(AT_WHITE, "You need to find the boss of this level before you can advance!\n\r", ch);
		return;
	}

	if (ch->rquestmob[ch->relquest_level] > 0 && ch->rcountdown > 0)
	{
		send_to_char(AT_WHITE, "You have not completed this section of your crusade!\n\r", ch);
		return;
	} else if (ch->rquestobj[ch->relquest_level] > 0 && ch->rcountdown > 0)
	{
		bool found = FALSE;
		OBJ_DATA* obj;
		for (obj = ch->carrying; obj; obj = obj->next)
		{
			if (obj->pIndexData->vnum == ch->rquestobj[ch->relquest_level])
			{
				found = TRUE;
				extract_obj(obj);
			}
		}
		if (!found)
		{
			send_to_char(AT_WHITE, "You have not completed this section of your crusade!\n\r", ch);
			return;
		}
	} 
	ch->rquestobj[ch->relquest_level]=0;
	ch->rquestmob[ch->relquest_level]=0;
	for (d=descriptor_list; d; d = d->next)
        {
                if ( d->connected != CON_PLAYING )
                        continue;
                if (is_same_group(d->character, ch))
                {
			d->character->rquestmob[ch->relquest_level] = 0;
			d->character->rquestobj[ch->relquest_level] = 0;
			send_to_char(AT_WHITE, "You feel free to pursue the next part of your crusade!\n\r", d->character);
		}
	} 
    } else
    {
        send_to_char(AT_WHITE, "CRUSADE commands: POINTS INFO TIME REQUEST COMPLETE LIST BUY ADVANCE.\n\r",ch);
        send_to_char(AT_WHITE, "For more information, type 'HELP CRUSADE'.\n\r",ch);
        return;
    }
}
Example #17
0
void do_mptransfer( CHAR_DATA *ch, char *argument )
{
    char             arg1[ MAX_INPUT_LENGTH ];
    char             arg2[ MAX_INPUT_LENGTH ];
    ROOM_INDEX_DATA *location;
    DESCRIPTOR_DATA *d;
    CHAR_DATA       *victim;

    if ( !IS_NPC( ch ) )
    {
	send_to_char( C_DEFAULT, "Huh?\n\r", ch );
	return;
    }

    if ( IS_AFFECTED( ch, AFF_CHARM ) )
    {
        return;
    }

    argument = one_argument( argument, arg1 );
    argument = one_argument( argument, arg2 );

    if ( arg1[0] == '\0' )
    {
	bug( "Mptransfer - Bad syntax: vnum %d.", ch->pIndexData->vnum );
	return;
    }

    if ( !str_cmp( arg1, "all" ) )
    {
	for ( d = descriptor_list; d != NULL; d = d->next )
	{
	    if ( d->connected == CON_PLAYING
	    &&   d->character != ch
	    &&   d->character->in_room != NULL
	    &&   can_see( ch, d->character ) )
	    {
		char buf[MAX_STRING_LENGTH];
		sprintf( buf, "%s %s", d->character->name, arg2 );
		do_transfer( ch, buf );
	    }
	}
	return;
    }

    /*
     * Thanks to Grodyn for the optional location parameter.
     */
    if ( arg2[0] == '\0' )
    {
	location = ch->in_room;
    }
    else
    {
	if ( ( location = find_location( ch, arg2 ) ) == NULL )
	{
	    bug( "Mptransfer - No such location: vnum %d.",
	        ch->pIndexData->vnum );
	    return;
	}

	if ( room_is_private( location ) )
	{
	    bug( "Mptransfer - Private room: vnum %d.",
		ch->pIndexData->vnum );
	    return;
	}
    }

    if ( ( victim = get_char_world( ch, arg1 ) ) == NULL )
    {
	bug( "Mptransfer - No such person: vnum %d.",
	    ch->pIndexData->vnum );
	return;
    }

    if ( victim->in_room == NULL )
    {
	bug( "Mptransfer - Victim in Limbo: vnum %d.",
	    ch->pIndexData->vnum );
	return;
    }

    if ( victim->in_room == location )
      return;

/* Changing this, if victim is fighting, DON'T WORK */
/*
    if ( victim->fighting != NULL )
	stop_fighting( victim, TRUE );
*/
    if ( victim->fighting != NULL )
    {
	bug( "Mptransfer - Victim fighting: vnum %d",
	    ch->pIndexData->vnum );
	return;
    }

    char_from_room( victim );
    char_to_room( victim, location );

    return;
}
Example #18
0
/*****************************************************************************
 Name:		save_resets
 Purpose:	Saves the #RESETS section of an area file.
                New format thanks to Rac.
 Called by:	save_area(olc_save.c)
 ****************************************************************************/
void save_resets( FILE *fp, AREA_DATA *pArea )
{
    RESET_DATA *pReset;
    MOB_INDEX_DATA *pLastMob = NULL;
    OBJ_INDEX_DATA *pLastObj;
    ROOM_INDEX_DATA *pRoomIndex;
    char buf[MAX_STRING_LENGTH];
    int vnum;

    fprintf( fp, "#RESETS\n" );

    for( vnum = pArea->lvnum; vnum <= pArea->uvnum; vnum++ )
    {
        if( ( pRoomIndex = get_room_index(vnum) ) )
        {
            if ( pRoomIndex->area == pArea )
            {
                for ( pReset = pRoomIndex->reset_first; pReset; pReset = pReset->next )
                {
                    switch ( pReset->command )
                    {
                        default:
                            bug( "Save_resets: bad command %c.", pReset->command );
                            break;

                        case 'M':
                            pLastMob = get_mob_index( pReset->arg1 );
                            fprintf( fp, "M 0 %d %d %d\n",
                                pReset->arg1,
                                pReset->arg2,
                                pReset->arg3 );
                            break;

                        case 'O':
                            pLastObj = get_obj_index( pReset->arg1 );
                            fprintf( fp, "O 0 %d 0 %d\n",
                                pReset->arg1,
                                pReset->arg3 );
                            break;

                        case 'P':
                            pLastObj = get_obj_index( pReset->arg1 );
                            fprintf( fp, "P 0 %d 0 %d\n",
                                pReset->arg1,
                                pReset->arg3  );
                            break;

                        case 'G':
                            fprintf( fp, "G 0 %d 0\n", pReset->arg1 );
                            if ( !pLastMob )
                            {
                                sprintf( buf,
                                    "Save_resets: !NO_MOB! in [%s]", pArea->filename );
                                bug( buf, 0 );
                            }
                            break;

                        case 'E':
                            fprintf( fp, "E 0 %d 0 %d\n",
                                pReset->arg1,
                                pReset->arg3 );
                            if ( !pLastMob )
                            {
                                sprintf( buf,
                                    "Save_resets: !NO_MOB! in [%s]", pArea->filename );
                                bug( buf, 0 );
                            }
                            break;

                        case 'D':
                            break;

                        case 'R':
                            fprintf( fp, "R 0 %d %d\n",
                                pReset->arg1,
                                pReset->arg2 );
                            break;
                    }                                       /* End switch */
                }                                           /* End for pReset */
            }                                               /* End if correct area */
        }                                                   /* End if pRoomIndex */
    }                                                       /* End for vnum */
    fprintf( fp, "S\n\n\n\n" );
    return;
}
Example #19
0
/*******************************************
 Name  : initVolume
 Descr.: maybe a better name would be mountVolume
         allocate resources for a new mounted device
 Input : device      - device pointer
         blockdevice - name of blockdevice
         unit        - unit number of blockdevice
         devicedef   - medium geometry data
         error       - return error code
 Output: 0 on error (error set dos dos error);
         pointer to struct Volume on success
********************************************/
struct Volume *initVolume
	(
		struct AFSBase *afsbase,
		struct Device *device,
		CONST_STRPTR blockdevice,
		ULONG unit,
		struct DosEnvec *devicedef,
		ULONG *error
	)
{
struct Volume *volume;

	volume = AllocMem(sizeof(struct Volume),MEMF_PUBLIC | MEMF_CLEAR);
	if (volume != NULL)
	{
		volume->device = device;
		volume->ioh.blockdevice = blockdevice;
		volume->ioh.unit = unit;
		volume->ioh.flags = 0;
		volume->SizeBlock=devicedef->de_SizeBlock;
		if (devicedef->de_TableSize>=20)
			volume->bootblocks=devicedef->de_BootBlocks;
		else
			volume->bootblocks=devicedef->de_Reserved;
		volume->blockcache=initCache(afsbase, volume, devicedef->de_NumBuffers);
		if (volume->blockcache != NULL)
		{
			if (openBlockDevice(afsbase, &volume->ioh)!= NULL)
			{
				volume->countblocks =
					(
						(
							devicedef->de_HighCyl-devicedef->de_LowCyl+1
						)*devicedef->de_Surfaces*devicedef->de_BlocksPerTrack
					);
				volume->rootblock =(volume->countblocks-1+devicedef->de_Reserved)/2;
				volume->startblock=
						devicedef->de_LowCyl*
						devicedef->de_Surfaces*
						devicedef->de_BlocksPerTrack;
				volume->lastblock=
						(
							(devicedef->de_HighCyl+1)
							*devicedef->de_Surfaces
							*devicedef->de_BlocksPerTrack
						)-1;
				check64BitSupport(afsbase, volume);
				volume->ah.volume=volume;
				if (mediumPresent(&volume->ioh))
				{
					*error = newMedium(afsbase, volume);
				}
				else
					*error = 0;
				if ((*error == 0) || (*error == ERROR_NOT_A_DOS_DISK))
				{
					D(bug("[afs] initVolume: BootBlocks=%d\n",volume->bootblocks));
					D(bug("[afs] initVolume: RootBlock=%ld\n",volume->rootblock));
					volume->ah.header_block = volume->rootblock;
					return volume;
				}
			}
			else
			{
				*error=ERROR_NO_FREE_STORE;
			}
			freeCache(afsbase, volume->blockcache);
		}
		else
		{
			*error=ERROR_NO_FREE_STORE;
		}
		FreeMem(volume,sizeof(struct Volume));
	}
	else
		*error=ERROR_NO_FREE_STORE;
	return NULL;
}
Example #20
0
/*****************************************************************************
 Name:		save_resets
 Purpose:	Saves the #RESETS section of an area file.
                New format thanks to Rac.
 Called by:	save_area(olc_save.c)
 ****************************************************************************/
void vsave_resets( FILE *fp, AREA_DATA *pArea )
{
    RESET_DATA *pReset;
    MOB_INDEX_DATA *pLastMob = NULL;
    OBJ_INDEX_DATA *pLastObj;
    ROOM_INDEX_DATA *pRoomIndex;
    char buf[MAX_STRING_LENGTH];
    int vnum;

    fprintf( fp, "#RESETS\n" );

    for( vnum = pArea->lvnum; vnum <= pArea->uvnum; vnum++ )
    {
        if( ( pRoomIndex = get_room_index(vnum) ) )
        {
            if ( pRoomIndex->area == pArea )
            {
                for ( pReset = pRoomIndex->reset_first; pReset; pReset = pReset->next )
                {
                    switch ( pReset->command )
                    {
                        default:
                            bug( "Save_resets: bad command %c.", pReset->command );
                            break;

                        case 'M':
                            pLastMob = get_mob_index( pReset->arg1 );
                            fprintf( fp, "M 0 %d %2d %-5d \t; %s to %s\n",
                                pReset->arg1,
                                pReset->arg2,
                                pReset->arg3,
                                pLastMob->short_descr,
                                pRoomIndex->name );
                            break;

                        case 'O':
                            pLastObj = get_obj_index( pReset->arg1 );
                            fprintf( fp, "O 0 %d  0 %-5d \t; %s to %s\n",
                                pReset->arg1,
                                pReset->arg3,
                                capitalize(pLastObj->short_descr),
                                pRoomIndex->name );
                            break;

                        case 'P':
                            pLastObj = get_obj_index( pReset->arg1 );
                            fprintf( fp, "P 0 %d  0 %-5d \t; %s inside %s\n",
                                pReset->arg1,
                                pReset->arg3,
                                capitalize(get_obj_index( pReset->arg1 )->short_descr),
                                pLastObj ? pLastObj->short_descr : "!NO_OBJ!" );

                            if ( !pLastObj )                /* Thanks Rac! */
                            {
                                sprintf( buf, "Save_resets: P with !NO_OBJ! in [%s]", pArea->filename );
                                bug( buf, 0 );
                            }

                            break;

                        case 'G':
                            pLastObj = get_obj_index( pReset->arg1 );
                            fprintf( fp, "G 0 %d  0      \t;   %s\n",
                                pReset->arg1,
                                capitalize(pLastObj->short_descr) );

                            if ( !pLastMob )
                            {
                                sprintf( buf, "Save_resets: !NO_MOB! in [%s]", pArea->filename );
                                bug( buf, 0 );
                            }
                            break;

                        case 'E':
                            fprintf( fp, "E 0 %d  0 %-5d \t;   %s %s\n",
                                pReset->arg1,
                                pReset->arg3,
                                capitalize(get_obj_index( pReset->arg1 )->short_descr),
                                flag_string( wear_loc_strings, pReset->arg3 ) );
                            if ( !pLastMob )
                            {
                                sprintf( buf, "Save_resets: !NO_MOB! in [%s]", pArea->filename );
                                bug( buf, 0 );
                            }
                            break;

                        case 'D':
                            break;

                        case 'R':
                            fprintf( fp, "R 0 %d %2d      \t; Randomize %s\n",
                                pReset->arg1,
                                pReset->arg2,
                                pRoomIndex->name );
                            break;
                    }                                       /* End switch */
                }                                           /* End for pReset */
            }                                               /* End if correct area */
        }                                                   /* End if pRoomIndex */
    }                                                       /* End for vnum */
    fprintf( fp, "S\n\n\n\n" );
    return;
}
Example #21
0
int main(void)
{
  bug(5, 36863);
  return 0;
}
Example #22
0
/*
 * Reset one room.
 */
void reset_room( ROOM_INDEX_DATA *room )
{
   RESET_DATA *pReset, *tReset, *gReset;
   OBJ_DATA *nestmap[MAX_NEST];
   CHAR_DATA *mob, *npc;
   OBJ_DATA *obj, *lastobj, *to_obj;
   ROOM_INDEX_DATA *pRoomIndex = NULL;
   MOB_INDEX_DATA *pMobIndex = NULL;
   OBJ_INDEX_DATA *pObjIndex = NULL, *pObjToIndex;
   EXIT_DATA *pexit;
   const char *filename = room->area->filename;
   int level = 0, n, num = 0, lastnest, onreset = 0;;
   bool notorious = FALSE;

   mob = NULL;
   obj = NULL;
   lastobj = NULL;
   if( !room->first_reset )
      return;
   level = 0;
   for( pReset = room->first_reset; pReset; pReset = pReset->next )
   {
      ++onreset;
      switch ( pReset->command )
      {
         default:
            bug( "%s: %s: bad command %c.", __FUNCTION__, filename, pReset->command );
            break;

         case 'M':
            if( !( pMobIndex = get_mob_index( pReset->arg1 ) ) )
            {
               bug( "%s: %s: 'M': bad mob vnum %d.", __FUNCTION__, filename, pReset->arg1 );
               continue;
            }
            if( !( pRoomIndex = get_room_index( pReset->arg3 ) ) )
            {
               bug( "%s: %s: 'M': bad room vnum %d.", __FUNCTION__, filename, pReset->arg3 );
               continue;
            }
            if( !pReset->sreset )
            {
               mob = NULL;
               break;
            }
            if( IS_SET( pMobIndex->act, ACT_NOTORIOUS ) ) 
               for( npc = first_char; npc; npc = npc->next )
                  if( IS_NPC( npc ) && npc->pIndexData->vnum == pMobIndex->vnum )
                  {
                     notorious = TRUE;
                     break;
                  }

            if( notorious )
               continue;

            mob = create_mobile( pMobIndex );
            {
               ROOM_INDEX_DATA *pRoomPrev = get_room_index( pReset->arg3 - 1 );

               if( pRoomPrev && IS_SET( pRoomPrev->room_flags, ROOM_PET_SHOP ) )
                  SET_BIT( mob->act, ACT_PET );
            }
            if( room_is_dark( pRoomIndex ) )
               xSET_BIT( mob->affected_by, AFF_INFRARED );
            mob->resetvnum = pRoomIndex->vnum;
            mob->resetnum = onreset;
            pReset->sreset = FALSE;
            char_to_room( mob, pRoomIndex );
            level = URANGE( 0, mob->top_level - 2, LEVEL_AVATAR );

            if( pReset->first_reset )
            {
               for( tReset = pReset->first_reset; tReset; tReset = tReset->next_reset )
               {
                  ++onreset;
                  switch( tReset->command )
                  {
                     case 'G':
                     case 'E':
                        if( !( pObjIndex = get_obj_index( tReset->arg1 ) ) )
                        {
                           bug( "%s: %s: 'E' or 'G': bad obj vnum %d.", __FUNCTION__, filename, tReset->arg1 );
                           continue;
                        }
                        if( !mob )
                        {
                           lastobj = NULL;
                           break;
                        }

                        if( mob->pIndexData->pShop )
                        {
                           int olevel = generate_itemlevel( room->area, pObjIndex );
                           obj = create_object( pObjIndex, olevel );
                           SET_BIT( obj->extra_flags, ITEM_INVENTORY );
                        }
                        else
                           obj = create_object( pObjIndex, number_fuzzy( level ) );
                        obj->level = URANGE( 0, obj->level, LEVEL_AVATAR );
                        obj = obj_to_char( obj, mob );
                        if( tReset->command == 'E' )
                        {
                           if( obj->carried_by != mob )
                           {
                              bug( "'E' reset: can't give object %d to mob %d.", obj->pIndexData->vnum, mob->pIndexData->vnum );
                              break;
                           }
                           equip_char( mob, obj, tReset->arg3 );
                        }
                        for( n = 0; n < MAX_NEST; n++ )
                           nestmap[n] = NULL;
                        nestmap[0] = obj;
                        lastobj = nestmap[0];
                        lastnest = 0;

                        if( tReset->first_reset )
                        {
                           for( gReset = tReset->first_reset; gReset; gReset = gReset->next_reset )
                           {
                              int iNest;
                              to_obj = lastobj;

                              ++onreset;
                              switch( gReset->command )
                              {
                                 case 'H':
                                    if( !lastobj )
                                       break;
                                    SET_BIT( lastobj->extra_flags, ITEM_HIDDEN );
                                    break;

                                 case 'P':
                                    if( !( pObjIndex = get_obj_index( gReset->arg1 ) ) )
                                    {
                                       bug( "%s: %s: 'P': bad obj vnum %d.", __FUNCTION__, filename, gReset->arg1 );
                                       continue;
                                    }
                                    iNest = gReset->extra;

                                    if( !( pObjToIndex = get_obj_index( gReset->arg3 ) ) )
                                    {
                                       bug( "%s: %s: 'P': bad objto vnum %d.", __FUNCTION__, filename, gReset->arg3 );
                                       continue;
                                    }
                                    if( iNest >= MAX_NEST )
                                    {
                                       bug( "%s: %s: 'P': Exceeded nesting limit of %d", __FUNCTION__, filename, MAX_NEST );
                                       obj = NULL;
                                       break;
                                    }
                                    if( count_obj_list( pObjIndex, to_obj->first_content ) > 0 )
                                    {
                                       obj = NULL;
                                       break;
                                    }

                                    if( iNest < lastnest )
                                       to_obj = nestmap[iNest];
                                    else if( iNest == lastnest )
                                       to_obj = nestmap[lastnest];
                                    else
                                       to_obj = lastobj;

                                    obj = create_object( pObjIndex, number_fuzzy( UMAX( generate_itemlevel( room->area, pObjIndex ), to_obj->level ) ) );
                                    if( num > 1 )
                                       pObjIndex->count += ( num - 1 );
                                    obj->count = gReset->arg2;
                                    obj->level = UMIN( obj->level, LEVEL_AVATAR );
                                    obj->count = gReset->arg2;
                                    obj_to_obj( obj, to_obj );
                                    if( iNest > lastnest )
                                    {
                                       nestmap[iNest] = to_obj;
                                       lastnest = iNest;
                                    }
                                    lastobj = obj;
                                    // Hackish fix for nested puts
                                    if( gReset->arg3 == OBJ_VNUM_MONEY_ONE )
                                       gReset->arg3 = to_obj->pIndexData->vnum;
                                    break;
                              }
                           }
                        }
                        break;
                  }
               }
            }
            break;

         case 'O':
            if( !( pObjIndex = get_obj_index( pReset->arg1 ) ) )
            {
               bug( "%s: %s: 'O': bad obj vnum %d.", __FUNCTION__, filename, pReset->arg1 );
               continue;
            }
            if( !( pRoomIndex = get_room_index( pReset->arg3 ) ) )
            {
               bug( "%s: %s: 'O': bad room vnum %d.", __FUNCTION__, filename, pReset->arg3 );
               continue;
            }

            if( count_obj_list( pObjIndex, pRoomIndex->first_content ) < 1 )
            {
               obj = create_object( pObjIndex, number_fuzzy( generate_itemlevel( room->area, pObjIndex ) ) );
               if( num > 1 )
                  pObjIndex->count += ( num - 1 );
               obj->count = pReset->arg2;
               obj->level = UMIN( obj->level, LEVEL_AVATAR );
               obj->cost = 0;
               obj_to_room( obj, pRoomIndex );
            }
            else
            {
               int x;

               if( !( obj = get_obj_room( pObjIndex, pRoomIndex ) ) )
               {
                  obj = NULL;
                  lastobj = NULL;
                  break;
               }
               obj->extra_flags = pObjIndex->extra_flags;
               for( x = 0; x < 6; ++x )
                  obj->value[x] = pObjIndex->value[x];
            }
            for( n = 0; n < MAX_NEST; n++ )
               nestmap[n] = NULL;
            nestmap[0] = obj;
            lastobj = nestmap[0];
            lastnest = 0;
            if( pReset->first_reset )
            {
               for( tReset = pReset->first_reset; tReset; tReset = tReset->next_reset )
               {
                  int iNest;

                  to_obj = lastobj;
                  ++onreset;

                  switch( tReset->command )
                  {
                     case 'H':
                        if( !lastobj )
                           break;
                        SET_BIT( lastobj->extra_flags, ITEM_HIDDEN );
                        break;

                     case 'T':
                        if( !IS_SET( tReset->extra, TRAP_OBJ ) )
                        {
                           bug( "%s: Room reset found on object reset list", __FUNCTION__ );
                           break;
                        }
                        else
                        {
                           /*
                            * We need to preserve obj for future 'T' checks 
                            */
                           OBJ_DATA *pobj;

                           if( tReset->arg3 > 0 )
                           {
                              if( !( pObjToIndex = get_obj_index( tReset->arg3 ) ) )
                              {
                                 bug( "%s: %s: 'T': bad objto vnum %d.", __FUNCTION__, filename, tReset->arg3 );
                                 continue;
                              }
                              if( room->area->nplayer > 0 || !( to_obj = get_obj_type( pObjToIndex ) ) ||
                                ( to_obj->carried_by && !IS_NPC( to_obj->carried_by ) ) || is_trapped( to_obj ) )
                                 break;
                           }
                           else
                           {
                              if( !lastobj || !obj )
                                 break;
                              to_obj = obj;
                           }
                           pobj = make_trap( tReset->arg2, tReset->arg1, number_fuzzy( to_obj->level ), tReset->extra );
                           obj_to_obj( pobj, to_obj );
                        }
                        break;

                     case 'P':
                        if( !( pObjIndex = get_obj_index( tReset->arg1 ) ) )
                        {
                           bug( "%s: %s: 'P': bad obj vnum %d.", __FUNCTION__, filename, tReset->arg1 );
                           continue;
                        }
                        iNest = tReset->extra;

                        if( !( pObjToIndex = get_obj_index( tReset->arg3 ) ) )
                        {
                           bug( "%s: %s: 'P': bad objto vnum %d.", __FUNCTION__, filename, tReset->arg3 );
                           continue;
                        }

                        if( iNest >= MAX_NEST )
                        {
                           bug( "%s: %s: 'P': Exceeded nesting limit of %d. Room %d.", __FUNCTION__, filename, MAX_NEST, room->vnum );
                           obj = NULL;
                           break;
                        }

                        if( count_obj_list( pObjIndex, to_obj->first_content ) > 0 )
                        {
                           obj = NULL;
                           break;
                        }
                        if( iNest < lastnest )
                           to_obj = nestmap[iNest];
                        else if( iNest == lastnest )
                           to_obj = nestmap[lastnest];
                        else
                           to_obj = lastobj;

                        obj = create_object( pObjIndex, number_fuzzy( UMAX( generate_itemlevel( room->area, pObjIndex ), to_obj->level ) ) );
                        if( num > 1 )
                           pObjIndex->count += ( num - 1 );
                        obj->count = tReset->arg2;
                        obj->level = UMIN( obj->level, LEVEL_AVATAR );
                        obj->count = tReset->arg2;
                        obj_to_obj( obj, to_obj );
                        if( iNest > lastnest )
                        {
                           nestmap[iNest] = to_obj;
                           lastnest = iNest;
                        }
                        lastobj = obj;
                        // Hackish fix for nested puts
                        if( tReset->arg3 == OBJ_VNUM_MONEY_ONE )
                           tReset->arg3 = to_obj->pIndexData->vnum;
                        break;
                  }
               }
            }
            break;

         case 'T':
            if( IS_SET( pReset->extra, TRAP_OBJ ) )
            {
               bug( "%s: Object trap found in room %d reset list", __FUNCTION__, room->vnum );
               break;
            }
            else
            {
               if( !( pRoomIndex = get_room_index( pReset->arg3 ) ) )
               {
                  bug( "%s: %s: 'T': bad room %d.", __FUNCTION__, filename, pReset->arg3 );
                  continue;
               }
               if( room->area->nplayer > 0 || count_obj_list( get_obj_index( OBJ_VNUM_TRAP ), pRoomIndex->first_content ) > 0 )
                  break;
               to_obj = make_trap( pReset->arg1, pReset->arg1, 10, pReset->extra );
               obj_to_room( to_obj, pRoomIndex );
            }
            break;

         case 'D':
            if( !( pRoomIndex = get_room_index( pReset->arg1 ) ) )
            {
               bug( "%s: %s: 'D': bad room vnum %d.", __FUNCTION__, filename, pReset->arg1 );
               continue;
            }
            if( !( pexit = get_exit( pRoomIndex, pReset->arg2 ) ) )
               break;
            switch ( pReset->arg3 )
            {
               case 0:
                  REMOVE_BIT( pexit->exit_info, EX_CLOSED );
                  REMOVE_BIT( pexit->exit_info, EX_LOCKED );
                  break;
               case 1:
                  SET_BIT( pexit->exit_info, EX_CLOSED );
                  REMOVE_BIT( pexit->exit_info, EX_LOCKED );
                  if( IS_SET( pexit->exit_info, EX_xSEARCHABLE ) )
                     SET_BIT( pexit->exit_info, EX_SECRET );
                  break;
               case 2:
                  SET_BIT( pexit->exit_info, EX_CLOSED );
                  SET_BIT( pexit->exit_info, EX_LOCKED );
                  if( IS_SET( pexit->exit_info, EX_xSEARCHABLE ) )
                     SET_BIT( pexit->exit_info, EX_SECRET );
                  break;
            }
            break;

         case 'R':
            if( !( pRoomIndex = get_room_index( pReset->arg1 ) ) )
            {
               bug( "%s: %s: 'R': bad room vnum %d.", __FUNCTION__, filename, pReset->arg1 );
               continue;
            }
            randomize_exits( pRoomIndex, pReset->arg2 - 1 );
            break;
      }
   }
   return;
}
Example #23
0
    BUGS

    SEE ALSO

    INTERNALS

******************************************************************************/

{
    AROS_LIBFUNC_INIT
    
    struct TextAttr *font = NULL;
    struct Hook *backfillHook = NULL;
    char *ret = NULL;

    D(bug("MUIS_OpenPubScreen(%p)\n", desc));

    // TODO desc->SysDefault
    // TODO desc->AutoClose
    // TODO desc->CloseGadget
    // TODO desc->SystemPens
    // TODO desc->Palette
    
    struct Screen *screen = OpenScreenTags(NULL,
	    SA_Type, (IPTR) PUBLICSCREEN,
	    SA_PubName, desc->Name,
	    SA_Title, desc->Title,
	    SA_Font, font,
	    (backfillHook ? SA_BackFill : TAG_IGNORE), backfillHook,
	    SA_DisplayID, (IPTR) desc->DisplayID,
	    SA_Width, (IPTR) desc->DisplayWidth,
Example #24
0
/*
 * Add a reset to an area -Thoric
 */
RESET_DATA *add_reset( ROOM_INDEX_DATA *room, char letter, int extra, int arg1, int arg2, int arg3 )
{
   RESET_DATA *pReset;

   if( !room )
   {
      bug( "%s: NULL room!", __FUNCTION__ );
      return NULL;
   }

   letter = UPPER( letter );
   pReset = make_reset( letter, extra, arg1, arg2, arg3 );
   pReset->sreset = TRUE;
   switch ( letter )
   {
      case 'M':
         room->last_mob_reset = pReset;
         break;

      case 'E':
      case 'G':
         if( !room->last_mob_reset )
         {
            bug( "%s: Can't add '%c' reset to room: last_mob_reset is NULL.", __FUNCTION__, letter );
            return NULL;
         }
         room->last_obj_reset = pReset;
         LINK( pReset, room->last_mob_reset->first_reset, room->last_mob_reset->last_reset, next_reset, prev_reset );
         return pReset;

      case 'P':
         if( !room->last_obj_reset )
         {
            bug( "%s: Can't add '%c' reset to room: last_obj_reset is NULL.", __FUNCTION__, letter );
            return NULL;
         }
         LINK( pReset, room->last_obj_reset->first_reset, room->last_obj_reset->last_reset, next_reset, prev_reset );
         return pReset;

      case 'O':
         room->last_obj_reset = pReset;
         break;

      case 'T':
         if( IS_SET( extra, TRAP_OBJ ) )
         {
            pReset->prev_reset = NULL;
            pReset->next_reset = room->last_obj_reset->first_reset;
            if( room->last_obj_reset->first_reset )
               room->last_obj_reset->first_reset->prev_reset = pReset;
            room->last_obj_reset->first_reset = pReset;
            if( !room->last_obj_reset->last_reset )
               room->last_obj_reset->last_reset = pReset;
            return pReset;
         }
         break;

      case 'H':
         pReset->prev_reset = NULL;
         pReset->next_reset = room->last_obj_reset->first_reset;
         if( room->last_obj_reset->first_reset )
            room->last_obj_reset->first_reset->prev_reset = pReset;
         room->last_obj_reset->first_reset = pReset;
         if( !room->last_obj_reset->last_reset )
            room->last_obj_reset->last_reset = pReset;
         return pReset;
   }
   LINK( pReset, room->first_reset, room->last_reset, next, prev );
   return pReset;
}
Example #25
0
VOID x11clipboard_handle_event(struct x11_staticdata *xsd, XEvent *event)
{
    switch(event->type)
    {
	case SelectionNotify:
	    D(bug("X11CLIPBOARD: SelectionNotify Event\n"));

	    if (xsd->hostclipboardmsg && (xsd->hostclipboard_readstate == HOSTCLIPBOARDSTATE_READ))
	    {
		Atom    	    actual_type;
		int     	    actual_format;
		unsigned long   nitems;
		unsigned long   bytes_after;
		unsigned char  *buffer, *arosbuffer;

		LOCK_X11
		XCALL(XGetWindowProperty, xsd->display,
				   xsd->dummy_window_for_creating_pixmaps,
				   xsd->clipboard_property_atom,
				   0,
				   0,
				   False,
				   AnyPropertyType,
				   &actual_type,
				   &actual_format,
				   &nitems,
				   &bytes_after,
				   &buffer);
		XCALL(XFree, buffer);
		UNLOCK_X11

		if (actual_type == xsd->clipboard_incr_atom)
		{
		    LOCK_X11
		    listen_for_xevent(xsd, PropertyChangeMask, TRUE);
		    XCALL(XDeleteProperty, xsd->display,
				    xsd->dummy_window_for_creating_pixmaps,
				    xsd->clipboard_property_atom);
    	    	    XCALL(XFlush, xsd->display);
		    UNLOCK_X11;

		    xsd->hostclipboard_readstate = HOSTCLIPBOARDSTATE_READ_INCR;

    	    	    D(bug("X11CLIPBOARD: SelectionNotify - INCR protocol\n"));
		    break;
		}       

		if (actual_format != 8)
		{
    	    	    D(bug("X11CLIPBOARD: SelectionNotify - format is <> 8, so terminating READ request with error.\n"));

    	    	    reply_async_request(xsd, NULL, FALSE);
		    break;				
		}

		LOCK_X11
		XCALL(XGetWindowProperty, xsd->display,
				   xsd->dummy_window_for_creating_pixmaps,
				   xsd->clipboard_property_atom,
				   0,
				   bytes_after,
				   False,
				   AnyPropertyType,
				   &actual_type,
				   &actual_format,
				   &nitems,
				   &bytes_after,
				   &buffer);

		XCALL(XDeleteProperty, xsd->display,
				xsd->dummy_window_for_creating_pixmaps,
				xsd->clipboard_property_atom);

		arosbuffer = AllocVec(nitems + 1, MEMF_ANY);
		if (arosbuffer)
		{
		    memcpy(arosbuffer, buffer, nitems);
		    arosbuffer[nitems] = '\0';
		}
    		XCALL(XFree, buffer);
		UNLOCK_X11;

    	    	D(bug("X11CLIPBOARD: SelectionNotify - terminating READ request with %s\n", arosbuffer ? "success" : "failure"));

    	    	reply_async_request(xsd, arosbuffer, arosbuffer ? TRUE : FALSE);
		
	    } /* if (xsd->hostclipboardmsg && (xsd->hostclipboard_readstate == HOSTCLIPBOARDSTATE_READ))*/
	    break;

	case PropertyNotify:
	    D(bug("X11CLIPBOARD: PropertyNotify Event\n"));

	    if (xsd->hostclipboardmsg && (xsd->hostclipboard_readstate == HOSTCLIPBOARDSTATE_READ_INCR))
	    {
		if ((event->xproperty.atom == xsd->clipboard_property_atom) &&
		    (event->xproperty.state == PropertyNewValue))
		{
		    Atom    	    actual_type;
		    int     	    actual_format;
		    unsigned long   nitems;
		    unsigned long   bytes_after;
		    unsigned char  *buffer, *arosbuffer;

    	    	    D(bug("X11CLIPBOARD: PropertyNotify - property event okay\n"));

		    LOCK_X11
		    XCALL(XGetWindowProperty, xsd->display,
			    	       xsd->dummy_window_for_creating_pixmaps,
				       xsd->clipboard_property_atom,
				       0,
				       0,
				       False,
				       AnyPropertyType,
				       &actual_type,
				       &actual_format,
				       &nitems,
				       &bytes_after,
				       &buffer);
		    XCALL(XFree, buffer);
		    UNLOCK_X11

		    if (actual_format == 8)
		    {
    	    	    	D(bug("X11CLIPBOARD: PropertyNotify - format(8) okay\n"));
 			if (bytes_after == 0)
			{
			    D(bug("X11CLIPBOARD: PropertyNotify - last one detected. Terminating READ request with %s\n",
			    	  xsd->hostclipboard_incrbuffer ? "success" : "failure"));

			    reply_async_request(xsd, xsd->hostclipboard_incrbuffer,
			    	    	    	xsd->hostclipboard_incrbuffer ? TRUE : FALSE);

			    xsd->hostclipboard_incrbuffer = NULL;
			    xsd->hostclipboard_incrbuffer_size = 0;
			    
			    listen_for_xevent(xsd, PropertyChangeMask, FALSE);			    
			}
			else
			{
			    LOCK_X11
			    XCALL(XGetWindowProperty, xsd->display,
			    	    	       xsd->dummy_window_for_creating_pixmaps,
					       xsd->clipboard_property_atom,
					       0,
					       bytes_after,
					       False,
					       AnyPropertyType,
					       &actual_type,
					       &actual_format,
					       &nitems,
					       &bytes_after,
					       &buffer);

			    if (!xsd->hostclipboard_incrbuffer)
			    {
				/* No buffer allocated yet. */

			    	D(bug("X11CLIPBOARD: PropertyNotify - First INCR packet of size %d\n", nitems));
				xsd->hostclipboard_incrbuffer = AllocVec(nitems + 1, MEMF_ANY);
				if (xsd->hostclipboard_incrbuffer)
				{
			    	    memcpy(xsd->hostclipboard_incrbuffer, buffer, nitems);
				    xsd->hostclipboard_incrbuffer[nitems] = '\0';
				    xsd->hostclipboard_incrbuffer_size = nitems;						
				}
				else
				{
    	    	    	    	    D(bug("X11CLIPBOARD: PropertyNotify - Allocation of incrbuffer failed! Terminating READ request with failure\n"));
				    
				    reply_async_request(xsd, NULL, FALSE);
				    
				    listen_for_xevent(xsd, PropertyChangeMask, FALSE);				    	
				}
			    }
			    else
			    {
				/* Buffer already allocated. Do a re-allocation! */

    	    	    	    	D(bug("X11CLIPBOARD: PropertyNotify - One more INCR packet of size %d. Total size now %d\n",
				      nitems, xsd->hostclipboard_incrbuffer_size + nitems));
				
				arosbuffer = AllocVec(xsd->hostclipboard_incrbuffer_size + nitems + 1, MEMF_ANY);
				if (arosbuffer)
				{
				    memcpy(arosbuffer, xsd->hostclipboard_incrbuffer, xsd->hostclipboard_incrbuffer_size);
				    FreeVec(xsd->hostclipboard_incrbuffer);
				    xsd->hostclipboard_incrbuffer = arosbuffer;

				    memcpy(xsd->hostclipboard_incrbuffer + xsd->hostclipboard_incrbuffer_size,
					   buffer,
					   nitems);

				    xsd->hostclipboard_incrbuffer_size += nitems;
				    xsd->hostclipboard_incrbuffer[xsd->hostclipboard_incrbuffer_size] = '\0';
				}
				else
				{
    	    	    	    	    D(bug("X11CLIPBOARD: PropertyNotify - Reallocation of incrbuffer failed! Terminating READ request with failure\n"));

				    FreeVec(xsd->hostclipboard_incrbuffer);
				    
				    reply_async_request(xsd, NULL, FALSE);

				    xsd->hostclipboard_incrbuffer = NULL;
				    xsd->hostclipboard_incrbuffer_size = 0;
				    
				    listen_for_xevent(xsd, PropertyChangeMask, FALSE);
				}
				
			    } /* if (!xsd->hostclipboard_incrbuffer) else ... */

			    XCALL(XFree, buffer);
			    UNLOCK_X11

			} /* if (bytes_after == 0) else ... */
			
		    } /* if (actual_format == 8) */

		    LOCK_X11
		    XCALL(XDeleteProperty, xsd->display,
				    xsd->dummy_window_for_creating_pixmaps,
				    xsd->clipboard_property_atom);
		    XCALL(XFlush, xsd->display);
		    UNLOCK_X11
		    
		} /* if it's right property and the property has new value */
Example #26
0
void note_remove( CHAR_DATA *ch, NOTE_DATA *pnote )
{
    FILE *fp;
    NOTE_DATA *prev;

    /*
     * Remove note from linked list.
     */
    if ( pnote == note_list )
    {
	note_list = pnote->next;
    }
    else
    {
	for ( prev = note_list; prev != NULL; prev = prev->next )
	{
	    if ( prev->next == pnote )
		break;
	}

	if ( prev == NULL )
	{
	    bug( "Note_remove: pnote not found.", 0 );
	    return;
	}

	prev->next = pnote->next;
    }

    free_string( pnote->text    );
    free_string( pnote->subject );
    free_string( pnote->to_list );
    free_string( pnote->date    );
    free_string( pnote->sender  );
    pnote->next	= note_free;
    note_free	= pnote;

    /*
     * Rewrite entire list.
     */
    fclose( fpReserve );
    if ( ( fp = fopen( NOTE_FILE, "w" ) ) == NULL )
    {
	perror( NOTE_FILE );
    }
    else
    {
	for ( pnote = note_list; pnote != NULL; pnote = pnote->next )
	{
	    fprintf( fp, "Sender  %s~\nDate    %s~\nTo      %s~\nSubject %s~\nText\n%s~\n\n",
		pnote->sender,
		pnote->date,
		pnote->to_list,
		pnote->subject,
		pnote->text
		);
	}
	fclose( fp );
    }
    fpReserve = fopen( NULL_FILE, "r" );
    return;
}
Example #27
0
bool InitAll(const char *vmdir)
{
	// Check ROM version
	if (!CheckROM()) {
		ErrorAlert(STR_UNSUPPORTED_ROM_TYPE_ERR);
		return false;
	}

#if EMULATED_68K
	// Set CPU and FPU type (UAE emulation)
	switch (ROMVersion) {
		case ROM_VERSION_64K:
		case ROM_VERSION_PLUS:
		case ROM_VERSION_CLASSIC:
			CPUType = 0;
			FPUType = 0;
			TwentyFourBitAddressing = true;
			break;
		case ROM_VERSION_II:
			CPUType = PrefsFindInt32("cpu");
			if (CPUType < 2) CPUType = 2;
			if (CPUType > 4) CPUType = 4;
			FPUType = PrefsFindBool("fpu") ? 1 : 0;
			if (CPUType == 4) FPUType = 1;	// 68040 always with FPU
			TwentyFourBitAddressing = true;
			break;
		case ROM_VERSION_32:
			CPUType = PrefsFindInt32("cpu");
			if (CPUType < 2) CPUType = 2;
			if (CPUType > 4) CPUType = 4;
			FPUType = PrefsFindBool("fpu") ? 1 : 0;
			if (CPUType == 4) FPUType = 1;	// 68040 always with FPU
			TwentyFourBitAddressing = false;
			break;
	}
	CPUIs68060 = false;
#endif

	// Load XPRAM
	XPRAMInit(vmdir);

	// Load XPRAM default values if signature not found
	if (XPRAM[0x0c] != 0x4e || XPRAM[0x0d] != 0x75
	 || XPRAM[0x0e] != 0x4d || XPRAM[0x0f] != 0x63) {
		D(bug("Loading XPRAM default values\n"));
		memset(XPRAM, 0, 0x100);
		XPRAM[0x0c] = 0x4e;	// "NuMc" signature
		XPRAM[0x0d] = 0x75;
		XPRAM[0x0e] = 0x4d;
		XPRAM[0x0f] = 0x63;
		XPRAM[0x01] = 0x80;	// InternalWaitFlags = DynWait (don't wait for SCSI devices upon bootup)
		XPRAM[0x10] = 0xa8;	// Standard PRAM values
		XPRAM[0x11] = 0x00;
		XPRAM[0x12] = 0x00;
		XPRAM[0x13] = 0x22;
		XPRAM[0x14] = 0xcc;
		XPRAM[0x15] = 0x0a;
		XPRAM[0x16] = 0xcc;
		XPRAM[0x17] = 0x0a;
		XPRAM[0x1c] = 0x00;
		XPRAM[0x1d] = 0x02;
		XPRAM[0x1e] = 0x63;
		XPRAM[0x1f] = 0x00;
		XPRAM[0x08] = 0x13;
		XPRAM[0x09] = 0x88;
		XPRAM[0x0a] = 0x00;
		XPRAM[0x0b] = 0xcc;
		XPRAM[0x76] = 0x00;	// OSDefault = MacOS
		XPRAM[0x77] = 0x01;
	}

	// Set boot volume
	int16 i16 = PrefsFindInt32("bootdrive");
	XPRAM[0x78] = i16 >> 8;
	XPRAM[0x79] = i16 & 0xff;
	i16 = PrefsFindInt32("bootdriver");
	XPRAM[0x7a] = i16 >> 8;
	XPRAM[0x7b] = i16 & 0xff;

	// Init drivers
	SonyInit();
	DiskInit();
	CDROMInit();
	SCSIInit();

#if SUPPORTS_EXTFS
	// Init external file system
	ExtFSInit();
#endif

	// Init serial ports
	SerialInit();

	// Init network
	EtherInit();

	// Init Time Manager
	TimerInit();

	// Init clipboard
	ClipInit();

	// Init ADB
	ADBInit();

	// Init audio
	AudioInit();

	// Init video
	if (!VideoInit(ROMVersion == ROM_VERSION_64K || ROMVersion == ROM_VERSION_PLUS || ROMVersion == ROM_VERSION_CLASSIC))
		return false;

	// Set default video mode in XPRAM
	XPRAM[0x56] = 0x42;	// 'B'
	XPRAM[0x57] = 0x32;	// '2'
	const monitor_desc &main_monitor = *VideoMonitors[0];
	XPRAM[0x58] = main_monitor.depth_to_apple_mode(main_monitor.get_current_mode().depth);
	XPRAM[0x59] = 0;

#if EMULATED_68K
	// Init 680x0 emulation (this also activates the memory system which is needed for PatchROM())
	if (!Init680x0())
		return false;
#endif

	// Install ROM patches
	if (!PatchROM()) {
		ErrorAlert(STR_UNSUPPORTED_ROM_TYPE_ERR);
		return false;
	}

#if ENABLE_MON
	// Initialize mon
	mon_init();
	mon_read_byte = mon_read_byte_b2;
	mon_write_byte = mon_write_byte_b2;
#endif

	return true;
}
Example #28
0
void do_mpoload( CHAR_DATA *ch, char *argument )
{
    char arg1[ MAX_INPUT_LENGTH ];
    char arg2[ MAX_INPUT_LENGTH ];
    OBJ_INDEX_DATA *pObjIndex;
    OBJ_DATA       *obj;
    int             level;

    if ( !IS_NPC( ch ) )
    {
        send_to_char( C_DEFAULT, "Huh?\n\r", ch );
	return;
    }

    if ( IS_AFFECTED( ch, AFF_CHARM ) )
    {
        return;
    }

    if ( IS_AFFECTED( ch, AFF_CHARM ) )
    {
	return;
    }

    argument = one_argument( argument, arg1 );
    argument = one_argument( argument, arg2 );
 
    if ( arg1[0] == '\0' || !is_number( arg1 ) )
    {
        bug( "Mpoload - Bad syntax: vnum %d.",
	    ch->pIndexData->vnum );
        return;
    }
 
    if ( arg2[0] == '\0' )
    {
	level = get_trust( ch );
    }
    else
    {
	/*
	 * New feature from Alander.
	 */
        if ( !is_number( arg2 ) )
        {
	    bug( "Mpoload - Bad syntax: vnum %d.", ch->pIndexData->vnum );
	    return;
        }
	level = atoi( arg2 );
	if ( level < 0 || level > get_trust( ch ) )
	{
	    bug( "Mpoload - Bad level: vnum %d.", ch->pIndexData->vnum );
	    return;
	}
    }

    if ( ( pObjIndex = get_obj_index( atoi( arg1 ) ) ) == NULL )
    {
	bug( "Mpoload - Bad vnum arg: vnum %d.", ch->pIndexData->vnum );
	return;
    }

    obj = create_object( pObjIndex, level );
    if ( CAN_WEAR(obj, ITEM_TAKE) )
    {
	obj_to_char( obj, ch );
    }
    else
    {
	obj_to_room( obj, ch->in_room );
    }

    return;
}
void
vsf_secutil_change_credentials(const struct mystr* p_user_str,
                               const struct mystr* p_dir_str,
                               const struct mystr* p_ext_dir_str,
                               unsigned int caps, unsigned int options)
{
  struct vsf_sysutil_user* p_user;
  if (!vsf_sysutil_running_as_root())
  {
    bug("vsf_secutil_change_credentials: not running as root");
  }
  p_user = str_getpwnam(p_user_str);
  if (p_user == 0)
  {
    die2("cannot locate user entry:", str_getbuf(p_user_str));
  }
  {
    struct mystr dir_str = INIT_MYSTR;
    /* Work out where the chroot() jail is */
    if (p_dir_str == 0 || str_isempty(p_dir_str))
    {
      str_alloc_text(&dir_str, vsf_sysutil_user_get_homedir(p_user));
    }
    else
    {
      str_copy(&dir_str, p_dir_str);
    }
    /* Sort out supplementary groups before the chroot(). We need to access
     * /etc/groups
     */
    if (options & VSF_SECUTIL_OPTION_USE_GROUPS)
    {
      vsf_sysutil_initgroups(p_user);
    }
    else
    {
      vsf_sysutil_clear_supp_groups();
    }
    /* Always do the chdir() regardless of whether we are chroot()'ing */
    {
      /* Do chdir() with the target effective IDs to cater for NFS mounted
       * home directories.
       */
      int saved_euid = 0;
      int saved_egid = 0;
      int retval;
      if (options & VSF_SECUTIL_OPTION_CHANGE_EUID)
      {
        saved_euid = vsf_sysutil_geteuid();
        saved_egid = vsf_sysutil_getegid();
        vsf_sysutil_setegid(p_user);
        vsf_sysutil_seteuid(p_user);
      }
      retval = str_chdir(&dir_str);
      if (retval != 0)
      {
        die2("cannot change directory:", str_getbuf(&dir_str));
      }
      if (p_ext_dir_str && !str_isempty(p_ext_dir_str))
      {
        retval = str_chdir(p_ext_dir_str);
        /* Failure on the extra directory is OK as long as we're not in
         * chroot() mode
         */
        if (retval != 0 && !(options & VSF_SECUTIL_OPTION_CHROOT))
        {
          retval = 0;
        }
      }
      if (retval != 0)
      {
        die2("cannot change directory:", str_getbuf(p_ext_dir_str));
      }
      if (options & VSF_SECUTIL_OPTION_CHANGE_EUID)
      {
        vsf_sysutil_seteuid_numeric(saved_euid);
        vsf_sysutil_setegid_numeric(saved_egid);
      }
      /* Do the chroot() if required */
      if (options & VSF_SECUTIL_OPTION_CHROOT)
      {
        vsf_sysutil_chroot(".");
      }
    }
    str_free(&dir_str);
  }
  if (options & VSF_SECUTIL_OPTION_NO_FDS)
  {
    vsf_sysutil_set_no_fds();
  }
  /* Handle capabilities */
  if (caps)
  {
    if (!vsf_sysdep_has_capabilities())
    {
      /* Need privilege but OS has no capabilities - have to keep root */
      return;
    }
    if (!vsf_sysdep_has_capabilities_as_non_root())
    {
      vsf_sysdep_adopt_capabilities(caps);
      return;
    }
    vsf_sysdep_keep_capabilities();
  }
  /* Set group id */
  vsf_sysutil_setgid(p_user);
  /* Finally set user id */
  vsf_sysutil_setuid(p_user);
  if (caps)
  {
    vsf_sysdep_adopt_capabilities(caps);
  }
  if (options & VSF_SECUTIL_OPTION_NO_PROCS)
  {
    vsf_sysutil_set_no_procs();
  }
  /* Misconfiguration check: don't ever chroot() to a directory writable by
   * the current user.
   */
  if (options & VSF_SECUTIL_OPTION_CHROOT)
  {
    if (vsf_sysutil_write_access("/"))
    {
      die("vsftpd: refusing to run with writable root inside chroot()");
    }
  }
}
Example #30
0
int add_new_room_to_map( CHAR_DATA * ch, char code )
{
   int i;
   ROOM_INDEX_DATA *location;

   /*
    * Get an unused room to copy to 
    */
   for( i = ch->pcdata->area->low_r_vnum; i <= ch->pcdata->area->hi_r_vnum; i++ )
   {
      if( get_room_index( i ) == NULL )
      {
         if( !( location = make_room( i, ch->pcdata->area ) ) )
         {
            bug( "%s: make_room failed", __FUNCTION__ );
            return -1;
         }
         /*
          * Clones current room  (quietly) 
          */
         location->area = ch->pcdata->area;
         location->name = STRALLOC( "Newly Created Room" );
         location->description = STRALLOC( "Newly Created Room\r\n" );
         xSET_BIT( location->room_flags, ROOM_PROTOTYPE );
         location->light = 0;
         if( code == 'I' )
            location->sector_type = SECT_INSIDE;
         else if( code == 'C' )
            location->sector_type = SECT_CITY;
         else if( code == 'f' )
            location->sector_type = SECT_FIELD;
         else if( code == 'F' )
            location->sector_type = SECT_FOREST;
         else if( code == 'H' )
            location->sector_type = SECT_HILLS;
         else if( code == 'M' )
            location->sector_type = SECT_MOUNTAIN;
         else if( code == 's' )
            location->sector_type = SECT_WATER_SWIM;
         else if( code == 'S' )
            location->sector_type = SECT_WATER_NOSWIM;
         else if( code == 'A' )
            location->sector_type = SECT_AIR;
         else if( code == 'D' )
            location->sector_type = SECT_DESERT;
         else if( code == 'U' )
            location->sector_type = SECT_DUNNO;
         else if( code == 'O' )
            location->sector_type = SECT_OCEANFLOOR;
         else if( code == 'u' )
            location->sector_type = SECT_UNDERGROUND;
         else if( code == 'U' )
            location->sector_type = SECT_UNDERWATER;
         else if( code == 'L' )
            location->sector_type = SECT_LAVA;
         else if( code == 'W' )
            location->sector_type = SECT_SWAMP;
         else
            location->sector_type = SECT_DUNNO;
         return i;
      }
   }
   send_to_char( "No available room in your vnums!", ch );
   return -1;
}