m_random.h.svn-base 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* Emacs style mode select -*- C++ -*-
  2. *-----------------------------------------------------------------------------
  3. *
  4. *
  5. * PrBoom: a Doom port merged with LxDoom and LSDLDoom
  6. * based on BOOM, a modified and improved DOOM engine
  7. * Copyright (C) 1999 by
  8. * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
  9. * Copyright (C) 1999-2000 by
  10. * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
  11. * Copyright 2005, 2006 by
  12. * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version 2
  17. * of the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  27. * 02111-1307, USA.
  28. *
  29. * DESCRIPTION:
  30. * Functions to return random numbers.
  31. *
  32. *-----------------------------------------------------------------------------*/
  33. #ifndef __M_RANDOM__
  34. #define __M_RANDOM__
  35. #include "doomtype.h"
  36. // killough 1/19/98: rewritten to use to use a better random number generator
  37. // in the new engine, although the old one is available for compatibility.
  38. // killough 2/16/98:
  39. //
  40. // Make every random number generator local to each control-equivalent block.
  41. // Critical for demo sync. Changing the order of this list breaks all previous
  42. // versions' demos. The random number generators are made local to reduce the
  43. // chances of sync problems. In Doom, if a single random number generator call
  44. // was off, it would mess up all random number generators. This reduces the
  45. // chances of it happening by making each RNG local to a control flow block.
  46. //
  47. // Notes to developers: if you want to reduce your demo sync hassles, follow
  48. // this rule: for each call to P_Random you add, add a new class to the enum
  49. // type below for each block of code which calls P_Random. If two calls to
  50. // P_Random are not in "control-equivalent blocks", i.e. there are any cases
  51. // where one is executed, and the other is not, put them in separate classes.
  52. //
  53. // Keep all current entries in this list the same, and in the order
  54. // indicated by the #'s, because they're critical for preserving demo
  55. // sync. Do not remove entries simply because they become unused later.
  56. typedef enum {
  57. pr_skullfly, // #1
  58. pr_damage, // #2
  59. pr_crush, // #3
  60. pr_genlift, // #4
  61. pr_killtics, // #5
  62. pr_damagemobj, // #6
  63. pr_painchance, // #7
  64. pr_lights, // #8
  65. pr_explode, // #9
  66. pr_respawn, // #10
  67. pr_lastlook, // #11
  68. pr_spawnthing, // #12
  69. pr_spawnpuff, // #13
  70. pr_spawnblood, // #14
  71. pr_missile, // #15
  72. pr_shadow, // #16
  73. pr_plats, // #17
  74. pr_punch, // #18
  75. pr_punchangle, // #19
  76. pr_saw, // #20
  77. pr_plasma, // #21
  78. pr_gunshot, // #22
  79. pr_misfire, // #23
  80. pr_shotgun, // #24
  81. pr_bfg, // #25
  82. pr_slimehurt, // #26
  83. pr_dmspawn, // #27
  84. pr_missrange, // #28
  85. pr_trywalk, // #29
  86. pr_newchase, // #30
  87. pr_newchasedir, // #31
  88. pr_see, // #32
  89. pr_facetarget, // #33
  90. pr_posattack, // #34
  91. pr_sposattack, // #35
  92. pr_cposattack, // #36
  93. pr_spidrefire, // #37
  94. pr_troopattack, // #38
  95. pr_sargattack, // #39
  96. pr_headattack, // #40
  97. pr_bruisattack, // #41
  98. pr_tracer, // #42
  99. pr_skelfist, // #43
  100. pr_scream, // #44
  101. pr_brainscream, // #45
  102. pr_cposrefire, // #46
  103. pr_brainexp, // #47
  104. pr_spawnfly, // #48
  105. pr_misc, // #49
  106. pr_all_in_one, // #50
  107. /* CPhipps - new entries from MBF, mostly unused for now */
  108. pr_opendoor, // #51
  109. pr_targetsearch, // #52
  110. pr_friends, // #53
  111. pr_threshold, // #54
  112. pr_skiptarget, // #55
  113. pr_enemystrafe, // #56
  114. pr_avoidcrush, // #57
  115. pr_stayonlift, // #58
  116. pr_helpfriend, // #59
  117. pr_dropoff, // #60
  118. pr_randomjump, // #61
  119. pr_defect, // #62 // Start new entries -- add new entries below
  120. // End of new entries
  121. NUMPRCLASS // MUST be last item in list
  122. } pr_class_t;
  123. // The random number generator's state.
  124. typedef struct {
  125. unsigned long seed[NUMPRCLASS]; // Each block's random seed
  126. int rndindex, prndindex; // For compatibility support
  127. } rng_t;
  128. extern rng_t rng; // The rng's state
  129. extern unsigned long rngseed; // The starting seed (not part of state)
  130. // As M_Random, but used by the play simulation.
  131. int P_Random(pr_class_t DA(const char *, int));
  132. #ifdef INSTRUMENTED
  133. #define P_Random(a) (P_Random) (a, __FILE__,__LINE__)
  134. #endif
  135. // Returns a number from 0 to 255,
  136. #define M_Random() P_Random(pr_misc)
  137. // Fix randoms for demos.
  138. void M_ClearRandom(void);
  139. #endif