Beispiel #1
0
void CUISequenceItem::Load(CUIXml* xml, int idx)
{
	XML_NODE* _stored_root			= xml->GetLocalRoot();
	xml->SetLocalRoot				(xml->NavigateToNode("item",idx));
	int disabled_cnt				= xml->GetNodesNum	(xml->GetLocalRoot(), "disabled_key");
	for(int i=0; i<disabled_cnt;++i){
		LPCSTR str					= xml->Read			("disabled_key", i, NULL);
		m_disabled_actions.push_back( action_name_to_id(str) );
	};

	LPCSTR		str;
	bool		functor_exists;
	int			j;
	int			f_num				= xml->GetNodesNum(xml->GetLocalRoot(),"function_on_start");
	m_start_lua_functions.resize	(f_num);
	for(j=0; j<f_num; ++j){
		str							= xml->Read(xml->GetLocalRoot(), "function_on_start", j, NULL);
		functor_exists				= ai().script_engine().functor(str ,m_start_lua_functions[j]);
		THROW3						(functor_exists, "Cannot find script function described in tutorial item ", str);
	}
	
	f_num							= xml->GetNodesNum(xml->GetLocalRoot(),"function_on_stop");
	m_stop_lua_functions.resize	(f_num);
	for(j=0; j<f_num; ++j){
		str							= xml->Read(xml->GetLocalRoot(), "function_on_stop", j, NULL);
		functor_exists				= ai().script_engine().functor(str ,m_stop_lua_functions[j]);
		THROW3						(functor_exists, "Cannot find script function described in tutorial item ", str);
	}

	xml->SetLocalRoot				(_stored_root);
}
Beispiel #2
0
void ServerSocket::listen(const SocketAddress& local, int backlog,
		bool reuseAddr, bool blocking) throw (IOException&)
{
	close();

	int sock = mxos::openSocket(AF_INET, SOCK_STREAM, 0);

	if (-1 == sock)
	{
		THROW3(IOException, "Can't open socket", mxos::getLastSocketError());
	}

	if (reuseAddr)
	{
		int val = 1;

		if (0 != mxos::setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &val,
				sizeof(val)))
		{
			mxos::closeSocket(sock);
			THROW3(IOException, "Can't reuse addr", mxos::getLastSocketError());
		}
	}

	if (0 != mxos::bind(sock, local.sockAddress(), local.length()))
	{
		mxos::closeSocket(sock);
		THROW3(IOException, std::string("Can't bind socket to:") + local.toString(), mxos::getLastSocketError());
	}

	if (!blocking)
	{
		try
		{
			IOUtil::configBlocking(sock, false);
		} catch (mxcore::IOException& e)
		{
			mxos::closeSocket(sock);
			throw e;
		}
	}
	if (0 != mxos::listen(sock, backlog))
	{
		mxos::closeSocket(sock);
		THROW3(IOException, "Can't listen socket", mxos::getLastSocketError());
	}

	handle_ = sock;
}
Beispiel #3
0
bool ServerSocket::accept(Socket& client) throw (IOException&)
{
	MX_ASSERT(!isClosed());

	int sock = mxos::accept(handle_, NULL, NULL);
	if (-1 == sock)
	{
		int err = mxos::getLastSocketError();
#if defined(WIN32)
		if (WSAEWOULDBLOCK == err || WSAEINTR == err)
		{
			return false;
		}
#else
		if (EAGAIN == err || EINTR == err)
		{
			return false;
		}
#endif
		THROW3 (IOException, "Can't accept socket", err);
	}

	client.attach(sock, true, true);
	return true;
}
Beispiel #4
0
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;
}
Beispiel #5
0
void CObjectHandler::weapon_bones	(int &b0, int &b1, int &b2) const
{
	CWeapon						*weapon = smart_cast<CWeapon*>(inventory().ActiveItem());
	if (!weapon || !planner().m_storage.property(ObjectHandlerSpace::eWorldPropertyStrapped)) {
		if (weapon)
			weapon->strapped_mode	(false);
		b0						= m_r_hand;
		b1						= m_r_finger2;
		b2						= m_l_finger1;
		return;
	}

	THROW3						(weapon->can_be_strapped(),"Cannot strap weapon",*weapon->cName());

	if (weapon->ID() != m_strap_object_id) {
		CKinematics				*kinematics = smart_cast<CKinematics*>(planner().m_object->Visual());
		m_strap_bone0			= kinematics->LL_BoneID(weapon->strap_bone0());
		m_strap_bone1			= kinematics->LL_BoneID(weapon->strap_bone1());
		m_strap_object_id		= weapon->ID();
	}

	weapon->strapped_mode		(true);
	b0							= m_strap_bone0;
	b1							= m_strap_bone1;
	b2							= b1;
}
void CUISequenceSimpleItem::OnKeyboardPress	(int dik)
{
	if(!m_flags.test(etiCanBeStopped) )
	{
		VERIFY		(m_continue_dik_guard!=-1);
		if(m_continue_dik_guard==-1)m_flags.set(etiCanBeStopped, TRUE); //not binded action :(

		if(m_continue_dik_guard==9999 || dik == m_continue_dik_guard)
			m_flags.set(etiCanBeStopped, TRUE); //match key
	}

	for(u32 idx=0; idx<m_actions.size(); ++idx)
	{
		SActionItem& itm			= m_actions[idx];
		bool b = is_binded(itm.m_action, dik);
		if(b)
		{
			luabind::functor<void>	functor_to_call;
			bool functor_exists		= ai().script_engine().functor(itm.m_functor.c_str() ,functor_to_call);
			THROW3					(functor_exists, "Cannot find script function described in tutorial item ", itm.m_functor.c_str());
			functor_to_call			();

			if(itm.m_bfinalize)
			{
				m_flags.set					(etiCanBeStopped, TRUE);
				m_stop_lua_functions.clear	();
				Stop						();
			}
		}
	}
}
void CALifeMonsterBrain::process_task			()
{
	CALifeSmartTerrainTask			*task = smart_terrain().task(&object());
	THROW3							(task,"smart terrain returned nil task, while npc is registered in it",smart_terrain().name_replace());
	movement().path_type			(MovementManager::ePathTypeGamePath);
	movement().detail().target		(*task);
}
Beispiel #8
0
void IOUtil::createPipe(int pipefds[2]) throw (IOException&)
{
#if defined(WIN32)
	createSocketPair(pipefds);
	if (0 != mxos::shutdownOutput(pipefds[0]) || 0 != mxos::shutdownInput(
			pipefds[1]))
	{
		mxos::closeSocket(pipefds[0]);
		mxos::closeSocket(pipefds[1]);
		THROW3(IOException, std::string("Can't create pipe"), mxos::getLastSocketError());
	}
#else
	if (0 != ::pipe(pipefds))
	{
		THROW3(IOException, std::string("Can't create pipe"), mxos::getLastSocketError());
	}
#endif
}
CPatrolPathParams::CPatrolPathParams	(LPCSTR caPatrolPathToGo, const PatrolPathManager::EPatrolStartType tPatrolPathStart, const PatrolPathManager::EPatrolRouteType tPatrolPathStop, bool bRandom, u32 index)
{
	m_path_name			= caPatrolPathToGo;
	m_path				= ai().patrol_paths().path(m_path_name,true);
	
	THROW3				(m_path,"There is no patrol path",caPatrolPathToGo);
	
	m_tPatrolPathStart	= tPatrolPathStart;
	m_tPatrolPathStop	= tPatrolPathStop;
	m_bRandom			= bRandom;
	m_previous_index	= index;
}
Beispiel #10
0
void CObjectHandler::actualize_strap_mode	(CWeapon *weapon) const
{
	VERIFY						(weapon);

	if (!planner().m_storage.property(ObjectHandlerSpace::eWorldPropertyStrapped)) {
		weapon->strapped_mode	(false);
		return;
	}

	THROW3						(weapon->can_be_strapped(),"Cannot strap weapon",*weapon->cName());
	weapon->strapped_mode		(true);
}
Beispiel #11
0
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));
}
Beispiel #12
0
SqlResultSet* MysqlStatement::executeQuery(const std::string& sql)
throw (SqlException&)
{
    lastUpdateCount_ = 0;

    if (0 != ::mysql_real_query(connection_->getConnection(), sql.c_str(),
                                sql.size()))
    {
        THROW3(SqlException, ::mysql_error(connection_->getConnection()), ::mysql_errno(connection_->getConnection()));
    }

    return getResultSet();
}
Beispiel #13
0
bool MysqlStatement::execute(const std::string& sql) throw (SqlException&)
{
    if (0 != ::mysql_real_query(connection_->getConnection(), sql.c_str(),
                                sql.size()))
    {
        THROW3(SqlException, ::mysql_error(connection_->getConnection()), ::mysql_errno(connection_->getConnection()));
    }

    bool ret = ::mysql_field_count(connection_->getConnection()) > 0;
    lastUpdateCount_ = ret ? 0 : ::mysql_affected_rows(
                           connection_->getConnection());
    return ret;
}
Beispiel #14
0
void IOUtil::configBlocking(int sock, bool blocking) throw (IOException&)
{
	MX_ASSERT(-1 != sock);
#if defined(WIN32)
	unsigned long flag = blocking ? 1 : 0;

	if (0 != ::ioctlsocket(sock, FIONBIO, &flag))
	{
		if (blocking)
		{
			THROW3(IOException, std::string("Can't config blocking for fd: ") + Integer(sock).toString(), mxos::getLastSocketError());
		}
		else
		{
			THROW3(IOException, std::string("Can't config nonblocking for fd: ") + Integer(sock).toString(), mxos::getLastSocketError());
		}
	}
#else
	int flag = ::fcntl(sock, F_GETFL, 0);

	if ((O_NONBLOCK & flag) && blocking)
	{
		if (-1 == ::fcntl(sock, F_SETFL, flag & ~O_NONBLOCK))
		{
			THROW3(IOException, std::string("Can't config blocking for fd: ") + Integer(sock).toString(), mxos::getLastSocketError());
		}
	}
	else if (!(O_NONBLOCK & flag) && !blocking)
	{
		if (-1 == ::fcntl(sock, F_SETFL, flag | O_NONBLOCK))
		{
			THROW3(IOException, std::string("Can't config nonblocking for fd: ") + Integer(sock).toString(), mxos::getLastSocketError());
		}
	}
#endif
}
Beispiel #15
0
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 (...) {
		}
	}
}
Beispiel #16
0
/**
 *  @brief Return the specified CPU from the cpu_set_t
 *  instance.
 *
 *  @param cpu_set The CPU set.
 *
 *  @param index The index of the CPU. Must be between 0 and the
 *  result of cpu_set_get_num_cpus(cpu_set).
 *
 *  @return NULL on error. On success, returns the specified CPU.
 */
cpu_t cpu_set_get_cpu(cpu_set_p cpu_set, int index)
{

  /* error checks */
    if ( cpu_set == NULL )
        THROW1(QPipeException, "Called with NULL cpu_set_t");
    
    if ( index < 0 )
        THROW2(OutOfRange, "Called with negative index %d\n", index);
    if ( index >= cpu_set->cpuset_num_cpus )
        THROW3(OutOfRange, 
                        "Called with index %d in a cpu_set_t with %d CPUs\n",
                        index,
                        cpu_set->cpuset_num_cpus);
  
    return &cpu_set->cpuset_cpus[index];
}
Beispiel #17
0
uint64_t MysqlStatement::executeUpdate(const std::string& sql)
throw (SqlException&)
{
    if (0 != ::mysql_real_query(connection_->getConnection(), sql.c_str(),
                                sql.size()))
    {
        THROW3(SqlException, ::mysql_error(connection_->getConnection()), ::mysql_errno(connection_->getConnection()));
    }

    if (::mysql_field_count(connection_->getConnection()))
    {
        THROW2(SqlException, "Run update but statement return result set");
    }

    lastUpdateCount_ = ::mysql_affected_rows(connection_->getConnection());
    return lastUpdateCount_;
}
Beispiel #18
0
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;

}
Beispiel #19
0
const SocketAddress& ServerSocket::getLocalAddress(void) const
		throw (IOException&)
{
	MX_ASSERT(!isClosed());

	if (NULL == local_)
	{
		struct sockaddr_in6 sa;
		size_t saLen = sizeof(struct sockaddr_in6);
		::memset(&sa, 0, sizeof(sa));

		if (0 != mxos::getsockname(handle_, (struct sockaddr*) &sa, &saLen))
		{
			THROW3(IOException, "Can't get sock name", mxos::getLastSocketError());
		}

		local_ = new SocketAddress;
		local_->set((struct sockaddr*) &sa, saLen);
	}

	return *local_;
}
Beispiel #20
0
void CPurchaseList::process	(CInifile &ini_file, LPCSTR section, CInventoryOwner &owner)
{
	owner.sell_useless_items();

	m_deficits.clear		();

	const CGameObject		&game_object = smart_cast<const CGameObject &>(owner);
	CInifile::Sect			&S = ini_file.r_section(section);
	CInifile::SectCIt		I = S.Data.begin();
	CInifile::SectCIt		E = S.Data.end();
	for ( ; I != E; ++I) {
		VERIFY3				((*I).second.size(),"PurchaseList : cannot handle lines in section without values",section);

		string256			temp0, temp1;
		THROW3				(_GetItemCount(*(*I).second) == 2,"Invalid parameters in section",section);
		process				(
			game_object,
			(*I).first,
			atoi(_GetItem(*(*I).second,0,temp0)),
			(float)atof(_GetItem(*(*I).second,1,temp1))
		);
	}
}
Beispiel #21
0
Fvector CScriptIniFile::r_fvector3(LPCSTR S, LPCSTR L)
{
    THROW3(inherited::section_exist(S), "Cannot find section", S);
    THROW3(inherited::line_exist(S, L), "Cannot find line", L);
    return		(inherited::r_fvector3(S, L));
}
Beispiel #22
0
u32	 CScriptIniFile::line_count(LPCSTR S)
{
    THROW3(inherited::section_exist(S), "Cannot find section", S);
    return		(inherited::line_count(S));
}
Beispiel #23
0
void CScriptIniFile::remove_line(LPCSTR S, LPCSTR L)
{
    THROW3(inherited::section_exist(S), "Cannot find section", S);
    THROW3(inherited::line_exist(S, L), "Cannot find line", L);
    inherited::remove_line(S, L);
}
Beispiel #24
0
void CScriptIniFile::w_u8(LPCSTR S, LPCSTR L, u8 V, LPCSTR comment)
{
    THROW3(inherited::section_exist(S), "Cannot find section", S);
    THROW3(inherited::line_exist(S, L), "Cannot find line", L);
    inherited::w_u8(S, L, V, comment);
}
Beispiel #25
0
void CInfoPortion::load_shared	(LPCSTR)
{
	const ITEM_DATA& item_data = *id_to_index::GetById(m_InfoId);

	CUIXml*		pXML		= item_data._xml;
	pXML->SetLocalRoot		(pXML->GetRoot());

	//loading from XML
	XML_NODE* pNode			= pXML->NavigateToNode(id_to_index::tag_name, item_data.pos_in_file);
	THROW3					(pNode, "info_portion id=", *item_data.id);

	//список названий диалогов
	int dialogs_num			= pXML->GetNodesNum(pNode, "dialog");
	info_data()->m_DialogNames.clear();
	int i = 0;
	for(; i<dialogs_num; ++i)
	{
		shared_str dialog_name = pXML->Read(pNode, "dialog", i,"");
		info_data()->m_DialogNames.push_back(dialog_name);
	}

	
	//список названий порций информации, которые деактивируются,
	//после получения этой порции
	int disable_num = pXML->GetNodesNum(pNode, "disable");
	info_data()->m_DisableInfo.clear();
	for(i=0; i<disable_num; ++i)
	{
		shared_str info_id		= pXML->Read(pNode, "disable", i,"");
		info_data()->m_DisableInfo.push_back(info_id);
	}

	//имена скриптовых функций
	info_data()->m_PhraseScript.Load(pXML, pNode);


	//индексы статей
	info_data()->m_Articles.clear();
	int articles_num	= pXML->GetNodesNum(pNode, "article");
	for(i=0; i<articles_num; ++i)
	{
		LPCSTR article_str_id = pXML->Read(pNode, "article", i, NULL);
		THROW(article_str_id);
		info_data()->m_Articles.push_back(article_str_id);
	}

	info_data()->m_ArticlesDisable.clear();
	articles_num = pXML->GetNodesNum(pNode, "article_disable");
	for(i=0; i<articles_num; ++i)
	{
		LPCSTR article_str_id = pXML->Read(pNode, "article_disable", i, NULL);
		THROW(article_str_id);
		info_data()->m_ArticlesDisable.push_back(article_str_id);
	}
	
	info_data()->m_GameTasks.clear();
	int task_num = pXML->GetNodesNum(pNode, "task");
	for(i=0; i<task_num; ++i)
	{
		LPCSTR task_str_id = pXML->Read(pNode, "task", i, NULL);
		THROW(task_str_id);
		info_data()->m_GameTasks.push_back(task_str_id);
	}
}
Beispiel #26
0
CScriptSound::~CScriptSound		()
{
	THROW3					(!m_sound._feedback(),"playing sound is not completed, but is destroying",m_sound._handle() ? m_sound._handle()->file_name() : "unknown");
	m_sound.destroy			();
}
Beispiel #27
0
void CScriptSound::Play			(CScriptGameObject *object, float delay, int flags)
{
	THROW3						(m_sound._handle(),"There is no sound",*m_caSoundToPlay);
//	Msg							("%6d : CScriptSound::Play (%s), delay %f, flags %d",Device.dwTimeGlobal,m_sound._handle()->file_name(),delay,flags);
	m_sound.play				(&object->object(),flags,delay);
}
Beispiel #28
0
void CScriptSound::PlayAtPos		(CScriptGameObject *object, const Fvector &position, float delay, int flags)
{
	THROW3						(m_sound._handle(),"There is no sound",*m_caSoundToPlay);
//	Msg							("%6d : CScriptSound::Play (%s), delay %f, flags %d",m_sound._handle()->file_name(),delay,flags);
	m_sound.play_at_pos			(&object->object(), position,flags,delay);
}
Beispiel #29
0
void CScriptSound::PlayNoFeedback	(CScriptGameObject *object,	u32 flags/*!< Looping */, float delay/*!< Delay */, Fvector pos, float vol)
{
	THROW3						(m_sound._handle(),"There is no sound",*m_caSoundToPlay);
	m_sound.play_no_feedback	(&object->object(), flags,delay,&pos,&vol);
}