#ifndef __MONKEYCAR_PERSON__	
#define __MONKEYCAR_PERSON__
#include <memory>
#include "base_data.h"
#include "linear_fit.h"
#include "fp_path.h"
#include "monkey_fit.h"
#include "../point.h"

struct monkey_bus;
struct monkey_area;

#define MAX_POINT_V 30
#define MAX_GETOFF_NUM 5
#define ZERO_  1E-5
extern const int num_fit_point[4];

struct monkey_person
{
	std::weak_ptr<monkey_bus>  m_bus;
	std::weak_ptr<monkey_area> m_area;
	
	std::deque<st_coord> m_fit_point;


	monkey_person(std::shared_ptr<monkey_area> area);

	~monkey_person();

	void GetOnTheBus(std::shared_ptr<monkey_bus> bus,double speed);
	void GetOffTheBus();
	bool Judge_OffIndex();
	void resetOffIndex();

	bool is_on_bus() const;
	std::shared_ptr<monkey_bus> getBus();

	bool on_step_map(const st_coord & pt);

	bool fit_speed(double*ret_speed);
	bool get_num_point(int * p);
	bool init_another_list(size_t index);
	point getPoint(uint64_t t)
	{
		point p;
		const auto pt = get_position();
		t=m_timeval;
		if(point_2::is_valid(pt))
		{
			p.x = pt.x_;
			p.y = pt.y_;
		}
		return p;
	}
	
	inline void setCompensationSpeed(double v)
	{
		//debug_print_syslog(0,"[framework adjust speed] :%s,v:%f",getCardId().c_str(),v);
		m_compensation_speed = v;
	}

	void reset(double speed);
	void Set_AverageSpeed();
	void handle_monkeycar_fit(double);
private:
	point_2 get_position();
public:
	int				m_getOffIndex;
	double			m_cur_distance;   //curTime distance
	double			m_compensation_speed;
	uint64_t		m_timeval;
	uint64_t		m_adjustDis_timeval;
	uint64_t		m_timestamp;

	comp_linear_fit* m_linear_fit;
	std::array<monkey_fit*,2> mp_monkey_fit;
};

#endif
