| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- /*
- ** Command & Conquer(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /* $Header: F:\projects\c&c\vcs\code\facing.cpv 1.9 16 Oct 1995 16:49:40 JOE_BOSTIC $ */
- /***********************************************************************************************
- *** 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 ***
- ***********************************************************************************************
- * *
- * Project Name : Command & Conquer *
- * *
- * File Name : FACING.CPP *
- * *
- * Programmer : Joe L. Bostic *
- * *
- * Start Date : 03/21/95 *
- * *
- * Last Update : March 21, 1995 [JLB] *
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * FacingClass::Rotation_Adjust -- Perform a rotation adjustment to current facing. *
- * FacingClass::Set_Current -- Sets the current rotation value. *
- * FacingClass::Set_Desired -- Sets the desired facing value. *
- * FacingClass::FacingClass -- Default constructor for the facing class. *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "function.h"
- #include "facing.h"
- /***********************************************************************************************
- * FacingClass::FacingClass -- Default constructor for the facing class. *
- * *
- * This default constructor merely sets the desired and current facing values to be the *
- * same (North). *
- * *
- * INPUT: none *
- * *
- * OUTPUT: none *
- * *
- * WARNINGS: none *
- * *
- * HISTORY: *
- * 03/21/1995 JLB : Created. *
- *=============================================================================================*/
- FacingClass::FacingClass(void)
- {
- CurrentFacing = DIR_N;
- DesiredFacing = DIR_N;
- }
- /***********************************************************************************************
- * FacingClass::Set_Desired -- Sets the desired facing value. *
- * *
- * This routine is used to set the desired facing value without altering the current *
- * facing setting. Typicall use of this routine is when a vehicle needs to face a *
- * direction, but currently isn't facing the correct direction. After this routine is *
- * called, it is presumed that subsequent calls to Rotation_Adjust() will result in the *
- * eventual alignment of the current facing. *
- * *
- * INPUT: facing -- The new facing to assign to the desired value. *
- * *
- * OUTPUT: bool; Did the desired facing value actually change by this routine call? *
- * *
- * WARNINGS: none *
- * *
- * HISTORY: *
- * 03/21/1995 JLB : Created. *
- *=============================================================================================*/
- int FacingClass::Set_Desired(DirType facing)
- {
- if (DesiredFacing != facing) {
- DesiredFacing = facing;
- return(true);
- }
- return(false);
- }
- /***********************************************************************************************
- * FacingClass::Set_Current -- Sets the current rotation value. *
- * *
- * This routine will set the current rotation value. It is used to override the facing *
- * value without adjusting the desired setting. *
- * *
- * INPUT: facing -- The new facing to assign to the current facing value. *
- * *
- * OUTPUT: bool; Was the current setting changed by this routine. Failure means that the *
- * current setting was already at the value specified. *
- * *
- * WARNINGS: none *
- * *
- * HISTORY: *
- * 03/21/1995 JLB : Created. *
- *=============================================================================================*/
- int FacingClass::Set_Current(DirType facing)
- {
- if (CurrentFacing != facing) {
- CurrentFacing = facing;
- return(true);
- }
- return(false);
- }
- /***********************************************************************************************
- * FacingClass::Rotation_Adjust -- Perform a rotation adjustment to current facing. *
- * *
- * This routine is used when the current and desired facings differ but the current *
- * facing should be adjusted toward the desired facing. The amount of rotation to adjust *
- * is provided as a rotation rate parameter. Typical use of this routine is for turrets *
- * and other vehicle related rotating. *
- * *
- * INPUT: rate -- The rotation rate to use when adjusting the current facing toward the *
- * desired facing. A value of 127 means instantaneous rotation. *
- * *
- * OUTPUT: bool; Did the rotation result in the current facing transitioning from one *
- * 1/32 zone to another? If true, then the owning object most likely will *
- * need to be redrawn to reflect the change. *
- * *
- * WARNINGS: none *
- * *
- * HISTORY: *
- * 03/21/1995 JLB : Created. *
- *=============================================================================================*/
- int FacingClass::Rotation_Adjust(int rate)
- {
- /*
- ** Only perform the rotation adjustment if the desired facing is not the
- ** same as the current facing.
- */
- if (Is_Rotating()) {
- rate = MIN(rate, 127);
- DirType oldfacing = CurrentFacing;
- int diff = Difference();
- /*
- ** If the allowed facing change is greater than the difference between
- ** the current facing and the desired facing, then just snap the
- ** facing to the new value.
- */
- if (ABS(diff) < rate) {
- CurrentFacing = DesiredFacing;
- } else {
- /*
- ** Adjust the current facing clockwise or counterclockwise depending
- ** on the shortest distance to the desired facing from the current
- ** facing.
- */
- if (diff < 0) {
- CurrentFacing = (DirType)(CurrentFacing - (DirType)rate);
- } else {
- CurrentFacing = (DirType)(CurrentFacing + (DirType)rate);
- }
- }
- /*
- ** If this facing adjustment caused the current facing to rotate into a
- ** new 1/32 rotation zone (likely to cause a redraw), then return
- ** this fact with a true value.
- */
- return(Facing_To_32(CurrentFacing) != Facing_To_32(oldfacing));
- }
- return(false);
- }
|