SDATA.CPP (32459B)
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/SDATA.CPP 1 3/03/97 10:25a 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 : July 9, 1996 [JLB] * 30 * * 31 *---------------------------------------------------------------------------------------------* 32 * Functions: * 33 * SmudgeTypeClass::As_Reference -- Fetches a reference to the smudge type specified. * 34 * SmudgeTypeClass::Create_And_Place -- Creates and places on map, a smudge object. * 35 * SmudgeTypeClass::Create_One_Of -- Creates a smudge object of this type. * 36 * SmudgeTypeClass::Display -- Draws a generic version of this smudge type. * 37 * SmudgeTypeClass::Draw_It -- Renders the smudge image at the coordinate specified. * 38 * SmudgeTypeClass::From_Name -- Converts an ASCII name into a smudge type. * 39 * SmudgeTypeClass::Init -- Performs theater specific initializations. * 40 * SmudgeTypeClass::Init_Heap -- Initialize the smudge type class object heap. * 41 * SmudgeTypeClass::One_Time -- Performs one-time initialization * 42 * SmudgeTypeClass::Prep_For_Add -- Prepares the scenario editor for adding a smudge object. * 43 * SmudgeTypeClass::SmudgeTypeClass -- Constructor for smudge type objects. * 44 * SmudgeTypeClass::operator delete -- Returns a smudge type class object to the pool. * 45 * SmudgeTypeClass::operator new -- Allocate a smudge type object from the memory pool. * 46 * SmudgetypeClass::Occupy_List -- Determines occupation list for smudge object. * 47 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 48 49 #include "function.h" 50 #include "type.h" 51 52 53 static SmudgeTypeClass const Crater1 ( 54 SMUDGE_CRATER1, 55 "CR1", 56 TXT_CRATER, 57 1,1, // Width and height of smudge (in icons). 58 false, // Is this a building bib? 59 true // Is this a crater smudge? 60 ); 61 static SmudgeTypeClass const Crater2 ( 62 SMUDGE_CRATER2, 63 "CR2", 64 TXT_CRATER, 65 1,1, // Width and height of smudge (in icons). 66 false, // Is this a building bib? 67 true // Is this a crater smudge? 68 ); 69 static SmudgeTypeClass const Crater3 ( 70 SMUDGE_CRATER3, 71 "CR3", 72 TXT_CRATER, 73 1,1, // Width and height of smudge (in icons). 74 false, // Is this a building bib? 75 true // Is this a crater smudge? 76 ); 77 static SmudgeTypeClass const Crater4 ( 78 SMUDGE_CRATER4, 79 "CR4", 80 TXT_CRATER, 81 1,1, // Width and height of smudge (in icons). 82 false, // Is this a building bib? 83 true // Is this a crater smudge? 84 ); 85 static SmudgeTypeClass const Crater5 ( 86 SMUDGE_CRATER5, 87 "CR5", 88 TXT_CRATER, 89 1,1, // Width and height of smudge (in icons). 90 false, // Is this a building bib? 91 true // Is this a crater smudge? 92 ); 93 static SmudgeTypeClass const Crater6 ( 94 SMUDGE_CRATER6, 95 "CR6", 96 TXT_CRATER, 97 1,1, // Width and height of smudge (in icons). 98 false, // Is this a building bib? 99 true // Is this a crater smudge? 100 ); 101 static SmudgeTypeClass const Scorch1 ( 102 SMUDGE_SCORCH1, 103 "SC1", 104 TXT_SCORCH, 105 1,1, // Width and height of smudge (in icons). 106 false, // Is this a building bib? 107 false // Is this a crater smudge? 108 ); 109 static SmudgeTypeClass const Scorch2 ( 110 SMUDGE_SCORCH2, 111 "SC2", 112 TXT_SCORCH, 113 1,1, // Width and height of smudge (in icons). 114 false, // Is this a building bib? 115 false // Is this a crater smudge? 116 ); 117 static SmudgeTypeClass const Scorch3 ( 118 SMUDGE_SCORCH3, 119 "SC3", 120 TXT_SCORCH, 121 1,1, // Width and height of smudge (in icons). 122 false, // Is this a building bib? 123 false // Is this a crater smudge? 124 ); 125 static SmudgeTypeClass const Scorch4 ( 126 SMUDGE_SCORCH4, 127 "SC4", 128 TXT_SCORCH, 129 1,1, // Width and height of smudge (in icons). 130 false, // Is this a building bib? 131 false // Is this a crater smudge? 132 ); 133 static SmudgeTypeClass const Scorch5 ( 134 SMUDGE_SCORCH5, 135 "SC5", 136 TXT_SCORCH, 137 1,1, // Width and height of smudge (in icons). 138 false, // Is this a building bib? 139 false // Is this a crater smudge? 140 ); 141 static SmudgeTypeClass const Scorch6 ( 142 SMUDGE_SCORCH6, 143 "SC6", 144 TXT_SCORCH, 145 1,1, // Width and height of smudge (in icons). 146 false, // Is this a building bib? 147 false // Is this a crater smudge? 148 ); 149 150 static SmudgeTypeClass const Bibx1 ( 151 SMUDGE_BIB1, 152 "BIB1", 153 TXT_BIB, 154 4,2, // Width and height of smudge (in icons). 155 true, // Is this a building bib? 156 false // Is this a crater smudge? 157 ); 158 static SmudgeTypeClass const Bibx2 ( 159 SMUDGE_BIB2, 160 "BIB2", 161 TXT_BIB, 162 3,2, // Width and height of smudge (in icons). 163 true, // Is this a building bib? 164 false // Is this a crater smudge? 165 ); 166 static SmudgeTypeClass const Bibx3 ( 167 SMUDGE_BIB3, 168 "BIB3", 169 TXT_BIB, 170 2,2, // Width and height of smudge (in icons). 171 true, // Is this a building bib? 172 false // Is this a crater smudge? 173 ); 174 175 176 /*********************************************************************************************** 177 * SmudgeTypeClass::SmudgeTypeClass -- Constructor for smudge type objects. * 178 * * 179 * This constructor is used to create the smudge type objects. These type objects contain * 180 * static information about the various smudge types supported in the game. * 181 * * 182 * INPUT: see below... * 183 * * 184 * OUTPUT: none * 185 * * 186 * WARNINGS: none * 187 * * 188 * HISTORY: * 189 * 08/12/1994 JLB : Created. * 190 *=============================================================================================*/ 191 SmudgeTypeClass::SmudgeTypeClass( 192 SmudgeType smudge, 193 char const * ininame, 194 int fullname, 195 int width, 196 int height, 197 bool isbib, 198 bool iscrater) : 199 ObjectTypeClass( 200 RTTI_SMUDGETYPE, 201 int(smudge), 202 false, 203 true, 204 false, 205 false, 206 true, 207 true, 208 false, 209 fullname, 210 ininame), 211 Type(smudge), 212 Width(width), 213 Height(height), 214 IsCrater(iscrater), 215 IsBib(isbib) 216 { 217 } 218 219 220 /*********************************************************************************************** 221 * SmudgeTypeClass::operator new -- Allocate a smudge type object from the memory pool. * 222 * * 223 * This will allocate a smudge type class object from the special memory pool for that * 224 * purpose. * 225 * * 226 * INPUT: none * 227 * * 228 * OUTPUT: Returns with the newly allocated smudge type class object. If there is insufficient* 229 * memory in the pool to fulfill the request, then NULL is returned. * 230 * * 231 * WARNINGS: none * 232 * * 233 * HISTORY: * 234 * 07/09/1996 JLB : Created. * 235 *=============================================================================================*/ 236 void * SmudgeTypeClass::operator new(size_t) 237 { 238 return(SmudgeTypes.Alloc()); 239 } 240 241 242 /*********************************************************************************************** 243 * SmudgeTypeClass::operator delete -- Returns a smudge type class object to the pool. * 244 * * 245 * This will return the smudge type class object back to the memory pool from whence it * 246 * was originally allocated. * 247 * * 248 * INPUT: pointer -- Pointer to the smudge type class object to return the pool. * 249 * * 250 * OUTPUT: none * 251 * * 252 * WARNINGS: none * 253 * * 254 * HISTORY: * 255 * 07/09/1996 JLB : Created. * 256 *=============================================================================================*/ 257 void SmudgeTypeClass::operator delete(void * pointer) 258 { 259 SmudgeTypes.Free((SmudgeTypeClass *)pointer); 260 } 261 262 263 /*********************************************************************************************** 264 * SmudgeTypeClass::Init_Heap -- Initialize the smudge type class object heap. * 265 * * 266 * This will initialize the special heap for smudge type class objects, by pre-allocated * 267 * all known smudge types. * 268 * * 269 * INPUT: none * 270 * * 271 * OUTPUT: none * 272 * * 273 * WARNINGS: Call this routine only once and before the rules.ini file is processed. * 274 * * 275 * HISTORY: * 276 * 07/09/1996 JLB : Created. * 277 *=============================================================================================*/ 278 void SmudgeTypeClass::Init_Heap(void) 279 { 280 /* 281 ** These smudge type class objects must be allocated in the exact order that they 282 ** are specified in the SmudgeType enumeration. This is necessary because the heap 283 ** allocation block index serves double duty as the type number index. 284 */ 285 new SmudgeTypeClass(Crater1); // SMUDGE_CRATER1 286 new SmudgeTypeClass(Crater2); // SMUDGE_CRATER2 287 new SmudgeTypeClass(Crater3); // SMUDGE_CRATER3 288 new SmudgeTypeClass(Crater4); // SMUDGE_CRATER4 289 new SmudgeTypeClass(Crater5); // SMUDGE_CRATER5 290 new SmudgeTypeClass(Crater6); // SMUDGE_CRATER6 291 new SmudgeTypeClass(Scorch1); // SMUDGE_SCORCH1 292 new SmudgeTypeClass(Scorch2); // SMUDGE_SCORCH2 293 new SmudgeTypeClass(Scorch3); // SMUDGE_SCORCH3 294 new SmudgeTypeClass(Scorch4); // SMUDGE_SCORCH4 295 new SmudgeTypeClass(Scorch5); // SMUDGE_SCORCH5 296 new SmudgeTypeClass(Scorch6); // SMUDGE_SCORCH6 297 new SmudgeTypeClass(Bibx1); // SMUDGE_BIB1 298 new SmudgeTypeClass(Bibx2); // SMUDGE_BIB2 299 new SmudgeTypeClass(Bibx3); // SMUDGE_BIB3 300 } 301 302 303 /*********************************************************************************************** 304 * SmudgeTypeClass::From_Name -- Converts an ASCII name into a smudge type. * 305 * * 306 * This converts an ASCII name into a smudge type number. This is typically necessary * 307 * when processing scenario INI files and not used otherwise. * 308 * * 309 * INPUT: name -- Pointer to the name to convert. * 310 * * 311 * OUTPUT: Returns with the SmudgeType number that matches the name supplied. If no match * 312 * was found, then SMUDGE_NONE is returned. * 313 * * 314 * WARNINGS: none * 315 * * 316 * HISTORY: * 317 * 08/12/1994 JLB : Created. * 318 *=============================================================================================*/ 319 SmudgeType SmudgeTypeClass::From_Name(char const * name) 320 { 321 if (name != NULL) { 322 for (SmudgeType index = SMUDGE_FIRST; index < SMUDGE_COUNT; index++) { 323 if (stricmp(As_Reference(index).IniName, name) == 0) { 324 return(index); 325 } 326 } 327 } 328 return(SMUDGE_NONE); 329 } 330 331 332 /*********************************************************************************************** 333 * SmudgetypeClass::Occupy_List -- Determines occupation list for smudge object. * 334 * * 335 * Smudges are always only one icon in dimension, so this routine always returns a cell * 336 * occupation offset list of the center cell. * 337 * * 338 * INPUT: placement -- Is this for placement legality checking only? The normal condition * 339 * is for marking occupation flags. * 340 * * 341 * OUTPUT: Returns occupation list specifying all the cells that the overlay occupies. This * 342 * is just the center cell. * 343 * * 344 * WARNINGS: none * 345 * * 346 * HISTORY: * 347 * 08/12/1994 JLB : Created. * 348 *=============================================================================================*/ 349 short const * SmudgeTypeClass::Occupy_List(bool) const 350 { 351 static short _occupy[4*4]; 352 short * ptr = &_occupy[0]; 353 354 for (int x = 0; x < Width; x++) { 355 for (int y = 0; y < Height; y++) { 356 *ptr++ = x + (y*MAP_CELL_W); 357 } 358 } 359 *ptr = REFRESH_EOL; 360 return(_occupy); 361 } 362 363 364 /*********************************************************************************************** 365 * SmudgeTypeClass::Init -- Performs theater specific initializations. * 366 * * 367 * Smudge object imagery varies between theaters. This routine will load the appropriate * 368 * imagery for the theater specified. * 369 * * 370 * INPUT: theater -- The theater to prepare for. * 371 * * 372 * OUTPUT: none * 373 * * 374 * WARNINGS: none * 375 * * 376 * HISTORY: * 377 * 08/12/1994 JLB : Created. * 378 *=============================================================================================*/ 379 void SmudgeTypeClass::Init(TheaterType theater) 380 { 381 if (theater != LastTheater) { 382 for (SmudgeType index = SMUDGE_FIRST; index < SMUDGE_COUNT; index++) { 383 SmudgeTypeClass const & smudge = As_Reference(index); 384 char fullname[_MAX_FNAME+_MAX_EXT]; // Fully constructed smudge data set name. 385 386 _makepath(fullname, NULL, NULL, smudge.IniName, Theaters[theater].Suffix); 387 ((void const *&)smudge.ImageData) = MFCD::Retrieve(fullname); 388 } 389 } 390 } 391 392 393 #ifdef SCENARIO_EDITOR 394 /*********************************************************************************************** 395 * SmudgeTypeClass::Display -- Draws a generic version of this smudge type. * 396 * * 397 * The scenario object editor will call this routine to display a typical imagery of this * 398 * smudge object for graphical identification purposes. * 399 * * 400 * INPUT: x,y -- Coordinate to render the smudge at. * 401 * * 402 * window-- The window to base the coordinate rendering upon. * 403 * * 404 * OUTPUT: none * 405 * * 406 * WARNINGS: none * 407 * * 408 * HISTORY: * 409 * 08/12/1994 JLB : Created. * 410 *=============================================================================================*/ 411 void SmudgeTypeClass::Display(int x, int y, WindowNumberType window, HousesType ) const 412 { 413 void const * ptr = Get_Image_Data(); 414 415 x += WindowList[window][WINDOWX]; 416 y += WindowList[window][WINDOWY]; 417 418 IsTheaterShape = true; // Smudges are theater specific 419 if (ptr != NULL) { 420 for (int w = 0; w < Width; w++) { 421 for (int h = 0; h < Height; h++) { 422 CC_Draw_Shape(ptr, w + (h*Width), x + w*ICON_PIXEL_W, y + h*ICON_PIXEL_H, WINDOW_TACTICAL, SHAPE_WIN_REL); 423 } 424 } 425 } 426 IsTheaterShape = false; 427 } 428 429 430 /*********************************************************************************************** 431 * SmudgeTypeClass::Prep_For_Add -- Prepares the scenario editor for adding a smudge object. * 432 * * 433 * This routine adds smudge objects to the list of objects that the scenario editor can * 434 * place upon the ground. It is only called from the scenario editor. * 435 * * 436 * INPUT: none * 437 * * 438 * OUTPUT: none * 439 * * 440 * WARNINGS: none * 441 * * 442 * HISTORY: * 443 * 08/12/1994 JLB : Created. * 444 *=============================================================================================*/ 445 void SmudgeTypeClass::Prep_For_Add(void) 446 { 447 for (SmudgeType index = SMUDGE_FIRST; index < SMUDGE_COUNT; index++) { 448 if (As_Reference(index).Get_Image_Data()) { 449 Map.Add_To_List(&As_Reference(index)); 450 } 451 } 452 } 453 #endif 454 455 456 /*********************************************************************************************** 457 * SmudgeTypeClass::Create_And_Place -- Creates and places on map, a smudge object. * 458 * * 459 * This routine will, in one motion, create a smudge object and place it upon the map. * 460 * Since placing a smudge on the map will destroy the object, this routine will leave the * 461 * smudge object count unchanged. Typically, this routine is used by the scenario editor * 462 * for creating smudges and placing them on the map. * 463 * * 464 * INPUT: cell -- The cell to place the smudge object. * 465 * * 466 * OUTPUT: bool; Was the placement successful? * 467 * * 468 * WARNINGS: none * 469 * * 470 * HISTORY: * 471 * 08/12/1994 JLB : Created. * 472 *=============================================================================================*/ 473 bool SmudgeTypeClass::Create_And_Place(CELL cell, HousesType ) const 474 { 475 if (new SmudgeClass(Type, Cell_Coord(cell))) { 476 return(true); 477 } 478 return(false); 479 } 480 481 482 /*********************************************************************************************** 483 * SmudgeTypeClass::Create_One_Of -- Creates a smudge object of this type. * 484 * * 485 * This routine will create a smudge object of the appropriate type. Smudge objects are * 486 * transitory in nature. They exist only from the point of creation until they are given * 487 * a spot on the map to reside. At that time the map data is updated and the smudge * 488 * object is destroyed. * 489 * * 490 * INPUT: none * 491 * * 492 * OUTPUT: Returns with a pointer to a created smudge object. If none could be created, then * 493 * NULL is returned. * 494 * * 495 * WARNINGS: none * 496 * * 497 * HISTORY: * 498 * 08/12/1994 JLB : Created. * 499 *=============================================================================================*/ 500 ObjectClass * SmudgeTypeClass::Create_One_Of(HouseClass *) const 501 { 502 return(new SmudgeClass(Type, -1)); 503 } 504 505 506 /*********************************************************************************************** 507 * SmudgeTypeClass::Draw_It -- Renders the smudge image at the coordinate specified. * 508 * * 509 * This routine will draw the smudge overlay image at the coordinate (upper left) * 510 * specified. The underlying terrain icon is presumed to have already been rendered. * 511 * * 512 * INPUT: x,y -- Coordinate of the upper left corner of icon to render the smudge object. * 513 * * 514 * OUTPUT: none * 515 * * 516 * WARNINGS: none * 517 * * 518 * HISTORY: * 519 * 08/12/1994 JLB : Created. * 520 *=============================================================================================*/ 521 void SmudgeTypeClass::Draw_It(int x, int y, int data) const 522 { 523 void const * ptr = Get_Image_Data(); 524 if (ptr != NULL) { 525 IsTheaterShape = true; // Smudges are theater specific 526 CC_Draw_Shape(ptr, data, x, y, WINDOW_TACTICAL, SHAPE_WIN_REL); 527 IsTheaterShape = false; 528 } 529 } 530 531 532 /*********************************************************************************************** 533 * SmudgeTypeClass::One_Time -- Performs one-time initialization * 534 * * 535 * INPUT: none * 536 * * 537 * OUTPUT: none * 538 * * 539 * WARNINGS: none * 540 * * 541 * HISTORY: * 542 * 08/12/1994 JLB : Created. * 543 *=============================================================================================*/ 544 void SmudgeTypeClass::One_Time(void) 545 { 546 } 547 548 549 /*********************************************************************************************** 550 * SmudgeTypeClass::As_Reference -- Fetches a reference to the smudge type specified. * 551 * * 552 * Use this routine to get a reference to the smudge type class object when given just * 553 * the smudge type identifier. * 554 * * 555 * INPUT: type -- The smudge type identifier to convert into a reference. * 556 * * 557 * OUTPUT: Returns with a reference to the smudge type class object. * 558 * * 559 * WARNINGS: Be sure that the smudge type specified is legal. An illegal type value will * 560 * produce undefined results. * 561 * * 562 * HISTORY: * 563 * 07/09/1996 JLB : Created. * 564 *=============================================================================================*/ 565 SmudgeTypeClass & SmudgeTypeClass::As_Reference(SmudgeType type) 566 { 567 return(*SmudgeTypes.Ptr(type)); 568 }