⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cbgame.cpp

📁 网页游戏赤壁
💻 CPP
📖 第 1 页 / 共 5 页
字号:
			&GAME.Players[nNum4].nWood, 
			&GAME.Players[nNum4].nIron )); 
		/*
		fscanf( fp, "%d, %d, %d, %d\n", 
			&GAME.Players[nNum4].nGold, 
			&GAME.Players[nNum4].nFood, 
			&GAME.Players[nNum4].nWood, 
			&GAME.Players[nNum4].nIron ); 
		*/
		FSCAN.l_scan (sscanf (FSCAN.expand_buf,"%d, ", &nNum5) );
		//fscanf( fp, "%d, ", &nNum5 );
		for( k=0; k<DATA_UNIT_GENERAL_MAX; k++ )
		{
			if( DATA_Lib.Gen[k].nJunZhu == nNum4 )
			{
				DATA_Lib.Gen[k].bOnBattle = TRUE;
			}
		}
		int nSaveGen[32];
		for( k=0; k<nNum5; k++ )
		{
			FSCAN.l_scan (sscanf (FSCAN.expand_buf,"%d,", &nNum6 ));
			//fscanf( fp, "%d,", &nNum6 );
			DATA_Lib.Gen[nNum6].bOnBattle = FALSE;
			//Assert( DATA_Lib.Gen[nNum6].nJunZhu == nNum4 );
			DATA_Lib.Gen[nNum6].nJunZhu = nNum4;

			// 初始化一些属性
//			DATA_Lib.Gen[nNum6].nID = nNum6;
			
			nSaveGen[k] = nNum6;
		}
		for( k=0; k<nNum5; k++ )
		{
			FSCAN.l_scan (sscanf (FSCAN.expand_buf,"%d,", &nNum6 ));
			if( nNum6 != 0 )
			{
				DATA_Lib.Gen[nSaveGen[k]].nLevel = nNum6-1;
			}
			else if( nSaveGen[k] >= 1 && nSaveGen[k] <= 33 
				&& DATA_Lib.Gen[nSaveGen[k]].nLevel == 0 )
			{
				DATA_Lib.Gen[nSaveGen[k]].nLevel = 5;	// 孙权的人,初始级别为5
			}
		}
	}

	Assert( GAME.Players[GAME.nMe].nType == PLAYER_TYPE_HUMAN );
	FSCAN.scan_close ();
	//fclose( fp );
	return TRUE;
}

