#include "stdafx.h"
|
#include "Model.h"
|
|
|
CModel::CModel()
|
{
|
m_pEuqipment = nullptr;
|
}
|
|
|
CModel::~CModel()
|
{
|
}
|
|
BEQ::IEquipment* CModel::createEquipment(const char* pszName)
|
{
|
if (m_pEuqipment != nullptr) {
|
return nullptr;
|
}
|
|
m_strEquipmentName = pszName;
|
BEQ_CreateEquipment(m_pEuqipment, pszName);
|
if (m_pEuqipment != nullptr) {
|
BEQ::EquipmentListener listener;
|
listener.onConnected = [&](void* pEquipment, const char* pszAddr, int port) -> int {
|
TRACE("%s:%dÁ¬½Ó½øÈë.", pszAddr, port);
|
return 0;
|
};
|
listener.onDisconnected = [&](void* pEquipment, const char* pszAddr, int port) -> int {
|
TRACE("%s:%dÁ¬½Ó¶Ï¿ª.\n", pszAddr, port);
|
return 0;
|
};
|
listener.onRunRecipe = [&](void* pEquipment, void* pUnit, int id) -> int {
|
BEQ::IUnit* p = (BEQ::IUnit*)pUnit;
|
char szUnitName[256];
|
p->getName(szUnitName, 256);
|
m_mapRecipe[szUnitName] = id;
|
TRACE("%sÕýÔÚÇл»ÖÁÅä·½%d.\n", szUnitName, id);
|
// ×öÇл»Åä·½µÄ¶¯×÷
|
Sleep(2000);
|
|
return 0;
|
};
|
listener.onGetRecipeList = [&](void* pEquipment, void* pUnit) -> int {
|
BEQ::IUnit* p = (BEQ::IUnit*)pUnit;
|
char szUnitName[256];
|
p->getName(szUnitName, 256);
|
TRACE("ÖпØÇëÇó»ñÈ¡µ¥Ôª[%s]Åä·½Áбí.\n", szUnitName);
|
// Ôڴ˸üÐÂÅä·½
|
// p->addRecipe();
|
Sleep(2000);
|
|
// ×èÈû·½Ê½·µ»Ø0£¬
|
// ¶àÏ̷߳½Ê½ÏÈ·µ»Ø1£¬ÔÚÏß³ÌÖлñÈ¡ÍêÅä·½ºó£¬µ÷ÓÃ
|
// IEquipment::repRecipeListCompleteÒì²½·µ»ØÊý¾Ý
|
return 0;
|
};
|
listener.onLoadReady = [&](void* pEquipment, void* pUnit, const char* pszMaterielId, const char* pszRecipeId) -> int {
|
BEQ::IUnit* p = (BEQ::IUnit*)pUnit;
|
char szUnitName[256];
|
p->getName(szUnitName, 256);
|
Sleep(2000);
|
|
return 0;
|
};
|
m_pEuqipment->setEquipmentListener(listener);
|
}
|
|
return m_pEuqipment;
|
}
|
|
BEQ::IEquipment* CModel::getEquipment()
|
{
|
return m_pEuqipment;
|
}
|
|
int CModel::getRecipeName(const char* pszUnitName)
|
{
|
static std::string strEmpty = "";
|
auto iter = m_mapRecipe.find(pszUnitName);
|
if (iter == m_mapRecipe.end()) return 0;
|
|
return iter->second;
|
}
|