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

  1. #include "copyright.h"
  2.  
  3. /* rob and kill */
  4.  
  5. #include "db.h"
  6. #include "config.h"
  7. #include "interface.h"
  8. #include "match.h"
  9. #include "externs.h"
  10.  
  11. void do_rob(dbref player, const char *what)
  12. {
  13.     dbref thing;
  14.     char buf[BUFFER_LEN];
  15.     
  16.     init_match(player, what, TYPE_PLAYER);
  17.     match_neighbor();
  18.     match_me();
  19.     if(Wizard(player)) {
  20.     match_absolute();
  21.     match_player();
  22.     }
  23.     thing = match_result();
  24.  
  25.     switch(thing) {
  26.       case NOTHING:
  27.     notify(player, "Rob whom?");
  28.     break;
  29.       case AMBIGUOUS:
  30.     notify(player, "I don't know who you mean!");
  31.     break;
  32.       default:
  33.     if(Typeof(thing) != TYPE_PLAYER) {
  34.         notify(player, "Sorry, you can only rob other players.");
  35.     } else if(db[thing].pennies < 1) {
  36.         sprintf(buf, "%s is penniless.", db[thing].name);
  37.         notify(player, buf);
  38.         sprintf(buf,
  39.             "%s tried to rob you, but you have no pennies to take.",
  40.             db[player].name);
  41.         notify(thing, buf);
  42.     } else if(can_doit(player, thing,
  43.                "Your conscience tells you not to.")) {
  44.         /* steal a penny */
  45.         db[player].pennies++;
  46.         db[thing].pennies--;
  47.         notify(player, "You stole a penny.");
  48.         sprintf(buf, "%s stole one of your pennies!", db[player].name);
  49.         notify(thing, buf);
  50.     }
  51.     break;
  52.     }
  53. }
  54.  
  55. void do_kill(dbref player, const char *what, int cost)
  56. {
  57.     dbref victim;
  58.     char buf[BUFFER_LEN];
  59.  
  60.     init_match(player, what, TYPE_PLAYER);
  61.     match_neighbor();
  62.     match_me();
  63.     if(Wizard(player)) {
  64.     match_player();
  65.     match_absolute();
  66.     }
  67.     victim = match_result();
  68.  
  69.     switch(victim) {
  70.       case NOTHING:
  71.     notify(player, "I don't see that player here.");
  72.     break;
  73.       case AMBIGUOUS:
  74.     notify(player, "I don't know who you mean!");
  75.     break;
  76.       default:
  77.     if(Typeof(victim) != TYPE_PLAYER) {
  78.         notify(player, "Sorry, you can only kill other players.");
  79.     } else if ((db[db[victim].location].flags & HAVEN) &&
  80.            !Wizard(player)) {
  81.         notify(player, "Sorry, this room is safe from killing.");
  82.     } else {
  83.         /* go for it */
  84.         /* set cost */
  85.         if(cost < KILL_MIN_COST) cost = KILL_MIN_COST;
  86.  
  87.         /* see if it works */
  88.         if(!payfor(player, cost)) {
  89.         notify(player, "You don't have enough pennies.");
  90.         } else if((random() % KILL_BASE_COST) < cost
  91.               && !Wizard(victim)) {
  92.         /* you killed him */
  93.         sprintf(buf, "You killed %s!", db[victim].name);
  94.         notify(player, buf);
  95.  
  96.         /* notify victim */
  97.         sprintf(buf, "%s killed you!", db[player].name);
  98.         notify(victim, buf);
  99.  
  100.         /* maybe pay off the bonus */
  101.         if(db[victim].pennies < MAX_PENNIES) {
  102.             sprintf(buf, "Your insurance policy pays %d pennies.",
  103.                 KILL_BONUS);
  104.             notify(victim, buf);
  105.             db[victim].pennies += KILL_BONUS;
  106.         } else {
  107.             notify(victim, "Your insurance policy has been revoked.");
  108.         }
  109.  
  110.         /* send him home */
  111.         send_home(victim);
  112.  
  113.         /* now notify everybody else */
  114.         sprintf(buf, "%s killed %s!",
  115.             db[player].name, db[victim].name);
  116.         notify_except(db[db[player].location].contents, player, buf);
  117.         } else {
  118.         /* notify player and victim only */
  119.         notify(player, "Your murder attempt failed.");
  120.         sprintf(buf, "%s tried to kill you!", db[player].name);
  121.         notify(victim, buf);
  122.         }
  123.     break;
  124.     }
  125.     }
  126. }
  127.  
  128. void do_give(dbref player, char *recipient, int amount)
  129. {
  130.     dbref who;
  131.     char buf[BUFFER_LEN];
  132.  
  133.     /* do amount consistency check */
  134.     if(amount < 0 && !Wizard(player)) {
  135.     notify(player, "Try using the \"rob\" command.");
  136.     return;
  137.     } else if(amount == 0) {
  138.     notify(player, "You must specify a positive number of pennies.");
  139.     return;
  140.     }
  141.  
  142.     /* check recipient */
  143.     init_match(player, recipient, TYPE_PLAYER);
  144.     match_neighbor();
  145.     match_me();
  146.     if(Wizard(player)) {
  147.     match_player();
  148.     match_absolute();
  149.     }
  150.     
  151.     switch(who = match_result()) {
  152.       case NOTHING:
  153.     notify(player, "Give to whom?");
  154.     return;
  155.       case AMBIGUOUS:
  156.     notify(player, "I don't know who you mean!");
  157.     return;
  158.       default:
  159.     if(!Wizard(player)) {
  160.         if(Typeof(who) != TYPE_PLAYER) {
  161.         notify(player, "You can only give to other players.");
  162.         return;
  163.         } else if(db[who].pennies + amount > MAX_PENNIES) {
  164.         notify(player, "That player doesn't need that many pennies!");
  165.         return;
  166.         }
  167.     }
  168.     break;
  169.     }
  170.  
  171.     /* try to do the give */
  172.     if(!payfor(player, amount)) {
  173.     notify(player, "You don't have that many pennies to give!");
  174.     } else {
  175.     /* he can do it */
  176.     sprintf(buf, "You give %d %s to %s.",
  177.         amount,
  178.         amount == 1 ? "penny" : "pennies",
  179.         db[who].name);
  180.     notify(player, buf);
  181.     if(Typeof(who) == TYPE_PLAYER) {
  182.         sprintf(buf, "%s gives you %d %s.",
  183.             db[player].name,
  184.             amount,
  185.             amount == 1 ? "penny" : "pennies");
  186.         notify(who, buf);
  187.     }
  188.  
  189.     db[who].pennies += amount;
  190.     }
  191. }
  192.