#pragma warning( push )
#pragma warning( disable : 4005)
#pragma warning( pop )
#include "common.h"
#include "platform.h"
#include "Game.h"
#include "main.h"
#include "RwHelper.h"
#include "Accident.h"
#include "Antennas.h"
#include "Bridge.h"
#include "Camera.h"
#include "CarCtrl.h"
#include "CarGen.h"
#include "CdStream.h"
#include "Clock.h"
#include "Clouds.h"
#include "Collision.h"
#include "Console.h"
#include "Coronas.h"
#include "Cranes.h"
#include "Credits.h"
#include "CutsceneMgr.h"
#include "DMAudio.h"
#include "Darkel.h"
#include "Debug.h"
#include "EventList.h"
#include "FileLoader.h"
#include "FileMgr.h"
#include "Fire.h"
#include "Fluff.h"
#include "Font.h"
#include "Frontend.h"
#include "GameLogic.h"
#include "Garages.h"
#include "GenericGameStorage.h"
#include "Glass.h"
#include "HandlingMgr.h"
#include "Heli.h"
#include "Hud.h"
#include "IniFile.h"
#include "Lights.h"
#include "MBlur.h"
#include "Messages.h"
#include "Pad.h"
#include "Particle.h"
#include "ParticleObject.h"
#include "PedRoutes.h"
#include "Phones.h"
#include "Pickups.h"
#include "Plane.h"
#include "PlayerSkin.h"
#include "Population.h"
#include "Radar.h"
#include "Record.h"
#include "References.h"
#include "Renderer.h"
#include "Replay.h"
#include "Restart.h"
#include "RoadBlocks.h"
#include "Rubbish.h"
#include "SceneEdit.h"
#include "Script.h"
#include "Shadows.h"
#include "Skidmarks.h"
#include "SetPieces.h"
#include "SpecialFX.h"
#include "Sprite2d.h"
#include "Stats.h"
#include "Streaming.h"
#include "SurfaceTable.h"
#include "TempColModels.h"
#include "Timecycle.h"
#include "TrafficLights.h"
#include "Train.h"
#include "TxdStore.h"
#include "User.h"
#include "VisibilityPlugins.h"
#include "WaterCannon.h"
#include "WaterLevel.h"
#include "Weapon.h"
#include "WeaponEffects.h"
#include "Weather.h"
#include "World.h"
#include "ZoneCull.h"
#include "Zones.h"
#include "Occlusion.h"
#include "debugmenu.h"
eLevelName CGame::currLevel;
int32 CGame::currArea;
bool CGame::bDemoMode = true;
bool CGame::nastyGame = true;
bool CGame::frenchGame;
bool CGame::germanGame;
bool CGame::noProstitutes;
bool CGame::playingIntro;
char CGame::aDatFile[32];
#ifdef MORE_LANGUAGES
bool CGame::russianGame = false;
bool CGame::japaneseGame = false;
#endif
int gameTxdSlot;
bool
CGame::InitialiseOnceBeforeRW(void)
{
CFileMgr::Initialise();
CdStreamInit(MAX_CDCHANNELS);
ValidateVersion();
return true;
}
bool
CGame::InitialiseRenderWare(void)
{
#ifdef USE_TEXTURE_POOL
_TexturePoolsInitialise();
#endif
CTxdStore::Initialise();
CVisibilityPlugins::Initialise();
/* Create camera */
Scene.camera = CameraCreate(RsGlobal.width, RsGlobal.height, TRUE);
ASSERT(Scene.camera != nil);
if (!Scene.camera)
{
return (false);
}
RwCameraSetFarClipPlane(Scene.camera, 2000.0f);
RwCameraSetNearClipPlane(Scene.camera, 0.9f);
CameraSize(Scene.camera, nil, DEFAULT_VIEWWINDOW, DEFAULT_ASPECT_RATIO);
/* Create a world */
RwBBox bbox;
bbox.sup.x = bbox.sup.y = bbox.sup.z = 10000.0f;
bbox.inf.x = bbox.inf.y = bbox.inf.z = -10000.0f;
Scene.world = RpWorldCreate(&bbox);
ASSERT(Scene.world != nil);
if (!Scene.world)
{
CameraDestroy(Scene.camera);
Scene.camera = nil;
return (false);
}
/* Add the camera to the world */
RpWorldAddCamera(Scene.world, Scene.camera);
LightsCreate(Scene.world);
CreateDebugFont();
#ifdef LIBRW
#ifdef PS2_MATFX
rw::MatFX::modulateEnvMap = true;
#else
rw::MatFX::modulateEnvMap = false;
#endif
#endif
CFont::Initialise();
CHud::Initialise();
CPlayerSkin::Initialise();
return (true);
}
void CGame::ShutdownRenderWare(void)
{
CMBlur::MotionBlurClose();
DestroySplashScreen();
CHud::Shutdown();
CFont::Shutdown();
for ( int32 i = 0; i < NUMPLAYERS; i++ )
CWorld::Players[i].DeletePlayerSkin();
CPlayerSkin::Shutdown();
DestroyDebugFont();
/* Destroy world */
LightsDestroy(Scene.world);
RpWorldRemoveCamera(Scene.world, Scene.camera);
RpWorldDestroy(Scene.world);
/* destroy camera */
CameraDestroy(Scene.camera);
Scene.world = nil;
Scene.camera = nil;
CVisibilityPlugins::Shutdown();
#ifdef USE_TEXTURE_POOL
_TexturePoolsShutdown();
#endif
}
bool CGame::InitialiseOnceAfterRW(void)
{
TheText.Load();
DMAudio.Initialise();
CTimer::Initialise();
CTempColModels::Initialise();
mod_HandlingManager.Initialise();
CSurfaceTable::Initialise("DATA\\SURFACE.DAT");
CPedStats::Initialise();
CTimeCycle::Initialise();
if ( DMAudio.GetNum3DProvidersAvailable() == 0 )
FrontEndMenuManager.m_nPrefsAudio3DProviderIndex = -1;
if ( FrontEndMenuManager.m_nPrefsAudio3DProviderIndex == -99 || FrontEndMenuManager.m_nPrefsAudio3DProviderIndex == -2 )
{
FrontEndMenuManager.m_PrefsSpeakers = 0;
int8 provider = DMAudio.AutoDetect3DProviders();
if ( provider != -1 )
FrontEndMenuManager.m_nPrefsAudio3DProviderIndex = provider;
}
DMAudio.SetCurrent3DProvider(FrontEndMenuManager.m_nPrefsAudio3DProviderIndex);
DMAudio.SetSpeakerConfig(FrontEndMenuManager.m_PrefsSpeakers);
DMAudio.SetDynamicAcousticModelingStatus(FrontEndMenuManager.m_PrefsDMA);
DMAudio.SetMusicMasterVolume(FrontEndMenuManager.m_PrefsMusicVolume);
DMAudio.SetEffectsMasterVolume(FrontEndMenuManager.m_PrefsSfxVolume);
DMAudio.SetEffectsFadeVol(127);
DMAudio.SetMusicFadeVol(127);
CWorld::Players[0].SetPlayerSkin(FrontEndMenuManager.m_PrefsSkinFile);
return true;
}
void
CGame::FinalShutdown(void)
{
CTxdStore::Shutdown();
CPedStats::Shutdown();
CdStreamShutdown();
}
bool CGame::Initialise(const char* datFile)
{
ResetLoadingScreenBar();
strcpy(aDatFile, datFile);
CPools::Initialise();
CIniFile::LoadIniFile();
currLevel = LEVEL_BEACH;
LoadingScreen("Loading the Game", "Loading generic textures", GetRandomSplashScreen());
gameTxdSlot = CTxdStore::AddTxdSlot("generic");
CTxdStore::Create(gameTxdSlot);
CTxdStore::AddRef(gameTxdSlot);
LoadingScreen("Loading the Game", "Loading particles", nil);
int particleTxdSlot = CTxdStore::AddTxdSlot("particle");
CTxdStore::LoadTxd(particleTxdSlot, "MODELS/PARTICLE.TXD");
CTxdStore::AddRef(particleTxdSlot);
CTxdStore::SetCurrentTxd(gameTxdSlot);
LoadingScreen("Loading the Game", "Setup game variables", nil);
CGameLogic::InitAtStartOfGame();
CReferences::Init();
TheCamera.Init();
TheCamera.SetRwCamera(Scene.camera);
CDebug::DebugInitTextBuffer();
ThePaths.Init();
ThePaths.AllocatePathFindInfoMem(4500);
CWeather::Init();
CCullZones::Init();
COcclusion::Init();
CCollision::Init();
CSetPieces::Init();
CTheZones::Init();
CUserDisplay::Init();
CMessages::Init();
CMessages::ClearAllMessagesDisplayedByGame();
CRecordDataForGame::Init();
CRestart::Initialise();
CWorld::Initialise();
CParticle::Initialise();
CAnimManager::Initialise();
CCutsceneMgr::Initialise();
CCarCtrl::Init();
InitModelIndices();
CModelInfo::Initialise();
CPickups::Init();
CTheCarGenerators::Init();
CdStreamAddImage("MODELS\\GTA3.IMG");
CFileLoader::LoadLevel("DATA\\DEFAULT.DAT");
CFileLoader::LoadLevel(datFile);
CWorld::AddParticles();
CVehicleModelInfo::LoadVehicleColours();
CVehicleModelInfo::LoadEnvironmentMaps();
CTheZones::PostZoneCreation();
LoadingScreen("Loading the Game", "Setup paths", GetRandomSplashScreen());
ThePaths.PreparePathData();
for (int i = 0; i < NUMPLAYERS; i++)
CWorld::Players[i].Clear();
CWorld::Players[0].LoadPlayerSkin();
TestModelIndices();
LoadingScreen("Loading the Game", "Setup water", nil);
CWaterLevel::Initialise("DATA\\WATER.DAT");
TheConsole.Init();
CDraw::SetFOV(120.0f);
CDraw::ms_fLODDistance = 500.0f;
LoadingScreen("Loading the Game", "Setup streaming", nil);
CStreaming::LoadInitialVehicles();
CStreaming::LoadInitialPeds();
CStreaming::RequestBigBuildings(LEVEL_NONE);
CStreaming::LoadAllRequestedModels(false);
printf("Streaming uses %dK of its memory", CStreaming::ms_memoryUsed / 1024);
LoadingScreen("Loading the Game", "Load animations", GetRandomSplashScreen());
CAnimManager::LoadAnimFiles();
CStreaming::LoadInitialWeapons();
CPed::Initialise();
CRouteNode::Initialise();
CEventList::Initialise();
LoadingScreen("Loading the Game", "Find big buildings", nil);
CRenderer::Init();
LoadingScreen("Loading the Game", "Setup game variables", nil);
CRadar::Initialise();
CRadar::LoadTextures();
CWeapon::InitialiseWeapons();
LoadingScreen("Loading the Game", "Setup traffic lights", nil);
CTrafficLights::ScanForLightsOnMap();
CRoadBlocks::Init();
LoadingScreen("Loading the Game", "Setup game variables", nil);
CPopulation::Initialise();
CWorld::PlayerInFocus = 0;
CCoronas::Init();
CShadows::Init();
CWeaponEffects::Init();
CSkidmarks::Init();
CAntennas::Init();
CGlass::Init();
gPhoneInfo.Initialise();
CSceneEdit::Initialise();
LoadingScreen("Loading the Game", "Load scripts", nil);
CTheScripts::Init();
CGangs::Initialise();
LoadingScreen("Loading the Game", "Setup game variables", nil);
CClock::Initialise(1000);
CHeli::InitHelis();
CCranes::InitCranes();
CMovingThings::Init();
CDarkel::Init();
CStats::Init();
CPacManPickups::Init();
CRubbish::Init();
CClouds::Init();
CSpecialFX::Init();
CWaterCannons::Init();
CBridge::Init();
CGarages::Init();
LoadingScreen("Loading the Game", "Initialise vehicle paths", nil);
CTrain::InitTrains();
CPlane::InitPlanes();
CCredits::Init();
CRecordDataForChase::Init();
CReplay::Init();
LoadingScreen("Loading the Game", "Start script", nil);
CTheScripts::StartTestScript();
CTheScripts::Process();
TheCamera.Process();
LoadingScreen("Loading the Game", "Load scene", nil);
CCollision::ms_collisionInMemory = currLevel;
for (int i = 0; i < MAX_PADS; i++)
CPad::GetPad(i)->Clear(true);
return true;
}
bool CGame::ShutDown(void)
{
CReplay::FinishPlayback();
CPlane::Shutdown();
CTrain::Shutdown();
CSpecialFX::Shutdown();
#ifndef PS2
CGarages::Shutdown();
#endif
CMovingThings::Shutdown();
gPhoneInfo.Shutdown();
CWeapon::ShutdownWeapons();
CPedType::Shutdown();
CMBlur::MotionBlurClose();
for (int32 i = 0; i < NUMPLAYERS; i++)
{
if ( CWorld::Players[i].m_pPed )
{
CWorld::Remove(CWorld::Players[i].m_pPed);
delete CWorld::Players[i].m_pPed;
CWorld::Players[i].m_pPed = nil;
}
CWorld::Players[i].Clear();
}
CRenderer::Shutdown();
CWorld::ShutDown();
DMAudio.DestroyAllGameCreatedEntities();
CModelInfo::ShutDown();
CAnimManager::Shutdown();
CCutsceneMgr::Shutdown();
CVehicleModelInfo::DeleteVehicleColourTextures();
CVehicleModelInfo::ShutdownEnvironmentMaps();
CRadar::Shutdown();
CStreaming::Shutdown();
CTxdStore::GameShutdown();
CCollision::Shutdown();
CWaterLevel::Shutdown();
CRubbish::Shutdown();
CClouds::Shutdown();
CShadows::Shutdown();
CCoronas::Shutdown();
CSkidmarks::Shutdown();
CWeaponEffects::Shutdown();
CParticle::Shutdown();
CPools::ShutDown();
CTxdStore::RemoveTxdSlot(gameTxdSlot);
CdStreamRemoveImages();
return true;
}
void CGame::ReInitGameObjectVariables(void)
{
CGameLogic::InitAtStartOfGame();
TheCamera.CCamera::Init();
TheCamera.SetRwCamera(Scene.camera);
CDebug::DebugInitTextBuffer();
CWeather::Init();
CUserDisplay::Init();
CMessages::Init();
CRestart::Initialise();
CWorld::bDoingCarCollisions = false;
CHud::ReInitialise();
CRadar::Initialise();
CCarCtrl::ReInit();
CTimeCycle::Initialise();
CDraw::SetFOV(120.0f);
CDraw::ms_fLODDistance = 500.0f;
CStreaming::RequestBigBuildings(LEVEL_NONE);
CStreaming::LoadAllRequestedModels(false);
CPed::Initialise();
CEventList::Initialise();
CWeapon::InitialiseWeapons();
CPopulation::Initialise();
for (int i = 0; i < NUMPLAYERS; i++)
CWorld::Players[i].Clear();
CWorld::PlayerInFocus = 0;
CAntennas::Init();
CGlass::Init();
gPhoneInfo.Initialise();
CTheScripts::Init();
CGangs::Initialise();
CTimer::Initialise();
CClock::Initialise(1000);
CTheCarGenerators::Init();
CHeli::InitHelis();
CMovingThings::Init();
CDarkel::Init();
CStats::Init();
CPickups::Init();
CPacManPickups::Init();
CGarages::Init();
CSpecialFX::Init();
CWaterCannons::Init();
CParticle::ReloadConfig();
if ( !FrontEndMenuManager.m_bWantToLoad )
{
CCranes::InitCranes();
CTheScripts::StartTestScript();
CTheScripts::Process();
TheCamera.Process();
CTrain::InitTrains();
CPlane::InitPlanes();
}
for (int32 i = 0; i < MAX_PADS; i++)
CPad::GetPad(i)->Clear(true);
}
void CGame::ReloadIPLs(void)
{
CTimer::Stop();
CWorld::RemoveStaticObjects();
ThePaths.Init();
CCullZones::Init();
CFileLoader::ReloadPaths("GTA3.IDE");
CFileLoader::LoadScene("INDUST.IPL");
CFileLoader::LoadScene("COMMER.IPL");
CFileLoader::LoadScene("SUBURBAN.IPL");
CFileLoader::LoadScene("CULL.IPL");
ThePaths.PreparePathData();
CTrafficLights::ScanForLightsOnMap();
CRoadBlocks::Init();
CCranes::InitCranes();
CGarages::Init();
CRenderer::SortBIGBuildings();
CTimer::Update();
}
void CGame::ShutDownForRestart(void)
{
CReplay::FinishPlayback();
CReplay::EmptyReplayBuffer();
DMAudio.DestroyAllGameCreatedEntities();
for (int i = 0; i < NUMPLAYERS; i++)
CWorld::Players[i].Clear();
CGarages::SetAllDoorsBackToOriginalHeight();
CTheScripts::UndoBuildingSwaps();
CTheScripts::UndoEntityInvisibilitySettings();
CWorld::ClearForRestart();
CTimer::Shutdown();
CStreaming::FlushRequestList();
CStreaming::DeleteAllRwObjects();
CStreaming::RemoveAllUnusedModels();
CStreaming::ms_disableStreaming = false;
CRadar::RemoveRadarSections();
FrontEndMenuManager.UnloadTextures();
CParticleObject::RemoveAllParticleObjects();
CSetPieces::Init();
CPedType::Shutdown();
CSpecialFX::Shutdown();
TidyUpMemory(true, false);
}
void CGame::InitialiseWhenRestarting(void)
{
CRect rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
CRGBA color(255, 255, 255, 255);
CTimer::Initialise();
CSprite2d::SetRecipNearClip();
b_FoundRecentSavedGameWantToLoad = false;
TheCamera.Init();
if ( FrontEndMenuManager.m_bWantToLoad == true )
{
RestoreForStartLoad();
CStreaming::LoadScene(TheCamera.GetPosition());
}
ReInitGameObjectVariables();
if ( FrontEndMenuManager.m_bWantToLoad == true )
{
if ( GenericLoad() == true )
{
DMAudio.ResetTimers(CTimer::GetTimeInMilliseconds());
CTrain::InitTrains();
CPlane::InitPlanes();
}
else
{
for ( int32 i = 0; i < 50; i++ )
{
HandleExit();
FrontEndMenuManager.MessageScreen("FED_LFL"); // Loading save game has failed. The game will restart now.
}
ShutDownForRestart();
CTimer::Stop();
CTimer::Initialise();
FrontEndMenuManager.m_bWantToLoad = false;
ReInitGameObjectVariables();
currLevel = LEVEL_NONE;
CCollision::SortOutCollisionAfterLoad();
}
}
CTimer::Update();
DMAudio.ChangeMusicMode(MUSICMODE_GAME);
}
void CGame::Process(void)
{
CPad::UpdatePads();
#ifdef GTA_PS2
ProcessTidyUpMemory();
#endif
TheCamera.SetMotionBlurAlpha(0);
if (TheCamera.m_BlurType == MBLUR_NONE || TheCamera.m_BlurType == MBLUR_SNIPER || TheCamera.m_BlurType == MBLUR_NORMAL)
TheCamera.SetMotionBlur(0, 0, 0, 0, MBLUR_NONE);
#ifdef DEBUGMENU
DebugMenuProcess();
#endif
CCutsceneMgr::Update();
if (!CCutsceneMgr::IsCutsceneProcessing() && !CTimer::GetIsCodePaused())
FrontEndMenuManager.Process();
CStreaming::Update();
if (!CTimer::GetIsPaused())
{
CTheZones::Update();
CSprite2d::SetRecipNearClip();
CSprite2d::InitPerFrame();
CFont::InitPerFrame();
CRecordDataForGame::SaveOrRetrieveDataForThisFrame();
CRecordDataForChase::SaveOrRetrieveDataForThisFrame();
CPad::DoCheats();
CClock::Update();
CWeather::Update();
CTheScripts::Process();
CCollision::Update();
CTrain::UpdateTrains();
CPlane::UpdatePlanes();
CHeli::UpdateHelis();
CDarkel::Update();
CSkidmarks::Update();
CAntennas::Update();
CGlass::Update();
CSceneEdit::Update();
CSetPieces::Update();
CEventList::Update();
CParticle::Update();
gFireManager.Update();
CPopulation::Update();
CWeapon::UpdateWeapons();
if (!CCutsceneMgr::IsRunning())
CTheCarGenerators::Process();
if (!CReplay::IsPlayingBack())
CCranes::UpdateCranes();
CClouds::Update();
CMovingThings::Update();
CWaterCannons::Update();
CUserDisplay::Process();
CReplay::Update();
CWorld::Process();
gAccidentManager.Update();
CPacManPickups::Update();
CPickups::Update();
CGarages::Update();
CRubbish::Update();
CSpecialFX::Update();
CTimeCycle::Update();
if (CReplay::ShouldStandardCameraBeProcessed())
TheCamera.Process();
CCullZones::Update();
if (!CReplay::IsPlayingBack())
CGameLogic::Update();
CBridge::Update();
CCoronas::DoSunAndMoon();
CCoronas::Update();
CShadows::UpdateStaticShadows();
CShadows::UpdatePermanentShadows();
gPhoneInfo.Update();
if (!CReplay::IsPlayingBack())
{
CCarCtrl::GenerateRandomCars();
CRoadBlocks::GenerateRoadBlocks();
CCarCtrl::RemoveDistantCars();
}
}
}
void
CGame::InitAfterFocusLoss()
{
/*
byte_869656 = byte_86969D;
result = cDMAudio::SetCurrent3DProvider(byte_86969D);
if ( !bGameStarted && !bMenuVisible )
byte_869642 = 1;
*/
//cDMAudio::SetCurrent3DProvider( ? ? ? );
if (!FrontEndMenuManager.m_bGameNotLoaded && !FrontEndMenuManager.m_bMenuActive)
FrontEndMenuManager.m_bStartUpFrontEndRequested = true;
}
bool
CGame::CanSeeOutSideFromCurrArea(void)
{
return currArea == AREA_MAIN_MAP || currArea == AREA_MALL ||
currArea == AREA_MANSION || currArea == AREA_HOTEL;
}
void CGame::DrasticTidyUpMemory(bool)
{
#ifdef PS2
// meow
#endif
}
void CGame::TidyUpMemory(bool, bool)
{
#ifdef PS2
// meow
#endif
}
void CGame::ProcessTidyUpMemory(void)
{
#ifdef PS2
// meow
#endif
}