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

📄 cbmain.cpp

📁 网页游戏赤壁
💻 CPP
📖 第 1 页 / 共 4 页
字号:

/////////////
//	CBMain.cpp		:	v0010
//	Written by		:	Liu Gang
//	Compiler		:	Microsoft Visual C++ 4.0 & DirectX
//	Library			:	DDraw.Lib & Winmm.lib & dxguid.lib
//	Copyright (C)	:	1996 WayAhead Corporation 
//	v0010			:	Sep.20.1996
//  v0090			:	Sep.11.1997
/////////////
// implementation file

// This file is the major file of the game, includes WinMain()
// and WindowProc(), for entering graph mode and processing main 
// programe cricle.

#include "stdafx.h"	// compatible with MFC
#include <stdio.h>
#include <mmsystem.h>	// timeGetTime()
#include "resource.h"
#include "Assert.h"	// ErrorMessage(), Assert()
#include <stdio.h>
#include <imm.h>

//#include "DDApi.h"	// direct draw object
#include "DDCompo.h"	// Direct Draw objects and components


#include "CBData.h"	// game data, ReadCBSetFile(), ReadMedFile()
#include "CBMap.h"	// game map data
#include "CBGame.h"	// readcbsetfile, readmedfile

#include "cbavi.h"	// FACE_AVI_PLAY() , FACE_AVI_CLOSE()

#include "CBDraw.h"	// DrawMaps(), LoadMaps()
#include "CBMouse.h"	// MOUSE_
#include "CBShadow.h"	// for shadow
#include "puthz.h"

#include "CBMain.h"	

//---------sound
#include "DSApi.h"
//WAVEDYNAMIC	waveBack;
//---------

#include "CBRun.h"
extern	BOOL	RUN_bAUTO;			//declared in CBRun.cpp
extern  BOOL	RUN_DEBUG_bEndGame;	//declared in CBRun.cpp
extern  void RUN_EndGame( int bWin );		// defined in CBRun.cpp

// defined in CBCTRl.cpp, debug for do not die
extern BOOL CTRL_bDebugDie;
// defined in CBCTRl.cpp, debug for upgrade general for one level
extern void CTRL_DebugGeneral( int nUp );

//added by tian yue
#include "Tbnbase.h"
#include "Temperor.h"
extern POINT ThinkDead(WORD Player);	// declared in Temperor.h

//----------LHJ
#include "Marco.h"
#include "DDButton.h"
#include "DDMenu.h"
#include "interfac.h"
#include "interfa1.h"
#include "interfa2.h"

extern	BOOL	FACE_bMessageBox;
extern	CDDMenu		* CurrentMenu;

//////////////////////////////////////////
// to set this flag for DH	Nov.8.1997
extern BOOL IsInSetNetMenu ;
//////////////////////////////////////////

//----------

//#define	_MAIN_DEBUG
extern GFWI_bUpdate;
// debug commandunit, defined in CBCTRl.cpp
extern BOOL CTRL_bDebugCommand;

// Copyright info
char	strCopyright[65];

BOOL        bActive=FALSE;        // is application active?
BOOL		MAIN_bFirst = TRUE;	  // 绕过Bug
BOOL		MAIN_bInitGraph = FALSE;

// palettes
class CDDPalette	pal, palMain;

//added by tian yue
extern PALETTEENTRY	pe[256];
extern PALETTEENTRY	peFadeSave[256];

// DDAPI.h
extern int DD_nSurfaceCounter;			// stores for the number of surfaces have been loaded

BOOL MAIN_AVI_bFullScreen = FALSE;
BOOL MAIN_bRelease = FALSE;
extern int FACE_AVI_FLAG;	// defined in CBAVI.cpp

// 检测是否已经有本游戏的其它实例(进程)在运行了
// 如果有,则返回真
BOOL MAIN_TestInstance( char *wndname );

