//CGameRules::IHitInfo virtual void OnHit(const HitInfo &hitInfo) { if(GetPortBool(&m_actInfo, EIP_Enable) == false) return; EntityId shooter = GetPortEntityId(&m_actInfo, EIP_ShooterId); if(shooter != 0 && shooter != hitInfo.shooterId) return; EntityId target = GetPortEntityId(&m_actInfo, EIP_TargetId); if(target != 0 && target != hitInfo.targetId) return; IEntitySystem *pEntitySys = gEnv->pEntitySystem; IEntity *pTempEntity; // check weapon match const string &weapon = GetPortString(&m_actInfo, EIP_Weapon); if(weapon.empty() == false) { pTempEntity = pEntitySys->GetEntity(hitInfo.weaponId); if(pTempEntity == 0 || weapon.compare(pTempEntity->GetClass()->GetName()) != 0) return; } // check ammo match const string &ammo = GetPortString(&m_actInfo, EIP_Ammo); if(ammo.empty() == false) { pTempEntity = pEntitySys->GetEntity(hitInfo.projectileId); if(pTempEntity == 0 || ammo.compare(pTempEntity->GetClass()->GetName()) != 0) return; } ActivateOutput(&m_actInfo, EOP_ShooterId, hitInfo.shooterId); ActivateOutput(&m_actInfo, EOP_TargetId, hitInfo.targetId); ActivateOutput(&m_actInfo, EOP_WeaponId, hitInfo.weaponId); ActivateOutput(&m_actInfo, EOP_ProjectileId, hitInfo.projectileId); ActivateOutput(&m_actInfo, EOP_HitPos, hitInfo.pos); ActivateOutput(&m_actInfo, EOP_HitDir, hitInfo.dir); ActivateOutput(&m_actInfo, EOP_HitNormal, hitInfo.normal); ActivateOutput(&m_actInfo, EOP_Damage, hitInfo.damage); ISurfaceType *pSurface = g_pGame->GetGameRules()->GetHitMaterial(hitInfo.material); ActivateOutput(&m_actInfo, EOP_Material, string(pSurface ? pSurface->GetName() : "")); const char *hitType = ""; if(CGameRules *pGR = g_pGame->GetGameRules()) hitType = pGR->GetHitType(hitInfo.type); ActivateOutput(&m_actInfo, EOP_HitType, string(hitType)); }
bool CScriptSurfaceTypesLoader::LoadSurfaceTypes( const char *sFolder,bool bReload ) { { if (!gEnv->p3DEngine) return false; I3DEngine *pEngine = gEnv->p3DEngine; ISurfaceTypeEnumerator *pEnum = pEngine->GetMaterialManager()->GetSurfaceTypeManager()->GetEnumerator(); if (pEnum) { for (ISurfaceType *pSurfaceType = pEnum->GetFirst(); pSurfaceType; pSurfaceType = pEnum->GetNext()) { SmartScriptTable mtlTable(gEnv->pScriptSystem); gEnv->pScriptSystem->SetGlobalValue( pSurfaceType->GetName(),mtlTable ); SmartScriptTable aiTable(gEnv->pScriptSystem); mtlTable->SetValue("AI",aiTable); aiTable->SetValue( "fImpactRadius",5.0f ); aiTable->SetValue( "fFootStepRadius",15.0f ); aiTable->SetValue( "proneMult",0.2f ); aiTable->SetValue( "crouchMult",0.5f ); aiTable->SetValue( "movingMult",2.5f ); } pEnum->Release(); } } return true; // Do not load surface types from script anymore. m_root = GetISystem()->CreateXmlNode("SurfaceTypes"); IScriptSystem *pScriptSystem = gEnv->pScriptSystem; ////////////////////////////////////////////////////////////////////////// // Make sure Materials table exist. ////////////////////////////////////////////////////////////////////////// SmartScriptTable mtlTable; if (!pScriptSystem->GetGlobalValue("Materials", mtlTable) || bReload) { mtlTable = pScriptSystem->CreateTable(); pScriptSystem->SetGlobalValue("Materials", mtlTable); } ICryPak *pIPak = gEnv->pCryPak; ISurfaceTypeManager *pSurfaceManager = gEnv->p3DEngine->GetMaterialManager()->GetSurfaceTypeManager(); if (!bReload) stl::push_back_unique( m_folders,sFolder ); string searchFolder = string(sFolder) + "/";; string searchFilter = searchFolder + "mat_*.lua"; gEnv->pScriptSystem->ExecuteFile(searchFolder+"common.lua", false, bReload); _finddata_t fd; intptr_t fhandle; fhandle = pIPak->FindFirst( searchFilter,&fd ); if (fhandle != -1) { do { // Skip back folders. if (fd.attrib & _A_SUBDIR) // skip if directory. continue; char name[_MAX_PATH]; _splitpath( fd.name,NULL,NULL,name,NULL ); if (strlen(name) == 0) continue; if (bReload) { ISurfaceType *pSurfaceType = pSurfaceManager->GetSurfaceTypeByName(name); if (pSurfaceType) { pSurfaceType->Load( pSurfaceType->GetId() ); continue; } } ISurfaceType *pSurfaceType = new CScriptSurfaceType( this,name,searchFolder+fd.name,0 ); if (pSurfaceManager->RegisterSurfaceType( pSurfaceType )) m_surfaceTypes.push_back(pSurfaceType); else pSurfaceType->Release(); } while (pIPak->FindNext( fhandle,&fd ) == 0); pIPak->FindClose(fhandle); } if (m_root) { m_root->saveToFile( "SurfaceTypes.xml" ); } return true; }