void World::battleEventCheck() { BattleState* bs = static_cast<BattleState*>( GetWorldStateManager().getState( GAME_WORLD_STATE_BATTLE ) ); assert( bs ); // Detect battle event. // If current selected unit isn't hero unit, and isn't talkable, // regard as enemy. And if hero is in the fight area of enemy, start battle. UnitSet::iterator it = m_unitSet.begin(); for ( ; it != m_unitSet.end(); ++it ) { if ( (*it) != getHeroUnit() ) { Enemy* oppCharacter = static_cast<Enemy*>( *it ); assert( oppCharacter ); if ( oppCharacter->getType() == UT_ENEMY && oppCharacter->isTalkable() == false && !oppCharacter->getRemoveFlag() ) { if ( isInEventArea( getHeroUnit(), oppCharacter ) == true) { ////////////////////////////////////////////////////////////////////////// // Check whether there is obstacle between hero and enemy. // Shoot ray from hero to enemy, and if distance to the third intersected // mesh is shorter than distance between hero and enemy, then there exists // at least one obstacle. ArnVec3 vStartPos( getHero()->getPos() ); ArnVec3 vRayDir = oppCharacter->getPos() - getHero()->getPos(); float fRayLength = ArnVec3Length( &vRayDir ); ArnVec3Normalize( &vRayDir, &vRayDir ); float f3rdDist = Utility::FullTraverseExhaustiveRayTesting( getArnSceneGraphPt()->getSceneRoot(), vStartPos, vRayDir, 1 ); //printf( "3rd dist, ray length %f, %f\n", f3rdDist, fRayLength ); if ( f3rdDist < fRayLength ) continue; ////////////////////////////////////////////////////////////////////////// // No more move! getHeroUnit()->clearKey(); oppCharacter->clearKey(); getHeroUnit()->setControllable( false ); // view each other getHero()->setViewAt( &oppCharacter->getPos() ); oppCharacter->setViewAt( &getHero()->getPos() ); // Insert to enemy pool at BattleState bs->insertEnemy( oppCharacter ); if ( GetWorldStateManager().curStateEnum() == GAME_WORLD_STATE_FIELD ) GetWorldStateManager().setNextState( GAME_WORLD_STATE_BATTLE ); } } } } }
void World::wannaTalkingEventCheck() { BattleState* bs = static_cast<BattleState*>( GetWorldStateManager().getState( GAME_WORLD_STATE_BATTLE ) ); assert( bs ); // Check if hero is in the talking enemy's fight area. If true, the enemy look at hero. // This work is almost same as battle event check. UnitSet::iterator it = m_unitSet.begin(); for ( ; it != m_unitSet.end(); ++it ) { if ( (*it) != getHeroUnit() ) { Enemy* unconfirmedEnemy = dynamic_cast<Enemy*>( *it ); if ( unconfirmedEnemy != NULL && unconfirmedEnemy->isTalkable() == true && !unconfirmedEnemy->getRemoveFlag() ) { Enemy* talkingEnemy = unconfirmedEnemy; if ( isInEventArea( getHeroUnit() , talkingEnemy ) == true ) { // no more move! talkingEnemy->clearKey(); // View at hero talkingEnemy->setViewAt( &getHero()->getPos() ); //bs->insertEnemy( talkingEnemy ); } else { talkingEnemy->setRotZ( 0.0f ); } } } } }