Object Oriented robots

The version 0.80 introduce the concept of is Object Oriented robots.

In the previous versions of Rars, the robots where defined as a function

  con_vec RobotName( situation &s )

This function was called several times in the program for several reasons.

1) A first time with an empty situation, to ask for the name of the robot.
2) At the beginning of a race, with s.starting = 1, to allow the robots to prepare themselves for a race, a track.
3) And finally a lot of times with s.starting = 0 during the simulation.

The simplest robot looks like this.
 
The simplest robot
#include "car.h"

con_vec RobotName( situation &s )
{
  static int      init_flag = 1, high_speed=0;
  con_vec         result;

  if (init_flag == 1) 
  {
    my_name_is("robot_name);
    init_flag = 0;
    return result;
  }

  if( s.starting )
  {
    result.fuel_amount = MAX_FUEL;     // fuel when starting
  }

  if (stuck(s.backward, s.v, s.vn, s.to_lft, s.to_rgt, &result.alpha, &result.vc)) 
  {
    return result;
  }

  result.vc = 20;                      // going slowly
  result.alpha = 0.0;                  // straight
  result.request_pit = 0;              // do not ask to pit

  return result;
}

From the version Rars 0.80, it is possible to write Object Oriented Robots. Robots are defined as C++ classes subclassing the type Driver

  class ObjectOriented : public Driver

associated with a function to create an object

  Driver * getObjectOrientedInstance()
 

This object works like this:

  1. During the construction of the object, the object declares

  2. - Its name
    - Its author
    - Its colors
    - Its bitmap
  3. The function "drive" is called at the beginning of a race, with s.starting = 1.
  4. And finally a lot of times with s.starting = 0 during the simulation.
The simplest object oriented robot looks like this. (The code is available in tutorial1.cpp)
 
The simplest object oriented robot
#include "car.h"

class Tutorial1 : public Driver
{
public:
   Tutorial1::Tutorial1()
   {
     m_sName = "Tuto 1";
     m_sAuthor = "Lucky Luke";
     m_iNoseColor = oBLUE;
     m_iTailColor = oBLUE;
     m_sBitmapName2D = "car_blue_blue";
   }

  con_vec drive(situation& s)
  {
    con_vec result; 

    if( s.starting )
    {
      result.fuel_amount = MAX_FUEL;     // fuel when starting
    }

    if( stuck( s.backward, s.v, s.vn, s.to_lft, s.to_rgt, &result.alpha, &result.vc ) )
    {
      return result;
    }

    result.vc = 20;                      // going slowly
    result.alpha = 0.0;                  // straight
    result.request_pit = 0;              // do not ask to pit

    return result;
  }
};

Driver * getTutorial1Instance()

  return new Tutorial1();
}
 

There are a least 2 main advantages:

1) The object robots can be created several times.
2) The object can declare its color and its name more properly.