CarMotor::CarMotor(const std::string& mainPath, CL_ResourceManager resources, CACarUpgrades* carUp)
: CarOption(resources, carUp, 5, mainPath + "motorPrice", "Engine")
{
    std::string path = mainPath + "acceleration";
    m_acceleration = 6 * resources.get_integer_resource( path, 1 );

    path = mainPath + "maxSpeed";
    m_maxSpeed = 6 * resources.get_integer_resource( path, 1 );
}
CarOption::CarOption(CL_ResourceManager resources, CACarUpgrades* carUp, int maxOption, const std::string& pathPrice, const std::string& name)
:  m_carUp(carUp), m_current(0), m_maxOpt(maxOption), m_name(name)
{
    int pathPricei = resources.get_integer_resource(pathPrice,0);
    for (int i=0; i < m_maxOpt; i++)
        m_PriceList.push_back((i*pathPricei)/2+pathPricei);
}
CarType::CarType(const std::string& mainPath, CL_ResourceManager resources, CACarUpgrades* carUp, const bool debug)
     :
         m_motor (mainPath, resources, carUp),
         m_tires (mainPath, resources, carUp),
         m_armor (mainPath, resources, carUp)
{
    if(debug) std::cout << "  name" << std::endl;

    std::string path = mainPath + "name";
    name = resources.get_string_resource( path, "name" );

    if(debug) std::cout << "  surface" << std::endl;

    path = mainPath + "surface";
    surface = CL_Texture( *CA_APP->graphicContext, path, &resources );

    if(debug) std::cout << "  surface3d" << std::endl;

    path = mainPath + "surface3d";
    surface3d = CL_Texture( *CA_APP->graphicContext, path, &resources );

    path = mainPath + "length";
    length = resources.get_integer_resource( path, 0 );
    path = mainPath + "width";
    width = resources.get_integer_resource( path, 0 );
    path = mainPath + "minSpeed";
    minSpeed = 6 * resources.get_integer_resource( path, 1 );
    path = mainPath + "maxTurbo";
    maxTurbo = resources.get_integer_resource( path, 1000 );
    path = mainPath + "acceleration";
    deceleration = 6 * resources.get_integer_resource( path, 1000 );
    path = mainPath + "steeringPower";
    steeringPower = resources.get_integer_resource( path, 1 );
    path = mainPath + "price";
    price = resources.get_integer_resource( path, 0 );


    radius = std::sqrt( (double)width/2 * (double)width/2 + (double)length/2 * (double)length/2 );
    angle = atan( (double)(width/2) / (double)(length/2) ) * ARAD;
}
CarTires::CarTires(const std::string& mainPath, CL_ResourceManager resources, CACarUpgrades* carUp)
: CarOption(resources, carUp, 5, mainPath + "tiresPrice", "Tires")
{
    std::string path = mainPath + "slidingFactor";
    m_slidingFactor = 0.01 * resources.get_integer_resource( path, 1 );
}