📄 cbgame.cpp
字号:
// load Game data header, must before load minimap surfaces
if( ! ::GAME_ReadMEDHeader( hwndGame, GAME.strNameMED, GAME.strPathMED ) )
{
OutputDebugString( "DRAW_LoadMaps Error(10): Read med file error!\n" );
return FALSE;
}
// Load minimap surfaces, must after read med header, before read med file
// 缩略图要知道战场图的大小,但是在读取MED文件时,要在缩略图上显示数据
OutputDebugString( "MiniMap Load:\n" );
if( !MINI_Load() )
{
OutputDebugString( "DRAW_LoadMaps Error(6): Error when loading minimap surfaces!\n" );
return FALSE;
}
if( ! ::GAME_ReadMEDFile( hwndGame, GAME.strNameMED, GAME.strPathMED ) )
{
OutputDebugString( "DRAW_LoadMaps Error(1): Read med file error!\n" );
return FALSE;
}
// 设置屏幕左边部队按钮
for( int i=0; i<PLAYER_GROUP_MAX-1; i++ )
{
if( GAME.Players[GAME.nMe].wGroup[i] != MAP_DATA_NONE )
FACE_SetNumberButtonState( i, BUTTON_UP, FALSE );
else
FACE_SetNumberButtonState( i, BUTTON_DISABLE, FALSE );
}
if( GAME.Players[GAME.nMe].wGroup[i] != MAP_DATA_NONE )
FACE_SetNumberButtonState( i, BUTTON_UP, TRUE );
else
FACE_SetNumberButtonState( i, BUTTON_DISABLE, TRUE );
// draw shadow
// SHADOW_DrawAll();
// draw minimap
MINI_DrawAll();
GAME_bBegin = TRUE; // set flag
//palMain.SetPalette();
// play background music
// DATA_WAVE_MusicPlay( GAME.nMusicID );
// get system time
GetSystemTime( &GAME_Time.Start );
// jump screen
DRAW_JumpScreen( GAME.ptStart[GAME.nMe] );
return TRUE;
}
// 游戏结束
void GAME_End( int nGameID )
{
Assert( GAME_bBegin == TRUE );
// release minimap surfaces
MINI_Release();
GAME_bBegin = FALSE; // set flag
}
// 从文件里得到将领信息,经验,升级,并设置到全局结构DATA_Lib.Gen中
// nSlot : 存盘文件号
BOOL GAME_GetGenInfo( int nSlot )
{
char name[32];
GAME_MakeSaveName( nSlot, ".GEN", name );
FILE *fp;
// 读取文件
fp = fopen( name, "rb" );
if( !fp )
{
OutputDebugString( "GAME_GetGenInfo Error: Cannot open file!\n" );
return FALSE;
}
//struct DATA_GENERAL_STRUCT Gen[DATA_UNIT_GENERAL_MAX];
//fread( DATA_Lib.Gen, sizeof( DATA_Lib.Gen ), 1, fp );
for( int i=0; i<DATA_UNIT_GENERAL_MAX; i++ )
{
fread( &DATA_Lib.Gen[i].nLevel, sizeof(DATA_Lib.Gen[i].nLevel), 1, fp );
fread( &DATA_Lib.Gen[i].nJingYan, sizeof(DATA_Lib.Gen[i].nJingYan), 1, fp );
}
fclose( fp );
return TRUE;
}
// 把将领信息,经验,升级,从全局结构DATA_Lib.Gen中写到文件里
// nSlot : 存盘文件号
void GAME_SetGenInfo( int nSlot )
{
char name[32];
GAME_MakeSaveName( nSlot, ".GEN", name );
FILE *fp;
// 读取文件
fp = fopen( name, "wb" );
if( !fp )
{
OutputDebugString( "GAME_SetGenInfo Error: Cannot open file!\n" );
return;
}
//struct DATA_GENERAL_STRUCT Gen[DATA_UNIT_GENERAL_MAX];
//fwrite( DATA_Lib.Gen, sizeof( DATA_Lib.Gen ), 1, fp );
for( int i=0; i<DATA_UNIT_GENERAL_MAX; i++ )
{
fwrite( &DATA_Lib.Gen[i].nLevel, sizeof(DATA_Lib.Gen[i].nLevel), 1, fp );
fwrite( &DATA_Lib.Gen[i].nJingYan, sizeof(DATA_Lib.Gen[i].nJingYan), 1, fp );
}
fclose( fp );
}
///////////
///////////
// 得到安装路径
// filename : 存放安装路径的文件名
// strSrcPath : 返回的安装路径
// nSize : 路径字符串的大小
BOOL GAME_GetSrcPath( LPCTSTR filename, LPSTR strSrcPath, int nSize )
{
FILE *fp;
fp = fopen( filename, "rb" );
if( !fp )
{
// ErrorMessage( hwndGame, GAME_ERROR_ID+31, "Cannot source path file!" );
OutputDebugString( "Cannot source path file named: WayAhead.dat!\n" );
return FALSE;
}
memset( strSrcPath, 0, nSize );
int i=0;
char c = fgetc( fp );
while( feof( fp ) == 0 )
{
strSrcPath[i] = (char )(c^34);
i++;
if( i == nSize-1 ) break;
c = fgetc( fp );
}
strSrcPath[i]=0;
fclose( fp );
return TRUE;
}
///////////
SYSTEMTIME TimeSub( SYSTEMTIME time1, SYSTEMTIME time2 )
{
SYSTEMTIME timeSub;
if( time1.wSecond<time2.wSecond )
{
time1.wMinute--;
timeSub.wSecond = time1.wSecond+60-time2.wSecond;
}
else
{
timeSub.wSecond = time1.wSecond-time2.wSecond;
}
if( time1.wMinute<time2.wMinute )
{
time1.wHour--;
timeSub.wMinute = time1.wMinute+60-time2.wMinute;
}
else
{
timeSub.wMinute = time1.wMinute-time2.wMinute;
}
if( time1.wHour<time2.wHour )
{
time1.wDay--;
timeSub.wHour = time1.wHour+12-time2.wHour;
}
else
{
timeSub.wHour = time1.wHour-time2.wHour;
}
timeSub.wDay = time1.wDay-time2.wDay;
return timeSub;
}
///////////
// 游戏结束播放结尾动画和制作群
// nType : 结束类型
void GAME_Ending( int nType )
{
char *strEnd[4]={ "liuwin", "liuwin1", "caowin","caowin1" };
char *strPath="\\End\\";
Assert( nType >=0 && nType < 4 );
/*
char fullname[_MAX_FNAME];
char fullpath[_MAX_PATH];
strcpy( fullname, GAME_strSetupDirectory );
strcat( fullname, strPath );
strcpy( fullpath, fullname );
strcat( fullname, strEnd[nType] );
WinExec( fullname, SW_SHOWMAXIMIZED );
*/
// to stop the music before play the end avi
// WriteLogFile( "dead.log","1\n" );
// DD_QuitGraph();
// WriteLogFile( "dead.log","2\n" );
DATA_WAVE_MusicStop();
// 运行其它组件的安装程序
STARTUPINFO si;
PROCESS_INFORMATION pi;
memset(&si, 0, sizeof(si));
si.cb=sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_MAXIMIZE|SW_SHOW;
char fullname[_MAX_FNAME];
char fullpath[_MAX_PATH];
strcpy( fullname, GAME_strSetupDirectory );
strcat( fullname, strPath );
strcpy( fullpath, fullname );
strcat( fullname, strEnd[nType] );
if(CreateProcess(NULL, fullname,
NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi))
{
::ShowWindow( hwndGame, SW_HIDE );
::UpdateWindow( hwndGame );
WaitForInputIdle( pi.hProcess, INFINITE );
//DWORD ret = WaitForSingleObject( pi.hProcess, INFINITE );
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
}
///////////
///////////
// 设置同盟,用于网络版
// Aug. 20. 1997
// nPlayer1, nPlayer2 : 两个游戏者
// bSet : TRUE时为设置同盟,否则为解除同盟
void GAME_SetAlly( int nPlayer1, int nPlayer2, BOOL bSet/*=TRUE*/ )
{
if( nPlayer1 == nPlayer2 )
return;
GAME.Players[nPlayer1].nAllies[nPlayer2] = bSet;
GAME.Players[nPlayer2].nAllies[nPlayer1] = bSet;
}
// Nov.10.1997
// CBAvi.cpp
extern int nCurrentVideoID;
// nType : -1, continue the end procedure
// 0-3, begin some kind of ending, must used in the frist call
// -2, jump to the last procedure
// -3, shut down the program immediatly
BOOL GAME_EndingEx( int nType/*=-1*/ )
{
static int nStep=0;
static int nSType = -1;
int i;
char *strAVI[4][3]={
{"liu1.avi","liu2.avi","liu3.avi"},
{"liu11.avi","liu22.avi","liu33.avi"},
{"cao1.avi","cao2.avi","cao3.avi"},
{"cao11.avi","cao22.avi","cao33.avi"} };
char *strBMP[4][3]={
{"liu1.bmp","liu2.bmp","liu3.bmp"},
{"liu4.bmp","liu5.bmp","liu6.bmp"},
{"cao1.bmp","cao2.bmp","cao3.bmp"},
{"cao4.bmp","cao5.bmp","cao6.bmp"} };
char *strBMP2[18]={
"cbname01.bmp", "cbname02.bmp", "cbname03.bmp",
"cbname04.bmp", "cbname05.bmp", "cbname06.bmp",
"cbname07.bmp", "cbname08.bmp", "cbname09.bmp",
"cbname10.bmp", "cbname11.bmp", "cbname12.bmp",
"cbname13.bmp", "cbname14.bmp", "cbname15.bmp",
"cbname16.bmp", "cbname17.bmp" };
char fullpath[_MAX_PATH];
char *strPath="\\End";
//char *strPath="";
POINT ptOne = { 343, 232 };
RECT rcAVI = {45,69,285,249};
static int bHighColor = FALSE;
static WAVEDYNAMIC wave;
static int nVideoID = -1;
// 执行过一遍,不再执行了
if( nStep > 21 ) return TRUE;
strcpy( fullpath, GAME_strSetupDirectory );
strcat( fullpath, strPath );
// 检测是否可以设置屏幕为640x480x16
// the first time
if( nStep == 0 )
{
// must add this function
FACE_SetProgramState( PROGRAM_STATE_NONE );
FACE_SetCommandState( COMMAND_STATE_NONE );
CURSOR_Set( NULL );
DD_EraseBackScreen();
DDC_UpdateScreen();
DATA_WAVE_MusicStop();
DS_QuitSound();
DD_QuitGraph();
if( DD_InitGraph( hwndGame, 640, 480, 16, FALSE ) == FALSE )
// if( 1 )
{ // 设置失败,则返回
bHighColor = FALSE;
if( DD_InitGraph( hwndGame, 640, 480, 8, FALSE ) == FALSE )
{
ErrorMessage( hwndGame, 2000, "Cannot initialize graph mode\n" );
return FALSE;
}
}
else
{
bHighColor = TRUE;
}
DS_InitSound( hwndGame );
// play background music
strcpy( wave.strFileName, fullpath );
strcat( wave.strFileName, "\\" );
strcat( wave.strFileName, "vend.wav" );
wave.Play();
}
// jump to game end
if( nType == -2 )
{
if( bHighColor == TRUE
&& nVideoID != -1 )
{
MCI_AVI_Stop( hwndGame, nVideoID );
MCI_AVI_Close( nVideoID );
nVideoID = -1;
}
else if( nVideoID != -1 )
{
KillTimer( hwndGame, 0 );
PostMessage( hwndGame, MM_MCINOTIFY, 99, nCurrentVideoID );
nVideoID = -1;
}
nStep = 21;
return TRUE;
}
if( nType == -3 )
{
if( bHighColor == TRUE
&& nVideoID != -1 )
{
MCI_AVI_Stop( hwndGame, nVideoID );
MCI_AVI_Close( nVideoID );
nVideoID = -1;
}
else if( nVideoID != -1 )
{
KillTimer( hwndGame, 0 );
PostMessage( hwndGame, MM_MCINOTIFY, 99, nCurrentVideoID );
nVideoID = -1;
}
return 2;
}
// game turly end
if( nStep == 21 )
{
if( bHighColor == TRUE
&& nVideoID != -1 )
{
MCI_AVI_Close( nVideoID );
nVideoID = -1;
}
Sleep( 2000 );
RECT rcTop, rcBottom;
rcTop.left=rcBottom.left=0;
rcTop.right=rcBottom.right=640;
rcTop.top=0;rcBottom.bottom=480;
for( i=1; i<240; i++ )
{
rcTop.bottom=rcTop.top+i;
rcBottom.top=rcBottom.bottom-i;
DD_EraseBackScreen( 0, &rcTop );
DD_EraseBackScreen( 0, &rcBottom );
DDC_UpdateScreen();
}
DD_EraseBackScreen( 0 );
DDC_UpdateScreen();
nStep ++;
return 2;
}
SetCursor(NULL);
if( nType != -1 )
nSType = nType;
CDDSurface sBack;
char backname[_MAX_FNAME];
strcpy( backname, fullpath );
if( nSType == 0 || nSType == 1 )
{
strcat( backname, "\\cbend2.bmp" );
}
else
{
strcat( backname, "\\cbend1.bmp" );
}
CDDPalette pal;
if( bHighColor == FALSE )
{ // load and set palette
if( pal.LoadPalette( backname, TRUE ) == FALSE )
{
ErrorMessage( hwndGame, 2006, "load palette file when ending!\n", backname );
return FALSE;
}
}
if( sBack.LoadBitmap( backname, FALSE, FALSE ) == FALSE )
{
ErrorMessage( hwndGame, 2002, "Cannot load background file when ending!\n", backname );
return FALSE;
}
CDDSurface sOne;
if( nStep < 3 )
{
char onename[_MAX_FNAME];
strcpy( onename, fullpath );
strcat( onename, "\\" );
strcat( onename, strBMP[nSType][nStep] );
if( sOne.LoadBitmap( onename, FALSE, FALSE ) == FALSE )
{
ErrorMessage( hwndGame, 2003, "Cannot load front image file when ending!\n", onename );
return FALSE;
}
}
POINT pt={0,0};
if( nStep == 0 )
{
// Draw background to back buffer andupdate
sBack.BltToBack( pt, NULL );
DDC_UpdateScreen();
// draw front screen
RECT rcSrc={0,0,0,0};
rcSrc.right = sOne.GetSize().cx;
rcSrc.bottom = sOne.GetSize().cy;
POINT ptDest={0,0};
ptDest.y = ptOne.y;
for( i=1; i<sOne.GetSize().cx; i+=2 )
{
rcSrc.left = rcSrc.right - i;
ptDest.x = ptOne.x+rcSrc.left;
sOne.BltToBack( ptDest, &rcSrc );
DDC_UpdateScreen();
}
if( bHighColor == TRUE )
{
// open and play avi
char aviname[_MAX_FNAME];
strcpy( aviname, fullpath );
strcat( aviname, "\\" );
strcat( aviname, strAVI[nSType][0] );
if( (nVideoID = MCI_AVI_Open( hwndGame, aviname, &rcAVI )) == -1 )
{
ErrorMessag
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -