Advertisement
Guest User

Untitled

a guest
Oct 9th, 2011
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. From b55127aa00831b9386a03b3c5a4a762e424836a0 Mon Sep 17 00:00:00 2001
  2. From: evilmike <evilmike@gmail.com>
  3. Date: Sun, 9 Oct 2011 02:33:42 -0700
  4. Subject: [PATCH] Randomize triggering fleeing at low HP.
  5.  
  6. Monsters get a random chance of fleeing at low HP, rather than a guaranteed
  7. chance whenever HP is less than 25%. This means that fleeing is less predictable
  8. and occurs at lower HP levels.
  9.  
  10. The formula may be worth adjusting still. Particularly the 20 in there. I think
  11. that 20 is a good start, but also the highest it should go. 10 would be the
  12. lowest, I think.
  13.  
  14. This also makes it so fleeing is triggered when a monster is hit, and not just
  15. whenever its HP is low. This includes being hit for 0 damage. This is done to
  16. make it so a monster won't just randomly start fleeing... you have to at least
  17. do something hostile to it first.
  18. ---
  19. crawl-ref/source/mon-behv.cc | 40 ++++++++++++++++++++++++++++------------
  20. 1 files changed, 28 insertions(+), 12 deletions(-)
  21.  
  22. diff --git a/crawl-ref/source/mon-behv.cc b/crawl-ref/source/mon-behv.cc
  23. index 94970eb..d7e63a6 100644
  24. --- a/crawl-ref/source/mon-behv.cc
  25. +++ b/crawl-ref/source/mon-behv.cc
  26. @@ -187,11 +187,9 @@ void handle_behaviour(monster* mon)
  27. proxPlayer = false;
  28. #endif
  29. bool proxFoe;
  30. - bool isHurt = (mon->hit_points <= mon->max_hit_points / 4 - 1);
  31. bool isHealthy = (mon->hit_points > mon->max_hit_points / 2);
  32. bool isSmart = (mons_intel(mon) > I_ANIMAL);
  33. bool isScared = mon->has_ench(ENCH_FEAR);
  34. - bool isMobile = !mons_is_stationary(mon);
  35. bool isPacified = mon->pacified();
  36. bool patrolling = mon->is_patrolling();
  37. static std::vector<level_exit> e;
  38. @@ -611,15 +609,6 @@ void handle_behaviour(monster* mon)
  39. mon->target = menv[mon->foe].pos();
  40. }
  41.  
  42. - // Smart monsters, undead, plants, and nonliving monsters cannot flee.
  43. - if (isHurt && !isSmart && isMobile
  44. - && mon->holiness() != MH_UNDEAD
  45. - && mon->holiness() != MH_PLANT
  46. - && mon->holiness() != MH_NONLIVING
  47. - && !mons_class_flag(mon->type, M_NO_FLEE))
  48. - {
  49. - new_beh = BEH_FLEE;
  50. - }
  51. break;
  52.  
  53. case BEH_WANDER:
  54. @@ -881,7 +870,21 @@ void behaviour_event(monster* mon, mon_event_type event, int src,
  55.  
  56. const beh_type old_behaviour = mon->behaviour;
  57.  
  58. + // Set up random fleeing:
  59. + // Monster can flee if HP is less than 1/4 maxhp or less than 20 hp
  60. + // (whichever is lower). Chance starts quite low, and is 100% at 1 hp.
  61. + // These numbers could still use some adjusting.
  62. + //
  63. + // Assuming fleeThreshold is 20:
  64. + // at 20 hp: 5% chance of fleeing
  65. + // at 10 hp: 55% chance of fleeing
  66. + // (chance increases by 5% for every hp lost.)
  67. + int fleeThreshold = std::min(mon->max_hit_points / 4, 20);
  68. + bool willFlee = x_chance_in_y(fleeThreshold - mon->hit_points + 1,
  69. + fleeThreshold);
  70. +
  71. bool isSmart = (mons_intel(mon) > I_ANIMAL);
  72. + bool isMobile = !mons_is_stationary(mon);
  73. bool wontAttack = mon->wont_attack();
  74. bool sourceWontAttack = false;
  75. bool setTarget = false;
  76. @@ -969,7 +972,7 @@ void behaviour_event(monster* mon, mon_event_type event, int src,
  77. {
  78. mon->behaviour = BEH_RETREAT;
  79. }
  80. - else if (!mons_is_cornered(mon))
  81. + else if (!mons_is_cornered(mon) && (mon->hit_points > fleeThreshold))
  82. mon->behaviour = BEH_SEEK;
  83.  
  84. if (src == MHITYOU)
  85. @@ -987,6 +990,19 @@ void behaviour_event(monster* mon, mon_event_type event, int src,
  86. // invisible foe.
  87. if (event == ME_WHACK)
  88. setTarget = true;
  89. +
  90. + // Smart monsters, undead, plants, and nonliving monsters cannot flee.
  91. + // Cannot flee if cornered. There is also a random chance involved.
  92. + if (willFlee && !isSmart && isMobile
  93. + && mon->holiness() != MH_UNDEAD
  94. + && mon->holiness() != MH_PLANT
  95. + && mon->holiness() != MH_NONLIVING
  96. + && !mons_class_flag(mon->type, M_NO_FLEE)
  97. + && !mons_is_cornered(mon))
  98. + {
  99. + mon->behaviour = BEH_FLEE;
  100. + }
  101. +
  102. break;
  103.  
  104. case ME_ALERT:
  105. --
  106. 1.7.5.GIT
  107.  
  108.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement