home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / games / tinymud2.zip / SANITY-C.C < prev    next >
C/C++ Source or Header  |  1990-09-02  |  4KB  |  181 lines

  1. #include "copyright.h"
  2.  
  3. #include <stdio.h>
  4.  
  5. #include "db.h"
  6. #include "config.h"
  7.  
  8. # define HAS_ENTRANCES 0x40000000
  9.  
  10. void check_exits(dbref i)
  11. {
  12.     dbref exit;
  13.     int count;
  14.  
  15.     count = 10000;
  16.     for(exit = db[i].exits;
  17.     exit != NOTHING;
  18.     exit = db[exit].next) {
  19.     if(exit < 0 || exit >= db_top || Typeof(exit) != TYPE_EXIT) {
  20.         printf("%d has bad exit %d\n", i, exit);
  21.         break;
  22.     }
  23.  
  24.     /* set type of exit to be really strange */
  25.     db[exit].flags = 4;    /* nonexistent type */
  26.  
  27.     if(count-- < 0) {
  28.         printf("%d has looping exits\n");
  29.         break;
  30.     }
  31.     }
  32. }
  33.  
  34. void check_contents(dbref i)
  35. {
  36.     dbref thing;
  37.     dbref loc;
  38.     int count;
  39.  
  40.     count = 10000;
  41.     for(thing = db[i].contents;
  42.     thing != NOTHING;
  43.     thing = db[thing].next) {
  44.     if(thing < 0 || thing >= db_top || Typeof(thing) == TYPE_ROOM) {
  45.         printf("%d contains bad object %d\n", i, thing);
  46.         break;
  47.     } else if(Typeof(thing) == TYPE_EXIT) {
  48.         db[thing].flags = 4; /* nonexistent type */
  49.     } else if((loc = db[thing].location) != i) {
  50.         printf("%d in %d but location is %d\n", thing, i, loc);
  51.     }
  52.     if(count-- < 0) {
  53.         printf("%d has looping contents\n");
  54.         break;
  55.     }
  56.     }
  57. }
  58.  
  59. void check_location(dbref i)
  60. {
  61.     dbref loc;
  62.  
  63.     loc = db[i].location;
  64.     if(loc < 0 || loc >= db_top) {
  65.     printf("%d has bad loc %d\n", i, loc);
  66.     } else if(!member(i, db[loc].contents)) {
  67.     printf("%d not in loc %d\n", i, loc);
  68.     }
  69. }
  70.  
  71. void check_owner(dbref i)
  72. {
  73.     dbref owner;
  74.  
  75.     owner = db[i].owner;
  76.     if(owner < 0 || owner >= db_top || Typeof(owner) != TYPE_PLAYER) {
  77.     printf("Object %s(%d) has bad owner %d\n",
  78.            db[i].name, i, owner);
  79.     }
  80. }
  81.  
  82. void check_pennies(dbref i)
  83. {
  84.     dbref pennies;
  85.  
  86.     pennies = db[i].pennies;
  87.  
  88.     switch(Typeof(i)) {
  89.       case TYPE_ROOM:
  90.       case TYPE_EXIT:
  91.     break;
  92.       case TYPE_PLAYER:
  93.     if(pennies < 0 || pennies > MAX_PENNIES+100) {
  94.         printf("Player %s(%d) has %d pennies\n", db[i].name, i, pennies);
  95.     }
  96.     break;
  97.       case TYPE_THING:
  98.     if(pennies < 0 || pennies > MAX_OBJECT_ENDOWMENT) {
  99.         printf("Object %s(%d) endowed with %d pennies\n",
  100.            db[i].name, i, pennies);
  101.     }
  102.     break;
  103.     }
  104. }
  105.  
  106. void main(int argc, char **argv)
  107. {
  108.     dbref i;
  109.  
  110.     if(db_read(stdin) < 0) {
  111.     puts("Database load failed!");
  112.     exit(1);
  113.     } 
  114.  
  115.     puts("Done loading database");
  116.  
  117.     for(i = 0; i < db_top; i++) {
  118.     check_pennies(i);
  119.     check_owner(i);
  120.     switch(Typeof(i)) {
  121.       case TYPE_PLAYER:
  122.         check_contents(i);
  123.         check_location(i);
  124.         if(Wizard(i)) printf("Wizard: %s(%d)\n", db[i].name, i);
  125.         if(Dark(i)) printf("Dark: %s(%d)\n", db[i].name, i);
  126.         if(Robot(i)) printf("Robot: %s(%d)\n", db[i].name, i);
  127.         if(db[i].password == NULL)
  128.         { printf ("Null password: %s(%d)\n", db[i].name, i); }
  129.         break;
  130.       case TYPE_THING:
  131.         check_location(i);
  132.         break;
  133.       case TYPE_ROOM:
  134.         if(Robot(i)) printf("UnRobot: %s(%d)\n", db[i].name, i);
  135.         check_contents(i);
  136.         check_exits(i);
  137.         break;
  138.     }
  139.     }
  140.  
  141.     /* scan for unattached exits */
  142.     for(i = 0; i < db_top; i++) {
  143.     if(Typeof(i) == TYPE_EXIT) {
  144.         printf("Unattached exit %d\n", i);
  145.     }
  146.     }
  147.         
  148.     /* scan for unattached exits */
  149.     for(i = 0; i < db_top; i++) {
  150.     if(Typeof(i) == TYPE_EXIT) {
  151.         printf("Unattached exit %d\n", i);
  152.     }
  153.     }
  154.         
  155.     /*---- scan for unattached rooms ----*/
  156.     
  157.     /* Clear entry flags */
  158.     for(i = 0; i < db_top; i++) db[i].flags &= ~HAS_ENTRANCES;
  159.  
  160.     /* For each exit, set its destination entry bit */    
  161.     for(i = 0; i < db_top; i++) {
  162.     if(Typeof(i) == TYPE_EXIT || Typeof(i) == 4) {
  163.         if(db[i].location >= 0) db[db[i].location].flags |= HAS_ENTRANCES;
  164.     }
  165.     }
  166.  
  167.     /* Now print every room with no entrances */    
  168.     for(i = 0; i < db_top; i++) {
  169.     if(Typeof(i) == TYPE_ROOM && 
  170.        (db[i].flags & HAS_ENTRANCES) == 0) {
  171.         if (db[i].exits == NOTHING && db[i].contents == NOTHING) {
  172.         printf ("Room %d has no entrances, exits, or contents\n", i);
  173.         } else {
  174.         printf ("Room %d has no entrances\n", i);
  175.         }
  176.     }
  177.     }
  178.         
  179.     exit(0);
  180. }
  181.