CnC_Remastered_Collection

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

FUSE.CPP (12430B)


      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: /CounterStrike/FUSE.CPP 1     3/03/97 10:24a 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 : FUSE.CPP                                                     *
     24  *                                                                                             *
     25  *                   Programmer : Joe L. Bostic                                                *
     26  *                                                                                             *
     27  *                   Start Date : April 24, 1994                                               *
     28  *                                                                                             *
     29  *                  Last Update : October 17, 1994   [JLB]                                     *
     30  *                                                                                             *
     31  *---------------------------------------------------------------------------------------------*
     32  * Functions:                                                                                  *
     33  *   FuseClass::Arm_Fuse -- Sets up fuse for detonation check.                                 *
     34  *   FuseClass::Fuse_Checkup -- Determines if the fuse triggers.                               *
     35  *   FuseClass::Fuse_Read -- Reads the fuse class data from the save game file.                *
     36  *   FuseClass::Fuse_Write -- Writes the fuse data to the save game file.                      *
     37  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     38 
     39 #include	"function.h"
     40 
     41 
     42 /***********************************************************************************************
     43  * FuseClass::FuseClass -- Constructor.                                                        *
     44  *                                                                                             *
     45  * INPUT:   none                                                                               *
     46  *                                                                                             *
     47  * OUTPUT:  none                                                                               *
     48  *                                                                                             *
     49  * WARNINGS:   none                                                                            *
     50  *                                                                                             *
     51  * HISTORY:                                                                                    *
     52  *   06/27/1995 BRR : Created.  Gosh, what a lotta work.                                       *
     53  *=============================================================================================*/
     54 FuseClass::FuseClass(void)
     55 {
     56 	Timer = 0;
     57 	Arming = 0;
     58 	HeadTo = 0;
     59 	Proximity = 0;
     60 }
     61 
     62 
     63 /***********************************************************************************************
     64  * FuseClass::Arm_Fuse -- Sets up fuse for detonation check.                                   *
     65  *                                                                                             *
     66  *    This starts a fuse. Fuses are proximity detonation variety but                           *
     67  *    can be modified to have a minimum time to elapse before detonation                       *
     68  *    and a maximum time to exist before detonation. Typically, the                            *
     69  *    timing values are used for missiles that have a minimum arming                           *
     70  *    distance and a limited amount of fuel.                                                   *
     71  *                                                                                             *
     72  * INPUT:   location -- The coordinate where the projectile start. This                        *
     73  *                      is needed for proper proximity tracking.                               *
     74  *                                                                                             *
     75  *          target   -- The actual impact point. Fuses are based on real                       *
     76  *                      word coordinates.                                                      *
     77  *                                                                                             *
     78  *          time     -- The maximum time that the fuse may work before                         *
     79  *                      explosion is forced.                                                   *
     80  *                                                                                             *
     81  *          arming   -- The minimum time that must elapse before the                           *
     82  *                      fuse may explode.                                                      *
     83  *                                                                                             *
     84  * OUTPUT:  none                                                                               *
     85  *                                                                                             *
     86  * WARNINGS:   none                                                                            *
     87  *                                                                                             *
     88  * HISTORY:                                                                                    *
     89  *   04/24/1994 JLB : Created.                                                                 *
     90  *=============================================================================================*/
     91 void FuseClass::Arm_Fuse(COORDINATE location, COORDINATE target, int timeto, int arming)
     92 {
     93 	timeto = max(timeto, arming);
     94 	Timer = min(timeto, 0xFF);
     95 	Arming = min(arming, 0xFF);
     96 	HeadTo = target;
     97 	Proximity = Distance(location, target);
     98 }
     99 
    100 
    101 /***********************************************************************************************
    102  * FuseClass::Fuse_Checkup -- Determines if the fuse triggers.                                 *
    103  *                                                                                             *
    104  *    This will process the fuse and update the internal clocks as well                        *
    105  *    as check to see if the fuse should trigger (explode) or not.                             *
    106  *                                                                                             *
    107  * INPUT:   newlocation -- The new location of the fuse. This is needed                        *
    108  *                         to determine proximity explosions.                                  *
    109  *                                                                                             *
    110  * OUTPUT:  bool; Was the fuse triggered to explode now?                                       *
    111  *                                                                                             *
    112  * WARNINGS:   none                                                                            *
    113  *                                                                                             *
    114  * HISTORY:                                                                                    *
    115  *   04/24/1994 JLB : Created.                                                                 *
    116  *=============================================================================================*/
    117 bool FuseClass::Fuse_Checkup(COORDINATE newlocation)
    118 {
    119 	int	proximity;
    120 
    121 	/*
    122 	**	Always decrement the fuse timer.
    123 	*/
    124 	if (Timer) Timer--;
    125 
    126 	/*
    127 	**	If the arming countdown has not expired, then do nothing.
    128 	*/
    129 	if (Arming) {
    130 		Arming--;
    131 	} else {
    132 
    133 		/*
    134 		**	If the timer has run out, then the warhead explodes.
    135 		*/
    136 		if (!Timer) return(true);
    137 
    138 		proximity = Distance(newlocation, HeadTo);
    139 		if (proximity < 0x0010) return(true);
    140 		if (proximity < ICON_LEPTON_W && proximity > Proximity) {
    141 			return(true);
    142 		}
    143 		Proximity = proximity;
    144 	}
    145 	return(false);
    146 }
    147 
    148 
    149 /***********************************************************************************************
    150  * FuseClass::Fuse_Write -- Writes the fuse data to the save game file.                        *
    151  *                                                                                             *
    152  *    Use this routine to output the fuse class data to the save game file specified.          *
    153  *                                                                                             *
    154  * INPUT:   file  -- The file to output the data to.                                           *
    155  *                                                                                             *
    156  * OUTPUT:  none                                                                               *
    157  *                                                                                             *
    158  * WARNINGS:   none                                                                            *
    159  *                                                                                             *
    160  * HISTORY:                                                                                    *
    161  *   10/17/1994 JLB : Created.                                                                 *
    162  *=============================================================================================*/
    163 void FuseClass::Fuse_Write(FileClass & file)
    164 {
    165 	file.Write(&Timer, sizeof(Timer));
    166 	file.Write(&Arming, sizeof(Arming));
    167 	file.Write(&HeadTo, sizeof(HeadTo));
    168 	file.Write(&Proximity, sizeof(Proximity));
    169 }
    170 
    171 
    172 /***********************************************************************************************
    173  * FuseClass::Fuse_Read -- Reads the fuse class data from the save game file.                  *
    174  *                                                                                             *
    175  *    Use this routine to input the fuse class data from the save game file specified.         *
    176  *                                                                                             *
    177  * INPUT:   file  -- The file to input the data from.                                          *
    178  *                                                                                             *
    179  * OUTPUT:  none                                                                               *
    180  *                                                                                             *
    181  * WARNINGS:   none                                                                            *
    182  *                                                                                             *
    183  * HISTORY:                                                                                    *
    184  *   10/17/1994 JLB : Created.                                                                 *
    185  *=============================================================================================*/
    186 void FuseClass::Fuse_Read(FileClass & file)
    187 {
    188 	file.Read(&Timer, sizeof(Timer));
    189 	file.Read(&Arming, sizeof(Arming));
    190 	file.Read(&HeadTo, sizeof(HeadTo));
    191 	file.Read(&Proximity, sizeof(Proximity));
    192 }
    193 
    194