|
| 1 | +/***************************************************************************** |
| 2 | + * |
| 3 | + * PROJECT: Multi Theft Auto |
| 4 | + * (Shared logic for modifications) |
| 5 | + * LICENSE: See LICENSE in the top level directory |
| 6 | + * FILE: mods/deathmatch/logic/CClientModel.h |
| 7 | + * PURPOSE: Model handling class |
| 8 | + * |
| 9 | + *****************************************************************************/ |
| 10 | + |
| 11 | +#include "StdInc.h" |
| 12 | + |
| 13 | +CClientModel::CClientModel(CClientManager* pManager, int iModelID, eClientModelType eModelType) |
| 14 | +{ |
| 15 | + // Init |
| 16 | + m_pManager = pManager; |
| 17 | + m_pModelManager = pManager->GetModelManager(); |
| 18 | + m_iModelID = iModelID; |
| 19 | + m_eModelType = eModelType; |
| 20 | + |
| 21 | + m_pModelManager->Add(this); |
| 22 | +} |
| 23 | + |
| 24 | +CClientModel::~CClientModel(void) |
| 25 | +{ |
| 26 | + Deallocate(); |
| 27 | + |
| 28 | + m_pModelManager->Remove(this); |
| 29 | +} |
| 30 | + |
| 31 | +bool CClientModel::Allocate(void) |
| 32 | +{ |
| 33 | + m_bAllocatedByUs = true; |
| 34 | + |
| 35 | + CModelInfo* pModelInfo = g_pGame->GetModelInfo(m_iModelID, true); |
| 36 | + |
| 37 | + // Allocate only on free IDs |
| 38 | + if (!pModelInfo->IsValid()) |
| 39 | + { |
| 40 | + pModelInfo->MakePedModel("PSYCHO"); |
| 41 | + return true; |
| 42 | + } |
| 43 | + return false; |
| 44 | +} |
| 45 | + |
| 46 | +bool CClientModel::Deallocate(void) |
| 47 | +{ |
| 48 | + if (!m_bAllocatedByUs) |
| 49 | + return false; |
| 50 | + |
| 51 | + CModelInfo* pModelInfo = g_pGame->GetModelInfo(m_iModelID, true); |
| 52 | + |
| 53 | + // ModelInfo must be valid |
| 54 | + if (pModelInfo->IsValid()) |
| 55 | + { |
| 56 | + if (m_eModelType == CCLIENTMODELPED) |
| 57 | + { |
| 58 | + // If some ped is using this ID, change him to CJ |
| 59 | + CClientPedManager* pPedManager = g_pClientGame->GetManager()->GetPedManager(); |
| 60 | + std::vector<CClientPed*>::const_iterator iter = pPedManager->IterBegin(); |
| 61 | + for (; iter != pPedManager->IterEnd(); iter++) |
| 62 | + { |
| 63 | + if ((*iter)->GetModel() == m_iModelID) |
| 64 | + { |
| 65 | + if ((*iter)->IsStreamedIn()) |
| 66 | + { |
| 67 | + (*iter)->StreamOutForABit(); |
| 68 | + } |
| 69 | + (*iter)->SetModel(0); |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + // Restore DFF/TXD |
| 75 | + g_pClientGame->GetManager()->GetDFFManager()->RestoreModel(m_iModelID); |
| 76 | + |
| 77 | + // Restore COL (for non ped models) |
| 78 | + if (m_eModelType != CCLIENTMODELPED) |
| 79 | + { |
| 80 | + g_pClientGame->GetManager()->GetColModelManager()->RestoreModel(m_iModelID); |
| 81 | + } |
| 82 | + |
| 83 | + pModelInfo->DeallocateModel(); |
| 84 | + |
| 85 | + this->SetParentResource(nullptr); |
| 86 | + return true; |
| 87 | + } |
| 88 | + return false; |
| 89 | +} |
0 commit comments