float Animal_Wild_Flee::preCondition() { return 0.0f; /* * Fleeing from an approaching player has the following preconditions: * - There is a player within flight range. * - There is no character attacking us. * - Our owner is not in range. * */ if ( m_npc->attackTarget() ) return 0.0f; MapCharsIterator ri = MapObjects::instance()->listCharsInCircle( m_npc->pos(), Config::instance()->animalWildFleeRange() ); for ( P_CHAR pChar = ri.first(); pChar; pChar = ri.next() ) { P_PLAYER pPlayer = dynamic_cast<P_PLAYER>( pChar ); if ( pPlayer && !pPlayer->free && !pPlayer->isGMorCounselor() && !pPlayer->isHidden() && !pPlayer->isInvisible() ) { pFleeFromSer = pPlayer->serial(); } if ( pPlayer && m_npc->owner() == pPlayer ) return 0.0f; } if ( pFleeFromSer != INVALID_SERIAL ) return 1.0f; return 0.0f; }
float Animal_Wild_Flee::postCondition() { /* * Fleeing from an approaching player has the following postconditions: * - There is no character in flight range. * - There is an character attacking us. * - Our owner has come in range. * */ if( m_npc->attackTarget() ) return 1.0f; RegionIterator4Chars ri( m_npc->pos(), SrvParams->animalWildFleeRange() ); bool found = false; for(ri.Begin(); !ri.atEnd(); ri++) { P_PLAYER pPlayer = dynamic_cast<P_PLAYER>(ri.GetData()); if( pPlayer && !pPlayer->free && !pPlayer->isGMorCounselor() && !pPlayer->isHidden() && !pPlayer->isInvisible() ) found = true; if( pPlayer && m_npc->owner() == pPlayer ) return 1.0f; } if( found ) return 0.0f; return 1.0f; }
float Animal_Wild_Flee::postCondition() { /* * Fleeing from an approaching player has the following postconditions: * - There is no character in flight range. * - There is an character attacking us. * - Our owner has come in range. * */ if ( m_npc->attackTarget() ) return 1.0f; bool found = false; MapCharsIterator ri = MapObjects::instance()->listCharsInCircle( m_npc->pos(), Config::instance()->animalWildFleeRange() ); for ( P_CHAR pChar = ri.first(); pChar; pChar = ri.next() ) { P_PLAYER pPlayer = dynamic_cast<P_PLAYER>( pChar ); if ( pPlayer && !pPlayer->free && !pPlayer->isGMorCounselor() && !pPlayer->isHidden() && !pPlayer->isInvisible() ) found = true; if ( pPlayer && m_npc->owner() == pPlayer ) return 1.0f; } if ( found ) return 0.0f; return 1.0f; }