wolf_pushwalls.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. Copyright (C) 2004 Michael Liebscher
  3. Copyright (C) 2000-2002 by DarkOne the Hacker
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. /*
  17. * wolf_pushwalls.c: Wolfenstein3-D push-wall handler.
  18. *
  19. * Author: Michael Liebscher <johnnycanuck@users.sourceforge.net>
  20. * Date: 2004
  21. *
  22. * Acknowledgement:
  23. * This code was derived from NewWolf, and was originally
  24. * written by DarkOne the Hacker.
  25. *
  26. */
  27. #include "../wolfiphone.h"
  28. Pwall_t PWall;
  29. /*
  30. -----------------------------------------------------------------------------
  31. Function: PushWall_Reset() -Reset pushwall status.
  32. Parameters: Nothing.
  33. Returns: Nothing.
  34. Notes:
  35. -----------------------------------------------------------------------------
  36. */
  37. PUBLIC void PushWall_Reset(void)
  38. {
  39. memset( &PWall, 0, sizeof( Pwall_t ) );
  40. }
  41. /*
  42. -----------------------------------------------------------------------------
  43. Function: PushWall_Push() -Try to move push-wall.
  44. Parameters: x, y -[in] Coordinates in tilemap.
  45. dir -[in] Direction in which push-wall is intended to move.
  46. Returns: true if push successful, otherwise false.
  47. Notes: Called whenever someone tries to push a secret wall.
  48. -----------------------------------------------------------------------------
  49. */
  50. PUBLIC _boolean PushWall_Push( int x, int y, dir4type dir )
  51. {
  52. int dx, dy;
  53. if( PWall.active )
  54. {
  55. return false; // another PWall is moving [only one at a time!]
  56. }
  57. dx = dx4dir[ dir ];
  58. dy = dy4dir[ dir ];
  59. if( r_world->tilemap[ x + dx ][ y + dy ] & (SOLID_TILE | DOOR_TILE) )
  60. { // noway (smth is blocking)
  61. return true;
  62. }
  63. // remove secret flag & make everything needed when pushwall used!
  64. r_world->tilemap[ x ][ y ] &= (~SECRET_TILE);
  65. r_world->tilemap[ x ][ y ] &= (~WALL_TILE);
  66. r_world->tilemap[ x ][ y ] |= PUSHWALL_TILE;
  67. if ( ++levelstate.found_secrets == levelstate.total_secrets ) {
  68. iphoneSetNotifyText( "You found the last secret!" );
  69. } else {
  70. iphoneSetNotifyText( "You found a secret!" );
  71. }
  72. if( g_version->value == SPEAROFDESTINY && currentMap.episode >= 6 && currentMap.episode < 9)//added the episode check... gsh ).. TODO: fix sfx and other media
  73. {
  74. Sound_StartSound( NULL, 1, CHAN_AUTO, Sound_RegisterSound( "sfx/030.wav" ), 1, ATTN_STATIC, 0 );
  75. }
  76. else
  77. {
  78. Sound_StartSound( NULL, 1, CHAN_AUTO, Sound_RegisterSound( "sfx/034.wav" ), 1, ATTN_STATIC, 0 );
  79. }
  80. // good way to avoid stuckness; [un]comment one more down!
  81. // it makes a tile behind pushwall unpassable
  82. r_world->tilemap[ x + dx ][ y + dy ] |= PUSHWALL_TILE;
  83. r_world->wall_tex_x[ x + dx ][ y + dy ] = r_world->wall_tex_x[ x ][ y ];
  84. r_world->wall_tex_y[ x + dx ][ y + dy ] = r_world->wall_tex_y[ x ][ y ];
  85. // write down PWall info
  86. PWall.active = true;
  87. PWall.PWtilesmoved = PWall.PWpointsmoved = 0;
  88. PWall.dir = dir;
  89. PWall.x = x; PWall.y = y;
  90. PWall.dx = dx; PWall.dy = dy;
  91. PWall.tex_x = r_world->wall_tex_x[ x ][ y ];
  92. PWall.tex_y = r_world->wall_tex_y[ x ][ y ];
  93. return true;
  94. }
  95. /*
  96. -----------------------------------------------------------------------------
  97. Function: PushWall_Process() -Process push-walls.
  98. Parameters: Nothing.
  99. Returns: Nothing.
  100. Notes:
  101. -----------------------------------------------------------------------------
  102. */
  103. PUBLIC void PushWall_Process( void )
  104. {
  105. if( ! PWall.active )
  106. {
  107. return; // no active PWall to work with
  108. }
  109. PWall.PWpointsmoved += tics;
  110. if( PWall.PWpointsmoved < 128 )
  111. {
  112. return;
  113. }
  114. PWall.PWpointsmoved -= 128;
  115. PWall.PWtilesmoved++;
  116. // Free tile
  117. r_world->tilemap[ PWall.x ][ PWall.y ] &= (~PUSHWALL_TILE);
  118. // Occupy new tile
  119. PWall.x += PWall.dx;
  120. PWall.y += PWall.dy;
  121. // Shall we move further?
  122. if( r_world->tilemap[ PWall.x + PWall.dx ][ PWall.y + PWall.dy ] & (SOLID_TILE | DOOR_TILE | ACTOR_TILE | POWERUP_TILE) ||
  123. PWall.PWtilesmoved == 3 )
  124. {
  125. r_world->tilemap[ PWall.x ][ PWall.y ] &= (~PUSHWALL_TILE); // wall now
  126. r_world->tilemap[ PWall.x ][ PWall.y ] |= WALL_TILE; // wall now
  127. r_world->wall_tex_x[ PWall.x ][ PWall.y ] = PWall.tex_x;
  128. r_world->wall_tex_y[ PWall.x ][ PWall.y ] = PWall.tex_y;
  129. PWall.active = false; // Free Push Wall
  130. }
  131. else
  132. {
  133. r_world->tilemap[ PWall.x + PWall.dx ][ PWall.y + PWall.dy ] |= PUSHWALL_TILE;
  134. }
  135. }