代码拉取完成,页面将自动刷新
#include "StdAfx.h"
#include "GameMir.h"
#include ".\gamemir.h"
#define DIR_PRE "data\\"
CGameMir::CDataManager::CDataManager(void)
{
LoadDoorLink();
LoadMapTitle();
LoadMiniMap();
LoadBindItems();
}
CGameMir::CDataManager::~CDataManager(void)
{
}
bool CGameMir::CDataManager::GetMap(const std::string& name, sMap** map)
{
for(tMapList::iterator pos=m_Maps.begin();pos!=m_Maps.end();pos++)
{
if ( pos->mapname == name )
{
*map=&(*pos);
return true;
}
}
*map=NULL;
return false;
}
CGameMir::sMap* CGameMir::CDataManager::InsertMap(std::string name)
{
sMap* pmap;
if(GetMap(name,&pmap))
return pmap;
sMap map;
map.mapname=name;
m_Maps.push_back(map);
if(GetMap(name,&pmap))
return pmap;
return NULL;
}
void CGameMir::CDataManager::LoadDoorLink(void)
{
// doorlink.ini
CFile doorlink_ini((CGameMir::GetMainDir()+DIR_PRE"doorlink.ini").c_str(),CFile::typeBinary|CFile::modeRead|CFile::shareDenyWrite);
long flen=doorlink_ini.GetLength();
char*pBuf=new char[flen+1];
ZeroMemory(pBuf,flen+1);
doorlink_ini.Read(pBuf,flen);
pBuf[flen]=static_cast<char>(0);
std::wstring text;
LPWSTR UBuf=new WCHAR[flen+1];;
text=ToUnicode(pBuf,UBuf,flen);
delete[]pBuf;
delete[]UBuf;
std::vector<std::wstring> Lines;
const boost::wregex reSplit(L"\\s*\\n\\s*",boost::regbase::normal|boost::regbase::icase);
const boost::wregex reDoorLink(L"^(\\S+)\\s+(\\d+)\\s+(\\d+)\\s+(\\S+)\\s+(\\d+)\\s+(\\d+)(?:\\s+\\[>>(.+?)\\])?$",boost::regbase::normal|boost::regbase::icase);
const boost::wregex reDoorDist(L"^(.+?)\\s+(\\d+)\\s+(\\d+)\\s+\\1\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)$",boost::regbase::normal|boost::regbase::icase);
boost::regex_split(std::back_inserter(Lines),text,reSplit);
boost::wsmatch match;
int cnt1=0,cnt2=0;
char cBuf[STRING_BUFFER_LENGTH+1];
for(std::vector<std::wstring>::iterator pos=Lines.begin();pos!=Lines.end();pos++)
{
if (boost::regex_match( *pos, match, reDoorLink))
{
sDoorLink dlink;
dlink.source.mapname=ToAnsi(match.str(1).c_str(),cBuf,STRING_BUFFER_LENGTH);
dlink.source.pos.x=boost::lexical_cast<int>(match.str(2));
dlink.source.pos.y=boost::lexical_cast<int>(match.str(3));
dlink.dest.mapname=ToAnsi(match.str(4).c_str(),cBuf,STRING_BUFFER_LENGTH);
dlink.dest.pos.x=boost::lexical_cast<int>(match.str(5));
dlink.dest.pos.y=boost::lexical_cast<int>(match.str(6));
dlink.dlg_name=ToAnsi(match.str(7).c_str(),cBuf,STRING_BUFFER_LENGTH);
sMap* map=NULL;
map=InsertMap(dlink.dest.mapname);
if (map==NULL)
{
throw "氝樓華芞囮啖1";
}
map=InsertMap(dlink.source.mapname);
if (map==NULL)
{
throw "氝樓華芞囮啖2";
}
map->DoorLinks.push_back(dlink);
cnt1++;
}
else if (boost::regex_match( *pos, match, reDoorDist))
{
sDoorDist ddist;
ddist.mapname=ToAnsi(match.str(1).c_str(),cBuf,STRING_BUFFER_LENGTH);
ddist.pos1.x=boost::lexical_cast<int>(match.str(2));
ddist.pos1.y=boost::lexical_cast<int>(match.str(3));
ddist.pos2.x=boost::lexical_cast<int>(match.str(4));
ddist.pos2.y=boost::lexical_cast<int>(match.str(5));
ddist.dist=boost::lexical_cast<int>(match.str(6));
sMap* map=NULL;
map=InsertMap(ddist.mapname);
if (map==NULL)
{
throw "氝樓華芞囮啖";
}
map->DoorDists.push_back(ddist);
cnt2++;
}
}
}
void CGameMir::CDataManager::LoadMapTitle(void)
{
// mapinfo.txt
CFile mapinfo_txt((CGameMir::GetMainDir()+DIR_PRE"mapinfo.txt").c_str(),CFile::typeBinary|CFile::modeRead|CFile::shareDenyWrite);
long flen=mapinfo_txt.GetLength();
char*pBuf=new char[flen+1];
ZeroMemory(pBuf,flen+1);
mapinfo_txt.Read(pBuf,flen);
pBuf[flen]=static_cast<char>(0);
std::wstring text;
LPWSTR UBuf=new WCHAR[flen+1];;
text=ToUnicode(pBuf,UBuf,flen);
delete[]pBuf;
delete[]UBuf;
std::vector<std::wstring> Lines;
const boost::wregex reSplit(L"\\s*\\n\\s*",boost::regbase::normal|boost::regbase::icase);
const boost::wregex reMapTitle(L"^\\[(.+?)\\s+(.+?)\\s+.+$",boost::regbase::normal|boost::regbase::icase);
boost::regex_split(std::back_inserter(Lines),text,reSplit);
boost::wsmatch match;
char cBuf[STRING_BUFFER_LENGTH+1];
for(std::vector<std::wstring>::iterator pos=Lines.begin();pos!=Lines.end();++pos)
{
if (boost::regex_match( *pos, match, reMapTitle))
{
sMap* map=NULL;
map=InsertMap(ToAnsi(match.str(1).c_str(),cBuf,STRING_BUFFER_LENGTH));
if (map==NULL)
{
throw "氝樓華芞囮啖";
}
map->maptitle=ToAnsi(match.str(2).c_str(),cBuf,STRING_BUFFER_LENGTH);
}
}
}
void CGameMir::CDataManager::LoadMiniMap(void)
{
// MiniMap.txt
CFile minimap_txt((CGameMir::GetMainDir()+DIR_PRE"MiniMap.txt").c_str(),CFile::typeBinary|CFile::modeRead|CFile::shareDenyWrite);
long flen=minimap_txt.GetLength();
char*pBuf=new char[flen+1];
ZeroMemory(pBuf,flen+1);
minimap_txt.Read(pBuf,flen);
pBuf[flen]=static_cast<char>(0);
std::wstring text;
LPWSTR UBuf=new WCHAR[flen+1];;
text=ToUnicode(pBuf,UBuf,flen);
delete[]pBuf;
delete[]UBuf;
std::vector<std::wstring> Lines;
const boost::wregex reSplit(L"\\s*\\n\\s*",boost::regbase::normal|boost::regbase::icase);
const boost::wregex reMapTitle(L"^(\\S+)\\s+(\\d+)$",boost::regbase::normal|boost::regbase::icase);
boost::regex_split(std::back_inserter(Lines),text,reSplit);
boost::wsmatch match;
m_MiniMaps.clear();
char cBuf[STRING_BUFFER_LENGTH+1];
for(std::vector<std::wstring>::iterator pos=Lines.begin();pos!=Lines.end();pos++)
{
if (boost::regex_match( *pos, match, reMapTitle))
{
std::pair<std::string,WORD> item;
item.first=ToAnsi(match.str(1).c_str(),cBuf,STRING_BUFFER_LENGTH);
item.second=boost::lexical_cast<WORD>(match.str(2));
m_MiniMaps.insert(item);
}
}
}
void CGameMir::CDataManager::LoadBindItems(void)
{
// BindItems.txt
CFile BindItems_txt((CGameMir::GetMainDir()+DIR_PRE"BindItems.txt").c_str(),CFile::typeBinary|CFile::modeRead|CFile::shareDenyWrite);
long flen=BindItems_txt.GetLength();
char*pBuf=new char[flen+1];
ZeroMemory(pBuf,flen+1);
BindItems_txt.Read(pBuf,flen);
pBuf[flen]=static_cast<char>(0);
std::wstring text;
LPWSTR UBuf=new WCHAR[flen+1];;
text=ToUnicode(pBuf,UBuf,flen);
delete[]pBuf;
delete[]UBuf;
std::vector<std::wstring> Lines;
const boost::wregex reSplit(L"\\s*\\n\\s*",boost::regbase::normal|boost::regbase::icase);
const boost::wregex reBindItem(L"^(.+?)\\s+(.+)$",boost::regbase::normal|boost::regbase::icase);
boost::regex_split(std::back_inserter(Lines),text,reSplit);
boost::wsmatch match;
m_BandItems.clear();
char cBuf[STRING_BUFFER_LENGTH+1];
for(std::vector<std::wstring>::iterator pos=Lines.begin();pos!=Lines.end();pos++)
{
if (boost::regex_match( *pos, match, reBindItem))
{
std::pair<std::string,std::string> item;
item.first=ToAnsi(match.str(1).c_str(),cBuf,STRING_BUFFER_LENGTH);
item.second=ToAnsi(match.str(2).c_str(),cBuf,STRING_BUFFER_LENGTH);
m_BandItems.insert(item);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。