本文整理汇总了C++中CGameManager::FindUnit方法的典型用法代码示例。如果您正苦于以下问题:C++ CGameManager::FindUnit方法的具体用法?C++ CGameManager::FindUnit怎么用?C++ CGameManager::FindUnit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGameManager
的用法示例。
在下文中一共展示了CGameManager::FindUnit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Execute
void CScriptManager::Execute( CAbility* pAbility, CTile* pTile, CUnit* pCaster, CTile* TileCharged )
{
// Finds the facing for the specified unit
int face = pCaster->GetFacing();
std::vector< Vec2D > TilePos;
std::vector< Vec2D > pat;
if( pAbility->GetIfFacing() )
pat = CAbilityManager::GetInstance()->GetProperFacing(pCaster->GetFacing(), pAbility, pTile);
else
pat = pAbility->GetPattern();
for( unsigned int i = 0; i < pAbility->GetPattern().size(); i++ )
{
pat[i].nPosX += pTile->GetPosition().nPosX;
pat[i].nPosY += pTile->GetPosition().nPosY;
TilePos.push_back(pat[i]);
}
lua_getglobal(L, "OnUse");
lua_newtable(L);
CGameManager* pGM = CGameManager::GetInstance();
vector< CUnit* > affected;
int nCount = 0;
int z = (int)TilePos.size()-1;
for( int i = 0; i <= z; i++ )
{
CUnit* tmp = pGM->FindUnit(TilePos[i].nPosX, TilePos[i].nPosY);
if( pAbility->GetType() == SP_CHARGE || pAbility->GetType() == SP_RUSH )
{
if( TilePos[i] == TileCharged->GetPosition() )
break;
}
if( tmp == nullptr )
continue;
affected.push_back( tmp );
lua_newtable(L);
lua_pushstring(L, "posX");
lua_pushnumber(L, tmp->GetPos().nPosX);
lua_settable(L, -3);
lua_pushstring(L, "posY");
lua_pushnumber(L, tmp->GetPos().nPosY);
lua_settable(L, -3);
lua_pushstring(L, "health");
lua_pushnumber(L, tmp->GetHP());
lua_settable(L, -3);
lua_pushstring(L, "speed");
lua_pushnumber(L, tmp->GetSpeed());
lua_settable(L, -3);
lua_pushstring(L, "shielded");
lua_pushnumber(L, tmp->GetShielded());
lua_settable(L, -3);
lua_pushstring(L, "uniqueID");
lua_pushnumber(L, tmp->GetUniqueID());
lua_settable(L, -3);
lua_pushnumber(L, nCount+1);
nCount++;
lua_insert(L, -2);
lua_settable(L, -3);
}
lua_setglobal(L, "tUnitData");
std::string path = "Assets/Ability/" + pAbility->GetLua();
luaL_dofile(L, path.c_str());
lua_getglobal(L, "OnUse");
lua_pcall(L, 0, 0, 0);
lua_getglobal(L, "tUnitData");
lua_pushnil(L);
vector<std::pair<std::string, int>> tData;
// std::pair<std::string, int> tmp;
tData.clear();
while(lua_next(L, -2) != 0)
{
if( lua_istable(L, -1) )
{
lua_pushnil(L);
while( lua_next(L, -2) )
{
if(lua_isnumber(L, -1))
{
std::pair<std::string, int> tmp;
tmp.first = lua_tostring(L, -2);
tmp.second = (int)lua_tonumber(L, -1);
tData.push_back(tmp);
}
lua_pop(L, 1);
}
}
//.........这里部分代码省略.........