// 读取战场数据文件
// hwnd		:	window to receive error message
// filename	:	battle field data file name
// path		:	battle field data file path
// return	:	TRUE if successful
BOOL GAME_ReadMEDFile( HWND hwnd, LPCTSTR filename, LPCTSTR path )
{
	char fname[65];
	FILE *fp;

	if( path != 0 )
	{
		strcpy( fname, path );
		strcat( fname, filename );
	}
	else	strcpy( fname, filename );
	fp = fopen( fname, "rb" );
	if( !fp )
	{
		ErrorMessage( hwnd, GAME_ERROR_ID+2,"Cannot open Med file: ", fname );
		return FALSE;
	}

	// read MED file version
	fread( &GAME.lVerMED, sizeof(long), 1, fp );
	if( GAME.lVerMED<100 )
	{
		ErrorMessage( hwnd, GAME_ERROR_ID+5,"Cannot read old version of MED file: ", fname );
		return FALSE;
	}

	// read MED file( Map Editer Data file )
	char strTemp[65];
	// read name of the battlefield
	int nName=0;
	fread( &nName, sizeof(BYTE), 1, fp );
	fread( GAME.strName, nName, 1, fp );
	GAME.strName[nName] = 0;
	
	// read size of the battlefield
	fread( &MAP_Lib.szNum.cx, sizeof(DWORD), 1, fp );
	fread( &MAP_Lib.szNum.cy, sizeof(DWORD), 1, fp );

	// read something not used
	fread( strTemp, sizeof(long)*(MAP_DATA_THICK+2), 1, fp );

	// initialize data
	::MAP_ResetGround();
	::MAP_ResetRegion();
	::MAP_ResetUnit();


	// set allies
	// Aug. 28. 1997
	GAME_SetAlly( 0, 1 );
	GAME_SetAlly( 0, 2 );
	GAME_SetAlly( 0, 3 );
	GAME_SetAlly( 0, 4 );

	// read ground data
	for( int i=0; i<MAP_DATA_THICK; i++ )
	for( int j=0; j<MAP_Lib.szNum.cx; j++ )
		fread( MAP_wGroundData[i][j], sizeof(WORD)*MAP_Lib.szNum.cy, 1, fp );

	// read starting points
	for( int k=0; k<GAME_PLAYER_MAX; k++ )
	{
		fread( &GAME.ptStart[k], sizeof(POINT), 1, fp );
	}

	// read unit data
	DWORD codeU;
	WORD wCounter;
	for( int x=0; x< GAME_PLAYER_MAX; x++ )
	{
		fread( &wCounter, sizeof(WORD), 1, fp );
		for( int y=0; y<wCounter; y++ )
		{
			struct UNIT_STRUCT Unit;
			fread( &Unit.nType, sizeof(BYTE), 1, fp );
			if( Unit.nType == MAP_UNIT_TYPE_NONE ) continue;
			fread( &Unit.Draw.nX, sizeof(WORD), 1, fp );
			fread( &Unit.Draw.nY, sizeof(WORD), 1, fp );
			fread( &Unit.Draw.nLayer, sizeof(WORD), 1, fp );
			fread( &codeU, sizeof(codeU), 1, fp );
			WORD codeUEx;
			if( (codeUEx = ::CTRL_UNIT_Create( Unit.Draw.nLayer, Unit.Draw.nX, Unit.Draw.nY, codeU )) == MAP_DATA_NONE )
			{
				OutputDebugString( "GAME_ReadMedFile Error(0): Read Med file error!\n" );
				ErrorMessage( hwnd, GAME_ERROR_ID+4,"Read Med file error: ", fname );
				return FALSE;
			}

			struct UNIT_STRUCT *pUnit = ::MAP_GetUnit( codeUEx );
			Assert( pUnit );
			Assert( EYE_IfUnitIsUnit( pUnit ) );
			Assert( pUnit->nID == codeUEx );
			if( EYE_IfUnitIsBuild( pUnit ) )
			{
				// 战斗记分
				RUN_CountDown[pUnit->Draw.nPlayer].nBuildings ++;

				if( EYE_IfUnitIsRes( pUnit ) )
				{
					fread( &pUnit->Build.nResource, sizeof(DWORD), 1, fp );
				}
				else
				{	// added by Liu Gang
					TY_IDProcess(pUnit->nID,JZFINISH,CBNULL);
				}
			}
			else if( EYE_IfUnitIsSoldier( pUnit ) )
			{
				// 战斗记分
				RUN_CountDown[pUnit->Draw.nPlayer].nSoldiers += EYE_GetFullLife( -1, pUnit->Draw.nFile );

				WORD nGenNum;
				fread( &nGenNum, sizeof(WORD), 1, fp );
				if( nGenNum != 0 )
				{
					Assert( nGenNum > 0 && nGenNum <= 118 );	// temp
					pUnit->Status.nID = codeUEx;
					pUnit->Status.nTaskID = ZUJIAN;
					if( EYE_IfUnitIsWorker( pUnit ) )
						pUnit->Status.nTaskIDEx = MAP_UNIT_TYPE_WGEN;		// 部队类型是工人部队
					else
						pUnit->Status.nTaskIDEx = MAP_UNIT_TYPE_GEN;		// 部队类型是战斗部队
					Assert( nGenNum != MAP_DATA_NONE );
					pUnit->Status.nParam1 = nGenNum;	// 将领编号
					pUnit->Status.bDone = FALSE;
					RUN_GroupUnit( pUnit );
					pUnit->Status.nTaskID = QUXIAO;
					Assert( pUnit->nHasShadow == 1 );
				}
			}
		}
	}

	fclose( fp );
	return TRUE;
} // end of GAME_ReadMedFile()

