예제 #1
0
void ConsoleUI::add_computer()
{
    Computer c = Computer();
    string name_, type_, yearBuilt_, wasBuilt_;
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Name of Computer:" << endl;
    cout << endl << " -> ";
    cin >> name_;
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Type of Computer:" << endl;
    cout << endl << " -> ";
    cin >> type_;
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "When was the computer built? [YYYY]" << endl;
    cout << endl << " -> ";
    cin >> yearBuilt_;
    while (!is_digits(yearBuilt_))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;

        cout << "Invalid input! Please try again:" << endl;
        cout << "When was the computer built? [YYYY]" << endl;
        cin >> yearBuilt_;
    }
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Was the computer built? [Y/N]" << endl;
    cout << endl << " -> ";
    cin >> wasBuilt_;
    while ((wasBuilt_ != "Y") && (wasBuilt_ != "N") && (wasBuilt_ != "y") && (wasBuilt_ != "n"))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;
        cout << "Invalid input! Please try again:" << endl;
        cout << "Was the computer built? [Y/N]" << endl;
        cout << endl << " -> ";
        cin >> wasBuilt_;
    }
    if ((wasBuilt_ == "Y") || (wasBuilt_ == "y"))
    {
        c.set_wasBuilt("Yes");
    }
    else if ((wasBuilt_ == "N") || (wasBuilt_ == "n"))
    {
        c.set_wasBuilt("No");
    }
    fix_string(name_);
    fix_string(type_);
    c.set_name(name_);
    c.set_type(type_);
    c.set_yearBuilt(yearBuilt_);
    dbService.addC(c);
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "\t\t     " << "Computer has been added to the list! \n\n\n\n\n\n\n" << endl;
}
예제 #2
0
/*****************************************************************************
 Name:		save_rooms
 Purpose:	Save #ROOMDATA section of an area file.
 Called by:	save_area(olc_save.c).
 ****************************************************************************/
void save_rooms( FILE *fp, AREA_DATA *pArea )
{
    ROOM_INDEX_DATA *pRoomIndex;
    EXTRA_DESCR_DATA *pEd;
    ROOMTEXT_DATA *prt;
    EXIT_DATA *pExit;
    int vnum;
    int door;

    fprintf( fp, "#ROOMDATA\n" );
    for( vnum = pArea->lvnum; vnum <= pArea->uvnum; vnum++ )
    {
        if( ( pRoomIndex = get_room_index(vnum) ) )
        {
            if ( pRoomIndex->area == pArea )
            {
                fprintf( fp, "#%d\n", pRoomIndex->vnum );
                fprintf( fp, "%s~\n", pRoomIndex->name );
                fprintf( fp, "%s~\n", fix_string( pRoomIndex->description ) );
                fprintf( fp, "0 " );
                fprintf( fp, "%d ", pRoomIndex->room_flags );
                fprintf( fp, "%d\n", pRoomIndex->sector_type );

                for ( pEd = pRoomIndex->extra_descr; pEd; pEd = pEd->next )
                {
                    fprintf( fp, "E\n%s~\n%s~\n", pEd->keyword,
                        fix_string( pEd->description ) );
                }
                for (prt = pRoomIndex->roomtext; prt; prt = prt->next )
                {
                    fprintf(fp, "T\n%s~\n%s~\n%s~\n%s~\n%d %d %d\n",
                        prt->input, prt->output, prt->choutput,
                        prt->name, prt->type, prt->power, prt->mob);

                }
                for( door = 0; door < MAX_DIR; door++ )
                {
                    if ( ( pExit = pRoomIndex->exit[door] ) )
                    {
                        fprintf( fp, "D%d\n", door );
                        fprintf( fp, "%s~\n",
                            fix_string( pExit->description ) );
                        fprintf( fp, "%s~\n", pExit->keyword );
                        fprintf( fp, "%d %d %d\n", pExit->rs_flags,
                            pExit->key,
                            pExit->to_room ? pExit->to_room->vnum : 0 );
                    }
                }
                fprintf( fp, "S\n" );
            }
        }
    }
    fprintf( fp, "#0\n\n\n\n" );
    return;
}
예제 #3
0
파일: pgr.c 프로젝트: jbmulligan/quip
static PGR_Cam *unique_camera_instance( QSP_ARG_DECL  dc1394camera_t *cam_p )
{
	int i;
	char cname[80];	// How many chars is enough?
	PGR_Cam *pgcp;

	i=1;
	pgcp=NULL;
	while(pgcp==NULL){
		sprintf(cname,"%s_%d",cam_p->model,i);
		fix_string(cname);	// change spaces to underscores
		pgcp = pgc_of( cname );
		if( pgcp == NULL ){	// This index is free
			pgcp = new_pgc( cname );
			if( pgcp == NULL ){
				sprintf(ERROR_STRING,
			"Failed to create camera %s!?",cname);
				error1(ERROR_STRING);
			}
		} else {
			pgcp = NULL;
		}
		i++;
		if( i>=5 ){
			error1("Too many cameras!?"); 
		}
	}
	return pgcp;
}
예제 #4
0
//////////////////////////////////////////
// return value: 0, execute new statement.
//               -20, abort it.
//		other error codes from readStmt()
//////////////////////////////////////////
Int32 InputStmt::fix(Int32 append_only)
{
  Int32 retval = 0;

  if (!append_only)
    {
      Option option;

      StringFragment * fragment = first_fragment;

      while (fragment)
	{
	  char * new_fragment = new char[MAX_FRAGMENT_LEN + 1];
	  option = fix_string(fragment->fragment,new_fragment,MAX_FRAGMENT_LEN);
	  if (option == ABORT_O)
	    return -20;	  // caller is responsible for deleting this InputStmt

	  delete [] fragment->fragment;
	  fragment->fragment = new_fragment;
	  fragment = fragment->next;
	}
    }
  else
    {
      retval = readStmt(NULL/*interactive only, so input is stdin*/);
    }

  // Pack (or repack) the new stmt.
  pack();

  return retval;
}	// fix()
예제 #5
0
파일: video.c 프로젝트: OS2World/LIB-libfly
void video_put_str (char *s, int n, int row, int col)
{
    if (n <= 0 || row < 0 || col < 0) return;
    if (row >= ROWS || col >= COLS) return;
    n = min1 (n, COLS-col);
    memcpy (scrn_cache_chars+row*COLS+col, s, n);
    fix_string (scrn_cache_chars+row*COLS+col, n);
}
예제 #6
0
파일: tables.c 프로젝트: vcosta/greedmud
/*
 * New code for writing a clan to a file.
 */
void save_clan( CLAN_DATA *clan )
{
    FILE                    *fp;
    char                     buf	[ MAX_STRING_LENGTH ];

    if ( !clan->filename )
	return;
    
    sprintf( buf, "%s%s", CLAN_DIR, clan->filename );

    fclose( fpReserve );

    if ( !( fp = fopen( buf, "w" ) ) )
    {
        bugf( "Cannot open: %s for writing", clan->filename );
    }
    else
    {
	fprintf( fp, "#CLAN\n"						    );
	fprintf( fp, "WhoName       %s~\n",        clan->who_name	    );
	fprintf( fp, "Name          %s~\n",        clan->name		    );
	fprintf( fp, "Motto         %s~\n",        clan->motto		    );
	fprintf( fp, "Desc          %s~\n", fix_string( clan->description ) );
	fprintf( fp, "Overlord      %s~\n",        clan->overlord	    );
	fprintf( fp, "Chieftain     %s~\n",        clan->chieftain	    );
	fprintf( fp, "PKills        %d\n",         clan->pkills		    );
	fprintf( fp, "PDeaths       %d\n",         clan->pdeaths	    );
	fprintf( fp, "MKills        %d\n",         clan->mkills		    );
	fprintf( fp, "MDeaths       %d\n",         clan->mdeaths	    );
	fprintf( fp, "IllegalPK     %d\n",         clan->illegal_pk	    );
	fprintf( fp, "Score         %d\n",         clan->score		    );
	fprintf( fp, "ClanType      %d\n",         clan->clan_type	    );
	fprintf( fp, "Clanheros     %d\n",         clan->clanheros	    );
	fprintf( fp, "Subchiefs     %d\n",         clan->subchiefs	    );
	fprintf( fp, "Members       %d\n",         clan->members	    );
	fprintf( fp, "ClanObjOne    %d\n",         clan->clanobj1	    );
	fprintf( fp, "ClanObjTwo    %d\n",         clan->clanobj2	    );
	fprintf( fp, "ClanObjThree  %d\n",         clan->clanobj3	    );
	fprintf( fp, "Recall        %d\n",         clan->recall 	    );
	fprintf( fp, "Donation      %d\n",         clan->donation	    );

	if ( clan->cclass )
	    fprintf( fp, "Class         %s~\n",    clan->cclass->name  	    );

	fprintf( fp, "End\n"						    );
	fprintf( fp, "#END\n"						    );

	fclose( fp );
    }

    fpReserve = fopen( NULL_FILE, "r" );

    return;
}
예제 #7
0
파일: gtext.c 프로젝트: idaohang/GLFGPSSim
/* ***** print string  routine for PostScript device *************** */
int cg_text(float xpos, float ypos, float dir, char *text)
{
	fprintf(cgstream,"\n%% Text line.\n");
	if (cgTEXTAX)
		fprintf(cgstream,"%g %g sm\n",xpos,ypos);
	else
		fprintf(cgstream,"%g %g mto\n",xpos*cgSCALE,ypos*cgSCALE);
	if (dir == 0)
		fprintf(cgstream,"(%s) show\n", fix_string(text,1));
	else {
	  fprintf(cgstream," cpt\t%.2f rotate\t(%s) show\n",dir,fix_string(text,1));
	  fprintf(cgstream,"0 0 mto %.2f rotate\t",-dir);
	  if (cgTEXTAX)
	      fprintf(cgstream,"%g ys -1.0 mul %g ys -1.0 mul ",xpos,ypos);
	  else
	      fprintf(cgstream,"%g %g ",-xpos*cgSCALE,-ypos*cgSCALE);
	  fprintf(cgstream," mto cpt\n");
	}
	fprintf(cgstream,"%% END Text line.\n");
	return(0);
}
예제 #8
0
/*****************************************************************************
 Name:		save_mobiles
 Purpose:	Save #MOBILES secion of an area file.
 Called by:	save_area(olc_save.c).
 ****************************************************************************/
