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

  1. #include "copyright.h"
  2.  
  3. /* Commands that create new objects */
  4.  
  5. #include "db.h"
  6. #include "config.h"
  7. #include "interface.h"
  8. #include "externs.h"
  9.  
  10. /* utility for open and link */
  11. static dbref parse_linkable_room(dbref player, object_flag_type thing,
  12.                  const char *room_name)
  13. {
  14.     dbref room;
  15.  
  16.     /* skip leading NUMBER_TOKEN if any */
  17.     if(*room_name == NUMBER_TOKEN) room_name++;
  18.  
  19.     /* parse room */
  20.     if(!string_compare(room_name, "here")) {
  21.     room = db[player].location;
  22.     } else if(!string_compare(room_name, "home")) {
  23.     return HOME;        /* HOME is always linkable */
  24.     } else {
  25.     room = parse_dbref(room_name);
  26.     }
  27.  
  28.     /* check room */
  29.     if(room < 0 || room >= db_top
  30.        || Typeof(room) != TYPE_ROOM) {
  31.     notify(player, "That's not a room!");
  32.     return NOTHING;
  33.     } else if(!can_link_to(player, thing, room)) {
  34.     notify(player, "You can't link to that.");
  35.     return NOTHING;
  36.     } else {
  37.     return room;
  38.     }
  39. }
  40.  
  41. /* use this to create an exit */
  42. void do_open(dbref player, const char *direction, const char *linkto)
  43. {
  44.     dbref loc;
  45.     dbref exit;
  46.  
  47. #ifdef RESTRICTED_BUILDING
  48.     if(!Builder(player)) {
  49.     notify(player, "That command is restricted to authorized builders.");
  50.     return;
  51.     }
  52. #endif /* RESTRICTED_BUILDING */
  53.  
  54.     if((loc = getloc(player)) == NOTHING) return;
  55.     if(!*direction) {
  56.     notify(player, "Open where?");
  57.     return;
  58.     } else if(!ok_name(direction)) {
  59.     notify(player, "That's a strange name for an exit!");
  60.     return;
  61.     }
  62.  
  63.     if(!controls(player, loc)) {
  64.     notify(player, "Permission denied.");
  65.     } else if(!payfor(player, EXIT_COST)) {
  66.     notify(player,
  67.            "Sorry, you don't have enough pennies to open an exit.");
  68.     } else {
  69.     /* create the exit */
  70.     exit = new_object();
  71.  
  72.     /* initialize everything */
  73.     db[exit].name = alloc_string(direction);
  74.     db[exit].owner = player;
  75.     db[exit].flags = TYPE_EXIT;
  76.  
  77.     /* link it in */
  78.     PUSH(exit, db[loc].exits);
  79.  
  80.     /* and we're done */
  81.     notify(player, "Opened.");
  82.  
  83.     /* check second arg to see if we should do a link */
  84.     if(*linkto != '\0') {
  85.         notify(player, "Trying to link...");
  86.         if((loc = parse_linkable_room(player, TYPE_EXIT, linkto)) !=
  87.            NOTHING) {
  88.         if(!payfor(player, LINK_COST)) {
  89.             notify(player, "You don't have enough pennies to link.");
  90.         } else {
  91.             /* it's ok, link it */
  92.             db[exit].location = loc;
  93.             notify(player, "Linked.");
  94.         }
  95.         }
  96.     }
  97.     }
  98. }
  99.  
  100. /* use this to link to a room that you own */
  101. /* it seizes ownership of the exit */
  102. /* costs 1 penny */
  103. /* plus a penny transferred to the exit owner if they aren't you */
  104. /* you must own the linked-to room AND specify it by room number */
  105. void do_link(dbref player, const char *name, const char *room_name)
  106. {
  107.     dbref thing;
  108.     dbref room;
  109.  
  110.     init_match(player, name, TYPE_EXIT);
  111.     match_exit();
  112.     match_neighbor();
  113.     match_possession();
  114.     match_me();
  115.     match_here();
  116.     if(Wizard(player)) {
  117.     match_absolute();
  118.     match_player();
  119.     }
  120.  
  121.     if((thing = noisy_match_result()) != NOTHING) {
  122.     if((room = parse_linkable_room(player, Typeof(thing), room_name)) ==
  123.        NOTHING)
  124.         return;
  125.     switch(Typeof(thing)) {
  126.       case TYPE_EXIT:
  127.         /* we're ok, check the usual stuff */
  128.         if(db[thing].location != NOTHING) {
  129.         if(controls(player, thing)) {
  130.  
  131.             /*
  132.              * Changed 5/18/90 Fuzzy - exits linked to *home*
  133.              * break 'Typeof() call'
  134.              */
  135.  
  136.             if(db[thing].location >= 0 &&
  137.                Typeof(db[thing].location) == TYPE_PLAYER) {
  138.             notify(player, "That exit is being carried.");
  139.             } else {
  140.             notify(player, "That exit is already linked.");
  141.             }
  142.         } else {
  143.             notify(player, "Permission denied.");
  144.         }
  145.         } else {
  146.         /* handle costs */
  147.         if(db[thing].owner == player) {
  148.             if(!payfor(player, LINK_COST)) {
  149.             notify(player,
  150.                    "It costs a penny to link this exit.");
  151.             return;
  152.             }
  153.         } else {
  154.             if(!payfor(player, LINK_COST + EXIT_COST)) {
  155.             notify(player,
  156.                    "It costs two pennies to link this exit.");
  157.             return;
  158. #ifdef RESTRICTED_BUILDING
  159.             } else if(!Builder(player)) {
  160.             notify(player,
  161.                    "Only authorized builders may seize exits.");
  162. #endif /* RESTRICTED_BUILDING */            
  163.             } else {
  164.             /* pay the owner for his loss */
  165.             db[db[thing].owner].pennies += EXIT_COST;
  166.             }
  167.         }
  168.  
  169.         /* link has been validated and paid for; do it */
  170.         db[thing].owner = player;
  171.         db[thing].location = room;
  172.  
  173.         /* notify the player */
  174.         notify(player, "Linked.");
  175.         }
  176.         break;
  177.       case TYPE_PLAYER:
  178.       case TYPE_THING:
  179.         if(!controls(player, thing)) {
  180.         notify(player, "Permission denied.");
  181.         } else if(room == HOME) {
  182.         notify(player, "Can't set home to home.");
  183.         } else {
  184.         /* do the link */
  185.         db[thing].exits = room; /* home */
  186.         notify(player, "Home set.");
  187.         }
  188.         break;
  189.       case TYPE_ROOM:
  190.         if(!controls(player, thing)) {
  191.         notify(player, "Permission denied.");
  192.         } else {
  193.         /* do the link, in location */
  194.         db[thing].location = room; /* dropto */
  195.         notify(player, "Dropto set.");
  196.         }
  197.         break;
  198.       default:
  199.         notify(player, "Internal error: weird object type.");
  200.         writelog("PANIC weird object: Typeof(%d) = %d\n",
  201.             thing, Typeof(thing));
  202.         break;
  203.     }
  204.     }
  205. }
  206.  
  207. /* use this to create a room */
  208. void do_dig(dbref player, const char *name)
  209. {
  210.     dbref room;
  211.     char buf[BUFFER_LEN];
  212.  
  213. #ifdef RESTRICTED_BUILDING
  214.     if(!Builder(player)) {
  215.     notify(player, "That command is restricted to authorized builders.");
  216.     return;
  217.     }
  218. #endif /* RESTRICTED_BUILDING */
  219.  
  220.     /* we don't need to know player's location!  hooray! */
  221.     if(*name == '\0') {
  222.     notify(player, "Dig what?");
  223.     } else if(!ok_name(name)) {
  224.     notify(player, "That's a silly name for a room!");
  225.     } else if(!payfor(player, ROOM_COST)) {
  226.     notify(player, "Sorry, you don't have enough pennies to dig a room.");
  227.     } else {
  228.     room = new_object();
  229.  
  230.     /* Initialize everything */
  231.     db[room].name = alloc_string(name);
  232.     db[room].owner = player;
  233.     db[room].flags = TYPE_ROOM;
  234.  
  235.     sprintf(buf, "%s created with room number %d.", name, room);
  236.     notify(player, buf);
  237.     }
  238. }
  239.  
  240. /* use this to create an object */
  241. void do_create(dbref player, char *name, int cost)
  242. {
  243.     dbref loc;
  244.     dbref thing;
  245.  
  246. #ifdef RESTRICTED_BUILDING
  247.     if(!Builder(player)) {
  248.     notify(player, "That command is restricted to authorized builders.");
  249.     return;
  250.     }
  251. #endif /* RESTRICTED_BUILDING */
  252.  
  253.     if(*name == '\0') {
  254.     notify(player, "Create what?");
  255.     return;
  256.     } else if(!ok_name(name)) {
  257.     notify(player, "That's a silly name for a thing!");
  258.     return;
  259.     } else if(cost < 0) {
  260.     notify(player, "You can't create an object for less than nothing!");
  261.     return;
  262.     } else if(cost < OBJECT_COST) {
  263.     cost = OBJECT_COST;
  264.     }
  265.  
  266.     if(!payfor(player, cost)) {
  267.     notify(player, "Sorry, you don't have enough pennies.");
  268.     } else {
  269.     /* create the object */
  270.     thing = new_object();
  271.  
  272.     /* initialize everything */
  273.     db[thing].name = alloc_string(name);
  274.     db[thing].location = player;
  275.     db[thing].owner = player;
  276.     db[thing].pennies = OBJECT_ENDOWMENT(cost);
  277.     db[thing].flags = TYPE_THING;
  278.  
  279.     /* endow the object */
  280.     if(db[thing].pennies > MAX_OBJECT_ENDOWMENT) {
  281.         db[thing].pennies = MAX_OBJECT_ENDOWMENT;
  282.     }
  283.  
  284.     /* home is here (if we can link to it) or player's home */
  285.     if((loc = db[player].location) != NOTHING
  286.        && controls(player, loc)) {
  287.         db[thing].exits = loc;    /* home */
  288.     } else {
  289.         db[thing].exits = db[player].exits;    /* home */
  290.     }
  291.  
  292.     /* link it in */
  293.     PUSH(thing, db[player].contents);
  294.  
  295.     /* and we're done */
  296.     notify(player, "Created.");
  297.     }
  298. }
  299.  
  300. #ifdef REGISTRATION
  301. void do_pcreate (dbref player, char *newplayer, char *newpass)
  302. {
  303.     dbref ptmp;
  304.  
  305. #ifdef GOD_MODE && GOD_ONLY_PCREATE
  306.     if (!God(player))
  307. #ifndef TINKER
  308.         notify (player, "Only GOD can create a new player.");
  309. #else TINKER
  310.         notify (player, "Only the Master Tinker can create a new player.");
  311. #endif TINKER
  312. #else GOD_MODE && GOD_ONLY_PCREATE
  313.     if (!Wizard(player))
  314. #ifndef TINKER
  315.     notify (player, "Only a Wizard can create a new player.");
  316. #else TINKER
  317.     notify (player, "Only a Tinker can create a new player.");
  318. #endif TINKER
  319. #endif GOD_MODE && GOD_ONLY_PCREATE
  320.     else if (!*newplayer || !*newpass)
  321.     notify (player, "You must specify name and password.");
  322.     else {
  323.         ptmp = create_player (newplayer, newpass);
  324.     if (ptmp == NOTHING) {
  325.         notify(player, "Either there is already a player with that name, or that name is illegal.");
  326.         writelog("FAILED CREATE %s by %s\n",newplayer,db[player].name);
  327.     } else {
  328.         char buf[512];
  329.         sprintf(buf, "%s created as object #%d.",db[ptmp].name,ptmp);
  330.         notify(player, buf);
  331.         writelog("CREATED %s(%d) by %s\n",db[ptmp].name,ptmp,
  332.              db[player].name);
  333.     }
  334.     }
  335. }
  336. #endif REGISTRATION
  337.