📄 precedencetable.cpp
字号:
//////////////////////////////////////////////////////////////////////////////// Filename : PrecedenceTable.cpp// Written by : excel96// Description : // "冈磊" 规瘤甫 困茄 快急鼻 拌魂阑 困茄 努贰胶捞促.// 俺喊利牢 阁胶磐 按眉 救俊 粮犁窍促啊, 阁胶磐啊 磷芭唱 软趋 寸且 锭啊 // 登搁 敲饭捞绢啊 酒捞袍阑 冈芭唱, 软趋阑 且 荐 乐绰 沥寸茄 鼻府甫 啊瘤绊// 乐绰瘤甫 八荤茄促.//////////////////////////////////////////////////////////////////////////////#include "PrecedenceTable.h"#include "Creature.h"#include "StringStream.h"//////////////////////////////////////////////////////////////////////////////// class PrecedenceElement member methods//////////////////////////////////////////////////////////////////////////////PrecedenceElement::PrecedenceElement(){ m_Name = ""; m_PartyID = -1; m_Damage = 0; getCurrentTime(m_Deadline);}void PrecedenceElement::setNextTime(void){ getCurrentTime(m_Deadline); m_Deadline.tv_sec += 30;}string PrecedenceElement::toString(void) const{ StringStream msg; msg << "PrecedenceElement(" << "Name:" << m_Name << ",PartyID:" << m_PartyID << ",Damage:" << m_Damage << ")"; return msg.toString();}//////////////////////////////////////////////////////////////////////////////// class PrecedenceTable member methods//////////////////////////////////////////////////////////////////////////////PrecedenceTable::PrecedenceTable(){ m_FirstAttackerName = ""; m_FirstAttackerPartyID = 0; m_HostName = ""; m_HostPartyID = 0; m_bComputeFlag = false;}PrecedenceTable::~PrecedenceTable(){ // 农府媚 甘阑 厚款促. hash_map<string, PrecedenceElement*>::iterator itr = m_CreatureMap.begin(); for (; itr != m_CreatureMap.end(); itr++) { SAFE_DELETE(itr->second); } m_CreatureMap.clear(); // 颇萍 甘阑 厚款促. hash_map<int, PrecedenceElement*>::iterator itr2 = m_PartyMap.begin(); for (; itr2 != m_PartyMap.end(); itr2++) { SAFE_DELETE(itr2->second); } m_PartyMap.clear();}/*void PrecedenceTable::addPrecedence(Creature* pCreature, int damage){ Assert(pCreature != NULL); // 农府媚 甘捞 厚绢乐促绰 富篮, 弥檬狼 傍拜磊扼绰 富捞促. if (m_CreatureMap.empty()) { // 急傍磊狼 捞抚阑 技泼秦 林绊... m_FirstAttackerName = pCreature->getName(); // 农府媚 甘俊促 单捞磐甫 眠啊茄促. PrecedenceElement* pElement = new PrecedenceElement; pElement->setName(pCreature->getName()); pElement->setPartyID(-1); pElement->setDamage(damage); pElement->setNextTime(); m_CreatureMap[pCreature->getName()] = pElement; } else { hash_map<string, PrecedenceElement*>::iterator itr = m_CreatureMap.find(pCreature->getName()); if (itr == m_CreatureMap.end()) { // 捞傈俊 傍拜阑 窍瘤 臼疽促搁 单捞磐甫 货肺 积己秦 霖促. PrecedenceElement* pElement = new PrecedenceElement; pElement->setName(pCreature->getName()); pElement->setPartyID(-1); pElement->setDamage(damage); pElement->setNextTime(); m_CreatureMap[pCreature->getName()] = pElement; } else { // 捞傈俊 傍拜阑 沁促搁 单捞磐甫 盎脚秦 霖促. PrecedenceElement* pElement = itr->second; pElement->setDamage(pElement->getDamage() + damage); pElement->setNextTime(); } } // 颇萍俊 包茄 拌魂档 秦霖促. // 颇萍俊 啊涝登绢 乐瘤 臼促搁 颇萍 ID啊 0捞促. // 搬惫 0狼 蔼篮 颇萍俊 啊涝登绢 乐瘤 臼篮 磊甸捞 啊茄 单固瘤狼 蔼捞促. int PartyID = pCreature->getPartyID(); if (m_PartyMap.empty()) { PrecedenceElement* pElement = new PrecedenceElement; pElement->setPartyID(PartyID); pElement->setDamage(damage); pElement->setNextTime(); m_PartyMap[PartyID] = pElement; } else { hash_map<int, PrecedenceElement*>::iterator itr = m_PartyMap.find(PartyID); if (itr == m_PartyMap.end()) { PrecedenceElement* pElement = new PrecedenceElement; pElement->setPartyID(PartyID); pElement->setDamage(damage); pElement->setNextTime(); m_PartyMap[PartyID] = pElement; } else { PrecedenceElement* pElement = itr->second; pElement->setDamage(pElement->getDamage() + damage); pElement->setNextTime(); } }}*/void PrecedenceTable::addPrecedence(const string & Name, int PartyID, int damage){ // 农府媚 甘捞 厚绢乐促绰 富篮, 弥檬狼 傍拜磊扼绰 富捞促. if (m_CreatureMap.empty()) { // 急傍磊狼 捞抚阑 技泼秦 林绊... m_FirstAttackerName = Name; // 农府媚 甘俊促 单捞磐甫 眠啊茄促. PrecedenceElement* pElement = new PrecedenceElement; pElement->setName(Name); pElement->setPartyID(-1); pElement->setDamage(damage); pElement->setNextTime(); m_CreatureMap[Name] = pElement; } else { hash_map<string, PrecedenceElement*>::iterator itr = m_CreatureMap.find(Name); if (itr == m_CreatureMap.end()) { // 捞傈俊 傍拜阑 窍瘤 臼疽促搁 单捞磐甫 货肺 积己秦 霖促. PrecedenceElement* pElement = new PrecedenceElement; pElement->setName(Name); pElement->setPartyID(-1); pElement->setDamage(damage); pElement->setNextTime(); m_CreatureMap[Name] = pElement; } else { // 捞傈俊 傍拜阑 沁促搁 单捞磐甫 盎脚秦 霖促. PrecedenceElement* pElement = itr->second; pElement->setDamage(pElement->getDamage() + damage); pElement->setNextTime(); } } // 颇萍俊 包茄 拌魂档 秦霖促. // 颇萍俊 啊涝登绢 乐瘤 臼促搁 颇萍 ID啊 0捞促. // 搬惫 0狼 蔼篮 颇萍俊 啊涝登绢 乐瘤 臼篮 磊甸捞 啊茄 单固瘤狼 蔼捞促.// int PartyID = PartyID; if (m_PartyMap.empty()) { PrecedenceElement* pElement = new PrecedenceElement; pElement->setPartyID(PartyID); pElement->setDamage(damage); pElement->setNextTime(); m_PartyMap[PartyID] = pElement; } else { hash_map<int, PrecedenceElement*>::iterator itr = m_PartyMap.find(PartyID); if (itr == m_PartyMap.end()) { PrecedenceElement* pElement = new PrecedenceElement; pElement->setPartyID(PartyID); pElement->setDamage(damage); pElement->setNextTime(); m_PartyMap[PartyID] = pElement; } else { PrecedenceElement* pElement = itr->second; pElement->setDamage(pElement->getDamage() + damage); pElement->setNextTime(); } } // 促矫 拌魂窍档废 窍扁 困秦辑.. by sigi. 2002.10.14 m_bComputeFlag = false;}void PrecedenceTable::heartbeat(const Timeval& currentTime){ hash_map<string, PrecedenceElement*>::iterator c_before = m_CreatureMap.end(); hash_map<string, PrecedenceElement*>::iterator c_current = m_CreatureMap.begin(); while (c_current != m_CreatureMap.end()) { PrecedenceElement* pElement = c_current->second; Assert(pElement != NULL); if (pElement->getDeadline() < currentTime) { if (c_before == m_CreatureMap.end()) { m_CreatureMap.erase(c_current); c_current = m_CreatureMap.begin(); } else { m_CreatureMap.erase(c_current); c_current = c_before; c_current++; } } else { c_before = c_current++; } } hash_map<string, PrecedenceElement*>::iterator p_before = m_CreatureMap.end(); hash_map<string, PrecedenceElement*>::iterator p_current = m_CreatureMap.begin(); while (p_current != m_CreatureMap.end()) { PrecedenceElement* pElement = p_current->second; Assert(pElement != NULL); if (pElement->getDeadline() < currentTime) { if (p_before == m_CreatureMap.end()) { m_CreatureMap.erase(p_current); p_current = m_CreatureMap.begin(); } else { m_CreatureMap.erase(p_current); p_current = p_before; p_current++; } } else { p_before = p_current++; } }}void PrecedenceTable::compute(void){ // 捞固 拌魂沁栏搁 救茄促. by sigi. 2002.10.14 if (m_bComputeFlag) return; int MaxDamage = 0; string MaxDamageName = ""; string SecondDamageName = ""; int MaxDamagePartyID = 0; int SecondDamagePartyID = 0; Damage_t TotalDamage = 0; // 刚历 农府媚 甘阑 八祸茄促. hash_map<string, PrecedenceElement*>::const_iterator itr = m_CreatureMap.begin(); for (; itr != m_CreatureMap.end(); itr++) { PrecedenceElement* pElement = itr->second; Assert(pElement != NULL); if (MaxDamage < pElement->getDamage()) { if (MaxDamageName == "") { MaxDamageName = pElement->getName(); MaxDamage = pElement->getDamage(); } else { SecondDamageName = MaxDamageName; MaxDamageName = pElement->getName(); MaxDamage = pElement->getDamage(); } } TotalDamage += pElement->getDamage(); } m_TotalDamage = TotalDamage; if (MaxDamageName != "") { // 弥绊狼 单固瘤甫 霖 磊啊 急傍磊扼搁, // 40+20 = 60 捞 登绢 林牢捞 等促. if (MaxDamageName == m_FirstAttackerName) { m_HostName = MaxDamageName; } // 弥措 单固瘤甫 霖 磊啊 急傍磊啊 酒聪扼搁, // 滴锅掳肺 单固瘤甫 腹捞 霖 磊啊, 急傍磊老 版快 30+20捞 登绢 林牢捞 等促. // 滴锅掳肺 单固瘤甫 腹捞 霖 磊啊 急傍磊啊 酒聪扼搁, // 弥措 单固瘤甫 霖 磊啊 林牢捞 等促. else { if (SecondDamageName != "" && SecondDamageName == m_FirstAttackerName) { m_HostName = SecondDamageName; } else { m_HostName = MaxDamageName; } } } else { // 弥措 单固瘤甫 霖 磊啊 绝阑 府绰 绝摆瘤父, // 趣矫扼档 弊繁 版快啊 乐促搁 急傍磊甫 林牢栏肺 茄促. m_HostName = m_FirstAttackerName; } // 颇萍俊 包茄 沥焊档 拌魂秦 林绢具 茄促. // 颇萍 沥焊 拌魂俊 乐绢辑 蜡狼且 痢篮 颇萍 ID啊 0牢 惑怕, // 溜 颇萍俊 啊涝登绢 乐瘤 臼篮 磊甸狼 单固瘤档 鞍捞 拌魂茄促绰 痢捞促. // 父老 弥措 单固瘤甫 涝腮 颇萍ID啊 0捞扼搁, 溜 颇萍俊 啊涝登绢 乐瘤 臼篮 // 荤恩甸捞 弥措 单固瘤甫 涝躯促搁, HostPartyID啊 0捞 等促. // 捞 版快俊绰 颇萍俊 啊涝登绢 乐瘤 臼篮 荤恩甸捞 葛滴 鼻府甫 啊廉辑绰 帮鄂窍促. // 弊矾骨肺 canLoot唱 canDrainBlood俊辑 颇萍 ID啊 0捞 酒囱瘤甫 八荤秦具 且 巴捞促. MaxDamage = 0; MaxDamagePartyID = -1; SecondDamagePartyID = -1; hash_map<int, PrecedenceElement*>::const_iterator itr2 = m_PartyMap.begin(); for (; itr2 != m_PartyMap.end(); itr2++) { PrecedenceElement* pElement = itr2->second; Assert(pElement != NULL); if (MaxDamage < pElement->getDamage()) { if (MaxDamagePartyID == -1) { MaxDamagePartyID = pElement->getPartyID(); MaxDamage = pElement->getDamage(); } else { SecondDamagePartyID = MaxDamagePartyID; MaxDamagePartyID = pElement->getPartyID(); MaxDamage = pElement->getDamage(); } } } if (MaxDamagePartyID != -1) { // 弥绊狼 单固瘤甫 霖 颇萍啊 急傍 颇萍扼搁, // 40+20 = 60 捞 登绢 林牢捞 等促. if (MaxDamagePartyID == m_FirstAttackerPartyID) { m_HostPartyID = MaxDamagePartyID; } // 弥措 单固瘤甫 霖 颇萍啊 急傍磊啊 酒聪扼搁, // 滴锅掳肺 单固瘤甫 腹捞 霖 颇萍啊, 急傍颇萍老 版快 30+20捞 登绢 林牢捞 等促. // 滴锅掳肺 单固瘤甫 腹捞 霖 颇萍啊 急傍颇萍啊 酒聪扼搁, // 弥措 单固瘤甫 霖 颇萍啊 林牢捞 等促. else { if (SecondDamagePartyID != -1 && SecondDamagePartyID == m_FirstAttackerPartyID) { m_HostPartyID = SecondDamagePartyID; } else { m_HostPartyID = MaxDamagePartyID; } } } else { // 弥措 单固瘤甫 霖 磊啊 绝阑 府绰 绝摆瘤父, // 趣矫扼档 弊繁 版快啊 乐促搁 急傍磊甫 林牢栏肺 茄促. m_HostPartyID = m_FirstAttackerPartyID; } m_bComputeFlag = true;}bool PrecedenceTable::canLoot(Creature* pCreature) const{ // 快急鼻阑 啊柳 磊扼搁 风飘且 荐 乐促. if (m_HostName == pCreature->getName()) return true; // 快急鼻阑 啊柳 颇萍俊 啊涝登绢 乐促搁 风飘且 荐 乐促. int PartyID = pCreature->getPartyID(); if (PartyID != 0 && m_HostPartyID == PartyID) return true; return false;}bool PrecedenceTable::canDrainBlood(Creature* pCreature) const{ // 快急鼻阑 啊柳 磊扼搁 风飘且 荐 乐促. if (m_HostName == pCreature->getName()) return true; // 快急鼻阑 啊柳 颇萍俊 啊涝登绢 乐促搁 风飘且 荐 乐促. int PartyID = pCreature->getPartyID(); if (PartyID != 0 && m_HostPartyID == PartyID) return true; return false;}bool PrecedenceTable::canGainRankExp(Creature* pCreature) const{ // 阁胶磐啊 罐篮 单固瘤狼 醚钦俊辑 1/4阑 檬苞茄 父怒 单固瘤甫 玲促搁 拌鞭 版氰摹甫 掘阑 荐 乐促. hash_map<string, PrecedenceElement*>::const_iterator itr = m_CreatureMap.find( pCreature->getName() ); if ( itr == m_CreatureMap.end() ) return false; return ( m_TotalDamage >> 2 ) < itr->second->getDamage();}double PrecedenceTable::getDamagePercent(const string& Name, int PartyID) const{ if ( m_TotalDamage == 0 ) return 0.0; double ownDamage = 0.0; hash_map<string, PrecedenceElement*>::const_iterator itr = m_CreatureMap.find(Name); if ( itr != m_CreatureMap.end() ) { ownDamage = (double)(itr->second->getDamage()); } double partyDamage = 0.0; if ( PartyID != 0 ) { hash_map<int, PrecedenceElement*>::const_iterator itr = m_PartyMap.find(PartyID); if ( itr != m_PartyMap.end() ) { partyDamage = (double)(itr->second->getDamage()); } } double maxDamage = ( ownDamage > partyDamage ? ownDamage : partyDamage ); return maxDamage / (double)m_TotalDamage;}string PrecedenceTable::toString(void) const{ StringStream msg; msg << "PrecedenceTable(" << "FirstAttackerName:" << m_FirstAttackerName << ",FirstAttackerPartyID:" << m_FirstAttackerPartyID << ",HostName:" << m_HostName << ",HostPartyID:" << m_HostPartyID << ",ComputeFlag:" << m_bComputeFlag; msg << "\n,CreatureMap:\n"; hash_map<string, PrecedenceElement*>::const_iterator itr1 = m_CreatureMap.begin(); for (; itr1 != m_CreatureMap.end(); itr1++) { msg << itr1->second->toString() << ","; } msg << "\n,PartyMap:\n"; hash_map<int, PrecedenceElement*>::const_iterator itr2 = m_PartyMap.begin(); for (; itr2 != m_PartyMap.end(); itr2++) { msg << itr2->second->toString() << ","; } msg << ")"; return msg.toString();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -