home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / d / d-linux.zip / dm-dist / act.obj1.c < prev    next >
C/C++ Source or Header  |  1991-03-01  |  15KB  |  565 lines

  1. /* ************************************************************************
  2. *  file: act.obj1.c , Implementation of commands.         Part of DIKUMUD *
  3. *  Usage : Commands mainly moving around objects.                         *
  4. *  Copyright (C) 1990, 1991 - see 'license.doc' for complete information. *
  5. ************************************************************************* */
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. #include "structs.h"
  11. #include "utils.h"
  12. #include "comm.h"
  13. #include "interpreter.h"
  14. #include "handler.h"
  15. #include "db.h"
  16. #include "spells.h"
  17.  
  18. /* extern variables */
  19.  
  20. extern struct str_app_type str_app[];
  21. extern struct room_data *world;
  22. extern struct descriptor_data *descriptor_list;
  23. extern struct room_data *world;
  24.          
  25. /* extern functions */
  26.  
  27. struct obj_data *create_money( int amount );
  28.  
  29.  
  30. /* procedures related to get */
  31. void get(struct char_data *ch, struct obj_data *obj_object, 
  32.     struct obj_data *sub_object) {
  33. struct char_data *tmp_char;
  34. char buffer[MAX_STRING_LENGTH];
  35.  
  36.     if (sub_object) {
  37.         obj_from_obj(obj_object);
  38.         obj_to_char(obj_object, ch);
  39.         if (sub_object->carried_by == ch) {
  40.             act("You get $p from $P.", 0, ch, obj_object, sub_object,
  41.                 TO_CHAR);
  42.             act("$n gets $p from $s $P.", 1, ch, obj_object, sub_object, TO_ROOM);
  43.         } else {
  44.             act("You get $p from $P.", 0, ch, obj_object, sub_object,
  45.                 TO_CHAR);
  46.  
  47.             act("$n gets $p from $P.", 1, ch, obj_object, sub_object, TO_ROOM);
  48.         }
  49.     } else {
  50.         obj_from_room(obj_object);
  51.         obj_to_char(obj_object, ch);
  52.         act("You get $p.", 0, ch, obj_object, 0, TO_CHAR);
  53.         act("$n gets $p.", 1, ch, obj_object, 0, TO_ROOM);
  54.     }
  55.     if((obj_object->obj_flags.type_flag == ITEM_MONEY) && 
  56.         (obj_object->obj_flags.value[0]>=1))
  57.     {
  58.         obj_from_char(obj_object);
  59.         sprintf(buffer,"There was %d coins.\n\r", obj_object->obj_flags.value[0]);
  60.         send_to_char(buffer,ch);
  61.         GET_GOLD(ch) += obj_object->obj_flags.value[0];
  62.         extract_obj(obj_object);
  63.     }
  64. }
  65.  
  66.  
  67. void do_get(struct char_data *ch, char *argument, int cmd)
  68. {
  69.     char arg1[MAX_STRING_LENGTH];
  70.     char arg2[MAX_STRING_LENGTH];
  71.     char buffer[MAX_STRING_LENGTH];
  72.     struct obj_data *sub_object;
  73.     struct obj_data *obj_object;
  74.     struct obj_data *next_obj;
  75.     bool found = FALSE;
  76.     bool fail  = FALSE;
  77.     int type   = 3;
  78.  
  79.     argument_interpreter(argument, arg1, arg2);
  80.  
  81.     /* get type */
  82.     if (!*arg1) {
  83.         type = 0;
  84.     }
  85.     if (*arg1 && !*arg2) {
  86.         if (!str_cmp(arg1,"all")) {
  87.             type = 1;
  88.         } else {
  89.             type = 2;
  90.         }
  91.     }
  92.     if (*arg1 && *arg2) {
  93.         if (!str_cmp(arg1,"all")) {
  94.             if (!str_cmp(arg2,"all")) {
  95.                 type = 3;
  96.             } else {
  97.                 type = 4;
  98.             }
  99.         } else {
  100.             if (!str_cmp(arg2,"all")) {
  101.                 type = 5;
  102.             } else {
  103.                 type = 6;
  104.             }
  105.         }
  106.     }
  107.  
  108.     switch (type) {
  109.         /* get */
  110.         case 0:{ 
  111.             send_to_char("Get what?\n\r", ch); 
  112.         } break;
  113.         /* get all */
  114.         case 1:{ 
  115.             sub_object = 0;
  116.             found = FALSE;
  117.             fail    = FALSE;
  118.             for(obj_object = world[ch->in_room].contents;
  119.                 obj_object;
  120.                 obj_object = next_obj) {
  121.                 next_obj = obj_object->next_content;
  122.                 if (CAN_SEE_OBJ(ch,obj_object)) {
  123.                     if ((IS_CARRYING_N(ch) + 1) <= CAN_CARRY_N(ch)) {
  124.                         if ((IS_CARRYING_W(ch) + obj_object->obj_flags.weight) <= 
  125.                             CAN_CARRY_W(ch)) {
  126.                             if (CAN_WEAR(obj_object,ITEM_TAKE)) {
  127.                                 get(ch,obj_object,sub_object);
  128.                                 found = TRUE;
  129.                             } else {
  130.                                 send_to_char("You can't take that\n\r", ch);
  131.                                 fail = TRUE;
  132.                             }
  133.                         } else {
  134.                             sprintf(buffer,"%s : You can't carry that much weight.\n\r", 
  135.                                 fname(obj_object->name));
  136.                             send_to_char(buffer, ch);
  137.                             fail = TRUE;
  138.                         }
  139.                     } else {
  140.                         sprintf(buffer,"%s : You can't carry that many items.\n\r", 
  141.                             fname(obj_object->name));
  142.                         send_to_char(buffer, ch);
  143.                         fail = TRUE;
  144.                     }
  145.                 }
  146.             }
  147.             if (found) {
  148.                 send_to_char("OK.\n\r", ch);
  149.             } else {
  150.                 if (!fail) send_to_char("You see nothing here.\n\r", ch);
  151.             }
  152.         } break;
  153.         /* get ??? */
  154.         case 2:{
  155.             sub_object = 0;
  156.             found = FALSE;
  157.             fail    = FALSE;
  158.             obj_object = get_obj_in_list_vis(ch, arg1, 
  159.                 world[ch->in_room].contents);
  160.             if (obj_object) {
  161.                 if ((IS_CARRYING_N(ch) + 1 < CAN_CARRY_N(ch))) {
  162.                     if ((IS_CARRYING_W(ch) + obj_object->obj_flags.weight) < 
  163.                         CAN_CARRY_W(ch)) {
  164.                         if (CAN_WEAR(obj_object,ITEM_TAKE)) {
  165.                             get(ch,obj_object,sub_object);
  166.                             found = TRUE;
  167.                         } else {
  168.                             send_to_char("You can't take that\n\r", ch);
  169.                             fail = TRUE;
  170.                         }
  171.                     } else {
  172.                         sprintf(buffer,"%s : You can't carry that much weight.\n\r", 
  173.                             fname(obj_object->name));
  174.                         send_to_char(buffer, ch);
  175.                         fail = TRUE;
  176.                     }
  177.                 } else {
  178.                     sprintf(buffer,"%s : You can't carry that many items.\n\r", 
  179.                         fname(obj_object->name));
  180.                     send_to_char(buffer, ch);
  181.                     fail = TRUE;
  182.                 }
  183.             } else {
  184.                 sprintf(buffer,"You do not see a %s here.\n\r", arg1);
  185.                 send_to_char(buffer, ch);
  186.                 fail = TRUE;
  187.             }
  188.         } break;
  189.         /* get all all */
  190.         case 3:{ 
  191.             send_to_char("You must be joking?!\n\r", ch);
  192.         } break;
  193.         /* get all ??? */
  194.         case 4:{
  195.             found = FALSE;
  196.             fail    = FALSE; 
  197.             sub_object = get_obj_in_list_vis(ch, arg2, 
  198.                 world[ch->in_room].contents);
  199.             if (!sub_object){
  200.                 sub_object = get_obj_in_list_vis(ch, arg2, ch->carrying);
  201.             }
  202.             if (sub_object) {
  203.                 if (GET_ITEM_TYPE(sub_object) == ITEM_CONTAINER) {
  204.                     for(obj_object = sub_object->contains;
  205.                         obj_object;
  206.                         obj_object = next_obj) {
  207.                         next_obj = obj_object->next_content;
  208.                         if (CAN_SEE_OBJ(ch,obj_object)) {
  209.                             if ((IS_CARRYING_N(ch) + 1 < CAN_CARRY_N(ch))) {
  210.                                 if ((IS_CARRYING_W(ch) + obj_object->obj_flags.weight) < 
  211.                                     CAN_CARRY_W(ch)) {
  212.                                     if (CAN_WEAR(obj_object,ITEM_TAKE)) {
  213.                                         get(ch,obj_object,sub_object);
  214.                                         found = TRUE;
  215.                                     } else {
  216.                                         send_to_char("You can't take that\n\r", ch);
  217.                                         fail = TRUE;
  218.                                     }
  219.                                 } else {
  220.                                     sprintf(buffer,"%s : You can't carry that much weight.\n\r", 
  221.                                         fname(obj_object->name));
  222.                                     send_to_char(buffer, ch);
  223.                                     fail = TRUE;
  224.                                 }
  225.                             } else {
  226.                                 sprintf(buffer,"%s : You can't carry that many items.\n\r", 
  227.                                     fname(obj_object->name));
  228.                                 send_to_char(buffer, ch);
  229.                                 fail = TRUE;
  230.                             }
  231.                         }
  232.                     }
  233.                     if (!found && !fail) {
  234.                         sprintf(buffer,"You do not see anything in the %s.\n\r", 
  235.                             fname(sub_object->name));
  236.                         send_to_char(buffer, ch);
  237.                         fail = TRUE;
  238.                     }
  239.                 } else {
  240.                     sprintf(buffer,"The %s is not a container.\n\r",
  241.                         fname(sub_object->name));
  242.                     send_to_char(buffer, ch);
  243.                     fail = TRUE;
  244.                 }
  245.             } else { 
  246.                 sprintf(buffer,"You do not see or have the %s.\n\r", arg2);
  247.                 send_to_char(buffer, ch);
  248.                 fail = TRUE;
  249.             }
  250.         } break;
  251.         case 5:{ 
  252.             send_to_char("You can't take a thing from more than one container.\n\r", 
  253.                 ch);
  254.         } break;
  255.         case 6:{
  256.             found = FALSE;
  257.             fail    = FALSE;
  258.             sub_object = get_obj_in_list_vis(ch, arg2, 
  259.                 world[ch->in_room].contents);
  260.             if (!sub_object){
  261.                 sub_object = get_obj_in_list_vis(ch, arg2, ch->carrying);
  262.             }
  263.             if (sub_object) {
  264.                 if (GET_ITEM_TYPE(sub_object) == ITEM_CONTAINER) {
  265.                     obj_object = get_obj_in_list_vis(ch, arg1, sub_object->contains);
  266.                     if (obj_object) {
  267.                         if ((IS_CARRYING_N(ch) + 1 < CAN_CARRY_N(ch))) {
  268.                             if ((IS_CARRYING_W(ch) + obj_object->obj_flags.weight) < 
  269.                                 CAN_CARRY_W(ch)) {
  270.                                 if (CAN_WEAR(obj_object,ITEM_TAKE)) {
  271.                                     get(ch,obj_object,sub_object);
  272.                                     found = TRUE;
  273.                                 } else {
  274.                                     send_to_char("You can't take that\n\r", ch);
  275.                                     fail = TRUE;
  276.                                 }
  277.                             } else {
  278.                                 sprintf(buffer,"%s : You can't carry that much weight.\n\r", 
  279.                                     fname(obj_object->name));
  280.                                 send_to_char(buffer, ch);
  281.                                 fail = TRUE;
  282.                             }
  283.                         } else {
  284.                             sprintf(buffer,"%s : You can't carry that many items.\n\r", 
  285.                                 fname(obj_object->name));
  286.                             send_to_char(buffer, ch);
  287.                             fail = TRUE;
  288.                         }
  289.                     } else {
  290.                         sprintf(buffer,"The %s does not contain the %s.\n\r", 
  291.                             fname(sub_object->name), arg1);
  292.                         send_to_char(buffer, ch);
  293.                         fail = TRUE;
  294.                     }
  295.                 } else {
  296.                     sprintf(buffer,"The %s is not a container.\n\r", fname(sub_object->name));
  297.                     send_to_char(buffer, ch);
  298.                     fail = TRUE;
  299.                 }
  300.             } else {
  301.                 sprintf(buffer,"You do not see or have the %s.\n\r", arg2);
  302.                 send_to_char(buffer, ch);
  303.                 fail = TRUE;
  304.             }
  305.         } break;
  306.     }
  307. }
  308.  
  309.  
  310. void do_drop(struct char_data *ch, char *argument, int cmd) {
  311. char arg[MAX_STRING_LENGTH];
  312. int amount;
  313. char buffer[MAX_STRING_LENGTH];
  314. struct obj_data *tmp_object;
  315. struct obj_data *next_obj;
  316. struct char_data *tmp_char;
  317. bool test = FALSE;
  318.  
  319.     argument=one_argument(argument, arg);
  320.     if(is_number(arg))
  321.     {
  322.         amount = atoi(arg);
  323.         argument=one_argument(argument,arg);
  324.         if (str_cmp("coins",arg) && str_cmp("coin",arg))
  325.         {
  326.             send_to_char("Sorry, you can't do that (yet)...\n\r",ch);
  327.             return;
  328.         }
  329.         if(amount<0)
  330.         {
  331.             send_to_char("Sorry, you can't do that!\n\r",ch);
  332.             return;
  333.         }
  334.         if(GET_GOLD(ch)<amount)
  335.         {
  336.             send_to_char("You haven't got that many coins!\n\r",ch);
  337.             return;
  338.         }
  339.         send_to_char("OK.\n\r",ch);
  340.         if(amount==0)
  341.             return;
  342.         
  343.         act("$n drops some gold.", FALSE, ch, 0, 0, TO_ROOM);
  344.         tmp_object = create_money(amount);
  345.         obj_to_room(tmp_object,ch->in_room);
  346.         GET_GOLD(ch)-=amount;
  347.         return;
  348.     }
  349.  
  350.     if (*arg) {
  351.         if (!str_cmp(arg,"all")) {
  352.             for(tmp_object = ch->carrying;
  353.                 tmp_object;
  354.                 tmp_object = next_obj) {
  355.                 next_obj = tmp_object->next_content;
  356.                 if (! IS_SET(tmp_object->obj_flags.extra_flags, ITEM_NODROP)) {
  357.                     if (CAN_SEE_OBJ(ch, tmp_object)) {
  358.                         sprintf(buffer, "You drop the %s.\n\r", fname(tmp_object->name));
  359.                         send_to_char(buffer, ch);
  360.                     } else {
  361.                         send_to_char("You drop something.\n\r", ch);
  362.                     }
  363.                     act("$n drops $p.", 1, ch, tmp_object, 0, TO_ROOM);
  364.                     obj_from_char(tmp_object);
  365.                     obj_to_room(tmp_object,ch->in_room);
  366.                     test = TRUE;
  367.                 } else {
  368.                     if (CAN_SEE_OBJ(ch, tmp_object)) {
  369.                         sprintf(buffer, "You can't drop the %s, it must be CURSED!\n\r", fname(tmp_object->name));
  370.                         send_to_char(buffer, ch);
  371.                         test = TRUE;
  372.                     }
  373.                 }
  374.             }
  375.             if (!test) {
  376.                 send_to_char("You do not seem to have anything.\n\r", ch);
  377.             }
  378.      } else {
  379.             tmp_object = get_obj_in_list_vis(ch, arg, ch->carrying);
  380.             if (tmp_object) {
  381.                 if (! IS_SET(tmp_object->obj_flags.extra_flags, ITEM_NODROP)) {
  382.                     sprintf(buffer, "You drop the %s.\n\r", fname(tmp_object->name));
  383.                     send_to_char(buffer, ch);
  384.                     act("$n drops $p.", 1, ch, tmp_object, 0, TO_ROOM);
  385.                     obj_from_char(tmp_object);
  386.                     obj_to_room(tmp_object,ch->in_room);
  387.                 } else {
  388.                     send_to_char("You can't drop it, it must be CURSED!\n\r", ch);
  389.                 }
  390.             } else {
  391.                 send_to_char("You do not have that item.\n\r", ch);
  392.             }
  393.         }
  394.     } else {
  395.         send_to_char("Drop what?\n\r", ch);
  396.     }
  397. }
  398.  
  399.  
  400.  
  401. void do_put(struct char_data *ch, char *argument, int cmd)
  402. {
  403.     char buffer[MAX_STRING_LENGTH];
  404.     char arg1[MAX_STRING_LENGTH];
  405.     char arg2[MAX_STRING_LENGTH];
  406.     struct obj_data *obj_object;
  407.     struct obj_data *sub_object;
  408.     struct char_data *tmp_char;
  409.     int bits;
  410.  
  411.     argument_interpreter(argument, arg1, arg2);
  412.     if (*arg1) {
  413.         if (*arg2) {
  414.             obj_object = get_obj_in_list_vis(ch, arg1, ch->carrying);
  415.             if (obj_object) {
  416.                 bits = generic_find(arg2, FIND_OBJ_INV | FIND_OBJ_ROOM,
  417.                                     ch, &tmp_char, &sub_object);
  418.                 if (sub_object) {
  419.                     if (GET_ITEM_TYPE(sub_object) == ITEM_CONTAINER) {
  420.                         if (!IS_SET(sub_object->obj_flags.value[1], CONT_CLOSED)) {
  421.                             if (obj_object == sub_object) {
  422.                                 send_to_char("You attempt to fold it into itself, but fail.\n\r", ch);
  423.                                 return;
  424.                             }
  425.                             if (((sub_object->obj_flags.weight) + 
  426.                                 (obj_object->obj_flags.weight)) <
  427.                                 (sub_object->obj_flags.value[0])) {
  428.                                 send_to_char("Ok.\n\r", ch);
  429.                                 if (bits==FIND_OBJ_INV) {
  430.                                     obj_from_char(obj_object);
  431.                                     /* make up for above line */
  432.                                     IS_CARRYING_W(ch) += GET_OBJ_WEIGHT(obj_object);
  433. /*                                obj_from_char(sub_object); do not rearrange order... */
  434.                                     obj_to_obj(obj_object, sub_object);
  435. /*                                obj_to_char(sub_object,ch);do not rearrange order... */
  436.                                 } else {
  437.                                     obj_from_char(obj_object);
  438.                                     /* Do we need obj_from_room???(sub_object,....); */
  439.                                     obj_to_obj(obj_object, sub_object);
  440.                                     /* Dow we need obj_to_room???(sub_object,ch);    */
  441.                                 }
  442.     
  443.                                 act("$n puts $p in $P",TRUE, ch, obj_object, sub_object, TO_ROOM);
  444.                             } else {
  445.                                 send_to_char("It won't fit.\n\r", ch);
  446.                             }
  447.                         } else
  448.                             send_to_char("It seems to be closed.\n\r", ch);
  449.                     } else {
  450.                         sprintf(buffer,"The %s is not a container.\n\r", fname(sub_object->name));
  451.                         send_to_char(buffer, ch);
  452.                     }
  453.                 } else {
  454.                     sprintf(buffer, "You dont have the %s.\n\r", arg2);
  455.                     send_to_char(buffer, ch);
  456.                 }
  457.             } else {
  458.                 sprintf(buffer, "You dont have the %s.\n\r", arg1);
  459.                 send_to_char(buffer, ch);
  460.             }
  461.         } else {
  462.             sprintf(buffer, "Put %s in what?\n\r", arg1);
  463.             send_to_char(buffer, ch);
  464.         }
  465.     } else {
  466.         send_to_char("Put what in what?\n\r",ch);
  467.     }
  468. }
  469.  
  470.  
  471.  
  472.  
  473.  
  474. void do_give(struct char_data *ch, char *argument, int cmd)
  475. {
  476.     char obj_name[80], vict_name[80], buf[MAX_STRING_LENGTH];
  477.     char arg[80];
  478.     int amount;
  479.     struct char_data *vict, *sh;
  480.     struct obj_data *obj;
  481.  
  482.     argument=one_argument(argument,obj_name);
  483.     if(is_number(obj_name))
  484.     {
  485.         amount = atoi(obj_name);
  486.         argument=one_argument(argument, arg);
  487.         if (str_cmp("coins",arg) && str_cmp("coin",arg))
  488.         {
  489.             send_to_char("Sorry, you can't do that (yet)...\n\r",ch);
  490.             return;
  491.         }
  492.         if(amount<0)
  493.         {
  494.             send_to_char("Sorry, you can't do that!\n\r",ch);
  495.             return;
  496.         }
  497.         if((GET_GOLD(ch)<amount) && (IS_NPC(ch) || (GET_LEVEL(ch) < 22)))
  498.         {
  499.             send_to_char("You haven't got that many coins!\n\r",ch);
  500.             return;
  501.         }
  502.         argument=one_argument(argument, vict_name);
  503.         if(!*vict_name)
  504.         {
  505.             send_to_char("To who?\n\r",ch);
  506.             return;
  507.         }
  508.         if (!(vict = get_char_room_vis(ch, vict_name)))
  509.         {
  510.             send_to_char("To who?\n\r",ch);
  511.             return;
  512.         }
  513.         send_to_char("Ok.\n\r",ch);
  514.         sprintf(buf,"%s gives you %d gold coins.\n\r",PERS(ch,vict),amount);
  515.         send_to_char(buf,vict);
  516.         act("$n gives some gold to $N.", 1, ch, 0, vict, TO_NOTVICT);
  517.         if (IS_NPC(ch) || (GET_LEVEL(ch) < 22))
  518.             GET_GOLD(ch)-=amount;
  519.         GET_GOLD(vict)+=amount;
  520.         return;
  521.     }
  522.  
  523.     argument=one_argument(argument, vict_name);
  524.  
  525.  
  526.     if (!*obj_name || !*vict_name)
  527.     {
  528.         send_to_char("Give what to who?\n\r", ch);
  529.         return;
  530.     }
  531.     if (!(obj = get_obj_in_list_vis(ch, obj_name, ch->carrying)))
  532.     {
  533.         send_to_char("You do not seem to have anything like that.\n\r",
  534.            ch);
  535.         return;
  536.     }
  537.     if (IS_SET(obj->obj_flags.extra_flags, ITEM_NODROP))
  538.     {
  539.         send_to_char("You can't let go of it! Yeech!!\n\r", ch);
  540.         return;
  541.     }
  542.     if (!(vict = get_char_room_vis(ch, vict_name)))
  543.     {
  544.         send_to_char("No one by that name around here.\n\r", ch);
  545.         return;
  546.     }
  547.  
  548.     if ((1+IS_CARRYING_N(vict)) > CAN_CARRY_N(vict))
  549.     {
  550.         act("$N seems to have $S hands full.", 0, ch, 0, vict, TO_CHAR);
  551.         return;
  552.     }
  553.     if (obj->obj_flags.weight + IS_CARRYING_W(vict) > CAN_CARRY_W(vict))
  554.     {
  555.         act("$E can't carry that much weight.", 0, ch, 0, vict, TO_CHAR);
  556.         return;
  557.     }
  558.     obj_from_char(obj);
  559.     obj_to_char(obj, vict);
  560.     act("$n gives $p to $N.", 1, ch, obj, vict, TO_NOTVICT);
  561.     act("$n gives you $p.", 0, ch, obj, vict, TO_VICT);
  562.     send_to_char("Ok.\n\r", ch);
  563. }
  564.  
  565.