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

📄 cbarray.cpp

📁 经典游戏赤壁的源代码
💻 CPP
字号:
/////////////////
// CBArry.h		:	《赤壁》的数组查询
//
// 版本0010		:	一九九七年三月四日
//
// written by	:	Li Haijun
//
// Compiler		:	Visual C++ 4.2
//
// Copyright	:	WayAhead Co.Ltd.		1996-1997
/////////////////
// 此文件用来处理和存放所有被查询的对象单元(将领、士兵、建筑)的数组
#include "stdafx.h"
#include "stdio.h"

#include "cbdata.h"
#include "cbgame.h"

#include "marco.h"
#include "cbarray.h"
#include "ddlist.h"
//////////////////////////////////////Donghai//////////////////////////////////////
#include "Network.h"
static	int		CreatedPlayerNum = 0 ;
extern struct	EnumSessionCallback		DP_EnumSessionCb[256];
extern LPSTR	DP_FullName;
extern LPSTR	DP_NickName;
extern struct	EnumSessionCallback		DP_EnumSessionCb[256];
//////////////////////////////////////Donghai//////////////////////////////////////
class	CMyFile		AllFile[ MAX_SAVEFILE ];	// to handle all save file

class	CMyFile		MapFile[ MAX_MAPS ] ;

struct DATA_GENERAL_STRUCT * pAllGeneral[ MAX_ONEKINGGENERAL ];

extern class	CDDListUnit	*	pAllListUnit[MAX_LISTUNIT]; //to record all list-unit's pointer
////////////////////////////////
//	to set all my general into the pAllGeneral array
void	SetAllGeneral()
{
	int		GeneralNum = 0;

//	to initialize pAllGeneral array to NULL
	for( int j=0; j< MAX_ONEKINGGENERAL; j++ )
		pAllGeneral[j] = NULL;

	for( int i=1; i<DATA_UNIT_GENERAL_MAX; i++ )
	{
		if( ( DATA_Lib.Gen[i].nID != 0 ) &&
			( DATA_Lib.Gen[i].nJunZhu == GAME.nMe )&&
			( DATA_Lib.Gen[i].bOnBattle == FALSE  ) )
		{
			pAllGeneral[GeneralNum] = &DATA_Lib.Gen[i];
			GeneralNum++;
		}
	}

	return;
}

///////////////////////////////////////////
//	to pagedown or pageup pAllGeneral array
int	ToPageAllGeneral( int Flag )
{
	int	nTotal  = 0;
	static	int	nCurrent = 0;


	if( Flag == GET_CURRENT )
	{
		return nCurrent;
	}

	// to get the total general number
	if( nTotal == 0 )
	{
		for( int i=0; i<MAX_ONEKINGGENERAL; i++ )
		{
			if( pAllGeneral[i] != NULL)
				nTotal++;
		}
	}

	// to initialize the list-unit to show
	for( int i=0; i<MAX_LISTINUNIT; i++ )
	{
		if( pAllListUnit[0]->m_pList[i] != NULL )
			pAllListUnit[0]->m_pList[i]->m_ShowString[0] = '\0' ;
	}

	// to set the list-unit of select general 
	if( Flag == FIRST_IN )
		nCurrent = 0;
	else if( Flag == PAGE_UP )
		nCurrent = nCurrent - 6 ;
	else if( Flag == PAGE_DOWN )
		nCurrent = nCurrent + 6;

	if( (nCurrent+5) >= nTotal )
			nCurrent = nTotal - 6;
	if( nCurrent < 0 )
			nCurrent = 0;

	if( nTotal < 6 )
	{
		for( int j=0; j<nTotal; j++ )
		{
			strcpy( pAllListUnit[0]->m_pList[ j ]->m_ShowString, pAllGeneral[ j ]->strName );
			strcat( pAllListUnit[0]->m_pList[ j ]->m_ShowString, "\0" );
		}
	}
	else
	{
		for( int j=nCurrent; j<(nCurrent+6); j++ )
		{
			strcpy( pAllListUnit[0]->m_pList[ j - nCurrent ]->m_ShowString, pAllGeneral[ j ]->strName );
			strcat( pAllListUnit[0]->m_pList[ j - nCurrent ]->m_ShowString, "\0" );
		}
	}

	return nCurrent;
}
////////////////////////////////////////////
//
CMyFile::CMyFile()
{
	m_bFlag = FALSE ;
	m_nSerialNumber = NONE ;
//	strcpy(m_sFileName, "Empty") ;
	memset( m_sFileName, 0, sizeof(m_sFileName) ) ;
}

CMyFile::~CMyFile()
{
	m_bFlag = FALSE ;
	m_nSerialNumber = NONE ;
	m_sFileName[0] = '\0' ;
}

