FLY.CPP 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. ** Command & Conquer(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* $Header: F:\projects\c&c\vcs\code\fly.cpv 2.18 16 Oct 1995 16:50:40 JOE_BOSTIC $ */
  19. /***********************************************************************************************
  20. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Command & Conquer *
  24. * *
  25. * File Name : FLY.CPP *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : April 24, 1994 *
  30. * *
  31. * Last Update : June 5, 1995 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * FlyClass::Physics -- Performs vector physics (movement). *
  36. * FlyClass::Fly_Speed -- Sets the flying object to the speed specified. *
  37. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  38. #include "function.h"
  39. /***********************************************************************************************
  40. * FlyClass::Physics -- Performs vector physics (movement). *
  41. * *
  42. * This routine performs movement (vector) physics. It takes the *
  43. * specified location and moves it according to the facing and speed *
  44. * of the vector. It returns the status of the move. *
  45. * *
  46. * INPUT: coord -- Reference to the coordinate that the vector will *
  47. * be applied to. *
  48. * *
  49. * OUTPUT: Returns with the status of the vector physics. This could *
  50. * range from no effect, to exiting the edge of the world. *
  51. * *
  52. * WARNINGS: none *
  53. * *
  54. * HISTORY: *
  55. * 04/24/1994 JLB : Created. *
  56. * 06/05/1995 JLB : Simplified to just do movement. *
  57. *=============================================================================================*/
  58. ImpactType FlyClass::Physics(COORDINATE & coord, DirType facing)
  59. {
  60. if (SpeedAdd != MPH_IMMOBILE) {
  61. int actual = (int)SpeedAdd + SpeedAccum;
  62. div_t result = div(actual, PIXEL_LEPTON_W);
  63. SpeedAccum = result.rem;
  64. actual -= result.rem;
  65. COORDINATE old = coord;
  66. /*
  67. ** If movement occurred that is at least one
  68. ** pixel, then check update the coordinate and
  69. ** check for edge of world collision.
  70. */
  71. if (result.quot) {
  72. COORDINATE newcoord; // New working coordinate.
  73. newcoord = Coord_Move(coord, facing, actual);
  74. /*
  75. ** If no movement occurred, then presume it hasn't moved at all
  76. ** and return immediately with this indication.
  77. */
  78. if (newcoord == coord) {
  79. return(IMPACT_NONE);
  80. }
  81. /*
  82. ** Remember the new position.
  83. */
  84. coord = newcoord;
  85. /*
  86. ** If the new coordinate is off the edge of the world, then report
  87. ** this.
  88. */
  89. if (newcoord & 0xC000C000L /*|| !Map.In_Radar(Coord_Cell(newcoord))*/) {
  90. coord = old;
  91. return(IMPACT_EDGE);
  92. }
  93. return(IMPACT_NORMAL);
  94. }
  95. }
  96. return(IMPACT_NONE);
  97. }
  98. /***********************************************************************************************
  99. * FlyClass::Fly_Speed -- Sets the flying object to the speed specified. *
  100. * *
  101. * This sets the speed of the projectile. It basically functions like a throttle value *
  102. * where 0 equals stop and 255 equals maximum speed (whatever that is for the particular *
  103. * object). *
  104. * *
  105. * INPUT: speed -- Speed setting from 0 to 255. *
  106. * *
  107. * maximum -- The maximum speed of the object. *
  108. * *
  109. * OUTPUT: none *
  110. * *
  111. * WARNINGS: none *
  112. * *
  113. * HISTORY: *
  114. * 07/26/1994 JLB : Created. *
  115. * 07/26/1994 JLB : Added maximum speed as guiding value. *
  116. *=============================================================================================*/
  117. void FlyClass::Fly_Speed(int speed, MPHType maximum)
  118. {
  119. SpeedAdd = (MPHType)Fixed_To_Cardinal((int)maximum, speed);
  120. }