P_LIGHTS.C 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. #include "DoomDef.h"
  2. #include "P_local.h"
  3. //==================================================================
  4. //==================================================================
  5. //
  6. // BROKEN LIGHT FLASHING
  7. //
  8. //==================================================================
  9. //==================================================================
  10. //==================================================================
  11. //
  12. // T_LightFlash
  13. //
  14. // After the map has been loaded, scan each sector for specials
  15. // that spawn thinkers
  16. //
  17. //==================================================================
  18. void T_LightFlash (lightflash_t *flash)
  19. {
  20. if (--flash->count)
  21. return;
  22. if (flash->sector->lightlevel == flash->maxlight)
  23. {
  24. flash-> sector->lightlevel = flash->minlight;
  25. flash->count = (P_Random()&flash->mintime)+1;
  26. }
  27. else
  28. {
  29. flash-> sector->lightlevel = flash->maxlight;
  30. flash->count = (P_Random()&flash->maxtime)+1;
  31. }
  32. }
  33. //==================================================================
  34. //
  35. // P_SpawnLightFlash
  36. //
  37. // After the map has been loaded, scan each sector for specials that spawn thinkers
  38. //
  39. //==================================================================
  40. void P_SpawnLightFlash (sector_t *sector)
  41. {
  42. lightflash_t *flash;
  43. sector->special = 0; // nothing special about it during gameplay
  44. flash = Z_Malloc ( sizeof(*flash), PU_LEVSPEC, 0);
  45. P_AddThinker (&flash->thinker);
  46. flash->thinker.function = T_LightFlash;
  47. flash->sector = sector;
  48. flash->maxlight = sector->lightlevel;
  49. flash->minlight = P_FindMinSurroundingLight(sector,sector->lightlevel);
  50. flash->maxtime = 64;
  51. flash->mintime = 7;
  52. flash->count = (P_Random()&flash->maxtime)+1;
  53. }
  54. //==================================================================
  55. //
  56. // STROBE LIGHT FLASHING
  57. //
  58. //==================================================================
  59. //==================================================================
  60. //
  61. // T_StrobeFlash
  62. //
  63. // After the map has been loaded, scan each sector for specials that spawn thinkers
  64. //
  65. //==================================================================
  66. void T_StrobeFlash (strobe_t *flash)
  67. {
  68. if (--flash->count)
  69. return;
  70. if (flash->sector->lightlevel == flash->minlight)
  71. {
  72. flash-> sector->lightlevel = flash->maxlight;
  73. flash->count = flash->brighttime;
  74. }
  75. else
  76. {
  77. flash-> sector->lightlevel = flash->minlight;
  78. flash->count =flash->darktime;
  79. }
  80. }
  81. //==================================================================
  82. //
  83. // P_SpawnLightFlash
  84. //
  85. // After the map has been loaded, scan each sector for specials that spawn thinkers
  86. //
  87. //==================================================================
  88. void P_SpawnStrobeFlash (sector_t *sector,int fastOrSlow, int inSync)
  89. {
  90. strobe_t *flash;
  91. flash = Z_Malloc ( sizeof(*flash), PU_LEVSPEC, 0);
  92. P_AddThinker (&flash->thinker);
  93. flash->sector = sector;
  94. flash->darktime = fastOrSlow;
  95. flash->brighttime = STROBEBRIGHT;
  96. flash->thinker.function = T_StrobeFlash;
  97. flash->maxlight = sector->lightlevel;
  98. flash->minlight = P_FindMinSurroundingLight(sector, sector->lightlevel);
  99. if (flash->minlight == flash->maxlight)
  100. flash->minlight = 0;
  101. sector->special = 0; // nothing special about it during gameplay
  102. if (!inSync)
  103. flash->count = (P_Random()&7)+1;
  104. else
  105. flash->count = 1;
  106. }
  107. //==================================================================
  108. //
  109. // Start strobing lights (usually from a trigger)
  110. //
  111. //==================================================================
  112. void EV_StartLightStrobing(line_t *line)
  113. {
  114. int secnum;
  115. sector_t *sec;
  116. secnum = -1;
  117. while ((secnum = P_FindSectorFromLineTag(line,secnum)) >= 0)
  118. {
  119. sec = &sectors[secnum];
  120. if (sec->specialdata)
  121. continue;
  122. P_SpawnStrobeFlash (sec,SLOWDARK, 0);
  123. }
  124. }
  125. //==================================================================
  126. //
  127. // TURN LINE'S TAG LIGHTS OFF
  128. //
  129. //==================================================================
  130. void EV_TurnTagLightsOff(line_t *line)
  131. {
  132. int i;
  133. int j;
  134. int min;
  135. sector_t *sector;
  136. sector_t *tsec;
  137. line_t *templine;
  138. sector = sectors;
  139. for (j = 0;j < numsectors; j++, sector++)
  140. if (sector->tag == line->tag)
  141. {
  142. min = sector->lightlevel;
  143. for (i = 0;i < sector->linecount; i++)
  144. {
  145. templine = sector->lines[i];
  146. tsec = getNextSector(templine,sector);
  147. if (!tsec)
  148. continue;
  149. if (tsec->lightlevel < min)
  150. min = tsec->lightlevel;
  151. }
  152. sector->lightlevel = min;
  153. }
  154. }
  155. //==================================================================
  156. //
  157. // TURN LINE'S TAG LIGHTS ON
  158. //
  159. //==================================================================
  160. void EV_LightTurnOn(line_t *line, int bright)
  161. {
  162. int i;
  163. int j;
  164. sector_t *sector;
  165. sector_t *temp;
  166. line_t *templine;
  167. sector = sectors;
  168. for (i=0;i<numsectors;i++, sector++)
  169. if (sector->tag == line->tag)
  170. {
  171. //
  172. // bright = 0 means to search for highest
  173. // light level surrounding sector
  174. //
  175. if (!bright)
  176. {
  177. for (j = 0;j < sector->linecount; j++)
  178. {
  179. templine = sector->lines[j];
  180. temp = getNextSector(templine,sector);
  181. if (!temp)
  182. continue;
  183. if (temp->lightlevel > bright)
  184. bright = temp->lightlevel;
  185. }
  186. }
  187. sector-> lightlevel = bright;
  188. }
  189. }
  190. //==================================================================
  191. //
  192. // Spawn glowing light
  193. //
  194. //==================================================================
  195. void T_Glow(glow_t *g)
  196. {
  197. switch(g->direction)
  198. {
  199. case -1: // DOWN
  200. g->sector->lightlevel -= GLOWSPEED;
  201. if (g->sector->lightlevel <= g->minlight)
  202. {
  203. g->sector->lightlevel += GLOWSPEED;
  204. g->direction = 1;
  205. }
  206. break;
  207. case 1: // UP
  208. g->sector->lightlevel += GLOWSPEED;
  209. if (g->sector->lightlevel >= g->maxlight)
  210. {
  211. g->sector->lightlevel -= GLOWSPEED;
  212. g->direction = -1;
  213. }
  214. break;
  215. }
  216. }
  217. void P_SpawnGlowingLight(sector_t *sector)
  218. {
  219. glow_t *g;
  220. g = Z_Malloc( sizeof(*g), PU_LEVSPEC, 0);
  221. P_AddThinker(&g->thinker);
  222. g->sector = sector;
  223. g->minlight = P_FindMinSurroundingLight(sector,sector->lightlevel);
  224. g->maxlight = sector->lightlevel;
  225. g->thinker.function = T_Glow;
  226. g->direction = -1;
  227. sector->special = 0;
  228. }