📄 cbmain.cpp
字号:
int xPos = LOWORD(lParam);
int yPos = HIWORD(lParam);
if( FACE_GetCommandState() == COMMAND_STATE_PLAY )
{ // 一定在客户区以内
if( DRAW_rcClient.left < xPos &&
DRAW_rcClient.top < yPos &&
DRAW_rcClient.right >= xPos &&
DRAW_rcClient.bottom >= yPos )
{
CTRL_TASK_AssembleCmdDest( xPos, yPos );
}
else
{ // 鼠标右键点击缩略图,移动到该地点
POINT pt = MOUSE_InMiniMap( xPos, yPos );
if( pt.x != -1 )
CTRL_TASK_AssembleCmdDest( (pt.x*MAP_Lib.szItem.cx)-DRAW_ptScreenOffset.x,
(pt.y*MAP_Lib.szItem.cy>>1)-DRAW_ptScreenOffset.y );
}
}
// to cancel the current menu if the current menu if select_general
else if( FACE_GetCommandState() != COMMAND_STATE_NONE )
{
FACE_RightButtonDown(fwKeys, xPos, yPos) ;
}
}
break;
case WM_DESTROY:
DATA_WAVE_MusicClose();
DS_QuitSound();
DD_QuitGraph();
HZ_CloseLib();
PostQuitMessage(1);
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
} /* WindowProc */
/*
* doInit - do work required for every instance of the application:
* create the window, initialize data
*/
static BOOL doInit( HANDLE hInstance, int nCmdShow )
{
char wndname[33]; // file name of the major window
char stpname[33]; // file name of stores the setup directory
char frname[33]; // file name of frame rate
char csname[33]; // file name of cursor
char cspath[33]; // path of cursor
char btlname[33]; // file name of palette in battle field
char facename[33]; // file name of main back-ground palette
int bTestIns=TRUE; // TRUE for test instance
// open game setup file
FILE * fp = fopen( "CBGame.set" , "rt");
if( fp == NULL )
{
ErrorMessage( hwndGame, MAIN_ERROR_ID+0, "Cannot open game set file:", "CBGame.set" );
return FALSE;
}
fscanf( fp, "%s\n", strCopyright );
fscanf( fp, "%s\n", wndname );
fscanf( fp, "%s\n", stpname );
fscanf( fp, "%s\n", frname );
fscanf( fp, "%s %s\n", csname, cspath );
fscanf( fp, "%s\n", btlname );
fscanf( fp, "%s\n", facename );
fscanf( fp, "%d\n", &MAIN_AVI_bFullScreen ); // 是否全屏播放AVI
fscanf( fp, "%d\n", &MAIN_bRelease ); // 是否为发行版
fscanf( fp, "%d\n", &FACE_AVI_FLAG ); // 是否播放AVI
fscanf( fp, "%d\n", &bTestIns ); // 是否检测多实例进程,缺省是检测
fclose( fp );
// 检测是否已经有本游戏的其它实例(进程)在运行了
// 如果有,则返回真
if( bTestIns == TRUE )
{
if( MAIN_TestInstance( wndname ) == TRUE )
return FALSE;
}
/*
* create major window
*/
if( !DD_InitWindow( hInstance, nCmdShow, wndname ) )
{
ErrorMessage( hwndGame, MAIN_ERROR_ID+1, "Error creating window!" );
return FALSE;
}
// 游戏安装路径
if( !GAME_GetSrcPath( stpname, GAME_strSetupDirectory, strlen(GAME_strSetupDirectory) ) )
{
ErrorMessage( hwndGame, MAIN_ERROR_ID+9, "Install game first please!\n" );
return FALSE;
}
// 检测光驱,正式版必须要有CD
if( MAIN_bRelease == TRUE && MAIN_TestCD() == FALSE )
{
ErrorMessage( hwndGame, MAIN_ERROR_ID+11, "Insert game CD please!\n" );
return FALSE;
}
/*
* create the main DirectDraw object
*/
if( !DD_InitGraph( hwndGame, 640, 480, 8, FALSE ) )
{
return FALSE;
}
MAIN_bInitGraph = TRUE;
#ifdef _MMX_SPLASH_
// detect if CPU supports MMX, and initialize splash
MAIN_bMMX = MMXCPUID();
//MAIN_bMMX = FALSE;
OutputDebugString( "CBMAIN: MMX Compatible:" );
OutputString( MAIN_bMMX, "\n" );
if( IntelSplashInit() == TRUE );
// IntelSplash();
#endif
// 播放AVI
// FACE_SetProgramState ( PROGRAM_STATE_AVI );
char avifile[_MAX_PATH];
strcpy( avifile, GAME_strSetupDirectory );
strcat( avifile, "\\avi\\" );
strcat( avifile, "Start.avi" );
strcpy( GAME.strStartAVI, avifile );
FACE_Avi_Play( avifile, COMMAND_STATE_AVI_BEGIN );
strcpy( avifile, GAME_strSetupDirectory );
return TRUE;
} /* doInit */
BOOL MAIN_InitOthers()
{
char wndname[33]; // file name of the major window
char stpname[33]; // file name of stores the setup directory
char frname[33]; // file name of frame rate
char csname[33]; // file name of cursor
char cspath[33]; // path of cursor
char btlname[33]; // file name of palette in battle field
char facename[33]; // file name of main back-ground palette
// open game setup file
FILE * fp = fopen( "CBGame.set" , "rt");
if( fp == NULL )
{
ErrorMessage( hwndGame, MAIN_ERROR_ID+0, "Cannot open game set file:", "CBGame.set" );
return FALSE;
}
fscanf( fp, "%s\n", strCopyright );
fscanf( fp, "%s\n", wndname );
fscanf( fp, "%s\n", stpname );
fscanf( fp, "%s\n", frname );
fscanf( fp, "%s %s\n", csname, cspath );
fscanf( fp, "%s\n", btlname );
fscanf( fp, "%s\n", facename );
fclose( fp );
/*
* create sound object
*/
DS_InitSound( hwndGame );
// initialize game data
::GAME_InitGame();
::MAP_InitMap();
if( ! ::GAME_ReadCBSetFile( hwndGame ) )
return FALSE;
// to init all pointer array of interface
FACE_InitInterface();
// to show the begin bitmap file
FACE_ShowABitmapPicture( PICTURE_BEGIN );
// create and set the palette
if( !pal.LoadPalettePAL( facename, FALSE ) )
{
ErrorMessage( hwndGame, MAIN_ERROR_ID
+3, " Cannot load Palette file", facename );
return FALSE;
}
if( !palMain.LoadPalettePAL( btlname, FALSE ) )
{
ErrorMessage( hwndGame, MAIN_ERROR_ID+6, " Cannot load Main Palette file", btlname );
return FALSE;
}
// create and set the cursor
if( !MAIN_LoadCursors( hwndGame, csname, cspath ) )
{
ErrorMessage( hwndGame, MAIN_ERROR_ID+4, " Cannot load cursor files", csname );
return FALSE;
}
// CURSOR_Set( &MAIN_Cursors[0] );
// create and set the frame rate
if( !DDC_LoadFrameRate( frname ) )
{
ErrorMessage( hwndGame, MAIN_ERROR_ID+5, " Cannot load FRate bitmap", frname );
return FALSE;
}
if( !HZ_OpenLib( "hzk\\simple.exp" ) )
{
ErrorMessage( hwndGame, MAIN_ERROR_ID+15, "No HZ Library at all", frname );
return FALSE;
}
return TRUE;
}
/*
* WinMain - initialization, message loop
*/
int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
lpCmdLine = lpCmdLine;
hPrevInstance = hPrevInstance;
if( !doInit( hInstance, nCmdShow ) )
{
OutputDebugString( "WinMain: Do Init failure!\n" );
return FALSE;
}
// load other maps
#ifdef _MAIN_DEBUG
if( ChangeProgramState( PROGRAM_STATE_PLAY, BUTTON_MENU_MAIN_NEWGAME_OK ) == PROGRAM_STATE_ERROR )
return FALSE;
#else
#endif
// play background wave
// strcpy( waveBack.strFileName, GAME.strPathWAV );
// strcat( waveBack.strFileName, "one.wav" );
// waveBack.Play();
DWORD dwTimeBegin;
DWORD dwTimeEnd;
dwTimeBegin = timeGetTime();
DWORD dwTimeBeginCursor;
DWORD dwTimeEndCursor;
dwTimeBeginCursor = timeGetTime();
//---- DH
// DH_NetworkInit();
//---- DH
// counter for moving screen
while( 1 )
{
if( CurrentMenu != NULL )
{
// if( (FACE_GetProgramState() == PROGRAM_STATE_MENU)&&
// (CurrentMenu->GetID() == MENU_MAIN_NETWORK_SETNET)
// )
if( (FACE_GetProgramState() == PROGRAM_STATE_MENU) && (IsInSetNetMenu == TRUE) )
{ // to receive the network message when you are in the Menu_NetWork_SetNet menu
DH_ReceiveMessage();
// if(GAME.nMe<=0)
{
int j;
for(j=0;j<MAX_PLAYERS;j++)
{
if((DP_PlayerInformation[j].DP_dcoID==DP_dcoID)&&(DP_dcoID!=0))
{
GAME.nMe=j+1;
GAME.Players[GAME.nMe].nType=PLAYER_TYPE_HUMAN;
}
else
{
if(DP_PlayerInformation[j].DP_dcoID!=0)
{GAME.Players[j+1].nType=PLAYER_TYPE_REMOTE;}
}
}
if(GAME.nMe!=0 && GAME.nMe!=1)
{
//发送消息给lihaijun
// SendMessage( hwndGame, WM_COMMAND, SHOW_MENU_MAIN_NETWORK_IPX_JOIN, GAME.nMe );
SendMessage( hwndGame, WM_COMMAND, BACKTO_BUTTON_MENU_MAIN_NETWORK_IPX_CREATE, 0 );
}
}
// else{
// GAME.Players[GAME.nMe].nType=PLAYER_TYPE_HUMAN;
// }
}
}
while( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) )
{
if( !GetMessage( &msg, NULL, 0, 0 ) )
return msg.wParam;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if( bActive )
{
#ifdef _DEBUG
bInRun = TRUE;
#endif
// game core loop
// draw cursor
if( MAIN_bFirst )
{
// move ime window (RU_LI) outside main window rectangle
HIMC himc = ImmGetContext( hwndGame );
POINT pt={800,600};
ImmSetStatusWindowPos( himc, &pt );
DDC_UpdateScreen();
}
MAIN_bFirst = FALSE;
// update cursor
dwTimeEndCursor = timeGetTime();
if( dwTimeEndCursor - dwTimeBeginCursor >= MAIN_CURSOR_WAIT )
{
dwTimeBeginCursor = dwTimeEndCursor;
// perform animate cursor,
// only change the current frame of the curosr, do not draw it
CURSOR_Animate();
}
// main circle of the game
dwTimeEnd = timeGetTime();
int nAdd = 0;
if( MAIN_bMMX == FALSE )
nAdd = 15;
if( dwTimeEnd - dwTimeBegin >= GAME.nSpeed+nAdd )
{
dwTimeBegin = dwTimeEnd;
if( FACE_GetProgramState() == PROGRAM_STATE_PLAY )
{
//---- DH
// DH_ReceiveInit();
//---- DH
updateFrame();
// test if should move screen
::DRAW_MoveScreen();
}
}
#ifdef _DEBUG
bInRun = FALSE;
#endif
}
else
{
// make sure we go to sleep if we have nothing else to do
WaitMessage();
}
}
} /* WinMain */
////////////////////////
// 用原始的办法检测光驱
BOOL MAIN_TestCD()
{
char tmp[128];
// test 1
strcpy( tmp, GAME_strSetupDirectory );
strcat( tmp, "\\TestCD.log" );
FILE *fp = fopen( tmp, "wb" );
if( fp != NULL )
{
char test[64];
strcpy( test, GAME_strSetupDirectory );
if( fwrite( test, strlen(test), 1, fp ) == 1 )
{
fclose( fp );
return FALSE;
}
fclose( fp );
}
// test 2
strcpy( tmp, GAME_strSetupDirectory );
strcat( tmp, "\\CB.EXE" );
fp = fopen( tmp, "rb" );
if( fp == NULL )
{
return FALSE;
}
fclose( fp );
// test 3
// Nov.7.1997
// 实际不是检测光盘,而是读取是否是豪华版的信息
// 也实际是增强版和标准版的区别判定
strcpy( tmp, GAME_strSetupDirectory );
strcat( tmp, "\\Disk.no" );
fp = fopen( tmp, "rb" );
if( fp == NULL )
{ // 不是增强版或豪华版
return FALSE;
}
fscanf( fp, "%d\n", &GAME_nDisk ); // 是否是豪华版,0为不是,1为是豪华版的A盘,2为是豪华版的B盘。
fclose( fp );
return TRUE;
}
// 检测是否已经有本游戏的其它实例(进程)在运行了
// 如果有,则返回真
BOOL MAIN_TestInstance( char *wndname )
{
HWND hWndFirst, hWndFirstChild;
static char title[_MAX_FNAME];
strcpy( title, wndname );
if(hWndFirst = FindWindow(NULL, title))
{
hWndFirstChild = GetLastActivePopup(hWndFirst);
BringWindowToTop(hWndFirst);
if(hWndFirst != hWndFirstChild)
BringWindowToTop(hWndFirstChild);
ShowWindow(hWndFirst, SW_SHOWNORMAL);
return TRUE;
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -