CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

FLY.CPP (7688B)


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