www.pudn.com > 3D_OnlineGame_Humen.rar > MapInfo.cpp
#include "stdafx.h" #include "XMudClient.h" #include "D3DRMScreen.h" #include "MapInfo.h" #include "MenuCreateNew.h" #include "FacePlate.h" #include "MyMusic.h" #include#include "MyDInput.h" extern char g_szReceive[]; extern char g_tszPathName[256]; //extern char g_szSrvActiveBuf[2048]; extern rmfullglobals myglobs; extern D3DAppInfo* d3dapp; extern LPDIRECT3DRM3 g_lpD3DRM; extern CRITICAL_SECTION csAnimation; extern CList animationlist; extern animationCallbackArgs *cb; extern CList maplist; extern CList playerlist; extern CPlayerInfo * lpPlayerInfo; extern CList skilllist; extern CSkillInfo * lpSkillInfo; extern CList equiplist; extern CList equiprentlist; extern CStringList g_equiprentlist; extern CEquipInfo *lpEquipInfo; extern CList exitlist; extern CExitInfo *lpExitInfo; extern int g_nGameState; extern BOOL g_bClientNet; extern LPDIRECT3DRMFRAME3 g_lpplayer; extern void QuitResolution(void); BOOL GetNewMap(CString strtmp) { CMapInfo * lpMapInfo; int i,j; CStringList strls,strlsmap; CString parm; double ftmp; LPTSTR lpsz; char *ps; BOOL bFindHead=FALSE; // strtmp = g_szReceive; lpsz = strtmp.GetBuffer(strtmp.GetLength()+1); parm=CString("\t"); ps=strtok(lpsz,(const char*)parm); strls.AddTail(ps); for(;;) { ps=strtok(NULL,(const char*)parm); if(ps==NULL)break; strls.AddTail(ps); } j = strls.GetCount(); for(i=0;i m_sCNAME = strtmp.Mid(1,strtmp.GetLength()-2); strtmp = strlsmap.GetNext(pos); lpMapInfo->m_sENAME = strtmp.Mid(1,strtmp.GetLength()-2); strtmp = strlsmap.GetNext(pos); lpMapInfo->m_sXFILENAME = strtmp.Mid(1,strtmp.GetLength()-2); maplist.AddTail(lpMapInfo); for(i=0;i m_sEXIT_DBF = strtmp.Mid(1,strtmp.GetLength()-2); strtmp = strlsmap.GetAt(strlsmap.FindIndex(i+2)); lpMapInfo->m_sCNAME = strtmp.Mid(1,strtmp.GetLength()-2);; strtmp = strlsmap.GetAt(strlsmap.FindIndex(i+3)); lpMapInfo->m_sENAME = strtmp.Mid(1,strtmp.GetLength()-2);; strtmp = strlsmap.GetAt( strlsmap.FindIndex(i+4)); strtmp = strtmp.Mid(1,strtmp.GetLength()-2); lpsz = strtmp.GetBuffer(20); ftmp=strtod(lpsz,'\0'); strtmp.ReleaseBuffer(); lpMapInfo->m_fPOSITION_X = ftmp; strtmp = strlsmap.GetAt( strlsmap.FindIndex(i+5)); strtmp = strtmp.Mid(1,strtmp.GetLength()-2); lpsz = strtmp.GetBuffer(20); ftmp=strtod(lpsz,'\0'); strtmp.ReleaseBuffer(); lpMapInfo->m_fPOSITION_Z = ftmp; maplist.AddTail(lpMapInfo); i += 5; } else if(!stricmp(strtmp,"'NPCDATA'")) { lpMapInfo = new CMapInfo; strtmp = strlsmap.GetAt(strlsmap.FindIndex(i+1)); lpMapInfo->m_sCNAME = strtmp.Mid(1,strtmp.GetLength()-2); strtmp = strlsmap.GetAt(strlsmap.FindIndex(i+2)); lpMapInfo->m_sENAME = strtmp.Mid(1,strtmp.GetLength()-2); strtmp = strlsmap.GetAt(strlsmap.FindIndex(i+3)); lpMapInfo->m_sXFILENAME = strtmp.Mid(1,strtmp.GetLength()-2); strtmp = strlsmap.GetAt(strlsmap.FindIndex(i+4)); lpMapInfo->m_sNPC_DBF = strtmp.Mid(1,strtmp.GetLength()-2); if(lpMapInfo->m_sNPC_DBF.IsEmpty()) lpMapInfo->m_sNPC_DBF = "百姓"; strtmp = strlsmap.GetAt(strlsmap.FindIndex(i+5)); lpMapInfo->m_sMAPINFO = strtmp.Mid(1,strtmp.GetLength()-2); strtmp = strlsmap.GetAt(strlsmap.FindIndex(i+6)); lpMapInfo->szPerson = strtmp.Mid(1,strtmp.GetLength()-2); maplist.AddTail(lpMapInfo); i += 6; } else if(!stricmp(strtmp,"'PLAYDATA'")) { lpMapInfo = new CMapInfo; strtmp = strlsmap.GetAt(strlsmap.FindIndex(i+1)); lpMapInfo->m_sCNAME = strtmp.Mid(1,strtmp.GetLength()-2); strtmp = strlsmap.GetAt(strlsmap.FindIndex(i+2)); lpMapInfo->m_sENAME = strtmp.Mid(1,strtmp.GetLength()-2); strtmp = strlsmap.GetAt(strlsmap.FindIndex(i+3)); lpMapInfo->m_sXFILENAME = strtmp.Mid(1,strtmp.GetLength()-2); strtmp = strlsmap.GetAt(strlsmap.FindIndex(i+4)); lpMapInfo->m_sPLAYER_DBF = strtmp.Mid(1,strtmp.GetLength()-2); if(lpMapInfo->m_sPLAYER_DBF.IsEmpty()) lpMapInfo->m_sPLAYER_DBF = "百姓"; strtmp = strlsmap.GetAt(strlsmap.FindIndex(i+5)); lpMapInfo->m_sMAPINFO = strtmp.Mid(1,strtmp.GetLength()-2); strtmp = strlsmap.GetAt(strlsmap.FindIndex(i+6)); lpMapInfo->szPerson = strtmp.Mid(1,strtmp.GetLength()-2); strtmp = strlsmap.GetAt(strlsmap.FindIndex(i+7)); lpMapInfo->szPlayerIP = strtmp.Mid(1,strtmp.GetLength()-2); strtmp = strlsmap.GetAt(strlsmap.FindIndex(i+8)); lpMapInfo->m_sTITLE = strtmp.Mid(1,strtmp.GetLength()-2); maplist.AddTail(lpMapInfo); i += 8; } } return TRUE; } CString GetMapMessage(CString sFileName) { CString buf; CFile file; char szFileName[256]; strcpy(szFileName,g_tszPathName); strcat(szFileName,"\\muddata\\mapmsg.dat"); if( !file.Open( szFileName, CFile::modeRead , NULL ) ) { return sFileName; } CArchive ar(&file,CArchive::load); while(ar.ReadString(buf)) { if( sFileName == buf ) { ar.ReadString(buf); sFileName = CString("〔") + sFileName + CString("〕") + buf; break; } } ar.Close(); file.Close(); return sFileName; } BOOL CheckExitCondiInt(int iTempInt,int iCheck,int iString) { BOOL bCheck = TRUE; switch(iCheck) { case 1: if(iTempInt == iString) bCheck = TRUE; else bCheck = FALSE; break; case 2: if(iTempInt > iString) bCheck = TRUE; else bCheck = FALSE; break; case 3: if(iTempInt < iString) bCheck = TRUE; else bCheck = FALSE; break; case 4: if(iTempInt != iString) bCheck = TRUE; else bCheck = FALSE; break; default: break; } if(bCheck) return TRUE; return FALSE; } BOOL CheckExitCondiString(CString sTempStr,int iCheck,CString sString) { BOOL bCheck = TRUE; switch(iCheck) { case 1: if(sTempStr == sString) bCheck = TRUE; else bCheck = FALSE; break; case 2: break; case 3: break; case 4: if(sTempStr != sString) bCheck = TRUE; else bCheck = FALSE; break; default: break; } if(bCheck) return TRUE; return FALSE; } void ShowExitmsg(CString sExitMsg) { CString buf; CFile file; char tmpFilName[256]; strcpy(tmpFilName,g_tszPathName); strcat(tmpFilName,"\\muddata\\exitmsg.dat"); if( !file.Open( tmpFilName, CFile::modeRead , NULL ) ) { return; } CArchive ar(&file,CArchive::load); while(ar.ReadString(buf)) { buf.MakeUpper(); if( sExitMsg == buf ) { ar.ReadString(buf); sExitMsg = buf; break; } } ar.Close(); file.Close(); // m_MsgWnd.AddMsg(sExitMsg); return; } //cary ChangeMapReceive extern CString lastRcvBuf; BOOL ChangeMapReceive() { CStringList strls; CString strtmp,parm,sendToclient; CString sSendToClient,sSendToServer; char *ps; char tmpreceive[8192]; //開啟發送在切換地圖期間接收到的消息的timer //cary SetTimer(myglobs.hWndMain, TIMER_SENDMSG, 250, NULL); lstrcpy(tmpreceive,lastRcvBuf); parm=CString(" \n\t\r"); ps=strtok(tmpreceive,(const char*)parm); strls.AddTail(ps); for(;;) { ps=strtok(NULL,(const char*)parm); if(ps==NULL)break; strls.AddTail(ps); } strtmp=strls.GetHead(); strtmp.MakeUpper(); //dainty remove 2000/7/14 if(strtmp!="OK") { strls.RemoveAll(); g_nGameState = GAME_MAIN; return FALSE;//加入另一張地圖不成功 } //dainty end strls.RemoveAll(); //刪除所有3D場景和人物 ReleaseD3DScreen(); maplist.RemoveAll(); EnterCriticalSection(&csAnimation); animationlist.RemoveAll(); LeaveCriticalSection(&csAnimation); exitlist.RemoveAll(); //create maplist if(!GetNewMap(lastRcvBuf)) { Msg("接收數據錯誤"); QuitDirectMusic(); QuitResolution(); QuitIME(myglobs.hWndMain); exit(1); } g_bClientNet = TRUE;//accept connect // //建立新的場景 // if(CreateNewScreen()) { if (!BuildScene(g_lpD3DRM, myglobs.dev, myglobs.view, myglobs.scene, myglobs.camera)) { goto error; } g_nGameState = GAME_MAIN; // AppPause(FALSE); return TRUE; } goto error; error: g_nGameState = GAME_MAIN; // AppPause(FALSE); return TRUE; } BOOL CreateNewScreen() { HRESULT rval; // // 建立主場景和攝像機場景 // Create the master scene frame and camera frame // rval = g_lpD3DRM->CreateFrame(NULL, &myglobs.scene); if (rval != D3DRM_OK) { Msg("Failed to create the master scene frame.\n%s", D3DAppErrorToString(rval)); return FALSE; } rval = g_lpD3DRM->CreateFrame(myglobs.scene, &myglobs.camera); if (rval != D3DRM_OK) { Msg("Failed to create the camera's frame.\n%s", D3DAppErrorToString(rval)); return FALSE; } rval = myglobs.camera->SetPosition(myglobs.scene, D3DVAL(0.0), D3DVAL(0.0), D3DVAL(0.0)); if (rval != D3DRM_OK) { Msg("Failed to position the camera in the frame.\n%s", D3DAppErrorToString(rval)); return FALSE; } g_lpD3DRM->CreateViewport( myglobs.dev, myglobs.camera, MAINFACEXPOS, MAINFACEYPOS, MAINFACEWIELD,MAINFACEHIGH, &myglobs.view ); myglobs.view->SetBack( 5000.0f ); return TRUE; }