CnC_Remastered_Collection

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

CRATE.CPP (10471B)


      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/CRATE.CPP 3     3/04/97 3:12p 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 : CRATE.CPP                                                    *
     24  *                                                                                             *
     25  *                   Programmer : Joe L. Bostic                                                *
     26  *                                                                                             *
     27  *                   Start Date : 08/26/96                                                     *
     28  *                                                                                             *
     29  *                  Last Update : October 14, 1996 [JLB]                                       *
     30  *                                                                                             *
     31  *---------------------------------------------------------------------------------------------*
     32  * Functions:                                                                                  *
     33  *   CrateClass::Create_Crate -- Create a crate in the cell specified.                         *
     34  *   CrateClass::Get_Crate -- Pick up a crate from the cell specified.                         *
     35  *   CrateClass::Put_Crate -- Generates crate overlay at cell specified.                       *
     36  *   CrateClass::Remove_It -- Removes the crate from wherever it is.                           *
     37  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     38 
     39 #include	"function.h"
     40 
     41 
     42 /***********************************************************************************************
     43  * CrateClass::Remove_It -- Removes the crate from wherever it is.                             *
     44  *                                                                                             *
     45  *    This routine will remove the crate from whereever it happens to be.                      *
     46  *                                                                                             *
     47  * INPUT:   none                                                                               *
     48  *                                                                                             *
     49  * OUTPUT:  bool; Was the crate found and removed?                                             *
     50  *                                                                                             *
     51  * WARNINGS:   none                                                                            *
     52  *                                                                                             *
     53  * HISTORY:                                                                                    *
     54  *   08/26/1996 JLB : Created.                                                                 *
     55  *=============================================================================================*/
     56 bool CrateClass::Remove_It(void)
     57 {
     58 	if (Is_Valid()) {
     59 		Get_Crate(Cell);
     60 		Make_Invalid();
     61 		return(true);
     62 	}
     63 	return(false);
     64 }
     65 
     66 
     67 /***********************************************************************************************
     68  * CrateClass::Create_Crate -- Create a crate in the cell specified.                           *
     69  *                                                                                             *
     70  *    This will create a crate in the cell specified. If the crate could not be crated there   *
     71  *    then 'false' will be returned.                                                           *
     72  *                                                                                             *
     73  * INPUT:   cell  -- The desired cell to place the crate in.                                   *
     74  *                                                                                             *
     75  * OUTPUT:  bool; Was the crate created and placed in the cell?                                *
     76  *                                                                                             *
     77  * WARNINGS:   It is quite possible for the crate not to have been placed. Only the most clear *
     78  *             locations are valid for crate placement.                                        *
     79  *                                                                                             *
     80  * HISTORY:                                                                                    *
     81  *   08/26/1996 JLB : Created.                                                                 *
     82  *=============================================================================================*/
     83 bool CrateClass::Create_Crate(CELL cell)
     84 {
     85 	/*
     86 	**	Remove any existing crate that this crate class is tracking.
     87 	*/
     88 	Remove_It();
     89 
     90 	/*
     91 	**	Try to place a new crate at the cell specified.
     92 	*/
     93 	if (Put_Crate(cell)) {
     94 		Cell = cell;
     95 		Timer = Random_Pick(Rule.CrateTime * (TICKS_PER_MINUTE/2), Rule.CrateTime * (TICKS_PER_MINUTE*2));
     96 		Timer.Start();
     97 		return(true);
     98 	}
     99 	return(false);
    100 }
    101 
    102 
    103 /***********************************************************************************************
    104  * CrateClass::Put_Crate -- Generates crate overlay at cell specified.                         *
    105  *                                                                                             *
    106  *    This helpter routine will examine the cell and place the appropriate crate type into     *
    107  *    the cell specified. If the overlay could not be generated, then 'false' is returned.     *
    108  *                                                                                             *
    109  * INPUT:   cell  -- The cell to generate the crate overlay in.                                *
    110  *                                                                                             *
    111  * OUTPUT:  bool; Was the crate overlay generated?                                             *
    112  *                                                                                             *
    113  * WARNINGS:   none                                                                            *
    114  *                                                                                             *
    115  * HISTORY:                                                                                    *
    116  *   08/26/1996 JLB : Created.                                                                 *
    117  *   10/14/1996 JLB : Takes reference to cell so that tracking can occur.                      *
    118  *=============================================================================================*/
    119 bool CrateClass::Put_Crate(CELL & cell)
    120 {
    121 	int old = ScenarioInit;
    122 	ScenarioInit = 0;
    123 
    124 	if (Map.In_Radar(cell)) {
    125 		CellClass * cellptr = &Map[cell];
    126 
    127 		while (cellptr->Overlay != OVERLAY_NONE && !cellptr->Is_Clear_To_Build(SPEED_FLOAT) && !cellptr->Is_Clear_To_Build(SPEED_FOOT)) {
    128 			cell = Map.Pick_Random_Location();
    129 
    130 			if (Percent_Chance(100 * Rule.WaterCrateChance)) {
    131 				cell = Map.Nearby_Location(cell, SPEED_FLOAT);
    132 			} else {
    133 				cell = Map.Nearby_Location(cell, SPEED_TRACK);
    134 			}
    135 			cellptr = &Map[cell];
    136 		}
    137 
    138 		if (cellptr->Is_Clear_To_Build(SPEED_FLOAT)) {
    139 			new OverlayClass(OVERLAY_WATER_CRATE, cell);
    140 		} else {
    141 			new OverlayClass(OVERLAY_WOOD_CRATE, cell);
    142 		}
    143 		ScenarioInit = old;
    144 		return(true);
    145 	}
    146 
    147 	ScenarioInit = old;
    148 	return(false);
    149 }
    150 
    151 
    152 /***********************************************************************************************
    153  * CrateClass::Get_Crate -- Pick up a crate from the cell specified.                           *
    154  *                                                                                             *
    155  *    This will remove the crate from the cell specified.                                      *
    156  *                                                                                             *
    157  * INPUT:   cell  -- The cell to examine and remove any crate overlays present.                *
    158  *                                                                                             *
    159  * OUTPUT:  bool; Was a crate overlay found and removed?                                       *
    160  *                                                                                             *
    161  * WARNINGS:   none                                                                            *
    162  *                                                                                             *
    163  * HISTORY:                                                                                    *
    164  *   08/26/1996 JLB : Created.                                                                 *
    165  *=============================================================================================*/
    166 bool CrateClass::Get_Crate(CELL cell)
    167 {
    168 	if (Map.In_Radar(cell)) {
    169 		CellClass * cellptr = &Map[cell];
    170 
    171 		if (cellptr->Overlay == OVERLAY_WOOD_CRATE ||
    172 			cellptr->Overlay == OVERLAY_STEEL_CRATE ||
    173 			cellptr->Overlay == OVERLAY_WATER_CRATE) {
    174 
    175 			cellptr->Overlay = OVERLAY_NONE;
    176 			cellptr->OverlayData = 0;
    177 			cellptr->Redraw_Objects();
    178 			return(true);
    179 		}
    180 	}
    181 	return(false);
    182 }