1 // Emacs style mode select -*- C++ -*- 2 //----------------------------------------------------------------------------- 3 // 4 // $Id: m_random.h 1511 2020-04-04 08:50:49Z wesleyjohnson $ 5 // 6 // Copyright (C) 1993-1996 by id Software, Inc. 7 // Portions Copyright (C) 1998-2000 by DooM Legacy Team. 8 // 9 // This program is free software; you can redistribute it and/or 10 // modify it under the terms of the GNU General Public License 11 // as published by the Free Software Foundation; either version 2 12 // of the License, or (at your option) any later version. 13 // 14 // This program is distributed in the hope that it will be useful, 15 // but WITHOUT ANY WARRANTY; without even the implied warranty of 16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 // GNU General Public License for more details. 18 // 19 // 20 // $Log: m_random.h,v $ 21 // Revision 1.4 2001/06/10 21:16:01 bpereira 22 // 23 // Revision 1.3 2001/01/25 22:15:42 bpereira 24 // added heretic support 25 // 26 // Revision 1.2 2000/02/27 00:42:10 hurdler 27 // Revision 1.1.1.1 2000/02/22 20:32:32 hurdler 28 // Initial import into CVS (v1.29 pr3) 29 // 30 // 31 // DESCRIPTION: 32 // Random 33 // 34 // 35 //----------------------------------------------------------------------------- 36 37 #ifndef M_RANDOM_H 38 #define M_RANDOM_H 39 40 #include "doomtype.h" 41 42 //#define DEBUGRANDOM 43 44 // For debugging, like in PrBoom 45 //#define PP_RANDOM_EXPOSED 46 47 48 // P_Random: for gameplay decisions, demo sync. 49 // Returns a number from 0 to 255, 50 // from a lookup table. 51 52 #ifdef DEBUGRANDOM 53 #define P_Random() P_RandomFL(__FILE__,__LINE__) 54 #define P_SignedRandom() P_SignedRandomFL(__FILE__,__LINE__) 55 byte P_RandomFL (char *fn, int ln); 56 int P_SignedRandomFL (char *fn, int ln); 57 #else 58 // As M_Random, but used only by the play simulation. 59 byte P_Random (void); 60 int P_SignedRandom (); 61 #endif 62 63 #ifdef PP_RANDOM_EXPOSED 64 // killough 2/16/98: 65 // 66 // Make every random number generator local to each control-equivalent block. 67 // Critical for demo sync. Changing the order of this list breaks all previous 68 // versions' demos. The random number generators are made local to reduce the 69 // chances of sync problems. In Doom, if a single random number generator call 70 // was off, it would mess up all random number generators. This reduces the 71 // chances of it happening by making each RNG local to a control flow block. 72 // 73 // Notes to developers: if you want to reduce your demo sync hassles, follow 74 // this rule: for each call to P_Random you add, add a new class to the enum 75 // type below for each block of code which calls P_Random. If two calls to 76 // P_Random are not in "control-equivalent blocks", i.e. there are any cases 77 // where one is executed, and the other is not, put them in separate classes. 78 // 79 // Keep all current entries in this list the same, and in the order 80 // indicated by the #'s, because they're critical for preserving demo 81 // sync. Do not remove entries simply because they become unused later. 82 83 typedef enum { 84 pr_skullfly, // #1 85 pr_damage, // #2 86 pr_crush, // #3 87 pr_genlift, // #4 88 pr_killtics, // #5 89 pr_damagemobj, // #6 90 pr_painchance, // #7 91 pr_lights, // #8 92 pr_explode, // #9 93 pr_respawn, // #10 94 pr_lastlook, // #11 95 pr_spawnthing, // #12 96 pr_spawnpuff, // #13 97 pr_spawnblood, // #14 98 pr_missile, // #15 99 pr_shadow, // #16 100 pr_plats, // #17 101 pr_punch, // #18 102 pr_punchangle, // #19 103 pr_saw, // #20 104 pr_plasma, // #21 105 pr_gunshot, // #22 106 pr_misfire, // #23 107 pr_shotgun, // #24 108 pr_bfg, // #25 109 pr_slimehurt, // #26 110 pr_dmspawn, // #27 111 pr_missrange, // #28 112 pr_trywalk, // #29 113 pr_newchase, // #30 114 pr_newchasedir, // #31 115 pr_see, // #32 116 pr_facetarget, // #33 117 pr_posattack, // #34 118 pr_sposattack, // #35 119 pr_cposattack, // #36 120 pr_spidrefire, // #37 121 pr_troopattack, // #38 122 pr_sargattack, // #39 123 pr_headattack, // #40 124 pr_bruisattack, // #41 125 pr_tracer, // #42 126 pr_skelfist, // #43 127 pr_scream, // #44 128 pr_brainscream, // #45 129 pr_cposrefire, // #46 130 pr_brainexp, // #47 131 pr_spawnfly, // #48 132 pr_misc, // #49 133 pr_all_in_one, // #50 134 /* CPhipps - new entries from MBF, mostly unused for now */ 135 pr_opendoor, // #51 136 pr_targetsearch, // #52 (unused in MBF) 137 pr_friends, // #53 138 pr_threshold, // #54 (unused in MBF) 139 pr_skiptarget, // #55 140 pr_enemystrafe, // #56 141 pr_avoidcrush, // #57 142 pr_stayonlift, // #58 143 pr_helpfriend, // #59 144 pr_dropoff, // #60 145 pr_randomjump, // #61 146 pr_defect, // #62 // Start new entries -- add new entries below 147 148 // Legacy use of P_Random, Not in Doom, PrBoom, MBF 149 pL_smoketrail, // SmokeTrailer, EV_Legacy 150 pL_smokefeet, // SpawnSmoke, EV_Legacy >= 125 151 pL_splashsound, // SpawnSplash, EV_Legacy >= 125 152 pL_spawnbloodxy, // SpawnBlood, EV_Legacy >= 128 153 pL_bloodsplat, // SpawnBloodSplat, cv_splats 154 pL_bloodtrav, // SpawnBloodSplat, cv_splats 155 pL_initlastlook, // LookForPlayers, EV_Legacy >= 129 156 pL_PRnd, // fragglescript 157 pL_coopthing, // Legacy 1.48: coop mode, cv_deathmatch= COOP_60, COOP_80 158 159 // Heretic 160 ph_heretic, 161 ph_spawnmobjfloat, 162 ph_spawnfloatbob, 163 ph_teleglitter1, 164 ph_teleglitter2, 165 ph_blooddrip, 166 ph_floorwater, 167 ph_floorlava, 168 ph_floorsludge, 169 ph_volcanotic, 170 ph_volcanobl, 171 ph_volcanohit, 172 ph_podgoo, 173 ph_podgoomom, 174 ph_podthrust, 175 ph_lookmon, 176 ph_notseen, 177 ph_ripdam, 178 ph_impattack, 179 ph_impball, 180 ph_impdamage, 181 ph_impexpl, 182 ph_clinkdam, 183 ph_knightaxe, 184 ph_beastpuff, 185 ph_headatk, 186 ph_headdam, 187 ph_headwind, 188 ph_whirlwind, 189 ph_wizscream, 190 ph_sormissile, 191 ph_sorsparkmom, 192 ph_sortele1, 193 ph_sortele2, 194 ph_sordam, 195 ph_soratkdam, 196 ph_minocharge, 197 ph_minofire, 198 ph_minoatk3, 199 ph_minoslam, 200 ph_chickenmorph, 201 ph_chickenthink, 202 ph_beakatk1, 203 ph_beakatk2, 204 ph_chickendam, 205 ph_feathers, 206 ph_morphlast, 207 ph_staffready, 208 ph_staffatk1, 209 ph_staffatk2, 210 ph_goldwandatk1, 211 ph_goldwandatk2, 212 ph_blaster1, 213 ph_blasterthink, 214 ph_boltspark, 215 ph_skullrodatk1, 216 ph_skullrodrain, 217 ph_rainimpact, 218 ph_raindam, 219 ph_phoenix2, 220 ph_phoenixdam2, 221 ph_gauntlet, 222 ph_gauntlet2, 223 ph_macepos1, 224 ph_macepos2, 225 ph_maceatk1, 226 ph_bloodyskullmom, 227 ph_dropitem, 228 ph_dropmom, 229 ph_telearti, 230 231 // End of new entries 232 NUMPRCLASS // MUST be last item in list 233 } pr_class_t; 234 235 byte PP_Random( byte pr ); 236 int PP_SignedRandom( byte pr ); 237 #else 238 239 // MBF, PrBoom 240 // Ignore the pr_class parameter. 241 # define PP_Random(pr) P_Random() 242 # define PP_SignedRandom(pr) P_SignedRandom() 243 #endif 244 245 // New Legacy stuffs, unsynced. 246 byte N_Random(void); 247 int N_SignedRandom(void); 248 249 // M_Random: music, st_stuff, wi_stuff 250 // Returns a number from 0 to 255. 251 byte M_Random (void); 252 253 // separate so to not affect demo playback 254 byte A_Random (void); // ambience 255 byte B_Random (void); // bots etc.. 256 257 // Fix randoms for demos. 258 void M_ClearRandom (void); 259 260 byte P_Rand_GetIndex(void); 261 byte B_Rand_GetIndex(void); 262 263 void P_Rand_SetIndex(byte rindex); 264 void B_Rand_SetIndex(byte rindex); 265 266 // [WDJ] Extended random, has long repeat period. 267 // returns unsigned 16 bit 268 int E_Random(void); 269 // returns -range, 0, +range 270 int E_SignedRandom( int range ); 271 272 // True for the percentage of the calls. 273 #define E_RandomPercent( per ) (E_Random() < ((unsigned int)(per * (0.01f * 0xFFFF)))) 274 275 uint32_t E_Rand_Get( uint32_t * rs ); 276 void E_Rand_Set( uint32_t rn, uint32_t rs ); 277 278 #endif 279