bool CDialogScriptHelper::Precondition (const CGameObject* pSpeakerGO, LPCSTR dialog_id, LPCSTR phrase_id) const { bool predicate_result = true; if(!CheckInfo(smart_cast<const CInventoryOwner*>(pSpeakerGO))) { #ifdef DEBUG if (psAI_Flags.test(aiDialogs)) Msg("dialog [%s] phrase[%s] rejected by CheckInfo",dialog_id,phrase_id); #endif return false; } for(u32 i = 0; i<Preconditions().size(); ++i) { luabind::functor<bool> lua_function; THROW(*Preconditions()[i]); bool functor_exists = ai().script_engine().functor(*Preconditions()[i] ,lua_function); THROW3(functor_exists, "Cannot find precondition", *Preconditions()[i]); predicate_result = lua_function (pSpeakerGO->lua_game_object()); if(!predicate_result){ #ifdef DEBUG if (psAI_Flags.test(aiDialogs)) Msg("dialog [%s] phrase[%s] rejected by script predicate", dialog_id, phrase_id); #endif break; } } return predicate_result; }
void CDialogScriptHelper::Action (const CGameObject* pSpeakerGO, LPCSTR dialog_id, LPCSTR phrase_id) const { for(u32 i = 0; i<Actions().size(); ++i) { luabind::functor<void> lua_function; THROW(*Actions()[i]); bool functor_exists = ai().script_engine().functor(*Actions()[i] ,lua_function); THROW3(functor_exists, "Cannot find phrase dialog script function", *Actions()[i]); lua_function (pSpeakerGO->lua_game_object(), dialog_id); } TransferInfo(smart_cast<const CInventoryOwner*>(pSpeakerGO)); }
void CPhraseScript::Action(const CGameObject* pSpeakerGO1, const CGameObject* pSpeakerGO2, LPCSTR dialog_id, LPCSTR phrase_id) const { TransferInfo(smart_cast<const CInventoryOwner*>(pSpeakerGO1)); for(u32 i = 0; i<Actions().size(); ++i) { luabind::functor<void> lua_function; THROW(*Actions()[i]); bool functor_exists = ai().script_engine().functor(*Actions()[i] ,lua_function); THROW3(functor_exists, "Cannot find phrase dialog script function", *Actions()[i]); try { lua_function (pSpeakerGO1->lua_game_object(), pSpeakerGO2->lua_game_object(), dialog_id, phrase_id); } catch (...) { } } }
LPCSTR CDialogScriptHelper::GetScriptText(LPCSTR str_to_translate, const CGameObject* pSpeakerGO1, const CGameObject* pSpeakerGO2, LPCSTR dialog_id, LPCSTR phrase_id) { if(!m_sScriptTextFunc.size()) return str_to_translate; luabind::functor<LPCSTR> lua_function; bool functor_exists = ai().script_engine().functor(m_sScriptTextFunc.c_str() ,lua_function); THROW3 (functor_exists, "Cannot find phrase script text ", m_sScriptTextFunc.c_str()); LPCSTR res = lua_function( pSpeakerGO1->lua_game_object(), pSpeakerGO2->lua_game_object(), dialog_id, phrase_id); return res; }
void CScriptBinder::reload (LPCSTR section) { #ifdef DEBUG_MEMORY_MANAGER u32 start = 0; if (g_bMEMO) start = Memory.mem_usage(); #endif // DEBUG_MEMORY_MANAGER #ifndef DBG_DISABLE_SCRIPTS VERIFY (!m_object); if (!pSettings->line_exist(section,"script_binding")) return; luabind::functor<void> lua_function; if (!ai().script_engine().functor(pSettings->r_string(section,"script_binding"),lua_function)) { ai().script_engine().script_log (ScriptStorage::eLuaMessageTypeError,"function %s is not loaded!",pSettings->r_string(section,"script_binding")); return; } CGameObject *game_object = smart_cast<CGameObject*>(this); try { lua_function (game_object ? game_object->lua_game_object() : 0); } catch(...) { clear (); return; } if (m_object) { try { m_object->reload(section); } catch(...) { clear (); } } #endif #ifdef DEBUG_MEMORY_MANAGER if (g_bMEMO) { // lua_gc (ai().script_engine().lua(),LUA_GCCOLLECT,0); // lua_gc (ai().script_engine().lua(),LUA_GCCOLLECT,0); Msg ("CScriptBinder::reload() : %d",Memory.mem_usage() - start); } #endif // DEBUG_MEMORY_MANAGER }