////////////////////////////////////////////
//	to read all saving files information
void	GetAllSaveFile()
{
	for( int i=0; i<MAX_SAVEFILE; i++ )
	{
		if( GAME_GetSaveInfo( i, AllFile[i].m_sFileName ) == FALSE )
		{
			AllFile[i].m_bFlag = FALSE ;
			AllFile[i].m_nSerialNumber = i ;
//			AllFile[i].m_sFileName[0] = '\0' ;
		}
		else
			AllFile[i].m_bFlag = TRUE ;
	}
}

///////////////////////////////////////////
//	to pagedown or pageup AllFile array
int	ToPageAllFile( int Flag )
{
	int	nTotal  = 20;
	static	int	nCurrent = 0;


	if( Flag == GET_CURRENT )
	{
		return nCurrent;
	}

	// to initialize the list-unit to show
	for( int i=0; i<4; i++ )
	{
		if( pAllListUnit[0]->m_pList[i] != NULL )
			pAllListUnit[0]->m_pList[i]->m_ShowString[0] = '\0' ;
	}

	// to set the list-unit of select general 
	if( Flag == FIRST_IN )
		nCurrent = 0;
	else if( Flag == PAGE_UP )
	{
		if( (nCurrent-1) >= 0 )
			nCurrent = nCurrent - 1 ;
	}
	else if( Flag == PAGE_DOWN )
	{
		if( (nCurrent+4) < MAX_SAVEFILE )
			nCurrent = nCurrent + 1;
	}

	for( int j=nCurrent; j<(nCurrent+4); j++ )
	{
		// to set the serial number of this list
		char	temp[100] ;
		memset( temp, 0, sizeof(temp) ) ;
		_itoa(j, temp, 10) ;
	//	pAllListUnit[0]->m_pList[ j - nCurrent ]->SetSerial(temp) ;
		// to set the show string of this list
		memset(pAllListUnit[0]->m_pList[ j - nCurrent ]->m_ShowString, 0, sizeof(pAllListUnit[0]->m_pList[ j - nCurrent ]->m_ShowString) ) ;

		pAllListUnit[0]->m_pList[ j - nCurrent ]->SetState( LIST_UP ) ;

		if( AllFile[j].m_bFlag == TRUE )
		{
			strcpy( pAllListUnit[0]->m_pList[ j - nCurrent ]->m_ShowString, AllFile[ j ].m_sFileName );
			strcat( pAllListUnit[0]->m_pList[ j - nCurrent ]->m_ShowString, "\0" );
		}
	}

	return nCurrent;
}
///////////////////////////////////////////////////////////////////
//	to manage all player that on the network now
//
//例子:
//DP_EnumSessionCb[i].PointDPGameDesc.szSessionName[j]='\0';
//DP_EnumSessionCb[i].PointDPGameDesc.dwSession=0;
void	GetAllCreatedPlayer()
{
/*	if( CreatedPlayerNum < 1 )
	{
		for( int j=0; j<3; j++ )
		{
			DP_EnumSessionCb[j].PointDPGameDesc.dwSession=1;
			strcpy( DP_EnumSessionCb[j].PointDPGameDesc.szSessionName, "ABCDE" ) ;
		}
*/
		for( int i=0; i<256; i++ )
		{
			if( DP_EnumSessionCb[i].PointDPGameDesc.dwSession != 0 )
				CreatedPlayerNum++;
			else
				break ;
		}
//	}

	return;
}
///////////////////////////////////////////
//	to pagedown or pageup AllFile array
int	ToPageAllCreatePlayer( int Flag )
{
	static	int	nCurrent = 0;

	if( Flag == GET_CURRENT )
	{
		return nCurrent;
	}

	// to initialize the list-unit to show
	for( int i=0; i<4; i++ )
	{
		if( pAllListUnit[0]->m_pList[i] != NULL )
			pAllListUnit[0]->m_pList[i]->m_ShowString[0] = '\0' ;
	}

	// to set the list-unit of select general 
	if( Flag == FIRST_IN )
		nCurrent = 0;
	else if( Flag == PAGE_UP )
	{
		if( (nCurrent-1) >= 0 )
			nCurrent = nCurrent - 1 ;
	}
	else if( Flag == PAGE_DOWN )
	{
		if( (nCurrent+4) < CreatedPlayerNum )
			nCurrent = nCurrent + 1;
	}

	for( int j=nCurrent; j<(nCurrent+4); j++ )
	{
		// to set the serial number of this list
		char	temp[100] ;
		memset( temp, 0, sizeof(temp) ) ;
		_itoa(j, temp, 10) ;
//		pAllListUnit[0]->m_pList[ j - nCurrent ]->SetSerial(temp) ;
		// to set the show string of this list
		memset(pAllListUnit[0]->m_pList[ j - nCurrent ]->m_ShowString, 0, sizeof(pAllListUnit[0]->m_pList[ j - nCurrent ]->m_ShowString) ) ;

		pAllListUnit[0]->m_pList[ j - nCurrent ]->SetState( LIST_UP ) ;

		if( DP_EnumSessionCb[j].PointDPGameDesc.dwSession != 0 )
		{
			strcpy( pAllListUnit[0]->m_pList[ j - nCurrent ]->m_ShowString, DP_EnumSessionCb[j].PointDPGameDesc.szSessionName );
			strcat( pAllListUnit[0]->m_pList[ j - nCurrent ]->m_ShowString, "\0" );

			// to constrant the special symbole "&" to space block
			int		length = sizeof( pAllListUnit[0]->m_pList[j-nCurrent]->m_ShowString ) ;
			for( int I=0; I<length; I++ )
			{
				if( pAllListUnit[0]->m_pList[j - nCurrent]->m_ShowString[I]  == '&' )
					pAllListUnit[0]->m_pList[j - nCurrent]->m_ShowString[I]  = ' ' ;
			}
		}
	}

	return nCurrent;
}