// 用原始的办法检测光驱
BOOL MAIN_TestCD();
///////////////////////
// MMX tech
// 使用MMX技术的开关
BOOL MAIN_bMMX = FALSE;

// MMX片头
#ifndef	_DEBUG
#define	_MMX_SPLASH_
#endif
#ifdef	_MMX_SPLASH_
	extern "C" BOOL WINAPI IntelSplashInit();
	extern "C" BOOL WINAPI IntelSplash();
//#include "CPUID.h"
	#include "splshapi.h"
	#include "errorapi.h"
	extern int MMXCPUID();
#endif
///////////////////////

///////////////////////
// AVI播放函数
#include "MciApi.h"
#include "VCMApi.h"
///////////////////////

///////////////////////
#define MAIN_CURSOR_WAIT	33
class CDDCursor MAIN_Cursors[4];	// all the cursors
class CDDCursor DDC_Cursor;
// defined in CBFile.cpp
BOOL MAIN_LoadCursors( HWND hwnd, LPCTSTR filename , LPCTSTR path );

BOOL MAIN_InitOthers();
///////////////////////

///////////////////////
// move screen ex
extern BOOL DRAW_bMoveScreenEx;
extern BOOL DRAW_bShowScrollBorder;

// mouse hit test
extern RECT DRAW_rcClient;			// declared in CBDraw.cpp
extern POINT DRAW_ptScreenOffset;	// declared in CBDraw.cpp
//extern int MOUSE_nHitCounter;
//extern struct MOUSE_HITRESULT_STRUCT MOUSE_hitResult[CTRL_TASK_LIST_MAX];

#ifdef	_DEBUG
// for debug only, to confirm that message processes must be done outside run circle
BOOL bInRun=FALSE;
#endif

// Nov.7.1997
// CBAvi.cpp
extern int nCurrentVideoID;	// Video 的句柄
// CBData.cpp
extern int MUSIC_hCDHandle;	// CD Audio 的句柄
// CBData.cpp
extern BOOL MUSIC_bEnable;	// 是否播放CD
extern BOOL EFFECT_bEnable;	// 是否播放音效
///////////////////////

///////////////////////////////Donghai/////////////////////////////////////
#include "network.h"
#include "net_face.h"
extern	int		DP_NetworkInterface(int	Action, HWND   MainWndHandle);
extern	int		DH_ReceiveMessage();
extern	int		DP_ReceiveGameMessages( void );
extern	int		DP_SendGameMessages(/*DWORD to*/);
extern  BOOL	CTRL_TASK_LIST_Send( int nPlayer, CONST struct CTRL_TASK_STRUCT *pTask );	// 发送任务返回真
extern	BOOL	GAME_Network_Begin(void);//网络游戏开始时的初始化
int	DH_ServerInit();
int	DH_ClientInit();
void DH_NetworkReceive();
void DH_NetworkInit();
void DH_ReceiveInit();

int		CB_Counter=0;//在进入战场之前,应该只置0。
int		DH_ComputerTaskNum[CTRL_TASK_LIST_MAX+CTRL_TASK_LIST_MAX];
//int		Games_Status[MAX_PLAYERS+1];//初始化时,应该置为-1。
extern	BYTE                    DP_SendMessageBuff[BUFFER_MAX_BYTE];//用于存储玩家要发送的消息
extern	BYTE					DP_ReadMessage[BUFFER_MAX_BYTE];//用于将消息队列中的消息读出并传给调用者
extern	int						DP_ProviderNO;//用于返回玩家对网络服务的选择
extern	int						DP_SessionNO;//用于返回玩家对已经创建的游戏Session的选择
extern	LPSTR					DP_FullName;//玩家给Session起的名字
extern	LPSTR					DP_NickName;//玩家给本人起的在游戏中的名字
extern	PlayerInfo				DP_PlayerInformation[MAX_PLAYERS];
extern	DPID                    DP_dcoID;        // 用于存储本玩家在网络中ID值
extern	BOOL					GAME_bNetwork;
extern	struct CTRL_TASK_STRUCT	CTRL_TaskList[GAME_PLAYER_MAX][CTRL_TASK_LIST_MAX+CTRL_TASK_LIST_MAX];
///////////////////////////////Donghai/////////////////////////////////////

