CnC_Remastered_Collection

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

GETSHAPE.CPP (18255B)


      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 /***************************************************************************
     17  **   C O N F I D E N T I A L --- W E S T W O O D   A S S O C I A T E S   **
     18  ***************************************************************************
     19  *                                                                         *
     20  *                 Project Name : Westwood Library                         *
     21  *                                                                         *
     22  *                    File Name : GETSHAPE.CPP                             *
     23  *                                                                         *
     24  *                   Programmer : Joe L. Bostic                            *
     25  *                                                                         *
     26  *                   Start Date : April 5, 1992                            *
     27  *                                                                         *
     28  *                  Last Update : May 25, 1994   [BR]                      *
     29  *                                                                         *
     30  *-------------------------------------------------------------------------*
     31  * Functions:                                                              *
     32  *   Get_Shape_Size -- Fetch the size of the shape in memory.              *
     33  *   Get_Shape_Uncomp_Size -- gets shape's uncompressed size in bytes		*
     34  *   Get_Shape_Data -- retrieves a shape's special prefix data					*
     35  *   Extract_Shape_Count -- returns # of shapes in the given shape block	*
     36  *   Extract_Shape -- Gets pointer to shape in given shape block				*
     37  *   Get_Shape_Width -- gets shape width in pixels									*
     38  *   Get_Shape_Height -- gets shape height in pixels								*
     39  *   Set_Shape_Height -- modifies shape's height									*
     40  *   Restore_Shape_Height -- restores a shape to its original height			*
     41  *   Get_Shape_Original_Height -- gets shape's unmodified height				*
     42  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     43 /*
     44 ********************************* Includes **********************************
     45 */
     46 #include "wwstd.h"
     47 #include	"shape.h"
     48 
     49 
     50 /***************************************************************************
     51  * Get_Shape_Size -- Fetch the size of the shape in memory.                *
     52  *                                                                         *
     53  * The shape size returned includes both the shape header & its data.		*
     54  *																									*
     55  * INPUT:                                                                  *
     56  *	shape		pointer to shape																*
     57  *                                                                         *
     58  * OUTPUT:                                                                 *
     59  * shape's size in memory																	*
     60  *                                                                         *
     61  * WARNINGS:                                                               *
     62  * none																							*
     63  *                                                                         *
     64  * HISTORY:                                                                *
     65  *   06/09/1992 JLB : Created.                                             *
     66  *   08/19/1993 SKB : Split drawshp.asm into several modules.              *
     67  *   05/25/1994 BR : Converted to 32-bit                                   *
     68  *=========================================================================*/
     69 int cdecl Get_Shape_Size(VOID const *shape)
     70 {
     71 	Shape_Type *shp = (Shape_Type *)shape;
     72 
     73 	/*
     74 	------------------------- Return if NULL pointer -------------------------
     75 	*/
     76 	if (!shape) 
     77 		return(0);
     78 
     79 	/*
     80 	-------------------------- Returns shape's size --------------------------
     81 	*/
     82 	return (shp->ShapeSize);
     83 
     84 }	/* end of Get_Shape_Size */
     85 
     86 
     87 /***************************************************************************
     88  * Get_Shape_Uncomp_Size -- gets shape's uncompressed size in bytes			*
     89  *                                                                         *
     90  * INPUT:                                                                  *
     91  *	shape		pointer to shape																*
     92  *                                                                         *
     93  * OUTPUT:                                                                 *
     94  *	shape's size in bytes when uncompressed											*
     95  *                                                                         *
     96  * WARNINGS:                                                               *
     97  * none																							*
     98  *                                                                         *
     99  * HISTORY:                                                                *
    100  *   06/09/1992 JLB : Created.                                             *
    101  *   08/19/1993 SKB : Split drawshp.asm into several modules.              *
    102  *   05/25/1994 BR : Converted to 32-bit                                   *
    103  *=========================================================================*/
    104 int Get_Shape_Uncomp_Size(VOID const *shape)
    105 {
    106 	Shape_Type *shp = (Shape_Type *)shape;
    107 
    108 	return (shp->DataLength);
    109 
    110 }	/* end of Get_Shape_Uncomp_Size */
    111 
    112 
    113 /***************************************************************************
    114  * Get_Shape_Data -- retrieves a shape's special prefix data					*
    115  *																									*
    116  * MAKESHPS.EXE can store special data values along with a shape.  These	*
    117  * values are inserted in the shape table >before< the shape's header.		*
    118  * So, this routine uses the 'data' parameter as a negative index from		*
    119  * the given shape pointer.																*
    120  *                                                                         *
    121  * INPUT:                                                                  *
    122  *	shape		pointer to shape																*
    123  * data		index of WORD data value to get											*
    124  *                                                                         *
    125  * OUTPUT:                                                                 *
    126  * data value																					*
    127  *                                                                         *
    128  * WARNINGS:                                                               *
    129  *	The shape pointer must be a pointer into a shape table created by			*
    130  * MAKESHPS.EXE; it >cannot< be a pointer to shape returned by Make_Shape!	*
    131  *                                                                         *
    132  * HISTORY:                                                                *
    133  *   06/09/1992 JLB : Created.                                             *
    134  *   08/19/1993 SKB : Split drawshp.asm into several modules.              *
    135  *   05/25/1994 BR : Converted to 32-bit                                   *
    136  *=========================================================================*/
    137 WORD cdecl Get_Shape_Data(VOID const *shape, WORD data)
    138 {
    139 	WORD *word_ptr = (WORD *)shape;
    140 	WORD retval;
    141 
    142 	retval = *(word_ptr - (data+1));
    143 
    144 	return (retval);
    145 
    146 }	/* end of Get_Shape_Data */
    147 
    148 
    149 /***************************************************************************
    150  * Extract_Shape_Count -- returns # of shapes in the given shape block		*
    151  *                                                                         *
    152  * The # of shapes in a shape block is the first WORD in the block, so		*
    153  * this is the value returned.															*
    154  *																									*
    155  * INPUT:                                                                  *
    156  * buffer	pointer to shape block, created with MAKESHPS.EXE					*
    157  *                                                                         *
    158  * OUTPUT:                                                                 *
    159  * # shapes in the block																	*
    160  *                                                                         *
    161  * WARNINGS:                                                               *
    162  *	none																							*
    163  *                                                                         *
    164  * HISTORY:                                                                *
    165  *   06/09/1992 JLB : Created.                                             *
    166  *   08/19/1993 SKB : Split drawshp.asm into several modules.              *
    167  *   05/25/1994 BR : Converted to 32-bit                                   *
    168  *=========================================================================*/
    169 int cdecl Extract_Shape_Count(VOID const *buffer)
    170 {
    171 	ShapeBlock_Type *block = (ShapeBlock_Type *)buffer;
    172 
    173 	return (block->NumShapes);
    174 
    175 }	/* end of Extract_Shape_Count */
    176 
    177 
    178 /***************************************************************************
    179  * Extract_Shape -- Gets pointer to shape in given shape block					*
    180  *                                                                         *
    181  * INPUT:                                                                  *
    182  * buffer	pointer to shape block, created with MAKESHPS.EXE					*
    183  * shape		index of shape to get														*
    184  *                                                                         *
    185  * OUTPUT:                                                                 *
    186  * pointer to shape in the shape block													*
    187  *                                                                         *
    188  * WARNINGS:                                                               *
    189  *	none																							*
    190  *                                                                         *
    191  * HISTORY:                                                                *
    192  *   06/09/1992 JLB : Created.                                             *
    193  *   08/19/1993 SKB : Split drawshp.asm into several modules.              *
    194  *   05/25/1994 BR : Converted to 32-bit                                   *
    195  *=========================================================================*/
    196 VOID * cdecl Extract_Shape(VOID const *buffer, int shape)
    197 {
    198 	ShapeBlock_Type *block = (ShapeBlock_Type*) buffer;
    199 	//int numshapes;		// Number of shapes
    200 	long offset;			// Offset of shape data, from start of block
    201 	char *bytebuf = (char*) buffer;
    202 
    203 	/*
    204 	----------------------- Return if invalid argument -----------------------
    205 	*/
    206 	if (!buffer || shape < 0 || shape >= block->NumShapes)
    207 		return(NULL);
    208 
    209 	offset = block->Offsets[shape];
    210 
    211 	return(bytebuf + 2 + offset);
    212 
    213 }	/* end of Extract_Shape */
    214 
    215 
    216 /***************************************************************************
    217  * Get_Shape_Width -- gets shape width in pixels									*
    218  *                                                                         *
    219  * INPUT:                                                                  *
    220  * shape		pointer to a shape															*
    221  *                                                                         *
    222  * OUTPUT:                                                                 *
    223  *	shape width in pixels																	*
    224  *                                                                         *
    225  * WARNINGS:                                                               *
    226  * none																							*
    227  *                                                                         *
    228  * HISTORY:                                                                *
    229  *   06/09/1992 JLB : Created.                                             *
    230  *   08/19/1993 SKB : Split drawshp.asm into several modules.              *
    231  *   05/25/1994 BR : Converted to 32-bit                                   *
    232  *=========================================================================*/
    233 int Get_Shape_Width(VOID const *shape)
    234 {
    235 	Shape_Type *shp = (Shape_Type *)shape;
    236 
    237 	return (shp->Width);
    238 
    239 }	/* end of Get_Shape_Width */
    240 
    241 
    242 /***************************************************************************
    243  * Get_Shape_Height -- gets shape height in pixels									*
    244  *                                                                         *
    245  * INPUT:                                                                  *
    246  * shape		pointer to a shape															*
    247  *                                                                         *
    248  * OUTPUT:                                                                 *
    249  * shape height in pixels																	*
    250  *                                                                         *
    251  * WARNINGS:                                                               *
    252  * none																							*
    253  *                                                                         *
    254  * HISTORY:                                                                *
    255  *   06/09/1992 JLB : Created.                                             *
    256  *   08/19/1993 SKB : Split drawshp.asm into several modules.              *
    257  *   05/25/1994 BR : Converted to 32-bit                                   *
    258  *=========================================================================*/
    259 int Get_Shape_Height(VOID const *shape)
    260 {
    261 	Shape_Type *shp = (Shape_Type *)shape;
    262 
    263 	return (shp->Height);
    264 
    265 }	/* end of Get_Shape_Height */
    266 
    267 
    268 /***************************************************************************
    269  * Set_Shape_Height -- modifies shape's height										*
    270  *                                                                         *
    271  * The new height must be shorter than the original height.  This effect	*
    272  * chops off the lower portion of the shape, like it's sinking into the		*
    273  * ground.																						*
    274  *																									*
    275  * INPUT:                                                                  *
    276  * shape			pointer to a shape														*
    277  * newheight	new shape height															*
    278  *                                                                         *
    279  * OUTPUT:                                                                 *
    280  * old shape height																			*
    281  *                                                                         *
    282  * WARNINGS:                                                               *
    283  * none																							*
    284  *                                                                         *
    285  * HISTORY:                                                                *
    286  *   06/09/1992 JLB : Created.                                             *
    287  *   08/19/1993 SKB : Split drawshp.asm into several modules.              *
    288  *   05/25/1994 BR : Converted to 32-bit                                   *
    289  *=========================================================================*/
    290 int cdecl Set_Shape_Height(VOID const *shape, WORD newheight)
    291 {
    292 	Shape_Type *shp = (Shape_Type *)shape;
    293 	WORD oldheight;
    294 
    295 	oldheight = shp->Height;
    296 	shp->Height = newheight;
    297 
    298 	return(oldheight);
    299 
    300 }	/* end of Set_Shape_Height */
    301 
    302 
    303 /***************************************************************************
    304  * Restore_Shape_Height -- restores a shape to its original height			*
    305  *                                                                         *
    306  * INPUT:                                                                  *
    307  * shape		pointer to a shape															*
    308  *                                                                         *
    309  * OUTPUT:                                                                 *
    310  * old shape height																			*
    311  *                                                                         *
    312  * WARNINGS:                                                               *
    313  *                                                                         *
    314  * HISTORY:                                                                *
    315  *   06/09/1992 JLB : Created.                                             *
    316  *   08/19/1993 SKB : Split drawshp.asm into several modules.              *
    317  *   05/25/1994 BR : Converted to 32-bit                                   *
    318  *=========================================================================*/
    319 int cdecl Restore_Shape_Height(VOID *shape)
    320 {
    321 	Shape_Type *shp = (Shape_Type *)shape;
    322 	WORD oldheight;
    323 
    324 	oldheight = shp->Height;
    325 	shp->Height = shp->OriginalHeight;
    326 
    327 	return(oldheight);
    328 
    329 }	/* end of Restore_Shape_Height */
    330 
    331 
    332 /***************************************************************************
    333  * Get_Shape_Original_Height -- gets shape's unmodified height					*
    334  *                                                                         *
    335  * INPUT:                                                                  *
    336  *	shape		pointer to a shape															*
    337  *                                                                         *
    338  * OUTPUT:                                                                 *
    339  * shape's unmodified height																*
    340  *                                                                         *
    341  * WARNINGS:                                                               *
    342  *	none																							*
    343  *                                                                         *
    344  * HISTORY:                                                                *
    345  *   06/09/1992 JLB : Created.                                             *
    346  *   08/19/1993 SKB : Split drawshp.asm into several modules.              *
    347  *   05/25/1994 BR : Converted to 32-bit                                   *
    348  *=========================================================================*/
    349 int Get_Shape_Original_Height(VOID const *shape)
    350 {
    351 	Shape_Type *shp = (Shape_Type *)shape;
    352 	
    353 	return (shp->OriginalHeight);
    354 
    355 }	/* end of Get_Shape_Original_Height */
    356 
    357 
    358 /************************* end of getshape.cpp *****************************/