void save_mobiles( FILE *fp, AREA_DATA *pArea )
{
    int vnum;
    MOB_INDEX_DATA *pMobIndex;

    fprintf( fp, "#MOBILES\n" );
    for( vnum = pArea->lvnum; vnum <= pArea->uvnum; vnum++ )
    {
        if( ( pMobIndex = get_mob_index(vnum) ) )
        {
            if ( pMobIndex->area == pArea )
            {
                fprintf( fp, "#%d\n",       pMobIndex->vnum );
                fprintf( fp, "%s~\n",       pMobIndex->player_name );
                fprintf( fp, "%s~\n",       pMobIndex->short_descr );
                fprintf( fp, "%s~\n",       fix_string( pMobIndex->long_descr ) );
                fprintf( fp, "%s~\n",       fix_string( pMobIndex->description ) );
                fprintf( fp, "%d ",     pMobIndex->act );
                fprintf( fp, "%d ",     pMobIndex->affected_by );
                fprintf( fp, "%d S\n",      pMobIndex->alignment );
                fprintf( fp, "%d ",     pMobIndex->level );
                fprintf( fp, "%d ",     pMobIndex->hitroll );
                fprintf( fp, "%d ",     pMobIndex->ac );
                fprintf( fp, "%dd%d+%d ",   pMobIndex->hitnodice,
                    pMobIndex->hitsizedice,
                    pMobIndex->hitplus );
                fprintf( fp, "%dd%d+%d\n",  pMobIndex->damnodice,
                    pMobIndex->damsizedice,
                    pMobIndex->damplus );
                fprintf( fp, "%d ",     pMobIndex->gold );
                fprintf( fp, "0\n0 0 " );
                fprintf( fp, "%d\n",  pMobIndex->sex );
            }
        }
    }
    fprintf( fp, "#0\n\n\n\n" );
    return;
}
예제 #9
0
nya_render::blend::mode blend_mode_from_string(const std::string &s)
{
    const std::string ss=fix_string(s);
    if(ss=="src_alpha") return nya_render::blend::src_alpha;
    if(ss=="inv_src_alpha") return nya_render::blend::inv_src_alpha;
    if(ss=="src_color") return nya_render::blend::src_color;
    if(ss=="inv_src_color") return nya_render::blend::inv_src_color;
    if(ss=="dst_color") return nya_render::blend::dst_color;
    if(ss=="inv_dst_color") return nya_render::blend::inv_dst_color;
    if(ss=="dst_alpha") return nya_render::blend::dst_alpha;
    if(ss=="inv_dst_alpha") return nya_render::blend::inv_dst_alpha;
    if(ss=="zero") return nya_render::blend::zero;
    if(ss=="one") return nya_render::blend::one;

    return nya_render::blend::one;
}
예제 #10
0
bool cull_face_from_string(const std::string &s,nya_render::cull_face::order &order_out)
{
    const std::string ss=fix_string(s);
    if(ss=="cw")
    {
        order_out=nya_render::cull_face::cw;
        return true;
    }

    if(ss=="ccw")
    {
        order_out=nya_render::cull_face::ccw;
        return true;
    }

    order_out=nya_render::cull_face::ccw;
    return false;
}
예제 #11
0
/*****************************************************************************
 Name:		save_area
 Purpose:	Save an area, note that this format is new.
 Called by:	do_asave(olc_save.c).
 ****************************************************************************/
