home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / d / d-linux.zip / dm-dist / update.c < prev    next >
C/C++ Source or Header  |  1991-03-01  |  4KB  |  176 lines

  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4. #include "structs.h"
  5.  
  6. #define bytemask 0xFF
  7.  
  8.  
  9. struct old_char_point_data
  10. {
  11.   sh_int mana;
  12.   sh_int max_mana;     /* Not useable may be erased upon player file renewal */
  13.   sh_int hit;
  14.   sh_int max_hit;      /* Max hit for NPC                         */
  15.   sh_int move;
  16.   sh_int max_move;     /* Max move for NPC                        */
  17.  
  18.   byte armor;          /* Internal -100..100, external -10..10 AC */
  19.   int gold;            /* Money carried                           */
  20.   int exp;             /* The experience of the player            */
  21.  
  22.   sbyte hitroll;       /* Any bonus or penalty to the hit roll    */
  23.   sbyte damroll;       /* Any bonus or penalty to the damage roll */
  24. };
  25.  
  26.  
  27.  
  28. struct char_file_old_u
  29. {
  30.   byte sex;
  31.   byte class;
  32.   byte level;
  33.   time_t birth;  /* Time of birth of character     */
  34.   int played;    /* Number of secs played in total */
  35.  
  36.   ubyte weight;
  37.   ubyte height;
  38.  
  39.   char title[80];
  40.   sh_int hometown;
  41.   char description[240];
  42.   bool talks[MAX_TOUNGE];
  43.  
  44.   sh_int load_room;            /* Which room to place char in           */
  45.  
  46.   struct char_ability_data abilities;
  47.  
  48.   struct old_char_point_data points;
  49.  
  50.   struct char_skill_data skills[MAX_SKILLS];
  51.  
  52.   struct affected_type affected[MAX_AFFECT];
  53.  
  54.   /* specials */
  55.  
  56.   byte spells_to_learn;
  57.   int alignment;
  58.  
  59.   time_t last_logon;  /* Time (in secs) of last logon */
  60.   ubyte act;          /* ACT Flags                    */
  61.  
  62.   /* char data */
  63.   char name[20];
  64.   char pwd[11];
  65.   sh_int apply_saving_throw[5];
  66.   int conditions[3];
  67. };
  68.  
  69.  
  70. void do_it(FILE *src, FILE *trg);
  71.  
  72. main(int argc, char **argv)
  73. {
  74.     FILE *src, *trg;
  75.  
  76.     if (argc != 3) {
  77.         fprintf(stderr, "Usage: %s source target\n", argv[0]);
  78.         exit (0);
  79.     } else if (!(src = fopen(argv[1], "rb")))
  80.         fprintf(stderr, "%s: Could not open.\n", argv[1]);
  81.     else if (!(trg = fopen(argv[2], "wb")))
  82.         fprintf(stderr, "%s: Could not open.\n", argv[2]);
  83.     else
  84.         do_it(src, trg);
  85.  
  86.     fclose(src);
  87.     fclose(trg);
  88.  
  89. }
  90.  
  91.  
  92. void do_it(FILE *src, FILE *trg)
  93. {
  94.     struct char_file_u buf;
  95.     struct char_file_old_u oldbuf;
  96.     int a,b,c,d, n;
  97.  
  98.     srand((int) time(0));
  99.  
  100.     n=1;
  101.  
  102.     for (;;)
  103.     {
  104.         fread(&oldbuf, sizeof(oldbuf), 1, src);
  105.         if (feof(src))
  106.             break;
  107.         /* do something */
  108.  
  109.         buf.sex = oldbuf.sex;
  110.         buf.class = oldbuf.class;
  111.         buf.level = oldbuf.level;
  112.         buf.birth = oldbuf.birth;      /* Time of birth of character     */
  113.     buf.played = oldbuf.played;    /* Number of secs played in total */
  114.  
  115.         buf.weight = oldbuf.weight;
  116.         buf.height = oldbuf.height;
  117.  
  118.         strcpy(buf.title, oldbuf.title);
  119.         buf.hometown = oldbuf.hometown;
  120.         strcpy(buf.description, oldbuf.description);
  121.         buf.talks[0] = oldbuf.talks[0];
  122.         buf.talks[1] = oldbuf.talks[1];
  123.         buf.talks[2] = oldbuf.talks[2];
  124.  
  125.         buf.load_room = oldbuf.load_room;
  126.  
  127.         buf.abilities = oldbuf.abilities;
  128.  
  129.     buf.points.mana = oldbuf.points.mana;
  130.     buf.points.max_mana = oldbuf.points.max_mana;
  131.     buf.points.hit = oldbuf.points.hit;
  132.     buf.points.max_hit = oldbuf.points.max_hit;
  133.     buf.points.move = oldbuf.points.move;
  134.     buf.points.max_move = oldbuf.points.max_move;
  135.  
  136.     buf.points.armor = 100;
  137.     buf.points.gold = oldbuf.points.gold;
  138.     buf.points.exp = oldbuf.points.exp;
  139.  
  140.     buf.points.hitroll = 0;
  141.     buf.points.damroll = 0;
  142.  
  143.         for(n=0; n < MAX_SKILLS; n++)
  144.             buf.skills[n] = oldbuf.skills[n];
  145.  
  146.         for(n=0; n < MAX_AFFECT; n++)
  147.             buf.affected[n] = oldbuf.affected[n];
  148.  
  149.         buf.spells_to_learn = oldbuf.spells_to_learn;
  150.         buf.alignment = oldbuf.alignment;
  151.  
  152.         buf.last_logon = oldbuf.last_logon;
  153.         buf.act = oldbuf.act;
  154.  
  155.         strcpy(buf.name,oldbuf.name);
  156.         strcpy(buf.pwd, oldbuf.pwd);
  157.  
  158.         buf.apply_saving_throw[0] = oldbuf.apply_saving_throw[0];
  159.         buf.apply_saving_throw[1] = oldbuf.apply_saving_throw[1];
  160.         buf.apply_saving_throw[2] = oldbuf.apply_saving_throw[2];
  161.         buf.apply_saving_throw[3] = oldbuf.apply_saving_throw[3];
  162.         buf.apply_saving_throw[4] = oldbuf.apply_saving_throw[4];
  163.  
  164.         buf.conditions[0] = oldbuf.conditions[0];
  165.         buf.conditions[1] = oldbuf.conditions[1];
  166.         buf.conditions[2] = oldbuf.conditions[2];
  167.  
  168.         /* do something else */
  169.         fwrite(&buf, sizeof(buf), 1, trg);
  170.     }
  171.  
  172.     printf("Size of buf is %d\n\rSize of oldbuf is %d\n\r",
  173.       sizeof(buf),
  174.         sizeof(oldbuf));
  175. }
  176.