MudBytes
Code Repository
Return to File » Root » dm-dist
lib doc

  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. char buf[256];
  25. register struct char_data *ch;
  26. struct char_data *tmp_ch;
  27. struct obj_data *obj, *best_obj, *worst_obj;
  28. int door, found, max, min;
  29.  
  30. extern int no_specials;
  31.  
  32. void do_move(struct char_data *ch, char *argument, int cmd);
  33. void do_get(struct char_data *ch, char *argument, int cmd);
  34.  
  35. for (ch = character_list; ch; ch = ch->next)
  36. if (IS_MOB(ch))
  37. {
  38. /* Examine call for special procedure */
  39. if (IS_SET(ch->specials.act, ACT_SPEC) && !no_specials) {
  40. if (!mob_index[ch->nr].func) {
  41. sprintf(buf, "Non-Existing MOB[%d] SPEC procedure (mobact.c)",mob_index[ch->nr].virtual);
  42. log(buf);
  43. REMOVE_BIT(ch->specials.act, ACT_SPEC);
  44. } else {
  45. if ((*mob_index[ch->nr].func) (ch, 0, ""))
  46. continue;
  47. }
  48. }
  49.  
  50. if (AWAKE(ch) && !(ch->specials.fighting)) {
  51.  
  52. if (IS_SET(ch->specials.act, ACT_SCAVENGER)) {
  53. if (world[ch->in_room].contents && !number(0,10)) {
  54. for (max = 1, best_obj = 0, obj = world[ch->in_room].contents;
  55. obj; obj = obj->next_content) {
  56. if (CAN_GET_OBJ(ch, obj)) {
  57. if (obj->obj_flags.cost > max) {
  58. best_obj = obj;
  59. max = obj->obj_flags.cost;
  60. }
  61. }
  62. } /* for */
  63.  
  64. if (best_obj) {
  65. obj_from_room(best_obj);
  66. obj_to_char(best_obj, ch);
  67. act("$n gets $p.",FALSE,ch,best_obj,0,TO_ROOM);
  68. }
  69. }
  70. } /* Scavenger */
  71.  
  72. if (!IS_SET(ch->specials.act, ACT_SENTINEL) &&
  73. (GET_POS(ch) == POSITION_STANDING) &&
  74. ((door = number(0, 45)) <= 5) && CAN_GO(ch,door) &&
  75. !IS_SET(world[EXIT(ch, door)->to_room].room_flags, NO_MOB) &&
  76. !IS_SET(world[EXIT(ch, door)->to_room].room_flags, DEATH)) {
  77. if (ch->specials.last_direction == door) {
  78. ch->specials.last_direction = -1;
  79. } else {
  80. if (!IS_SET(ch->specials.act, ACT_STAY_ZONE)) {
  81. ch->specials.last_direction = door;
  82. do_move(ch, "", ++door);
  83. } else {
  84. if (world[EXIT(ch, door)->to_room].zone == world[ch->in_room].zone) {
  85. ch->specials.last_direction = door;
  86. do_move(ch, "", ++door);
  87. }
  88. }
  89. }
  90. } /* if can go */
  91.  
  92.  
  93. if (IS_SET(ch->specials.act,ACT_AGGRESSIVE)) {
  94. found = FALSE;
  95. for (tmp_ch = world[ch->in_room].people; tmp_ch && !found;
  96. tmp_ch = tmp_ch->next_in_room) {
  97. if (!IS_NPC(tmp_ch) && CAN_SEE(ch, tmp_ch)) {
  98. if (!IS_SET(ch->specials.act, ACT_WIMPY) || !AWAKE(tmp_ch)) {
  99. hit(ch, tmp_ch, 0);
  100. found = TRUE;
  101. }
  102. }
  103. }
  104. }
  105. } /* If AWAKE(ch) */
  106. } /* If IS_MOB(ch) */
  107. }
  108.  
  109.  
Parsed in 0.017 seconds, using GeSHi 1.0.8.4