void SjCoverBrowser::OnContextMenu(int clickX, int clickY) { SjMenu mainMenu(0); SjCol* cover; long found = FindCover(clickX, clickY, &cover); if( found == FOUND_COVER && cover->m_rowCount > 0 && cover->m_rows[0]->m_roughType == SJ_RRTYPE_COVER ) { // select the item under the mouse if( cover->FindFirstSelectedRow() == NULL ) { g_mainFrame->m_columnMixer.SelectAll(FALSE); SelectAllRows(cover); RefreshSelection(); } m_lastClickedCover = cover; cover->m_rows[0]->CreateContextMenu(mainMenu); } else { m_lastClickedCover = NULL; } // add main items to menu g_mainFrame->CreateContextMenu_(mainMenu); // show menu if( mainMenu.GetMenuItemCount() ) { m_window->PopupMenu(&mainMenu); } }
void SjCoverBrowser::OnMouseMiddleUp(wxMouseEvent& event) { bool skip = TRUE; SjCol* cover; long found = FindCover(event.GetX(), event.GetY(), &cover); if( found == FOUND_COVER && cover->m_rowCount > 0 ) { SjRow* row = cover->m_rows[0]; int usesMiddleClick = row->UsesMiddleClick(); if( usesMiddleClick ) { g_mainFrame->m_columnMixer.SelectAll(false); SelectAllRows(cover); RefreshSelection(); m_window->Update(); skip = FALSE; row->OnMiddleClick(event.ShiftDown() || event.ControlDown()); } } if( skip ) { event.Skip(); } }
void SjCoverBrowser::OnDropImage(SjDataObject* data, int mouseX, int mouseY) { SjCol* cover; long found = FindCover(mouseX, mouseY, &cover); if( found == FOUND_COVER && cover->m_rowCount > 0 ) { if( cover->m_rows[0]->OnDropData(data) ) { Realize(false, true /*keep col index*/); m_window->Refresh(); m_window->Update(); } } }
bool SjCoverBrowser::OnMouseLeftDClick(wxMouseEvent& event) { SjCol* cover; long found = FindCover(event.GetX(), event.GetY(), &cover); if( found == FOUND_COVER ) { ToggleView(); return true; // click used } else if( found == FOUND_COVER_ARROW ) { return true; // click used (avoid toggle the view by fast clicks on the cover toggler) } return false; // click not used }
wxRect SjCoverBrowser::GetToolTipRect(int mouseX, int mouseY) { wxRect retRect; SjCol* cover; long found = FindCover(mouseX, mouseY, &cover, &retRect); if( found == FOUND_COVER || found == FOUND_COVER_ARROW ) { ; // rect is set up by FindRow } else { retRect.x = -1000; retRect.y = -1000; retRect.width = 1; retRect.height = 1; } return retRect; }
void SjCoverBrowser::OnMouseSelect(wxMouseEvent& event) { /* (de-)select the item under the mouse (if any) */ SjCol* cover; long found = FindCover(event.GetX(), event.GetY(), &cover); if( found == FOUND_COVER ) { g_mainFrame->m_columnMixer.SelectAll(false); SelectAllRows(cover); RefreshSelection(); } else if( found == FOUND_COVER_ARROW ) { g_mainFrame->GetEventHandler()->QueueEvent(new wxCommandEvent(wxEVT_COMMAND_MENU_SELECTED, IDT_WORKSPACE_SHOW_COVERS)); } else if( g_mainFrame->m_columnMixer.IsAnythingSelected() ) { g_mainFrame->m_columnMixer.SelectAll(false); RefreshSelection(); } }
void SjCoverBrowser::OnMouseLeftDown(wxMouseEvent& event) { /* prepare dragscroll and object dragging */ m_window->m_mouseAction = SJ_ACTION_NONE; m_dragStartX = event.GetX(); /* client coordinates */ m_dragStartY = event.GetY(); /* client coordinates */ /* perform selection */ m_mouseSelectionOnDown = FALSE; #ifdef USE_COVER_DND SjCol* cover; if( g_accelModule->m_selDragNDrop == 1 && (cover=FindCover(m_dragStartX, m_dragStartY))!=NULL /*&& !cover->IsAnyRowSelected() -- we preserve given selections but allow only one album selected by us*/ ) { OnMouseSelect(event); m_mouseSelectionOnDown = TRUE; } #endif }
wxString SjCoverBrowser::GetToolTipText(int mouseX, int mouseY, long &flags) { wxString retString; SjCol* cover; long found = FindCover(mouseX, mouseY, &cover); if( found == FOUND_COVER ) { if( cover != m_lastTooltipCover ) { for( int r = 0; r < cover->m_rowCount; r++ ) { SjRow* row = cover->m_rows[r]; if( row && (row->m_roughType == SJ_RRTYPE_TITLE1 || row->m_roughType == SJ_RRTYPE_TITLE2) ) { if( !retString.IsEmpty() ) retString += wxT("\n"); retString += row->m_textm; } } m_lastTooltipCover = cover; } } else { if( found == FOUND_COVER_ARROW ) { retString = _("Show cover titles"); } m_lastTooltipCover = NULL; } retString.Replace(wxT("\t"), wxT("")); // TAB is used for hiliting return retString; }
/* ** Called during each update of the main measure. ** */ void CPlayerWMP::UpdateData() { if (m_Initialized) { // Get the volume long volume; m_ISettings->get_volume(&volume); m_Volume = (UINT)volume; if (m_State != STATE_STOPPED) { double position; m_IControls->get_currentPosition(&position); m_Position = (UINT)position; } if (m_TrackChanged) { m_TrackChanged = false; CComPtr<IWMPMedia> spMedia; m_IPlayer->get_currentMedia(&spMedia); if (spMedia) { BSTR val; spMedia->getItemInfo(CComBSTR(L"Artist"), &val); m_Artist = val; spMedia->getItemInfo(CComBSTR(L"Title"), &val); m_Title = val; spMedia->getItemInfo(CComBSTR(L"Album"), &val); m_Album = val; spMedia->getItemInfo(CComBSTR(L"UserRating"), &val); int rating = _wtoi(val); if (rating > 75) { m_Rating = 5; } else if (rating > 50) { m_Rating = 4; } else if (rating > 25) { m_Rating = 3; } else if (rating > 1) { m_Rating = 2; } else { m_Rating = rating; } spMedia->getItemInfo(CComBSTR(L"WM/TrackNumber"), &val); m_Number = (UINT)_wtoi(val); spMedia->getItemInfo(CComBSTR(L"WM/Year"), &val); m_Year = (UINT)_wtoi(val); double duration; spMedia->get_duration(&duration); m_Duration = (UINT)duration; BSTR url; spMedia->get_sourceURL(&url); std::wstring targetPath = url; if (targetPath != m_FilePath) { ++m_TrackCount; m_FilePath = targetPath; // Find cover if needed // TODO: Fix temp solution if (m_Measures & MEASURE_COVER || m_InstanceCount == 0) { spMedia->getItemInfo(CComBSTR(L"WM/WMCollectionID"), &val); targetPath.resize(targetPath.find_last_of(L'\\') + 1); targetPath += L"AlbumArt_"; targetPath += val; targetPath += L"_Large.jpg"; if (_waccess(targetPath.c_str(), 0) == 0) { m_CoverPath = targetPath; } else { FindCover(); } } if (m_Measures & MEASURE_LYRICS) { FindLyrics(); } } } } } else { DWORD time = GetTickCount(); // Try to find WMP window every 5 seconds if (m_LastCheckTime = 0 || time - m_LastCheckTime > 5000) { m_LastCheckTime = time; if (FindWindow(L"WMPlayerApp", NULL)) { Initialize(); } } } }
void SjCoverBrowser::OnMouseMotion(wxMouseEvent& event) { if( !m_window->HasCapture() ) return; long hDifference, vDifference; long oldRowIndex, oldScrollY; long xPos = event.GetX(); /* client coordinates */ long yPos = event.GetY(); /* client coordinates */ // start dragscroll or object dragging? if( m_window->m_mouseAction == SJ_ACTION_NONE ) { hDifference = xPos - m_dragStartX; vDifference = yPos - m_dragStartY; if( hDifference > DRAGSCROLL_DELTA || hDifference < -DRAGSCROLL_DELTA || vDifference > DRAGSCROLL_DELTA || vDifference < -DRAGSCROLL_DELTA ) { #ifdef USE_COVER_DND SjCol* cover; if( g_accelModule->m_selDragNDrop && (cover=FindCover(m_dragStartX, m_dragStartY))!=NULL && cover->IsAnyRowSelected() ) { // do object dragging m_window->m_dragUrls.Clear(); g_mainFrame->m_columnMixer.GetSelectedUrls(m_window->m_dragUrls); if( g_accelModule->m_flags&SJ_ACCEL_USEDNDIMAGES ) { g_mainFrame->m_dragImage = m_window->GetCoverDragNDropBitmap(cover, g_mainFrame->m_dragRect); if( g_mainFrame->m_dragImage ) { g_mainFrame->m_dragHotspot.x = xPos - cover->m_textlLeft; g_mainFrame->m_dragHotspot.y = yPos - cover->m_top + m_scrollY; } } if( g_mainFrame->DragNDrop(SJ_DND_ENTER, m_window, event.GetPosition(), NULL, &m_window->m_dragUrls) ) { m_window->m_mouseAction = SJ_ACTION_DRAGNDROP; } } else #endif if( g_accelModule->m_flags&SJ_ACCEL_CONTENT_DRAG && m_applRowCount ) { // start dragscroll m_window->m_mouseAction = SJ_ACTION_DRAGSCROLL; m_dragscrollCurrY = yPos; } } } // in drag'n'drop? #ifdef USE_COVER_DND if( m_window->m_mouseAction == SJ_ACTION_DRAGNDROP ) { if( !g_mainFrame->DragNDrop(SJ_DND_MOVE, m_window, event.GetPosition(), NULL, &m_window->m_dragUrls) ) { m_window->m_mouseAction = SJ_ACTION_NONE; } } #endif // in dragscroll? if( m_window->m_mouseAction == SJ_ACTION_DRAGSCROLL ) { oldScrollY = m_scrollY; oldRowIndex = m_applRowIndex; // horizontal scrolling vDifference = yPos - m_dragscrollCurrY; m_dragscrollCurrY = yPos; if( vDifference ) { if( vDifference > m_coverNTitleHeight ) { vDifference = m_coverNTitleHeight; } else if( vDifference < 0 - m_coverNTitleHeight ) { vDifference = 0 - m_coverNTitleHeight; } m_scrollY -= vDifference; if( m_scrollY < 0 ) { // decrease application column position if possible if( m_applRowIndex > 0 ) { m_scrollY += m_coverNTitleHeight + SPACE_TOP; m_applRowIndex--; CalcPositions(); SetVScrollInfo(); } else { m_scrollY = 0; } } else if( m_scrollY >= m_coverNTitleHeight + SPACE_TOP ) { // increase application column position if possible if( m_applRowIndex < m_applRowCount-m_coversYCount ) { m_scrollY -= m_coverNTitleHeight + SPACE_TOP; m_applRowIndex++; CalcPositions(); SetVScrollInfo(); } else { m_scrollY = m_coverNTitleHeight + SPACE_TOP; } } else if( (m_allocatedCoverCount/m_coversXCount)*(m_coverNTitleHeight+SPACE_TOP)-m_scrollY < m_window->m_clientH ) { // a new column will fit on the right if( m_applRowIndex+m_coversYCount < m_applRowCount ) { CalcPositions(); } } } // update window if( vDifference ) { if( g_mainFrame->m_imgThread->HasWaitingImages() ) { // if there are waiting images, invalidate the whole rectangle as // some areas are no yet okay m_window->Refresh(); } else { vDifference = (oldRowIndex*(m_coverNTitleHeight+SPACE_TOP) + oldScrollY) - (m_applRowIndex*(m_coverNTitleHeight+SPACE_TOP) + m_scrollY); wxRect scrollRect = SCROLL_RECT; m_window->ScrollWindow(0, vDifference, &scrollRect); m_window->Update(); } } } }
//========================================================= // Start task - selects the correct activity and performs // any necessary calculations to start the next task on the // schedule. //========================================================= void CBaseMonster :: StartTask ( Task_t *pTask ) { switch ( pTask->iTask ) { case TASK_TURN_RIGHT: { float flCurrentYaw; flCurrentYaw = UTIL_AngleMod( pev->angles.y ); pev->ideal_yaw = UTIL_AngleMod( flCurrentYaw - pTask->flData ); SetTurnActivity(); break; } case TASK_TURN_LEFT: { float flCurrentYaw; flCurrentYaw = UTIL_AngleMod( pev->angles.y ); pev->ideal_yaw = UTIL_AngleMod( flCurrentYaw + pTask->flData ); SetTurnActivity(); break; } case TASK_REMEMBER: { Remember ( (int)pTask->flData ); TaskComplete(); break; } case TASK_FORGET: { Forget ( (int)pTask->flData ); TaskComplete(); break; } case TASK_FIND_HINTNODE: { m_iHintNode = FindHintNode(); if ( m_iHintNode != NO_NODE ) { TaskComplete(); } else { TaskFail(); } break; } case TASK_STORE_LASTPOSITION: { m_vecLastPosition = pev->origin; TaskComplete(); break; } case TASK_CLEAR_LASTPOSITION: { m_vecLastPosition = g_vecZero; TaskComplete(); break; } case TASK_CLEAR_HINTNODE: { m_iHintNode = NO_NODE; TaskComplete(); break; } case TASK_STOP_MOVING: { if ( m_IdealActivity == m_movementActivity ) { m_IdealActivity = GetStoppedActivity(); } RouteClear(); TaskComplete(); break; } case TASK_PLAY_SEQUENCE_FACE_ENEMY: case TASK_PLAY_SEQUENCE_FACE_TARGET: case TASK_PLAY_SEQUENCE: { m_IdealActivity = ( Activity )( int )pTask->flData; break; } case TASK_PLAY_ACTIVE_IDLE: { // monsters verify that they have a sequence for the node's activity BEFORE // moving towards the node, so it's ok to just set the activity without checking here. m_IdealActivity = ( Activity )WorldGraph.m_pNodes[ m_iHintNode ].m_sHintActivity; break; } case TASK_SET_SCHEDULE: { Schedule_t *pNewSchedule; pNewSchedule = GetScheduleOfType( (int)pTask->flData ); if ( pNewSchedule ) { ChangeSchedule( pNewSchedule ); } else { TaskFail(); } break; } case TASK_FIND_NEAR_NODE_COVER_FROM_ENEMY: { if ( m_hEnemy == NULL ) { TaskFail(); return; } if ( FindCover( m_hEnemy->pev->origin, m_hEnemy->pev->view_ofs, 0, pTask->flData ) ) { // try for cover farther than the FLData from the schedule. TaskComplete(); } else { // no coverwhatsoever. TaskFail(); } break; } case TASK_FIND_FAR_NODE_COVER_FROM_ENEMY: { if ( m_hEnemy == NULL ) { TaskFail(); return; } if ( FindCover( m_hEnemy->pev->origin, m_hEnemy->pev->view_ofs, pTask->flData, CoverRadius() ) ) { // try for cover farther than the FLData from the schedule. TaskComplete(); } else { // no coverwhatsoever. TaskFail(); } break; } case TASK_FIND_NODE_COVER_FROM_ENEMY: { if ( m_hEnemy == NULL ) { TaskFail(); return; } if ( FindCover( m_hEnemy->pev->origin, m_hEnemy->pev->view_ofs, 0, CoverRadius() ) ) { // try for cover farther than the FLData from the schedule. TaskComplete(); } else { // no coverwhatsoever. TaskFail(); } break; } case TASK_FIND_COVER_FROM_ENEMY: { entvars_t *pevCover; if ( m_hEnemy == NULL ) { // Find cover from self if no enemy available pevCover = pev; // TaskFail(); // return; } else pevCover = m_hEnemy->pev; if ( FindLateralCover( pevCover->origin, pevCover->view_ofs ) ) { // try lateral first m_flMoveWaitFinished = gpGlobals->time + pTask->flData; TaskComplete(); } else if ( FindCover( pevCover->origin, pevCover->view_ofs, 0, CoverRadius() ) ) { // then try for plain ole cover m_flMoveWaitFinished = gpGlobals->time + pTask->flData; TaskComplete(); } else { // no coverwhatsoever. TaskFail(); } break; } case TASK_FIND_COVER_FROM_ORIGIN: { if ( FindCover( pev->origin, pev->view_ofs, 0, CoverRadius() ) ) { // then try for plain ole cover m_flMoveWaitFinished = gpGlobals->time + pTask->flData; TaskComplete(); } else { // no cover! TaskFail(); } } break; case TASK_FIND_COVER_FROM_BEST_SOUND: { CSound *pBestSound; pBestSound = PBestSound(); ASSERT( pBestSound != NULL ); /* if ( pBestSound && FindLateralCover( pBestSound->m_vecOrigin, g_vecZero ) ) { // try lateral first m_flMoveWaitFinished = gpGlobals->time + pTask->flData; TaskComplete(); } */ if ( pBestSound && FindCover( pBestSound->m_vecOrigin, g_vecZero, pBestSound->m_iVolume, CoverRadius() ) ) { // then try for plain ole cover m_flMoveWaitFinished = gpGlobals->time + pTask->flData; TaskComplete(); } else { // no coverwhatsoever. or no sound in list TaskFail(); } break; } case TASK_FACE_HINTNODE: { pev->ideal_yaw = WorldGraph.m_pNodes[ m_iHintNode ].m_flHintYaw; SetTurnActivity(); break; } case TASK_FACE_LASTPOSITION: MakeIdealYaw ( m_vecLastPosition ); SetTurnActivity(); break; case TASK_FACE_TARGET: if ( m_hTargetEnt != NULL ) { MakeIdealYaw ( m_hTargetEnt->pev->origin ); SetTurnActivity(); } else TaskFail(); break; case TASK_FACE_ENEMY: { MakeIdealYaw ( m_vecEnemyLKP ); SetTurnActivity(); break; } case TASK_FACE_IDEAL: { SetTurnActivity(); break; } case TASK_FACE_ROUTE: { if (FRouteClear()) { ALERT(at_aiconsole, "No route to face!\n"); TaskFail(); } else { MakeIdealYaw(m_Route[m_iRouteIndex].vecLocation); SetTurnActivity(); } break; } case TASK_WAIT_PVS: case TASK_WAIT_INDEFINITE: { // don't do anything. break; } case TASK_WAIT: case TASK_WAIT_FACE_ENEMY: {// set a future time that tells us when the wait is over. m_flWaitFinished = gpGlobals->time + pTask->flData; break; } case TASK_WAIT_RANDOM: {// set a future time that tells us when the wait is over. m_flWaitFinished = gpGlobals->time + RANDOM_FLOAT( 0.1, pTask->flData ); break; } case TASK_MOVE_TO_TARGET_RANGE: { if ( (m_hTargetEnt->pev->origin - pev->origin).Length() < 1 ) TaskComplete(); else { m_vecMoveGoal = m_hTargetEnt->pev->origin; if ( !MoveToTarget( ACT_WALK, 2 ) ) TaskFail(); } break; } case TASK_RUN_TO_SCRIPT: case TASK_WALK_TO_SCRIPT: { Activity newActivity; if ( !m_pGoalEnt || (m_pGoalEnt->pev->origin - pev->origin).Length() < 1 ) TaskComplete(); else { if ( pTask->iTask == TASK_WALK_TO_SCRIPT ) newActivity = ACT_WALK; else newActivity = ACT_RUN; // This monster can't do this! if ( LookupActivity( newActivity ) == ACTIVITY_NOT_AVAILABLE ) TaskComplete(); else { if ( m_pGoalEnt != NULL ) { Vector vecDest; vecDest = m_pGoalEnt->pev->origin; if ( !MoveToLocation( newActivity, 2, vecDest ) ) { TaskFail(); ALERT( at_aiconsole, "%s Failed to reach script!!!\n", STRING(pev->classname) ); RouteClear(); } } else { TaskFail(); ALERT( at_aiconsole, "%s: MoveTarget is missing!?!\n", STRING(pev->classname) ); RouteClear(); } } } TaskComplete(); break; } case TASK_CLEAR_MOVE_WAIT: { m_flMoveWaitFinished = gpGlobals->time; TaskComplete(); break; } case TASK_MELEE_ATTACK1_NOTURN: case TASK_MELEE_ATTACK1: { m_IdealActivity = ACT_MELEE_ATTACK1; break; } case TASK_MELEE_ATTACK2_NOTURN: case TASK_MELEE_ATTACK2: { m_IdealActivity = ACT_MELEE_ATTACK2; break; } case TASK_RANGE_ATTACK1_NOTURN: case TASK_RANGE_ATTACK1: { m_IdealActivity = ACT_RANGE_ATTACK1; break; } case TASK_RANGE_ATTACK2_NOTURN: case TASK_RANGE_ATTACK2: { m_IdealActivity = ACT_RANGE_ATTACK2; break; } case TASK_RELOAD_NOTURN: case TASK_RELOAD: { m_IdealActivity = ACT_RELOAD; break; } case TASK_SPECIAL_ATTACK1: { m_IdealActivity = ACT_SPECIAL_ATTACK1; break; } case TASK_SPECIAL_ATTACK2: { m_IdealActivity = ACT_SPECIAL_ATTACK2; break; } case TASK_SET_ACTIVITY: { m_IdealActivity = (Activity)(int)pTask->flData; TaskComplete(); break; } case TASK_GET_PATH_TO_ENEMY_LKP: { if ( BuildRoute ( m_vecEnemyLKP, bits_MF_TO_LOCATION, NULL ) ) { TaskComplete(); } else if (BuildNearestRoute( m_vecEnemyLKP, pev->view_ofs, 0, (m_vecEnemyLKP - pev->origin).Length() )) { TaskComplete(); } else { // no way to get there =( ALERT ( at_aiconsole, "GetPathToEnemyLKP failed!!\n" ); TaskFail(); } break; } case TASK_GET_PATH_TO_ENEMY: { CBaseEntity *pEnemy = m_hEnemy; if ( pEnemy == NULL ) { TaskFail(); return; } if ( BuildRoute ( pEnemy->pev->origin, bits_MF_TO_ENEMY, pEnemy ) ) { TaskComplete(); } else if (BuildNearestRoute( pEnemy->pev->origin, pEnemy->pev->view_ofs, 0, (pEnemy->pev->origin - pev->origin).Length() )) { TaskComplete(); } else { // no way to get there =( ALERT ( at_aiconsole, "GetPathToEnemy failed!!\n" ); TaskFail(); } break; } case TASK_GET_PATH_TO_ENEMY_CORPSE: { UTIL_MakeVectors( pev->angles ); if ( BuildRoute ( m_vecEnemyLKP - gpGlobals->v_forward * 64, bits_MF_TO_LOCATION, NULL ) ) { TaskComplete(); } else { ALERT ( at_aiconsole, "GetPathToEnemyCorpse failed!!\n" ); TaskFail(); } } break; case TASK_GET_PATH_TO_SPOT: { CBaseEntity *pPlayer = UTIL_FindEntityByClassname( NULL, "player" ); if ( BuildRoute ( m_vecMoveGoal, bits_MF_TO_LOCATION, pPlayer ) ) { TaskComplete(); } else { // no way to get there =( ALERT ( at_aiconsole, "GetPathToSpot failed!!\n" ); TaskFail(); } break; } case TASK_GET_PATH_TO_TARGET: { RouteClear(); if ( m_hTargetEnt != NULL && MoveToTarget( m_movementActivity, 1 ) ) { TaskComplete(); } else { // no way to get there =( ALERT ( at_aiconsole, "GetPathToSpot failed!!\n" ); TaskFail(); } break; } case TASK_GET_PATH_TO_SCRIPT: { RouteClear(); if ( m_pCine != NULL && MoveToLocation( m_movementActivity, 1, m_pCine->pev->origin ) ) { TaskComplete(); } else { // no way to get there =( ALERT ( at_aiconsole, "GetPathToSpot failed!!\n" ); TaskFail(); } break; } case TASK_GET_PATH_TO_HINTNODE:// for active idles! { if ( MoveToLocation( m_movementActivity, 2, WorldGraph.m_pNodes[ m_iHintNode ].m_vecOrigin ) ) { TaskComplete(); } else { // no way to get there =( ALERT ( at_aiconsole, "GetPathToHintNode failed!!\n" ); TaskFail(); } break; } case TASK_GET_PATH_TO_LASTPOSITION: { m_vecMoveGoal = m_vecLastPosition; if ( MoveToLocation( m_movementActivity, 2, m_vecMoveGoal ) ) { TaskComplete(); } else { // no way to get there =( ALERT ( at_aiconsole, "GetPathToLastPosition failed!!\n" ); TaskFail(); } break; } case TASK_GET_PATH_TO_BESTSOUND: { CSound *pSound; pSound = PBestSound(); if ( pSound && MoveToLocation( m_movementActivity, 2, pSound->m_vecOrigin ) ) { TaskComplete(); } else { // no way to get there =( ALERT ( at_aiconsole, "GetPathToBestSound failed!!\n" ); TaskFail(); } break; } case TASK_GET_PATH_TO_BESTSCENT: { CSound *pScent; pScent = PBestScent(); if ( pScent && MoveToLocation( m_movementActivity, 2, pScent->m_vecOrigin ) ) { TaskComplete(); } else { // no way to get there =( ALERT ( at_aiconsole, "GetPathToBestScent failed!!\n" ); TaskFail(); } break; } case TASK_RUN_PATH: { // UNDONE: This is in some default AI and some monsters can't run? -- walk instead? if ( LookupActivity( ACT_RUN ) != ACTIVITY_NOT_AVAILABLE ) { m_movementActivity = ACT_RUN; } else { m_movementActivity = ACT_WALK; } TaskComplete(); break; } case TASK_WALK_PATH: { if ( pev->movetype == MOVETYPE_FLY ) { m_movementActivity = ACT_FLY; } if ( LookupActivity( ACT_WALK ) != ACTIVITY_NOT_AVAILABLE ) { m_movementActivity = ACT_WALK; } else { m_movementActivity = ACT_RUN; } TaskComplete(); break; } case TASK_STRAFE_PATH: { Vector2D vec2DirToPoint; Vector2D vec2RightSide; // to start strafing, we have to first figure out if the target is on the left side or right side UTIL_MakeVectors ( pev->angles ); vec2DirToPoint = ( m_Route[ 0 ].vecLocation - pev->origin ).Make2D().Normalize(); vec2RightSide = gpGlobals->v_right.Make2D().Normalize(); if ( DotProduct ( vec2DirToPoint, vec2RightSide ) > 0 ) { // strafe right m_movementActivity = ACT_STRAFE_RIGHT; } else { // strafe left m_movementActivity = ACT_STRAFE_LEFT; } TaskComplete(); break; } case TASK_WAIT_FOR_MOVEMENT: { if (FRouteClear()) { TaskComplete(); } break; } case TASK_EAT: { Eat( pTask->flData ); TaskComplete(); break; } case TASK_SMALL_FLINCH: { m_IdealActivity = GetSmallFlinchActivity(); break; } case TASK_DIE: { RouteClear(); m_IdealActivity = GetDeathActivity(); pev->deadflag = DEAD_DYING; break; } case TASK_SOUND_WAKE: { AlertSound(); TaskComplete(); break; } case TASK_SOUND_DIE: { DeathSound(); TaskComplete(); break; } case TASK_SOUND_IDLE: { IdleSound(); TaskComplete(); break; } case TASK_SOUND_PAIN: { PainSound(); TaskComplete(); break; } case TASK_SOUND_DEATH: { DeathSound(); TaskComplete(); break; } case TASK_SOUND_ANGRY: { // sounds are complete as soon as we get here, cause we've already played them. ALERT ( at_aiconsole, "SOUND\n" ); TaskComplete(); break; } case TASK_WAIT_FOR_SCRIPT: { if ( m_pCine->m_iDelay <= 0 && gpGlobals->time >= m_pCine->m_startTime ) { TaskComplete(); //LRC - start playing immediately } else if (!m_pCine->IsAction() && m_pCine->m_iszIdle) { m_pCine->StartSequence( (CBaseMonster *)this, m_pCine->m_iszIdle, FALSE ); if (FStrEq( STRING(m_pCine->m_iszIdle), STRING(m_pCine->m_iszPlay))) { pev->framerate = 0; } } else m_IdealActivity = ACT_IDLE; break; } case TASK_PLAY_SCRIPT: { if (m_pCine->IsAction()) { //ALERT(at_console,"PlayScript: setting idealactivity %d\n",m_pCine->m_fAction); switch(m_pCine->m_fAction) { case 0: m_IdealActivity = ACT_RANGE_ATTACK1; break; case 1: m_IdealActivity = ACT_RANGE_ATTACK2; break; case 2: m_IdealActivity = ACT_MELEE_ATTACK1; break; case 3: m_IdealActivity = ACT_MELEE_ATTACK2; break; case 4: m_IdealActivity = ACT_SPECIAL_ATTACK1; break; case 5: m_IdealActivity = ACT_SPECIAL_ATTACK2; break; case 6: m_IdealActivity = ACT_RELOAD; break; case 7: m_IdealActivity = ACT_HOP; break; } pev->framerate = 1.0; // shouldn't be needed, but just in case pev->movetype = MOVETYPE_FLY; ClearBits(pev->flags, FL_ONGROUND); } else { m_pCine->StartSequence( (CBaseMonster *)this, m_pCine->m_iszPlay, TRUE ); if ( m_fSequenceFinished ) ClearSchedule(); pev->framerate = 1.0; //ALERT( at_aiconsole, "Script %s has begun for %s\n", STRING( m_pCine->m_iszPlay ), STRING(pev->classname) ); } m_scriptState = SCRIPT_PLAYING; break; } case TASK_ENABLE_SCRIPT: { m_pCine->DelayStart( 0 ); TaskComplete(); break; } //LRC case TASK_END_SCRIPT: { m_pCine->SequenceDone( this ); TaskComplete(); break; } case TASK_PLANT_ON_SCRIPT: { if ( m_pCine != NULL ) { // Plant on script // LRC - if it's a teleport script, do the turn too if (m_pCine->m_fMoveTo == 4 || m_pCine->m_fMoveTo == 6) { if (m_pCine->m_fTurnType == 0) //LRC pev->angles.y = m_hTargetEnt->pev->angles.y; else if (m_pCine->m_fTurnType == 1) pev->angles.y = UTIL_VecToYaw(m_hTargetEnt->pev->origin - pev->origin); pev->ideal_yaw = pev->angles.y; pev->avelocity = Vector( 0, 0, 0 ); pev->velocity = Vector( 0, 0, 0 ); pev->effects |= EF_NOINTERP; } if (m_pCine->m_fMoveTo != 6) pev->origin = m_pGoalEnt->pev->origin; } TaskComplete(); break; } case TASK_FACE_SCRIPT: { if ( m_pCine != NULL && m_pCine->m_fMoveTo != 0) // movetype "no move" makes us ignore turntype { switch (m_pCine->m_fTurnType) { case 0: pev->ideal_yaw = UTIL_AngleMod( m_pCine->pev->angles.y ); break; case 1: // yes, this is inconsistent- turn to face uses the "target" and turn to angle uses the "cine". if (m_hTargetEnt) MakeIdealYaw ( m_hTargetEnt->pev->origin ); else MakeIdealYaw ( m_pCine->pev->origin ); break; // default: don't turn } } TaskComplete(); m_IdealActivity = ACT_IDLE; RouteClear(); break; } case TASK_SUGGEST_STATE: { m_IdealMonsterState = (MONSTERSTATE)(int)pTask->flData; TaskComplete(); break; } case TASK_SET_FAIL_SCHEDULE: m_failSchedule = (int)pTask->flData; TaskComplete(); break; case TASK_CLEAR_FAIL_SCHEDULE: m_failSchedule = SCHED_NONE; TaskComplete(); break; default: { ALERT ( at_aiconsole, "No StartTask entry for %d\n", (SHARED_TASKS)pTask->iTask ); break; } } }
//========================================================= // StartTask //========================================================= void CLuciole :: StartTask ( Task_t *pTask ) { switch ( pTask->iTask ) { case TASK_RANGE_ATTACK1: CBaseMonster :: StartTask ( pTask ); break; case TASK_GET_PATH_TO_ENEMY_LKP: { if (BuildNearestRoute( m_vecEnemyLKP, pev->view_ofs, pTask->flData, (m_vecEnemyLKP - pev->origin).Length() + 1024 )) { TaskComplete(); } else { // no way to get there =( ALERT ( at_aiconsole, "GetPathToEnemyLKP failed!!\n" ); TaskFail(); } break; } case TASK_GET_PATH_TO_ENEMY: { CBaseEntity *pEnemy = m_hEnemy; if ( pEnemy == NULL ) { TaskFail(); return; } if (BuildNearestRoute( pEnemy->pev->origin, pEnemy->pev->view_ofs, pTask->flData, (pEnemy->pev->origin - pev->origin).Length() + 1024 )) { TaskComplete(); } else { // no way to get there =( ALERT ( at_aiconsole, "GetPathToEnemy failed!!\n" ); TaskFail(); } break; } // modif de julien case TASK_FLYBEE_WAIT_FOR_MOVEMENT: { if (FRouteClear()) { TaskComplete(); } break; } // trouve son chemin vers le joueur case TASK_LUCIOLE_GET_PATH: break; case TASK_FIND_COVER_FROM_ENEMY: { entvars_t *pevCover; if ( m_hEnemy == NULL ) { // Find cover from self if no enemy available pevCover = pev; } else pevCover = m_hEnemy->pev; if ( FindLateralCover( pevCover->origin, pevCover->view_ofs ) ) { // try lateral first m_flMoveWaitFinished = gpGlobals->time + pTask->flData; TaskComplete(); } else if ( FindCover( pevCover->origin, pevCover->view_ofs, 0, CoverRadius() ) ) { // then try for plain ole cover m_flMoveWaitFinished = gpGlobals->time + pTask->flData; TaskComplete(); } // passe de l'autre coté du joueur else if (BuildNearestRoute( pev->origin + (pevCover->origin-pev->origin).Normalize() * 128, pev->view_ofs, 0, 4096) ) { TaskComplete(); } else { // no coverwhatsoever. TaskFail(); } break; } default: CBaseMonster :: StartTask ( pTask ); break; } }
void CTalkMonster :: StartTask( const Task_t& task ) { switch ( task.iTask ) { case TASK_TLK_SPEAK: // ask question or make statement FIdleSpeak(); TaskComplete(); break; case TASK_TLK_RESPOND: // respond to question IdleRespond(); TaskComplete(); break; case TASK_TLK_HELLO: // greet player FIdleHello(); TaskComplete(); break; case TASK_TLK_STARE: // let the player know I know he's staring at me. FIdleStare(); TaskComplete(); break; case TASK_FACE_PLAYER: case TASK_TLK_LOOK_AT_CLIENT: case TASK_TLK_CLIENT_STARE: // track head to the client for a while. m_flWaitFinished = gpGlobals->time + task.flData; break; case TASK_TLK_EYECONTACT: break; case TASK_TLK_IDEALYAW: if (m_hTalkTarget != NULL) { SetYawSpeed( 60 ); float yaw = VecToYaw(m_hTalkTarget->GetAbsOrigin() - GetAbsOrigin()) - GetAbsAngles().y; if (yaw > 180) yaw -= 360; if (yaw < -180) yaw += 360; if (yaw < 0) { SetIdealYaw( min( yaw + 45, 0.0f ) + GetAbsAngles().y ); } else { SetIdealYaw( max( yaw - 45, 0.0f ) + GetAbsAngles().y ); } } TaskComplete(); break; case TASK_TLK_HEADRESET: // reset head position after looking at something m_hTalkTarget = NULL; TaskComplete(); break; case TASK_TLK_STOPSHOOTING: // tell player to stop shooting PlaySentence( m_szGrp[TLK_NOSHOOT], RANDOM_FLOAT(2.8, 3.2), VOL_NORM, ATTN_NORM ); TaskComplete(); break; case TASK_CANT_FOLLOW: StopFollowing( false ); PlaySentence( m_szGrp[TLK_STOP], RANDOM_FLOAT(2, 2.5), VOL_NORM, ATTN_NORM ); TaskComplete(); break; case TASK_WALK_PATH_FOR_UNITS: m_movementActivity = ACT_WALK; break; case TASK_MOVE_AWAY_PATH: { Vector dir = GetAbsAngles(); dir.y = GetIdealYaw() + 180; Vector move; UTIL_MakeVectorsPrivate( dir, &move, nullptr, nullptr ); dir = GetAbsOrigin() + move * task.flData; if ( MoveToLocation( ACT_WALK, 2, dir ) ) { TaskComplete(); } else if ( FindCover( GetAbsOrigin(), GetViewOffset(), 0, CoverRadius() ) ) { // then try for plain ole cover m_flMoveWaitFinished = gpGlobals->time + 2; TaskComplete(); } else { // nowhere to go? TaskFail(); } } break; case TASK_PLAY_SCRIPT: m_hTalkTarget = NULL; CBaseMonster::StartTask( task ); break; default: CBaseMonster::StartTask( task ); } }
void CMTalkMonster :: StartTask( Task_t *pTask ) { switch ( pTask->iTask ) { case TASK_TLK_SPEAK: // ask question or make statement FIdleSpeak(); TaskComplete(); break; case TASK_TLK_RESPOND: // respond to question IdleRespond(); TaskComplete(); break; case TASK_TLK_HELLO: // greet player FIdleHello(); TaskComplete(); break; case TASK_TLK_STARE: // let the player know I know he's staring at me. FIdleStare(); TaskComplete(); break; case TASK_FACE_PLAYER: case TASK_TLK_LOOK_AT_CLIENT: case TASK_TLK_CLIENT_STARE: // track head to the client for a while. m_flWaitFinished = gpGlobals->time + pTask->flData; break; case TASK_TLK_EYECONTACT: break; case TASK_TLK_IDEALYAW: if (m_hTalkTarget != NULL) { pev->yaw_speed = 60; float yaw = VecToYaw(m_hTalkTarget->v.origin - pev->origin) - pev->angles.y; if (yaw > 180) yaw -= 360; if (yaw < -180) yaw += 360; if (yaw < 0) { pev->ideal_yaw = min( yaw + 45.0f, 0.0f ) + pev->angles.y; } else { pev->ideal_yaw = max( yaw - 45.0f, 0.0f ) + pev->angles.y; } } TaskComplete(); break; case TASK_TLK_HEADRESET: // reset head position after looking at something m_hTalkTarget = NULL; TaskComplete(); break; case TASK_TLK_STOPSHOOTING: // tell player to stop shooting PlaySentence( m_szGrp[TLK_NOSHOOT], RANDOM_FLOAT(2.8, 3.2), VOL_NORM, ATTN_NORM ); TaskComplete(); break; case TASK_CANT_FOLLOW: StopFollowing( FALSE ); PlaySentence( m_szGrp[TLK_STOP], RANDOM_FLOAT(2, 2.5), VOL_NORM, ATTN_NORM ); TaskComplete(); break; case TASK_WALK_PATH_FOR_UNITS: m_movementActivity = ACT_WALK; break; case TASK_MOVE_AWAY_PATH: { Vector dir = pev->angles; dir.y = pev->ideal_yaw + 180; Vector move; UTIL_MakeVectorsPrivate( dir, move, NULL, NULL ); dir = pev->origin + move * pTask->flData; if ( MoveToLocation( ACT_WALK, 2, dir ) ) { TaskComplete(); } else if ( FindCover( pev->origin, pev->view_ofs, 0, CoverRadius() ) ) { // then try for plain ole cover m_flMoveWaitFinished = gpGlobals->time + 2; TaskComplete(); } else { // nowhere to go? TaskFail(); } } break; case TASK_PLAY_SCRIPT: m_hTalkTarget = NULL; CMBaseMonster::StartTask( pTask ); break; default: CMBaseMonster::StartTask( pTask ); } }
/* ** Called during each update of the main measure. ** */ void CPlayerAIMP::UpdateData() { if (!m_Initialized) { if (m_LastTitleSize != 0) { m_LastFileSize = 0; m_LastTitleSize = 0; } if (!CheckWindow()) return; } // If initialized m_State = (StateType)SendMessage(m_Window, WM_AIMP_COMMAND, WM_AIMP_STATUS_GET, AIMP_STS_Player); if (m_State == STATE_STOPPED) { // Make sure AIMP is still active if (!IsWindow(m_Window)) { m_Initialized = false; ClearData(); if (m_FileMap) UnmapViewOfFile(m_FileMap); if (m_FileMapHandle) CloseHandle(m_FileMapHandle); } else if (m_State != STATE_STOPPED) { ClearData(false); m_LastFileSize = 0; m_LastTitleSize = 0; } // Don't continue if AIMP has quit or is stopped return; } m_Position = SendMessage(m_Window, WM_AIMP_COMMAND, WM_AIMP_STATUS_GET, AIMP_STS_POS); m_Volume = SendMessage(m_Window, WM_AIMP_COMMAND, WM_AIMP_STATUS_GET, AIMP_STS_VOLUME); AIMP2FileInfo* info = (AIMP2FileInfo*)m_FileMap; if (info->cbSizeOf > 0 && info->nFileSize != m_LastFileSize || // Avoid reading the same file info->nTitleLen != m_LastTitleSize) { m_LastFileSize = info->nFileSize; m_LastTitleSize = info->nTitleLen; // 44 is sizeof(AIMP2FileInfo) / 2 (due to WCHAR being 16-bit). // Written explicitly due to size differences in 32bit/64bit. LPCTSTR stringData = (LPCTSTR)m_FileMap; stringData += 44; m_Album.assign(stringData, info->nAlbumLen); stringData += info->nAlbumLen; m_Artist.assign(stringData, info->nArtistLen); stringData += info->nArtistLen; stringData += info->nDateLen; std::wstring filepath(stringData, info->nFileNameLen); stringData += info->nFileNameLen; stringData += info->nGenreLen; m_Title.assign(stringData, info->nTitleLen); m_Duration = info->nDuration / 1000; m_Number = (UINT)info->nTrackID; m_Shuffle = (bool)SendMessage(m_Window, WM_AIMP_COMMAND, WM_AIMP_STATUS_GET, AIMP_STS_SHUFFLE); m_Repeat = (bool)SendMessage(m_Window, WM_AIMP_COMMAND, WM_AIMP_STATUS_GET, AIMP_STS_REPEAT); // Get rating through the AIMP Winamp API m_Rating = SendMessage(m_WinampWindow, WM_WA_IPC, 0, IPC_GETRATING); if (filepath != m_FilePath) { m_FilePath = filepath; ++m_TrackCount; if (m_Measures & MEASURE_COVER) FindCover(); if (m_Measures & MEASURE_LYRICS) FindLyrics(); } } }