void save_area( AREA_DATA *pArea )
{
    FILE *fp;

    fclose( fpReserve );
    if ( !( fp = fopen( pArea->filename, "w" ) ) )
    {
        bug( "Open_area: fopen", 0 );
        perror( pArea->filename );
    }

    fprintf( fp, "#AREADATA\n" );
    fprintf( fp, "Name        %s~\n",        pArea->name );
    fprintf( fp, "Builders    %s~\n",        fix_string( pArea->builders ) );
    fprintf( fp, "VNUMs       %d %d\n",      pArea->lvnum, pArea->uvnum );
    fprintf( fp, "Security    %d\n",         pArea->security );
    fprintf( fp, "Recall      %d\n",         pArea->recall );
    fprintf( fp, "Flags	      %d\n",         pArea->area_flags );
    fprintf( fp, "End\n\n\n\n" );

    save_helps( fp, pArea );                                /* OLC 1.1b */
    save_mobiles( fp, pArea );
    save_objects( fp, pArea );
    save_rooms( fp, pArea );

    if ( IS_SET(pArea->area_flags, AREA_VERBOSE) )          /* OLC 1.1b */
    {
        vsave_specials( fp, pArea );
        vsave_resets( fp, pArea );
        vsave_shops( fp, pArea );
    }
    else
    {
        save_specials( fp, pArea );
        save_resets( fp, pArea );
        save_shops( fp, pArea );
    }

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

    fclose( fp );
    fpReserve = fopen( NULL_FILE, "r" );
    return;
}
예제 #12
0
파일: olc_save.c 프로젝트: verias/SRMud
void save_mobprogs( FILE *fp, AREA_DATA *pArea )
{
	MPROG_CODE *pMprog;
        int i;

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

	for( i = pArea->min_vnum; i <= pArea->max_vnum; i++ )
        {
          if ( (pMprog = get_mprog_index(i) ) !=NULL)
		{
		          fprintf(fp, "#%d\n", i);
		          fprintf(fp, "%s~\n", fix_string(pMprog->code));
		}
        }

        fprintf(fp,"#0\n\n");
        return;
}
예제 #13
0
tree_entry * gbIso9660 :: get_file_info(const char * path)
{
	tree_entry * ret = NULL;

	if(tree)
	{
		//Make a copy of the path
		char * tmp = new char[strlen(path) + 1];
		strcpy(tmp, path);

		//Check for format errors
		fix_string(tmp);

		//Start search
		ret = get_file_info_recursive(tmp, tree);

		delete [] tmp;
	};

	return ret;
};
예제 #14
0
void save_help()
{
    FILE *fp;
    HELP_DATA *pHelp;

    rename( "help.are", "help.bak");
    if((fp=fopen( "help.are", "w")) == NULL)
    {
        bug("save_helps: fopen", 0);
        perror( "help.are" );
        return;
    }
    fprintf( fp, "#HELPS\n\n");
    for (pHelp = first_help; pHelp != NULL; pHelp = pHelp->next)
    {
        fprintf(fp, "%d ", pHelp->level);
        fprintf(fp, pHelp->keyword);
        fprintf(fp, "~\n");
        fprintf(fp, fix_string2(fix_string(pHelp->text)));
        fprintf(fp, "~\n\n");
    }
    fprintf(fp, "0 $~\n\n#$\n");
    fclose( fp );
}
예제 #15
0
void 
note_remove (CHAR_DATA * ch, NOTE_DATA * pnote)
{
  char to_new[SML_LENGTH];
  char to_one[SML_LENGTH];
  FILE *fp;
  NOTE_DATA *prev;
  char *to_list;
/*
   * Build a new to_list.
   * Strip out this recipient.
 */
  to_new[0] = '\0';
  to_list = pnote->to_list;
  while (*to_list != '\0')
    {
      to_list = one_argy (to_list, to_one);
      if (to_one[0] != '\0' && str_cmp (NAME (ch), to_one))
	{
	  strcat (to_new, " ");
	  strcat (to_new, to_one);
	}
    }
/*
   * Just a simple recipient removal?
 */
  if (LEVEL (ch) < MAX_LEVEL && !is_note_to (ch, pnote))
    {
      if (str_cmp (NAME (ch), pnote->sender) && to_new[0] != '\0')
	{
	  free_string (pnote->to_list);
	  pnote->to_list = str_dup (to_new + 1);
	  return;
	}
    }
/*
   * 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.
 */
#ifndef WINDOWS
//  fclose (fpReserve);
#endif
  if ((fp = fopen (NOTE_FILE, "w")) == NULL)
    {
      perror (NOTE_FILE);
    }
  else
    {
      for (pnote = note_list; pnote != NULL; pnote = pnote->next)
	{
	  fprintf (fp, "Sender %s~\n", fix_string (pnote->sender));
	  fprintf (fp, "TBoard %d\n", pnote->board_num);
	  fprintf (fp, "Date %s~\n", pnote->date);
	  fprintf (fp, "Stamp %ld\n", pnote->date_stamp);
	  fprintf (fp, "To %s~\n", fix_string (pnote->to_list));
	  fprintf (fp, "Subject %s~\n", fix_string (pnote->subject));
	  fprintf (fp, "Text\n%s~\n", fix_string (pnote->text));
	  fprintf (fp, "End\n");
	}
      fclose (fp);
    }
#ifndef WINDOWS
//  fpReserve = fopen (NULL_FILE, "r");
#endif
  return;
}
예제 #16
0
void 
do_note (CHAR_DATA * ch, char *argy)
{
  char buf[STD_LENGTH * 17];
  char buf1[STD_LENGTH * 17];
  char arg[SML_LENGTH];
  NOTE_DATA *pnote;
  int vnum;
  int board_here;		/*Boards and board nums by Owen Emlen */
  SINGLE_OBJECT *obj;
  int anum;
  DEFINE_COMMAND ("note", do_note, POSITION_DEAD, 0, LOG_NORMAL, "This command is used to post/read/remove notes.")

    if (IS_MOB (ch))
    return;
  board_here = 0;
  obj = get_obj_here (ch, "board", SEARCH_ROOM_FIRST);
  if (obj == NULL)
    {
      board_here = 1;
    }
  else
    board_here = obj->pIndexData->value[9];
  buf1[0] = '\0';
  argy = one_argy (argy, arg);
  smash_tilde (argy);
  if (arg[0] == '\0')
    {
      do_note (ch, "read");
      return;
    }
  if (!str_cmp (arg, "list"))
    {
      vnum = 0;
      
 	sprintf(buf1,"\x1B[1;30m------------------------------------------------------------------------\x1B[37;0m\n\r");
      sprintf(buf1+strlen(buf1),"\x1B[1;36m New  ###  Sender/From         Subject\x1B[37;0m\n\r");
	sprintf(buf1+strlen(buf1),"\x1B[1;30m------------------------------------------------------------------------\x1B[37;0m\n\r");

      for (pnote = note_list; pnote != NULL; pnote = pnote->next)
	{
	  if (is_note_to (ch, pnote) &&
	      (board_here == pnote->board_num || IS_IMMORTAL (ch)))
	    {
		  if (strlen(pnote->subject)>35) {
			pnote->subject[35]='\0';
			}
	      sprintf (buf, "%s \x1B[1;36m%3d\x1B[37;0m  From \x1b[1;37m%-14s\x1B[37;0m '\x1B[1;36m%s\x1B[37;0m'\n\r",
		       (pnote->date_stamp > ch->pcdata->last_note
			&& str_cmp (pnote->sender, NAME (ch))) ? "\x1B[1;34m(New)\x1B[37;0m" : "     ",
		       vnum,
		pnote->sender, pnote->subject);
	      strcat (buf1, buf);
	      vnum++;
	    }
	  else
	    vnum++;
	  if (strlen (buf1) > (STD_LENGTH * 16))
	    {
	      strcat (buf1, "\n\rTOO MANY NOTES.. WAIT UNTIL A GOD REMOVES SOME!\n\r");
	      break;
	    }
	}
      page_to_char_limited (buf1, ch); 
      return;
    }
  if (!str_cmp (arg, "read"))
    {
      bool fAll;
      if (!str_cmp (argy, "all"))
	{
	  fAll = TRUE;
	  anum = 0;
	}
      else if (argy[0] == '\0' || !str_prefix (argy, "next"))
	/* read next unread note */
	{
	  vnum = 0;
	  for (pnote = note_list; pnote != NULL; pnote = pnote->next)
	    {
	      if (is_note_to (ch, pnote) &&
		  (board_here == pnote->board_num || IS_IMMORTAL (ch))
		  && str_cmp (NAME (ch), pnote->sender)
		  && ch->pcdata->last_note < pnote->date_stamp)
		{
		  sprintf (buf,"\x1B[1;30m---------------------------------------------------------------------------\x1B[37;0m\n\r");
		  sprintf (buf+strlen(buf), "[Note #\x1B[1;37m%d:%d\x1B[37;0m] From: \x1B[1;37m%s\x1B[37;0m  To: \x1B[1;37m%s\x1B[37;0m\n\r",
			   vnum,
			   pnote->board_num,
			   pnote->sender,
			   pnote->to_list);
		  if (strlen(pnote->subject)>35) {
			pnote->subject[35]='\0';
			}
		  sprintf (buf+strlen(buf),"%s.  Subject: \x1B[1;36m%s\x1B[37;0m\n\r",
			   pnote->date,
			   pnote->subject);
		  sprintf (buf+strlen(buf),"\x1B[1;30m---------------------------------------------------------------------------\x1B[37;0m\n\r");
		  strcat (buf1, buf);
		  strcat (buf1, pnote->text);
		  ch->pcdata->last_note = UMAX (ch->pcdata->last_note, pnote->date_stamp);
		
                  page_to_char_limited (buf1, ch); 
		  return;
		}
	      else
		vnum++;
	    }
	  send_to_char ("You have no unread notes.\n\r", ch);
	  return;
	}
      else if (is_number (argy))
	{
	  fAll = FALSE;
	  anum = atoi (argy);
	}
      else
	{
	  send_to_char ("Note read which number?\n\r", ch);
	  return;
	}
      vnum = 0;
      for (pnote = note_list; pnote != NULL; pnote = pnote->next)
	{
	  if ((vnum++ == anum || fAll) && is_note_to (ch, pnote) &&
	      (board_here == pnote->board_num || IS_IMMORTAL (ch)))
	    {
		  sprintf (buf,"\x1B[1;30m---------------------------------------------------------------------------\x1B[37;0m\n\r");
		  sprintf (buf+strlen(buf), "[Note #\x1B[1;37m%d:%d\x1B[37;0m] From: \x1B[1;37m%s\x1B[37;0m  To: \x1B[1;37m%s\x1B[37;0m\n\r",
			   vnum - 1,
			   pnote->board_num,
			   pnote->sender,
			   pnote->to_list);
		  if (strlen(pnote->subject)>35) {
			pnote->subject[35]='\0';
			}
		  sprintf (buf+strlen(buf),"Dated %s.  Subject: \x1B[1;36m%s\x1B[37;0m\n\r",
			   pnote->date,
			   pnote->subject);
		  sprintf (buf+strlen(buf),"\x1B[1;30m---------------------------------------------------------------------------\x1B[37;0m\n\r");
	      strcat (buf1, buf);
	      strcat (buf1, pnote->text);
	  
              page_to_char_limited (buf1, ch); 
	      return;
	    }
	}
      send_to_char ("No such note.\n\r", ch);
      return;
    }
  if (!str_cmp (arg, "write"))
    {
      if (LEVEL (ch) < IMM_LEVEL && board_here == 1)
	{
	  send_to_char ("You can't write on the immortal notice board.\n\r", ch);
	  return;
	}
      if (IS_SET(ch->act, PLR_LAMER))
	{
	  send_to_char("You have lost your board writing privileges.\n\r", ch);
	  send_to_char("Maybe if you grow up you will be allowed to start\n\r", ch);
	  send_to_char("posting on the board again, however since you have\n\r", ch);
	  send_to_char("consistently shown yourself to be lame this is not likely.\n\r", ch);
	  return;
	}
      check_ced (ch);
      note_attach (ch);
      string_append (ch, &ch->ced->pnote->text);
      return;
    }
  if (!str_cmp (arg, "fwrite"))
    {
      if (IS_SET(ch->act, PLR_LAMER))
	{
	  send_to_char("You have lost your board writing privileges.\n\r", ch);
	  send_to_char("Maybe if you grow up you will be allowed to start\n\r", ch);
	  send_to_char("posting on the board again, however since you have\n\r", ch);
	  send_to_char("consistently shown yourself to be lame this is not likely.\n\r", ch);
	  return;
	}
      if (LEVEL (ch) < IMM_LEVEL && board_here == 1)
	{
	  send_to_char ("You can't write on the immortal notice board.\n\r", ch);
	  return;
	}
      check_ced (ch);
      note_attach (ch);
      fullscreen_editor (ch, &ch->ced->pnote->text);
      return;
    }

  if (!str_cmp (arg, "+"))
    {
      
      check_ced (ch);
      note_attach (ch);
      strcpy (buf, ch->ced->pnote->text);
      if (strlen (buf) + strlen (argy) >= STD_LENGTH - 200)
	{
	  send_to_char ("Note too long.\n\r", ch);
	  return;
	}
      strcat (buf, argy);
      strcat (buf, "\n\r");
      free_string (ch->ced->pnote->text);
      ch->ced->pnote->text = str_dup (buf);
      ch->ced->pnote->lines += 1;
      send_to_char ("Ok.\n\r", ch);
      return;
    }  
  if (!str_cmp (arg, "-"))
    {
      int num, cnt;
      char new_buf[STD_LENGTH];
      const char *str;
      check_ced (ch);
      if (ch->ced->pnote == NULL)
	{
	  send_to_char ("You have to start a note first.\n\r", ch);
	  return;
	}
      if (ch->ced->pnote->lines == 0)
	{
	  send_to_char ("Nothing to delete.\n\r", ch);
	  return;
	}
      new_buf[0] = '\0';
      str = ch->ced->pnote->text;
      cnt = 1;
      for (num = 1; num <= ch->ced->pnote->lines; num++)
	{
	  while (*str != '\r' && *str != '\0')
	    {
	      ++str;
	      ++cnt;
	    }
	}
      strncpy (new_buf, ch->ced->pnote->text, cnt);
      new_buf[cnt] = '\0';
      free_string (ch->ced->pnote->text);
      ch->ced->pnote->text = str_dup (new_buf);
      ch->ced->pnote->lines -= 1;
      send_to_char ("Ok.\n\r", ch);
      return;
    }
  if (!str_cmp (arg, "subject"))
    {
      if (IS_SET(ch->act, PLR_LAMER))
	{
	  send_to_char("You have lost your board writing privileges.\n\r", ch);
	  send_to_char("Maybe if you grow up you will be allowed to start\n\r", ch);
	  send_to_char("posting on the board again, however since you have\n\r", ch);
	  send_to_char("consistently shown yourself to be lame this is not likely.\n\r", ch);
	  return;
	}
      check_ced (ch);
      note_attach (ch);
      free_string (ch->ced->pnote->subject);
      ch->ced->pnote->subject = str_dup (argy);
      send_to_char ("Ok.\n\r", ch);
      return;
    }
  if (!str_cmp (arg, "to"))
    {
      if (IS_SET(ch->act, PLR_LAMER))
	{
	  send_to_char("You have lost your board writing privileges.\n\r", ch);
	  send_to_char("Maybe if you grow up you will be allowed to start\n\r", ch);
	  send_to_char("posting on the board again, however since you have\n\r", ch);
	  send_to_char("consistently shown yourself to be lame this is not likely.\n\r", ch);
	  return;
	}
      check_ced (ch);
      note_attach (ch);
      free_string (ch->ced->pnote->to_list);
      ch->ced->pnote->to_list = str_dup (argy);
      send_to_char("\x1b[1;31mBe sure to put 'pkill' or 'flame' if this is a pkill flame note.\x1b[0;37m", ch);
      send_to_char ("Ok.\n\r", ch);
      return;
    }
  if (!str_cmp (arg, "clear"))
    {
      if (IS_SET(ch->act, PLR_LAMER))
	{
	  send_to_char("You have lost your board writing privileges.\n\r", ch);
	  send_to_char("Maybe if you grow up you will be allowed to start\n\r", ch);
	  send_to_char("posting on the board again, however since you have\n\r", ch);
	  send_to_char("consistently shown yourself to be lame this is not likely.\n\r", ch);
	  return;
	}
      check_ced (ch);
      if (ch->ced->pnote != NULL)
	{
	  free_string (ch->ced->pnote->text);
	  free_string (ch->ced->pnote->subject);
	  free_string (ch->ced->pnote->to_list);
	  free_string (ch->ced->pnote->date);
	  free_string (ch->ced->pnote->sender);
	  ch->ced->pnote->next = note_free;
	  note_free = ch->ced->pnote;
	  ch->ced->pnote = NULL;
	}
      send_to_char ("Ok.\n\r", ch);
      return;
    }
  if (!str_cmp (arg, "show"))
    {
      if (IS_SET(ch->act, PLR_LAMER))
	{
	  send_to_char("You have lost your board writing privileges.\n\r", ch);
	  send_to_char("Maybe if you grow up you will be allowed to start\n\r", ch);
	  send_to_char("posting on the board again, however since you have\n\r", ch);
	  send_to_char("consistently shown yourself to be lame this is not likely.\n\r", ch);
	  return;
	}
      check_ced (ch);
      if (ch->ced->pnote == NULL)
	{
	  send_to_char ("You have no note in progress.\n\r", ch);
	  return;
	}
      sprintf (buf, "%s: %s\n\rTo: %s\n\rLines: %d\n\r",
	       ch->ced->pnote->sender,
	       ch->ced->pnote->subject,
	       ch->ced->pnote->to_list,
	       ch->ced->pnote->lines
	);
      strcat (buf1, buf);
      strcat (buf1, ch->ced->pnote->text);

      page_to_char_limited (buf1, ch); 
      return;
    }
  if (!str_cmp (arg, "post") || !str_prefix (arg, "send"))
    {
      FILE *fp;
      char *strtime;
      
      check_ced (ch);
      
      if (ch->ced->pnote == NULL)
	{
	  send_to_char ("You have no note in progress.\n\r", ch);
	  return;
	}
      if (board_here == 1 && LEVEL (ch) < IMM_LEVEL)
	{
	  send_to_char ("This board is reserved for immortals posting messages to mortals.\n\r", ch);
	  send_to_char ("Please post on a public board if you wish to write a note.\n\r", ch);
	  return;
	}
      if (!str_cmp (ch->ced->pnote->to_list, ""))
	{
	  send_to_char (
	    "You need to provide a recipient (name, all, or immortal).\n\r",
			 ch);
	  return;
	}
      if (!str_cmp (ch->ced->pnote->subject, ""))
	{
	  send_to_char ("You need to provide a subject.\n\r", ch);
	  return;
	}
      if (IS_SET(ch->act, PLR_LAMER))
	{
	  send_to_char("You have lost your board writing privileges.\n\r", ch);
	  send_to_char("Maybe if you grow up you will be allowed to start\n\r", ch);
	  send_to_char("posting on the board again, however since you have\n\r", ch);
	  send_to_char("consistently shown yourself to be lame this is not likely.\n\r", ch);
	  return;
	}
      ch->pcdata->online_spot->notes_this_reboot++;
      if(ch->pcdata->online_spot->notes_this_reboot > 8)
	{
	  send_to_char("You have already written too many notes this reboot.\n\r", ch);
	  return;
	}

      ch->ced->pnote->next = NULL;
      strtime = ctime (&current_time);
      strtime[strlen (strtime) - 1] = '\0';
      ch->ced->pnote->board_num = board_here;
      ch->ced->pnote->date = str_dup (strtime);
      ch->ced->pnote->date_stamp = current_time;
      if (note_list == NULL)
	{
	  note_list = ch->ced->pnote;
	}
      else
	{
	  for (pnote = note_list; pnote->next != NULL; pnote = pnote->next)
	    ;
	  pnote->next = ch->ced->pnote;
	}
      pnote = ch->ced->pnote;
      ch->ced->pnote = NULL;
#ifndef WINDOWS
//      fclose (fpReserve);
#endif
      if ((fp = fopen (NOTE_FILE, "a")) == NULL)
	{
	  perror (NOTE_FILE);
	}
      else
	{
	  fprintf (fp, "Sender %s~\n", fix_string (pnote->sender));
	  fprintf (fp, "TBoard %d\n", pnote->board_num);
	  fprintf (fp, "Date %s~\n", pnote->date);
	  fprintf (fp, "Stamp %ld\n", pnote->date_stamp);
	  fprintf (fp, "To %s~\n", fix_string (pnote->to_list));
	  fprintf (fp, "Subject %s~\n", fix_string (pnote->subject));
	  fprintf (fp, "Text\n%s~\n", pnote->text);
	  fprintf (fp, "End\n\n");
	  fclose (fp);
	}
#ifndef WINDOWS
//      fpReserve = fopen (NULL_FILE, "r");
#endif
      send_to_char ("Ok.\n\r", ch);
      return;
    }
  if (!str_cmp (arg, "remove"))
    {
      if (!is_number (argy))
	{
	  send_to_char ("Note remove which number?\n\r", ch);
	  return;
	}
      anum = atoi (argy);
      vnum = 0;
      for (pnote = note_list; pnote != NULL; pnote = pnote->next)
	{
	  if (vnum++ == anum && (
				  (is_note_to (ch, pnote) && !is_name ("all", pnote->to_list)) || LEVEL (ch) > 109))
	    {
	      note_remove (ch, pnote);
	      send_to_char ("Ok.\n\r", ch);
	      return;
	    }
	}
      send_to_char ("No such note.\n\r", ch);
      return;
    }
  send_to_char ("Huh? Type 'help note' for usage.\n\r", ch);
  return;
}
예제 #17
0
int read_parameter_file(  char *parameter_filename,
																			RUN_TIME_TYPE **pp,
																			NEURONE_TYPE **n_neurone,
																			MATCH_TYPE **match,
																			int *batch_flag )
{
	char string[241], keyword[11];
	FILE    *input_stream;
	long input_weight_offset;
	RUN_TIME_TYPE  *p;
	NEURONE_TYPE  *neurone;
	int card_type=NOTHING,
					n, j, k, r1, c1,
					tpat_count, npat_count, row_count;
	int q;
	char dflag[2],temp_str[2];
	int state_val;
	int random_val;
	int rtype_flag_temp;
	long fp;
	int num_rands = 0;
	//int				local_var;
	int r;
	int count, temp_act;


	if ( (input_stream = fopen( parameter_filename, "r" )) == NULL )
	{
									printf( "\nFatal Error - could not open input file : %s\n",parameter_filename );
									return( F_FALSE );
	}

	//  Read in the cards. The NET card is the first valid card expected.
	//  This should be followed by the TPAT cards.
	//	Then the single NPAT block should be read.

	// First allocate memory for the parameter block.
	p = (RUN_TIME_TYPE *) malloc( sizeof(RUN_TIME_TYPE) );
	*pp = p; // Set for return

	p->weight.flag = MEMORY; // use memory rather than disk
	p->number_of_patterns = 0;
	p->states = 0;
	p->actives = 0;
	p->brain_iterations = 1;
	p->noise_level = 0;
	p->match_perc       = 100.0F;
	p->report.flag = F_FALSE;

	tpat_count = 0;
	npat_count = 0;
	row_count  = 0;


	while ( fgets( string, 240, input_stream ) != NULL )
	{
									//printf("%s", string ) ;

									// Condition the input string for further processing
									uppercase(lr_pack(fix_string(string)));

									// Take care of the NET card case
									if ( strncmp( "NET", string, 3 ) == 0 )
									{
																	if ( card_type != NOTHING ) // Have already read a NET card
																	{
																									printf( "\nFatal Error - a NET card has already been read. Only\n"
																																	"one NET specification is allowed. This should be the\n"
																																	"first valid card in the file.\n");
																									return( F_FALSE );
																	}
																	else if ( sscanf( string, "%s %d %d %d %d %d %d %s %s %s %s",
																																			keyword,
																																			&(p->rows),
																																			&(p->cols),
																																			&(p->states),
																																			&(p->actives),
																																			&(p->update_cycles),
																																			&(p->num_pats),
																																			dflag,
																																			p->input_weight.file,
																																			p->output_weight.file,
																																			p->pattern.file
																																			) != 11 )
																	{
																									printf("\nFatal Error - NET card did not have enough parameters !\n");
																									return( F_FALSE );
																	}

																	// check to see if we have valid input for the int data types ...
																	if ( (p->rows) < 1 || (p->cols) < 1 || (p->num_pats) < 0 || (p->states) < 0 || (p->actives) < 0 )
																	{
																									printf("\nFatal Error - NET has illegal parameters specified !\n" );
																									return( F_FALSE );
																	}

																	// Set dflag and check input ...
																	if   ( *dflag == 'N' ) (p->rtype_flag) = NOT_DREAMING;
																	else if ( *dflag == 'R' ) (p->rtype_flag) = RANDOM_TEST;
																	else
																	{
																									printf("\nFatal Error - NET run parameters must be N or R !!" );
																									return( F_FALSE );
																	}

																	if ( *(p->input_weight.file) == '-' ) // Set up input weight file flags
																									p->input_weight.flag = F_FALSE;
																	else
																	{
																									// Make sure that the input weight file actually exists.
																									if ( (p->input_weight.stream=fopen( p->input_weight.file, "rb" )) == NULL )

																									{
																																	printf("\nFatal Error - %s was not found !!!\n", p->input_weight.file );
																																	return( F_FALSE );
																									}

																									// Make sure of matching dimensions.
																									fread( &r1, sizeof( int ), 1, p->input_weight.stream );
																									fread( &c1, sizeof( int ), 1, p->input_weight.stream );
																									input_weight_offset = ftell( p->input_weight.stream ); // Save
																									if ( r1 != (p->rows)  ||  c1 != (p->cols) )
																									{
																																	printf(  "\nFatal Error - Weight matrix mismatch...."
																																										"\n  NET image has %d rows and %d cols while"
																																										"\n  weight file %s has %d rows and %d cols."
																																										"\n  rows and columns must match !!!\n",
																																										(p->rows), (p->cols), p->input_weight.file, r1, c1);
																																	return( F_FALSE );
																									}
																									p->input_weight.flag = F_TRUE;
																	}

																	if ( *(p->output_weight.file) == '-' ) // ...output weight file flags
																									p->output_weight.flag = F_FALSE;
																	else
																									p->output_weight.flag = F_TRUE;

																	if ( (p->num_pats) == 0  && p->input_weight.flag == F_FALSE )
																	{
																									printf( "\nFatal Error - You have specified a run with no input"
																																	"\n              weight file and and no patterns to learn"
																																	"\n              from (see parameter 5 of the NET image and"
																																	"\n              your TPAT and RPAT images). Brainex needs"
																																	"\n              to get a connection weight matrix from"
																																	"\n              somewhere you ninkempoop.\n" );
																									return( F_FALSE );
																	}

																	if ( *(p->pattern.file) == '-' ) // Set up for learnt patterns
																	{
																									p->pattern.flag = F_FALSE;
																									if ( (p->rtype_flag) == RANDOM_TEST )
																									{
																																	printf( "\nFatal Error - must have pattern file "
																																									"when random testing !!\n" );
																																	return( F_FALSE );
																									}
																	}
																	else
																	{
																									// Make sure that the input pattern file actually exists. */
																									if ( (p->pattern.stream=fopen( p->pattern.file, "a+b" )) == NULL )
																									{
																																	printf("\nFatal Error - %s illegal !!!\n", p->pattern.file );
																																	return( F_FALSE );
																									}

																									fseek( p->pattern.stream, 0L, SEEK_END ); // Set to end of file
																									fp = ftell( p->pattern.stream ); // Where are we ?

																									if ( fp == 0L  &&  (p->rtype_flag) == RANDOM_TEST )
																									{
																																	printf("\nFatal Error - pattern file empty, no report possible!!\n" );
																																	return( F_FALSE );
																									}
																									else if ( fp == 0L  &&  (p->rtype_flag) != RANDOM_TEST )
																									{
																																	fwrite( &(p->rows), sizeof(int), 1, p->pattern.stream );
																																	fwrite( &(p->cols), sizeof(int), 1, p->pattern.stream );
																									}
																									else if ( fp > 0L )
																									{
																																	fseek( p->pattern.stream, 0L, SEEK_SET ); // Go to start of file
																																	// Make sure of matching dimensions
																																	fread( &r1, sizeof(int), 1, p->pattern.stream );
																																	fread( &c1, sizeof(int), 1, p->pattern.stream );
																																	if ( r1 != (p->rows)  ||  c1 != (p->cols) )
																																	{
																																									printf( "\nFatal Error - Pattern file matrix mismatch...."
																																																	"\n  NET image has %d rows and %d cols while"
																																																	"\n  learnt pattern file %s has %d rows and %d cols."
																																																	"\n  Rows and columns must match !!!\n",
																																																	(p->rows), (p->cols), p->pattern.file, r1, c1 );
																																									return( F_FALSE );
																																	}
																									}
																									p->pattern.flag = F_TRUE;
																	}

																	card_type = NET;

																	// set the number of modules in the network
																	p->number_of_neurones = (p->rows) * (p->cols);
																	n = p->number_of_neurones;

																	// If we are here then we must have found a NET card with valid parameters
																	if ( ( neurone = (NEURONE_TYPE *) malloc( sizeof(NEURONE_TYPE) * n ) ) == NULL )
																	{
																									printf( "\nFatal Error - rows and columns specify a neural grid that\n"
																																	"                exceeds the available system memory.\t:(\n" );
																									return( F_FALSE );
																	}

																	*n_neurone = neurone; // Set for return

																	//printf("\ntrying to malloc some memory for the weight file...\n");

																	// get memory for the weights
																	count = 0;
																	for ( j=0; j<n; j++ )
																	{
																									(neurone+j)->id_num = j;
																									(neurone+j)->nw     = n*n*(p->states)*(p->states);// we have n squared weights
																									// malloc the top level:
																									if ( ((neurone+j)->w = (WEIGHT_MATRIX **)malloc(sizeof(WEIGHT_MATRIX)*n)) == NULL)
																									{
																																	printf( "\n Not enough memory for the weight grid\n");
																																	return( F_FALSE );
																									}
																									else // malloc each matrix
																									{
																																	for(k=0; k<n; k++)
																																	{
																																									// malloc rows:
																																									if ( ((neurone+j)->w[k] = (WEIGHT_MATRIX *)malloc(sizeof(WEIGHT_MATRIX)*n)) == NULL)
																																									{
																																																	return( F_FALSE);
																																									}
																																									if (((neurone+j)->w[k]->weight = (int **) malloc( (p->states) * sizeof(int*))) == NULL )
																																									{
																																																	printf( "\n Not enough memory for the weight grid...\n");
																																																	return( F_FALSE );
																																									}
																																									// and finally malloc cols:
																																									for (q = 0; q<(p->states); q++)
																																									{
																																																	if (((neurone+j)->w[k]->weight[q] = malloc( (p->states) * sizeof(int))) == NULL )
																																																	{
																																																									printf( "\n Not enough memory for the weight grid...\n");
																																																									return( F_FALSE );
																																																	}
																																																	// init elements of the weight matrix to zero
																																																	else
																																																	{
																																																									for(r=0; r<(p->states); r++)
																																																									{
																																																																	(neurone+j)->w[k]->weight[q][r] = 0; //initialise to zero
																																																																	count++;
																																																																	//printf("j = %d\tk = %d\tweight matrix: weight[%d][%d] = %d\n",j,k,q,r,(neurone+j)->w[k]->weight[q][r]);
																																																									}
																																																	}
																																									}
																																	}
																									}
																	}

																	//printf("\nmalloc of weight memory done. did it work?\tcount = %d\tshould be %d\n\n",count,n*n*(p->states)*(p->states));
																	// read in the weights from file if requested to do so
																	if ( p->input_weight.flag == F_TRUE )
																	{
																									count = 0;
																									//printf("\nreading in predefined weights from file %s\n",p->input_weight.file);
																									for(j=0; j<n; j++)
																									{
																																	for(k=0; k<n; k++)
																																	{
																																									for(q=0; q< (p->states); q++)
																																									{
																																																	for(r=0; r< (p->states); r++)
																																																	{
																																																									fread(&((neurone+j)->w[k]->weight[q][r]), sizeof(int),1, p->input_weight.stream);
																																																									count++;
																																																									//printf("j = %d\tk = %d\tweight matrix: weight[%d][%d] = %d\n",j,k,q,r,(neurone+j)->w[k]->weight[q][r]);
																																																	}
																																									}
																																	}
																									}
																									// close the file
																									fclose( p->input_weight.stream );
																									//printf("read %d elements from file %s\tshould have read %d elements!\n",count,p->input_weight.file,n*n*(p->states)*(p->states));
																	}

																	// get memory for states per module
																	if (p->states == 0)
																	{
																									printf("p->states == 0. something bad is about to happen...\n");
																									return(F_FALSE);
																	}
																	else
																	{
																									for ( j=0; j<n; j++ )
																									{
																																	if ( ( (neurone+j)->states = (int *) malloc( sizeof(int)*(p->states) ) ) == NULL )
																																	{
																																									printf( "\nNot enough memory for the state vectors.\n");
																																									return( F_FALSE );
																																	}
																																	else
																																	{
																																									for ( k = 0; k < (p->states); k++ )
																																									{
																																																	(neurone+j)->states[k] = 0; // Initialise to 0
																																									}
																																	}
																									}
																	}
									} // end of the NET case

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

									// Take care of the TPAT/RPAT card case
									if ( strncmp( "TPAT", string, 4 ) == 0 || strncmp( "RPAT", string, 4 ) == 0     )
									{
																	// Investigate the entry status
																	if ( card_type != RPAT  &&  card_type != TPAT  &&  card_type != NET )
																	{
																									printf(  "\nFatal Error - Only a NET, TPAT or RPAT image may\n"
																																		"precede a TPAT or RPAT image. A NET card must precede\n"
																																		"all TPAT/RPAT blocks. Exactly one NET card must appear\n"
																																		"and it must be the first valid card in the parameter\n"
																																		"specification file.\n" );
																									return( F_FALSE );
																	}
																	else if ( card_type == TPAT  &&  row_count != (p->rows) )
																	{
																									printf( "\nFatal Error - TPAT Pattern block %d should have %d rows,"
																																	"\n              only %d rows were actually counted !\n",
																																	tpat_count, (p->rows), row_count );
																									return( F_FALSE );
																	}

																	if ( strncmp( "TPAT", string, 4)== 0)
																									card_type = TPAT;
																	else if ( strncmp( "RPAT", string, 4)== 0)
																									card_type = RPAT;

																	row_count = 0; // This is used to control image access

																	tpat_count++; // Use this to count both TPAT and RPAT images
																	if ( tpat_count > (p->num_pats) )
																	{
																									printf( "\nFatal Error - Too many TPAT/RPAT definitions. The number\n"
																																	"of TPAT/RPAT definitions must match the NET specification.\n" );
																									return( F_FALSE );
																	}
																	for(j=0; j<n; j++) // zero the states for TPAT reading
																	{
																									for(k=0; k<(p->states); k++)
																									{
																																	(neurone+j)->states[k] = 0; // zero the states
																									}
																									(neurone+j)->tag = 0; // and the tags
																	}
									} // end of the TPAT/RPAT case

									// Take care of the NPAT/RANDIN card case
									if ( strncmp( "NPAT", string, 4 ) == 0 || strncmp( "RANDIN", string, 6 ) == 0)
									{
																	if ( tpat_count != (p->num_pats) )
																	{
																									printf( "\nFatal Error - Not enough TPAT/RPAT sets before NPAT!!\n");
																									return( F_FALSE );
																	}
																	else if ( card_type == TPAT  &&  row_count != (p->rows) )
																	{
																									printf( "\nFatal Error - TPAT Pattern block %d should have %d rows,"
																																	"\n                only %d rows were actually counted !\n",
																																	tpat_count, (p->rows), row_count );
																									return( F_FALSE );
																	}
																	else if ( npat_count > 0 )
																	{
																									printf( "\nFatal Error - Only 1 NPAT/RANDIN block is allowed !!\n");
																									return( F_FALSE );
																	}

																	if ( strncmp( "NPAT", string, 4 ) == 0  )
																	{
																									row_count = 0; // We have to count the rows....
																	}

																	if ( strncmp( "RANDIN", string, 4 ) == 0  )
																	{
																									row_count = (p->rows); // Set up as dummy value

																									if ( sscanf(string, "%s %d %d %f %s",
																																					keyword,
																																					&(p->brain_iterations),&(p->noise_level),
																																					&(p->match_perc),
																																					p->report.file        ) != 5 )
																									{
																																	printf("\nFatal Error - RANDIN card, not enough parameters !\n");
																																	return( F_FALSE );
																									}

																									if ( (p->brain_iterations) < 1 )
																									{
																																	printf( "\nFatal Error - RANDIN parameters illegal - "
																																									"\n              Number of random cycles must be >= 1" );
																																	return( F_FALSE );
																									}

																									// Check on the report file.
																									if ( (p->report.stream=fopen( p->report.file, "a+" )) == NULL )
																									{
																																	printf("\nFatal Error - %s illegal !!!\n", p->report.file );
																																	return( F_FALSE );
																									}
																									p->report.flag = F_TRUE; // Enable

																									// Start the report
																									report_header( p->report.stream, p );

																									p->number_of_patterns = get_number_of_patterns( p->pattern.stream );

																									report_patterns( p->report.stream, p->pattern.stream );

																									// Get memory to be used in report of stats
																									*match = (MATCH_TYPE *) malloc( sizeof(MATCH_TYPE) * ( p->number_of_patterns + 1 ) );
																	}
																	card_type = NPAT;
																	npat_count = 1;
									} // end of the NPAT/RANDIN case


									if ( ( card_type == TPAT || card_type == NPAT) && ( strncmp( "0", string, 1 ) == 0 ||
																																																													strncmp( "1", string, 1 ) == 0 || strncmp( "2", string, 1 ) == 0 ||
																																																													strncmp( "3", string, 1 ) == 0 || strncmp( "4", string, 1 ) == 0 ||
																																																													strncmp( "5", string, 1 ) == 0 || strncmp( "6", string, 1 ) == 0 ||
																																																													strncmp( "7", string, 1 ) == 0 || strncmp( "8", string, 1 ) == 0 ||
																																																													strncmp( "9", string, 1 ) == 0   )  )
									{
																	row_count++;
																	if ( row_count > (p->rows) )
																	{
																									printf( "\nFatal Error - Pattern block must have only %d rows!\n",(p->rows));
																									return( F_FALSE );
																	}

																	if ( (int)strlen( string ) != (p->cols) )
																	{
																									printf( "\nFatal Error - Pattern block bad row %d\n\n"
																																	"There are an incorrect number of columns.\n"
																																	"in the pattern string.\n"
																																	"The number of columns found was : %d\n"
																																	"There should be exactly %d columns.\n",
																																	row_count, (int)strlen( string ), (p->cols) );
																									return( F_FALSE );
																	}

																	if ( (int)strspn( string, "0123456789" ) != (p->cols)  )
																	{
																									printf( "\nFatal Error - Pattern block bad at row %d\n\n"
																																	"There are illegal characters in the pattern string.\n"
																																	"Only integers are allowed in a pattern string.\n",
																																	row_count );
																									return( F_FALSE );
																	}

																	// fill in the neural array with the TPAT/NPAT values...
																	//printf("temp_act: NPAT/TPAT\n");
																	for(k=0; k<(p->cols); k++)
																	{
																									strncpy(temp_str, &string[k], sizeof(char));
																									temp_act = atoi(&temp_str[0]);
																									//printf("%d",temp_act);
																									if(temp_act != 0)
																																	(neurone+((row_count-1)*(p->cols)+k))->states[temp_act-1] = 1; // set the state
																	}
																	//printf("\n");



																	//  If the neural array has been filled with the input
																	//	activation values then we can calculate the connecting
																	//	weights (to this point).

																	if ( card_type == TPAT && row_count == (p->rows) )
																	{
																									rtype_flag_temp   = p->rtype_flag;// Preserve for restoration
																									p->rtype_flag   = NOT_DREAMING;// Set for call to update_...

																									update_neural_weights( p, neurone );

																									p->rtype_flag   = rtype_flag_temp;// Restore

																									/*
																									   printf("\nTPAT follows\n");
																									   printf("\n");

																									   for(j=0;j<n;j++)
																									   {
																									   local_var = 0;
																									   for(k=0;k<(p->states);k++)
																									   {
																									   if((neurone+j)->states[k] == 0)
																									   local_var++;
																									   else
																									   {
																									   printf("%d",local_var+1);
																									   break;
																									   }
																									   }
																									   if( local_var == (p->states))
																									   printf("0");
																									   if( (j+1) % (p->cols) == 0)
																									   printf("\n");
																									   }
																									 */
																	}

									}
									else if (  card_type != TPAT && card_type != NPAT &&
																				( strncmp( "0", string, 1 ) == 0 || strncmp( "1", string, 1 ) == 0 ||
																						strncmp( "2", string, 1 ) == 0 || strncmp( "3", string, 1 ) == 0 ||
																						strncmp( "4", string, 1 ) == 0 || strncmp( "5", string, 1 ) == 0 ||
																						strncmp( "6", string, 1 ) == 0 || strncmp( "7", string, 1 ) == 0 ||
																						strncmp( "8", string, 1 ) == 0 || strncmp( "9", string, 1 ) == 0 ))
									{
																	printf("\nFatal Error - Pattern detected without a preceding TPAT!\n" );
																	return( F_FALSE );
									}

									// Now process RPAT. This means the generation of a random pattern.
									if ( card_type == RPAT  &&  row_count == 0 )
									{
																	for(j=0; j<n; j++)
																	{
																									for(k=0; k<(p->states); k++)
																									{
																																	(neurone+j)->states[k] = 0; // zero the states
																									}
																									(neurone+j)->tag = 0; // and the tags
																	}
																	// Fill in the neural array....
																	num_rands = 0;
																	//printf("generating an RPAT...\n");
																	do
																	{
																									random_val = (int)ceil((n-1) * ran4());
																									//printf("random_val = %d\n",random_val);
																									if( (neurone+(int)random_val)->tag != 1 )
																									{
																																	state_val = (int)ceil((p->states)*ran4());
																																	//printf("\tstate_val = %d\n",state_val);
																																	(neurone+(int)random_val)->states[(int)state_val-1] = 1; // -1 because 0 is the first element
																																	(neurone+(int)random_val)->tag=1;
																																	num_rands++;
																									}
																	} while(num_rands != (p->actives));

																	/*
																	   printf("\nRPAT follows\n");
																	   printf("\n");

																	   for(j=0;j<n;j++)
																	   {
																	   local_var = 0;
																	   for(k=0;k<(p->states);k++)
																	   {
																	   if((neurone+j)->states[k] == 0)
																	   local_var++;
																	   else
																	   {
																	   printf("%d",local_var+1);
																	   break;
																	   }
																	   }
																	   if( local_var == (p->states))
																	   printf("0");
																	   if( (j+1) % (p->cols) == 0)
																	   printf("\n");
																	   }
																	 */


																	//  If the neural array has been filled with the input
																	//	activation values then we can calculate the connecting
																	//	weights (to this point)


																	rtype_flag_temp   = p->rtype_flag;// Preserve for restoration
																	p->rtype_flag   = NOT_DREAMING;// Set for call to update_...
																	//printf("\n calculating weights.....\n");
																	update_neural_weights( p, neurone ); // calculate the connecting weights up to this point ***************

																	p->rtype_flag   = rtype_flag_temp;// Restore


																	// We set row_count to force a new TPAT/RPAT before re-entry
																	row_count = (p->rows);
									}
	} // End of the outer while loop

	// Make sure that there were enough patterns
	if ( tpat_count != (p->num_pats) )
	{
									printf(  "\nFatal Error - Incorrect number of TPAT definitions.\n"
																		"The number of TPAT definitions must match the\n"
																		"NET specification.\n\n"
																		"Number of TPAT blocks from the NET specification : %d\n"
																		"Number of TPAT blocks actually found             : %d\n",
																		(p->num_pats), tpat_count );
									return( F_FALSE );
	}
	else if ( npat_count != 1 )
	{
									printf("\nFatal Error - There should be exactly 1 NPAT block!\n" );
									return( F_FALSE );
	}
	else if ( row_count != (p->rows)  &&  (p->update_cycles) > 0 )
	{
									printf(  "\nFatal Error - NPAT pattern block should have %d rows,\n"
																		"                only %d rows were actually counted !\n",
																		(p->rows), row_count );
									return( F_FALSE );
	}

	fclose( input_stream ); // Close the input parameter file
	return( F_TRUE ); // and return to main()
}
예제 #18
0
void save_helps( FILE *fp, AREA_DATA *pArea )
{
    HELP_DATA *pHelp;
    bool found = FALSE;

    for (pHelp = first_help; pHelp; pHelp = pHelp->next)
    {
        if( pHelp->area && pHelp->area == pArea )
        {
            if( !found )
            {
                fprintf( fp, "#HELPS\n\n" );
                found = TRUE;
            }
            fprintf(fp, "%d %s~\n%s~\n", pHelp->level, all_capitalize(pHelp->keyword), fix_string(pHelp->text));
        }
    }

    if( found )
        fprintf( fp, "\n0 $~\n\n" );

    return;
}
예제 #19
0
파일: olc_save.c 프로젝트: verias/SRMud
/*****************************************************************************
 Name:		save_rooms
 Purpose:	Save #ROOMS section of an area file.
 Called by:	save_area(olc_save.c).
 ****************************************************************************/
void save_rooms( FILE *fp, AREA_DATA *pArea )
{
    ROOM_INDEX_DATA *pRoomIndex;
    EXTRA_DESCR_DATA *pEd;
    EXIT_DATA *pExit;
    char buf[MSL];
    int iHash, i, locks;

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

    for( iHash = 0; iHash < MAX_KEY_HASH; iHash++ )
    {
        for( pRoomIndex = room_index_hash[iHash]; pRoomIndex; pRoomIndex = pRoomIndex->next )
        {
            if ( pRoomIndex->area == pArea )
            {
                fprintf( fp, "#%d\n",		pRoomIndex->vnum );
                fprintf( fp, "%s~\n",		pRoomIndex->name );
                fprintf( fp, "%s~\n0\n",	fix_string( pRoomIndex->description ) );
                fprintf( fp, "%s ",		fwrite_flag(pRoomIndex->room_flags, buf) );
                fprintf( fp, "%d\n",		pRoomIndex->sector_type );

                for ( pEd = pRoomIndex->extra_descr; pEd;
                      pEd = pEd->next )
                {
                    fprintf( fp, "E\n%s~\n%s~\n", pEd->keyword,
                                                  fix_string( pEd->description ) );
                }

		for( i = 0; i < MAX_DIR; i++ )
                {
		    if ((pExit = pRoomIndex->exit[i]) == NULL)
		    	continue;

                    if ( pExit->u1.to_room )
                    {
			locks = 0;

			if ( IS_SET(pExit->rs_flags, EX_CLOSED)
			||   IS_SET(pExit->rs_flags, EX_LOCKED)
			||   IS_SET(pExit->rs_flags, EX_PICKPROOF)
			||   IS_SET(pExit->rs_flags, EX_NOPASS)
			||   IS_SET(pExit->rs_flags, EX_EASY)
			||   IS_SET(pExit->rs_flags, EX_HARD)
			||   IS_SET(pExit->rs_flags, EX_INFURIATING)
			||   IS_SET(pExit->rs_flags, EX_NOCLOSE)
			||   IS_SET(pExit->rs_flags, EX_NOLOCK) )
				SET_BIT(pExit->rs_flags, EX_ISDOOR);

			if (IS_SET(pExit->rs_flags, EX_ISDOOR))
				locks = IS_SET(pExit->rs_flags, EX_LOCKED) ? 2 : 1;

                        fprintf( fp, "D%d\n",      pExit->orig_door );
                        fprintf( fp, "%s~\n",      fix_string( pExit->description ) );
                        fprintf( fp, "%s~\n",      pExit->keyword );
                        fprintf( fp, "%d %d %d\n", locks,
                                                   pExit->key,
                                                   pExit->u1.to_room->vnum );
                    }
                }

		if (pRoomIndex->mana_rate != 100 || pRoomIndex->heal_rate != 100)
		 fprintf ( fp, "M %d H %d\n",pRoomIndex->mana_rate,
		                             pRoomIndex->heal_rate);
		if (pRoomIndex->clan > 0)
			fprintf ( fp, "L '%s'\n" , clan_table[pRoomIndex->clan].name );
		 			     
		if (pRoomIndex->owner && str_cmp(pRoomIndex->owner,""))
		 fprintf ( fp, "O %s~\n" , pRoomIndex->owner );

		fprintf( fp, "S\n" );
            }
        }
    }
    fprintf( fp, "#0\n\n\n\n" );
    return;
}
예제 #20
0
파일: olc_save.c 프로젝트: verias/SRMud
/*****************************************************************************
 Name:		save_object
 Purpose:	Save one object to file.
                new ROM format saving -- Hugin
 Called by:	save_objects (below).
 ****************************************************************************/
