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 ); } } } } }
BOOL CRVTrackerTextureWrap::OnStart() { // Make sure we're in a valid mode... if ((m_pView->GetEditMode() != GEOMETRY_EDITMODE) && (m_pView->GetEditMode() != BRUSH_EDITMODE) ) return FALSE; // Get the poly we're pointing at.. m_cStartPoint = m_pView->GetCurMousePos(); CEditRay cStartRay = m_pView->ViewDef()->MakeRayFromScreenPoint(m_cStartPoint); m_rBasePoly = FindBestPoly(cStartRay); // Make sure they clicked on a poly... if (!m_rBasePoly.IsValid()) return FALSE; // For geometry mode.. if (m_pView->GetEditMode() == GEOMETRY_EDITMODE) { // Make sure we've got the poly we're clicking on selected.. CPolyRefArray &rTaggedPolies = m_pView->TaggedPolies(); for (uint32 nFindBaseLoop = 0; nFindBaseLoop < rTaggedPolies.GetSize(); ++nFindBaseLoop) { if (rTaggedPolies[nFindBaseLoop] == m_rBasePoly) break; } if (nFindBaseLoop >= rTaggedPolies.GetSize()) return FALSE; } // For brush mode... else if (m_pView->GetEditMode() == BRUSH_EDITMODE) { // Make sure we're clicking on a selected brush poly CEditRegion *pRegion = m_pView->GetRegionDoc()->GetRegion(); for (uint32 nBrushSearch = 0; nBrushSearch < pRegion->GetNumSelections(); ++nBrushSearch) { if (pRegion->GetSelection(nBrushSearch)->GetType() == Node_Brush) { CEditBrush *pBrush = pRegion->GetSelection(nBrushSearch)->AsBrush(); if (m_rBasePoly.m_pBrush == pBrush) break; } } if (nBrushSearch >= pRegion->GetNumSelections()) return FALSE; } // Get the intersection point.. CReal fPolyDist; if (!m_rBasePoly()->IntersectRay(cStartRay, fPolyDist, TRUE)) { // Uh.. This really shouldn't happen.. But whatever... return FALSE; } LTVector pos = cStartRay.m_Dir * fPolyDist + cStartRay.m_Pos; CEditVert vStartPos(pos); // Set up the drawing brush.. m_pView->DrawingBrush().Term(); m_pView->DrawingBrush().m_Points.Append(vStartPos); m_pView->DrawingBrush().m_Points.Append(vStartPos); return TRUE; }