1 /* inits the system and controls environment and player loading */
2 
3 #include "3dc.h"
4 #include "module.h"
5 #include "stratdef.h"
6 #include "gamedef.h"
7 #include "bh_types.h"
8 #include "bh_marin.h"
9 #include "game.h"
10 #include "gameplat.h"
11 #include "lighting.h"
12 #include "messagehistory.h"
13 #include "particle.h"
14 #include "pldnet.h"
15 #define UseLocalAssert Yes
16 #include "ourasert.h"
17 
18 /* patrick 5/12/96 */
19 #include "bh_far.h"
20 #include "pheromon.h"
21 #include "huddefs.h"
22 #include "hud.h"
23 //#include "hudgfx.h"
24 #include "fmv.h"
25 #include "font.h"
26 #include "bh_gener.h"
27 #include "pvisible.h"
28 #include "system.h"
29 
30 #include "projload.hpp" // c++ header which ignores class definitions/member functions if __cplusplus is not defined ?
31 #include "chnkload.hpp" // c++ header which ignores class definitions/member functions if __cplusplus is not defined ?
32 
33 #include "ffstdio.h" // fast file stdio
34 #include "avp_menus.h"
35 #include "cdplayer.h"
36 
37 /*------------Patrick 1/6/97---------------
38 New sound system
39 -------------------------------------------*/
40 #include "psndplat.h"
41 #include "progress_bar.h"
42 #include "bh_rubberduck.h"
43 #include "game_statistics.h"
44 #include "cdtrackselection.h"
45 
46 
47 // EXTERNS
48 
49 
50 
51 extern int WindowMode;
52 extern int VideoMode;
53 
54 extern SCREENDESCRIPTORBLOCK ScreenDescriptorBlock;
55 
56 extern SHAPEHEADER** mainshapelist;
57 
58 extern int NumActiveBlocks;
59 extern int NumOnScreenBlocks;
60 extern DISPLAYBLOCK *ActiveBlockList[];
61 
62 extern MODULEMAPBLOCK AvpCompiledMaps[];
63 extern MAPHEADER TestMap[];
64 extern MAPHEADER Map[];
65 extern MAPHEADER * staticmaplist[];
66 extern MAPBLOCK8 Player_and_Camera_Type8[];
67 
68 extern SCENEMODULE **Global_ModulePtr;
69 extern SCENEMODULE *MainSceneArray[];
70 
71 extern void (*SetVideoMode[]) (void);
72 extern int HWAccel;
73 extern int Resolution;
74 extern void SetupVision(void);
75 extern void ReInitHUD(void);
76 extern void CheckCDStatus(void);
77 
78 extern void DeallocateSoundsAndPoolAllocatedMemory();
79 
80 
81 /*Globals */
82 
83 int WindowRequestMode;
84 int VideoRequestMode;
85 int ZBufferRequestMode;
86 int RasterisationRequestMode;
87 int SoftwareScanDrawRequestMode;
88 int DXMemoryRequestMode;
89 WINSCALEXY TopLeftSubWindow;
90 WINSCALEXY ExtentXYSubWindow;
91 
92 
93 // static
94 
95 static int ReadModuleMapList(MODULEMAPBLOCK *mmbptr);
96 RIFFHANDLE env_rif = INVALID_RIFFHANDLE;
97 RIFFHANDLE player_rif = INVALID_RIFFHANDLE;
98 RIFFHANDLE alien_weapon_rif = INVALID_RIFFHANDLE;
99 RIFFHANDLE marine_weapon_rif = INVALID_RIFFHANDLE;
100 RIFFHANDLE predator_weapon_rif = INVALID_RIFFHANDLE;
101 
102 void ProcessSystemObjects();
103 
104 /*
105 
106  Video Mode at start-up
107 
108  The source to set up the initial video mode obviously
109  depends on the platform, and so this routine is best placed
110  in this file
111 
112 */
113 
114 /* THIS IS FOR THE MENU SCREEN */
115 
InitialVideoMode(void)116 void InitialVideoMode(void)
117 
118 {
119 /*
120 	Note that video modes are now only
121 	REQUESTED, not set.
122 	Sound will also be dealt with in the
123 	same way.
124 */
125 
126 
127 	ScreenDescriptorBlock.SDB_Flags = SDB_Flag_Raw256 | SDB_Flag_MIP;
128 
129     /*
130 		Setup for Windows mode.  Note that
131 		TopLeftSubWindow and ExtentXYSubWindow
132 		should be set to sensible defaults even
133 		if we are in FullScreen mode.
134 		Also: TopLeftSubWindow and ExtentXYSubWindow
135 		are proportions of the current Windows display
136 		extents, set in floating point in a range of
137 		0.0-1.0 THIS CODE IS INTENDED FOR PENTIUM TARGETS
138 		ONLY, AND THEREFORE USES FLOATING PT.  IT MUST
139 		NOT
140 		 LEAK.
141 	*/
142 
143     /*
144 	  Note this is now only a request mode.
145 	*/
146 
147     #if 1
148     WindowRequestMode = WindowModeFullScreen;
149 	#else
150     WindowRequestMode = WindowModeSubWindow;
151 	#endif
152 
153     TopLeftSubWindow.x = 0.3;
154 	TopLeftSubWindow.y = 0.3;
155 	ExtentXYSubWindow.x = 0.6;
156 	ExtentXYSubWindow.y = 0.6;
157 
158 /*
159 	Experimental settings for other
160 	request modes affecting rendering.
161 */
162 
163 	/*VideoRequestMode = VideoMode_DX_640x480x8;  for menus - is this guaranteed? */
164 	VideoRequestMode = AvP.MenuVideoRequestMode;
165 
166 	/* JH 20/5/97
167 		begin in minmal h/w configuration - for menus
168 		- don't need any h/w 3d, but do need to know
169 		about h/w direct draw and what video modes
170 		will be available */
171 
172 	ZBufferRequestMode = RequestZBufferNever;
173 
174     RasterisationRequestMode = RequestDefaultRasterisation;
175 
176     SoftwareScanDrawRequestMode = RequestScanDrawDirectDraw;
177 
178     DXMemoryRequestMode = RequestSystemMemoryAlways;
179 
180     /*
181 		IMPORTANT!!!! In the Windows 95 version,
182 		SetVideoMode MUST NOT be called from this
183 		routine, since InitialVideoMode is called
184 		first in WinMain to prepare for windows
185 		initialisation and the actual DirectX
186 		initialisation (done through SetVideoMode)
187 		must be done after windows initialisation
188 	*/
189 
190 }
191 
192 
193 
194 
195 /****************** AVP Change Display Modes*/
196 
197 /*
198 	This function is intended to allow YOU,
199 	the user, to obtain your heart's fondest desires
200 	by one simple call.  Money? Love? A better job?
201 	It's all here, you have only to ask...
202 	No, I was lying actually.
203 	In fact, this should allow you to change
204 	display modes cleanly.  Pass your request modes
205 	(as normally set up in system.c).  For all entries
206 	which you do not want to change, simply pass
207 	the current global value (e.g. ZBufferRequestMode
208 	in the NewZBufferMode entry).
209 
210     Note that the function must always be passed the
211 	HINSTANCE and nCmdShow from winmain.
212 */
213 
214 /*
215 	Note that this function will NOT
216 	reinitialise the DirectDraw object
217 	or switch to or from a hardware DD
218 	device, but it will release and rebuild
219 	all the Direct3D objects.
220 */
221 
222 /*
223 	Note that you MUST be in the right
224 	directory for a texture reload before you
225 	call this, and normal operations CAN change
226 	the directory...
227 */
228 
229 /*
230 	NOTE!!! If you start in DirectDraw mode
231 	and go to Direct3D mode, this function
232 	CANNOT POSSIBLY WORK WITHOUT A FULL SHAPE
233 	RELOAD, since the shape data is overwritten
234 	during DirectDraw initialisation!!!!
235 
236     NOTE ALSO: TEXTURE RELOAD MAY BE DODGY
237 	WITHOUT A SHAPE RELOAD!!!
238 */
239 
240 
AVP_ChangeDisplayMode(HINSTANCE hInst,int nCmd,int NewVideoMode,int NewWindowMode,int NewZBufferMode,int NewRasterisationMode,int NewSoftwareScanDrawMode,int NewDXMemoryMode)241 int AVP_ChangeDisplayMode
242 		(
243 			HINSTANCE hInst,
244 			int nCmd,
245 			int NewVideoMode,
246 			int NewWindowMode,
247 			int NewZBufferMode,
248 			int NewRasterisationMode,
249 			int NewSoftwareScanDrawMode,
250 			int NewDXMemoryMode
251 		)
252 {
253 	BOOL ChangeWindow = No;
254 
255 	/*
256 		Shut down DirectX objects and destroy
257 		the current window, if necessary.
258 	*/
259 
260     if (NewWindowMode != WindowMode)
261 		{
262 		  ChangeWindow = Yes;
263 		}
264 
265     /* JH 30/5/97 - added this line back in so that d3d is cleaned up properly when the
266 	   display is changed back to 8-but for the menus */
267 	/* JH 3/6/97 - don't quit kill off the images - still keep buffers in system memory
268 	   that are not linked to direct draw */
269     MinimizeAllImages();
270     ReleaseDirect3DNotDDOrImages();
271 
272     finiObjectsExceptDD();
273 
274     if (ChangeWindow)
275       ExitWindowsSystem();
276 
277 
278 	/*
279 		Set the request modes and actual modes
280 		according to the passed values.
281 	*/
282 
283     VideoRequestMode = NewVideoMode;
284     WindowRequestMode = NewWindowMode;
285 	ZBufferRequestMode = NewZBufferMode;
286 	RasterisationRequestMode = NewRasterisationMode;
287 	SoftwareScanDrawRequestMode = NewSoftwareScanDrawMode;
288 	DXMemoryRequestMode = NewDXMemoryMode;
289 
290     VideoMode = VideoRequestMode;
291 	WindowMode = WindowRequestMode;
292 
293 	/* this may reconstruct the dd object depending
294 	   on the rasterisation request mode and whether
295 	   a hardware dd driver is selected or could be
296 	   available - JH 20/5/97 */
297 	ChangeDirectDrawObject();
298 
299 	/*
300 		Recreate the window, allowing
301 		for possible change in WindowMode.
302 	*/
303 
304     if (ChangeWindow)
305 	  {
306 	   	BOOL rc = InitialiseWindowsSystem
307 		(
308 			hInst,
309 			nCmd,
310 			WinInitChange
311 		);
312 
313        	if (rc == FALSE)
314 	     	return rc;
315 	  }
316 
317 	/*
318 		Set the video mode again.  This
319 		will handle all changes to DirectDraw
320 		objects, all Direct3D initialisation,
321 		and other request modes such as
322 		zbuffering.
323 	*/
324 /*
325 	SetVideoMode[VideoMode]();
326 */
327 
328 
329     return TRUE;
330 }
331 
332 
333 //void ReleaseDirect3DNotDDOrImages(void)
334 //{
335 //    RELEASE(d3d.lpD3DViewport);
336 //    RELEASE(d3d.lpD3DDevice);
337 //    RELEASE(d3d.lpD3D);
338 //}
339 
340 
341 //empty functions for hooks
342 // hooks for doing stuff after drawing and
343 // after a flip
344 
ProjectSpecificItemListPostProcessing(void)345 void ProjectSpecificItemListPostProcessing(void){;}
ProjectSpecificBufferFlipPostProcessing(void)346 void ProjectSpecificBufferFlipPostProcessing(void){;}
347 
348 
349 
350 /*******************************************************************************************/
351 /*******************************************************************************************/
352 
353 /***************						GAME AND ENIVROMENT CONTROL 					**************************/
354 
355 
356 
InitCharacter()357 void InitCharacter()
358 {
359 	/*** RWH cleans up the character initialisation
360 			 it would be nice if this can be called when
361 			 we load up a game of a different character
362 	***/
363 
364 	// load charcater specific rif and sounds
365 
366 
367 	if(player_rif != INVALID_RIFFHANDLE)
368 	{
369 			// we already have a player loaded - delete the bastard
370 			avp_undo_rif_load(player_rif);
371 	}
372 	if(alien_weapon_rif != INVALID_RIFFHANDLE)
373 	{
374 			// we already have a player loaded - delete the bastard
375 		avp_undo_rif_load(alien_weapon_rif);
376 	}
377 	if(marine_weapon_rif != INVALID_RIFFHANDLE)
378 	{
379 			// we already have a player loaded - delete the bastard
380 		avp_undo_rif_load(marine_weapon_rif);
381 	}
382 	if(predator_weapon_rif != INVALID_RIFFHANDLE)
383 	{
384 			// we already have a player loaded - delete the bastard
385 		avp_undo_rif_load(predator_weapon_rif);
386 	}
387 
388 	#if MaxImageGroups==1
389 	InitialiseTextures();
390 	#else
391 	SetCurrentImageGroup(0);
392 	DeallocateCurrentImages();
393 	#endif
394 
395 	Start_Progress_Bar();
396 
397 
398 	Set_Progress_Bar_Position(PBAR_HUD_START);
399 
400 	switch(AvP.Network)
401 	{
402 		case I_No_Network:
403 		{
404 
405 
406 			// set up the standard single player game
407 			switch(AvP.PlayerType)
408 				{
409 					case I_Marine:
410 						{
411 							marine_weapon_rif = avp_load_rif("avp_huds/marwep.rif");
412 							Set_Progress_Bar_Position(PBAR_HUD_START+PBAR_HUD_INTERVAL*.25);
413 							player_rif = avp_load_rif("avp_huds/marine.rif");
414 							break;
415 						}
416 					case I_Predator:
417 						{
418 							predator_weapon_rif = avp_load_rif("avp_huds/pred_hud.rif");
419 							Set_Progress_Bar_Position(PBAR_HUD_START+PBAR_HUD_INTERVAL*.25);
420 							player_rif = avp_load_rif("avp_huds/predator.rif");
421 							break;
422 						}
423 
424 					case I_Alien:
425 						{
426 							#if ALIEN_DEMO
427 							alien_weapon_rif = avp_load_rif("alienavp_huds/alien_hud.rif");
428 							Set_Progress_Bar_Position(PBAR_HUD_START+PBAR_HUD_INTERVAL*.25);
429 							player_rif = avp_load_rif("alienavp_huds/alien.rif");
430 							#else
431 							alien_weapon_rif = avp_load_rif("avp_huds/alien_hud.rif");
432 							Set_Progress_Bar_Position(PBAR_HUD_START+PBAR_HUD_INTERVAL*.25);
433 							player_rif = avp_load_rif("avp_huds/alien.rif");
434 							#endif
435 							break;
436 						}
437 					default:
438 						{
439 							GLOBALASSERT(2<1);
440 						}
441 				}
442 				break;
443 			}
444 			default:
445 			{
446 
447 
448 
449 				// set up a multiplayer game - here becuse we might end
450 				// up with a cooperative game
451 				//load all weapon rifs
452 				marine_weapon_rif = avp_load_rif("avp_huds/marwep.rif");
453 				predator_weapon_rif = avp_load_rif("avp_huds/pred_hud.rif");
454 				alien_weapon_rif = avp_load_rif("avp_huds/alien_hud.rif");
455 
456 				Set_Progress_Bar_Position(PBAR_HUD_START+PBAR_HUD_INTERVAL*.25);
457 				player_rif = avp_load_rif("avp_huds/multip.rif");
458 			}
459 	}
460 	Set_Progress_Bar_Position(PBAR_HUD_START+PBAR_HUD_INTERVAL*.5);
461 
462 	#if MaxImageGroups>1
463 	SetCurrentImageGroup(0);
464 	#endif
465 	copy_rif_data(player_rif,CCF_IMAGEGROUPSET,PBAR_HUD_START+PBAR_HUD_INTERVAL*.5,PBAR_HUD_INTERVAL*.25);
466 
467 	Set_Progress_Bar_Position(PBAR_HUD_START+PBAR_HUD_INTERVAL*.75);
468 
469 
470 	if(alien_weapon_rif!=INVALID_RIFFHANDLE)
471 		copy_rif_data(alien_weapon_rif,CCF_LOAD_AS_HIERARCHY_IF_EXISTS|CCF_IMAGEGROUPSET|CCF_DONT_INITIALISE_TEXTURES,PBAR_HUD_START+PBAR_HUD_INTERVAL*.5,PBAR_HUD_INTERVAL*.25);
472 
473 	if(marine_weapon_rif!=INVALID_RIFFHANDLE)
474 		copy_rif_data(marine_weapon_rif,CCF_LOAD_AS_HIERARCHY_IF_EXISTS|CCF_IMAGEGROUPSET|CCF_DONT_INITIALISE_TEXTURES,PBAR_HUD_START+PBAR_HUD_INTERVAL*.5,PBAR_HUD_INTERVAL*.25);
475 
476 	if(predator_weapon_rif!=INVALID_RIFFHANDLE)
477 		copy_rif_data(predator_weapon_rif,CCF_LOAD_AS_HIERARCHY_IF_EXISTS|CCF_IMAGEGROUPSET|CCF_DONT_INITIALISE_TEXTURES,PBAR_HUD_START+PBAR_HUD_INTERVAL*.5,PBAR_HUD_INTERVAL*.25);
478 
479 	Set_Progress_Bar_Position(PBAR_HUD_START+PBAR_HUD_INTERVAL);
480 	//copy_chunks_from_environment(0);
481 
482 	/*KJL*************************************
483 	*   Setup generic data for weapons etc   *
484 	*************************************KJL*/
485 
486  	InitialiseEquipment();
487 	InitHUD();
488 
489 }
490 
491 extern void create_strategies_from_list ();
492 extern void AssignAllSBNames();
493 
RestartLevel()494 void RestartLevel()
495 {
496 	//get the cd to start again at the beginning of the play list.
497 	ResetCDPlayForLevel();
498 
499 	CleanUpPheromoneSystem();
500 	// now deallocate the module vis array
501 	DeallocateModuleVisArrays();
502 
503 	/* destroy the VDB list */
504 	InitialiseVDBs();
505 	InitialiseTxAnimBlocks();
506 
507 
508 	// deallocate strategy and display blocks
509 	{
510 		int i ;
511 
512 		i = maxstblocks;
513 		DestroyAllStrategyBlocks();
514 		while(i--)
515 			ActiveStBlockList[i] = NULL;
516 
517 		i = maxobjects;
518 	 	InitialiseObjectBlocks();
519 		while(i --)
520 			ActiveBlockList[i] = NULL;
521 	}
522 
523 	//stop all sound
524 	SoundSys_StopAll();
525 
526 	//reset the displayblock for modules to 0
527 	{
528 		int i=2;
529 		while(MainScene.sm_module[i].m_type!=mtype_term)
530 		{
531 			MainScene.sm_module[i].m_dptr=0;
532 			i++;
533 		}
534 
535 	}
536 
537 	// set the Onscreenbloock lsit to zero
538  	NumOnScreenBlocks = 0;
539 
540  	//start reinitialising stuff
541 
542 // 	InitialiseEquipment();
543 //	InitHUD();
544 
545 	ProcessSystemObjects();
546 
547 	create_strategies_from_list ();
548 	AssignAllSBNames();
549 
550 	SetupVision();
551 	InitObjectVisibilities();
552 	InitPheromoneSystem();
553 	InitHive();
554 	InitSquad();
555 
556 	/* KJL 14:22:41 17/11/98 - reset HUD data, such as where the crosshair is,
557 	whether the Alien jaw is on-screen, and so on */
558 	ReInitHUD();
559 
560 	InitialiseParticleSystem();
561 	InitialiseSfxBlocks();
562 	InitialiseLightElementSystem();
563 	CreateRubberDucks();
564 	InitialiseTriggeredFMVs();
565 
566 	CheckCDStatus();
567 
568 	/*Make sure we don't get a slow frame when we restart , since this can cause problems*/
569 	ResetFrameCounter();
570 
571 	CurrentGameStats_Initialise();
572 	MessageHistory_Initialise();
573 
574 	if(AvP.Network!=I_No_Network)
575 	{
576 		TeleportNetPlayerToAStartingPosition(Player->ObStrategyBlock,1);
577 	}
578 	else
579 	{
580 		//make sure the visibilities are up to date
581 		extern VIEWDESCRIPTORBLOCK* Global_VDB_Ptr;
582 		Global_VDB_Ptr->VDB_World = Player->ObWorld;
583 		AllNewModuleHandler();
584 		DoObjectVisibilities();
585 	}
586 }
587 
588 static ELO JunkEnv; /* This is not needed */
589 ELO* Env_List[I_Num_Environments] = { &JunkEnv };
590 
591 /**** Construct filename and go for it ***************/
592 
593 void catpathandextension(char*, char*);
594 void DestroyActiveBlockList(void);
595 void InitialiseObjectBlocks(void);
596 
597 
598 char EnvFileName[100];
599 char LevelDir[100];
600 
ProcessSystemObjects()601 void ProcessSystemObjects()
602 {
603 	int i;
604 
605 	MODULEMAPBLOCK* mmbptr= &AvpCompiledMaps[0];
606 	STRATEGYBLOCK* sbptr;
607 
608 	/* PC Loading.
609 		 1 LoadRif File
610 		 			a sets up precompiled shapes
611 					b	sets up other loaded shapes
612 					c sets maps ans SBs for loaded maps
613 
614 		 2
615 	*/
616 
617 
618 	#if TestRiffLoaders
619 	ReadMap(Map);							 /* for chunck loader*/
620 	ReadModuleMapList(mmbptr);
621 	#else
622 	#if SupportModules
623 	ReadModuleMapList(mmbptr);
624 	#endif /*SupportModules*/
625 	ReadMap(Map);
626 	#endif
627 
628 	/*HACK HACK*/
629 
630 	sbptr = AttachNewStratBlock((MODULE*)NULL,
631 															(MODULEMAPBLOCK*)&Player_and_Camera_Type8[0],
632 															Player);
633 	AssignRunTimeBehaviours(sbptr);
634 
635 	#if SupportModules
636 
637 	Global_ModulePtr = MainSceneArray;
638 	PreprocessAllModules();
639 	i = GetModuleVisArrays();
640 	if(i == No) textprint("GetModuleVisArrays() failed\n");
641 
642 
643 	/*WaitForReturn();*/
644 
645 	#endif
646 }
647 
ReadModuleMapList(MODULEMAPBLOCK * mmbptr)648 static int ReadModuleMapList(MODULEMAPBLOCK *mmbptr)
649 {
650 	MODULE m_temp;
651 
652 	DISPLAYBLOCK *dptr;
653 	STRATEGYBLOCK *sbptr;
654 	/* this automatically attaches sbs to dbs */
655 
656 	while(mmbptr->MapType != MapType_Term)
657 		{
658 			m_temp.m_mapptr = mmbptr;
659 			m_temp.m_sbptr = (STRATEGYBLOCK*)NULL;
660 			m_temp.m_dptr = NULL;
661 			AllocateModuleObject(&m_temp);
662 			dptr = m_temp.m_dptr;
663 			LOCALASSERT(dptr); /* if this fires, cannot allocate displayblock */
664 			dptr->ObMyModule = NULL;
665 			sbptr = AttachNewStratBlock((MODULE*)NULL, mmbptr, dptr);
666 			/* enable compile in behaviours here */
667 			AssignRunTimeBehaviours(sbptr);
668 
669 			mmbptr++;
670 		}
671 
672 	return(0);
673 }
674 
675 
UnloadRifFile()676 void UnloadRifFile()
677 {
678 	unload_rif(env_rif);
679 }
680 
681 
ChangeEnvironmentToEnv(I_AVP_ENVIRONMENTS env_to_load)682 void ChangeEnvironmentToEnv(I_AVP_ENVIRONMENTS env_to_load)
683 {
684 
685 	GLOBALASSERT(env_to_load != AvP.CurrentEnv);
686 
687 	GLOBALASSERT(Env_List[env_to_load]);
688 
689 	Destroy_CurrentEnvironment();
690 	/* Patrick: 26/6/97
691 	Stop and remove all sounds here */
692 	SoundSys_StopAll();
693 	SoundSys_RemoveAll();
694 	CDDA_Stop();
695 
696 	// Loading functions
697 	AvP.CurrentEnv = env_to_load;
698 	LoadRifFile();
699 
700 }
701 
702 
IntegrateNewEnvironment()703 void IntegrateNewEnvironment()
704 {
705 	int i;
706 	MODULEMAPBLOCK* mmbptr= &AvpCompiledMaps[0];
707 
708 	// elements we need form processsystemobjects
709 
710 	ReadMap(Map);							 /* for chunck loader*/
711 	ReadModuleMapList(mmbptr);
712 
713 	Global_ModulePtr = MainSceneArray;
714 	PreprocessAllModules();
715 	i = GetModuleVisArrays();
716 	if(i == No) textprint("GetModuleVisArrays() failed\n");
717 
718 
719 	// elements from start game for AI
720 
721 	InitObjectVisibilities();
722 	InitPheromoneSystem();
723 	BuildFarModuleLocs();
724 	InitHive();
725 
726 	AssignAllSBNames();
727 
728 	/* KJL 20:54:55 05/15/97 - setup player vision (alien wideangle, etc) */
729 	SetupVision();
730 
731 	UnloadRifFile();//deletes environment File_Chunk since it is no longer needed
732 
733 	/* Patrick: 26/6/97
734 	Load our sounds for the new env */
735 	LoadSounds("PLAYER");
736 
737 	/* remove resident loaded 'fast' files */
738 	ffcloseall();
739 
740 	ResetFrameCounter();
741 }
742 
743 
744 const char GameDataDirName[20] = {"avp_rifs"};
745 const char FileNameExtension[5] =  {".rif"};
746 
LoadRifFile()747 void LoadRifFile()
748 {
749 
750 	char file_and_path[100];
751 	int i = 0;
752 
753 	Set_Progress_Bar_Position(PBAR_LEVEL_START);
754 
755 	// clear the dir names
756 
757 	for(i = 0; i < 100; i++)
758 	  {
759 	  	file_and_path[i] = (char)0;
760 			EnvFileName[i] = (char)0;
761 			LevelDir[i] = (char)0;
762 	  }
763 
764 	// Set up the dirname for the Rif load
765 
766 	catpathandextension(&file_and_path[0], (char *)&GameDataDirName[0]);
767 	catpathandextension(&file_and_path[0], Env_List[AvP.CurrentEnv]->main); /* root of the file name,smae as dir*/
768 	catpathandextension(&file_and_path[0], (char *)&FileNameExtension[0]);	/* extension*/
769 
770 	env_rif = avp_load_rif((const char*)&file_and_path[0]);
771 	Set_Progress_Bar_Position(PBAR_LEVEL_START+PBAR_LEVEL_INTERVAL*.4);
772 
773 	if(INVALID_RIFFHANDLE == env_rif)
774 	  {
775 			finiObjects();
776 			exit(0x3421);
777 
778 	  };
779 
780 	#if MaxImageGroups>1
781 	SetCurrentImageGroup(2); // FOR ENV
782 	#endif
783 	copy_rif_data(env_rif,CCF_ENVIRONMENT,PBAR_LEVEL_START+PBAR_LEVEL_INTERVAL*.4,PBAR_LEVEL_INTERVAL*.6);
784 	//setup_shading_tables();
785 }
786 
Destroy_CurrentEnvironment(void)787 int Destroy_CurrentEnvironment(void)
788 {
789 	// RWH destroys all en specific data
790 
791 	// function to change environment when we
792 	// are playing a game	- environmnet reset
793 
794 	// this stores all info we need
795 
796 	TimeStampedMessage("Beginning Destroy_CurrentEnvironment");
797 	//CreateLevelMetablocks(AvP.CurrentEnv);
798 	TimeStampedMessage("After CreateLevelMetablocks");
799 
800 	/*----------------------Patrick 14/3/97-----------------------
801 	  Clean up AI systems at end of level
802 	--------------------------------------------------------------*/
803 
804 	{
805 		int i ;
806 
807 		i = maxstblocks;
808 		DestroyAllStrategyBlocks();
809 		while(i--)
810 			ActiveStBlockList[i] = NULL;
811 
812 		i = maxobjects;
813 	 	InitialiseObjectBlocks();
814 		while(i --)
815 			ActiveBlockList[i] = NULL;
816 	}
817 	TimeStampedMessage("After object blocks");
818 
819 	//Get rid of all sounds
820 	//Deallocate memory for all shapes and hierarchy animations
821 	DeallocateSoundsAndPoolAllocatedMemory();
822 
823 	KillFarModuleLocs();
824 	TimeStampedMessage("After KillFarModuleLocs");
825 	CleanUpPheromoneSystem();
826 	TimeStampedMessage("After CleanUpPheromoneSystem");
827 
828 	#if MaxImageGroups>1
829 	SetCurrentImageGroup(2); // FOR ENV
830 	TimeStampedMessage("After SetCurrentImageGroup");
831 
832 	DeallocateCurrentImages();
833 	TimeStampedMessage("After DeallocateCurrentImages");
834 	#endif
835 	// now deasllocate the module vis array
836 	DeallocateModuleVisArrays();
837 	TimeStampedMessage("After DeallocateModuleVisArrays");
838 
839 
840 
841 	/* destroy the VDB list */
842 	InitialiseVDBs();
843 	TimeStampedMessage("After InitialiseVDBs");
844 
845 
846 	InitialiseTxAnimBlocks(); // RUN THE npcS ON OUR OWN
847 	TimeStampedMessage("After InitialiseTxAnimBlocks");
848 
849 
850 	/* frees the memory from the env load*/
851 	DeallocateModules();
852 	TimeStampedMessage("After DeallocateModules");
853 
854 	avp_undo_rif_load(env_rif);
855 	TimeStampedMessage("After avp_undo_rif_load");
856 
857 
858 	// set the Onscreenbloock lsit to zero
859  	NumOnScreenBlocks = 0;
860 
861  	return(0);
862 }
863 
864 
865 
866 #if 0
867 void InitEnvironmentFromLoad(void)
868 {
869 	// in DB menus - we only destroy the current environment
870 	// after we have selected a leve, to load - WE could
871 	// be going TO ANY ENV or CHARACTER here (ughh)
872 
873 	// this is an entire game destroy (with no save) killing
874 	// both the env and the character followed by a complete
875 	// game restart
876 
877 	// environment clean up - sets up the load info
878 	Destroy_CurrentEnvironment();
879 	// then the REST
880 	DestroyAllStrategyBlocks();
881 	#if MaxImageGroups>1
882 	SetCurrentImageGroup(0); // FOR ENV
883 	DeallocateCurrentImages();
884 	#endif
885 	/* Patrick: 26/6/97
886 	Stop and remove all sounds here */
887 	SoundSys_StopAll();
888 	SoundSys_RemoveAll();
889 	CDDA_Stop();
890 
891 	// start the loading - we load the player
892 	InitCharacter();	// intis the char
893 	LoadRifFile();    // env
894 
895 	// do all the ness processing
896 	// start games calles FormatSaveBuffer and
897 	// Process System Objects
898 
899 	AssignAllSBNames();
900 
901 	// Set the timer, or we have just taken
902 	// 10 secs for the frame
903 
904 	/***** No need to do frame counter stuff in a computer! *****/
905 
906 	/* Patrick: 26/6/97
907 	Load our sounds for the new env */
908 	LoadSounds("PLAYER");
909 }
910 
911 
912 
913 /************************ SAVE AND LOAD **********************/
914 
915 
916 
917 
918 
919 
920 
921 
922 void LoadGameFromFile(void)
923 {
924 	// now we right to a file
925 	char * savename = "slot1.AvP";
926 	FILE* fp = fopen(savename, "rb");
927 	if(fp == NULL)
928 		return;
929 	fread(&AvP, sizeof(AVP_GAME_DESC), 1, fp);
930 	fread(&save_game_buffer, SAVEBUFFERSIZE, 1, fp);
931 	UnpackSaveBuffer();
932 	fclose(fp);
933 }
934 
935 
936 void SaveGameToFile(void)
937 {
938 	char * savename = "slot1.AvP";
939 	FILE* fp = fopen(savename, "wb");
940 	CreateLevelMetablocks(AvP.CurrentEnv);
941 	PackSaveBuffer();
942 	fwrite(&AvP, sizeof(AVP_GAME_DESC), 1, fp);
943 	fwrite(&save_game_buffer, SAVEBUFFERSIZE, 1, fp);
944 	fclose(fp);
945 }
946 
947 #endif
948 
949 // project spec game exit
ExitGame(void)950 void ExitGame(void)
951 {
952 	if(player_rif != INVALID_RIFFHANDLE)
953 	{
954 		avp_undo_rif_load(player_rif);
955 	  	player_rif=INVALID_RIFFHANDLE;
956 
957 	}
958 
959 	if(alien_weapon_rif != INVALID_RIFFHANDLE)
960 	{
961 		avp_undo_rif_load(alien_weapon_rif);
962 		alien_weapon_rif=INVALID_RIFFHANDLE;
963 	}
964 	if(marine_weapon_rif != INVALID_RIFFHANDLE)
965 	{
966 		avp_undo_rif_load(marine_weapon_rif);
967 		marine_weapon_rif=INVALID_RIFFHANDLE;
968 	}
969 	if(predator_weapon_rif != INVALID_RIFFHANDLE)
970 	{
971 		avp_undo_rif_load(predator_weapon_rif);
972 		predator_weapon_rif=INVALID_RIFFHANDLE;
973 	}
974 	#if MaxImageGroups>1
975 	SetCurrentImageGroup(0);
976 	DeallocateCurrentImages();
977 	#endif
978 }
979