/*
        The following code is added by Bill 
        The MMXCPUID detected program
        Usage:  BOOL MMXCPUID();
*/
unsigned long MMXFLAG;
#define CPU_MMX                 (MMXFLAG & (unsigned long)(0x01 << 23))

BOOL MMXCPUID()
{
        unsigned int  cpu_type = 0;
        unsigned long cpuIdCount = 0l;
        unsigned long tmp1 = 0l;
        unsigned long tmp2 = 0l;
        unsigned long tmp3 = 0l;
        unsigned long tmp4 = 0l;

        MMXFLAG = 0l;
        _asm {

// CHECK_8086:
                                // 8086 ?
						pushf                   ; push original FLAGS
						pop     ax              ; get original FLAGS
						mov     cx, ax          ; save original FLAGS
						and     ax, 0fffh       ; clear bits 12-15 in FLAGS
						push    ax              ; save new FLAGS value on stack
						popf                    ; replace current FLAGS value
						pushf                   ; get new FLAGS
						pop     ax              ; store new FLAGS in AX
						and     ax, 0f000h      ; if bits 12-15 are set, then
						cmp     ax, 0f000h      ;   processor is an 8086/8088
												; turn on 8086/8088 flag
						je     EXIT_8086        ; jump if processor is 8086/8088
                        jmp             CHECK_80286

EXIT_8086:      
                        mov             cpu_type, 1
                        jmp     EXIT

CHECK_80286:
                        // 80286 ?
						or      cx, 0f000h      ; try to set bits 12-15
						push    cx              ; save new FLAGS value on stack
						popf                    ; replace current FLAGS value
						pushf                   ; get new FLAGS
						pop     ax              ; store new FLAGS in AX
						and     ax, 0f000h      ; if bits 12-15 are clear
												; processor=80286, turn on 80286 flag
						jz      END_80286       ; if no bits set, processor is 80286
                        jmp             CHECK_80386

END_80286:
                        mov     cpu_type, 2
                        jmp             EXIT

CHECK_80386:
                        // 80386 ?
                        pushfd                  ; push original EFLAGS
                        pop     eax             ; get original EFLAGS
                        mov     ecx, eax        ; save original EFLAGS
						xor     eax, 40000h     ; flip AC bit in EFLAGS
						push    eax             ; save new EFLAGS value on stack
						popfd                   ; replace current EFLAGS value
						pushfd                                  ; get new EFLAGS
						pop     eax             ; store new EFLAGS in EAX
						xor     eax, ecx        ; can't toggle AC bit, processor=80386
																		; turn on 80386 processor flag
						jz     END_80386        ; jump if 80386 processor
                        jmp             CHECK_80486

END_80386:
                        mov     cpu_type, 3 
                        jmp     EXIT

CHECK_80486:
                        // 80486 ?
                        push    ecx
                popfd                          
                        mov     eax, ecx
                        xor     eax, 0200000h
                        push    eax
                        popfd
                        pushfd
                        pop     eax
                        xor     eax, ecx
                        je              END_80486
                        jmp     CHECK_PENTIUM
END_80486:
						mov     cpu_type, 4    
						jmp             EXIT

CHECK_PENTIUM:
						xor     eax, eax        ; set up for CPUID instruction
						xor     ebx, ebx
						xor     ecx, ecx
						xor     edx, edx

						inc     eax
						_emit   0x0F 
						_emit   0xA2 ;CPU_ID 

						mov     cpuIdCount, eax

						mov tmp1, eax
						mov tmp2, ebx
						mov tmp3, ecx
						mov tmp4, edx

                        }

        _asm {

EXIT:
        }
        MMXFLAG = tmp4;
        if ( CPU_MMX )
                return TRUE;
        else
                return FALSE;

}
///////////////////////

