FLY.CPP 7.6 KB

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