コード例 #1
0
ファイル: char.cpp プロジェクト: cwc/OmegaRPG
/* set player to begin with */
bool initplayer(void)
{
    int i;
    int oldchar=false;
    FILE *fd;
    char *lname;
    int ret_value = false;

    lname = getlogin();

#if !defined(WIN32)
    // Get the login name if getlogin() failed
    if (!lname || strlen(lname) == 0)
    {
        struct passwd *dastuff;

        dastuff = getpwuid(getuid());
        lname = dastuff->pw_name;
    }
#endif

    strcpy(Player.name,lname);
    if (Player.name[0] >= 'a' && Player.name[0] <= 'z')
        Player.name[0] += 'A'-'a'; /* capitalise 1st letter */
    Player.itemweight = 0;
    Player.food = 36;
    Player.packptr = 0;
    Behavior = -1;
    Player.options = 0;
    for (i=0; i<MAXITEMS; i++)
        Player.possessions[i] = NULL;
    for (i=0; i<MAXPACK; i++)
        Player.pack[i] = NULL;
    for (i=0; i<NUMIMMUNITIES; i++) Player.immunity[i] = 0;
    for (i=0; i<NUMSTATI; i++) Player.status[i] = 0;
    for (i=0; i<NUMRANKS; i++) {
        Player.rank[i] = 0;
        Player.guildxp[i] = 0;
    }
    Player.patron = 0;
    Player.alignment = 0;
    Player.cash = 250;
    change_to_user_perms();
    if ((fd=omegarc_check())!=NULL) {
        fread((char *)&i,sizeof(int),1,fd);
        if (i != VERSION) {
            print1("Out of date .omegarc! Make another!");
            morewait();
        }
        else {
            oldchar = true;
            fread((char *)&Player,sizeof(Player),1,fd);
            fread((char *)&Searchnum,sizeof(int),1,fd);
            fread((char *)&Verbosity,sizeof(char),1,fd);
            strcpy(Player.name,lname);
            if (Player.name[0] >= 'a' && Player.name[0] <= 'z')
                Player.name[0] += 'A'-'a'; /* capitalise 1st letter */
        }
        fclose(fd);
    }
    change_to_game_perms();

    // Zop: initstats() can load a save file, so this block needs to precede the function
    /* DAG - put the code back in the same place, rather than duplicating */
    Searchnum = max(1,min(9,Searchnum));
    Player.hp = Player.maxhp = Player.maxcon;
    Player.mana = Player.maxmana = calcmana();
    Player.click = 1;
    strcpy(Player.combatManeuvers,"CCBC");
    calc_melee();
    ScreenOffset = -1000;	/* to force a redraw */

    if (! oldchar) {
        optionset(RUNSTOP);
        optionset(CONFIRM);
        optionset(SHOW_COLOUR);
        ret_value = initstats() ; /* RM 04-19-2000:loading patch */ /* DAG */
    }

    return ret_value > 0; /* RM 04-19-2000: loading patch */ /* DAG */
}
コード例 #2
0
ファイル: char.c プロジェクト: DavidKinder/Omega
/* set player to begin with */
void initplayer()
{
  int i;
  int oldchar=FALSE;
  FILE *fd;
  char *lname;
#if !defined(MSDOS) && !defined(_WIN32)
  struct passwd *dastuff;
#endif

  lname = getlogin();
#if !defined(MSDOS) && !defined(_WIN32)
  if (!lname || strlen(lname) == 0)
  {
       dastuff = getpwuid(getuid());
       lname = dastuff->pw_name;
  }
#endif
  strcpy(Player.name,lname);
  if (Player.name[0] >= 'a' && Player.name[0] <= 'z')
       Player.name[0] += 'A'-'a'; /* capitalise 1st letter */
  Player.itemweight = 0;
  Player.food = 36; 
  Player.packptr = 0;
  Behavior = -1;
  Player.options = 0;
  for (i=0;i<MAXITEMS;i++)
    Player.possessions[i] = NULL;
  for (i=0;i<MAXPACK;i++)
    Player.pack[i] = NULL;
  for (i=0;i<NUMIMMUNITIES;i++) Player.immunity[i] = 0;
  for (i=0;i<NUMSTATI;i++) Player.status[i] = 0;
  for (i=0;i<NUMRANKS;i++) {
    Player.rank[i] = 0;
    Player.guildxp[i] = 0;
  }
  Player.patron = 0;
  Player.alignment = 0;
  Player.cash = 250;
  change_to_user_perms();
  if ((fd=omegarc_check())!=NULL) {
    fread((char *)&i,sizeof(int),1,fd);
    if (i != VERSION) {
#if defined(MSDOS) || defined(AMIGA) || defined(_WIN32)
      print1("Out of date omega.rc! Make another!");
#else
      print1("Out of date .omegarc! Make another!");
#endif
      morewait();
    }
    else {
      oldchar = TRUE;
      fread((char *)&Player,sizeof(Player),1,fd);
      fread((char *)&Searchnum,sizeof(int),1,fd);
      fread((char *)&Verbosity,sizeof(char),1,fd);
      strcpy(Player.name,lname);
      if (Player.name[0] >= 'a' && Player.name[0] <= 'z')
	   Player.name[0] += 'A'-'a'; /* capitalise 1st letter */
    }
    fclose(fd);
  }
  change_to_game_perms();
  if (! oldchar) {
    optionset(RUNSTOP);
    optionset(CONFIRM);
#ifdef COMPRESS_SAVE_FILES
    optionset(COMPRESS_OPTION);
#endif
#if defined(MSDOS) || defined(AMIGA) || defined(_WIN32)
    optionset(SHOW_COLOUR);
#endif
    initstats();
  }
  Searchnum = max(1,min(9,Searchnum));
  Player.hp = Player.maxhp = Player.maxcon;
  Player.mana = Player.maxmana = calcmana();
  Player.click = 1;
  strcpy(Player.meleestr,"CCBC");
  calc_melee();
  ScreenOffset = -1000;	/* to force a redraw */
}