大家都知道在战网,Ghost自动主机,建立dota游戏的时候,胜负的判断是必须推倒生命之树或者冰封王座,但有的时候对面很早就退了,大家为了战绩也必须慢慢推完,否则没有战绩。
于是我修改ghost自动主胜负判断,类似VS平台一样.
(
http://cid-4b5bdf2f7fd33dee.office.live.com/self.aspx/pvpgn/ghostcb%5E_release%5E_win32%5E_x86.rar,在这可以直接下载我已经修改编译好的)
当没有推完的情况下,判定最后退出游戏的一方为胜.
首先去
http://www.codelain.com/官方下载ghost源码包.(我用的版本ghost17.1cb3.6source.zip:http://www.codelain.com/forum/index.php?topic=13083.0)
1 在game.cpp 中,修改析构函数CGame :: ~CGame( )(注保存游戏是在析构函数中实现的)
CGame :: ~CGame( )
{
if( m_CallableGameAdd && m_CallableGameAdd->GetReady( ) )
{
if( m_CallableGameAdd->GetResult( ) > 0 )
{
CONSOLE_Print( "[GAME: " + m_GameName + "] saving player/stats data to database" );
// store the CDBGamePlayers in the database
uint32_t max_leave_time=0;//记录玩家最晚退出游戏的时间
uint32_t winner=0;
bool is_save=true;
for( vector<CDBGamePlayer *> :: iterator i = m_DBGamePlayers.begin( ); i != m_DBGamePlayers.end( ); i++ )
{
m_GHost->m_Callables.push_back( m_GHost->m_DB->ThreadedGamePlayerAdd( m_CallableGameAdd->GetResult( ), (*i)->GetName( ), (*i)->GetIP( ), (*i)->GetSpoofed( ), (*i)->GetSpoofedRealm( ), (*i)->GetReserved( ), (*i)->GetLoadingTime( ), (*i)->GetLeft( ), (*i)->GetLeftReason( ), (*i)->GetTeam( ), (*i)->GetColour( ) ) );
if((*i)->GetLeft()>max_leave_time)
{
max_leave_time=(*i)->GetLeft();
winner=(*i)->GetTeam()+1;//最后退出游戏的一方为胜方,1 近卫 2 天灾
}
}
if( max_leave_time<300)//游戏小于5分钟不记录战绩
{
is_save=false;
CONSOLE_Print( "[GAME: " + m_GameName + "] game end in 5 min,Don't store the stats" );
}
// store the stats in the database
if(is_save && m_Stats )
{
if(m_Stats->getWinner()<=0)//ok
{
CONSOLE_Print( "[GAME: " + m_GameName + "] using winner by judeg last leave" );
m_Stats->setWinner(winner);
}else//表示推倒了生命之树或冰封王座,因此不修改
{
CONSOLE_Print( "[GAME: " + m_GameName + "] using winner by ghost" );
}
m_Stats->Save( m_GHost, m_GHost->m_DB, m_CallableGameAdd->GetResult( ) );
}
}
else
CONSOLE_Print( "[GAME: " + m_GameName + "] unable to save player/stats data to database" );
m_GHost->m_DB->RecoverCallable( m_CallableGameAdd );
delete m_CallableGameAdd;
m_CallableGameAdd = NULL;
}
2 在stats.h中,CStatsDota的基类添加两个虚函数,用于设置winner。
virtual uint32_t getWinner()
{
return 0;
}
virtual void setWinner(uint32_t winner)
{
}
3. 在statsdota.h实现两个虚函数
virtual uint32_t getWinner()
{
return m_Winner;
}
virtual void setWinner(uint32_t winner)
{
this->m_Winner=winner;
}
ok,这样ghost在未推完的情况下也能统计胜负了.
个人联系方式:
kuramawzw@163.com
QQ:370180103
如有问题请pm我。
posted on 2010-07-01 11:01
kuramawzw 阅读(765)
评论(0) 编辑 收藏 引用 所属分类:
战网 PVPGN & GHOST