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 / mobact.c < prev    next >
C/C++ Source or Header  |  1991-03-01  |  3KB  |  107 lines

  1. /* ************************************************************************
  2. *  file: mobact.c , Mobile action module.                 Part of DIKUMUD *
  3. *  Usage: Procedures generating 'intelligent' behavior in the mobiles.    *
  4. *  Copyright (C) 1990, 1991 - see 'license.doc' for complete information. *
  5. ************************************************************************* */
  6.  
  7. #include <stdio.h>
  8.  
  9. #include "utils.h"
  10. #include "structs.h"
  11. #include "db.h"
  12. #include "comm.h"
  13.  
  14. extern struct char_data *character_list;
  15. extern struct index_data *mob_index;
  16. extern struct room_data *world;
  17. extern struct str_app_type str_app[];
  18.  
  19. void hit(struct char_data *ch, struct char_data *victim, int type);
  20.  
  21.  
  22. void mobile_activity(void)
  23. {
  24.     register struct char_data *ch;
  25.     struct char_data *tmp_ch;
  26.     struct obj_data *obj, *best_obj, *worst_obj;
  27.     int door, found, max, min;
  28.  
  29.     extern int no_specials;
  30.  
  31.     void do_move(struct char_data *ch, char *argument, int cmd);
  32.     void do_get(struct char_data *ch, char *argument, int cmd);
  33.  
  34.     for (ch = character_list; ch; ch = ch->next)
  35.         if (IS_MOB(ch))
  36.         {
  37.             /* Examine call for special procedure */
  38.             if (IS_SET(ch->specials.act, ACT_SPEC) && !no_specials) {
  39.                 if (!mob_index[ch->nr].func) {
  40.                     log("Attempting to call a non-existing MOB func. (mobact.c)");
  41.                     REMOVE_BIT(ch->specials.act, ACT_SPEC);
  42.                 } else {
  43.                    if ((*mob_index[ch->nr].func)    (ch, 0, ""))
  44.                       continue;
  45.                 }
  46.             }
  47.  
  48.             if (AWAKE(ch) && !(ch->specials.fighting)) {
  49.  
  50.                 if (IS_SET(ch->specials.act, ACT_SCAVENGER)) {
  51.                     if (world[ch->in_room].contents && !number(0,10)) {
  52.                         for (max = 1, best_obj = 0, obj = world[ch->in_room].contents;
  53.                            obj; obj = obj->next_content) {
  54.                             if (CAN_GET_OBJ(ch, obj)) {
  55.                                 if (obj->obj_flags.cost > max) {
  56.                                     best_obj = obj;
  57.                                     max = obj->obj_flags.cost;
  58.                                 }
  59.                             }
  60.                         } /* for */
  61.  
  62.                         if (best_obj) {
  63.                             obj_from_room(best_obj);
  64.                             obj_to_char(best_obj, ch);
  65.                             act("$n gets $p.",FALSE,ch,best_obj,0,TO_ROOM);
  66.                         }
  67.                     }
  68.                 } /* Scavenger */
  69.  
  70.                 if (!IS_SET(ch->specials.act, ACT_SENTINEL) && 
  71.                     (GET_POS(ch) == POSITION_STANDING) &&
  72.                     ((door = number(0, 45)) <= 5) && CAN_GO(ch,door) &&
  73.                     !IS_SET(world[EXIT(ch, door)->to_room].room_flags, NO_MOB) &&
  74.                      !IS_SET(world[EXIT(ch, door)->to_room].room_flags, DEATH)) {
  75.                     if (ch->specials.last_direction == door) {
  76.                         ch->specials.last_direction = -1;
  77.                     } else {
  78.                         if (!IS_SET(ch->specials.act, ACT_STAY_ZONE)) {
  79.                             ch->specials.last_direction = door;
  80.                             do_move(ch, "", ++door);
  81.                         } else {
  82.                             if (world[EXIT(ch, door)->to_room].zone == world[ch->in_room].zone) {
  83.                                 ch->specials.last_direction = door;
  84.                                 do_move(ch, "", ++door);
  85.                             }
  86.                         }
  87.                     }
  88.                 } /* if can go */
  89.  
  90.  
  91.                 if (IS_SET(ch->specials.act,ACT_AGGRESSIVE)) {
  92.                     found = FALSE;
  93.                     for (tmp_ch = world[ch->in_room].people; tmp_ch && !found;
  94.                          tmp_ch = tmp_ch->next_in_room) {
  95.                         if (!IS_NPC(tmp_ch) && CAN_SEE(ch, tmp_ch)) {
  96.                             if (!IS_SET(ch->specials.act, ACT_WIMPY) || !AWAKE(tmp_ch)) {
  97.                                 hit(ch, tmp_ch, 0);
  98.                                 found = TRUE;
  99.                             }
  100.                         }
  101.                     }
  102.                 }
  103.             } /* If AWAKE(ch)   */
  104.         }   /* If IS_MOB(ch)  */
  105. }
  106.  
  107.