float CPersonalWeaponTypeFunction::ffGetTheBestWeapon() { u32 dwBestWeapon = 0; if (ef_storage().non_alife().member() && ef_storage().non_alife().member_item()) return (float(dwfGetWeaponType())); if (ef_storage().non_alife().member()) { const CInventoryOwner *tpInventoryOwner = smart_cast<const CInventoryOwner*>(ef_storage().non_alife().member()); if (tpInventoryOwner) { xr_vector<CInventorySlot>::const_iterator I = tpInventoryOwner->inventory().m_slots.begin(); xr_vector<CInventorySlot>::const_iterator E = tpInventoryOwner->inventory().m_slots.end(); for ( ; I != E; ++I) if ((*I).m_pIItem) { CWeapon *tpCustomWeapon = smart_cast<CWeapon*>((*I).m_pIItem); if (tpCustomWeapon && (tpCustomWeapon->GetSuitableAmmoTotal(true) > tpCustomWeapon->GetAmmoMagSize()/10)) { ef_storage().non_alife().member_item() = tpCustomWeapon; u32 dwCurrentBestWeapon = dwfGetWeaponType(); if (dwCurrentBestWeapon > dwBestWeapon) dwBestWeapon = dwCurrentBestWeapon; ef_storage().non_alife().member_item() = 0; } } } } else { if (!ef_storage().alife().member() || !ef_storage().alife().member()->m_tpCurrentBestWeapon) return(0); ef_storage().alife().member_item() = ef_storage().alife().member()->m_tpCurrentBestWeapon; dwBestWeapon = dwfGetWeaponType(); } return(float(dwBestWeapon)); }
float CDistanceFunction::ffGetValue() { if (ef_storage().non_alife().member()) return(ef_storage().non_alife().member()->Position().distance_to(ef_storage().non_alife().enemy()->Position())); else return(ef_storage().alife().member()->base()->Position().distance_to(ef_storage().alife().enemy()->base()->Position())); }
float CPersonalMoraleFunction::ffGetValue() { if (ef_storage().non_alife().member()) return(ef_storage().non_alife().member()->m_fMorale); else { const CSE_ALifeMonsterAbstract *l_tpALifeMonsterAbstract = smart_cast<const CSE_ALifeMonsterAbstract*>(ef_storage().alife().member()); VERIFY3 (l_tpALifeMonsterAbstract,"Invalid object passed to the evaluation function ",m_caName); return(l_tpALifeMonsterAbstract->m_fMorale); } }
u32 CPersonalWeaponTypeFunction::dwfGetWeaponType() { u32 result; if (ef_storage().non_alife().member_item()) result = ef_storage().non_alife().member_item()->ef_weapon_type(); else { VERIFY2 (ef_storage().alife().member_item(),"No object specified for evaluation function"); result = ef_storage().alife().member_item()->ef_weapon_type(); } return (result); }
IC CLASS_ID CBaseFunction::clsid_enemy_item() const { CLASS_ID result; if (ef_storage().non_alife().enemy_item()) result = ef_storage().non_alife().enemy_item()->CLS_ID; else { VERIFY2 (ef_storage().alife().enemy_item(),"No object specified for evaluation function"); result = ef_storage().alife().enemy_item()->m_tClassID; } return (result); }
float CMainWeaponType::ffGetValue() { u32 result; if (ef_storage().non_alife().member_item()) result = ef_storage().non_alife().member_item()->ef_main_weapon_type(); else { VERIFY2 (ef_storage().alife().member_item(),"No object specified for evaluation function"); result = ef_storage().alife().member_item()->ef_main_weapon_type(); } VERIFY (float(result) < m_fMaxResultValue + 1.f); return (float(result)); }
float CMainWeaponPreference::ffGetValue() { if (ef_storage().non_alife().member()) { #pragma todo("Dima to Dima : Append MainWeaponPreference with non-ALife branch") return (0); } else { CSE_ALifeHumanAbstract *l_tpALifeHumanAbstract = smart_cast<CSE_ALifeHumanAbstract*>(ef_storage().alife().member()); R_ASSERT2 (l_tpALifeHumanAbstract,"Non-human object in EquipmentPreference evaluation function"); return (l_tpALifeHumanAbstract->m_cpMainWeaponPreferences[ef_storage().m_pfMainWeaponType->dwfGetDiscreteValue(iFloor(ef_storage().m_pfMainWeaponType->ffGetMaxResultValue() + .5f))]); } }
IC CLASS_ID CBaseFunction::clsid_enemy() const { CLASS_ID result; if (ef_storage().non_alife().enemy()) result = ef_storage().non_alife().enemy()->CLS_ID; else { VERIFY2 (ef_storage().alife().enemy(),"No object specified for evaluation function"); const CSE_ALifeDynamicObject *l_tpALifeDynamicObject = smart_cast<const CSE_ALifeDynamicObject*>(ef_storage().alife().enemy()); VERIFY2 (l_tpALifeDynamicObject,"Invalid object passed to the evaluation function"); result = l_tpALifeDynamicObject->m_tClassID; } return (result); }
float CEnemyAnomalyType::ffGetValue() { u32 result; if (ef_storage().non_alife().enemy()) result = ef_storage().non_alife().enemy()->ef_anomaly_type(); else { VERIFY2 (ef_storage().alife().enemy(),"No object specified for evaluation function"); result = ef_storage().alife().enemy()->ef_anomaly_type(); } VERIFY (float(result) < m_fMaxResultValue + 1.f); return (float(result)); }
float CPersonalCreatureTypeFunction::ffGetValue() { u32 result; if (ef_storage().non_alife().member()) result = ef_storage().non_alife().member()->ef_creature_type(); else { VERIFY2 (ef_storage().alife().member(),"No object specified for evaluation function"); result = ef_storage().alife().member()->ef_creature_type(); } VERIFY (float(result) < m_fMaxResultValue + 1); return (float(result)); }
float CPersonalHealthFunction::ffGetValue() { if (ef_storage().non_alife().member()) { m_fMaxResultValue = ef_storage().non_alife().member()->GetMaxHealth(); return(ef_storage().non_alife().member()->GetfHealth()); } else { const CSE_ALifeMonsterAbstract *l_tpALifeMonsterAbstract = smart_cast<const CSE_ALifeMonsterAbstract*>(ef_storage().alife().member()); VERIFY3 (l_tpALifeMonsterAbstract,"Invalid object passed to the evaluation function ",m_caName); m_fMaxResultValue = l_tpALifeMonsterAbstract->g_MaxHealth(); return(l_tpALifeMonsterAbstract->get_health()); } }
float CItemDeterioration::ffGetValue() { if (ef_storage().non_alife().member_item()) { const CWeapon *weapon = smart_cast<const CWeapon*>(ef_storage().non_alife().member_item()); if (weapon) return (1.f - weapon->GetCondition()); #pragma todo("Dima to Dima : Append ItemDeterioration with non-ALife non-weapon branch") return (0.f); } else { const CSE_ALifeInventoryItem *l_tpALifeInventoryItem = smart_cast<const CSE_ALifeInventoryItem*>(ef_storage().alife().member_item()); R_ASSERT2 (l_tpALifeInventoryItem,"Non-item object specified for the ItemDeterioration evaluation function"); return (l_tpALifeInventoryItem->m_fDeteriorationValue); } }
float CEnemyRukzakWeightFunction::ffGetValue() { float m_fLastValue; if (ef_storage().non_alife().member()) { const CInventoryOwner *tpInventoryOwner = smart_cast<const CInventoryOwner*>(ef_storage().non_alife().member()); if (tpInventoryOwner) m_fLastValue = tpInventoryOwner->inventory().TotalWeight(); else m_fLastValue = 0; } else { // CSE_ALifeHumanAbstract *l_tpALifeHumanAbstract = smart_cast<CSE_ALifeHumanAbstract*>(ef_storage().alife().member()); // if (l_tpALifeHumanAbstract) // m_fLastValue = l_tpALifeHumanAbstract->m_fCumulativeItemMass; // else m_fLastValue = 0; } return (m_fLastValue); }
float CItemValue::ffGetValue() { if (ef_storage().non_alife().member()) { #pragma todo("Dima to Dima : Append ItemValue with non-ALife branch") return (0); } else { const CSE_ALifeInventoryItem *l_tpALifeInventoryItem = smart_cast<const CSE_ALifeInventoryItem*>(ef_storage().alife().member_item()); R_ASSERT2 (l_tpALifeInventoryItem,"Non-item object specified for the ItemDeterioration evaluation function"); return (float(l_tpALifeInventoryItem->m_dwCost)); } }
float CWeaponAmmoCount::ffGetValue() { if (ef_storage().non_alife().member()) { #pragma todo("Dima to Dima : Append WeaponAmmoCount with non-ALife branch") return (0); } else { CSE_ALifeHumanAbstract *l_tpALifeHumanAbstract = smart_cast<CSE_ALifeHumanAbstract*>(ef_storage().alife().member()); R_ASSERT2 (l_tpALifeHumanAbstract,"Non-human object in WeaponAmmoCount evaluation function"); return (l_tpALifeHumanAbstract->get_available_ammo_count(smart_cast<const CSE_ALifeItemWeapon*>(ef_storage().alife().member_item()),l_tpALifeHumanAbstract->alife().m_temp_item_vector)); } }
float CPersonalWeaponTypeFunction::ffGetValue() { float result; if (ef_storage().non_alife().member()) if (ef_storage().non_alife().member()->natural_weapon()) result = (float)ef_storage().non_alife().member()->ef_weapon_type(); else result = ffGetTheBestWeapon(); else { VERIFY2 (ef_storage().alife().member(),"No object specified for evaluation function"); if (ef_storage().alife().member()->natural_weapon()) result = (float)ef_storage().alife().member()->ef_weapon_type(); else result = ffGetTheBestWeapon(); } VERIFY (result < m_fMaxResultValue + 1.f); return (result); }
float CPatternFunction::ffGetValue() { for (u32 i=0; i<m_dwVariableCount; ++i) m_dwaVariableValues[i] = ef_storage().m_fpaBaseFunctions[m_dwaVariableTypes[i]]->dwfGetDiscreteValue(m_dwaAtomicFeatureRange[i]); #ifdef DEBUG if (psAI_Flags.test(aiFuncs)) { float value = ffEvaluate(); string256 caString; int j = sprintf_s(caString,sizeof(caString),"%32s (",m_caName); for (u32 i=0; i<m_dwVariableCount; ++i) j += sprintf_s(caString + j, sizeof(caString)-j, " %3d",m_dwaVariableValues[i] + 1); sprintf_s (caString + j,sizeof(caString)-j, ") = %7.2f",value); Msg ("- %s",caString); return (value); } #endif return(ffEvaluate()); }
float CPersonalEyeRange::ffGetValue() { const CSE_ALifeMonsterAbstract *l_tpALifeMonsterAbstract = smart_cast<const CSE_ALifeMonsterAbstract*>(ef_storage().alife().member()); VERIFY3 (l_tpALifeMonsterAbstract,"Invalid object passed to the evaluation function ",m_caName); return (l_tpALifeMonsterAbstract->m_fEyeRange); }
float CPersonalMaxHealth::ffGetValue() { CSE_ALifeMonsterAbstract *l_tpALifeMonsterAbstract = smart_cast<CSE_ALifeMonsterAbstract*>(ef_storage().alife().member()); VERIFY3 (l_tpALifeMonsterAbstract,"Invalid object passed to the evaluation function ",m_caName); const CSE_ALifeGroupAbstract *l_tpALifeGroupAbstract = smart_cast<const CSE_ALifeGroupAbstract*>(ef_storage().alife().member()); if (!l_tpALifeGroupAbstract) return (l_tpALifeMonsterAbstract->m_fMaxHealthValue); else return (l_tpALifeMonsterAbstract->m_fMaxHealthValue*l_tpALifeGroupAbstract->m_wCount); }
float CEnemyDistanceToGraphPoint::ffGetValue() { CSE_ALifeDynamicObject *l_tpALifeDynamicObject = smart_cast<CSE_ALifeDynamicObject*>(ef_storage().alife().enemy()); R_ASSERT3 (l_tpALifeDynamicObject,"Invalid object passed to the evaluation function ",m_caName); if (l_tpALifeDynamicObject->m_fDistance < 5.f) return (0); if (l_tpALifeDynamicObject->m_fDistance < 10.f) return (1); if (l_tpALifeDynamicObject->m_fDistance < 15.f) return (2); if (l_tpALifeDynamicObject->m_fDistance < 20.f) return (3); return (4); }
float CDetectorType::ffGetValue() { if (ef_storage().non_alife().member()) { if (!ef_storage().non_alife().member_item()) return (0); } else { if (!ef_storage().alife().member_item()) return (0); } u32 result; if (ef_storage().non_alife().member()) if (ef_storage().non_alife().member()->natural_detector()) result = ef_storage().non_alife().member()->ef_detector_type(); else result = ef_storage().non_alife().member_item()->ef_detector_type(); else { VERIFY2 (ef_storage().alife().member(),"No object specified for evaluation function"); if (ef_storage().alife().member()->natural_detector()) result = ef_storage().alife().member()->ef_detector_type(); else result = ef_storage().alife().member_item()->ef_detector_type(); } VERIFY (float(result) < m_fMaxResultValue + 1.f); return (float(result)); }
void CPatternFunction::vfLoadEF(LPCSTR caFileName) { string_path caPath; if (!FS.exist(caPath,"$game_ai$",caFileName)) { Msg ("! Evaluation function : File not found \"%s\"",caPath); R_ASSERT (false); return; } IReader *F = FS.r_open(caPath); F->r (&m_tEFHeader,sizeof(SEFHeader)); if (EFC_VERSION != m_tEFHeader.dwBuilderVersion) { FS.r_close (F); Msg ("! Evaluation function (%s) : Not supported version of the Evaluation Function Contructor",caPath); R_ASSERT (false); return; } F->r (&m_dwVariableCount,sizeof(m_dwVariableCount)); m_dwaAtomicFeatureRange = xr_alloc<u32>(m_dwVariableCount); ZeroMemory (m_dwaAtomicFeatureRange,m_dwVariableCount*sizeof(u32)); u32 *m_dwaAtomicIndexes = xr_alloc<u32>(m_dwVariableCount); ZeroMemory (m_dwaAtomicIndexes,m_dwVariableCount*sizeof(u32)); for (u32 i=0; i<m_dwVariableCount; ++i) { F->r(m_dwaAtomicFeatureRange + i,sizeof(u32)); if (i) m_dwaAtomicIndexes[i] = m_dwaAtomicIndexes[i-1] + m_dwaAtomicFeatureRange[i-1]; } m_dwaVariableTypes = xr_alloc<u32>(m_dwVariableCount); F->r (m_dwaVariableTypes,m_dwVariableCount*sizeof(u32)); F->r (&m_dwFunctionType,sizeof(u32)); F->r (&m_fMinResultValue,sizeof(float)); F->r (&m_fMaxResultValue,sizeof(float)); F->r (&m_dwPatternCount,sizeof(m_dwPatternCount)); m_tpPatterns = xr_alloc<SPattern>(m_dwPatternCount); m_dwaPatternIndexes = xr_alloc<u32>(m_dwPatternCount); ZeroMemory (m_dwaPatternIndexes,m_dwPatternCount*sizeof(u32)); m_dwParameterCount = 0; for (u32 i=0; i<m_dwPatternCount; ++i) { if (i) m_dwaPatternIndexes[i] = m_dwParameterCount; F->r (&(m_tpPatterns[i].dwCardinality),sizeof(m_tpPatterns[i].dwCardinality)); m_tpPatterns[i].dwaVariableIndexes = xr_alloc<u32>(m_tpPatterns[i].dwCardinality); F->r (m_tpPatterns[i].dwaVariableIndexes,m_tpPatterns[i].dwCardinality*sizeof(u32)); u32 m_dwComplexity = 1; for (int j=0; j<(int)m_tpPatterns[i].dwCardinality; ++j) m_dwComplexity *= m_dwaAtomicFeatureRange[m_tpPatterns[i].dwaVariableIndexes[j]]; m_dwParameterCount += m_dwComplexity; } m_faParameters = xr_alloc<float>(m_dwParameterCount); F->r (m_faParameters,m_dwParameterCount*sizeof(float)); FS.r_close (F); m_dwaVariableValues = xr_alloc<u32>(m_dwVariableCount); xr_free (m_dwaAtomicIndexes); ef_storage().m_fpaBaseFunctions[m_dwFunctionType] = this; _splitpath (caPath,0,0,m_caName,0); // Msg ("* Evaluation function \"%s\" is successfully loaded",m_caName); }
u32 CWeaponAmmoCount::dwfGetDiscreteValue(u32 dwDiscretizationValue) { float fTemp = ffGetValue(); if (fTemp <= m_fMinResultValue) return(0); else if (fTemp >= m_fMaxResultValue) return(dwDiscretizationValue - 1); else { const CSE_ALifeItemWeapon *l_tpALifeItemWeapon = smart_cast<const CSE_ALifeItemWeapon*>(ef_storage().alife().member_item()); if (l_tpALifeItemWeapon && l_tpALifeItemWeapon->m_caAmmoSections) { string32 S; _GetItem (l_tpALifeItemWeapon->m_caAmmoSections,0,S); u32 l_dwBoxSize = pSettings->r_s32(S,"box_size"); if (fTemp <= 3*l_dwBoxSize) return(iFloor(1*float(dwDiscretizationValue)/10 + .5f)); return(iFloor(2*float(dwDiscretizationValue)/10 + .5f)); } else return(dwDiscretizationValue - 1); } }
float CGraphPointType0::ffGetValue() { return (ai().game_graph().vertex(ef_storage().alife().member_item()->m_tGraphID)->vertex_type()[0]); }