home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #2 / amigaacscoverdisc1998-021998.iso / games / doom / source / linuxdoom-1.10 / p_switch.c < prev    next >
C/C++ Source or Header  |  1997-12-22  |  13KB  |  655 lines

  1. // Emacs style mode select   -*- C++ -*- 
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. //
  18. // $Log:$
  19. //
  20. // DESCRIPTION:
  21. //    Switches, buttons. Two-state animation. Exits.
  22. //
  23. //-----------------------------------------------------------------------------
  24.  
  25. static const char
  26. rcsid[] = "$Id: p_switch.c,v 1.3 1997/01/28 22:08:29 b1 Exp $";
  27.  
  28.  
  29. #include "i_system.h"
  30. #include "doomdef.h"
  31. #include "p_local.h"
  32.  
  33. #include "g_game.h"
  34.  
  35. #include "s_sound.h"
  36.  
  37. // Data.
  38. #include "sounds.h"
  39.  
  40. // State.
  41. #include "doomstat.h"
  42. #include "r_state.h"
  43.  
  44.  
  45. //
  46. // CHANGE THE TEXTURE OF A WALL SWITCH TO ITS OPPOSITE
  47. //
  48. switchlist_t alphSwitchList[] =
  49. {
  50.     // Doom shareware episode 1 switches
  51.     {"SW1BRCOM",    "SW2BRCOM",    1},
  52.     {"SW1BRN1",    "SW2BRN1",    1},
  53.     {"SW1BRN2",    "SW2BRN2",    1},
  54.     {"SW1BRNGN",    "SW2BRNGN",    1},
  55.     {"SW1BROWN",    "SW2BROWN",    1},
  56.     {"SW1COMM",    "SW2COMM",    1},
  57.     {"SW1COMP",    "SW2COMP",    1},
  58.     {"SW1DIRT",    "SW2DIRT",    1},
  59.     {"SW1EXIT",    "SW2EXIT",    1},
  60.     {"SW1GRAY",    "SW2GRAY",    1},
  61.     {"SW1GRAY1",    "SW2GRAY1",    1},
  62.     {"SW1METAL",    "SW2METAL",    1},
  63.     {"SW1PIPE",    "SW2PIPE",    1},
  64.     {"SW1SLAD",    "SW2SLAD",    1},
  65.     {"SW1STARG",    "SW2STARG",    1},
  66.     {"SW1STON1",    "SW2STON1",    1},
  67.     {"SW1STON2",    "SW2STON2",    1},
  68.     {"SW1STONE",    "SW2STONE",    1},
  69.     {"SW1STRTN",    "SW2STRTN",    1},
  70.     
  71.     // Doom registered episodes 2&3 switches
  72.     {"SW1BLUE",    "SW2BLUE",    2},
  73.     {"SW1CMT",        "SW2CMT",    2},
  74.     {"SW1GARG",    "SW2GARG",    2},
  75.     {"SW1GSTON",    "SW2GSTON",    2},
  76.     {"SW1HOT",        "SW2HOT",    2},
  77.     {"SW1LION",    "SW2LION",    2},
  78.     {"SW1SATYR",    "SW2SATYR",    2},
  79.     {"SW1SKIN",    "SW2SKIN",    2},
  80.     {"SW1VINE",    "SW2VINE",    2},
  81.     {"SW1WOOD",    "SW2WOOD",    2},
  82.     
  83.     // Doom II switches
  84.     {"SW1PANEL",    "SW2PANEL",    3},
  85.     {"SW1ROCK",    "SW2ROCK",    3},
  86.     {"SW1MET2",    "SW2MET2",    3},
  87.     {"SW1WDMET",    "SW2WDMET",    3},
  88.     {"SW1BRIK",    "SW2BRIK",    3},
  89.     {"SW1MOD1",    "SW2MOD1",    3},
  90.     {"SW1ZIM",        "SW2ZIM",    3},
  91.     {"SW1STON6",    "SW2STON6",    3},
  92.     {"SW1TEK",        "SW2TEK",    3},
  93.     {"SW1MARB",    "SW2MARB",    3},
  94.     {"SW1SKULL",    "SW2SKULL",    3},
  95.     
  96.     {"\0",        "\0",        0}
  97. };
  98.  
  99. int        switchlist[MAXSWITCHES * 2];
  100. int        numswitches;
  101. button_t        buttonlist[MAXBUTTONS];
  102.  
  103. //
  104. // P_InitSwitchList
  105. // Only called at game initialization.
  106. //
  107. void P_InitSwitchList(void)
  108. {
  109.     int        i;
  110.     int        index;
  111.     int        episode;
  112.     
  113.     episode = 1;
  114.  
  115.     if (gamemode == registered)
  116.     episode = 2;
  117.     else
  118.     if ( gamemode == commercial )
  119.         episode = 3;
  120.         
  121.     for (index = 0,i = 0;i < MAXSWITCHES;i++)
  122.     {
  123.     if (!alphSwitchList[i].episode)
  124.     {
  125.         numswitches = index/2;
  126.         switchlist[index] = -1;
  127.         break;
  128.     }
  129.         
  130.     if (alphSwitchList[i].episode <= episode)
  131.     {
  132. #if 0    // UNUSED - debug?
  133.         int        value;
  134.             
  135.         if (R_CheckTextureNumForName(alphSwitchList[i].name1) < 0)
  136.         {
  137.         I_Error("Can't find switch texture '%s'!",
  138.             alphSwitchList[i].name1);
  139.         continue;
  140.         }
  141.         
  142.         value = R_TextureNumForName(alphSwitchList[i].name1);
  143. #endif
  144.         switchlist[index++] = R_TextureNumForName(alphSwitchList[i].name1);
  145.         switchlist[index++] = R_TextureNumForName(alphSwitchList[i].name2);
  146.     }
  147.     }
  148. }
  149.  
  150.  
  151. //
  152. // Start a button counting down till it turns off.
  153. //
  154. void
  155. P_StartButton
  156. ( line_t*    line,
  157.   bwhere_e    w,
  158.   int        texture,
  159.   int        time )
  160. {
  161.     int        i;
  162.     
  163.     // See if button is already pressed
  164.     for (i = 0;i < MAXBUTTONS;i++)
  165.     {
  166.     if (buttonlist[i].btimer
  167.         && buttonlist[i].line == line)
  168.     {
  169.         
  170.         return;
  171.     }
  172.     }
  173.     
  174.  
  175.     
  176.     for (i = 0;i < MAXBUTTONS;i++)
  177.     {
  178.     if (!buttonlist[i].btimer)
  179.     {
  180.         buttonlist[i].line = line;
  181.         buttonlist[i].where = w;
  182.         buttonlist[i].btexture = texture;
  183.         buttonlist[i].btimer = time;
  184.         buttonlist[i].soundorg = (mobj_t *)&line->frontsector->soundorg;
  185.         return;
  186.     }
  187.     }
  188.     
  189.     I_Error("P_StartButton: no button slots left!");
  190. }
  191.  
  192.  
  193.  
  194.  
  195.  
  196. //
  197. // Function that changes wall texture.
  198. // Tell it if switch is ok to use again (1=yes, it's a button).
  199. //
  200. void
  201. P_ChangeSwitchTexture
  202. ( line_t*    line,
  203.   int         useAgain )
  204. {
  205.     int     texTop;
  206.     int     texMid;
  207.     int     texBot;
  208.     int     i;
  209.     int     sound;
  210.     
  211.     if (!useAgain)
  212.     line->special = 0;
  213.  
  214.     texTop = sides[line->sidenum[0]].toptexture;
  215.     texMid = sides[line->sidenum[0]].midtexture;
  216.     texBot = sides[line->sidenum[0]].bottomtexture;
  217.     
  218.     sound = sfx_swtchn;
  219.  
  220.     // EXIT SWITCH?
  221.     if (line->special == 11)                
  222.     sound = sfx_swtchx;
  223.     
  224.     for (i = 0;i < numswitches*2;i++)
  225.     {
  226.     if (switchlist[i] == texTop)
  227.     {
  228.         S_StartSound(buttonlist->soundorg,sound);
  229.         sides[line->sidenum[0]].toptexture = switchlist[i^1];
  230.  
  231.         if (useAgain)
  232.         P_StartButton(line,top,switchlist[i],BUTTONTIME);
  233.  
  234.         return;
  235.     }
  236.     else
  237.     {
  238.         if (switchlist[i] == texMid)
  239.         {
  240.         S_StartSound(buttonlist->soundorg,sound);
  241.         sides[line->sidenum[0]].midtexture = switchlist[i^1];
  242.  
  243.         if (useAgain)
  244.             P_StartButton(line, middle,switchlist[i],BUTTONTIME);
  245.  
  246.         return;
  247.         }
  248.         else
  249.         {
  250.         if (switchlist[i] == texBot)
  251.         {
  252.             S_StartSound(buttonlist->soundorg,sound);
  253.             sides[line->sidenum[0]].bottomtexture = switchlist[i^1];
  254.  
  255.             if (useAgain)
  256.             P_StartButton(line, bottom,switchlist[i],BUTTONTIME);
  257.  
  258.             return;
  259.         }
  260.         }
  261.     }
  262.     }
  263. }
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270. //
  271. // P_UseSpecialLine
  272. // Called when a thing uses a special line.
  273. // Only the front sides of lines are usable.
  274. //
  275. boolean
  276. P_UseSpecialLine
  277. ( mobj_t*    thing,
  278.   line_t*    line,
  279.   int        side )
  280. {               
  281.  
  282.     // Err...
  283.     // Use the back sides of VERY SPECIAL lines...
  284.     if (side)
  285.     {
  286.     switch(line->special)
  287.     {
  288.       case 124:
  289.         // Sliding door open&close
  290.         // UNUSED?
  291.         break;
  292.  
  293.       default:
  294.         return false;
  295.         break;
  296.     }
  297.     }
  298.  
  299.     
  300.     // Switches that other things can activate.
  301.     if (!thing->player)
  302.     {
  303.     // never open secret doors
  304.     if (line->flags & ML_SECRET)
  305.         return false;
  306.     
  307.     switch(line->special)
  308.     {
  309.       case 1:     // MANUAL DOOR RAISE
  310.       case 32:    // MANUAL BLUE
  311.       case 33:    // MANUAL RED
  312.       case 34:    // MANUAL YELLOW
  313.         break;
  314.         
  315.       default:
  316.         return false;
  317.         break;
  318.     }
  319.     }
  320.  
  321.     
  322.     // do something  
  323.     switch (line->special)
  324.     {
  325.     // MANUALS
  326.       case 1:        // Vertical Door
  327.       case 26:        // Blue Door/Locked
  328.       case 27:        // Yellow Door /Locked
  329.       case 28:        // Red Door /Locked
  330.  
  331.       case 31:        // Manual door open
  332.       case 32:        // Blue locked door open
  333.       case 33:        // Red locked door open
  334.       case 34:        // Yellow locked door open
  335.  
  336.       case 117:        // Blazing door raise
  337.       case 118:        // Blazing door open
  338.     EV_VerticalDoor (line, thing);
  339.     break;
  340.     
  341.     //UNUSED - Door Slide Open&Close
  342.     // case 124:
  343.     // EV_SlidingDoor (line, thing);
  344.     // break;
  345.  
  346.     // SWITCHES
  347.       case 7:
  348.     // Build Stairs
  349.     if (EV_BuildStairs(line,build8))
  350.         P_ChangeSwitchTexture(line,0);
  351.     break;
  352.  
  353.       case 9:
  354.     // Change Donut
  355.     if (EV_DoDonut(line))
  356.         P_ChangeSwitchTexture(line,0);
  357.     break;
  358.     
  359.       case 11:
  360.     // Exit level
  361.     P_ChangeSwitchTexture(line,0);
  362.     G_ExitLevel ();
  363.     break;
  364.     
  365.       case 14:
  366.     // Raise Floor 32 and change texture
  367.     if (EV_DoPlat(line,raiseAndChange,32))
  368.         P_ChangeSwitchTexture(line,0);
  369.     break;
  370.     
  371.       case 15:
  372.     // Raise Floor 24 and change texture
  373.     if (EV_DoPlat(line,raiseAndChange,24))
  374.         P_ChangeSwitchTexture(line,0);
  375.     break;
  376.     
  377.       case 18:
  378.     // Raise Floor to next highest floor
  379.     if (EV_DoFloor(line, raiseFloorToNearest))
  380.         P_ChangeSwitchTexture(line,0);
  381.     break;
  382.     
  383.       case 20:
  384.     // Raise Plat next highest floor and change texture
  385.     if (EV_DoPlat(line,raiseToNearestAndChange,0))
  386.         P_ChangeSwitchTexture(line,0);
  387.     break;
  388.     
  389.       case 21:
  390.     // PlatDownWaitUpStay
  391.     if (EV_DoPlat(line,downWaitUpStay,0))
  392.         P_ChangeSwitchTexture(line,0);
  393.     break;
  394.     
  395.       case 23:
  396.     // Lower Floor to Lowest
  397.     if (EV_DoFloor(line,lowerFloorToLowest))
  398.         P_ChangeSwitchTexture(line,0);
  399.     break;
  400.     
  401.       case 29:
  402.     // Raise Door
  403.     if (EV_DoDoor(line,normal))
  404.         P_ChangeSwitchTexture(line,0);
  405.     break;
  406.     
  407.       case 41:
  408.     // Lower Ceiling to Floor
  409.     if (EV_DoCeiling(line,lowerToFloor))
  410.         P_ChangeSwitchTexture(line,0);
  411.     break;
  412.     
  413.       case 71:
  414.     // Turbo Lower Floor
  415.     if (EV_DoFloor(line,turboLower))
  416.         P_ChangeSwitchTexture(line,0);
  417.     break;
  418.     
  419.       case 49:
  420.     // Ceiling Crush And Raise
  421.     if (EV_DoCeiling(line,crushAndRaise))
  422.         P_ChangeSwitchTexture(line,0);
  423.     break;
  424.     
  425.       case 50:
  426.     // Close Door
  427.     if (EV_DoDoor(line,close))
  428.         P_ChangeSwitchTexture(line,0);
  429.     break;
  430.     
  431.       case 51:
  432.     // Secret EXIT
  433.     P_ChangeSwitchTexture(line,0);
  434.     G_SecretExitLevel ();
  435.     break;
  436.     
  437.       case 55:
  438.     // Raise Floor Crush
  439.     if (EV_DoFloor(line,raiseFloorCrush))
  440.         P_ChangeSwitchTexture(line,0);
  441.     break;
  442.     
  443.       case 101:
  444.     // Raise Floor
  445.     if (EV_DoFloor(line,raiseFloor))
  446.         P_ChangeSwitchTexture(line,0);
  447.     break;
  448.     
  449.       case 102:
  450.     // Lower Floor to Surrounding floor height
  451.     if (EV_DoFloor(line,lowerFloor))
  452.         P_ChangeSwitchTexture(line,0);
  453.     break;
  454.     
  455.       case 103:
  456.     // Open Door
  457.     if (EV_DoDoor(line,open))
  458.         P_ChangeSwitchTexture(line,0);
  459.     break;
  460.     
  461.       case 111:
  462.     // Blazing Door Raise (faster than TURBO!)
  463.     if (EV_DoDoor (line,blazeRaise))
  464.         P_ChangeSwitchTexture(line,0);
  465.     break;
  466.     
  467.       case 112:
  468.     // Blazing Door Open (faster than TURBO!)
  469.     if (EV_DoDoor (line,blazeOpen))
  470.         P_ChangeSwitchTexture(line,0);
  471.     break;
  472.     
  473.       case 113:
  474.     // Blazing Door Close (faster than TURBO!)
  475.     if (EV_DoDoor (line,blazeClose))
  476.         P_ChangeSwitchTexture(line,0);
  477.     break;
  478.     
  479.       case 122:
  480.     // Blazing PlatDownWaitUpStay
  481.     if (EV_DoPlat(line,blazeDWUS,0))
  482.         P_ChangeSwitchTexture(line,0);
  483.     break;
  484.     
  485.       case 127:
  486.     // Build Stairs Turbo 16
  487.     if (EV_BuildStairs(line,turbo16))
  488.         P_ChangeSwitchTexture(line,0);
  489.     break;
  490.     
  491.       case 131:
  492.     // Raise Floor Turbo
  493.     if (EV_DoFloor(line,raiseFloorTurbo))
  494.         P_ChangeSwitchTexture(line,0);
  495.     break;
  496.     
  497.       case 133:
  498.     // BlzOpenDoor BLUE
  499.       case 135:
  500.     // BlzOpenDoor RED
  501.       case 137:
  502.     // BlzOpenDoor YELLOW
  503.     if (EV_DoLockedDoor (line,blazeOpen,thing))
  504.         P_ChangeSwitchTexture(line,0);
  505.     break;
  506.     
  507.       case 140:
  508.     // Raise Floor 512
  509.     if (EV_DoFloor(line,raiseFloor512))
  510.         P_ChangeSwitchTexture(line,0);
  511.     break;
  512.     
  513.     // BUTTONS
  514.       case 42:
  515.     // Close Door
  516.     if (EV_DoDoor(line,close))
  517.         P_ChangeSwitchTexture(line,1);
  518.     break;
  519.     
  520.       case 43:
  521.     // Lower Ceiling to Floor
  522.     if (EV_DoCeiling(line,lowerToFloor))
  523.         P_ChangeSwitchTexture(line,1);
  524.     break;
  525.     
  526.       case 45:
  527.     // Lower Floor to Surrounding floor height
  528.     if (EV_DoFloor(line,lowerFloor))
  529.         P_ChangeSwitchTexture(line,1);
  530.     break;
  531.     
  532.       case 60:
  533.     // Lower Floor to Lowest
  534.     if (EV_DoFloor(line,lowerFloorToLowest))
  535.         P_ChangeSwitchTexture(line,1);
  536.     break;
  537.     
  538.       case 61:
  539.     // Open Door
  540.     if (EV_DoDoor(line,open))
  541.         P_ChangeSwitchTexture(line,1);
  542.     break;
  543.     
  544.       case 62:
  545.     // PlatDownWaitUpStay
  546.     if (EV_DoPlat(line,downWaitUpStay,1))
  547.         P_ChangeSwitchTexture(line,1);
  548.     break;
  549.     
  550.       case 63:
  551.     // Raise Door
  552.     if (EV_DoDoor(line,normal))
  553.         P_ChangeSwitchTexture(line,1);
  554.     break;
  555.     
  556.       case 64:
  557.     // Raise Floor to ceiling
  558.     if (EV_DoFloor(line,raiseFloor))
  559.         P_ChangeSwitchTexture(line,1);
  560.     break;
  561.     
  562.       case 66:
  563.     // Raise Floor 24 and change texture
  564.     if (EV_DoPlat(line,raiseAndChange,24))
  565.         P_ChangeSwitchTexture(line,1);
  566.     break;
  567.     
  568.       case 67:
  569.     // Raise Floor 32 and change texture
  570.     if (EV_DoPlat(line,raiseAndChange,32))
  571.         P_ChangeSwitchTexture(line,1);
  572.     break;
  573.     
  574.       case 65:
  575.     // Raise Floor Crush
  576.     if (EV_DoFloor(line,raiseFloorCrush))
  577.         P_ChangeSwitchTexture(line,1);
  578.     break;
  579.     
  580.       case 68:
  581.     // Raise Plat to next highest floor and change texture
  582.     if (EV_DoPlat(line,raiseToNearestAndChange,0))
  583.         P_ChangeSwitchTexture(line,1);
  584.     break;
  585.     
  586.       case 69:
  587.     // Raise Floor to next highest floor
  588.     if (EV_DoFloor(line, raiseFloorToNearest))
  589.         P_ChangeSwitchTexture(line,1);
  590.     break;
  591.     
  592.       case 70:
  593.     // Turbo Lower Floor
  594.     if (EV_DoFloor(line,turboLower))
  595.         P_ChangeSwitchTexture(line,1);
  596.     break;
  597.     
  598.       case 114:
  599.     // Blazing Door Raise (faster than TURBO!)
  600.     if (EV_DoDoor (line,blazeRaise))
  601.         P_ChangeSwitchTexture(line,1);
  602.     break;
  603.     
  604.       case 115:
  605.     // Blazing Door Open (faster than TURBO!)
  606.     if (EV_DoDoor (line,blazeOpen))
  607.         P_ChangeSwitchTexture(line,1);
  608.     break;
  609.     
  610.       case 116:
  611.     // Blazing Door Close (faster than TURBO!)
  612.     if (EV_DoDoor (line,blazeClose))
  613.         P_ChangeSwitchTexture(line,1);
  614.     break;
  615.     
  616.       case 123:
  617.     // Blazing PlatDownWaitUpStay
  618.     if (EV_DoPlat(line,blazeDWUS,0))
  619.         P_ChangeSwitchTexture(line,1);
  620.     break;
  621.     
  622.       case 132:
  623.     // Raise Floor Turbo
  624.     if (EV_DoFloor(line,raiseFloorTurbo))
  625.         P_ChangeSwitchTexture(line,1);
  626.     break;
  627.     
  628.       case 99:
  629.     // BlzOpenDoor BLUE
  630.       case 134:
  631.     // BlzOpenDoor RED
  632.       case 136:
  633.     // BlzOpenDoor YELLOW
  634.     if (EV_DoLockedDoor (line,blazeOpen,thing))
  635.         P_ChangeSwitchTexture(line,1);
  636.     break;
  637.     
  638.       case 138:
  639.     // Light Turn On
  640.     EV_LightTurnOn(line,255);
  641.     P_ChangeSwitchTexture(line,1);
  642.     break;
  643.     
  644.       case 139:
  645.     // Light Turn Off
  646.     EV_LightTurnOn(line,35);
  647.     P_ChangeSwitchTexture(line,1);
  648.     break;
  649.             
  650.     }
  651.     
  652.     return true;
  653. }
  654.  
  655.