08-14-2010, 05:54 PM
Okay, so i thought I'd look to see if i could improve the jerky code for fun. But, I'm having trouble finding it. Is this some it in GameObject.cpp??
If it is the code that controls the "attraction" to the meat/jerky, could you please explain in more detail how it works? If it's not, could you please explain what it does, and where to find the jerky/meat/food code? Thanks.
Quote:////////////////////////////////////////////
//Attracts Enemies
pObject->mAttractProps.mbActive = cString::ToBool(pGameElem->Attribute("AttractEnemies"),false);
if(pObject->mAttractProps.mbActive)
{
pObject->mAttractProps.mfDistance = cString::ToFloat(pGameElem->Attribute("AttractDistance"),0);
tString sSubTypes = cString::ToString(pGameElem->Attribute("AttractSubtypes"),"");
cString::GetStringVec(sSubTypes,pObject->mAttractProps.mvSubtypes,NULL);
pObject->mAttractProps.mbIsEaten = cString::ToBool(pGameElem->Attribute("AttractIsEaten"),false);
pObject->mAttractProps.mfEatLength = cString::ToFloat(pGameElem->Attribute("AttractEatLength"),0);
}
////////////////////////////////////////////
//-----------------------------------------------------------------------
void cGameObject::UpdateAttraction(float afTimeStep)
{
if(mAttractProps.mbActive==false) return;
///////////////////////////////////////////////
//Check if the current attraction is near enough
if(mpCurrentAttraction)
{
////////////////////////////////////////
//Check for the attracted enemy
iCharacterBody *pBody = mpCurrentAttraction->GetMover()->GetCharBody();
float fDist = cMath::Vector3Dist( pBody->GetFeetPosition(),
mvBodies[0]->GetWorldPosition());
//Check if the enemy have become busy.
if( (mpCurrentAttraction->GetCurrentStateId() != STATE_MOVETO && fDist <pBody->GetSize().x*0.75f)
||
(mAttractProps.mbIsEaten && fDist <pBody->GetSize().x*0.75f))
{
//Use half the width here.
if(mAttractProps.mbIsEaten)
{
mpCurrentAttraction->SetTempFloat(mAttractProps.mfEatLength);
mpCurrentAttraction->ChangeState(STATE_EAT);
}
mpCurrentAttraction->SetAttracted(false);
mpCurrentAttraction = NULL;
mbDestroyMe = true;
return;
}
else if(mpCurrentAttraction->GetCurrentStateId() != STATE_MOVETO)
{
mpCurrentAttraction->SetAttracted(false);
mpCurrentAttraction = NULL;
return;
}
}
///////////////////////////////////////////////
//Check if any enemy is near enough to be attracted
else
{
if(mfAttractCount <=0)
{
float fClosestDist = 10000.0f;
iGameEnemy *pChosenEnemy = NULL;
tGameEnemyIterator enemyIt = mpInit->mpMapHandler->GetGameEnemyIterator();
while(enemyIt.HasNext())
{
iGameEnemy *pEnemy = enemyIt.Next();
if( pEnemy->GetHealth() <= 0 || pEnemy->IsActive()==false ||
pEnemy->IsAttracted())
{
continue;
}
bool bCorrectSub = false;
for(size_t i=0; i< mAttractProps.mvSubtypes.size(); ++i)
{
if(mAttractProps.mvSubtypes[i] == pEnemy->GetSubType()) bCorrectSub = true;
}
if(bCorrectSub==false) continue;
//Check if the enemy has already been attracted by this object
if(m_setAttractedEnemies.find(pEnemy) != m_setAttractedEnemies.end()) continue;
float fDist = cMath::Vector3Dist( pEnemy->GetMover()->GetCharBody()->GetFeetPosition(),
mvBodies[0]->GetWorldPosition());
if(fDist < mAttractProps.mfDistance && fDist < fClosestDist)
{
fClosestDist = fDist;
pChosenEnemy = pEnemy;
}
}
if(pChosenEnemy)
{
if(pChosenEnemy->MoveToPos(mvBodies[0]->GetWorldPosition() +cVector3f(0,0.2f,0)))
{
mpCurrentAttraction = pChosenEnemy;
pChosenEnemy->SetAttracted(true);
m_setAttractedEnemies.insert(pChosenEnemy);
}
}
mfAttractCount = 0.2f;
}
else
{
mfAttractCount -= afTimeStep;
}
}
}
//--------------------------------------------------------------------
If it is the code that controls the "attraction" to the meat/jerky, could you please explain in more detail how it works? If it's not, could you please explain what it does, and where to find the jerky/meat/food code? Thanks.