CnC_Remastered_Collection

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

CARGO.CPP (10902B)


      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\cargo.cpv   2.18   16 Oct 1995 16:49:50   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 : CARGO.CPP                                                    *
     24  *                                                                                             *
     25  *                   Programmer : Joe L. Bostic                                                *
     26  *                                                                                             *
     27  *                   Start Date : April 23, 1994                                               *
     28  *                                                                                             *
     29  *                  Last Update : 10/31/94 [JLB]                                               *
     30  *                                                                                             *
     31  *---------------------------------------------------------------------------------------------*
     32  * Functions:                                                                                  *
     33  *   CargoClass::Attach -- Add unit to cargo hold.                                             *
     34  *   CargoClass::Attached_Object -- Determine attached unit pointer.                           *
     35  *   CargoClass::Detach_Object -- Removes a unit from the cargo hold.                          *
     36  *   CargoClass::Debug_Dump -- Displays the cargo value to the monochrome screen.              *
     37  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     38 
     39 #include	"function.h"
     40 
     41 
     42 #ifdef CHEAT_KEYS
     43 /***********************************************************************************************
     44  * CargoClass::Debug_Dump -- Displays the cargo value to the monochrome screen.                *
     45  *                                                                                             *
     46  *    This routine is used to dump the current cargo value to the monochrome monitor.          *
     47  *                                                                                             *
     48  * INPUT:   none                                                                               *
     49  *                                                                                             *
     50  * OUTPUT:  none                                                                               *
     51  *                                                                                             *
     52  * WARNINGS:   none                                                                            *
     53  *                                                                                             *
     54  * HISTORY:                                                                                    *
     55  *   06/02/1994 JLB : Created.                                                                 *
     56  *=============================================================================================*/
     57 void CargoClass::Debug_Dump(MonoClass * mono) const
     58 {
     59 	if (How_Many()) {
     60 		mono->Set_Cursor(63, 3);
     61 		mono->Printf("(%d)%04X", How_Many(), Attached_Object());
     62 	}
     63 }
     64 #endif
     65 
     66 
     67 /***********************************************************************************************
     68  * CargoClass::Attach -- Add unit to cargo hold.                                               *
     69  *                                                                                             *
     70  *    This routine will add the specified unit to the cargo hold. The                          *
     71  *    unit will chain to any existing units in the hold. The chaining is                       *
     72  *    in a LIFO order.                                                                         *
     73  *                                                                                             *
     74  * INPUT:   object-- Pointer to the object to attach to the cargo hold.                        *
     75  *                                                                                             *
     76  * OUTPUT:  none                                                                               *
     77  *                                                                                             *
     78  * WARNINGS:   none                                                                            *
     79  *                                                                                             *
     80  * HISTORY:                                                                                    *
     81  *   04/23/1994 JLB : Created.                                                                 *
     82  *   10/31/94   JLB : Handles chained objects.                                                 * 
     83  *=============================================================================================*/
     84 void CargoClass::Attach(FootClass * object)
     85 {
     86 	/*
     87 	**	If there is no object, then no action is necessary.
     88 	*/
     89 	if (!object) return;
     90 
     91 	object->Limbo();
     92 
     93 	/*
     94 	**	Attach any existing cargo hold object to the end of the list as indicated by the
     95 	**	object pointer passed into this routine. This is necessary because several objects may
     96 	**	be attached at one time or several objects may be attached as a result of several calls
     97 	**	to this routine. Either case must be handled properly.
     98 	*/
     99 	ObjectClass * o = object->Next;
    100 	while (o) {
    101 		if (!o->Next) break;
    102 		o = o->Next;
    103 	}
    104 	if (o) {
    105 		o->Next = CargoHold;
    106 	} else {
    107 		object->Next = CargoHold;
    108 	}
    109 
    110 	/*
    111 	**	Finally, assign the object pointer as the first object attached to this cargo hold.
    112 	*/
    113 	CargoHold = object;
    114 	Quantity = 0;
    115 	object = CargoHold;
    116 	while (object) {
    117 		Quantity++;
    118 		object = (FootClass *)object->Next;
    119 	}
    120 }
    121 
    122 
    123 /***********************************************************************************************
    124  * CargoClass::Detach_Object -- Removes a unit from the cargo hold.                            *
    125  *                                                                                             *
    126  *    This routine will take a unit from the cargo hold and extract it.                        *
    127  *    The unit extracted is the last unit added to the hold. If there                          *
    128  *    is no unit in the hold or the occupant is not a unit, then NULL is                       *
    129  *    returned.                                                                                *
    130  *                                                                                             *
    131  * INPUT:   none                                                                               *
    132  *                                                                                             *
    133  * OUTPUT:  Returns with a pointer to the unit that has been extracted.                        *
    134  *                                                                                             *
    135  * WARNINGS:   none                                                                            *
    136  *                                                                                             *
    137  * HISTORY:                                                                                    *
    138  *   04/23/1994 JLB : Created.                                                                 *
    139  *   06/07/1994 JLB : Handles generic object types.                                            *
    140  *=============================================================================================*/
    141 FootClass * CargoClass::Detach_Object(void)
    142 {
    143 	FootClass * unit = Attached_Object();
    144 
    145 	if (unit) {
    146 		CargoHold = (FootClass *)unit->Next;
    147 		unit->Next = 0;
    148 		Quantity--;
    149 	}
    150 	return(unit);
    151 }
    152 
    153 
    154 /***********************************************************************************************
    155  * CargoClass::Attached_Object -- Determine attached unit pointer.                             *
    156  *                                                                                             *
    157  *    This routine will return with a pointer to the attached unit if one                      *
    158  *    is present. One would need to know this if this is a transport                           *
    159  *    unit and it needs to unload.                                                             *
    160  *                                                                                             *
    161  * INPUT:   none                                                                               *
    162  *                                                                                             *
    163  * OUTPUT:  Returns a pointer to the attached unit. If there is no                             *
    164  *          attached unit, then return NULL.                                                   *
    165  *                                                                                             *
    166  * WARNINGS:   none                                                                            *
    167  *                                                                                             *
    168  * HISTORY:                                                                                    *
    169  *   09/07/1992 JLB : Created.                                                                 *
    170  *   06/07/1994 JLB : Handles generic object types.                                            *
    171  *=============================================================================================*/
    172 FootClass * CargoClass::Attached_Object(void) const
    173 {
    174 	if (Is_Something_Attached()) {
    175 		return(CargoHold);
    176 	}
    177 	return(NULL);
    178 }
    179 
    180