///////////////////////////////////////////////////////////////
//
//	to operate the network maps when you want a net work fight
//
////////////////////////////////////////////
void	GetAllMaps()
{
	char	CurrentDir[2048] ;
	char	MapsDir[2048] ;

	memset( CurrentDir, 0, sizeof(CurrentDir) ) ;
	memset( MapsDir, 0, sizeof(MapsDir) ) ;

	GetCurrentDirectory( sizeof(CurrentDir), CurrentDir ) ;
	strcpy( MapsDir, CurrentDir ) ;
	strcat( MapsDir, "\\netmeds\\*.med" ) ;

	HANDLE				FileHandle ;
	WIN32_FIND_DATA		FindFile ;

	FileHandle = FindFirstFile( MapsDir, &FindFile );

	if( FileHandle == INVALID_HANDLE_VALUE )
		return ;

	strcpy( MapFile[0].m_sFileName, FindFile.cFileName ) ;
	MapFile[0].m_bFlag = TRUE ;
	MapFile[0].m_nSerialNumber = 0 ;

	for( int i=1; i<MAX_MAPS; i++ )
	{
		if( FindNextFile(	FileHandle,	&FindFile ) )
		{
			strcpy( MapFile[i].m_sFileName, FindFile.cFileName ) ;
			MapFile[i].m_bFlag = TRUE ;
			MapFile[i].m_nSerialNumber = i ;
		}
		else
			break ;
	}
}

///////////////////////////////////////////
//	to pagedown or pageup All maps array
int	ToPageAllMaps( int Flag )
{
	int	nTotal  = 0 ;
	static	int	nCurrent = 0;

	if( MapFile[0].m_bFlag == FALSE )
		return FALSE ;

	if( Flag == GET_CURRENT )
	{
		return nCurrent;
	}

	// to initialize the list-unit to show
	for( int j=0; j<3; j++ )
	{
		if( pAllListUnit[0]->m_pList[j] != NULL )
			pAllListUnit[0]->m_pList[j]->m_ShowString[0] = '\0' ;
	}

	// to get the total general number
	if( nTotal == 0 )
	{
		for( int i=0; i<MAX_MAPS; i++ )
		{
			if( MapFile[i].m_bFlag == TRUE)
				nTotal++;
			else
				break ;
		}
	}

	// to set the list-unit of select general 
	if( Flag == FIRST_IN )
		nCurrent = 0;
	else if( Flag == PAGE_UP )
		nCurrent = nCurrent - 3 ;
	else if( Flag == PAGE_DOWN )
		nCurrent = nCurrent + 3;

	if( (nCurrent+3) > nTotal )
			nCurrent = nTotal - 3;
	if( nCurrent < 0 )
			nCurrent = 0;

	for( int k=0; k<3; k++ )
	{
		// to set the show string of this list
		memset(pAllListUnit[0]->m_pList[ k ]->m_ShowString, 0, sizeof(pAllListUnit[0]->m_pList[ k ]->m_ShowString) ) ;
		pAllListUnit[0]->m_pList[ k ]->SetState( LIST_UP ) ;
	}

	if( nTotal <= 3 )
	{
		for( int j=0; j<nTotal; j++ )
		{
			strcpy( pAllListUnit[0]->m_pList[ j ]->m_ShowString, MapFile[j].m_sFileName );
		}
	}
	else
	{
		for( int j=nCurrent; j<(nCurrent+3); j++ )
		{
			strcpy( pAllListUnit[0]->m_pList[ j - nCurrent ]->m_ShowString, MapFile[j].m_sFileName );
		}
	}

	return nCurrent;
}

⌨️ 快捷键说明

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