cheetah.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. function CheetahCar::onAdd(%this, %obj)
  23. {
  24. Parent::onAdd(%this, %obj);
  25. %obj.setWheelTire(0,CheetahCarTire);
  26. %obj.setWheelTire(1,CheetahCarTire);
  27. %obj.setWheelTire(2,CheetahCarTireRear);
  28. %obj.setWheelTire(3,CheetahCarTireRear);
  29. // Setup the car with some tires & springs
  30. for (%i = %obj.getWheelCount() - 1; %i >= 0; %i--)
  31. {
  32. %obj.setWheelPowered(%i, true);
  33. %obj.setWheelSpring(%i, CheetahCarSpring);
  34. }
  35. // Steer with the front tires
  36. %obj.setWheelSteering(0, 1);
  37. %obj.setWheelSteering(1, 1);
  38. // Add tail lights
  39. %obj.rightBrakeLight = new PointLight()
  40. {
  41. radius = "1";
  42. isEnabled = "0";
  43. color = "1 0 0.141176 1";
  44. brightness = "2";
  45. castShadows = "1";
  46. priority = "1";
  47. animate = "0";
  48. animationPeriod = "1";
  49. animationPhase = "1";
  50. flareScale = "1";
  51. attenuationRatio = "0 1 1";
  52. shadowType = "DualParaboloidSinglePass";
  53. texSize = "512";
  54. overDarkFactor = "2000 1000 500 100";
  55. shadowDistance = "400";
  56. shadowSoftness = "0.15";
  57. numSplits = "1";
  58. logWeight = "0.91";
  59. fadeStartDistance = "0";
  60. lastSplitTerrainOnly = "0";
  61. representedInLightmap = "0";
  62. shadowDarkenColor = "0 0 0 -1";
  63. includeLightmappedGeometryInShadow = "0";
  64. rotation = "1 0 0 0";
  65. canSave = "1";
  66. canSaveDynamicFields = "1";
  67. splitFadeDistances = "10 20 30 40";
  68. };
  69. %obj.leftBrakeLight = new PointLight()
  70. {
  71. radius = "1";
  72. isEnabled = "0";
  73. color = "1 0 0.141176 1";
  74. brightness = "2";
  75. castShadows = "1";
  76. priority = "1";
  77. animate = "0";
  78. animationPeriod = "1";
  79. animationPhase = "1";
  80. flareScale = "1";
  81. attenuationRatio = "0 1 1";
  82. shadowType = "DualParaboloidSinglePass";
  83. texSize = "512";
  84. overDarkFactor = "2000 1000 500 100";
  85. shadowDistance = "400";
  86. shadowSoftness = "0.15";
  87. numSplits = "1";
  88. logWeight = "0.91";
  89. fadeStartDistance = "0";
  90. lastSplitTerrainOnly = "0";
  91. representedInLightmap = "0";
  92. shadowDarkenColor = "0 0 0 -1";
  93. includeLightmappedGeometryInShadow = "0";
  94. rotation = "1 0 0 0";
  95. canSave = "1";
  96. canSaveDynamicFields = "1";
  97. splitFadeDistances = "10 20 30 40";
  98. };
  99. // Mount a ShapeBaseImageData
  100. %didMount = %obj.mountImage(TurretImage, %this.turretSlot);
  101. // Mount the brake lights
  102. %obj.mountObject(%obj.rightBrakeLight, %this.rightBrakeSlot);
  103. %obj.mountObject(%obj.leftBrakeLight, %this.leftBrakeSlot);
  104. }
  105. function CheetahCar::onRemove(%this, %obj)
  106. {
  107. Parent::onRemove(%this, %obj);
  108. if(isObject(%obj.rightBrakeLight))
  109. %obj.rightBrakeLight.delete();
  110. if(isObject(%obj.leftBrakeLight))
  111. %obj.leftBrakeLight.delete();
  112. if(isObject(%obj.turret))
  113. %obj.turret.delete();
  114. }
  115. function serverCmdtoggleBrakeLights(%client)
  116. {
  117. %car = %client.player.getControlObject();
  118. if (%car.getClassName() $= "WheeledVehicle")
  119. {
  120. if(%car.rightBrakeLight.isEnabled)
  121. {
  122. %car.rightBrakeLight.setLightEnabled(0);
  123. %car.leftBrakeLight.setLightEnabled(0);
  124. }
  125. else
  126. {
  127. %car.rightBrakeLight.setLightEnabled(1);
  128. %car.leftBrakeLight.setLightEnabled(1);
  129. }
  130. }
  131. }
  132. // Callback invoked when an input move trigger state changes when the CheetahCar
  133. // is the control object
  134. function CheetahCar::onTrigger(%this, %obj, %index, %state)
  135. {
  136. // Pass trigger states on to TurretImage (to fire weapon)
  137. switch ( %index )
  138. {
  139. case 0: %obj.setImageTrigger( %this.turretSlot, %state );
  140. case 1: %obj.setImageAltTrigger( %this.turretSlot, %state );
  141. }
  142. }
  143. function TurretImage::onMount(%this, %obj, %slot)
  144. {
  145. // Load the gun
  146. %obj.setImageAmmo(%slot, true);
  147. }