Advertisement
Guest User

Untitled

a guest
Sep 15th, 2014
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.60 KB | None | 0 0
  1. package java.game.parts.rgearpart.reciprocatingrgearpart;
  2. import java.render.osd.*;
  3. import java.io.*;
  4. import java.util.*;
  5. import java.util.resource.*;
  6. import java.game.cars.*;
  7. import java.game.*;
  8. import java.game.parts.*;
  9. import java.game.parts.bodypart.*;
  10. import java.game.parts.enginepart.*;
  11. import java.game.parts.rgearpart.*;
  12.  
  13. public class Tyre extends ReciprocatingRGearPart
  14. {
  15. final static int tcSTREET = 0;
  16. final static int tcSPORT = 1;
  17. final static int tcSUPERSPORT = 2;
  18. final static int tcDRAGRADIAL = 3;
  19.  
  20. //this is not where you want to edit ._.
  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 Ns, 1 lb = ~0.45 kg, 1kg = ~ 9.81N
  28. float loadsmooth = 0.5;
  29. float CPatchMaximumAngle = 0.300;
  30.  
  31. float min_pressure=0.5;//do not set lower than 0.3
  32. float max_pressure=5.0;
  33.  
  34. float deg_to_rad=3.1415926535897932384626433832795/180.0;//degrees to radians
  35. float inch_to_mm=25.4;//inches to millimetres
  36. float kg_to_n=9.80665002864;//kilograms to newtons
  37. float kg_to_lb=2.20462262;//kilograms to pounds
  38.  
  39. // Sala: the following variables are used for scripted calculations //
  40.  
  41. float insider_friction = 1.0;
  42. float wheel_radius;// inches
  43. float profile_ratio;// between 0 and 1
  44. float tyre_width;// millimetres
  45. float profile_height;// millimetres
  46. float min_radius;
  47. float max_radius;
  48. float slide_interval;
  49. float cpatch_width;// millimetres
  50. float stiffness_rate;
  51. float sliction_rate;
  52.  
  53. float min_rollres;
  54. float optimal_inflation;
  55. float inflation=2.0;
  56. float par_8;
  57. float par_15;
  58.  
  59. int maxRimWidth_i;
  60. int minRimWidth_i;
  61. float maxRimWidth;
  62. float minRimWidth;
  63.  
  64. float default_fric=1.0;
  65. float fric_mul=1.6;
  66. float load_mul2=1.00;
  67. float CPatchMaxA=16.000;
  68. float CPatchMinA= 4.000;
  69. float roll_res_mul = 0.725;
  70. float slic_mul=0.4;
  71. float rubber_rigidity=1.000;
  72.  
  73. float load_mul=1.000;
  74. float gravity=9.81;
  75. float CPatch_static_width=0;
  76. float AirPressure=2.5;
  77. float massonwheel=300;
  78.  
  79. int[] render_types = new int[22];
  80. String tyre_size_label;
  81.  
  82. TyreCalculations Calc = new TyreCalculations();
  83.  
  84. public Tyre()
  85. {
  86. repair_max_wear = 0.0;
  87. prestige_calc_weight = 15.0;
  88.  
  89. catalog_view_ypr = new Ypr( 1.571, -0.7, 0.0 );
  90. }
  91.  
  92. public void SetInflation( float I )
  93. {
  94. SetInflation( I, 0 );
  95. }
  96.  
  97. public void SetInflation( float I, int forced )
  98. {
  99. if (inflation != I || forced)
  100. {
  101. inflation = clampTo(I,min_pressure,max_pressure);
  102.  
  103. //insider_friction = friction * (0.5+0.5*(tyre_width/275.0)) * fric_mul;
  104.  
  105. loadcap = 4000.0+(0.75+profile_ratio/0.4*0.25)*(tyre_width-165.0)*gravity*load_mul*1.350/rubber_rigidity*Math.sqrt(Math.sqrt(inflation/2)); // tyre: max load capacity (Ns = kgs*gravity)
  106. CPatchMaximumAngle = deg_to_rad * (CPatchMinA+(0.6+(405.0-tyre_width)/405.0*0.4)*profile_ratio*(CPatchMaxA-CPatchMinA));
  107. stiffness = -18.0+Math.sqrt(1.0-slide_interval)*Math.sqrt(1.0-profile_ratio)*80.0/rubber_rigidity*Math.sqrt(inflation/2);
  108. stiffness = clampTo(stiffness,8.0,150.0);
  109. radius = max_radius; // min_radius+(max_radius-min_radius)/misinflation;
  110. rollres = min_rollres/Math.sqrt(Math.sqrt(inflation/2));//*(1.0-(tyre_width-215.0)/1000.0); // tyre: rolling resistance - hungarian note: function of inflation
  111. par_15=500/Math.sqrt(rubber_rigidity);
  112.  
  113. setMaxWear((0.15+(rubber_rigidity*rubber_rigidity*rubber_rigidity*rubber_rigidity)*0.85)*50000000000.0);
  114.  
  115. WheelRef w = getWheel();
  116.  
  117. if (w)
  118. {
  119. int whlID = getWheelID();
  120. massonwheel=Calc.getWeightOnWheel(whlID);
  121. Calc.setVars(tyre_width, profile_ratio*100, 255 , inflation, massonwheel);
  122.  
  123. insider_friction = friction * (0.5+0.5*(Calc.getContactPatchWidth()/250.0)) * fric_mul /Math.sqrt(Math.sqrt(Math.sqrt(inflation/2)));
  124. //cpatch_width=Calc.getContactPatchWidth();
  125. cpatch_width=Calc.getContactPatchArea();
  126. stiffness_rate=Calc.getStiffnessRate();
  127. //stiffness_rate=25*inflation+stiffness_rate*0.5;
  128. sliction_rate=sliction/Math.sqrt(Math.sqrt(inflation/2));
  129.  
  130. w.setPacejka( 0, 0.0 );//doesn't do anything because there's w.setSliction function
  131. w.setPacejka( 1, 0.000025 );//prevents tyres from sliding,loosing traction(very low value,0.00001, haven't tested yet)
  132. w.setPacejka( 2, 0.0 );//setFriction
  133. w.setPacejka( 3, 0.0 );//+
  134. w.setPacejka( 4, 0.0 );//setStiffness
  135. w.setPacejka( 5, 0.0 );//shit -
  136. w.setPacejka( 6, 0.0 );//shit -
  137. w.setPacejka( 7, 0.0 );//bouncy,gripy stuff -
  138. w.setPacejka( 8, -2.0 );//par_8
  139. w.setPacejka( 9, 0.0 );//looks like Pacejka 10, bouncing, glitchy
  140. w.setPacejka( 10, 0.0 );//does something with suspension, goes up and down while standing still
  141. w.setPacejka( 11, 0.0 );//setMaxLoad
  142. w.setPacejka( 12, 1.0 );//not sure if this does something
  143. w.setPacejka( 13, 0.0 );//doesn't do anything, some function overrides it.
  144. w.setPacejka( 14, 0.0 );//doesn't do anything, some function overrides it.
  145. w.setPacejka( 15, par_15 );//looks like load stiffness, adds understeer, should be tuned along with Pacejka16
  146. w.setPacejka( 16, par_15 );//oversteering, lower value -> more oversteering(1000)
  147.  
  148. w.setFrictn_x( 1.1 );
  149. w.setLoadSmooth( loadsmooth*(-1) );
  150.  
  151. w.setMaxLoad( loadcap );
  152. w.setStiffness( stiffness );//stiffness
  153. w.setFriction( insider_friction );
  154. w.setSliction( sliction_rate );
  155. w.setRadius( (Calc.getTyreHeight()+wheel_radius)/1000.0 );
  156. w.setWidth( Calc.getTyreWidth()/1000.0 );
  157. w.setRollRes( rollres );
  158. w.setBearing( 20.0 );//guolis
  159. //w.setCPatch(tyre_width/1000.0, CPatchMaximumAngle, 0); this is in Wheel.java
  160.  
  161. if ((whlID>=0) && ((whlID % 2)==1))//odd numbers, right side
  162. setSlotPos(1, new Vector3(0.0,0.0,0.0), new Ypr(0.0,0.0,0.0) );
  163. else//even numbers, left side
  164. setSlotPos(1, new Vector3(0.0,0.0,0.0), new Ypr(3.1415926535897932384626433832795,0.0,0.0) );
  165. }
  166. }
  167. }
  168.  
  169. public void SetupRubber( int RT )
  170. {
  171. String compound_label;
  172.  
  173. if (RT == tcSPORT) // sport tyre //
  174. {
  175. rubber_rigidity = 0.900;
  176. load_mul = 0.800*load_mul2;
  177. min_rollres = 0.005*roll_res_mul; // tyre: depends on contact patch
  178. friction = default_fric/rubber_rigidity; // tyre: static friction (compound efficiency)
  179. sliction = 0.740*slic_mul; // tyre: slip ratio (sliction*friction = slipfriction)
  180. frictn_x = 1.000; // tyre: longitudinal friction and sliction * ratio = horizontal friction and sliction
  181. loadsmooth = 2.750;
  182. compound_label = " medium compound sport tyre";
  183. police_check_fine_value = 0.0;
  184. } else
  185. if (RT == tcSUPERSPORT) // supersport tyre //
  186. {
  187. rubber_rigidity = 0.750;
  188. load_mul = 0.800*load_mul2;
  189. min_rollres = 0.004*roll_res_mul; // tyre: depends on contact patch
  190. friction = default_fric/rubber_rigidity; // tyre: static friction (compound efficiency)
  191. sliction = 0.760*slic_mul; // tyre: slip ratio (sliction*friction = slipfriction)
  192. frictn_x = 1.000; // tyre: longitudinal friction and sliction * ratio = horizontal friction and sliction
  193. loadsmooth = 3.000;
  194. compound_label = " soft compound racing tyre";
  195. police_check_fine_value = 50.0;
  196. } else
  197. if (RT == tcDRAGRADIAL) // drag-radial //
  198. {
  199. rubber_rigidity = 0.550;
  200. load_mul = 1.800*load_mul2;
  201. min_rollres = 0.002*roll_res_mul; // tyre: depends on contact patch
  202. friction = default_fric/rubber_rigidity; // tyre: static friction (compound efficiency)
  203. sliction = 0.720*slic_mul; // tyre: slip ratio (sliction*friction = slipfriction)
  204. frictn_x = 1.000; // tyre: longitudinal friction and sliction * ratio = horizontal friction and sliction
  205. loadsmooth = 2.000;
  206. compound_label = " drag radial";
  207. police_check_fine_value = 50.0;
  208. }
  209. else
  210. if (RT == tcSTREET) // street tyre //
  211. {
  212. rubber_rigidity = 1.000;
  213. load_mul = 0.750*load_mul2;
  214. min_rollres = 0.0055*roll_res_mul; // tyre: depends on contact patch
  215. friction = default_fric/rubber_rigidity; // tyre: static friction (compound efficiency)
  216. sliction = 0.695*slic_mul; // tyre: slip ratio (sliction*friction = slipfriction)
  217. frictn_x = 1.000; // tyre: longitudinal friction and sliction * ratio = horizontal friction and sliction
  218. loadsmooth = 2.500;
  219. compound_label = " hard compound street tyre";
  220. police_check_fine_value = 0.0;
  221. }
  222. else
  223. {
  224. rubber_rigidity = 1.000;
  225. load_mul = 0.750*load_mul2;
  226. min_rollres = 0.0055*roll_res_mul; // tyre: depends on contact patch
  227. friction = default_fric/rubber_rigidity; // tyre: static friction (compound efficiency)
  228. sliction = 0.695*slic_mul; // tyre: slip ratio (sliction*friction = slipfriction)
  229. frictn_x = 1.000; // tyre: longitudinal friction and sliction * ratio = horizontal friction and sliction
  230. loadsmooth = 2.500;
  231. compound_label = " tyre";
  232. police_check_fine_value = 0.0;
  233. }
  234. friction = (1.3+(friction-1.0)*0.35)*1.15;
  235. value /= rubber_rigidity;
  236. brand_new_prestige_value = 25.0/rubber_rigidity + tyre_width/10.0-20.0;
  237. if(name=="<unnamed>")//doesn't change tyres name if there's one
  238. name = tyre_size_label+compound_label;// removed name_prefix
  239. }
  240.  
  241. public void calcStuffs()
  242. {
  243. for (minRimWidth_i=0; minRimWidth_i<21; minRimWidth_i++)
  244. if (render_types[minRimWidth_i])
  245. {
  246. minRimWidth = minRimWidth_i*0.5+5.0;
  247. break;
  248. }
  249.  
  250. for (maxRimWidth_i=20; maxRimWidth_i>=0; maxRimWidth_i--)
  251. if (render_types[maxRimWidth_i])
  252. {
  253. maxRimWidth = maxRimWidth_i*0.5+5.0;
  254. break;
  255. }
  256.  
  257. float R = wheel_radius*2.0/25.4;
  258. //if(name=="<unnamed>")//doesn't change tyres name if there's one
  259. //name = tyre_size_label+compound_label;// removed name_prefix
  260.  
  261. if(maxRimWidth==minRimWidth)//a bit description fix, not much
  262. description = "This "+name+" is a "+Float.toString(tyre_width, "%1.0f mm wide ")+" tyre, diameter is "+Float.toString(R, "%1.0f inch at the rims and the height of 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 %1.1f inch width.");
  263. else
  264. description = "This "+name+" is a "+Float.toString(tyre_width, "%1.0f mm wide ")+" tyre, diameter is "+Float.toString(R, "%1.0f inch at the rims and the height of 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 width.");
  265.  
  266. if (police_check_fine_value > 0.0)
  267. description = description + Float.toString(police_check_fine_value, " This tyre is not street legal! Police may fine you up to $%1.0f!");
  268. }
  269.  
  270. public String installCheck( Part p, int[] slotId )
  271. {
  272. if (p)
  273. {
  274. if (p instanceof Wheel)
  275. {
  276. Wheel wheel = p;
  277. int wr1=wheel.wheel_radius*1000.0;
  278. int wr2=wheel_radius;
  279. if (wr1 != wr2)
  280. return "The tyre inner radius does not match the rim!";
  281. else
  282. if (wheel.rim_width > maxRimWidth)
  283. return "This tyre is too narrow for this rim!";
  284. else
  285. if (wheel.rim_width < minRimWidth)
  286. return "This tyre is too wide for this rim!";
  287.  
  288. return null;
  289. }
  290. else
  291. return "Tyres can only be installed on rims!";
  292. }
  293. return "There's nothing to install this part to!";
  294. }
  295.  
  296. public void SetupTyre( float W, float r, float R, float rW, int compound_type )
  297. {
  298. SetupTyre( W, r, R, rW, compound_type, 0.0, 104 );
  299. }
  300.  
  301. public void SetupTyre( float W, float r, float R, float rW, int compound_type, float optI )
  302. {
  303. SetupTyre( W, r, R, rW, compound_type, 0.0, 104 );
  304. }
  305.  
  306. public void SetupTyre( float W, float r, float R, float rW, int compound_type, float optI, int loadIndex )
  307. {
  308. value = HUF2USD(W*80+2500*(R-13.0));
  309.  
  310. optimal_inflation=2.0;
  311.  
  312. wheel_radius = R*25.4/2.0;
  313. tyre_width = W;
  314. cpatch_width = W;
  315. profile_ratio = r/100.0;
  316. if (optI >= min_pressure && optI <= max_pressure)
  317. optimal_inflation = optI;
  318.  
  319. slide_interval = (tyre_width-rW*25.4)/tyre_width; // Sala: percentage to the tyre width //
  320. slide_interval = clampTo(slide_interval,0.0,1.0);
  321.  
  322. profile_height = tyre_width*profile_ratio;
  323. max_radius = (wheel_radius+profile_height)/1000.0; // Sala: mm -> m //
  324. min_radius = wheel_radius/1000.0; // Sala: 1.5cm more than rim diameter, mm -> m //
  325. if (max_radius < min_radius)
  326. min_radius = max_radius-0.01;
  327.  
  328. SetupRubber(compound_type);
  329. if (optI >= min_pressure && optI <= max_pressure)
  330. SetInflation(optimal_inflation);
  331. }
  332.  
  333. public void updatevariables()
  334. {
  335. SetInflation(inflation,1);
  336. }
  337.  
  338. public void load( File saveGame )
  339. {
  340. super.load( saveGame );
  341.  
  342. int save_ver = saveGame.readInt();
  343.  
  344. if (save_ver >= 1)
  345. {
  346. inflation = saveGame.readFloat();
  347. }
  348. }
  349.  
  350. public void save( File saveGame )
  351. {
  352. super.save( saveGame );
  353.  
  354. int save_ver = 1;
  355.  
  356. saveGame.write( save_ver );
  357. if (save_ver >= 1)
  358. {
  359. saveGame.write( inflation );
  360. }
  361. }
  362.  
  363. //---------tuning
  364. public int isTuneable()
  365. {
  366. return 1;
  367. }
  368.  
  369. // backup values //
  370. float old_inflation;
  371. float new_inflation;
  372.  
  373. final static SfxRef inc_inflation_SFX = new SfxRef( MW_Mod:0x0071r );
  374. final static SfxRef dec_inflation_SFX = new SfxRef( MW_Mod:0x0072r );
  375.  
  376. public void buildTuningMenu( Menu m )
  377. {
  378. old_inflation = inflation;
  379. new_inflation = inflation;
  380. float f=Calc.getTyreHeight();
  381. m.addItem( "Tire pressure", 1, inflation, min_pressure, max_pressure, (max_pressure-min_pressure)*10+1, null ).changeVLabelText( Float.toString(new_inflation, "%1.2f bar")+Float.toString(new_inflation*14.7, " (%1.2f psi)"));//1psi = 0.069bar
  382.  
  383. getCar_LocalVersion();
  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.  
  396. float spendTime = 1 + (new_inflation > old_inflation) ? (new_inflation-old_inflation)*2*60 : 1;
  397. GameLogic.spendTime( spendTime );
  398. }
  399. GameLogic.garage.osd.text.elementAt(1).changeText( "Debug: P " + inflation + "bar, TH " + Calc.getTyreHeight() + "mm, MoW " + massonwheel + "kg, Stf " + stiffness +", StfR " + stiffness_rate + ", CPW " + cpatch_width + " LoadCap:" + loadcap +"Ns" + " silction:" + sliction_rate + " friction:" + insider_friction );
  400.  
  401. getCar_LocalVersion();
  402. if (the_car)
  403. {
  404. the_car.command( "wakeup" );
  405. }
  406. }
  407.  
  408. public void handleMessage( Event m )
  409. {
  410. if( m.cmd == 1 )
  411. {
  412. float sliderVal = ((Slider)m.gadget).value;
  413.  
  414. if( sliderVal != new_inflation )
  415. {
  416. if( sliderVal > new_inflation )
  417. inc_inflation_SFX.play( getPos(), 0.0, (sliderVal/max_pressure)+0.5, 0.5, 0, 1 ); // SFX
  418. else
  419. dec_inflation_SFX.play( getPos(), 0.0, (sliderVal/max_pressure)+0.5, 0.5, 0, 1 ); // SFX
  420.  
  421. new_inflation = sliderVal;
  422. ((Slider)m.gadget).changeVLabelText( Float.toString(new_inflation, "%1.2f bar")+Float.toString(new_inflation*14.7, " (%1.2f psi)"));
  423.  
  424. if( the_car )
  425. {
  426. System.timeWarp( 1.0f );
  427. SetInflation(new_inflation,1);
  428. the_car.command( "wakeup" );
  429. }
  430. }
  431. }
  432. }
  433. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement