/* static */ bool AIRail::RemoveRailTrack(TileIndex tile, RailTrack rail_track) { EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, ::IsPlainRailTile(tile) || ::IsLevelCrossingTile(tile)); EnforcePrecondition(false, GetRailTracks(tile) & rail_track); EnforcePrecondition(false, KillFirstBit((uint)rail_track) == 0); return AIObject::DoCommand(tile, tile, GetCurrentRailType() | (FindFirstTrack((::TrackBits)rail_track) << 4), CMD_REMOVE_RAILROAD_TRACK); }
/* static */ bool AIRail::BuildRailTrack(TileIndex tile, RailTrack rail_track) { EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, rail_track != 0); EnforcePrecondition(false, (rail_track & ~::TRACK_BIT_ALL) == 0); EnforcePrecondition(false, KillFirstBit((uint)rail_track) == 0); EnforcePrecondition(false, IsRailTypeAvailable(GetCurrentRailType())); return AIObject::DoCommand(tile, tile, GetCurrentRailType() | (FindFirstTrack((::TrackBits)rail_track) << 4), CMD_BUILD_RAILROAD_TRACK); }
Trackdir Ship::GetVehicleTrackdir() const { if (this->vehstatus & VS_CRASHED) return INVALID_TRACKDIR; if (this->IsInDepot()) { /* We'll assume the ship is facing outwards */ return DiagDirToDiagTrackdir(GetShipDepotDirection(this->tile)); } if (this->state == TRACK_BIT_WORMHOLE) { /* ship on aqueduct, so just use his direction and assume a diagonal track */ return DiagDirToDiagTrackdir(DirToDiagDir(this->direction)); } return TrackDirectionToTrackdir(FindFirstTrack(this->state), this->direction); }
BOOL FAR PASCAL ControlWndProc( IN HWND hwnd, IN DWORD message, IN DWORD wParam, IN LONG lParam ) /*++ Routine Description: This routine handles messages from the child windows for this routine. Arguments: hwnd - supplies a handle to the window to draw into message - supplies the window message to the window pointed to be "hwnd" wParam - supplies the word parameter for the message in "message" lParam - supplies the long parameter for the message in "message" Return Value: Whatever our call to DefWindowProc returns for this window. --*/ { HDC hdc; PAINTSTRUCT ps; RECT r; LPDRAWITEMSTRUCT lpdis; UINT ButtonId; INT i; HWND hwndCntl; UINT WorkState; BOOL bPlaying,bPaused; PTRACK_PLAY tr; switch( message ) { case WM_CREATE: // // Load in the bitmap with the appropriate buttons. // hbmCtrlBtns = LoadBitmap((HANDLE) gInstance, "ControlBtns"); break; case WM_DRAWITEM: // // Take care of drawing the appropriate button. // lpdis = (LPDRAWITEMSTRUCT) lParam; // // Find the control which needs to be drawn. This should be the // ButtonId = LOWORD(wParam); for (i = 0; i < gNumControls; i++) { if ((cChild[i].ParentId == ID_CHILD_CONTROL)&&(cChild[i].id == ButtonId)) { break; } } // // If it's not one of the controls we draw, break. // if (i == gNumControls) { break; } // // All of our child controls are user-drawn buttons currently, so // call our routine to draw an ownerdrawn button. // DrawOdButton(lpdis,hbmCtrlBtns,&cChild[i]); break; case WM_COMMAND: // // Need to detect button presses, etc. // if ((HIWORD(wParam) == BN_CLICKED)||(HIWORD(wParam) == BN_DOUBLECLICKED)) { ButtonId = LOWORD(wParam); hwndCntl = (HWND) lParam; for (i = 0; i < gNumControls; i++) { if ((cChild[i].ParentId == ID_CHILD_CONTROL)&&(cChild[i].id==ButtonId)) { break; } } // // Don't process button clicks for disabled buttons. // if (cChild[i].state & STATE_DISABLED) { break; } switch (ButtonId) { case IDB_SCAN_FORWARD: //TimeAdjustIncSecond( gCurrCdrom ); break; case IDB_SCAN_REVERSE: //TimeAdjustDecSecond( gCurrCdrom ); break; case IDB_TRACK_FORWARD: case IDB_TRACK_REVERSE: if (ButtonId == IDB_TRACK_FORWARD) { WorkState = SKIP_F; } else { WorkState = SKIP_B; } // // skip to track button pressed and is legal // gState |= WorkState; // // If we are currently playing, stop play thread // temporarily until we are at the next track // if (gState & PLAYING) ResetEvent( hPlayEv ); // // Initiate request to skip to next track // PostDisplayMessage((WorkState == SKIP_F)?MESS_SKIP_F:MESS_SKIP_B); // // Let play thread continue execution // if (gState & PLAYING) SetEvent( hPlayEv ); gState &= (~WorkState); break; case IDB_EJECT: // // User pressed EJECT button // if (gState & PAUSED) { gState &= (~(PAUSED_AND_MOVED|PAUSED)); ResetEvent(hPauseEv); } if (gState & PLAYING) { // // Reset button // SetOdCntl(ghwndPlay, 'U', TRUE); // // Mark not playing // gState &= ~PLAYING; gState |= STOPPED; } if (EjectTheCdromDisc(gCurrCdrom)) { // // Need to reset this drive to generic // disc... // gState = (NO_CD | STOPPED); TimeAdjustInitialize( gCurrCdrom ); } break; case IDB_PLAY: if (gState & CD_LOADED) { SetOdCntl(ghwndPlay, 'D', TRUE); SetEvent( hPlayEv ); gState |= PLAY_PENDING; if (gState & PAUSED) { if (gState & PAUSED_AND_MOVED) { gState &= (~PAUSED_AND_MOVED); gState |= PLAYING; if (SeekToCurrSecond( gCurrCdrom )) { SetOdCntl(ghwndPause, 'U', TRUE); gState &= (~PAUSED); gState |= PLAYING; ResetEvent( hPauseEv ); } else gState &= (~PLAYING); } else { if (ResumeTheCdromDrive(gCurrCdrom)) { SetOdCntl(ghwndPause, 'U', TRUE); gState &= (~PAUSED); gState |= PLAYING; ResetEvent( hPauseEv ); } } } else { if (gState & STOPPED) { if (PlayCurrTrack(gCurrCdrom)) { gState &= (~STOPPED); gState |= PLAYING; } else { ResetEvent( hPlayEv ); } } } if (!(gState & PLAYING)) { SetOdCntl(ghwndPlay,'U',TRUE); } } break; case IDB_STOP: bPlaying = gState & PLAYING; bPaused = gState & PAUSED; gState &= ~PLAY_PENDING; if ((bPlaying || bPaused)&&StopTheCdromDrive(gCurrCdrom)) { SetOdCntl(bPlaying ? ghwndPlay : ghwndPause, 'U', TRUE); gState &= (~(bPlaying ? PLAYING : PAUSED)); gState |= STOPPED; // // Stop Play Mechanism // ResetEvent( bPlaying ? hPlayEv : hPauseEv ); FlushDisplayMessageQueue(); // // Stop the current play operation and seek to first // playable track // CURRTRACK( gCurrCdrom ) = FindFirstTrack( gCurrCdrom ); tr = CURRTRACK( gCurrCdrom ); TimeAdjustSkipToTrack( gCurrCdrom, tr ); UpdateDisplay( DISPLAY_UPD_LED | DISPLAY_UPD_TRACK_TIME | DISPLAY_UPD_TRACK_NAME ); } break; case IDB_PAUSE: gState &= ~PLAY_PENDING; if (gState & PLAYING) { SetEvent( hPauseEv ); ResetEvent( hPlayEv ); if (PauseTheCdromDrive(gCurrCdrom)) { SetOdCntl(ghwndPlay, 'U', TRUE); SetOdCntl(ghwndPause, 'D', TRUE); gState &= (~PLAYING); gState |= PAUSED; } else { SetEvent( hPlayEv ); } } else { if (gState & PAUSED) { // // fake press on play button // PostMessage( ghwndPlay, WM_LBUTTONDOWN, 1, 0 ); PostMessage( ghwndPlay, WM_LBUTTONUP, 1, 0 ); } } break; } } break; case WM_PAINT: hdc = BeginPaint( hwnd, &ps ); GetClientRect( hwnd, &r ); // // Draw line across top // SelectObject( hdc, (HGDIOBJ)hpWhite ); MoveToEx( hdc, r.left, r.top, NULL ); LineTo( hdc, r.right, r.top ); EndPaint( hwnd, (CONST PAINTSTRUCT *)&ps ); return( 0 ); break; case WM_DESTROY: // // Unload the bitmap for the buttons. // DeleteObject(hbmCtrlBtns); break; } return( DefWindowProc( hwnd, message, wParam, lParam ) ); }