00001 00013 /*************************************************************************** 00014 * Copyright (C) 2007 by Jan Koci * 00015 * honza.koci@email.cz * 00016 * http://kengine.sourceforge.net/tutorial/ 00017 * * 00018 * This program is free software; you can redistribute it and/or modify * 00019 * it under the terms of the GNU General Public License as published by * 00020 * the Free Software Foundation; either version 2 of the License, or * 00021 * (at your option) any later version. * 00022 * * 00023 * This program is distributed in the hope that it will be useful, * 00024 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00025 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00026 * GNU General Public License for more details. * 00027 * * 00028 * You should have received a copy of the GNU General Public License * 00029 * along with this program; if not, write to the * 00030 * Free Software Foundation, Inc., * 00031 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00032 ***************************************************************************/ 00033 00034 #include "K3dBlockBuild.h" 00035 00039 K3dBlockBuild::K3dBlockBuild(K3dGameData *_pGameData) 00040 { 00041 m_pGameData = _pGameData; 00042 } 00043 00044 K3dBlockBuild::~K3dBlockBuild(void) 00045 { 00046 DeleteBlocks(); 00047 } 00048 00050 void K3dBlockBuild::LoadBlocks() 00051 { 00052 cout << "void K3dBlockBuild::LoadBlocks()" << endl; 00053 K3dString strFc = "void K3dBlockBuild::LoadBlocks() -- "; 00054 K3dString strOut; 00055 00056 // Get virtual machine from global data 00057 K3dLua *pLua = m_pGameData->GetLua(); 00058 00059 // Get number of blocs 00060 pLua->LuaGetGlobal(K_STR_NUM_BLOCKS); 00061 if (!pLua->LuaIsNumber(-1)) 00062 { 00063 //strOut = strFc + K_STR_NUM_BLOCKS; 00064 //strOut += " is not a valid number"; 00065 //pLua->LuaError(strOut.GetString().c_str()); 00066 cerr << "Warning :: void K3dBlockBuild::LoadBlocks() -- Doesn`t load " << K_STR_NUM_BLOCKS << " from map file" << endl; 00067 } 00068 00069 int iNumBlocks = (int) pLua->LuaToNumber(-1); 00070 for(int i=0; i<iNumBlocks; i++) 00071 { 00072 00073 K3dBlockObj *pBlock = m_pGameData->GetBlockObjSP().New(); 00074 00075 K3dString kString(K_STR_BLOCK); 00076 // Add number behind string 00077 kString.AddNumber(i); 00078 00079 pLua->LuaGetGlobal(kString.GetString().c_str()); 00080 if (!pLua->LuaIsTable(-1)) 00081 { 00082 strOut = strFc + kString; 00083 strOut += " is not a valid block table"; 00084 pLua->LuaError(strOut.GetString().c_str()); 00085 } 00086 pBlock->GetName() = pLua->LuaGetFieldString(K_STR_NAME); 00087 pBlock->GetId() = m_pGameData->GetBlockObjSP().GetNum(); 00088 pBlock->GetNumFaces() = (int)pLua->LuaGetFieldNumber(K_STR_NUM_FACES); 00089 pBlock->GetFirstFaceId() = (int)pLua->LuaGetFieldNumber(K_STR_FIRST_FACE); 00090 } 00091 } 00092 00094 void K3dBlockBuild::DeleteBlocks() 00095 { 00096 std::cout << "void K3dBlockBuild::DeleteBlocks()" << endl; 00097 while(m_pGameData->GetBlockObjSP().GetNum()) 00098 { 00099 K3dBlockObj *p = m_pGameData->GetBlockObjSP().Get(0); 00100 p = m_pGameData->GetBlockObjSP().Delete(p); 00101 } 00102 }