///////////////////////
// change program state
// returns old state
int	 ChangeProgramState( int nState, int nButtonID )
{
	int OldProgramState = 0;

	switch( nButtonID )
	{
		case BUTTON_PAUSE :
			{
				if( nState == PROGRAM_STATE_PAUSE )
				{
					// to set all button to disable state when you show a menu or dialog
					FACE_SetAllButtonState( BUTTON_DISABLE );
					FACE_SetPauseButtonActive();
					FACE_SetProgramState( PROGRAM_STATE_PAUSE );
				}
				else
				{
					FACE_RestoreAllButtonState();
					FACE_SetProgramState( PROGRAM_STATE_PLAY );
				}
			}
			break;
		case BUTTON_MENU_MAIN_NEWGAME_OK :
			{
#ifdef	_DEBUG
				DWORD timeBegin, timeEnd;
				timeBegin = timeGetTime();
#endif

				// 设置鼠标
				CURSOR_Set( &MAIN_Cursors[0] );

			//---------------
				// load interface
				if( !FACE_LoadAllBmp() )  // to load all bitmap and set the destination surface to blit
										  // all button on---->sBack
				{
					OutputDebugString( "FACE_LoadMaps: Load Interface bitmap failure!\n" );
					return PROGRAM_STATE_ERROR;
				}
#ifdef	_DEBUG
				timeEnd = timeGetTime();
				OutputString( timeEnd-timeBegin, "\n" );
				timeBegin = timeEnd;
#endif
				FACE_ShowAllBmp();

#ifdef	_DEBUG
				timeEnd = timeGetTime();
				OutputString( timeEnd-timeBegin,"\n" );
				timeBegin = timeEnd;
#endif
			//---------------
				// load other maps
				if( !::DRAW_LoadMaps() )
				{
					OutputDebugString( "DRAW_LoadMaps: Load battlefield bitmaps failure!\n" );
					return PROGRAM_STATE_ERROR;
				}

				DD_FadeOutScreen( 5, 10 );


				if( GAME.nMe == 2 )	// 刘备
					GAME_Begin( 0 );
				else				// 曹操
					GAME_Begin( 17 );

#ifdef	_DEBUG
				timeEnd = timeGetTime();
				OutputString( timeEnd-timeBegin,"\n" );
				timeBegin = timeEnd;
#endif
				DRAW_UpdateScreen( FALSE );

				FACE_SetCommandState(COMMAND_STATE_PLAY);

#ifdef	_DEBUG
				timeEnd = timeGetTime();
				OutputString( timeEnd-timeBegin,"\n" );
				timeBegin = timeEnd;
#endif
			}
			break;
		case BUTTON_MENU_MAIN_NETWORK_NEWGAME_OK :
			{
//				WriteLogFile( "Dead.log", "UUU" );
#ifdef	_DEBUG
				DWORD timeBegin, timeEnd;
				timeBegin = timeGetTime();
#endif

//				WriteLogFile( "Dead.log", "LLL" );
				// 设置鼠标
				CURSOR_Set( &MAIN_Cursors[0] );

//				WriteLogFile( "Dead.log", "WWW" );
			//---------------
				// load interface
				if( !FACE_LoadAllBmp() )  // to load all bitmap and set the destination surface to blit
										  // all button on---->sBack
				{
					OutputDebugString( "FACE_LoadMaps: Load Interface bitmap failure!\n" );
					return PROGRAM_STATE_ERROR;
				}
#ifdef	_DEBUG
				timeEnd = timeGetTime();
				OutputString( timeEnd-timeBegin, "\n" );
				timeBegin = timeEnd;
#endif
				FACE_ShowAllBmp();

#ifdef	_DEBUG
				timeEnd = timeGetTime();

⌨️ 快捷键说明

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