void save_object( FILE *fp, OBJ_INDEX_DATA *pObjIndex )
{
    char letter;
    AFFECT_DATA *pAf;
    EXTRA_DESCR_DATA *pEd;
    char buf[MAX_STRING_LENGTH];

    fprintf( fp, "#%d\n",    pObjIndex->vnum );
    fprintf( fp, "%s~\n",    pObjIndex->name );
    fprintf( fp, "%s~\n",    pObjIndex->short_descr );
    fprintf( fp, "%s~\n",    fix_string( pObjIndex->description ) );
    fprintf( fp, "%s~\n",	pObjIndex->material);
    fprintf( fp, "%s ",      item_name(pObjIndex->item_type));
    fprintf( fp, "%s ",      fwrite_flag( pObjIndex->extra_flags, buf ) );
    fprintf( fp, "%s\n",     fwrite_flag( pObjIndex->wear_flags,  buf ) );

/*
 *  Using fwrite_flag to write most values gives a strange
 *  looking area file, consider making a case for each
 *  item type later.
 */

    switch ( pObjIndex->item_type )
    {
        default:
	    fprintf( fp, "%s ",  fwrite_flag( pObjIndex->value[0], buf ) );
	    fprintf( fp, "%s ",  fwrite_flag( pObjIndex->value[1], buf ) );
	    fprintf( fp, "%s ",  fwrite_flag( pObjIndex->value[2], buf ) );
	    fprintf( fp, "%s ",  fwrite_flag( pObjIndex->value[3], buf ) );
	    fprintf( fp, "%s\n", fwrite_flag( pObjIndex->value[4], buf ) );
	    break;

        case ITEM_LIGHT:
	    fprintf( fp, "0 0 %d 0 0\n",
		     pObjIndex->value[2] < 1 ? 999  /* infinite */
		     : pObjIndex->value[2] );
	    break;

        case ITEM_MONEY:
            fprintf( fp, "%d %d 0 0 0\n",
                     pObjIndex->value[0],
                     pObjIndex->value[1]);
            break;
            
        case ITEM_DRINK_CON:
            fprintf( fp, "%d %d '%s' %d 0\n",
                     pObjIndex->value[0],
                     pObjIndex->value[1],
                     liq_table[pObjIndex->value[2]].liq_name,
		     pObjIndex->value[3] );
            break;
                    
	case ITEM_FOUNTAIN:
	    fprintf( fp, "%d %d '%s' 0 0\n",
	             pObjIndex->value[0],
	             pObjIndex->value[1],
	             liq_table[pObjIndex->value[2]].liq_name);
	    break;
	    
        case ITEM_CONTAINER:
            fprintf( fp, "%d %s %d %d %d\n",
                     pObjIndex->value[0],
                     fwrite_flag( pObjIndex->value[1], buf ),
                     pObjIndex->value[2],
                     pObjIndex->value[3],
                     pObjIndex->value[4]);
            break;
            
        case ITEM_FOOD:
            fprintf( fp, "%d %d 0 %s 0\n",
                     pObjIndex->value[0],
                     pObjIndex->value[1],
                     fwrite_flag( pObjIndex->value[3], buf ) );
            break;
            
        case ITEM_PORTAL:
            fprintf( fp, "%d %s %s %d 0\n",
                     pObjIndex->value[0],
                     fwrite_flag( pObjIndex->value[1], buf ),
                     fwrite_flag( pObjIndex->value[2], buf ),
                     pObjIndex->value[3]);
            break;
            
        case ITEM_FURNITURE:
            fprintf( fp, "%d %d %s %d %d\n",
                     pObjIndex->value[0],
                     pObjIndex->value[1],
                     fwrite_flag( pObjIndex->value[2], buf),
                     pObjIndex->value[3],
                     pObjIndex->value[4]);
            break;
            
        case ITEM_WEAPON:
            fprintf( fp, "%s %d %d '%s' %s\n",
                     weapon_name(pObjIndex->value[0]),
                     pObjIndex->value[1],
                     pObjIndex->value[2],
                     attack_table[pObjIndex->value[3]].name,
                     fwrite_flag( pObjIndex->value[4], buf ) );
            break;

        case ITEM_ARMOR:
            fprintf( fp, "%d %d %d %d %d\n",
                     pObjIndex->value[0],
                     pObjIndex->value[1],
                     pObjIndex->value[2],
                     pObjIndex->value[3],
                     pObjIndex->value[4]);
            break;
            
        case ITEM_PILL:
        case ITEM_POTION:
        case ITEM_SCROLL:
	    fprintf( fp, "%d '%s' '%s' '%s' '%s'\n",
		     pObjIndex->value[0] > 0 ? /* no negative numbers */
		     pObjIndex->value[0]
		     : 0,
		     pObjIndex->value[1] > 0 ?
		     skill_table[pObjIndex->value[1]].name
		     : "",
		     pObjIndex->value[2] > 0 ?
		     skill_table[pObjIndex->value[2]].name
		     : "",
		     pObjIndex->value[3] > 0 ?
		     skill_table[pObjIndex->value[3]].name
		     : "",
		     pObjIndex->value[4] > 0 ?
		     skill_table[pObjIndex->value[4]].name
		     : "");
	    break;

        case ITEM_STAFF:
        case ITEM_WAND:
	    fprintf( fp, "%d ", pObjIndex->value[0] );
	    fprintf( fp, "%d ", pObjIndex->value[1] );
	    fprintf( fp, "%d '%s' 0\n",
		     pObjIndex->value[2],
		     pObjIndex->value[3] > 0 ?
		       skill_table[pObjIndex->value[3]].name
		       : "" );
	    break;
    }

    fprintf( fp, "%d ", pObjIndex->level );
    fprintf( fp, "%d ", pObjIndex->weight );
    fprintf( fp, "%d ", pObjIndex->cost );

         if ( pObjIndex->condition >  90 ) letter = 'P';
    else if ( pObjIndex->condition >  75 ) letter = 'G';
    else if ( pObjIndex->condition >  50 ) letter = 'A';
    else if ( pObjIndex->condition >  25 ) letter = 'W';
    else if ( pObjIndex->condition >  10 ) letter = 'D';
    else if ( pObjIndex->condition >   0 ) letter = 'B';
    else                                   letter = 'R';

    fprintf( fp, "%c\n", letter );

    for( pAf = pObjIndex->affected; pAf; pAf = pAf->next )
    {
	if (pAf->where == TO_OBJECT || pAf->bitvector == 0)
	        fprintf( fp, "A\n%d %d\n",  pAf->location, pAf->modifier );
	else
	{
		fprintf( fp, "F\n" );

		switch(pAf->where)
		{
			case TO_AFFECTS:
				fprintf( fp, "A " );
				break;
			case TO_IMMUNE:
				fprintf( fp, "I " );
				break;
			case TO_RESIST:
				fprintf( fp, "R " );
				break;
			case TO_VULN:
				fprintf( fp, "V " );
				break;
			default:
				bug( "olc_save: Invalid Affect->where", 0);
				break;
		}

		fprintf( fp, "%d %d %s\n", pAf->location, pAf->modifier,
				fwrite_flag( pAf->bitvector, buf ) );
	}
    }

    for( pEd = pObjIndex->extra_descr; pEd; pEd = pEd->next )
    {
        fprintf( fp, "E\n%s~\n%s~\n", pEd->keyword,
		 fix_string( pEd->description ) );
    }

    return;
}
예제 #21
0
파일: olc_save.c 프로젝트: verias/SRMud
/*****************************************************************************
 Name:		save_mobile
 Purpose:	Save one mobile to file, new format -- Hugin
 Called by:	save_mobiles (below).
 ****************************************************************************/
