Annotation of 43BSDTahoe/games/phantasia/convert.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *     Convert Phantasia 3.3.1 and 3.3.1+ characs file format to 3.3.2
        !             3:  *
        !             4:  */
        !             5: 
        !             6: #include "include.h"
        !             7: #include "oldplayer.h"
        !             8: 
        !             9: struct oldplayer       Oldplayer;              /* old format structure */
        !            10: struct player  Newplayer;                      /* new format structure */
        !            11: 
        !            12: char   Oldpfile[] = DEST/characs";             /* old format file */
        !            13: char   Newpfile[] = DEST/newcharacs";          /* new format file */
        !            14: 
        !            15: /************************************************************************
        !            16: /
        !            17: / FUNCTION NAME: main()
        !            18: /
        !            19: / FUNCTION: convert old Phantasia player file to new format
        !            20: /
        !            21: / AUTHOR: C. Robertson, 9/1/85  E. A. Estes, 3/12/86
        !            22: /
        !            23: / ARGUMENTS: none
        !            24: /
        !            25: / RETURN VALUE: none
        !            26: /
        !            27: / MODULES CALLED: time(), exit(), fread(), fopen(), srandom(), floor(), 
        !            28: /      random(), strcmp(), fwrite(), strcpy(), fclose(), fprintf()
        !            29: /
        !            30: / GLOBAL INPUTS: _iob[], Oldplayer, Newplayer
        !            31: /
        !            32: / GLOBAL OUTPUTS: Oldplayer, Newplayer
        !            33: /
        !            34: / DESCRIPTION:
        !            35: /      Read in old player structures and write out to new file in
        !            36: /      new format.
        !            37: /      Old player file is unmodified.
        !            38: /      New file is "DEST/newcharacs".
        !            39: /      #define PHANTPLUS to convert from 3.3.1+.
        !            40: /
        !            41: /************************************************************************/
        !            42: 
        !            43: main()
        !            44: {
        !            45: FILE   *oldcharac, *newcharac;         /* to open old and new files */
        !            46: 
        !            47:     if ((oldcharac = fopen(Oldpfile, "r")) == NULL)
        !            48:        {
        !            49:        fprintf(stderr, "Cannot open original character file!\n");
        !            50:        exit(1);
        !            51:        }
        !            52: 
        !            53:     if ((newcharac = fopen(Newpfile, "w")) == NULL)
        !            54:        {
        !            55:        fprintf(stderr, "Cannot create new character file!\n");
        !            56:        exit(1);
        !            57:        }
        !            58: 
        !            59:     srandom((unsigned) time((long *) NULL));   /* prime random numbers */
        !            60: 
        !            61:     while (fread((char *) &Oldplayer, sizeof(struct oldplayer), 1, oldcharac) == 1)
        !            62:        /* read and convert old structures into new */
        !            63:        {
        !            64:        Newplayer.p_experience = Oldplayer.o_experience;
        !            65:        Newplayer.p_level = (double) Oldplayer.o_level;
        !            66:        Newplayer.p_strength =  Oldplayer.o_strength;
        !            67:        Newplayer.p_sword =  Oldplayer.o_sword;
        !            68:        Newplayer.p_might =  0.0;               /* game will calculate */
        !            69:        Newplayer.p_energy =  Oldplayer.o_energy;
        !            70:        Newplayer.p_maxenergy =  Oldplayer.o_maxenergy;
        !            71:        Newplayer.p_shield =  Oldplayer.o_shield;
        !            72:        Newplayer.p_quickness = (double) Oldplayer.o_quickness;
        !            73:        Newplayer.p_quksilver = (double) Oldplayer.o_quksilver;
        !            74:        Newplayer.p_speed = 0.0;                /* game will calculate */
        !            75:        Newplayer.p_magiclvl = Oldplayer.o_magiclvl;
        !            76:        Newplayer.p_mana = Oldplayer.o_mana;
        !            77:        Newplayer.p_brains = Oldplayer.o_brains;
        !            78:        Newplayer.p_poison = Oldplayer.o_poison;
        !            79:        Newplayer.p_gold = Oldplayer.o_gold;
        !            80:        Newplayer.p_gems = Oldplayer.o_gems;
        !            81:        Newplayer.p_sin = Oldplayer.o_sin;
        !            82:        Newplayer.p_x = Oldplayer.o_x;
        !            83:        Newplayer.p_y = Oldplayer.o_y;
        !            84:        Newplayer.p_1scratch = Oldplayer.o_1scratch;
        !            85:        Newplayer.p_2scratch = Oldplayer.o_2scratch;
        !            86: 
        !            87:        Newplayer.p_ring.ring_type = Oldplayer.o_ring.ring_type;
        !            88:        Newplayer.p_ring.ring_duration = Oldplayer.o_ring.ring_duration;
        !            89:        Newplayer.p_ring.ring_inuse = FALSE;
        !            90: 
        !            91:        Newplayer.p_age = (long) Oldplayer.o_degenerated * N_AGE;
        !            92: 
        !            93:        Newplayer.p_degenerated = Oldplayer.o_degenerated + 1;
        !            94: 
        !            95:        /* convert character type into character type and special type */
        !            96: 
        !            97:        if (Oldplayer.o_type < 0)
        !            98:            /* player with crown */
        !            99:            Oldplayer.o_type = -Oldplayer.o_type;
        !           100: 
        !           101:        if (Oldplayer.o_type == 99)
        !           102:            /* valar */
        !           103:            {
        !           104:            Newplayer.p_specialtype = SC_VALAR;
        !           105:            Newplayer.p_type = (short) ROLL(C_MAGIC, C_EXPER - C_MAGIC + 1);
        !           106:            Newplayer.p_lives = Oldplayer.o_ring.ring_duration;
        !           107:            }
        !           108:        else if (Oldplayer.o_type == 90)
        !           109:            /* ex-valar */
        !           110:            {
        !           111:            Newplayer.p_specialtype = SC_EXVALAR;
        !           112:            Newplayer.p_type = (short) ROLL(C_MAGIC, C_EXPER - C_MAGIC + 1);
        !           113:            Newplayer.p_lives = 0;
        !           114:            }
        !           115:        else if (Oldplayer.o_type > 20)
        !           116:            /* council of wise */
        !           117:            {
        !           118:            Newplayer.p_specialtype = SC_COUNCIL;
        !           119:            Newplayer.p_type = Oldplayer.o_type - 20;
        !           120:            Newplayer.p_lives = Oldplayer.o_ring.ring_duration;
        !           121:            }
        !           122:        else if (Oldplayer.o_type > 10)
        !           123:            /* king */
        !           124:            {
        !           125:            Newplayer.p_specialtype = SC_KING;
        !           126:            Newplayer.p_type = Oldplayer.o_type - 10;
        !           127:            Newplayer.p_lives = 0;
        !           128:            }
        !           129:        else
        !           130:            /* normal player */
        !           131:            {
        !           132:            Newplayer.p_specialtype = SC_NONE;
        !           133:            Newplayer.p_type = Oldplayer.o_type;
        !           134:            Newplayer.p_lives = 0;
        !           135:            }
        !           136: 
        !           137:        Newplayer.p_lives = 0;
        !           138:        Newplayer.p_crowns = Oldplayer.o_crowns;
        !           139:        Newplayer.p_charms = Oldplayer.o_charms;
        !           140:        Newplayer.p_amulets = Oldplayer.o_amulets;
        !           141:        Newplayer.p_holywater = Oldplayer.o_holywater;
        !           142:        Newplayer.p_lastused = Oldplayer.o_lastused;
        !           143: 
        !           144:        /* convert status and name into status */
        !           145: 
        !           146:        Newplayer.p_status = Oldplayer.o_status + S_OFF;
        !           147:        if (strcmp(Oldplayer.m_name, "<null>") == 0)
        !           148:            /* unused recored */
        !           149:            Newplayer.p_status = S_NOTUSED;
        !           150:        if (Oldplayer.o_quickness < 0)
        !           151:            /* hung up player */
        !           152:            {
        !           153:            Newplayer.p_quickness = (double) Oldplayer.o_tampered;
        !           154:            Oldplayer.o_tampered = T_OFF;
        !           155:            Newplayer.p_status = S_HUNGUP;
        !           156:            }
        !           157: 
        !           158:        Newplayer.p_tampered = Oldplayer.o_tampered + T_OFF;
        !           159:        Newplayer.p_istat = I_OFF;
        !           160: 
        !           161:        Newplayer.p_palantir = Oldplayer.o_palantir;
        !           162:        Newplayer.p_blessing = Oldplayer.o_blessing;
        !           163:        Newplayer.p_virgin = Oldplayer.o_virgin;
        !           164:        Newplayer.p_blindness = Oldplayer.o_blindness;
        !           165: 
        !           166:        strcpy(Newplayer.p_name, Oldplayer.o_name);
        !           167:        strcpy(Newplayer.p_password, Oldplayer.o_password);
        !           168:        strcpy(Newplayer.p_login, Oldplayer.o_login);
        !           169: 
        !           170:        /* write new structure */
        !           171:        fwrite((char *) &Newplayer, sizeof(Newplayer), 1, newcharac);
        !           172:        }
        !           173: 
        !           174:     fclose(oldcharac);         /* close files */
        !           175:     fclose(newcharac);
        !           176: 
        !           177:     exit(0);
        !           178: }
        !           179: /**/
        !           180: /************************************************************************
        !           181: /
        !           182: / FUNCTION NAME: drandom()
        !           183: /
        !           184: / FUNCTION: return a random number between 0.0 < 1.0
        !           185: /
        !           186: / AUTHOR: E. A. Estes, 2/7/86
        !           187: /
        !           188: / ARGUMENTS: none
        !           189: /
        !           190: / RETURN VALUE: random number
        !           191: /
        !           192: / MODULES CALLED: random()
        !           193: /
        !           194: / GLOBAL INPUTS: none
        !           195: /
        !           196: / GLOBAL OUTPUTS: none
        !           197: /
        !           198: / DESCRIPTION:
        !           199: /      Return a random number.
        !           200: /
        !           201: /************************************************************************/
        !           202: 
        !           203: double
        !           204: drandom()
        !           205: {
        !           206:     if (sizeof(int) != 2)
        !           207:        return((double) (random() & 0x7fff) / 32768.0);
        !           208:     else
        !           209:        return((double) random() / 32768.0);
        !           210: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.