CnC_Remastered_Collection

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

SDATA.CPP (25679B)


      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\sdata.cpv   2.17   16 Oct 1995 16:52:10   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 : SDATA.CPP                                                    *
     24  *                                                                                             *
     25  *                   Programmer : Joe L. Bostic                                                *
     26  *                                                                                             *
     27  *                   Start Date : August 9, 1994                                               *
     28  *                                                                                             *
     29  *                  Last Update : August 12, 1994   [JLB]                                      *
     30  *                                                                                             *
     31  *---------------------------------------------------------------------------------------------*
     32  * Functions:                                                                                  *
     33  *   SmudgeTypeClass::Draw_It -- Renders the smudge image at the coordinate specified.         *
     34  *   SmudgeTypeClass::Create_One_Of -- Creates a smudge object of this type.                   *
     35  *   SmudgeTypeClass::Create_And_Place -- Creates and places on map, a smudge object.          *
     36  *   SmudgeTypeClass::Prep_For_Add -- Prepares the scenario editor for adding a smudge object. *
     37  *   SmudgeTypeClass::Init -- Performs theater specific initializations.                       *
     38  *   SmudgeTypeClass::Display -- Draws a generic version of this smudge type.                  *
     39  *   SmudgetypeClass::Occupy_List -- Determines occupation list for smudge object.             *
     40  *   SmudgeTypeClass::From_Name -- Converts an ASCII name into a smudge type.                  *
     41  *   SmudgeTypeClass::SmudgeTypeClass -- Constructor for smudge type objects.                  *
     42  *   SmudgeTypeClass::One_Time -- Performs one-time initialization                             *
     43  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     44 
     45 #include	"function.h"
     46 #include	"type.h"
     47 
     48 
     49 static SmudgeTypeClass const Crater1 (
     50 
     51 	SMUDGE_CRATER1,
     52 	"CR1",
     53 	TXT_CRATER,
     54 	1,1,							// Width and height of smudge (in icons).
     55 	false,						// Is this a building bib?
     56 	true							// Is this a crater smudge?
     57 );
     58 static SmudgeTypeClass const Crater2 (
     59 	SMUDGE_CRATER2,
     60 	"CR2",
     61 	TXT_CRATER,
     62 	1,1,							// Width and height of smudge (in icons).
     63 	false,						// Is this a building bib?
     64 	true							// Is this a crater smudge?
     65 );
     66 static SmudgeTypeClass const Crater3 (
     67 	SMUDGE_CRATER3,
     68 	"CR3",
     69 	TXT_CRATER,
     70 	1,1,							// Width and height of smudge (in icons).
     71 	false,						// Is this a building bib?
     72 	true							// Is this a crater smudge?
     73 );
     74 static SmudgeTypeClass const Crater4 (
     75 	SMUDGE_CRATER4,
     76 	"CR4",
     77 	TXT_CRATER,
     78 	1,1,							// Width and height of smudge (in icons).
     79 	false,						// Is this a building bib?
     80 	true							// Is this a crater smudge?
     81 );
     82 static SmudgeTypeClass const Crater5 (
     83 	SMUDGE_CRATER5,
     84 	"CR5",
     85 	TXT_CRATER,
     86 	1,1,							// Width and height of smudge (in icons).
     87 	false,						// Is this a building bib?
     88 	true							// Is this a crater smudge?
     89 );
     90 static SmudgeTypeClass const Crater6 (
     91 	SMUDGE_CRATER6,
     92 	"CR6",
     93 	TXT_CRATER,
     94 	1,1,							// Width and height of smudge (in icons).
     95 	false,						// Is this a building bib?
     96 	true							// Is this a crater smudge?
     97 );
     98 static SmudgeTypeClass const Scorch1 (
     99 	SMUDGE_SCORCH1,
    100 	"SC1",
    101 	TXT_SCORCH,
    102 	1,1,							// Width and height of smudge (in icons).
    103 	false,						// Is this a building bib?
    104 	false							// Is this a crater smudge?
    105 );
    106 static SmudgeTypeClass const Scorch2 (
    107 	SMUDGE_SCORCH2,
    108 	"SC2",
    109 	TXT_SCORCH,
    110 	1,1,							// Width and height of smudge (in icons).
    111 	false,						// Is this a building bib?
    112 	false							// Is this a crater smudge?
    113 );
    114 static SmudgeTypeClass const Scorch3 (
    115 	SMUDGE_SCORCH3,
    116 	"SC3",
    117 	TXT_SCORCH,
    118 	1,1,							// Width and height of smudge (in icons).
    119 	false,						// Is this a building bib?
    120 	false							// Is this a crater smudge?
    121 );
    122 static SmudgeTypeClass const Scorch4 (
    123 	SMUDGE_SCORCH4,
    124 	"SC4",
    125 	TXT_SCORCH,
    126 	1,1,							// Width and height of smudge (in icons).
    127 	false,						// Is this a building bib?
    128 	false							// Is this a crater smudge?
    129 );
    130 static SmudgeTypeClass const Scorch5 (
    131 	SMUDGE_SCORCH5,
    132 	"SC5",
    133 	TXT_SCORCH,
    134 	1,1,							// Width and height of smudge (in icons).
    135 	false,						// Is this a building bib?
    136 	false							// Is this a crater smudge?
    137 );
    138 static SmudgeTypeClass const Scorch6 (
    139 	SMUDGE_SCORCH6,
    140 	"SC6",
    141 	TXT_SCORCH,
    142 	1,1,							// Width and height of smudge (in icons).
    143 	false,						// Is this a building bib?
    144 	false							// Is this a crater smudge?
    145 );
    146 
    147 static SmudgeTypeClass const Bibx1 (
    148 	SMUDGE_BIB1,
    149 	"BIB1",
    150 	TXT_BIB,
    151 	4,2,							// Width and height of smudge (in icons).
    152 	true,							// Is this a building bib?
    153 	false							// Is this a crater smudge?
    154 );
    155 static SmudgeTypeClass const Bibx2 (
    156 	SMUDGE_BIB2,
    157 	"BIB2",
    158 	TXT_BIB,
    159 	3,2,							// Width and height of smudge (in icons).
    160 	true,							// Is this a building bib?
    161 	false							// Is this a crater smudge?
    162 );
    163 
    164 /*
    165 ** The watcom code optimiser screws up the last constructor call. Making it 'volatile' reduces the
    166 ** level of optimisation enough for the problem not to manifest.
    167 */
    168 volatile SmudgeTypeClass const Bibx3 (
    169 	SMUDGE_BIB3,
    170 	"BIB3",
    171 	TXT_BIB,
    172 	2,2,							// Width and height of smudge (in icons).
    173 	true,							// Is this a building bib?
    174 	false							// Is this a crater smudge?
    175 );
    176 
    177 /*
    178 **	Working array to the smudge control objects types. This routine is
    179 **	used for quick conversion from a SmudgeType number into an actual
    180 **	smudge type object pointer.
    181 */
    182 SmudgeTypeClass const * const SmudgeTypeClass::Pointers[SMUDGE_COUNT] = {
    183 	&Crater1,			// SMUDGE_CRATER1
    184 	&Crater2,			// SMUDGE_CRATER2
    185 	&Crater3,			// SMUDGE_CRATER3
    186 	&Crater4,			// SMUDGE_CRATER4
    187 	&Crater5,			// SMUDGE_CRATER5
    188 	&Crater6,			// SMUDGE_CRATER6
    189 	&Scorch1,			// SMUDGE_SCORCH1
    190 	&Scorch2,			// SMUDGE_SCORCH2
    191 	&Scorch3,			// SMUDGE_SCORCH3
    192 	&Scorch4,			// SMUDGE_SCORCH4
    193 	&Scorch5,			// SMUDGE_SCORCH5
    194 	&Scorch6,			// SMUDGE_SCORCH6
    195 	&Bibx1,				// SMUDGE_BIB1
    196 	&Bibx2,				//	SMUDGE_BIB2
    197 	(SmudgeTypeClass const * const)&Bibx3				// SMUDGE_BIB3
    198 };
    199 
    200 
    201 /***********************************************************************************************
    202  * SmudgeTypeClass::SmudgeTypeClass -- Constructor for smudge type objects.                    *
    203  *                                                                                             *
    204  *    This constructor is used to create the smudge type objects. These type objects contain   *
    205  *    static information about the various smudge types supported in the game.                 *
    206  *                                                                                             *
    207  * INPUT:   see below...                                                                       *
    208  *                                                                                             *
    209  * OUTPUT:  none                                                                               *
    210  *                                                                                             *
    211  * WARNINGS:   none                                                                            *
    212  *                                                                                             *
    213  * HISTORY:                                                                                    *
    214  *   08/12/1994 JLB : Created.                                                                 *
    215  *=============================================================================================*/
    216 SmudgeTypeClass::SmudgeTypeClass(SmudgeType smudge, char const *ininame, int fullname, int width, int height, bool isbib, bool iscrater) :
    217 	ObjectTypeClass(false, false, false, true, false, false, true, true, fullname, ininame, ARMOR_NONE, 0)
    218 {
    219 	IsBib = isbib;
    220 	Width = width;
    221 	Height = height;
    222 	IsCrater = iscrater;
    223 	Type = smudge;
    224 }
    225 
    226 /***********************************************************************************************
    227  * SmudgeTypeClass::From_Name -- Converts an ASCII name into a smudge type.                    *
    228  *                                                                                             *
    229  *    This converts an ASCII name into a smudge type number. This is typically necessary       *
    230  *    when processing scenario INI files and not used otherwise.                               *
    231  *                                                                                             *
    232  * INPUT:   name  -- Pointer to the name to convert.                                           *
    233  *                                                                                             *
    234  * OUTPUT:  Returns with the SmudgeType number that matches the name supplied. If no match     *
    235  *          was found, then SMUDGE_NONE is returned.                                           *
    236  *                                                                                             *
    237  * WARNINGS:   none                                                                            *
    238  *                                                                                             *
    239  * HISTORY:                                                                                    *
    240  *   08/12/1994 JLB : Created.                                                                 *
    241  *=============================================================================================*/
    242 SmudgeType SmudgeTypeClass::From_Name(char const *name)
    243 {
    244 	if (name) {
    245 		for (SmudgeType index = SMUDGE_FIRST; index < SMUDGE_COUNT; index++) {
    246 			if (stricmp(As_Reference(index).IniName, name) == 0) {
    247 				return(index);
    248 			}
    249 		}
    250 	}
    251 	return(SMUDGE_NONE);
    252 }
    253 
    254 
    255 /***********************************************************************************************
    256  * SmudgetypeClass::Occupy_List -- Determines occupation list for smudge object.               *
    257  *                                                                                             *
    258  *    Smudges are always only one icon in dimension, so this routine always returns a cell     *
    259  *    occupation offset list of the center cell.                                               *
    260  *                                                                                             *
    261  * INPUT:   placement   -- Is this for placement legality checking only? The normal condition  *
    262  *                         is for marking occupation flags.                                    *
    263  *                                                                                             *
    264  * OUTPUT:  Returns occupation list specifying all the cells that the overlay occupies. This   *
    265  *          is just the center cell.                                                           *
    266  *                                                                                             *
    267  * WARNINGS:   none                                                                            *
    268  *                                                                                             *
    269  * HISTORY:                                                                                    *
    270  *   08/12/1994 JLB : Created.                                                                 *
    271  *=============================================================================================*/
    272 short const * SmudgeTypeClass::Occupy_List(bool) const
    273 {
    274 	static short _occupy[4*4];
    275 	short * ptr = &_occupy[0];
    276 
    277 	for (int x = 0; x < Width; x++) {
    278 		for (int y = 0; y < Height; y++) {
    279 			*ptr++ = x + (y*MAP_CELL_W);
    280 		}
    281 	}
    282 	*ptr = REFRESH_EOL;
    283 	return(_occupy);
    284 }
    285 
    286 
    287 /***********************************************************************************************
    288  * SmudgeTypeClass::Init -- Performs theater specific initializations.                         *
    289  *                                                                                             *
    290  *    Smudge object imagery varies between theaters. This routine will load the appropriate    *
    291  *    imagery for the theater specified.                                                       *
    292  *                                                                                             *
    293  * INPUT:   theater  -- The theater to prepare for.                                            *
    294  *                                                                                             *
    295  * OUTPUT:  none                                                                               *
    296  *                                                                                             *
    297  * WARNINGS:   none                                                                            *
    298  *                                                                                             *
    299  * HISTORY:                                                                                    *
    300  *   08/12/1994 JLB : Created.                                                                 *
    301  *=============================================================================================*/
    302 void SmudgeTypeClass::Init(TheaterType theater)
    303 {
    304 	if (theater != LastTheater){
    305 		for (SmudgeType index = SMUDGE_FIRST; index < SMUDGE_COUNT; index++) {
    306 			SmudgeTypeClass const & smudge = As_Reference(index);
    307 			char fullname[_MAX_FNAME+_MAX_EXT];	// Fully constructed smudge data set name.
    308 
    309 			_makepath(fullname, NULL, NULL, smudge.IniName, Theaters[theater].Suffix);
    310 			((void const *&)smudge.ImageData) = MixFileClass::Retrieve(fullname);
    311 		}
    312 	}
    313 }
    314 
    315 
    316 #ifdef SCENARIO_EDITOR
    317 /***********************************************************************************************
    318  * SmudgeTypeClass::Display -- Draws a generic version of this smudge type.                    *
    319  *                                                                                             *
    320  *    The scenario object editor will call this routine to display a typical imagery of this   *
    321  *    smudge object for graphical identification purposes.                                     *
    322  *                                                                                             *
    323  * INPUT:   x,y   -- Coordinate to render the smudge at.                                       *
    324  *                                                                                             *
    325  *          window-- The window to base the coordinate rendering upon.                         *
    326  *                                                                                             *
    327  * OUTPUT:  none                                                                               *
    328  *                                                                                             *
    329  * WARNINGS:   none                                                                            *
    330  *                                                                                             *
    331  * HISTORY:                                                                                    *
    332  *   08/12/1994 JLB : Created.                                                                 *
    333  *=============================================================================================*/
    334 void SmudgeTypeClass::Display(int x, int y, WindowNumberType window, HousesType ) const
    335 {
    336 	void const *ptr = Get_Image_Data();
    337 
    338 	x += WindowList[window][WINDOWX] << 3;
    339 	y += WindowList[window][WINDOWY];
    340 
    341 	if (ptr) {
    342 		for (int w = 0; w < Width; w++) {
    343 			for (int h = 0; h < Height; h++) {
    344 				CC_Draw_Shape(ptr, 0, x + w*ICON_PIXEL_W, y + h*ICON_PIXEL_H, WINDOW_TACTICAL, SHAPE_WIN_REL);
    345 				//LogicPage->Draw_Stamp(ptr, w + (h*Width), x + w*ICON_PIXEL_W, y + h*ICON_PIXEL_H, NULL, WINDOW_TACTICAL);
    346 			}
    347 		}
    348 	}
    349 }
    350 
    351 
    352 /***********************************************************************************************
    353  * SmudgeTypeClass::Prep_For_Add -- Prepares the scenario editor for adding a smudge object.   *
    354  *                                                                                             *
    355  *    This routine adds smudge objects to the list of objects that the scenario editor can     *
    356  *    place upon the ground. It is only called from the scenario editor.                       *
    357  *                                                                                             *
    358  * INPUT:   none                                                                               *
    359  *                                                                                             *
    360  * OUTPUT:  none                                                                               *
    361  *                                                                                             *
    362  * WARNINGS:   none                                                                            *
    363  *                                                                                             *
    364  * HISTORY:                                                                                    *
    365  *   08/12/1994 JLB : Created.                                                                 *
    366  *=============================================================================================*/
    367 void SmudgeTypeClass::Prep_For_Add(void)
    368 {
    369 	for (SmudgeType index = SMUDGE_FIRST; index < SMUDGE_COUNT; index++) {
    370 		if (As_Reference(index).Get_Image_Data()) {
    371 			Map.Add_To_List(&As_Reference(index));
    372 		}
    373 	}
    374 }
    375 #endif
    376 
    377 
    378 /***********************************************************************************************
    379  * SmudgeTypeClass::Create_And_Place -- Creates and places on map, a smudge object.            *
    380  *                                                                                             *
    381  *    This routine will, in one motion, create a smudge object and place it upon the map.      *
    382  *    Since placing a smudge on the map will destroy the object, this routine will leave the   *
    383  *    smudge object count unchanged. Typically, this routine is used by the scenario editor    *
    384  *    for creating smudges and placing them on the map.                                        *
    385  *                                                                                             *
    386  * INPUT:   cell  -- The cell to place the smudge object.                                      *
    387  *                                                                                             *
    388  * OUTPUT:  bool; Was the placement successful?                                                *
    389  *                                                                                             *
    390  * WARNINGS:   none                                                                            *
    391  *                                                                                             *
    392  * HISTORY:                                                                                    *
    393  *   08/12/1994 JLB : Created.                                                                 *
    394  *=============================================================================================*/
    395 bool SmudgeTypeClass::Create_And_Place(CELL cell, HousesType ) const
    396 {
    397 	if (new SmudgeClass(Type, Cell_Coord(cell))) {
    398 		return(true);
    399 	}
    400 	return(false);
    401 }
    402 
    403 
    404 /***********************************************************************************************
    405  * SmudgeTypeClass::Create_One_Of -- Creates a smudge object of this type.                     *
    406  *                                                                                             *
    407  *    This routine will create a smudge object of the appropriate type. Smudge objects are     *
    408  *    transitory in nature. They exist only from the point of creation until they are given    *
    409  *    a spot on the map to reside. At that time the map data is updated and the smudge         *
    410  *    object is destroyed.                                                                     *
    411  *                                                                                             *
    412  * INPUT:   none                                                                               *
    413  *                                                                                             *
    414  * OUTPUT:  Returns with a pointer to a created smudge object. If none could be created, then  *
    415  *          NULL is returned.                                                                  *
    416  *                                                                                             *
    417  * WARNINGS:   none                                                                            *
    418  *                                                                                             *
    419  * HISTORY:                                                                                    *
    420  *   08/12/1994 JLB : Created.                                                                 *
    421  *=============================================================================================*/
    422 ObjectClass * SmudgeTypeClass::Create_One_Of(HouseClass *) const
    423 {
    424 	return(new SmudgeClass(Type, -1));
    425 }
    426 
    427 
    428 /***********************************************************************************************
    429  * SmudgeTypeClass::Draw_It -- Renders the smudge image at the coordinate specified.           *
    430  *                                                                                             *
    431  *    This routine will draw the smudge overlay image at the coordinate (upper left)           *
    432  *    specified. The underlying terrain icon is presumed to have already been rendered.        *
    433  *                                                                                             *
    434  * INPUT:   x,y   -- Coordinate of the upper left corner of icon to render the smudge object.  *
    435  *                                                                                             *
    436  * OUTPUT:  none                                                                               *
    437  *                                                                                             *
    438  * WARNINGS:   none                                                                            *
    439  *                                                                                             *
    440  * HISTORY:                                                                                    *
    441  *   08/12/1994 JLB : Created.                                                                 *
    442  *=============================================================================================*/
    443 void SmudgeTypeClass::Draw_It(int x, int y, int data) const
    444 {
    445 	void const * ptr = Get_Image_Data();
    446 	if (ptr) {
    447 		IsTheaterShape = true;		// Smudges are theater specific
    448 		CC_Draw_Shape(ptr, data, x, y, WINDOW_TACTICAL, SHAPE_WIN_REL);
    449 		IsTheaterShape = false;
    450 //		LogicPage->Draw_Stamp(ptr, data, x, y, NULL, WINDOW_TACTICAL);
    451 	}
    452 }
    453 
    454 
    455 /***********************************************************************************************
    456  * SmudgeTypeClass::One_Time -- Performs one-time initialization                               *
    457  *                                                                                             *
    458  * INPUT:   none                                                                               *
    459  *                                                                                             *
    460  * OUTPUT:  none                                                                               *
    461  *                                                                                             *
    462  * WARNINGS:   none                                                                            *
    463  *                                                                                             *
    464  * HISTORY:                                                                                    *
    465  *   08/12/1994 JLB : Created.                                                                 *
    466  *=============================================================================================*/
    467 void SmudgeTypeClass::One_Time(void)
    468 {
    469 }
    470