// Nov.6.1997, Liu Gang
// 读取网络战场数据文件
// hwnd		:	window to receive error message
// filename	:	battle field data file name
// path		:	battle field data file path
// return	:	TRUE if successful
BOOL GAME_ReadMEDFileNet( HWND hwnd, LPCTSTR filename, LPCTSTR path )
{
	char fname[65];
	FILE *fp;

	if( path != 0 )
	{
		strcpy( fname, path );
		strcat( fname, filename );
	}
	else	strcpy( fname, filename );
	fp = fopen( fname, "rb" );
	if( !fp )
	{
		ErrorMessage( hwnd, GAME_ERROR_ID+2,"Cannot open Med file: ", fname );
		return FALSE;
	}

	// read MED file version
	fread( &GAME.lVerMED, sizeof(long), 1, fp );
	if( GAME.lVerMED<100 )
	{
		ErrorMessage( hwnd, GAME_ERROR_ID+5,"Cannot read old version of MED file: ", fname );
		return FALSE;
	}

	// read MED file( Map Editer Data file )
	char strTemp[65];
	// read name of the battlefield
	int nName=0;
	fread( &nName, sizeof(BYTE), 1, fp );
	fread( GAME.strName, nName, 1, fp );
	GAME.strName[nName] = 0;
	
	// read size of the battlefield
	fread( &MAP_Lib.szNum.cx, sizeof(DWORD), 1, fp );
	fread( &MAP_Lib.szNum.cy, sizeof(DWORD), 1, fp );

	// read something not used
	fread( strTemp, sizeof(long)*(MAP_DATA_THICK+2), 1, fp );

	// initialize data
	::MAP_ResetGround();
	::MAP_ResetRegion();
	::MAP_ResetUnit();


	// set allies
	// Aug. 28. 1997
	GAME_SetAlly( 0, 1 );
	GAME_SetAlly( 0, 2 );
	GAME_SetAlly( 0, 3 );
	GAME_SetAlly( 0, 4 );

	// read ground data
	for( int i=0; i<MAP_DATA_THICK; i++ )
	for( int j=0; j<MAP_Lib.szNum.cx; j++ )
		fread( MAP_wGroundData[i][j], sizeof(WORD)*MAP_Lib.szNum.cy, 1, fp );

	// read starting points
	for( int k=0; k<GAME_PLAYER_MAX; k++ )
	{
		fread( &GAME.ptStart[k], sizeof(POINT), 1, fp );
	}

	// read unit data
	DWORD codeU;
	WORD wCounter;
	for( int x=0; x< GAME_PLAYER_MAX; x++ )
	{
		// 网络版要跳过没用的游戏者
		if( GAME.Players[x].nType == PLAYER_TYPE_NONE && x!= 0 )
		{
			fread( &wCounter, sizeof(WORD), 1, fp );
			for( int y=0; y<wCounter; y++ )
			{
				struct UNIT_STRUCT Unit;
				fread( &Unit.nType, sizeof(BYTE), 1, fp );
				fread( &Unit.Draw.nX, sizeof(WORD), 1, fp );
				fread( &Unit.Draw.nY, sizeof(WORD), 1, fp );
				fread( &Unit.Draw.nLayer, sizeof(WORD), 1, fp );
				fread( &codeU, sizeof(codeU), 1, fp );
				if( Unit.nType == MAP_UNIT_TYPE_RESOURCE )// 资源
				{
					DWORD dwTemp;
					fread( &dwTemp, sizeof(DWORD), 1, fp );
				}
				else if( Unit.nType == MAP_UNIT_TYPE_SOLDIER	// 士兵
					|| Unit.nType == MAP_UNIT_TYPE_SHIP 		// 战船
					|| Unit.nType == MAP_UNIT_TYPE_LADDER 		// 云梯
					|| Unit.nType == MAP_UNIT_TYPE_WORKER		// 工人
					|| Unit.nType == MAP_UNIT_TYPE_MAN			// 平民
				)
				{
					WORD wTemp;
					fread( &wTemp, sizeof(WORD), 1, fp );
				}
			}
		}
		else
		{
			fread( &wCounter, sizeof(WORD), 1, fp );
			for( int y=0; y<wCounter; y++ )
			{
				struct UNIT_STRUCT Unit;
				fread( &Unit.nType, sizeof(BYTE), 1, fp );
				if( Unit.nType == MAP_UNIT_TYPE_NONE ) continue;
				fread( &Unit.Draw.nX, sizeof(WORD), 1, fp );
				fread( &Unit.Draw.nY, sizeof(WORD), 1, fp );
				fread( &Unit.Draw.nLayer, sizeof(WORD), 1, fp );
				fread( &codeU, sizeof(codeU), 1, fp );
				WORD codeUEx;
				if( (codeUEx = ::CTRL_UNIT_Create( Unit.Draw.nLayer, Unit.Draw.nX, Unit.Draw.nY, codeU )) == MAP_DATA_NONE )
				{
					OutputDebugString( "GAME_ReadMedFile Error(0): Read Med file error!\n" );
					ErrorMessage( hwnd, GAME_ERROR_ID+4,"Read Med file error: ", fname );
					return FALSE;
				}

				struct UNIT_STRUCT *pUnit = ::MAP_GetUnit( codeUEx );
				Assert( pUnit );
				Assert( EYE_IfUnitIsUnit( pUnit ) );
				Assert( pUnit->nID == codeUEx );
				if( EYE_IfUnitIsBuild( pUnit ) )
				{
					// 战斗记分
					RUN_CountDown[pUnit->Draw.nPlayer].nBuildings ++;

					if( EYE_IfUnitIsRes( pUnit ) )
					{
						fread( &pUnit->Build.nResource, sizeof(DWORD), 1, fp );
					}
					else
					{	// added by Liu Gang
						TY_IDProcess(pUnit->nID,JZFINISH,CBNULL);
					}
				}
				else if( EYE_IfUnitIsSoldier( pUnit ) )
				{
					// 战斗记分
					RUN_CountDown[pUnit->Draw.nPlayer].nSoldiers += EYE_GetFullLife( -1, pUnit->Draw.nFile );

					WORD nGenNum;
					fread( &nGenNum, sizeof(WORD), 1, fp );
					if( nGenNum != 0 )
					{
						Assert( nGenNum > 0 && nGenNum <= 118 );	// temp
						pUnit->Status.nID = codeUEx;
						pUnit->Status.nTaskID = ZUJIAN;
						if( EYE_IfUnitIsWorker( pUnit ) )
							pUnit->Status.nTaskIDEx = MAP_UNIT_TYPE_WGEN;		// 部队类型是工人部队
						else
							pUnit->Status.nTaskIDEx = MAP_UNIT_TYPE_GEN;		// 部队类型是战斗部队
						Assert( nGenNum != MAP_DATA_NONE );
						pUnit->Status.nParam1 = nGenNum;	// 将领编号
						pUnit->Status.bDone = FALSE;
						RUN_GroupUnit( pUnit );
						pUnit->Status.nTaskID = QUXIAO;
						Assert( pUnit->nHasShadow == 1 );
					}
				}
			}
		}
	}

	fclose( fp );
	return TRUE;
} // end of GAME_ReadMedFileNet()
///////////

