CnC_Remastered_Collection

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

IOMAP.CPP (67695B)


      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\iomap.cpv   2.18   16 Oct 1995 16:50:34   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 : IOMAP.CPP                                                    *
     24  *                                                                                             *
     25  *                   Programmer : Bill Randolph                                                *
     26  *                                                                                             *
     27  *                   Start Date : January 16, 1995                                             *
     28  *                                                                                             *
     29  *                  Last Update : January 16, 1995   [BR]                                      *
     30  *                                                                                             *
     31  *---------------------------------------------------------------------------------------------*
     32  * All map-related loading/saving routines should go in this module, so it can be overlayed.   *
     33  *---------------------------------------------------------------------------------------------*
     34  * Functions:                                                                                  *
     35  *   CellClass::Code_Pointers -- codes class's pointers for load/save                          *
     36  *   CellClass::Decode_Pointers -- decodes pointers for load/save                              *
     37  *   CellClass::Load -- Reads from a save game file.                                           *
     38  *   CellClass::Save -- Write to a save game file.                                             *
     39  *   CellClass::Should_Save -- Should the cell be written to disk?                             *
     40  *   DisplayClass::Code_Pointers -- codes class's pointers for load/save                       *
     41  *   DisplayClass::Decode_Pointers -- decodes pointers for load/save                           *
     42  *   GScreenClass::Code_Pointers -- codes class's pointers for load/save                       *
     43  *   GScreenClass::Decode_Pointers -- decodes pointers for load/save                           *
     44  *   HelpClass::Code_Pointers -- codes class's pointers for load/save                          *
     45  *   HelpClass::Decode_Pointers -- decodes pointers for load/save                              *
     46  *   MapClass::Code_Pointers -- codes class's pointers for load/save                           *
     47  *   MapClass::Decode_Pointers -- decodes pointers for load/save                               *
     48  *   MouseClass::Code_Pointers -- codes class's pointers for load/save                         *
     49  *   MouseClass::Decode_Pointers -- decodes pointers for load/save                             *
     50  *   MouseClass::Load -- Loads from a save game file.                                          *
     51  *   MouseClass::Save -- Saves to a save game file.                                            *
     52  *   PowerClass::Code_Pointers -- codes class's pointers for load/save                         *
     53  *   PowerClass::Decode_Pointers -- decodes pointers for load/save                             *
     54  *   RadarClass::Code_Pointers -- codes class's pointers for load/save                         *
     55  *   RadarClass::Decode_Pointers -- decodes pointers for load/save                             *
     56  *   ScrollClass::Code_Pointers -- codes class's pointers for load/save                        *
     57  *   ScrollClass::Decode_Pointers -- decodes pointers for load/save                            *
     58  *   SidebarClass::Code_Pointers -- codes class's pointers for load/save                       *
     59  *   SidebarClass::Decode_Pointers -- decodes pointers for load/save                           *
     60  *   SidebarClass::StripClass::Code_Pointers -- codes class's pointers for load/save           *
     61  *   SidebarClass::StripClass::Decode_Pointers -- decodes pointers for load/save               *
     62  *   TabClass::Code_Pointers -- codes class's pointers for load/save                           *
     63  *   TabClass::Decode_Pointers -- decodes pointers for load/save                               *
     64  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     65 
     66 #include "function.h"
     67 
     68 #pragma warning (disable : 4302)			// Truncation from pointer to TARGET
     69 
     70 /***********************************************************************************************
     71  * CellClass::Should_Save -- Should the cell be written to disk?                               *
     72  *                                                                                             *
     73  *    This function will determine if the cell needs to be written to disk. Any cell that      *
     74  *    contains special data should be written to disk.                                         *
     75  *                                                                                             *
     76  * INPUT:   none                                                                               *
     77  *                                                                                             *
     78  * OUTPUT:  bool; Should this cell's data be written to disk?                                  *
     79  *                                                                                             *
     80  * WARNINGS:   none                                                                            *
     81  *                                                                                             *
     82  * HISTORY:                                                                                    *
     83  *   09/19/1994 JLB : Created.                                                                 *
     84  *=============================================================================================*/
     85 bool CellClass::Should_Save(void) const
     86 {
     87 	return(
     88 			(Smudge != SMUDGE_NONE) ||
     89 			(TType != TEMPLATE_NONE) ||
     90 			(Overlay != OVERLAY_NONE) ||
     91 			IsMapped ||
     92 			IsVisible ||
     93 			IsMappedByPlayerMask ||
     94 			IsVisibleByPlayerMask ||
     95 			IsTrigger ||
     96 			Flag.Composite ||
     97 			OccupierPtr ||
     98 			Overlapper[0] || Overlapper[1] || Overlapper[2]
     99 			);
    100 }
    101 
    102 
    103 /***********************************************************************************************
    104  * CellClass::Load -- Loads from a save game file.                                             *
    105  *                                                                                             *
    106  * INPUT:   file  -- The file to read the cell's data from.                                    *
    107  *                                                                                             *
    108  * OUTPUT:  true = success, false = failure                                                    *
    109  *                                                                                             *
    110  * WARNINGS:   none                                                                            *
    111  *                                                                                             *
    112  * HISTORY:                                                                                    *
    113  *   09/19/1994 JLB : Created.                                                                 *
    114  *=============================================================================================*/
    115 bool CellClass::Load(FileClass & file)
    116 {
    117 	int rc;
    118 	TriggerClass * trig;
    119 
    120 	/*
    121 	-------------------------- Load the object data --------------------------
    122 	*/
    123 	rc = Read_Object(this, sizeof(CellClass), file, false);
    124 
    125 	/*
    126 	------------------------ Load the trigger pointer ------------------------
    127 	*/
    128 	if (rc) {
    129 		if (IsTrigger) {
    130 			if (file.Read(&trig,sizeof(trig)) != sizeof(trig))
    131 				return(false);
    132 			CellTriggers[Cell_Number()] = trig;
    133 		}
    134 	}
    135 
    136 	return(rc);
    137 }
    138 
    139 
    140 /***********************************************************************************************
    141  * CellClass::Save -- Write to a save game file.                                               *
    142  *                                                                                             *
    143  * INPUT:   file  -- The file to write the cell's data to.                                     *
    144  *                                                                                             *
    145  * OUTPUT:  true = success, false = failure                                                    *
    146  *                                                                                             *
    147  * WARNINGS:   none                                                                            *
    148  *                                                                                             *
    149  * HISTORY:                                                                                    *
    150  *   09/19/1994 JLB : Created.                                                                 *
    151  *=============================================================================================*/
    152 bool CellClass::Save(FileClass & file)
    153 {
    154 	int rc;
    155 	TriggerClass * trig;
    156 
    157 	/*
    158 	-------------------------- Save the object data --------------------------
    159 	*/
    160 	rc = Write_Object(this, sizeof(CellClass), file);
    161 
    162 	/*
    163 	------------------------ Save the trigger pointer ------------------------
    164 	*/
    165 	if (rc) {
    166 		if (IsTrigger) {
    167 			trig = CellTriggers[Cell_Number()];
    168 			if (file.Write(&trig,sizeof(trig)) != sizeof(trig))
    169 				return(false);
    170 		}
    171 	}
    172 
    173 	return(rc);
    174 }
    175 
    176 
    177 /***********************************************************************************************
    178  * CellClass::Code_Pointers -- codes class's pointers for load/save                            *
    179  *                                                                                             *
    180  * This routine "codes" the pointers in the class by converting them to a number               *
    181  * that still represents the object pointed to, but isn't actually a pointer.  This            *
    182  * allows a saved game to properly load without relying on the games data still                *
    183  * being in the exact same location.                                                           *
    184  *                                                                                             *
    185  * INPUT:                                                                                      *
    186  *      none.                                                                                  *
    187  *                                                                                             *
    188  * OUTPUT:                                                                                     *
    189  *      none.                                                                                  *
    190  *                                                                                             *
    191  * WARNINGS:                                                                                   *
    192  *      none.                                                                                  *
    193  *                                                                                             *
    194  * HISTORY:                                                                                    *
    195  *   01/02/1995 BR : Created.                                                                  *
    196  *=============================================================================================*/
    197 void CellClass::Code_Pointers(void)
    198 {
    199 	if (Cell_Occupier()) {
    200 		OccupierPtr = (ObjectClass *)OccupierPtr->As_Target();
    201 	}
    202 
    203 	if (Overlapper[0]) {
    204 		Overlapper[0] = (ObjectClass *)Overlapper[0]->As_Target();
    205 	}
    206 
    207 	if (Overlapper[1]) {
    208 		Overlapper[1] = (ObjectClass *)Overlapper[1]->As_Target();
    209 	}
    210 
    211 	if (Overlapper[2]) {
    212 		Overlapper[2] = (ObjectClass *)Overlapper[2]->As_Target();
    213 	}
    214 
    215 	/*
    216 	------------------------ Convert trigger pointer -------------------------
    217 	*/
    218 	if (IsTrigger) {
    219 		CellTriggers[Cell_Number()] = (TriggerClass *)CellTriggers[Cell_Number()]->As_Target();
    220 	}
    221 
    222 	/*
    223 	------------------------ Convert flag pointer -------------------------
    224 	*/
    225 	assert(CTFFlag == NULL);
    226 }
    227 
    228 
    229 /***********************************************************************************************
    230  * CellClass::Decode_Pointers -- decodes pointers for load/save                                *
    231  *                                                                                             *
    232  * This routine "decodes" the pointers coded in Code_Pointers by converting the                *
    233  * code values back into object pointers.                                                      *
    234  *                                                                                             *
    235  * INPUT:                                                                                      *
    236  *      none.                                                                                  *
    237  *                                                                                             *
    238  * OUTPUT:                                                                                     *
    239  *      none.                                                                                  *
    240  *                                                                                             *
    241  * WARNINGS:                                                                                   *
    242  *      none.                                                                                  *
    243  *                                                                                             *
    244  * HISTORY:                                                                                    *
    245  *   01/02/1995 BR : Created.                                                                  *
    246  *=============================================================================================*/
    247 void CellClass::Decode_Pointers(void)
    248 {
    249 	char bad[128];
    250 	
    251 	if (OccupierPtr) {
    252 		OccupierPtr = As_Object((TARGET)OccupierPtr, false);
    253 		Check_Ptr((void *)OccupierPtr,__FILE__,__LINE__);
    254 
    255 		/*
    256 		** Check for bad occupier that was saved. ST - 10/3/2019 11:50AM
    257 		*/
    258 		ObjectClass * optr = Cell_Occupier();
    259 		if (optr->IsActive == false) {
    260 			CellClass *cell0 = &Map[0];
    261 			int cell_number = this - cell0;
    262 			sprintf(bad, "Found bad cell occupier in cell %d", cell_number);
    263 			GlyphX_Debug_Print(bad);
    264 			OccupierPtr = NULL;
    265 		}
    266 	}
    267 
    268 	if (Overlapper[0]) {
    269 		Overlapper[0] = As_Object((TARGET)Overlapper[0], false);
    270 		Check_Ptr((void *)Overlapper[0],__FILE__,__LINE__);
    271 	}
    272 
    273 	if (Overlapper[1]) {
    274 		Overlapper[1] = As_Object((TARGET)Overlapper[1], false);
    275 		Check_Ptr((void *)Overlapper[1],__FILE__,__LINE__);
    276 	}
    277 
    278 	if (Overlapper[2]) {
    279 		Overlapper[2] = As_Object((TARGET)Overlapper[2], false);
    280 		Check_Ptr((void *)Overlapper[2],__FILE__,__LINE__);
    281 	}
    282 
    283 	/*
    284 	** Check for bad overlappers that were saved. ST - 10/3/2019 11:50AM
    285 	*/
    286 	for (int i=0 ; i <= 2 ; i++) {
    287 		if (Overlapper[i]) {
    288 			ObjectClass * optr = Overlapper[i];
    289 			if (optr->IsActive == false) {
    290 				CellClass *cell0 = &Map[0];
    291 				int cell_number = this - cell0;
    292 				sprintf(bad, "Found bad cell overlapper in slot %d of cell %d", i, cell_number);
    293 				GlyphX_Debug_Print(bad);
    294 				Overlapper[i] = NULL;
    295 			}
    296 		}
    297 	}
    298 
    299 
    300 	/*
    301 	**	Convert trigger pointer.
    302 	*/
    303 	if (IsTrigger) {
    304 		CellTriggers[Cell_Number()] = As_Trigger( (TARGET)CellTriggers[Cell_Number()], false );
    305 		Check_Ptr((void *)CellTriggers[Cell_Number()],__FILE__,__LINE__);
    306 	}
    307 
    308 	/*
    309 	**	Convert flag pointer.
    310 	*/
    311 	CTFFlag = NULL;
    312 }
    313 
    314 
    315 /***********************************************************************************************
    316  * MouseClass::Load -- Loads from a save game file.                                            *
    317  *                                                                                             *
    318  * Loading the map is very complicated.  Here are the steps:                                   *
    319  * - Read the Theater for this save-game                                                       *
    320  * - call Init_Theater to perform theater-specific inits                                       *
    321  * - call Free_Cells to free the cell array, because loading the map object will overwrite     *
    322  *   the pointer to the cell array                                                             *
    323  * - read the map object from disk                                                             *
    324  * - call Alloc_Cells to re-allocate the cell array                                            *
    325  * - call Init_Cells to set the cells to a known state, because not every cell will be loaded  *
    326  * - read the cell objects into the cell array                                                 *
    327  * - After the map & all objects have been loaded & the pointers decoded, Init_IO() >MUST< be  *
    328  *   called to restore the map's button list to the proper state.                              *
    329  *                                                                                             *
    330  * INPUT:   file  -- The file to read the cell's data from.                                    *
    331  *                                                                                             *
    332  * OUTPUT:  true = success, false = failure                                                    *
    333  *                                                                                             *
    334  * WARNINGS:   none                                                                            *
    335  *                                                                                             *
    336  * HISTORY:                                                                                    *
    337  *   09/19/1994 JLB : Created.                                                                 *
    338  *=============================================================================================*/
    339 bool MouseClass::Load(FileClass & file)
    340 {
    341 	unsigned count;
    342 	CELL cell = 0;
    343 	int index;
    344 //	int rc;
    345 //	int i;
    346 //	int j;
    347 
    348 	/*------------------------------------------------------------------------
    349 	Load Theater:  Even though this value is located in the DisplayClass,
    350 	it must be loaded first so initialization can be done before any other
    351 	map data is loaded.  If initialization isn't done first, data read from
    352 	disk will be over-written when initialization occurs.  This code must
    353 	go in the most-derived Map class.
    354 	------------------------------------------------------------------------*/
    355 	if (file.Read (&Theater,sizeof(Theater)) != sizeof(Theater))
    356 		return(false);
    357 
    358 	/*
    359 	** Remove any old theater specific uncompressed shapes
    360 	*/
    361 	if (Theater != LastTheater){
    362 		Reset_Theater_Shapes();
    363 	}
    364 
    365 	/*
    366 	------------------------- Init display mixfiles --------------------------
    367 	*/
    368 	Init_Theater(Theater);
    369 	TerrainTypeClass::Init(Theater);
    370 	TemplateTypeClass::Init(Theater);
    371 	OverlayTypeClass::Init(Theater);
    372 	UnitTypeClass::Init(Theater);
    373 	InfantryTypeClass::Init(Theater);
    374 	BuildingTypeClass::Init(Theater);
    375 	BulletTypeClass::Init(Theater);
    376 	AnimTypeClass::Init(Theater);
    377 	AircraftTypeClass::Init(Theater);
    378 	SmudgeTypeClass::Init(Theater);
    379 
    380 	LastTheater = Theater;
    381 
    382 	/*
    383 	** Free the cell array, because we're about to overwrite its pointers
    384 	*/
    385 	Free_Cells();
    386 
    387 	/*
    388 	** Read the entire map object in.  Only read in sizeof(MouseClass), so if we're
    389 	** in editor mode, none of the map editor object is read in.
    390 	*/
    391 	if (!Read_Object(this, sizeof(MouseClass), file, true)) {
    392 		return(false);
    393 	}
    394 
    395 	/*
    396 	** Reallocate the cell array
    397 	*/
    398 	Alloc_Cells();
    399 
    400 	/*
    401 	** Init all cells to empty
    402 	*/
    403 	Init_Cells();
    404 
    405 	/*
    406 	--------------------------- Read # cells saved ---------------------------
    407 	*/
    408 	if (file.Read(&count, sizeof(count)) != sizeof(count)) {
    409 		return(false);
    410 	}
    411 
    412 	/*
    413 	------------------------------- Read cells -------------------------------
    414 	*/
    415 	for (index = 0; index < (int)count; index++) {
    416 		if (file.Read(&cell, sizeof(cell)) != sizeof(cell))
    417 			return(false);
    418 
    419 		if (!(*this)[cell].Load(file))
    420 			return(false);
    421 	}
    422 
    423 	return(true);
    424 }
    425 
    426 
    427 /***********************************************************************************************
    428  * MouseClass::Save -- Save to a save game file.                                               *
    429  *                                                                                             *
    430  * INPUT:   file  -- The file to write the cell's data to.                                     *
    431  *                                                                                             *
    432  * OUTPUT:  true = success, false = failure                                                    *
    433  *                                                                                             *
    434  * WARNINGS:   none                                                                            *
    435  *                                                                                             *
    436  * HISTORY:                                                                                    *
    437  *   09/19/1994 JLB : Created.                                                                 *
    438  *=============================================================================================*/
    439 bool MouseClass::Save(FileClass & file)
    440 {
    441 	unsigned count;
    442 	long pos;
    443 
    444 	/*
    445 	-------------------------- Save Theater >first< --------------------------
    446 	*/
    447 	if (file.Write (&Theater,sizeof(Theater)) != sizeof(Theater))
    448 		return(false);
    449 
    450 	if (!Write_Object(this, sizeof(MouseClass), file))
    451 		return(false);
    452 
    453 	/*
    454 	---------------------- Record current file position ----------------------
    455 	*/
    456 	pos = file.Seek(0, SEEK_CUR);
    457 
    458 	/*
    459 	---------------------- write out placeholder bytes -----------------------
    460 	*/
    461 	if (file.Write(&count, sizeof(count)) != sizeof(count))
    462 		return(false);
    463 
    464 	/*
    465 	------------------------ Save cells that need it -------------------------
    466 	*/
    467 	count = 0;
    468 	for (CELL cell = 0; cell < MAP_CELL_TOTAL; cell++) {
    469 		
    470 		if ((*this)[cell].Should_Save()) {
    471 			if (file.Write(&cell, sizeof(cell)) != sizeof(cell))
    472 				return(false);
    473 
    474 			count++;
    475 
    476 			if (!(*this)[cell].Save(file))
    477 				return(false);
    478 		}
    479 	}
    480 
    481 	/*
    482 	-------------------------- Save # cells written --------------------------
    483 	*/
    484 	file.Seek(pos, SEEK_SET);
    485 
    486 	if (file.Write(&count, sizeof(count)) != sizeof(count))
    487 		return(false);
    488 
    489 	file.Seek(0, SEEK_END);
    490 
    491 	return(true);
    492 }
    493 
    494 
    495 /***********************************************************************************************
    496  * MouseClass::Code_Pointers -- codes class's pointers for load/save                           *
    497  *                                                                                             *
    498  * This routine "codes" the pointers in the class by converting them to a number               *
    499  * that still represents the object pointed to, but isn't actually a pointer.  This            *
    500  * allows a saved game to properly load without relying on the games data still                *
    501  * being in the exact same location.                                                           *
    502  *                                                                                             *
    503  * INPUT:                                                                                      *
    504  *      none.                                                                                  *
    505  *                                                                                             *
    506  * OUTPUT:                                                                                     *
    507  *      none.                                                                                  *
    508  *                                                                                             *
    509  * WARNINGS:                                                                                   *
    510  *      none.                                                                                  *
    511  *                                                                                             *
    512  * HISTORY:                                                                                    *
    513  *   01/02/1995 BR : Created.                                                                  *
    514  *=============================================================================================*/
    515 void MouseClass::Code_Pointers(void)
    516 {
    517 //	Control.Code_Pointers();
    518 
    519 	ScrollClass::Code_Pointers();
    520 }
    521 
    522 
    523 /***********************************************************************************************
    524  * MouseClass::Decode_Pointers -- decodes pointers for load/save                               *
    525  *                                                                                             *
    526  * This routine "decodes" the pointers coded in Code_Pointers by converting the                *
    527  * code values back into object pointers.                                                      *
    528  *                                                                                             *
    529  * INPUT:                                                                                      *
    530  *      none.                                                                                  *
    531  *                                                                                             *
    532  * OUTPUT:                                                                                     *
    533  *      none.                                                                                  *
    534  *                                                                                             *
    535  * WARNINGS:                                                                                   *
    536  *      none.                                                                                  *
    537  *                                                                                             *
    538  * HISTORY:                                                                                    *
    539  *   01/02/1995 BR : Created.                                                                  *
    540  *=============================================================================================*/
    541 void MouseClass::Decode_Pointers(void)
    542 {
    543 //	Control.Decode_Pointers();
    544 
    545 	ScrollClass::Decode_Pointers();
    546 }
    547 
    548 
    549 /***********************************************************************************************
    550  * ScrollClass::Code_Pointers -- codes class's pointers for load/save                          *
    551  *                                                                                             *
    552  * This routine "codes" the pointers in the class by converting them to a number               *
    553  * that still represents the object pointed to, but isn't actually a pointer.  This            *
    554  * allows a saved game to properly load without relying on the games data still                *
    555  * being in the exact same location.                                                           *
    556  *                                                                                             *
    557  * INPUT:                                                                                      *
    558  *      none.                                                                                  *
    559  *                                                                                             *
    560  * OUTPUT:                                                                                     *
    561  *      none.                                                                                  *
    562  *                                                                                             *
    563  * WARNINGS:                                                                                   *
    564  *      none.                                                                                  *
    565  *                                                                                             *
    566  * HISTORY:                                                                                    *
    567  *   01/02/1995 BR : Created.                                                                  *
    568  *=============================================================================================*/
    569 void ScrollClass::Code_Pointers(void)
    570 {
    571 	HelpClass::Code_Pointers();
    572 }
    573 
    574 
    575 /***********************************************************************************************
    576  * ScrollClass::Decode_Pointers -- decodes pointers for load/save                              *
    577  *                                                                                             *
    578  * This routine "decodes" the pointers coded in Code_Pointers by converting the                *
    579  * code values back into object pointers.                                                      *
    580  *                                                                                             *
    581  * INPUT:                                                                                      *
    582  *      none.                                                                                  *
    583  *                                                                                             *
    584  * OUTPUT:                                                                                     *
    585  *      none.                                                                                  *
    586  *                                                                                             *
    587  * WARNINGS:                                                                                   *
    588  *      none.                                                                                  *
    589  *                                                                                             *
    590  * HISTORY:                                                                                    *
    591  *   01/02/1995 BR : Created.                                                                  *
    592  *=============================================================================================*/
    593 void ScrollClass::Decode_Pointers(void)
    594 {
    595 	HelpClass::Decode_Pointers();
    596 }
    597 
    598 
    599 /***********************************************************************************************
    600  * HelpClass::Code_Pointers -- codes class's pointers for load/save                            *
    601  *                                                                                             *
    602  * This routine "codes" the pointers in the class by converting them to a number               *
    603  * that still represents the object pointed to, but isn't actually a pointer.  This            *
    604  * allows a saved game to properly load without relying on the games data still                *
    605  * being in the exact same location.                                                           *
    606  *                                                                                             *
    607  * INPUT:                                                                                      *
    608  *      none.                                                                                  *
    609  *                                                                                             *
    610  * OUTPUT:                                                                                     *
    611  *      none.                                                                                  *
    612  *                                                                                             *
    613  * WARNINGS:                                                                                   *
    614  *      none.                                                                                  *
    615  *                                                                                             *
    616  * HISTORY:                                                                                    *
    617  *   01/02/1995 BR : Created.                                                                  *
    618  *=============================================================================================*/
    619 void HelpClass::Code_Pointers(void)
    620 {
    621 	TabClass::Code_Pointers();
    622 }
    623 
    624 
    625 /***********************************************************************************************
    626  * HelpClass::Decode_Pointers -- decodes pointers for load/save                                *
    627  *                                                                                             *
    628  * This routine "decodes" the pointers coded in Code_Pointers by converting the                *
    629  * code values back into object pointers.                                                      *
    630  *                                                                                             *
    631  * INPUT:                                                                                      *
    632  *      none.                                                                                  *
    633  *                                                                                             *
    634  * OUTPUT:                                                                                     *
    635  *      none.                                                                                  *
    636  *                                                                                             *
    637  * WARNINGS:                                                                                   *
    638  *      none.                                                                                  *
    639  *                                                                                             *
    640  * HISTORY:                                                                                    *
    641  *   01/02/1995 BR : Created.                                                                  *
    642  *=============================================================================================*/
    643 void HelpClass::Decode_Pointers(void)
    644 {
    645 	TabClass::Decode_Pointers();
    646 }
    647 
    648 
    649 /***********************************************************************************************
    650  * TabClass::Code_Pointers -- codes class's pointers for load/save                             *
    651  *                                                                                             *
    652  * This routine "codes" the pointers in the class by converting them to a number               *
    653  * that still represents the object pointed to, but isn't actually a pointer.  This            *
    654  * allows a saved game to properly load without relying on the games data still                *
    655  * being in the exact same location.                                                           *
    656  *                                                                                             *
    657  * INPUT:                                                                                      *
    658  *      none.                                                                                  *
    659  *                                                                                             *
    660  * OUTPUT:                                                                                     *
    661  *      none.                                                                                  *
    662  *                                                                                             *
    663  * WARNINGS:                                                                                   *
    664  *      none.                                                                                  *
    665  *                                                                                             *
    666  * HISTORY:                                                                                    *
    667  *   01/02/1995 BR : Created.                                                                  *
    668  *=============================================================================================*/
    669 void TabClass::Code_Pointers(void)
    670 {
    671 	SidebarClass::Code_Pointers();
    672 }
    673 
    674 
    675 /***********************************************************************************************
    676  * TabClass::Decode_Pointers -- decodes pointers for load/save                                 *
    677  *                                                                                             *
    678  * This routine "decodes" the pointers coded in Code_Pointers by converting the                *
    679  * code values back into object pointers.                                                      *
    680  *                                                                                             *
    681  * INPUT:                                                                                      *
    682  *      none.                                                                                  *
    683  *                                                                                             *
    684  * OUTPUT:                                                                                     *
    685  *      none.                                                                                  *
    686  *                                                                                             *
    687  * WARNINGS:                                                                                   *
    688  *      none.                                                                                  *
    689  *                                                                                             *
    690  * HISTORY:                                                                                    *
    691  *   01/02/1995 BR : Created.                                                                  *
    692  *=============================================================================================*/
    693 void TabClass::Decode_Pointers(void)
    694 {
    695 	SidebarClass::Decode_Pointers();
    696 }
    697 
    698 
    699 /***********************************************************************************************
    700  * PowerClass::Code_Pointers -- codes class's pointers for load/save                           *
    701  *                                                                                             *
    702  * This routine "codes" the pointers in the class by converting them to a number               *
    703  * that still represents the object pointed to, but isn't actually a pointer.  This            *
    704  * allows a saved game to properly load without relying on the games data still                *
    705  * being in the exact same location.                                                           *
    706  *                                                                                             *
    707  * INPUT:                                                                                      *
    708  *      none.                                                                                  *
    709  *                                                                                             *
    710  * OUTPUT:                                                                                     *
    711  *      none.                                                                                  *
    712  *                                                                                             *
    713  * WARNINGS:                                                                                   *
    714  *      none.                                                                                  *
    715  *                                                                                             *
    716  * HISTORY:                                                                                    *
    717  *   01/02/1995 BR : Created.                                                                  *
    718  *=============================================================================================*/
    719 void PowerClass::Code_Pointers(void)
    720 {
    721 	RadarClass::Code_Pointers();
    722 }
    723 
    724 
    725 /***********************************************************************************************
    726  * PowerClass::Decode_Pointers -- decodes pointers for load/save                               *
    727  *                                                                                             *
    728  * This routine "decodes" the pointers coded in Code_Pointers by converting the                *
    729  * code values back into object pointers.                                                      *
    730  *                                                                                             *
    731  * INPUT:                                                                                      *
    732  *      none.                                                                                  *
    733  *                                                                                             *
    734  * OUTPUT:                                                                                     *
    735  *      none.                                                                                  *
    736  *                                                                                             *
    737  * WARNINGS:                                                                                   *
    738  *      none.                                                                                  *
    739  *                                                                                             *
    740  * HISTORY:                                                                                    *
    741  *   01/02/1995 BR : Created.                                                                  *
    742  *=============================================================================================*/
    743 void PowerClass::Decode_Pointers(void)
    744 {
    745 	RadarClass::Decode_Pointers();
    746 }
    747 
    748 
    749 /***********************************************************************************************
    750  * SidebarClass::Code_Pointers -- codes class's pointers for load/save                         *
    751  *                                                                                             *
    752  * This routine "codes" the pointers in the class by converting them to a number               *
    753  * that still represents the object pointed to, but isn't actually a pointer.  This            *
    754  * allows a saved game to properly load without relying on the games data still                *
    755  * being in the exact same location.                                                           *
    756  *                                                                                             *
    757  * INPUT:                                                                                      *
    758  *      none.                                                                                  *
    759  *                                                                                             *
    760  * OUTPUT:                                                                                     *
    761  *      none.                                                                                  *
    762  *                                                                                             *
    763  * WARNINGS:                                                                                   *
    764  *      none.                                                                                  *
    765  *                                                                                             *
    766  * HISTORY:                                                                                    *
    767  *   01/02/1995 BR : Created.                                                                  *
    768  *=============================================================================================*/
    769 void SidebarClass::Code_Pointers(void)
    770 {
    771 	for (int i = 0; i < COLUMNS; i++) {
    772 		Column[i].Code_Pointers();
    773 	}
    774 
    775 	PowerClass::Code_Pointers();
    776 }
    777 
    778 
    779 /***********************************************************************************************
    780  * SidebarClass::Decode_Pointers -- decodes pointers for load/save                             *
    781  *                                                                                             *
    782  * This routine "decodes" the pointers coded in Code_Pointers by converting the                *
    783  * code values back into object pointers.                                                      *
    784  *                                                                                             *
    785  * INPUT:                                                                                      *
    786  *      none.                                                                                  *
    787  *                                                                                             *
    788  * OUTPUT:                                                                                     *
    789  *      none.                                                                                  *
    790  *                                                                                             *
    791  * WARNINGS:                                                                                   *
    792  *      none.                                                                                  *
    793  *                                                                                             *
    794  * HISTORY:                                                                                    *
    795  *   01/02/1995 BR : Created.                                                                  *
    796  *=============================================================================================*/
    797 void SidebarClass::Decode_Pointers(void)
    798 {
    799 	for (int i = 0; i < COLUMNS; i++) {
    800 		Column[i].Decode_Pointers();
    801 	}
    802 
    803 	PowerClass::Decode_Pointers();
    804 }
    805 
    806 
    807 /***********************************************************************************************
    808  * SidebarClass::StripClass::Code_Pointers -- codes class's pointers for load/save             *
    809  *                                                                                             *
    810  * This routine "codes" the pointers in the class by converting them to a number               *
    811  * that still represents the object pointed to, but isn't actually a pointer.  This            *
    812  * allows a saved game to properly load without relying on the games data still                *
    813  * being in the exact same location.                                                           *
    814  *                                                                                             *
    815  * INPUT:                                                                                      *
    816  *      none.                                                                                  *
    817  *                                                                                             *
    818  * OUTPUT:                                                                                     *
    819  *      none.                                                                                  *
    820  *                                                                                             *
    821  * WARNINGS:                                                                                   *
    822  *      none.                                                                                  *
    823  *                                                                                             *
    824  * HISTORY:                                                                                    *
    825  *   01/02/1995 BR : Created.                                                                  *
    826  *=============================================================================================*/
    827 void SidebarClass::StripClass::Code_Pointers(void)
    828 {
    829 }
    830 
    831 
    832 /***********************************************************************************************
    833  * SidebarClass::StripClass::Decode_Pointers -- decodes pointers for load/save                 *
    834  *                                                                                             *
    835  * This routine "decodes" the pointers coded in Code_Pointers by converting the                *
    836  * code values back into object pointers.                                                      *
    837  *                                                                                             *
    838  * INPUT:                                                                                      *
    839  *      none.                                                                                  *
    840  *                                                                                             *
    841  * OUTPUT:                                                                                     *
    842  *      none.                                                                                  *
    843  *                                                                                             *
    844  * WARNINGS:                                                                                   *
    845  *      none.                                                                                  *
    846  *                                                                                             *
    847  * HISTORY:                                                                                    *
    848  *   01/02/1995 BR : Created.                                                                  *
    849  *=============================================================================================*/
    850 void SidebarClass::StripClass::Decode_Pointers(void)
    851 {
    852 }
    853 
    854 
    855 /***********************************************************************************************
    856  * RadarClass::Code_Pointers -- codes class's pointers for load/save                           *
    857  *                                                                                             *
    858  * This routine "codes" the pointers in the class by converting them to a number               *
    859  * that still represents the object pointed to, but isn't actually a pointer.  This            *
    860  * allows a saved game to properly load without relying on the games data still                *
    861  * being in the exact same location.                                                           *
    862  *                                                                                             *
    863  * INPUT:                                                                                      *
    864  *      none.                                                                                  *
    865  *                                                                                             *
    866  * OUTPUT:                                                                                     *
    867  *      none.                                                                                  *
    868  *                                                                                             *
    869  * WARNINGS:                                                                                   *
    870  *      none.                                                                                  *
    871  *                                                                                             *
    872  * HISTORY:                                                                                    *
    873  *   01/02/1995 BR : Created.                                                                  *
    874  *=============================================================================================*/
    875 void RadarClass::Code_Pointers(void)
    876 {
    877 	DisplayClass::Code_Pointers();
    878 }
    879 
    880 
    881 /***********************************************************************************************
    882  * RadarClass::Decode_Pointers -- decodes pointers for load/save                               *
    883  *                                                                                             *
    884  * This routine "decodes" the pointers coded in Code_Pointers by converting the                *
    885  * code values back into object pointers.                                                      *
    886  *                                                                                             *
    887  * INPUT:                                                                                      *
    888  *      none.                                                                                  *
    889  *                                                                                             *
    890  * OUTPUT:                                                                                     *
    891  *      none.                                                                                  *
    892  *                                                                                             *
    893  * WARNINGS:                                                                                   *
    894  *      none.                                                                                  *
    895  *                                                                                             *
    896  * HISTORY:                                                                                    *
    897  *   01/02/1995 BR : Created.                                                                  *
    898  *=============================================================================================*/
    899 void RadarClass::Decode_Pointers(void)
    900 {
    901 	DisplayClass::Decode_Pointers();
    902 }
    903 
    904 
    905 /***********************************************************************************************
    906  * DisplayClass::Code_Pointers -- codes class's pointers for load/save                         *
    907  *                                                                                             *
    908  * This routine "codes" the pointers in the class by converting them to a number               *
    909  * that still represents the object pointed to, but isn't actually a pointer.  This            *
    910  * allows a saved game to properly load without relying on the games data still                *
    911  * being in the exact same location.                                                           *
    912  *                                                                                             *
    913  * INPUT:                                                                                      *
    914  *      none.                                                                                  *
    915  *                                                                                             *
    916  * OUTPUT:                                                                                     *
    917  *      none.                                                                                  *
    918  *                                                                                             *
    919  * WARNINGS:                                                                                   *
    920  *      none.                                                                                  *
    921  *                                                                                             *
    922  * HISTORY:                                                                                    *
    923  *   01/02/1995 BR : Created.                                                                  *
    924  *=============================================================================================*/
    925 void DisplayClass::Code_Pointers(void)
    926 {
    927 	/*
    928 	**	Code PendingObjectPtr.
    929 	*/
    930 	if (PendingObjectPtr) {
    931 		PendingObjectPtr = (ObjectClass *)PendingObjectPtr->As_Target();
    932 	}
    933 
    934 	/*
    935 	** Fix for saving game while in structure placement mode. ST - 4/15/2020 2:41PM
    936 	*/
    937 	memset(CursorShapeSave, 0, sizeof(CursorShapeSave));
    938 	if (CursorSize && CursorSize != CursorShapeSave) {
    939 
    940 		int save_buffer_element_size = sizeof(CursorShapeSave) / sizeof(CursorShapeSave[0]);
    941 		
    942 		int index = 0;
    943 
    944 		while (index < save_buffer_element_size - 2 && CursorSize[index] != REFRESH_EOL) {
    945 			CursorShapeSave[index] = CursorSize[index];
    946 			index++;
    947 		}
    948 		CursorShapeSave[index] = REFRESH_EOL;
    949 	}
    950 
    951 	/*
    952 	**	Chain to parent.
    953 	*/
    954 	MapClass::Code_Pointers();
    955 }
    956 
    957 
    958 /***********************************************************************************************
    959  * DisplayClass::Decode_Pointers -- decodes pointers for load/save                             *
    960  *                                                                                             *
    961  * This routine "decodes" the pointers coded in Code_Pointers by converting the                *
    962  * code values back into object pointers.                                                      *
    963  *                                                                                             *
    964  * INPUT:                                                                                      *
    965  *      none.                                                                                  *
    966  *                                                                                             *
    967  * OUTPUT:                                                                                     *
    968  *      none.                                                                                  *
    969  *                                                                                             *
    970  * WARNINGS:                                                                                   *
    971  *      none.                                                                                  *
    972  *                                                                                             *
    973  * HISTORY:                                                                                    *
    974  *   01/02/1995 BR : Created.                                                                  *
    975  *=============================================================================================*/
    976 void DisplayClass::Decode_Pointers(void)
    977 {
    978 	/*
    979 	**	Decode PendingObjectPtr.  We can't decode PendingObject here, because we'd
    980 	**	have to reference PendingObjectPtr->Class_Of(), and the object that
    981 	**	PendingObjectPtr is pointing to hasn't been decoded yet.  Since we can't
    982 	**	decode PendingObjectPtr, we can't set the placement cursor shape here
    983 	**	either.  These have to be done as last-minute fixups.
    984 	*/
    985 	if (PendingObjectPtr) {
    986 		PendingObjectPtr = As_Object((TARGET)PendingObjectPtr, false);
    987 		Check_Ptr((void *)PendingObjectPtr,__FILE__,__LINE__);
    988 	}
    989 
    990 	if (CursorSize) {
    991 		CursorSize = CursorShapeSave;
    992 	}
    993 
    994 	/*
    995 	**	Chain to parent.
    996 	*/
    997 	MapClass::Decode_Pointers();
    998 }
    999 
   1000 
   1001 /***********************************************************************************************
   1002  * MapClass::Code_Pointers -- codes class's pointers for load/save                             *
   1003  *                                                                                             *
   1004  * This routine "codes" the pointers in the class by converting them to a number               *
   1005  * that still represents the object pointed to, but isn't actually a pointer.  This            *
   1006  * allows a saved game to properly load without relying on the games data still                *
   1007  * being in the exact same location.                                                           *
   1008  *                                                                                             *
   1009  * INPUT:                                                                                      *
   1010  *      none.                                                                                  *
   1011  *                                                                                             *
   1012  * OUTPUT:                                                                                     *
   1013  *      none.                                                                                  *
   1014  *                                                                                             *
   1015  * WARNINGS:                                                                                   *
   1016  *      none.                                                                                  *
   1017  *                                                                                             *
   1018  * HISTORY:                                                                                    *
   1019  *   01/02/1995 BR : Created.                                                                  *
   1020  *=============================================================================================*/
   1021 void MapClass::Code_Pointers(void)
   1022 {
   1023 	CELL cell;
   1024 
   1025 	/*
   1026 	------------------------- Destroy all flag animations --------------------
   1027 	*/
   1028 	for (cell = 0; cell < MAP_CELL_TOTAL; cell++) {
   1029 		(*this)[cell].Flag_Destroy();
   1030 	}
   1031 
   1032 	/*
   1033 	------------------------- Code the cell pointers -------------------------
   1034 	*/
   1035 	for (cell = 0; cell < MAP_CELL_TOTAL; cell++) {
   1036 		(*this)[cell].Code_Pointers();
   1037 	}
   1038 
   1039 	GScreenClass::Code_Pointers();
   1040 }
   1041 
   1042 
   1043 /***********************************************************************************************
   1044  * MapClass::Decode_Pointers -- decodes pointers for load/save                                 *
   1045  *                                                                                             *
   1046  * This routine "decodes" the pointers coded in Code_Pointers by converting the                *
   1047  * code values back into object pointers.                                                      *
   1048  *                                                                                             *
   1049  * INPUT:                                                                                      *
   1050  *      none.                                                                                  *
   1051  *                                                                                             *
   1052  * OUTPUT:                                                                                     *
   1053  *      none.                                                                                  *
   1054  *                                                                                             *
   1055  * WARNINGS:                                                                                   *
   1056  *      none.                                                                                  *
   1057  *                                                                                             *
   1058  * HISTORY:                                                                                    *
   1059  *   01/02/1995 BR : Created.                                                                  *
   1060  *=============================================================================================*/
   1061 void MapClass::Decode_Pointers(void)
   1062 {
   1063 	CELL cell;
   1064 
   1065 	/*
   1066 	------------------------ Decode the cell pointers ------------------------
   1067 	*/
   1068 	for (cell = 0; cell < MAP_CELL_TOTAL; cell++) {
   1069 		(*this)[cell].Decode_Pointers();
   1070 	}
   1071 
   1072 	GScreenClass::Decode_Pointers();
   1073 }
   1074 
   1075 
   1076 /***********************************************************************************************
   1077  * GScreenClass::Code_Pointers -- codes class's pointers for load/save                         *
   1078  *                                                                                             *
   1079  * This routine "codes" the pointers in the class by converting them to a number               *
   1080  * that still represents the object pointed to, but isn't actually a pointer.  This            *
   1081  * allows a saved game to properly load without relying on the games data still                *
   1082  * being in the exact same location.                                                           *
   1083  *                                                                                             *
   1084  * INPUT:                                                                                      *
   1085  *      none.                                                                                  *
   1086  *                                                                                             *
   1087  * OUTPUT:                                                                                     *
   1088  *      none.                                                                                  *
   1089  *                                                                                             *
   1090  * WARNINGS:                                                                                   *
   1091  *      none.                                                                                  *
   1092  *                                                                                             *
   1093  * HISTORY:                                                                                    *
   1094  *   01/02/1995 BR : Created.                                                                  *
   1095  *=============================================================================================*/
   1096 void GScreenClass::Code_Pointers(void)
   1097 {
   1098 }
   1099 
   1100 
   1101 /***********************************************************************************************
   1102  * GScreenClass::Decode_Pointers -- decodes pointers for load/save                             *
   1103  *                                                                                             *
   1104  * This routine "decodes" the pointers coded in Code_Pointers by converting the                *
   1105  * code values back into object pointers.                                                      *
   1106  *                                                                                             *
   1107  * INPUT:                                                                                      *
   1108  *      none.                                                                                  *
   1109  *                                                                                             *
   1110  * OUTPUT:                                                                                     *
   1111  *      none.                                                                                  *
   1112  *                                                                                             *
   1113  * WARNINGS:                                                                                   *
   1114  *      none.                                                                                  *
   1115  *                                                                                             *
   1116  * HISTORY:                                                                                    *
   1117  *   01/02/1995 BR : Created.                                                                  *
   1118  *=============================================================================================*/
   1119 void GScreenClass::Decode_Pointers(void)
   1120 {
   1121 }