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

  1. #include "copyright.h"
  2.  
  3. /* commands which look at things */
  4.  
  5. #include "db.h"
  6. #include "config.h"
  7. #include "interface.h"
  8. #include "match.h"
  9. #include "externs.h"
  10.  
  11. static void look_contents(dbref player, dbref loc, const char *contents_name)
  12. {
  13.     dbref thing;
  14.     dbref can_see_loc;
  15.  
  16.     /* check to see if he can see the location */
  17.     can_see_loc = (!Dark(loc) || controls(player, loc));
  18.  
  19.     /* check to see if there is anything there */
  20.     DOLIST(thing, db[loc].contents) {
  21.     if(can_see(player, thing, can_see_loc)) {
  22.         /* something exists!  show him everything */
  23.         notify(player, contents_name);
  24.         DOLIST(thing, db[loc].contents) {
  25.         if(can_see(player, thing, can_see_loc)) {
  26.             notify(player, unparse_object(player, thing));
  27.         }
  28.         }
  29.         break;        /* we're done */
  30.     }
  31.     }
  32. }
  33.  
  34. static void look_simple(dbref player, dbref thing)
  35. {
  36.     if(db[thing].description) {
  37.     notify(player, db[thing].description);
  38.     } else {
  39.     notify(player, "You see nothing special.");
  40.     }
  41. }
  42.  
  43. void look_room(dbref player, dbref loc)
  44. {
  45.     /* tell him the name, and the number if he can link to it */
  46.     notify(player, unparse_object(player, loc));
  47.  
  48.     /* tell him the description */
  49.     if(db[loc].description) notify(player, db[loc].description);
  50.  
  51.     /* tell him the appropriate messages if he has the key */
  52.     can_doit(player, loc, 0);
  53.  
  54.     /* tell him the contents */
  55.     look_contents(player, loc, "Contents:");
  56. }
  57.  
  58. void do_look_around(dbref player)
  59. {
  60.     dbref loc;
  61.  
  62.     if((loc = getloc(player)) == NOTHING) return;
  63.     look_room(player, loc);
  64. }
  65.  
  66. void do_look_at(dbref player, const char *name)
  67. {
  68.     dbref thing;
  69.  
  70.     if(*name == '\0') {
  71.     if((thing = getloc(player)) != NOTHING) {
  72.         look_room(player, thing);
  73.     }
  74.     } else {
  75.     /* look at a thing here */
  76.     init_match(player, name, NOTYPE);
  77.     match_exit();
  78.     match_neighbor();
  79.     match_possession();
  80.     if(Wizard(player)) {
  81.         match_absolute();
  82.         match_player();
  83.     }
  84.     match_here();
  85.     match_me();
  86.  
  87.     if((thing = noisy_match_result()) != NOTHING) {
  88.         switch(Typeof(thing)) {
  89.           case TYPE_ROOM:
  90.         look_room(player, thing);
  91.         break;
  92.           case TYPE_PLAYER:
  93.         look_simple(player, thing);
  94.         look_contents(player, thing, "Carrying:");
  95.         break;
  96.           default:
  97.         look_simple(player, thing);
  98.         break;
  99.         }
  100.     }
  101.     }
  102. }
  103.  
  104. #if 0
  105. static const char *flag_description(dbref thing)
  106. {
  107.     static char buf[BUFFER_LEN];
  108.  
  109.     strcpy(buf, "Type: ");
  110.     switch(Typeof(thing)) {
  111.       case TYPE_ROOM:
  112.     strcat(buf, "Room");
  113.     break;
  114.       case TYPE_EXIT:
  115.     strcat(buf, "Exit");
  116.     break;
  117.       case TYPE_THING:
  118.     strcat(buf, "Thing");
  119.     break;
  120.       case TYPE_PLAYER:
  121.     strcat(buf, "Player");
  122.     break;
  123.       default:
  124.     strcat(buf, "***UNKNOWN TYPE***");
  125.     break;
  126.     }
  127.  
  128.     if(db[thing].flags & ~TYPE_MASK) {
  129.     /* print flags */
  130.     strcat(buf, " Flags:");
  131.     if(db[thing].flags & WIZARD) strcat(buf, " WIZARD");
  132.     if(db[thing].flags & STICKY) strcat(buf, " STICKY");
  133.     if(db[thing].flags & DARK) strcat(buf, " DARK");
  134.     if(db[thing].flags & LINK_OK) strcat(buf, " LINK_OK");
  135.     if(db[thing].flags & TEMPLE) strcat(buf, " TEMPLE");
  136. #ifdef RESTRICTED_BUILDING
  137.     if(db[thing].flags & BUILDER) strcat(buf, " BUILDER");
  138. #endif /* RESTRICTED_BUILDING */
  139.     }
  140.  
  141.     return buf;
  142. }
  143. #endif /* 0 */
  144.  
  145. void do_examine(dbref player, const char *name)
  146. {
  147.     dbref thing;
  148.     dbref content;
  149.     dbref exit;
  150.     char buf[BUFFER_LEN];
  151.  
  152.     if(*name == '\0') {
  153.     if((thing = getloc(player)) == NOTHING) return;
  154.     } else {
  155.     /* look it up */
  156.     init_match(player, name, NOTYPE);
  157.     match_exit();
  158.     match_neighbor();
  159.     match_possession();
  160.     match_absolute();
  161.     /* only Wizards can examine other players */
  162.     if(Wizard(player)) match_player();
  163.     match_here();
  164.     match_me();
  165.  
  166.     /* get result */
  167.     if((thing = noisy_match_result()) == NOTHING) return;
  168.     }
  169.  
  170.     if(!can_link(player, thing)) {
  171.     sprintf(buf, "Owner: %s", db[db[thing].owner].name);
  172.     notify(player, buf);
  173.     if(db[thing].description) notify(player, db[thing].description);
  174.     return;
  175.     }
  176.  
  177.     notify(player, unparse_object(player, thing));
  178.     sprintf(buf, "Owner: %s  Key: %s Pennies: %d",
  179.         db[db[thing].owner].name,
  180.         unparse_boolexp(player, db[thing].key),
  181.         db[thing].pennies);
  182.     notify(player, buf);
  183.     if(db[thing].description) notify(player, db[thing].description);
  184.     if(db[thing].fail_message) {
  185.     sprintf(buf, "Fail: %s", db[thing].fail_message);
  186.     notify(player, buf);
  187.     }
  188.     if(db[thing].succ_message) {
  189.     sprintf(buf, "Success: %s", db[thing].succ_message);
  190.     notify(player, buf);
  191.     }
  192.     if(db[thing].ofail) {
  193.     sprintf(buf, "Ofail: %s", db[thing].ofail);
  194.     notify(player, buf);
  195.     }
  196.     if(db[thing].osuccess) {
  197.     sprintf(buf, "Osuccess: %s", db[thing].osuccess);
  198.     notify(player, buf);
  199.     }
  200.  
  201.     /* show him the contents */
  202.     if(db[thing].contents != NOTHING) {
  203.     notify(player, "Contents:");
  204.     DOLIST(content, db[thing].contents) {
  205.         notify(player, unparse_object(player, content));
  206.     }
  207.     }
  208.  
  209.     switch(Typeof(thing)) {
  210.       case TYPE_ROOM:
  211.     /* tell him about exits */
  212.     if(db[thing].exits != NOTHING) {
  213.         notify(player, "Exits:");
  214.         DOLIST(exit, db[thing].exits) {
  215.         notify(player, unparse_object(player, exit));
  216.         }
  217.     } else {
  218.         notify(player, "No exits.");
  219.     }
  220.  
  221.     /* print dropto if present */
  222.     if(db[thing].location != NOTHING) {
  223.         sprintf(buf, "Dropped objects go to: %s",
  224.             unparse_object(player, db[thing].location));
  225.         notify(player, buf);
  226.     }
  227.     break;
  228.       case TYPE_THING:
  229.       case TYPE_PLAYER:
  230.     /* print home */
  231.     sprintf(buf, "Home: %s",
  232.         unparse_object(player, db[thing].exits)); /* home */
  233.     notify(player, buf);
  234.     /* print location if player can link to it */
  235.     if(db[thing].location != NOTHING
  236.        && (controls(player, db[thing].location)
  237.            || can_link_to(player, Typeof(thing), db[thing].location))) {
  238.         sprintf(buf, "Location: %s",
  239.             unparse_object(player, db[thing].location));
  240.         notify(player, buf);
  241.     }
  242.     break;
  243.       case TYPE_EXIT:
  244.     /* print destination */
  245.     switch(db[thing].location) {
  246.       case NOTHING:
  247.         break;
  248.       case HOME:
  249.         notify(player, "Destination: *HOME*");
  250.         break;
  251.       default:
  252.         sprintf(buf, "%s: %s",
  253.             (Typeof(db[thing].location) == TYPE_ROOM
  254.              ? "Destination" : "Carried by"),
  255.             unparse_object(player, db[thing].location));
  256.         notify(player, buf);
  257.         break;
  258.     }
  259.     break;
  260.       default:
  261.     /* do nothing */
  262.     break;
  263.     }
  264. }
  265.  
  266. void do_score(dbref player) 
  267. {
  268.     char buf[BUFFER_LEN];
  269.  
  270.     sprintf(buf, "You have %d %s.",
  271.         db[player].pennies,
  272.         db[player].pennies == 1 ? "penny" : "pennies");
  273.     notify(player, buf);
  274. }
  275.  
  276. void do_inventory(dbref player)
  277. {
  278.     dbref thing;
  279.  
  280.     if((thing = db[player].contents) == NOTHING) {
  281.     notify(player, "You aren't carrying anything.");
  282.     } else {
  283.     notify(player, "You are carrying:");
  284.     DOLIST(thing, thing) {
  285.         notify(player, unparse_object(player, thing));
  286.     }
  287.     }
  288.  
  289.     do_score(player);
  290. }
  291.  
  292. void do_find(dbref player, const char *name)
  293. {
  294.     dbref i;
  295.  
  296.     if(!payfor(player, FIND_COST)) {
  297.     notify(player, "You don't have enough pennies.");
  298.     } else {
  299.     for(i = 0; i < db_top; i++) {
  300.         if(Typeof(i) != TYPE_EXIT
  301.            && controls(player, i)
  302.            && (!*name || string_match(db[i].name, name))) {
  303.         notify(player, unparse_object(player, i));
  304.         }
  305.     }
  306.     notify(player, "***End of List***");
  307.     }
  308. }
  309.  
  310. void do_owned(dbref player, const char *sowner)
  311. {
  312.     dbref owner,i;
  313.     
  314.     if(!Wizard(player)) {
  315. #ifndef TINKER
  316.      notify(player,"Only a Wizard can check the ownership list. Use @find.");
  317. #else TINKER
  318.      notify(player,"Only a Tinker can check the ownership list. Use @find.");
  319. #endif TINKER
  320.     } else if ((owner = lookup_player(sowner)) == NOTHING) {
  321.      notify(player,"I couldn't find that player.");
  322.     } else {
  323.      for(i = 0; i < db_top; i++)
  324.          if(Typeof(i) != TYPE_EXIT && db[i].owner == owner)
  325.          notify(player, unparse_object(player, i));
  326.      notify(player, "***End of List***");
  327.     }
  328. }
  329.