/* 
   Project: coevolutionary GP moto driving
   Dana Vrajitoru and Russel Mehler
   agent_steering.cc
   
   An agent class controling the steering.
     - determines whether to control by agent_hbar or agent_lean 
  
**/

#include <iostream>
using namespace std;
#include <cmath>
#include "agent_steering.h"
#include "agent_hbar.h"
#include "agent_lean.h"
#include "manager.h"

// constructor
Agent_steering::Agent_steering() : Agent()
{
  slow = new Agent_hbar();
  slow->set_id(my_id+1);
  if (boss)
    slow->set_manager(boss);
  fast = new Agent_lean();
  fast->set_id(my_id+2);
  if (boss)
    fast->set_manager(boss);
  set_nr_config();
  slow_fast_thr = 0.5;
}

// Set the pilot manager.
void Agent_steering::set_parent(Pilot_manager *pilot)
{
  fast->set_parent(pilot);
  slow->set_parent(pilot);
  Agent::set_parent(pilot);
}

// To be called if we find out who the boss is later.
void Agent_steering::set_manager(Manager *the_boss)
{
  slow->set_manager(the_boss);
  fast->set_manager(the_boss);
  Agent::set_manager(the_boss);
}

// output the values
void Agent_steering::output_data()
{
  slow->output_data();
  fast->output_data();
}

// Set the number of configuration values. To be defined by the
// derivate classes.
void Agent_steering::set_nr_config()
{
  nr_config = slow->nr_config + fast->nr_config;
  //cout << "Steering agent setting the config nr to " << nr_config << endl;
}

// Agent-specific set data to be defined in the derivate class.
void Agent_steering::set_data(float values[])
{
  //cout << "values in steering" << endl;
  //for (int i=0; i<nr_config; i++)
  //cout << values[i] << ' ';
  cout << endl;
  slow->set_data(values);
  fast->set_data(values+slow->nr_config);
}

// This will be specific to each agent.
void Agent_steering::update_action()

{
  //cout << "in agent steering update" << endl;
  get_status();
  if (boss->moto->get_speed() < 0.5)
    slow->update_action();
  else
    fast->update_action();
  //  print_status();
}
