Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.50 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 = 0.94; //static friction coeff.
  22. float sliction = 0.87; //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.setSliction( sliction );
  128. w.setPacejka( 1, 0.0 );
  129. w.setFriction( insider_friction );
  130. w.setPacejka( 3, 0.000 );//0.013 );
  131. w.setStiffness( stiffness );
  132. w.setPacejka( 5, 0.0 );
  133. w.setPacejka( 6, 0.0 );
  134. w.setPacejka( 7, 0.0 );
  135. w.setPacejka( 8, -1.00000 );//par_8 );
  136. w.setPacejka( 9, 0.0 );
  137. w.setPacejka( 10, 0.0 );
  138. w.setMaxLoad( loadcap );
  139. w.setPacejka( 12, 1.0 );//0.2 );
  140. // w.setPacejka( 15, load_progress ); // nevleges load a 'stiffness'-hez
  141. // w.setPacejka( 16, load_progress ); // +load ; 15+16 -nal lesz fel 'stiffness' ertek
  142. w.setFrictn_x( 1.0 );
  143. w.setLoadSmooth( 0.4 );
  144.  
  145. w.setRadius( radius );
  146. w.setWidth( tyre_width/1000.0 );
  147. w.setRollRes( rollres );
  148. w.setBearing( 20.0 );
  149.  
  150. /*
  151. System.log("Pacejka vars for tyre #"+getWheelID()+" ("+name+")");
  152. System.log(" Sliction: "+sliction);
  153. System.log(" #1: "+0.0);
  154. System.log(" Friction: "+friction);
  155. System.log(" #3: "+0.000 );//0.013 );
  156. System.log(" Stiffness: "+stiffness);
  157. System.log(" #5: "+0.0);
  158. System.log(" #6: "+0.0);
  159. System.log(" #7: "+0.0);
  160. System.log(" #8: "+(-1.00000) );//par_8 );
  161. System.log(" #9: "+0.0);
  162. System.log(" #10: "+0.0);
  163. System.log(" Load capacity: "+loadcap);
  164. System.log(" #12: "+1.0 );//0.2 );
  165. System.log(" Friction-x: "+1.0);
  166. System.log(" LoadSmooth: "+0.4);
  167. */
  168.  
  169. int whlID = getWheelID();
  170.  
  171. if ((whlID>=0) && ((whlID % 2)==1))
  172. setSlotPos(1, new Vector3(0.0,0.0,0.0), new Ypr(0.0,0.0,0.0) );
  173. else
  174. setSlotPos(1, new Vector3(0.0,0.0,0.0), new Ypr(3.142,0.0,0.0) );
  175. }
  176. }
  177.  
  178. public void SetupRubber( int RT )
  179. {
  180. String compound_label;
  181.  
  182. if (RT == tcSPORT) // sport tyre //
  183. {
  184. rubber_rigidity = 2.900; // the higher this value is the less traction there is
  185. load_mul = 0.800*load_mul2;
  186. min_rollres = 0.005*roll_res_mul; // tyre: depends on contact patch
  187. friction = default_fric/rubber_rigidity; // tyre: static friction (compound efficiency)
  188. sliction = 0.740*slic_mul; // tyre: slip ratio (sliction*friction = slipfriction)
  189. frictn_x = 1.000; // tyre: longitudinal friction and sliction * ratio = horizontal friction and sliction
  190. loadsmooth = 0.300;
  191. compound_label = " medium compound sport tyre";
  192. police_check_fine_value = 0.0;
  193. } else
  194. if (RT == tcSUPERSPORT) // supersport tyre //
  195. {
  196. rubber_rigidity = 1.950;
  197. load_mul = 0.800*load_mul2;
  198. min_rollres = 0.064*roll_res_mul; // tyre: depends on contact patch
  199. friction = default_fric/rubber_rigidity; // tyre: static friction (compound efficiency)
  200. sliction = 0.760*slic_mul; // tyre: slip ratio (sliction*friction = slipfriction)
  201. frictn_x = 2.120; // tyre: longitudinal friction and sliction * ratio = horizontal friction and sliction
  202. loadsmooth = 0.250;
  203. compound_label = " soft compound racing tyre";
  204. police_check_fine_value = 50.0;
  205. } else
  206. if (RT == tcDRAGRADIAL) // drag-radial //
  207. {
  208. rubber_rigidity = 0.550;
  209. load_mul = 1.800*load_mul2;
  210. min_rollres = 0.002*roll_res_mul; // tyre: depends on contact patch
  211. friction = default_fric/rubber_rigidity; // tyre: static friction (compound efficiency)
  212. sliction = 0.720*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.750;
  215. compound_label = " drag radial";
  216. police_check_fine_value = 50.0;
  217. }
  218. else
  219. if (RT == tcSTREET) // street tyre //
  220. {
  221. rubber_rigidity = 1.550;
  222. load_mul = 0.750*load_mul2;
  223. min_rollres = 0.0055*roll_res_mul; // tyre: depends on contact patch
  224. friction = default_fric/rubber_rigidity; // tyre: static friction (compound efficiency)
  225. sliction = 0.695*slic_mul; // tyre: slip ratio (sliction*friction = slipfriction)
  226. frictn_x = 1.000; // tyre: longitudinal friction and sliction * ratio = horizontal friction and sliction
  227. loadsmooth = 0.500;
  228. compound_label = " hard compound street tyre";
  229. police_check_fine_value = 0.0;
  230. }
  231. else
  232. {
  233. rubber_rigidity = 1.000;
  234. load_mul = 0.750*load_mul2;
  235. min_rollres = 0.0055*roll_res_mul; // tyre: depends on contact patch
  236. friction = default_fric/rubber_rigidity; // tyre: static friction (compound efficiency)
  237. sliction = 0.695*slic_mul; // tyre: slip ratio (sliction*friction = slipfriction)
  238. frictn_x = 1.000; // tyre: longitudinal friction and sliction * ratio = horizontal friction and sliction
  239. loadsmooth = 0.500;
  240. compound_label = " tyre";
  241. police_check_fine_value = 0.0;
  242. }
  243. friction = (1.3+(friction-1.0)/0.8*0.4)*1.15;
  244. value /= rubber_rigidity;
  245. brand_new_prestige_value = 25.0/rubber_rigidity + tyre_width/10.0-20.0;
  246. name = name_prefix + " " + tyre_size_label+compound_label;
  247. }
  248.  
  249. public void calcStuffs()
  250. {
  251. for (minRimWidth_i=0; minRimWidth_i<21; minRimWidth_i++)
  252. if (render_types[minRimWidth_i])
  253. {
  254. minRimWidth = minRimWidth_i*0.5+5.0;
  255. break;
  256. }
  257.  
  258. for (maxRimWidth_i=20; maxRimWidth_i>=0; maxRimWidth_i--)
  259. if (render_types[maxRimWidth_i])
  260. {
  261. maxRimWidth = maxRimWidth_i*0.5+5.0;
  262. break;
  263. }
  264.  
  265. float R = wheel_radius*2.0/25.4;
  266. 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.");
  267.  
  268. if (police_check_fine_value > 0.0)
  269. description = description + Float.toString(police_check_fine_value, " This tyre is not street legal! Police may fine you up to $%1.0f!");
  270. }
  271.  
  272. public String installCheck( Part p, int[] slotId )
  273. {
  274. if (p)
  275. {
  276. if (p instanceof Wheel)
  277. {
  278. Wheel wheel = p;
  279. int wr1=wheel.wheel_radius*1000.0;
  280. int wr2=wheel_radius;
  281. if (wr1 != wr2)
  282. return "The tyre inner radius does not match the rim!";
  283. else
  284. if (wheel.rim_width > maxRimWidth)
  285. return "This tyre is too narrow for this rim!";
  286. else
  287. if (wheel.rim_width < minRimWidth)
  288. return "This tyre is too wide for this rim!";
  289.  
  290. return null;
  291. }
  292. else
  293. return "Tyres can only be installed on rims!";
  294. }
  295. //else
  296. return "There's nothing to install this part to!";
  297. }
  298.  
  299. public void SetupTyre( float W, float r, float R, float rW, int compound_type )
  300. {
  301. SetupTyre( W, r, R, rW, compound_type, -1.0 );
  302. }
  303.  
  304. public void SetupTyre( float W, float r, float R, float rW, int compound_type, float optI )
  305. {
  306. value = HUF2USD(W*80+2500*(R-13.0));
  307.  
  308. wheel_radius = R*25.4/2.0;
  309. tyre_width = W;
  310. profile_ratio = r/100.0;
  311. if (optI > 0.0)
  312. optimal_inflation = optI;
  313. slide_cm = (tyre_width-rW*25.4)/10.0;
  314. slide_interval = (tyre_width-rW*25.4)/tyre_width; // Sala: percentage to the tyre width //
  315. if (slide_interval < 0.0)
  316. slide_interval = 0.0;
  317. if (slide_interval > 1.0)
  318. slide_interval = 1.0;
  319.  
  320. profile_height = tyre_width*profile_ratio;
  321. max_radius = (wheel_radius+profile_height)/1000.0; // Sala: mm -> m //
  322. min_radius = wheel_radius/1000.0; // Sala: 1.5cm more than rim diameter, mm -> m //
  323. if (max_radius < min_radius)
  324. min_radius = max_radius-0.01;
  325.  
  326. SetupRubber(compound_type);
  327. if (optI > 0.0)
  328. SetInflation(optimal_inflation);
  329. }
  330.  
  331. public void updatevariables()
  332. {
  333. SetInflation(inflation,1);
  334. }
  335.  
  336. public void load( File saveGame )
  337. {
  338. super.load( saveGame );
  339.  
  340. int save_ver = saveGame.readInt();
  341.  
  342. if (save_ver >= 1)
  343. {
  344. inflation = saveGame.readFloat();
  345. }
  346. }
  347.  
  348. public void save( File saveGame )
  349. {
  350. super.save( saveGame );
  351.  
  352. int save_ver = 1;
  353.  
  354. saveGame.write( save_ver );
  355. if (save_ver >= 1)
  356. {
  357. saveGame.write( inflation );
  358. }
  359. }
  360.  
  361. //---------tuning
  362. public int isTuneable()
  363. {
  364. return 1;
  365. }
  366.  
  367. // backup values //
  368. float old_inflation;
  369. float new_inflation;
  370.  
  371. public void buildTuningMenu( Menu m )
  372. {
  373. old_inflation = inflation;
  374. new_inflation = inflation;
  375. 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)"));
  376. }
  377.  
  378. public void endTuningSession( int cancelled )
  379. {
  380. if( cancelled )
  381. {
  382. SetInflation(old_inflation,1);
  383. }
  384. else
  385. {
  386. SetInflation(new_inflation,1);
  387. GameLogic.spendTime(1*60);
  388. }
  389.  
  390. getCar_LocalVersion();
  391. if (the_car)
  392. the_car.forceUpdate();
  393. }
  394.  
  395. public void handleMessage( Event m )
  396. {
  397. if( m.cmd == 1 )
  398. {
  399. new_inflation = ((Slider)m.gadget).value;
  400. ((Slider)m.gadget).changeVLabelText( Float.toString(new_inflation, "%1.2f bar")+Float.toString(new_inflation*14.7, " (%1.2f psi)"));
  401. }
  402. }
  403. //---------tuning
  404. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement