Guest User

Untitled

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