mux/src/rob.cpp

Go to the documentation of this file.
00001 // rob.cpp -- Commands dealing with giving/taking/killing things or money.
00002 //
00003 // $Id: rob.cpp,v 1.4 2006/01/07 08:26:39 sdennis Exp $
00004 //
00005 
00006 #include "copyright.h"
00007 #include "autoconf.h"
00008 #include "config.h"
00009 #include "externs.h"
00010 
00011 #include "attrs.h"
00012 #include "command.h"
00013 #include "powers.h"
00014 
00015 void do_kill
00016 (
00017     dbref executor,
00018     dbref caller,
00019     dbref enactor,
00020     int   key,
00021     int   nargs,
00022     char *what,
00023     char *costchar
00024 )
00025 {
00026     UNUSED_PARAMETER(caller);
00027     UNUSED_PARAMETER(enactor);
00028     UNUSED_PARAMETER(nargs);
00029 
00030     char *buf1, *buf2;
00031 
00032     init_match(executor, what, TYPE_PLAYER);
00033     match_neighbor();
00034     match_me();
00035     match_here();
00036     if (Long_Fingers(executor))
00037     {
00038         match_player();
00039         match_absolute();
00040     }
00041     dbref victim = match_result();
00042 
00043     switch (victim)
00044     {
00045     case NOTHING:
00046         notify(executor, "I don't see that player here.");
00047         break;
00048 
00049     case AMBIGUOUS:
00050         notify(executor, "I don't know who you mean!");
00051         break;
00052 
00053     default:
00054         if (  !isPlayer(victim)
00055            && !isThing(victim))
00056         {
00057             notify(executor, "Sorry, you can only kill players and things.");
00058             break;
00059         }
00060         if (  (  Haven(Location(victim))
00061               && !Wizard(executor))
00062            || (  Controls(victim, Location(victim))
00063               && !Controls(executor, Location(victim)))
00064            || Unkillable(victim))
00065         {
00066             notify(executor, "Sorry.");
00067             break;
00068         }
00069 
00070         // Go for it.
00071         //
00072         int cost = 0;
00073         if (key == KILL_KILL)
00074         {
00075             cost = mux_atol(costchar);
00076             if (cost < mudconf.killmin)
00077             {
00078                 cost = mudconf.killmin;
00079             }
00080             if (cost > mudconf.killmax)
00081             {
00082                 cost = mudconf.killmax;
00083             }
00084 
00085             // See if it works.
00086             //
00087             if (!payfor(executor, cost))
00088             {
00089                 notify(executor, tprintf("You don't have enough %s.", mudconf.many_coins));
00090                 return;
00091             }
00092         }
00093 
00094         if (  Wizard(victim)
00095            || (  0 < mudconf.killguarantee
00096               && !(  RandomINT32(0, mudconf.killguarantee-1) < cost
00097                   || key == KILL_SLAY)))
00098         {
00099             // Failure: notify player and victim only.
00100             //
00101             notify(executor, "Your murder attempt failed.");
00102             buf1 = alloc_lbuf("do_kill.failed");
00103             sprintf(buf1, "%s tried to kill you!", Name(executor));
00104             notify_with_cause_ooc(victim, executor, buf1);
00105             if (Suspect(executor))
00106             {
00107                 strcpy(buf1, Name(executor));
00108                 if (executor == Owner(executor))
00109                 {
00110                     raw_broadcast(WIZARD, "[Suspect] %s tried to kill %s(#%d).", buf1, Name(victim), victim);
00111                 }
00112                 else
00113                 {
00114                     buf2 = alloc_lbuf("do_kill.SUSP.failed");
00115                     strcpy(buf2, Name(Owner(executor)));
00116                     raw_broadcast(WIZARD, "[Suspect] %s <via %s(#%d)> tried to kill %s(#%d).",
00117                         buf2, buf1, executor, Name(victim), victim);
00118                     free_lbuf(buf2);
00119                 }
00120             }
00121             free_lbuf(buf1);
00122             break;
00123         }
00124 
00125         // Success!  You killed him
00126         //
00127         buf1 = alloc_lbuf("do_kill.succ.1");
00128         buf2 = alloc_lbuf("do_kill.succ.2");
00129         if (Suspect(executor))
00130         {
00131             strcpy(buf1, Name(executor));
00132             if (executor == Owner(executor))
00133             {
00134                 raw_broadcast(WIZARD, "[Suspect] %s killed %s(#%d).", buf1, Name(victim), victim);
00135             }
00136             else
00137             {
00138                 strcpy(buf2, Name(Owner(executor)));
00139                 raw_broadcast(WIZARD, "[Suspect] %s <via %s(#%d)> killed %s(#%d).",
00140                     buf2, buf1, executor, Name(victim), victim);
00141             }
00142         }
00143         sprintf(buf1, "You killed %s!", Name(victim));
00144         sprintf(buf2, "killed %s!", Name(victim));
00145         if (!isPlayer(victim))
00146         {
00147             if (halt_que(NOTHING, victim) > 0)
00148             {
00149                 if (!Quiet(victim))
00150                 {
00151                     notify(Owner(victim), "Halted.");
00152                 }
00153             }
00154         }
00155         did_it(executor, victim, A_KILL, buf1, A_OKILL, buf2, A_AKILL, (char **)NULL, 0);
00156 
00157         // notify victim
00158         //
00159         sprintf(buf1, "%s killed you!", Name(executor));
00160         notify_with_cause_ooc(victim, executor, buf1);
00161 
00162         // Pay off the bonus.
00163         //
00164         if (key == KILL_KILL)
00165         {
00166             cost /= 2;  // Victim gets half.
00167             if (Pennies(Owner(victim)) < mudconf.paylimit)
00168             {
00169                 sprintf(buf1, "Your insurance policy pays %d %s.", cost,
00170                     mudconf.many_coins);
00171                 notify(victim, buf1);
00172                 giveto(Owner(victim), cost);
00173             }
00174             else
00175             {
00176                 notify(victim, "Your insurance policy has been revoked.");
00177             }
00178         }
00179         free_lbuf(buf1);
00180         free_lbuf(buf2);
00181 
00182         // Send him home.
00183         //
00184         move_via_generic(victim, HOME, NOTHING, 0);
00185         divest_object(victim);
00186         break;
00187     }
00188 }
00189 
00190 /*
00191  * ---------------------------------------------------------------------------
00192  * * give_thing, give_money, do_give: Give away money or things.
00193  */
00194 
00195 static void give_thing(dbref giver, dbref recipient, int key, char *what)
00196 {
00197     init_match(giver, what, TYPE_THING);
00198     match_possession();
00199     match_me();
00200     dbref thing = match_result();
00201 
00202     switch (thing)
00203     {
00204     case NOTHING:
00205         notify(giver, "You don't have that!");
00206         return;
00207 
00208     case AMBIGUOUS:
00209         notify(giver, "I don't know which you mean!");
00210         return;
00211     }
00212     if (thing == giver)
00213     {
00214         notify(giver, "You can't give yourself away!");
00215         return;
00216     }
00217     if (thing == recipient)
00218     {
00219         notify(giver, "You can't give an object to itself.");
00220         return;
00221     }
00222     if (  (!isThing(thing) && !isPlayer(thing))
00223        || !(  Enter_ok(recipient)
00224           ||  Controls(giver, recipient))
00225        || isGarbage(recipient))
00226     {
00227         notify(giver, NOPERM_MESSAGE);
00228         return;
00229     }
00230     char *str, *sp;
00231     if (!could_doit(giver, thing, A_LGIVE))
00232     {
00233         sp = str = alloc_lbuf("do_give.gfail");
00234         safe_str("You can't give ", str, &sp);
00235         safe_str(Name(thing), str, &sp);
00236         safe_str(" away.", str, &sp);
00237         *sp = '\0';
00238 
00239         did_it(giver, thing, A_GFAIL, str, A_OGFAIL, NULL, A_AGFAIL, (char **)NULL, 0);
00240         free_lbuf(str);
00241         return;
00242     }
00243     if (!could_doit(thing, recipient, A_LRECEIVE))
00244     {
00245         sp = str = alloc_lbuf("do_give.rfail");
00246         safe_str(Name(recipient), str, &sp);
00247         safe_str(" doesn't want ", str, &sp);
00248         safe_str(Name(thing), str, &sp);
00249         safe_chr('.', str, &sp);
00250         *sp = '\0';
00251 
00252         did_it(giver, recipient, A_RFAIL, str, A_ORFAIL, NULL, A_ARFAIL, (char **)NULL, 0);
00253         free_lbuf(str);
00254         return;
00255     }
00256     move_via_generic(thing, recipient, giver, 0);
00257     divest_object(thing);
00258     if (!(key & GIVE_QUIET))
00259     {
00260         str = alloc_lbuf("do_give.thing.ok");
00261         strcpy(str, Name(giver));
00262         notify_with_cause_ooc(recipient, giver, tprintf("%s gave you %s.", str, Name(thing)));
00263         notify(giver, "Given.");
00264         notify_with_cause_ooc(thing, giver, tprintf("%s gave you to %s.", str, Name(recipient)));
00265         free_lbuf(str);
00266     }
00267     did_it(giver, thing, A_DROP, NULL, A_ODROP, NULL, A_ADROP, (char **)NULL, 0);
00268     did_it(recipient, thing, A_SUCC, NULL, A_OSUCC, NULL, A_ASUCC, (char **)NULL, 0);
00269 }
00270 
00271 static void give_money(dbref giver, dbref recipient, int key, int amount)
00272 {
00273     // Do amount consistency check.
00274     //
00275     if (  amount < 0
00276        && !Steal(giver))
00277     {
00278         notify(giver, tprintf("You look through your pockets. Nope, no negative %s.",
00279             mudconf.many_coins));
00280         return;
00281     }
00282     if (!amount)
00283     {
00284         notify(giver, tprintf("You must specify a positive number of %s.",
00285             mudconf.many_coins));
00286         return;
00287     }
00288     if (!Wizard(giver))
00289     {
00290         if (  isPlayer(recipient)
00291            && (Pennies(recipient) + amount > mudconf.paylimit))
00292         {
00293             notify(giver, tprintf("That player doesn't need that many %s!",
00294                 mudconf.many_coins));
00295             return;
00296         }
00297         if (!could_doit(giver, recipient, A_LUSE))
00298         {
00299             notify(giver, tprintf("%s won't take your money.", Name(recipient)));
00300             return;
00301         }
00302     }
00303 
00304     // Try to do the give.
00305     //
00306     if (!payfor(giver, amount))
00307     {
00308         notify(giver, tprintf("You don't have that many %s to give!",
00309             mudconf.many_coins));
00310         return;
00311     }
00312 
00313     // Find out cost if an object.
00314     //
00315     int cost;
00316     if (isThing(recipient))
00317     {
00318         dbref aowner;
00319         int aflags;
00320         char *str = atr_pget(recipient, A_COST, &aowner, &aflags);
00321         cost = mux_atol(str);
00322         free_lbuf(str);
00323 
00324         // Can't afford it?
00325         //
00326         if (amount < cost)
00327         {
00328             notify(giver, "Feeling poor today?");
00329             giveto(giver, amount);
00330             return;
00331         }
00332 
00333         // Negative cost
00334         //
00335         if (cost < 0)
00336         {
00337             return;
00338         }
00339     }
00340     else
00341     {
00342         cost = amount;
00343     }
00344 
00345     if (!(key & GIVE_QUIET))
00346     {
00347         if (amount == 1)
00348         {
00349             notify(giver, tprintf("You give a %s to %s.", mudconf.one_coin, Name(recipient)));
00350             notify_with_cause_ooc(recipient, giver, tprintf("%s gives you a %s.", Name(giver), mudconf.one_coin));
00351         }
00352         else
00353         {
00354             notify(giver, tprintf("You give %d %s to %s.", amount, mudconf.many_coins, Name(recipient)));
00355             notify_with_cause_ooc(recipient, giver, tprintf("%s gives you %d %s.",
00356                 Name(giver), amount, mudconf.many_coins));
00357         }
00358     }
00359 
00360     // Report change given
00361     //
00362     if ((amount - cost) == 1)
00363     {
00364         notify(giver, tprintf("You get 1 %s in change.", mudconf.one_coin));
00365         giveto(giver, 1);
00366     }
00367     else if (amount != cost)
00368     {
00369         notify(giver, tprintf("You get %d %s in change.", (amount - cost), mudconf.many_coins));
00370         giveto(giver, (amount - cost));
00371     }
00372 
00373     // Transfer the money and run PAY attributes
00374     //
00375     giveto(recipient, cost);
00376     did_it(giver, recipient, A_PAY, NULL, A_OPAY, NULL, A_APAY, (char **)NULL, 0);
00377     return;
00378 }
00379 
00380 void do_give
00381 (
00382     dbref executor,
00383     dbref caller,
00384     dbref enactor,
00385     int   key,
00386     int   nargs,
00387     char *who,
00388     char *amnt
00389 )
00390 {
00391     UNUSED_PARAMETER(caller);
00392     UNUSED_PARAMETER(enactor);
00393     UNUSED_PARAMETER(nargs);
00394 
00395     // Check recipient.
00396     //
00397     init_match(executor, who, TYPE_PLAYER);
00398     match_neighbor();
00399     match_possession();
00400     match_me();
00401     if (Long_Fingers(executor))
00402     {
00403         match_player();
00404         match_absolute();
00405     }
00406     dbref recipient = match_result();
00407     switch (recipient)
00408     {
00409     case NOTHING:
00410         notify(executor, "Give to whom?");
00411         return;
00412 
00413     case AMBIGUOUS:
00414         notify(executor, "I don't know who you mean!");
00415         return;
00416     }
00417 
00418     if (isExit(recipient))
00419     {
00420         notify(executor, "You can't give anything to an exit.");
00421         return;
00422     }
00423     if (Guest(recipient))
00424     {
00425         notify(executor, "Guests really don't need money or anything.");
00426         return;
00427     }
00428     if (is_rational(amnt))
00429     {
00430         give_money(executor, recipient, key, mux_atol(amnt));
00431     }
00432     else
00433     {
00434         give_thing(executor, recipient, key, amnt);
00435     }
00436 }

Generated on Mon May 28 04:40:11 2007 for MUX by  doxygen 1.4.7