示例#1
0
int LuaBehavior::interrupt(AiAgent* agent, SceneObject* source, int64 msg) {
#ifdef AI_DEBUG
	Time timer;
#endif

	Lua* lua = DirectorManager::instance()->getLuaInstance();

	LuaFunction messageFunc(lua->getLuaState(), className, "interrupt", 1);
	messageFunc << agent;
	messageFunc << source; //arg1
	messageFunc << msg; //arg2

	messageFunc.callFunction();

	int result = lua_tointeger(lua->getLuaState(), -1);
	lua_pop(lua->getLuaState(), 1);

#ifdef AI_DEBUG
	String key = className;
	if (msg == 17)
		key += "::startAwarenessInterrupt";
	else if (msg == 31)
		key += "::startCombatInterrupt";

	agent->incrementLuaCall(key);
	agent->addToLuaTime(key, Time().getMikroTime() - timer.getMikroTime());
#endif

	//1 remove observer, 0 keep observer
	return result;
}
示例#2
0
bool LuaBehavior::doAwarenessCheck(AiAgent* agent, SceneObject* target) {
#ifdef AI_DEBUG
	Time timer;
#endif

	Lua* lua = DirectorManager::instance()->getLuaInstance();
	//agent->info(className, true);
	LuaFunction messageFunc(lua->getLuaState(), className, "doAwarenessCheck", 1);
	messageFunc << agent;
	messageFunc << target; //pObject

	messageFunc.callFunction();

	bool result = lua_toboolean(lua->getLuaState(), -1);
	lua_pop(lua->getLuaState(), 1);

#ifdef AI_DEBUG
	String key = className + "::doAwarenessCheck";
	agent->incrementLuaCall(key);
	agent->addToLuaTime(key, Time().getMikroTime() - timer.getMikroTime());
#endif

	return result;
}