BOOL KDoodadMgr::RemoveFromScene( DWORD dwId ) { BOOL bResult = FALSE; KDoodad* pstDoodad = NULL; IKScene* pScene = NULL; PROCESS_ERROR(pstDoodad = m_cObjPool.GetById(dwId)); PROCESS_ERROR(pScene = pstDoodad->GetScene()); PROCESS_ERROR(pScene->RemoveDoodad(pstDoodad)); g_cScriptManager.GetSafeScript()->CallTableFunction("Doodad", "OnLeaveScene", 1, "os", pstDoodad->GetScriptInterface(), pstDoodad->m_strClass.c_str()); bResult = TRUE; EXIT0: return bResult; }
KDoodad* KDoodadMgr::CreateDoodad(DWORD dwTemplateId, DWORD dwId /*= KD_BAD_ID*/ ) { BOOL bResult = FALSE; INT nIndex = 0; KDoodad* pDoodad = NULL; pDoodad = m_cObjPool.GetById(dwId); if (pDoodad) { nIndex = pDoodad->m_nIndex; IKScene* pScene = pDoodad->GetScene(); if (pScene) pScene->RemoveDoodad(pDoodad); } else { KDoodadTemplateMapIt stIt = m_mapDoodadTemplate.find(dwTemplateId); LOG_PROCESS_ERROR(stIt != m_mapDoodadTemplate.end()); nIndex = m_cObjPool.Add(dwId); LOG_PROCESS_ERROR(pDoodad = m_cObjPool.GetByIndex(nIndex)); LOG_PROCESS_ERROR(pDoodad->Init(nIndex, &stIt->second)); } bResult = TRUE; EXIT0: if (FALSE == bResult) { if (pDoodad) { DestroyDoodad(pDoodad->m_dwId); pDoodad = NULL; } } return pDoodad; }