void save_mobile( FILE *fp, MOB_INDEX_DATA *pMobIndex )
{
    sh_int race = pMobIndex->race;
    long temp;
    char buf[MAX_STRING_LENGTH];
    MPROG_LIST *pMprog;

    fprintf( fp, "#%d\n",         pMobIndex->vnum );
    fprintf( fp, "%s~\n",         pMobIndex->player_name );
    fprintf( fp, "%s~\n",         pMobIndex->short_descr );
    fprintf( fp, "%s~\n",         fix_string( pMobIndex->long_descr ) );
    fprintf( fp, "%s~\n",         fix_string( pMobIndex->description) );
    fprintf( fp, "%s~\n",	race_table[race].name );

    temp = DIF( pMobIndex->act, race_table[race].act );
    fprintf( fp, "%s ",	          fwrite_flag( temp,	buf ) );

    temp = DIF( pMobIndex->affected_by, race_table[race].aff );
    fprintf( fp, "%s ",	          fwrite_flag( temp,	buf ) );

    fprintf( fp, "%d %d\n",	  pMobIndex->alignment , pMobIndex->group);
    fprintf( fp, "%d ",	          pMobIndex->level );
    fprintf( fp, "%d ",	          pMobIndex->hitroll );
    fprintf( fp, "%dd%d+%d ",     pMobIndex->hit[DICE_NUMBER], 
	     	     	          pMobIndex->hit[DICE_TYPE], 
	     	     	          pMobIndex->hit[DICE_BONUS] );
    fprintf( fp, "%dd%d+%d ",     pMobIndex->mana[DICE_NUMBER], 
	     	     	          pMobIndex->mana[DICE_TYPE], 
	     	     	          pMobIndex->mana[DICE_BONUS] );
    fprintf( fp, "%dd%d+%d ",     pMobIndex->damage[DICE_NUMBER], 
	     	     	          pMobIndex->damage[DICE_TYPE], 
	     	     	          pMobIndex->damage[DICE_BONUS] );
    fprintf( fp, "%s\n",          attack_table[pMobIndex->dam_type].name );
    fprintf( fp, "%d %d %d %d\n", pMobIndex->ac[AC_PIERCE] / 10, 
	     	     	          pMobIndex->ac[AC_BASH]   / 10, 
	     	     	          pMobIndex->ac[AC_SLASH]  / 10, 
	     	     	          pMobIndex->ac[AC_EXOTIC] / 10 );

    temp = DIF( pMobIndex->off_flags, race_table[race].off );
    fprintf( fp, "%s ",           fwrite_flag( temp,	buf ) );

    temp = DIF( pMobIndex->imm_flags, race_table[race].imm );
    fprintf( fp, "%s ",	          fwrite_flag( temp,	buf ) );

    temp = DIF( pMobIndex->res_flags, race_table[race].res );
    fprintf( fp, "%s ",           fwrite_flag( temp,	buf ) );

    temp = DIF( pMobIndex->vuln_flags, race_table[race].vuln );
    fprintf( fp, "%s\n",          fwrite_flag( temp,	buf ) );

    fprintf( fp, "%s %s %s %ld\n",
	                          position_table[pMobIndex->start_pos].short_name,
	         	     	  position_table[pMobIndex->default_pos].short_name,
	         	     	  sex_table[pMobIndex->sex].name,
	         	     	  pMobIndex->wealth );

    temp = DIF( pMobIndex->form,	race_table[race].form );
    fprintf( fp, "%s ",           fwrite_flag( temp,	buf ) );

    temp = DIF( pMobIndex->parts,	race_table[race].parts );
    fprintf( fp, "%s ",      	  fwrite_flag( temp,	buf ) );

    fprintf( fp, "%s ",           size_table[pMobIndex->size].name );
    fprintf( fp, "'%s'\n",	((pMobIndex->material[0] != '\0') ? pMobIndex->material : "unknown") );

    if ((temp = DIF(race_table[race].act,pMobIndex->act)))
     	fprintf( fp, "F act %s\n", fwrite_flag(temp, buf) );

    if ((temp = DIF(race_table[race].aff,pMobIndex->affected_by)))
     	fprintf( fp, "F aff %s\n", fwrite_flag(temp, buf) );

    if ((temp = DIF(race_table[race].off,pMobIndex->off_flags)))
     	fprintf( fp, "F off %s\n", fwrite_flag(temp, buf) );

    if ((temp = DIF(race_table[race].imm,pMobIndex->imm_flags)))
     	fprintf( fp, "F imm %s\n", fwrite_flag(temp, buf) );

    if ((temp = DIF(race_table[race].res,pMobIndex->res_flags)))
     	fprintf( fp, "F res %s\n", fwrite_flag(temp, buf) );
	
    if ((temp = DIF(race_table[race].vuln,pMobIndex->vuln_flags)))
     	fprintf( fp, "F vul %s\n", fwrite_flag(temp, buf) );
	
    if ((temp = DIF(race_table[race].form,pMobIndex->form)))
     	fprintf( fp, "F for %s\n", fwrite_flag(temp, buf) );

    if ((temp = DIF(race_table[race].parts,pMobIndex->parts)))
    	fprintf( fp, "F par %s\n", fwrite_flag(temp, buf) );

    for (pMprog=pMobIndex->mprogs;pMprog;pMprog=pMprog->next)
    {
        fprintf(fp, "M '%s' %d %s~\n",
        mprog_type_to_name(pMprog->trig_type), pMprog->vnum,
                pMprog->trig_phrase);
    }

    return;
}
예제 #22
0
/*****************************************************************************
 Name:		save_objects
 Purpose:	Save #OBJECTS section of an area file.
 Called by:	save_area(olc_save.c).
 ****************************************************************************/