///////////
// 读取战场数据文件头,仅供MINI_Load()缩略图使用
// hwnd		:	window to receive error message
// filename	:	battle field data file name
// path		:	battle field data file path
// return	:	TRUE if successful
BOOL GAME_ReadMEDHeader( HWND hwnd, LPCTSTR filename, LPCTSTR path )
{
	char fname[65];
	
	if( path != 0 )
	{
		strcpy( fname, path );
		strcat( fname, filename );
	}
	else	strcpy( fname, filename );
	FILE * fp = fopen( fname, "rb" );
	if( !fp )
	{
		ErrorMessage( hwnd, GAME_ERROR_ID+3,"Cannot open Med file header: ", fname );
		return FALSE;
	}

	// read MED file version
	fread( &GAME.lVerMED, sizeof(long), 1, fp );

	// read MED file( Map Editer Data file )
	char strTemp[65];
	// read name of the battlefield
	int nName=0;
	fread( &nName, sizeof(BYTE), 1, fp );
	fread( GAME.strName, nName, 1, fp );
	GAME.strName[nName] = 0;
	
	// read size of the battlefield
	fread( &MAP_Lib.szNum.cx, sizeof(DWORD), 1, fp );
	fread( &MAP_Lib.szNum.cy, sizeof(DWORD), 1, fp );

	// read something not used
	fread( strTemp, sizeof(long)*(MAP_DATA_THICK+2), 1, fp );

	fclose( fp );
	return TRUE;

} // end of GAME_ReadMedHeader()


// 释放所有游戏中产生出来的单元和其它个体
void GAME_ReleaseAllUnits()
{
	int i,j;
	int nCounter, nMax;

	nCounter = 0;
	for( j=0; j<GAME_PLAYER_MAX; j++ )
	{
		nMax = GAME.Players[j].wUnitCounter;
		for( i=0; i<PLAYER_UNIT_MAX; i++ )
		{
			if( GAME.Players[j].Unit[i].nType != MAP_UNIT_TYPE_NONE )
			{
				CTRL_UNIT_Destroy( &GAME.Players[j].Unit[i] );
				nCounter++;
				if( nCounter >= nMax )
					break;
			}
		}
	}

	nCounter = 0;
	nMax = OTHER_nCounter;
	for( i=0; i<OTHER_MAX; i++ )
	{
		if( OTHER[i].nType != OTHER_TYPE_NONE )
		{
			OTHER_DestroyData( i );
			nCounter++;
			if( nCounter >= nMax )
				break;
		}
	}
}
///////////



///////////
// First demension: 0-4 are the Waiting List of player 0-4
// 第一个下标:0-4代表游戏者0-4的等待队列
// defined in CBCtrl.cpp
extern struct CTRL_TASK_STRUCT	CTRL_TaskList[GAME_PLAYER_MAX][CTRL_TASK_LIST_MAX+CTRL_TASK_LIST_MAX];
extern RECT DRAW_rcScreen;

// defined in CBMap.cpp
// 地形图素数据数组
extern WORD MAP_wGroundData[MAP_DATA_THICK][MAP_DATA_WIDTH][MAP_DATA_HEIGHT];
// 区域数据数组,内部使用
// 但是不要直接访问,而是使用MAP_GetRegionData(),除非特别需要速度的地方(频繁调用的地方)。
extern WORD MAP_wRegionData[MAP_DATA_WIDTH][MAP_DATA_HEIGHT];	

// defined in CBShadow.cpp
// array for second layer of shadow
extern char	cMap_shadowEx [MAP_DATA_WIDTH][MAP_DATA_HEIGHT]; //lwc计录是否贴阴影;

// defined in TEmperor.cpp
// save AI
extern WORD SaveArr[70000];
///////////

///////////
// 读游戏设置文件

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -