Advertisement
Guest User

Untitled

a guest
Aug 28th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.24 KB | None | 0 0
  1. package java.game.parts.rgearpart.reciprocatingrgearpart;
  2.  
  3. import java.render.osd.*;
  4. import java.io.*;
  5. import java.util.*;
  6. import java.util.resource.*;
  7. import java.game.cars.*;
  8. import java.game.*;
  9. import java.game.parts.*;
  10. import java.game.parts.bodypart.*;
  11. import java.game.parts.enginepart.*;
  12. import java.game.parts.rgearpart.*;
  13.  
  14. public class Tyre extends ReciprocatingRGearPart
  15. {
  16.     final static int    tcSTREET = 0;
  17.     final static int    tcSPORT = 1;
  18.     final static int    tcSUPERSPORT = 2;
  19.     final static int    tcDRAGRADIAL = 3;
  20.  
  21.     float   friction = 1.0; //static friction coeff.
  22.     float   sliction = 1.0; //ratio of dynamic/static
  23.     float   frictn_x = 1.0; //factor (unused now)
  24.     float   radius   = 0.01;
  25.     float   stiffness = 10.0;
  26.     float   rollres  = 0.01;    //rolling resistance
  27.     float   loadcap  = 5000.0;  //load capacity
  28.     float   loadsmooth = 0.5;
  29.     float   CPatchMaximumAngle = 0.300;
  30.  
  31.     // Sala: the following variables are used for scripted calculations //
  32.  
  33.     float   insider_friction = 1.0;
  34.     float   wheel_radius;
  35.     float   profile_ratio;
  36.     float   tyre_width;
  37.     float   profile_height;
  38.     float   min_radius;
  39.     float   max_radius;
  40.     float   slide_interval;
  41.  
  42.     float   min_rollres;
  43.     float   optimal_inflation;
  44.     float   inflation;
  45.     float   par_8;
  46.  
  47.     int maxRimWidth_i;
  48.     int minRimWidth_i;
  49.     float   maxRimWidth;
  50.     float   minRimWidth;
  51.  
  52.     float   default_fric=1.0;
  53.     float   fric_mul=1.30;
  54.     float   load_mul2=10.500;
  55.     float   CPatchMaxA=16.000;
  56.     float   CPatchMinA= 4.000;
  57.     float   roll_res_mul = 0.725;
  58.     float   slic_mul=1.100;
  59.     float   rubber_rigidity=1.000;
  60. //  float   load_progress = 0.000;
  61.  
  62.     float   load_mul=1.000;
  63.  
  64.     // debug vars, remove them after use //
  65.     float   slide_cm;
  66.    
  67.     int[]   render_types = new int[22];
  68.     String  tyre_size_label;
  69.  
  70.     public Tyre()
  71.     {
  72.         repair_max_wear = 0.0;
  73.         prestige_calc_weight = 15.0;
  74.  
  75.         catalog_view_ypr = new Ypr( 1.571, -0.7, 0.0 );
  76.     }
  77.  
  78.     public void SetInflation( float I )
  79.     {
  80.         SetInflation( I, 0 );
  81.     }
  82.  
  83.     public void SetInflation( float I, int forced )
  84.     {
  85.         if (inflation != I || forced)
  86.         {
  87.             inflation = I;
  88.  
  89.             if (inflation < 0.5)
  90.                 inflation = 0.5;
  91.             if (inflation > optimal_inflation)
  92.                 inflation = optimal_inflation;
  93.  
  94.             float misinflation;
  95.  
  96.             if (inflation < optimal_inflation)
  97.                 misinflation = inflation / optimal_inflation;
  98.             else
  99.                 misinflation = optimal_inflation / inflation;
  100.  
  101.             misinflation = misinflation*misinflation*misinflation*0.6+0.4;
  102.  
  103. //          System.log("misinflation = "+misinflation);
  104.  
  105.             insider_friction = friction * (0.5+0.5*(tyre_width/275.0)) * fric_mul;
  106.  
  107.             float t = profile_ratio*optimal_inflation/inflation;
  108.  
  109.             loadcap = 4000.0+(0.75+profile_ratio/0.4*0.25)*(0.9+0.1*t)*(tyre_width-165.0)*9.81*load_mul*1.350/friction/fric_mul; // tyre: max load capacity (Ns = kgs*gravity)
  110.             loadcap /= rubber_rigidity;
  111.             CPatchMaximumAngle = 3.1415926535897932384626433832795/180.0 * (CPatchMinA+(0.6+(405.0-tyre_width)/405.0*0.4) /* *misinflation */ *profile_ratio*(CPatchMaxA-CPatchMinA));
  112. //          System.log(name+"->CPatchMaximumAngle = "+CPatchMaximumAngle);
  113.             stiffness = -18.0+(1.0-slide_interval)*(1.0-profile_ratio)*(0.5+0.5*misinflation)*80.0;
  114.             stiffness = clampTo(stiffness,8.0,40.0);
  115.             radius = max_radius; // min_radius+(max_radius-min_radius)/misinflation;
  116.             rollres = misinflation*min_rollres;//*(1.0-(tyre_width-215.0)/1000.0);      // tyre: rolling resistance - hungarian note: az inflation fuggvenye
  117.  
  118.             setMaxWear((0.15+(rubber_rigidity*rubber_rigidity*rubber_rigidity*rubber_rigidity)*0.85)*50000000000.0*misinflation);
  119.  
  120.             par_8 = 1.055+(insider_friction-default_fric)*0.045;
  121.         }
  122.  
  123.         WheelRef w = getWheel();
  124.  
  125.         if (w)
  126.         {
  127.             w.setPacejka(  0, 1.5 );//b0 //1.5
  128.             w.setPacejka(  1, 0.0 );//b1
  129.             w.setPacejka(  2, 1100.0 );//b2 //1100
  130.             w.setPacejka(  3, 0.0 );//b3 //0.013 );
  131.             w.setPacejka(  4, 300.0 );//300
  132.             w.setPacejka(  5, 0.0 );
  133.             w.setPacejka(  6, 0.0 );
  134.             w.setPacejka(  7, 0.0 );
  135.             w.setPacejka(  8, -2.0 );//par_8 );
  136.             w.setPacejka(  9, 0.0 );
  137.             w.setPacejka( 10, 0.0 );
  138.             w.setPacejka( 11, 0.0 );
  139.             w.setPacejka( 12, 0.0 );//0.2 );
  140.             w.setPacejka( 13, 0.0 );
  141.             w.setPacejka( 14, 1.4 );//a0
  142.             w.setPacejka( 15, 0.0 );//a1
  143.             w.setPacejka( 16, 1100.0 );//a2
  144.             w.setPacejka( 17, 1100.0 );//a3
  145.             w.setPacejka( 18, 0.0 );//a4
  146.             w.setPacejka( 19, 0.0 );//a5
  147.             w.setPacejka( 20, 0.0 );//a6
  148.             w.setPacejka( 21, -2.0 );//a7
  149.             w.setPacejka( 22, 0.0 );//a8
  150.             w.setPacejka( 23, 0.0 );//a9
  151.             w.setPacejka( 24, 0.0 );
  152.             w.setPacejka( 25, 0.0 );
  153.             w.setPacejka( 26, 0.0 );
  154.             w.setPacejka( 27, 0.0 );
  155.             w.setPacejka( 28, 0.0 );
  156.             w.setPacejka( 29, 0.0 );
  157.             w.setPacejka( 30, 0.0 );
  158. //          w.setPacejka( 15, load_progress ); // nevleges load a 'stiffness'-hez
  159. //          w.setPacejka( 16, load_progress ); // +load ; 15+16 -nal lesz fel 'stiffness' ertek
  160.  
  161.             w.setFrictn_x( 1.0 );
  162.             w.setLoadSmooth( 0.4 );
  163.            
  164.             w.setMaxLoad( loadcap );
  165.             w.setStiffness( stiffness );
  166.             w.setFriction( insider_friction );
  167.             w.setSliction( sliction );
  168.             w.setRadius( radius );
  169.             w.setWidth( tyre_width/1000.0 );
  170.             w.setRollRes( 0.0 );
  171.             w.setBearing( 20.0 );
  172.             w.setCPatch(tyre_width/2,CPatchMaximumAngle, 0.0);//contact patch
  173.            
  174.             /*
  175.             System.log("Pacejka vars for tyre #"+getWheelID()+" ("+name+")");
  176.             System.log("  Sliction: "+sliction);
  177.             System.log("  #1: "+0.0);
  178.             System.log("  Friction: "+friction);
  179.             System.log("  #3: "+0.000 );//0.013 );
  180.             System.log("  Stiffness: "+stiffness);
  181.             System.log("  #5: "+0.0);
  182.             System.log("  #6: "+0.0);
  183.             System.log("  #7: "+0.0);
  184.             System.log("  #8: "+(-1.00000) );//par_8 );
  185.             System.log("  #9: "+0.0);
  186.             System.log("  #10: "+0.0);
  187.             System.log("  Load capacity: "+loadcap);
  188.             System.log("  #12: "+1.0 );//0.2 );
  189.             System.log("  Friction-x: "+1.0);
  190.             System.log("  LoadSmooth: "+0.4);
  191.             */
  192.  
  193.             int whlID = getWheelID();
  194.  
  195.             if ((whlID>=0) && ((whlID % 2)==1))
  196.                 setSlotPos(1, new Vector3(0.0,0.0,0.0), new Ypr(0.0,0.0,0.0) );
  197.             else
  198.                 setSlotPos(1, new Vector3(0.0,0.0,0.0), new Ypr(3.1415926535897932384626433832795,0.0,0.0) );
  199.         }
  200.     }
  201.  
  202.     public void SetupRubber( int RT )
  203.     {
  204.         String compound_label;
  205.  
  206.         if (RT == tcSPORT) // sport tyre //
  207.         {
  208.             rubber_rigidity =    0.900;
  209.             load_mul    =    0.800*load_mul2;
  210.             min_rollres =    0.005*roll_res_mul;        // tyre: depends on contact patch
  211.             friction    =    default_fric/rubber_rigidity;  // tyre: static friction (compound efficiency)
  212.             sliction    =    0.740*slic_mul;        // tyre: slip ratio (sliction*friction = slipfriction)
  213.             frictn_x    =    1.000;         // tyre: longitudinal friction and sliction * ratio = horizontal friction and sliction
  214.             loadsmooth  =    0.300;
  215.             compound_label  = " medium compound sport tyre";
  216.             police_check_fine_value = 0.0;
  217.         } else
  218.         if (RT == tcSUPERSPORT) // supersport tyre //
  219.         {
  220.             rubber_rigidity =    0.750;
  221.             load_mul    =    0.800*load_mul2;
  222.             min_rollres =    0.004*roll_res_mul;        // tyre: depends on contact patch
  223.             friction    =    default_fric/rubber_rigidity;  // tyre: static friction (compound efficiency)
  224.             sliction    =    0.760*slic_mul;        // tyre: slip ratio (sliction*friction = slipfriction)
  225.             frictn_x    =    1.000;         // tyre: longitudinal friction and sliction * ratio = horizontal friction and sliction
  226.             loadsmooth  =    0.250;
  227.             compound_label  = " soft compound racing tyre";
  228.             police_check_fine_value = 50.0;
  229.         } else
  230.         if (RT == tcDRAGRADIAL) // drag-radial //
  231.         {
  232.             rubber_rigidity =    0.550;
  233.             load_mul    =    1.800*load_mul2;
  234.             min_rollres =    0.002*roll_res_mul;        // tyre: depends on contact patch
  235.             friction    =    default_fric/rubber_rigidity;  // tyre: static friction (compound efficiency)
  236.             sliction    =    0.720*slic_mul;        // tyre: slip ratio (sliction*friction = slipfriction)
  237.             frictn_x    =    1.000;         // tyre: longitudinal friction and sliction * ratio = horizontal friction and sliction
  238.             loadsmooth  =    0.750;
  239.             compound_label  = " drag radial";
  240.             police_check_fine_value = 50.0;
  241.         }
  242.         else
  243.         if (RT == tcSTREET) // street tyre //
  244.         {
  245.             rubber_rigidity =    1.000;
  246.             load_mul    =    0.750*load_mul2;
  247.             min_rollres =    0.0055*roll_res_mul;       // tyre: depends on contact patch
  248.             friction    =    default_fric/rubber_rigidity;  // tyre: static friction (compound efficiency)
  249.             sliction    =    0.695*slic_mul;        // tyre: slip ratio (sliction*friction = slipfriction)
  250.             frictn_x    =    1.000;         // tyre: longitudinal friction and sliction * ratio = horizontal friction and sliction
  251.             loadsmooth  =    0.500;
  252.             compound_label  = " hard compound street tyre";
  253.             police_check_fine_value = 0.0;
  254.         }
  255.         else
  256.         {
  257.             rubber_rigidity =    1.000;
  258.             load_mul    =    0.750*load_mul2;
  259.             min_rollres =    0.0055*roll_res_mul;       // tyre: depends on contact patch
  260.             friction    =    default_fric/rubber_rigidity;  // tyre: static friction (compound efficiency)
  261.             sliction    =    0.695*slic_mul;        // tyre: slip ratio (sliction*friction = slipfriction)
  262.             frictn_x    =    1.000;         // tyre: longitudinal friction and sliction * ratio = horizontal friction and sliction
  263.             loadsmooth  =    0.500;
  264.             compound_label  = " tyre";
  265.             police_check_fine_value = 0.0;
  266.         }
  267.         friction = (1.3+(friction-1.0)/0.8*0.4)*1.15;
  268.         value /= rubber_rigidity;
  269.         brand_new_prestige_value = 25.0/rubber_rigidity + tyre_width/10.0-20.0;
  270.         name = name_prefix + " " + tyre_size_label+compound_label;
  271.     }
  272.  
  273.     public void calcStuffs()
  274.     {
  275.         for (minRimWidth_i=0; minRimWidth_i<21; minRimWidth_i++)
  276.             if (render_types[minRimWidth_i])
  277.             {
  278.                 minRimWidth = minRimWidth_i*0.5+5.0;
  279.                 break;
  280.             }
  281.  
  282.         for (maxRimWidth_i=20; maxRimWidth_i>=0; maxRimWidth_i--)
  283.             if (render_types[maxRimWidth_i])
  284.             {
  285.                 maxRimWidth = maxRimWidth_i*0.5+5.0;
  286.                 break;
  287.             }
  288.            
  289.         float R = wheel_radius*2.0/25.4;
  290.         description = "This "+name+" is a "+Float.toString(tyre_width, "%1.0f mm wide ")+" tyre, that's diameter is "+Float.toString(R, "%1.0f inch at the rims and the height of its sidewalls is ")+Float.toString(profile_height, "%1.0f mm. ")+Float.toString(R, "It is compatible with all %1.0f inch rims ")+Float.toString(minRimWidth, "that are between %1.1f and ")+Float.toString(maxRimWidth, "%1.1f inch in width.");
  291.  
  292.         if (police_check_fine_value > 0.0)
  293.             description = description + Float.toString(police_check_fine_value, " This tyre is not street legal! Police may fine you up to $%1.0f!");
  294.     }
  295.  
  296.     public String installCheck( Part p, int[] slotId )
  297.     {
  298.         if (p)
  299.         {
  300.             if (p instanceof Wheel)
  301.             {
  302.                 Wheel wheel = p;
  303.                 int wr1=wheel.wheel_radius*1000.0;
  304.                 int wr2=wheel_radius;
  305.                 if (wr1 != wr2)
  306.                     return "The tyre inner radius does not match the rim!";
  307.                 else
  308.                 if (wheel.rim_width > maxRimWidth)
  309.                     return "This tyre is too narrow for this rim!";
  310.                 else
  311.                 if (wheel.rim_width < minRimWidth)
  312.                     return "This tyre is too wide for this rim!";
  313.  
  314.                 return null;
  315.             }
  316.             else
  317.                 return "Tyres can only be installed on rims!";
  318.         }
  319.         //else
  320.         return "There's nothing to install this part to!";
  321.     }
  322.  
  323.     public void SetupTyre( float W, float r, float R, float rW, int compound_type )
  324.     {
  325.         SetupTyre( W, r, R, rW, compound_type, -1.0 );
  326.     }
  327.  
  328.     public void SetupTyre( float W, float r, float R, float rW, int compound_type, float optI )
  329.     {
  330.         value = HUF2USD(W*80+2500*(R-13.0));
  331.  
  332.         wheel_radius    = R*25.4/2.0;
  333.         tyre_width  = W;
  334.         profile_ratio   = r/100.0;
  335.         if (optI > 0.0)
  336.             optimal_inflation = optI;
  337.         slide_cm    = (tyre_width-rW*25.4)/10.0;
  338.         slide_interval  = (tyre_width-rW*25.4)/tyre_width; // Sala: percentage to the tyre width //
  339.         if (slide_interval < 0.0)
  340.             slide_interval = 0.0;
  341.         if (slide_interval > 1.0)
  342.             slide_interval = 1.0;
  343.  
  344.         profile_height  = tyre_width*profile_ratio;
  345.         max_radius      = (wheel_radius+profile_height)/1000.0; // Sala: mm -> m //
  346.         min_radius      = wheel_radius/1000.0; // Sala: 1.5cm more than rim diameter, mm -> m //
  347.         if (max_radius < min_radius)
  348.             min_radius = max_radius-0.01;
  349.  
  350.         SetupRubber(compound_type);
  351.         if (optI > 0.0)
  352.             SetInflation(optimal_inflation);
  353.     }
  354.  
  355.     public void updatevariables()
  356.     {
  357.         SetInflation(inflation,1);
  358.     }
  359.  
  360.     public void load( File saveGame )
  361.     {
  362.         super.load( saveGame );
  363.  
  364.         int save_ver = saveGame.readInt();
  365.  
  366.         if (save_ver >= 1)
  367.         {
  368.             inflation = saveGame.readFloat();
  369.         }
  370.     }
  371.  
  372.     public void save( File saveGame )
  373.     {
  374.         super.save( saveGame );
  375.  
  376.         int save_ver = 1;
  377.  
  378.         saveGame.write( save_ver );
  379.         if (save_ver >= 1)
  380.         {
  381.             saveGame.write( inflation );
  382.         }
  383.     }
  384.  
  385.     //---------tuning
  386.     public int isTuneable()
  387.     {
  388.         return 1;
  389.     }
  390.  
  391.     // backup values //
  392.     float   old_inflation; 
  393.     float   new_inflation;
  394.  
  395.     public void buildTuningMenu( Menu m )
  396.     {
  397.         old_inflation = inflation;
  398.         new_inflation = inflation;
  399.         m.addItem( "Inflation",     1, inflation, 0.5, optimal_inflation, (optimal_inflation-0.5)/0.1+1, null ).changeVLabelText( Float.toString(new_inflation, "%1.2f bar")+Float.toString(new_inflation*14.7, " (%1.2f psi)"));
  400.     }
  401.  
  402.     public void endTuningSession( int cancelled )
  403.     {
  404.         if( cancelled )
  405.         {
  406.             SetInflation(old_inflation,1);
  407.         }
  408.         else
  409.         {
  410.             SetInflation(new_inflation,1);
  411.             GameLogic.spendTime(1*60);
  412.         }
  413.  
  414.         getCar_LocalVersion();
  415.         if (the_car)
  416.             the_car.forceUpdate();
  417.     }
  418.  
  419.     public void handleMessage( Event m )
  420.     {
  421.         if( m.cmd == 1 )
  422.         {
  423.             new_inflation = ((Slider)m.gadget).value;
  424.             ((Slider)m.gadget).changeVLabelText( Float.toString(new_inflation, "%1.2f bar")+Float.toString(new_inflation*14.7, " (%1.2f psi)"));
  425.         }
  426.     }
  427.     //---------tuning
  428. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement