Пример #1
0
	std::string getSuspect(v3s16 p, float nearness_shortcut, float min_nearness)
	{
		if(m_current_actor != "")
			return m_current_actor;
		int cur_time = time(0);
		int first_time = cur_time - (100-min_nearness);
		RollbackAction likely_suspect;
		float likely_suspect_nearness = 0;
		for(std::list<RollbackAction>::const_reverse_iterator
				i = m_action_latest_buffer.rbegin();
				i != m_action_latest_buffer.rend(); i++)
		{
			if(i->unix_time < first_time)
				break;
			if(i->actor == "")
				continue;
			// Find position of suspect or continue
			v3s16 suspect_p;
			if(!i->getPosition(&suspect_p))
				continue;
			float f = getSuspectNearness(i->actor_is_guess, suspect_p,
					i->unix_time, p, cur_time);
			if(f >= min_nearness && f > likely_suspect_nearness){
				likely_suspect_nearness = f;
				likely_suspect = *i;
				if(likely_suspect_nearness >= nearness_shortcut)
					break;
			}
		}
		// No likely suspect was found
		if(likely_suspect_nearness == 0)
			return "";
		// Likely suspect was found
		return likely_suspect.actor;
	}
Пример #2
0
std::string RollbackManager::getSuspect(v3s16 p, float nearness_shortcut,
		float min_nearness)
{
	if (!current_actor.empty()) {
		return current_actor;
	}
	int cur_time = time(0);
	time_t first_time = cur_time - (100 - min_nearness);
	RollbackAction likely_suspect;
	float likely_suspect_nearness = 0;
	for (std::list<RollbackAction>::const_reverse_iterator
	     i = action_latest_buffer.rbegin();
	     i != action_latest_buffer.rend(); ++i) {
		if (i->unix_time < first_time) {
			break;
		}
		if (i->actor.empty()) {
			continue;
		}
		// Find position of suspect or continue
		v3s16 suspect_p;
		if (!i->getPosition(&suspect_p)) {
			continue;
		}
		float f = getSuspectNearness(i->actor_is_guess, suspect_p,
					     i->unix_time, p, cur_time);
		if (f >= min_nearness && f > likely_suspect_nearness) {
			likely_suspect_nearness = f;
			likely_suspect = *i;
			if (likely_suspect_nearness >= nearness_shortcut) {
				break;
			}
		}
	}
	// No likely suspect was found
	if (likely_suspect_nearness == 0) {
		return "";
	}
	// Likely suspect was found
	return likely_suspect.actor;
}