int KScene::LuaAddHero(Lua_State* L)
{
    int     nResult         = 0;
    BOOL    bRetCode        = false;
    int     nTopIndex       = 0;
    DWORD   dwTemplateID    = ERROR_ID;
    int     nLevel          = 0;
    int     nSide           = 0;
    int     nAIType         = 0;
    KHero*  pHero           = NULL;
    int     nX              = 0;
    int     nY              = 0;
    int     nZ              = 0;
    int     nPos            = -1;
    int     nFaceDir        = csdInvalid;

    nTopIndex = Lua_GetTopIndex(L);
    KGLOG_PROCESS_ERROR(nTopIndex == 4 || nTopIndex == 7 || nTopIndex == 8);

    dwTemplateID    = (DWORD)Lua_ValueToNumber(L, 1);
    nLevel          = (int)Lua_ValueToNumber(L, 2);
    nSide           = (int)Lua_ValueToNumber(L, 3);
    nAIType         = (int)Lua_ValueToNumber(L, 4);

    if (nTopIndex == 7 || nTopIndex == 8)
    {
        nX = (int)Lua_ValueToNumber(L, 5);
        nY = (int)Lua_ValueToNumber(L, 6);
        nZ = (int)Lua_ValueToNumber(L, 7);
    }

    if (nTopIndex == 8)
        nFaceDir = (int)Lua_ValueToNumber(L, 8);

    bRetCode = GetFreePos(nSide, nPos);
    KGLOG_PROCESS_ERROR(bRetCode);

    pHero = AddHero(dwTemplateID, nLevel, nSide, nPos, nFaceDir);
    KGLOG_PROCESS_ERROR(pHero);

    pHero->SetPosition(nX, nY, nZ);

    if (nAIType != 0)
        pHero->m_AIData.nAIType = nAIType;
    
    pHero->m_bAiMode = true;
    pHero->SetUpAVM();

    g_PlayerServer.DoBroadcastNewHero(pHero, ERROR_ID);

    nResult = pHero->LuaGetObj(L);
Exit0:
    return nResult;
}
Exemple #2
0
template<class TA> unsigned int DynArray_cl<TA>::Pack()
{
  // Find the first hole in the list. If the list is completely full of valid
  // entries, return immediately.
  unsigned int iFirstFree = GetFreePos();
  if (iFirstFree == size)
    return size;

  // Iterate over all elements following the first free element, and move any
  // valid elements found to the front.
  for (unsigned int iTest = iFirstFree + 1; iTest < size; ++iTest)
  {
    if (defaultValue != data[iTest])
    {
      data[iFirstFree] = data[iTest];
      data[iTest] = defaultValue;
      iFirstFree++;
    }
  }

  // The first free index is equal to the number of valid entries; return it.
  return iFirstFree;
}