CnC_Remastered_Collection

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

DOOR.CPP (12071B)


      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/DOOR.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 : DOOR.CPP                                                     *
     24  *                                                                                             *
     25  *                   Programmer : Joe L. Bostic                                                *
     26  *                                                                                             *
     27  *                   Start Date : 06/11/95                                                     *
     28  *                                                                                             *
     29  *                  Last Update : June 14, 1995 [JLB]                                          *
     30  *                                                                                             *
     31  *---------------------------------------------------------------------------------------------*
     32  * Functions:                                                                                  *
     33  *   DoorClass::AI -- Handles the door processing logic.                                       *
     34  *   DoorClass::Close_Door -- Try to close the unit's door.                                    *
     35  *   DoorClass::DoorClass -- Constructor for the DoorClass object.                             *
     36  *   DoorClass::Door_Stage -- Fetches the current door animation frame.                        *
     37  *   DoorClass::Open_Door -- Opens the door for this unit.                                     *
     38  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     39 
     40 
     41 #include	"function.h"
     42 
     43 
     44 /***********************************************************************************************
     45  * DoorClass::DoorClass -- Constructor for the DoorClass object.                               *
     46  *                                                                                             *
     47  *    This constructor sets the door to an initial closed state.                               *
     48  *                                                                                             *
     49  * INPUT:   none                                                                               *
     50  *                                                                                             *
     51  * OUTPUT:  none                                                                               *
     52  *                                                                                             *
     53  * WARNINGS:   none                                                                            *
     54  *                                                                                             *
     55  * HISTORY:                                                                                    *
     56  *   06/14/1995 JLB : Created.                                                                 *
     57  *=============================================================================================*/
     58 DoorClass::DoorClass(void)
     59 {
     60 	State = IS_CLOSED;
     61 	IsToRedraw = false;
     62 	Stages = 0;
     63 }
     64 
     65 
     66 /***********************************************************************************************
     67  * DoorClass::AI -- Handles the door processing logic.                                         *
     68  *                                                                                             *
     69  *    This routine should be called every game frame. It handles the door closing and opening  *
     70  *    logic.                                                                                   *
     71  *                                                                                             *
     72  * INPUT:   none                                                                               *
     73  *                                                                                             *
     74  * OUTPUT:  none                                                                               *
     75  *                                                                                             *
     76  * WARNINGS:   none                                                                            *
     77  *                                                                                             *
     78  * HISTORY:                                                                                    *
     79  *   06/13/1995 JLB : Created.                                                                 *
     80  *=============================================================================================*/
     81 void DoorClass::AI(void)
     82 {
     83 	if (Control.Graphic_Logic()) {
     84 		if (Control.Fetch_Stage() >= Stages) {
     85 			Control.Set_Rate(0);
     86 			switch (State) {
     87 				case IS_OPENING:
     88 					State = IS_OPEN;
     89 					break;
     90 
     91 				case IS_CLOSING:
     92 					State = IS_CLOSED;
     93 					break;
     94 			}
     95 		}
     96 		IsToRedraw = true;
     97 	}
     98 }
     99 
    100 
    101 /***********************************************************************************************
    102  * DoorClass::Open_Door -- Opens the door for this unit.                                       *
    103  *                                                                                             *
    104  *    This routine will perform the door open operation for this unit. It will control vehicle *
    105  *    rotation if necessary.                                                                   *
    106  *                                                                                             *
    107  * INPUT:   rate     -- The animation rate (delay) to use for the door animation logic.        *
    108  *                                                                                             *
    109  *          stages   -- The number of animations stages that this door must pass through.      *
    110  *                                                                                             *
    111  * OUTPUT:  Was action initiated to open the door?                                             *
    112  *                                                                                             *
    113  * WARNINGS:   none                                                                            *
    114  *                                                                                             *
    115  * HISTORY:                                                                                    *
    116  *   05/08/1995 JLB : Created.                                                                 *
    117  *=============================================================================================*/
    118 bool DoorClass::Open_Door(int rate, int stages)
    119 {
    120 	switch (State) {
    121 		case IS_CLOSED:
    122 		case IS_CLOSING:
    123 			State = IS_OPENING;
    124 			Stages = stages-1;
    125 			Control.Set_Stage(0);
    126 			Control.Set_Rate(rate);
    127 			return(true);
    128 	}
    129 	return(false);
    130 }
    131 
    132 
    133 /***********************************************************************************************
    134  * DoorClass::Close_Door -- Try to close the unit's door.                                      *
    135  *                                                                                             *
    136  *    This routine will attempt to close the unit's door. If the door is already closed or     *
    137  *    in the process of closing, then no action is performed.                                  *
    138  *                                                                                             *
    139  * INPUT:   rate     -- The animation rate (delay) to use for the door animation logic.        *
    140  *                                                                                             *
    141  *          stages   -- The number of animations stages that this door must pass through.      *
    142  *                                                                                             *
    143  * OUTPUT:  Action was initiated to close the door?                                            *
    144  *                                                                                             *
    145  * WARNINGS:   none                                                                            *
    146  *                                                                                             *
    147  * HISTORY:                                                                                    *
    148  *   05/08/1995 JLB : Created.                                                                 *
    149  *=============================================================================================*/
    150 bool DoorClass::Close_Door(int rate, int stages)
    151 {
    152 	switch (State) {
    153 		case IS_OPEN:
    154 		case IS_OPENING:
    155 			State = IS_CLOSING;
    156 			Stages = stages-1;
    157 			Control.Set_Stage(0);
    158 			Control.Set_Rate(rate);
    159 			return(true);
    160 	}
    161 	return(false);
    162 }
    163 
    164 
    165 /***********************************************************************************************
    166  * DoorClass::Door_Stage -- Fetches the current door animation frame.                          *
    167  *                                                                                             *
    168  *    Use this routine to fetch the current door animation frame number. Frame zero is the     *
    169  *    closed frame and frame 'N' is the open frame. If the door is in the process of opening   *
    170  *    or closing, the appropriate frame number is used. 'N' is defined as the number of        *
    171  *    stages in the animation minus 1 (e.g., a four frame animation will return a door stage   *
    172  *    number between 0 and 3, inclusive).                                                      *
    173  *                                                                                             *
    174  * INPUT:   none                                                                               *
    175  *                                                                                             *
    176  * OUTPUT:  Returns with the door animation frame number.                                      *
    177  *                                                                                             *
    178  * WARNINGS:   none                                                                            *
    179  *                                                                                             *
    180  * HISTORY:                                                                                    *
    181  *   06/14/1995 JLB : Created.                                                                 *
    182  *=============================================================================================*/
    183 int DoorClass::Door_Stage(void) const
    184 {
    185 	switch (State) {
    186 		case IS_CLOSING:
    187 			return((Stages-1) - Control.Fetch_Stage());
    188 
    189 		case IS_CLOSED:
    190 			return(0);
    191 
    192 		case IS_OPENING:
    193 			return(Control.Fetch_Stage());
    194 
    195 		case IS_OPEN:
    196 			return(Stages-1);
    197 	}
    198 	return(0);
    199 }