void save_objects( FILE *fp, AREA_DATA *pArea )
{
    int vnum;
    OBJ_INDEX_DATA *pObjIndex;
    AFFECT_DATA *pAf;
    EXTRA_DESCR_DATA *pEd;

    fprintf( fp, "#OBJECTS\n" );
    for( vnum = pArea->lvnum; vnum <= pArea->uvnum; vnum++ )
    {
        if( ( pObjIndex = get_obj_index(vnum) ) )
        {
            if ( pObjIndex->area == pArea )
            {
                fprintf( fp, "#%d\n",    pObjIndex->vnum );
                fprintf( fp, "%s~\n",    pObjIndex->name );
                fprintf( fp, "%s~\n",    pObjIndex->short_descr );
                fprintf( fp, "%s~\n",    fix_string( pObjIndex->description ) );
                fprintf( fp, "~\n" );
                fprintf( fp, "%d ",      pObjIndex->item_type );
                fprintf( fp, "%d ",      pObjIndex->extra_flags );
                fprintf( fp, "%d\n",     pObjIndex->wear_flags);
                fprintf( fp, "%d %d %d\n",
                    pObjIndex->extra_flags2,
                    pObjIndex->weapflags,
                    pObjIndex->quest );

                switch ( pObjIndex->item_type )
                {
                    default:
                        fprintf( fp, "%d %d %d %d\n",
                            pObjIndex->value[0],
                            pObjIndex->value[1],
                            pObjIndex->value[2],
                            pObjIndex->value[3] );
                        break;
                    case ITEM_PILL:
                    case ITEM_POTION:
                    case ITEM_SCROLL:
                        fprintf( fp, "%d '%s' '%s' '%s'\n",
                            pObjIndex->value[0],
                            pObjIndex->value[1] != -1 ?
                            skill_table[pObjIndex->value[1]].name
                            : " ",
                            pObjIndex->value[2] != -1 ?
                            skill_table[pObjIndex->value[2]].name
                            : " ",
                            pObjIndex->value[3] != -1 ?
                            skill_table[pObjIndex->value[3]].name
                            : " " );
                        break;

                    case ITEM_STAFF:
                    case ITEM_WAND:
                        fprintf( fp, "%d %d %d '%s'\n",
                            pObjIndex->value[0],
                            pObjIndex->value[1],
                            pObjIndex->value[2],
                            pObjIndex->value[3] != -1 ?
                            skill_table[pObjIndex->value[3]].name
                            : " " );
                        break;
                }
                fprintf( fp, "%d ", pObjIndex->weight );
                fprintf( fp, "%d 0\n", pObjIndex->cost );

                for( pAf = pObjIndex->affected; pAf; pAf = pAf->next )
                {
                    fprintf( fp, "A\n%d %d\n",  pAf->location, pAf->modifier );
                }

                for( pEd = pObjIndex->extra_descr; pEd; pEd = pEd->next )
                {
                    fprintf( fp, "E\n%s~\n%s~\n", pEd->keyword,
                        fix_string( pEd->description ) );
                }
                fprintf( fp, "Q\n%s~\n%s~\n%s~\n%s~\n%s~\n%s~\n%d %d\n",
                    pObjIndex->chpoweron, pObjIndex->chpoweroff,
                    pObjIndex->chpoweruse, pObjIndex->victpoweron,
                    pObjIndex->victpoweroff, pObjIndex->victpoweruse,
                    pObjIndex->spectype, pObjIndex->specpower);
            }
        }
    }
    fprintf( fp, "#0\n\n\n\n" );
    return;
}
예제 #23
0
void ConsoleUI::add_scientist()
{
    Scientist s = Scientist();
    string firstname_, lastname_, gender_, birth_, death_;
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Name of Scientist: [FirstName LastName]" << endl;
    cout << endl << " -> ";
    cin >> firstname_ >> lastname_;
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Gender of scientist: \n(1) male \n(2) female" << endl;
    cout << endl << " -> ";
    cin >> gender_;
    while ((gender_ != "1") && (gender_ != "2"))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;

        cout << "Invalid input! Please try again:" << endl;
        cout << "Gender of scientist: \n(1) male \n(2) female" << endl;
        cout << endl << " -> ";
        cin >> gender_;
    }
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Birth year of scientist:" << endl;
    cout << endl << " -> ";
    cin >> birth_;
    while (!is_digits(birth_))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;

        cout << "Invalid input! Please try again:" << endl;
        cout << "Birth year of scientist:" << endl;
        cout << endl << " -> ";
        cin >> birth_;
    }
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Scientist's Year of death: " << endl;
    cout << endl << " -> ";
    cin >> death_;
    while (!is_digits(death_) || (atoi(death_.c_str()) < atoi(birth_.c_str())))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;

        if (!is_digits(death_))
        {
            cout << "Invalid input! Please try again:" << endl;
        }
        else if (atoi(death_.c_str()) < atoi(birth_.c_str()))
        {
            cout << "Year of death should be AFTER year of birth! Please ry again:" << endl;
        }
        cout << "Scientist's Year of death:" << endl;
        cout << endl << " -> ";
        cin >> death_;
    }
    if (gender_ == "1")
    {
        s.set_gender("Male");
    }
    else if (gender_ == "2")
    {
        s.set_gender("Female");
    }
    fix_string(firstname_);
    fix_string(lastname_);
    s.set_firstname(firstname_);
    s.set_lastname(lastname_);
    s.set_birth(birth_);
    s.set_death(death_);
    dbService.addS(s);
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "\t\t     " << "Scientist has been added to the list!\n\n\n\n\n\n\n" << endl;
}
예제 #24
0
bool bool_from_string(const std::string &s)
{
    const std::string ss=fix_string(s);
    return ss=="yes" || ss=="1" || ss=="true";
}
예제 #25
0
int cg_xaxis (float xsiz, float xmin, float xmax, float os, float xtix, int numsep)
{
    float x,xrang;
    int numdist, tt=0, tb=0, sigdec;
    char line[32];

    /* SET TO DEFAULT IF VALUE IS BEYOND RANGE */
    if ((numsep<1) || (numsep > 100)) numsep = 5;

    /* SET EVERYTHING UP */
    os=os*cgSCALE;
    cglogx= FALSE;
    realxmax=xsiz;
    cgxma= xmax +.001*(xmax-xmin);
    cgxmi= xmin;
    cgxticks=xtix;
    xsiz=xsiz*cgSCALE;
    xrang= cgxma-cgxmi;
    cgxscale= xsiz/xrang;
    numdist= (cglinnumdist)*(cgfsizex/10.0)+1;

    fprintf(cgstream,"\n\n%% X axis (linear).\n");
    fprintf(cgstream,"/xs {%g cvr mul} def\n",cgxscale);
    fprintf(cgstream,"/xtix {%g cvr} def\n",xtix);
    fprintf(cgstream,"/xsize {%g cvr} def\n",xsiz);
    fprintf(cgstream,"/xrange {%g cvr} def\n",xrang);
    fprintf(cgstream,"/xos {%g cvr sub} def\n\n",cgxmi);

    /* CREATE THE AXIS AND TICKS*/
    if(cgAxisEnable) {
        if ((cglintnposition == 3) || (cglintnposition == 4))
            tb= 0;
        else tb= -cglinticlen;
        if ((cglintnposition == 1) || (cglintnposition == 6))
            tt= 0;
        else tt = cglinticlen;
        fprintf(cgstream,"/x 0 def\n");
        fprintf(cgstream,"0 %g mto\n%g 0 rlto\nstroke\n",os,xsiz);
        fprintf(cgstream,"x 0 xtix xrange {xs dup %g mto\n",os+tt);
        fprintf(cgstream,"\t%g lto\n",os+tb);
        fprintf(cgstream,"\tstroke xtix x add} for\n");
    }

    if(cgAxisNumberEnable) {
        sigdec= 0;
        /* Determine The Maximum Significant Decimal Place*/
        sigdec=findsigdec(cgxmi,xrang*1.01,numsep,cgxticks);

        /*NOW FOR THE REAL NUMBER PLACEMENT LOOP*/
        for (x=cglinnumoff*cgxticks; x<= xrang*1.01; x+= numsep*xtix)
        {
            formaxnum(x+cgxmi,sigdec,line);
            fprintf(cgstream,"\nnewpath 1000 1000 mto\n");
            fprintf(cgstream,"(%s) stw pop 2 div\n",line);
            fprintf(cgstream,"%g cvr exch sub ", x*cgxscale);
            if ((cglintnposition > 0) && (cglintnposition < 4)) 	/* Numbers BELOW Axis */
                fprintf(cgstream,"%g charheight sub ",os+tb-numdist);

            else 					/* Numbers ABOVE Axis */
                fprintf(cgstream,"%g ",os+tt+numdist);

            fprintf(cgstream,"mto (%s) show\n", fix_string(line,1));
        }
    }

    leastY=os+tb-numdist-(1.4)*cgfontnum;
    fprintf(cgstream,"\n/xs {%g cvr sub %g cvr mul} def\n", cgxmi, cgxscale);
    fprintf(cgstream,"%% END X axis (linear).\n");
    return(0);
}
예제 #26
0
/*****************************************************************************
 Name:		save_rooms
 Purpose:	Save #ROOMS section of an area file.
 Called by:	save_area(olc_save.c).
 ****************************************************************************/
