P_SWITCH.C 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //**************************************************************************
  2. //**
  3. //** p_switch.c : Heretic 2 : Raven Software, Corp.
  4. //**
  5. //** $RCSfile: p_switch.c,v $
  6. //** $Revision: 1.8 $
  7. //** $Date: 95/09/05 13:58:59 $
  8. //** $Author: cjr $
  9. //**
  10. //**************************************************************************
  11. #include "h2def.h"
  12. #include "p_local.h"
  13. #include "soundst.h"
  14. //==================================================================
  15. //
  16. // CHANGE THE TEXTURE OF A WALL SWITCH TO ITS OPPOSITE
  17. //
  18. //==================================================================
  19. switchlist_t alphSwitchList[] =
  20. {
  21. { "SW_1_UP", "SW_1_DN", SFX_SWITCH1 },
  22. { "SW_2_UP", "SW_2_DN", SFX_SWITCH1 },
  23. { "VALVE1", "VALVE2", SFX_VALVE_TURN },
  24. { "SW51_OFF", "SW51_ON", SFX_SWITCH2 },
  25. { "SW52_OFF", "SW52_ON", SFX_SWITCH2 },
  26. { "SW53_UP", "SW53_DN", SFX_ROPE_PULL },
  27. { "PUZZLE5", "PUZZLE9", SFX_SWITCH1 },
  28. { "PUZZLE6", "PUZZLE10", SFX_SWITCH1 },
  29. { "PUZZLE7", "PUZZLE11", SFX_SWITCH1 },
  30. { "PUZZLE8", "PUZZLE12", SFX_SWITCH1 },
  31. {"\0", "\0", 0}
  32. };
  33. int switchlist[MAXSWITCHES * 2];
  34. int numswitches;
  35. button_t buttonlist[MAXBUTTONS];
  36. /*
  37. ===============
  38. =
  39. = P_InitSwitchList
  40. =
  41. = Only called at game initialization
  42. =
  43. ===============
  44. */
  45. void P_InitSwitchList(void)
  46. {
  47. int i;
  48. int index;
  49. for (index = 0, i = 0; i < MAXSWITCHES; i++)
  50. {
  51. if(!alphSwitchList[i].soundID)
  52. {
  53. numswitches = index/2;
  54. switchlist[index] = -1;
  55. break;
  56. }
  57. switchlist[index++] = R_TextureNumForName(alphSwitchList[i].name1);
  58. switchlist[index++] = R_TextureNumForName(alphSwitchList[i].name2);
  59. }
  60. }
  61. //==================================================================
  62. //
  63. // Start a button counting down till it turns off.
  64. //
  65. //==================================================================
  66. void P_StartButton(line_t *line,bwhere_e w,int texture,int time)
  67. {
  68. int i;
  69. for (i = 0;i < MAXBUTTONS;i++)
  70. {
  71. if (!buttonlist[i].btimer)
  72. {
  73. buttonlist[i].line = line;
  74. buttonlist[i].where = w;
  75. buttonlist[i].btexture = texture;
  76. buttonlist[i].btimer = time;
  77. buttonlist[i].soundorg = (mobj_t *)&line->frontsector->soundorg;
  78. return;
  79. }
  80. }
  81. I_Error("P_StartButton: no button slots left!");
  82. }
  83. //==================================================================
  84. //
  85. // Function that changes wall texture.
  86. // Tell it if switch is ok to use again (1=yes, it's a button).
  87. //
  88. //==================================================================
  89. void P_ChangeSwitchTexture(line_t *line, int useAgain)
  90. {
  91. int texTop;
  92. int texMid;
  93. int texBot;
  94. int i;
  95. texTop = sides[line->sidenum[0]].toptexture;
  96. texMid = sides[line->sidenum[0]].midtexture;
  97. texBot = sides[line->sidenum[0]].bottomtexture;
  98. for (i = 0; i < numswitches*2; i++)
  99. {
  100. if (switchlist[i] == texTop)
  101. {
  102. S_StartSound((mobj_t *)&line->frontsector->soundorg,
  103. alphSwitchList[i/2].soundID);
  104. sides[line->sidenum[0]].toptexture = switchlist[i^1];
  105. if(useAgain)
  106. {
  107. P_StartButton(line, SWTCH_TOP, switchlist[i], BUTTONTIME);
  108. }
  109. return;
  110. }
  111. else if (switchlist[i] == texMid)
  112. {
  113. S_StartSound((mobj_t *)&line->frontsector->soundorg,
  114. alphSwitchList[i/2].soundID);
  115. sides[line->sidenum[0]].midtexture = switchlist[i^1];
  116. if(useAgain)
  117. {
  118. P_StartButton(line, SWTCH_MIDDLE, switchlist[i], BUTTONTIME);
  119. }
  120. return;
  121. }
  122. else if (switchlist[i] == texBot)
  123. {
  124. S_StartSound((mobj_t *)&line->frontsector->soundorg,
  125. alphSwitchList[i/2].soundID);
  126. sides[line->sidenum[0]].bottomtexture = switchlist[i^1];
  127. if(useAgain)
  128. {
  129. P_StartButton(line, SWTCH_BOTTOM, switchlist[i], BUTTONTIME);
  130. }
  131. return;
  132. }
  133. }
  134. }