void save_rooms( FILE *fp, AREA_DATA *pArea )
{
	ROOM_INDEX_DATA *pRoomIndex;
	EXTRA_DESCR_DATA *pEd;
	EXIT_DATA *pExit;
	int iHash;
	int door;

	fprintf( fp, "#ROOMS\n" );
	for( iHash = 0; iHash < MAX_KEY_HASH; iHash++ )
	{
		for( pRoomIndex = room_index_hash[iHash]; pRoomIndex; pRoomIndex = pRoomIndex->next )
		{
			if ( pRoomIndex->area == pArea )
			{
				fprintf( fp, "#%d\n",		pRoomIndex->vnum );
				fprintf( fp, "%s~\n",		pRoomIndex->name );
				fprintf( fp, "%s~\n",		fix_string( pRoomIndex->description ) );
		fprintf( fp, "0 " );
				fprintf( fp, "%d ",		pRoomIndex->room_flags );
				fprintf( fp, "%d\n",		pRoomIndex->sector_type );

				for ( pEd = pRoomIndex->extra_descr; pEd;
					  pEd = pEd->next )
				{
					fprintf( fp, "E\n%s~\n%s~\n", pEd->keyword,
												  fix_string( pEd->description ) );
				}
				for( door = 0; door < MAX_DIR; door++ )	/* I hate this! */
				{
					if ( ( pExit = pRoomIndex->exit[door] )
						  && pExit->u1.to_room )
					{
			int locks = 0;

			/* HACK : TO PREVENT EX_LOCKED etc without EX_ISDOOR
			   to stop booting the mud */
			if ( IS_SET(pExit->rs_flags, EX_CLOSED)
			||   IS_SET(pExit->rs_flags, EX_LOCKED)
			||   IS_SET(pExit->rs_flags, EX_PICKPROOF)
			||   IS_SET(pExit->rs_flags, EX_NOPASS)
			||   IS_SET(pExit->rs_flags, EX_EASY)
			||   IS_SET(pExit->rs_flags, EX_HARD)
			||   IS_SET(pExit->rs_flags, EX_INFURIATING)
			||   IS_SET(pExit->rs_flags, EX_NOCLOSE)
			||   IS_SET(pExit->rs_flags, EX_NOLOCK) )
				SET_BIT(pExit->rs_flags, EX_ISDOOR);
			else
				REMOVE_BIT(pExit->rs_flags, EX_ISDOOR);

			/* THIS SUCKS but it's backwards compatible */
			/* NOTE THAT EX_NOCLOSE NOLOCK etc aren't being saved */
			if ( IS_SET( pExit->rs_flags, EX_ISDOOR ) 
			&& ( !IS_SET( pExit->rs_flags, EX_PICKPROOF ) ) 
				&& ( !IS_SET( pExit->rs_flags, EX_NOPASS ) ) )
				locks = 1;
			if ( IS_SET( pExit->rs_flags, EX_ISDOOR )
			&& ( IS_SET( pExit->rs_flags, EX_PICKPROOF ) )
				&& ( !IS_SET( pExit->rs_flags, EX_NOPASS ) ) )
				locks = 2;
			if ( IS_SET( pExit->rs_flags, EX_ISDOOR )
			&& ( !IS_SET( pExit->rs_flags, EX_PICKPROOF ) )
				&& ( IS_SET( pExit->rs_flags, EX_NOPASS ) ) )
				locks = 3;
			if ( IS_SET( pExit->rs_flags, EX_ISDOOR )
			&& ( IS_SET( pExit->rs_flags, EX_PICKPROOF ) )
				&& ( IS_SET( pExit->rs_flags, EX_NOPASS ) ) )
				locks = 4;

						fprintf( fp, "D%d\n",      pExit->orig_door );
						fprintf( fp, "%s~\n",      fix_string( pExit->description ) );
						fprintf( fp, "%s~\n",      pExit->keyword );
						fprintf( fp, "%d %d %d\n", locks,
												   pExit->key,
												   pExit->u1.to_room->vnum );
					}
				}
		if (pRoomIndex->mana_rate != 100 || pRoomIndex->heal_rate != 100)
		 fprintf ( fp, "M %d H %d\n",pRoomIndex->mana_rate,
									 pRoomIndex->heal_rate);
		if (pRoomIndex->clan > 0)
		 fprintf ( fp, "C %s~\n" , clan_table[pRoomIndex->clan].name );
						 
		if (!IS_NULLSTR(pRoomIndex->owner))
		 fprintf ( fp, "O %s~\n" , pRoomIndex->owner );

		fprintf( fp, "S\n" );
			}
		}
	}
	fprintf( fp, "#0\n\n\n\n" );
	return;
}