PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/Game/Scripts/Entities/_Archive/HeliStatic.lua

http://project-o.googlecode.com/
Lua | 518 lines | 257 code | 138 blank | 123 comment | 21 complexity | 4d5a723c8db5ea06618118c961bcbacc MD5 | raw file
  1. --
  2. -- HeliStatic
  3. -------------------------------------------------------------------------------------------------------------
  4. HeliStatic = {
  5. temp_ModelName = "none",
  6. pathStep = 0,
  7. dropState = 0,
  8. V22PhysParams = {
  9. mass = 900,
  10. height = .1,
  11. eyeheight = .1,
  12. sphereheight = .1,
  13. radius = .5,
  14. gravity = 0,
  15. aircontrol = 1,
  16. },
  17. damage = 0,
  18. bExploded = 0,
  19. pieces = {},
  20. explosionImpulse = 10,
  21. Properties = {
  22. fDmgScaleBullet = .1,
  23. fDmgScaleExplosion = 1.7,
  24. bTrackable=1,
  25. max_health = 100,
  26. bRigidBodyActive = 0,
  27. Mass = 5000,
  28. fileModel = "objects/vehicles/troopgunship/troopgunship_inflight.cgf",
  29. ExplosionParams = {
  30. nDamage = 100,
  31. fRadiusMin = 20.0, -- default 12
  32. fRadiusMax = 20.5, -- default 70.5
  33. fRadius = 20, -- default 30O
  34. fImpulsivePressure = 100600, -- default 200
  35. },
  36. sound_engine_file = "SOUNDS/Ambient/E3/hele/heleLP1.wav",
  37. },
  38. DamageParticles1 = {
  39. focus = 1.8, -- default 90
  40. speed = 1.55, -- default 0.25
  41. count = 1, -- default 1
  42. size = 0.04, size_speed=0.1, -- default size = 0.04-- default size_speed = 0.03
  43. gravity={x=0.0,y=0.0,z=0.3}, -- default z= 0.3
  44. rotation={x=0.0,y=0.0,z=1.75}, -- default z= 1.75
  45. lifetime=2, -- default 2
  46. tid = System.LoadTexture("textures/clouda.dds"),
  47. frames=0,
  48. color_based_blending = 0 -- default 0
  49. },
  50. DamageParticles2 = {
  51. focus = 1.8, -- default 1.8
  52. speed = 0.6, -- default 1
  53. count = 1, -- default 1
  54. size = 0.3, size_speed=0.5, -- default size = 1.5-- default size_speed = 0.5
  55. gravity={x=0.3,y=0.0,z=0.3}, -- default z= 0.3
  56. rotation={x=1.75,y=1,z=1.75}, -- default z= 1.75
  57. lifetime=4, -- default 7
  58. tid = System.LoadTexture("textures\\cloud_black1.dds"),
  59. frames=0,
  60. color_based_blending = 0 -- default 0
  61. },
  62. sound_engine = nil,
  63. }
  64. ----------------------------------------------------------------------------------------------------------------------------
  65. --
  66. --
  67. ----------------------------------------------------------------------------------------------------------------------------
  68. --
  69. --
  70. HeliStatic.Client = {
  71. OnInit = function(self)
  72. System.Log("Client HeliStatic onInit");
  73. self:InitClient();
  74. end,
  75. OnContact = function(self,player)
  76. self:OnContactClient(player);
  77. end,
  78. -- OnEvent = function (self, id, params)
  79. -- self:OnEventClient( id, params);
  80. -- end,
  81. OnUpdate = function(self,dt)
  82. --System.Log("V22 Client Update ");
  83. -- self:OnUpdate(dt);
  84. self:UpdateClient(dt);
  85. -- self:UpdateCommon();
  86. end
  87. }
  88. ------------------------------------------------------
  89. --
  90. --
  91. HeliStatic.Server = {
  92. OnInit = function(self)
  93. System.Log("Server HeliStatic onInit");
  94. self:InitServer();
  95. end,
  96. OnContact = function(self,player)
  97. self:OnContactServer(player);
  98. end,
  99. OnEvent = function (self, id, params)
  100. self:OnEventServer( id, params);
  101. end,
  102. OnShutDown = function (self)
  103. self:OnShutDownServer(self);
  104. end,
  105. OnUpdate = function(self,dt)
  106. --System.Log("V22 Server Update ");
  107. -- self:OnUpdate(dt);
  108. self:UpdateServer(dt);
  109. -- self:UpdateCommon();
  110. end,
  111. OnDamage = function (self, hit)
  112. self:OnDamageServer( hit );
  113. end,
  114. }
  115. ----------------------------------------------------------------------------------------------------------------------------
  116. --
  117. --
  118. function HeliStatic:OnReset()
  119. self.damage = 0;
  120. self.sound_engine = Sound.Load3DSound(self.Properties.sound_engine_file, bor(SOUND_OUTDOOR,SOUND_UNSCALABLE),255,1,100);
  121. end
  122. ----------------------------------------------------------------------------------------------------------------------------
  123. --
  124. --
  125. function HeliStatic:OnPropertyChange()
  126. self:OnReset();
  127. self:LoadModel();
  128. Sound.SetSoundLoop(self.sound_engine, 1);
  129. end
  130. ----------------------------------------------------------------------------------------------------------------------------
  131. --
  132. --
  133. function HeliStatic:LoadModel()
  134. System.Log( "loading HeliStatic "..self.Properties.fileModel );
  135. -- if(self.IsPhisicalized == 0) then
  136. if( self.temp_ModelName ~= self.Properties.fileModel ) then
  137. -- self:LoadObjectPiece(self.Properties.fileModel, -1 );
  138. self:LoadObject( self.Properties.fileModel, 0,1 );
  139. -- self:DrawObject(0,1);
  140. -- self:CreateLivingEntity(self.V22PhysParams);
  141. if (self.Properties.bRigidBodyActive == 1) then
  142. self:CreateRigidBody( 1000,5000,0 );
  143. -- self:CreateRigidBody( self.Properties.Density,self.Properties.Mass,0 );
  144. else
  145. self:CreateStaticEntity( 5000, 0 );
  146. self:EnablePhysics( 1 );
  147. self:DrawObject( 0, 1 );
  148. -- self:CreateStaticEntity( self.Properties.Mass, 0 );
  149. end
  150. self.temp_ModelName = self.Properties.fileModel;
  151. -- load parts for explosion
  152. local idx=1;
  153. local loaded=1;
  154. while loaded==1 do
  155. local piece=Server:SpawnEntity("Piece");
  156. if(piece)then
  157. System.Log( "loading Piece #"..idx );
  158. self.pieces[idx] = piece;
  159. loaded = self.pieces[idx].Load(self.pieces[idx],self.Properties.fileModel, idx );
  160. idx = idx + 1;
  161. else
  162. break
  163. end
  164. end
  165. self.pieces[idx-1] = nil;
  166. end
  167. -- self:ActivatePhysics(0);
  168. self.temp_ModelName = self.Properties.fileModel;
  169. end
  170. ----------------------------------------------------------------------------------------------------------------------------
  171. --
  172. --
  173. function HeliStatic:InitClient()
  174. self:LoadModel();
  175. self:OnReset();
  176. Sound.SetSoundLoop(self.sound_engine, 1);
  177. self.ExplosionSound=Sound.Load3DSound("sounds\\weapons\\explosions\\mbarrel.wav",0,0,7,100);
  178. end
  179. ----------------------------------------------------------------------------------------------------------------------------
  180. --
  181. --
  182. function HeliStatic:InitServer()
  183. self:OnReset();
  184. self:Activate(1);
  185. self:LoadModel();
  186. -- self:NetPresent(1);
  187. end
  188. ----------------------------------------------------------------------------------------------------------------------------
  189. --
  190. --
  191. ----------------------------------------------------------------------------------------------------------------------------
  192. --
  193. --
  194. ----------------------------------------------------------------------------------------------------------------------------
  195. --
  196. --
  197. -------------------------------------------------------------------------------------------------------------
  198. --
  199. --
  200. function HeliStatic:OnContactServer( player )
  201. if(player.type ~= "Player" ) then
  202. do return end
  203. end
  204. end
  205. -------------------------------------------------------------------------------------------------------------
  206. --
  207. --
  208. function HeliStatic:OnContactClient( player )
  209. if(player.type ~= "Player" ) then
  210. do return end
  211. end
  212. end
  213. -------------------------------------------------------------------------------------------------------------
  214. --
  215. --
  216. function HeliStatic:UpdateServer(dt)
  217. end
  218. -------------------------------------------------------------------------------------------------------------
  219. --
  220. function HeliStatic:UpdateClient(dt)
  221. --do force - grass/bushes deformation
  222. local pos = self:GetPos();
  223. pos.z=pos.z-5;
  224. System.ApplyForceToEnvironment(pos, 50, 1);
  225. --do sounds
  226. if( _localplayer and _localplayer.id and self.sound_engine ~= nil ) then
  227. -- no hellicopter sound whein inside
  228. if( System.IsPointIndoors(_localplayer:GetPos()) ) then
  229. if (Sound.IsPlaying(self.sound_engine)) then
  230. Sound.StopSound(self.sound_engine);
  231. end
  232. else
  233. Sound.SetSoundPosition(self.sound_engine, pos);
  234. if (Sound.IsPlaying(self.sound_engine) == nil) then
  235. Sound.PlaySound(self.sound_engine);
  236. end
  237. end
  238. end
  239. self:ExecuteDamageModel();
  240. end
  241. ----------------------------------------------------------------------------------------------------------------------------
  242. --
  243. function HeliStatic:OnDamageServer( hit )
  244. --do return end
  245. System.LogToConsole( "Damage "..hit.damage.." total "..self.damage );
  246. if( self.damage<0 ) then
  247. do return end
  248. end
  249. if( hit.explosion ) then
  250. self.damage = self.damage + hit.damage*self.Properties.fDmgScaleExplosion;
  251. else
  252. self.damage = self.damage + hit.damage*self.Properties.fDmgScaleBullet;
  253. end
  254. --self:SetDamage;
  255. end
  256. ----------------------------------------------------------------------------------------------------------------------------
  257. --
  258. --
  259. function HeliStatic:OnShutDownServer()
  260. System.LogToConsole( "HeliStatic OnShutDOWN ---------------------------" );
  261. for idx,piece in pairs(self.pieces) do
  262. --System.Log( " Piece #"..idx );
  263. Server:RemoveEntity( piece.id );
  264. end
  265. end
  266. ----------------------------------------------------------------------------------------------------------------------------
  267. --
  268. --
  269. function HeliStatic:OnSave(stm)
  270. end
  271. ----------------------------------------------------------------------------------------------------------------------------
  272. --
  273. --
  274. function HeliStatic:OnLoad(stm)
  275. end
  276. ----------------------------------------------------------------------------------------------------------------------------
  277. --
  278. --
  279. function HeliStatic:OnEventServer( id, params)
  280. -- if (id == ScriptEvent_Reset)
  281. -- then
  282. -- end
  283. end
  284. ----------------------------------------------------------------------------------------------------------------------------
  285. --
  286. --
  287. ----------------------------------------------------------------------------------------------------------------------------
  288. --
  289. --
  290. function HeliStatic:OnWrite( stm )
  291. end
  292. ----------------------------------------------------------------------------------------------------------------------------
  293. --
  294. --
  295. function HeliStatic:OnRead( stm )
  296. end
  297. ----------------------------------------------------------------------------------------------------------------------------
  298. --
  299. --
  300. ----------------------------------------------------------------------------------------------------------------------------
  301. --
  302. --
  303. --////////////////////////////////////////////////////////////////////////////////////////
  304. function HeliStatic:ExecuteDamageModel()
  305. if (self.damage>self.Properties.max_health*.2) then -- default 0.5
  306. -- middle damage
  307. local vVec=self:GetHelperPos("vehicle_damage1",0);
  308. Particle.CreateParticle(vVec,{x=0, y=0, z=1},self.DamageParticles1); --vector(0,0,1) is up
  309. -- maximum damage
  310. if (self.damage>self.Properties.max_health) then -- default 0.1
  311. vVec=self:GetHelperPos("vehicle_damage2",0);
  312. Particle.CreateParticle(vVec,{x=0, y=0, z=1},self.DamageParticles2);
  313. HeliStatic.BlowUp(self);
  314. end
  315. end
  316. end
  317. --////////////////////////////////////////////////////////////////////////////////////////
  318. function HeliStatic:BlowUp()
  319. if (self.bExploded==1) then
  320. do return end
  321. end
  322. -- System.Log("BLOW UP!");
  323. local explDir={x=0, y=0, z=1};
  324. ExecuteMaterial(self:GetPos(),explDir,HeliExplosion,1);
  325. local ExplosionParams = {};
  326. ExplosionParams.pos = self:GetPos();
  327. ExplosionParams.damage= self.Properties.ExplosionParams.nDamage;
  328. ExplosionParams.rmin = self.Properties.ExplosionParams.fRadiusMin;
  329. ExplosionParams.rmax = self.Properties.ExplosionParams.fRadiusMax;
  330. ExplosionParams.radius = self.Properties.ExplosionParams.fRadius;
  331. ExplosionParams.impulsive_pressure = self.Properties.ExplosionParams.fImpulsivePressure;
  332. ExplosionParams.shooter = self;
  333. ExplosionParams.weapon = self;
  334. Game:CreateExplosion( ExplosionParams );
  335. -- ExplosionParams.pos = self:GetPos();
  336. -- ExplosionParams.pos.x=ExplosionParams.pos.x+2;
  337. ExplosionParams.pos = self:GetHelperPos("vehicle_damage2",0);
  338. Game:CreateExplosion( ExplosionParams );
  339. --play explosion sound
  340. if (self.ExplosionSound ~= nil) then
  341. --make sure to place the explosion sound at the correct position
  342. Sound.SetSoundPosition(self.ExplosionSound,self:GetPos());
  343. Sound.PlaySound(self.ExplosionSound);
  344. --System.LogToConsole("playing explo sound");
  345. end
  346. self:BreakOnPieces();
  347. -- self.damage=0;
  348. self.bExploded=1;
  349. --self.IsPhisicalized = 0; -- so that the next call to reset will reload the normal model
  350. end
  351. --------------------------------------------------------------------------------------------------------------
  352. function HeliStatic:BreakOnPieces()
  353. local pos=self:GetPos();
  354. local angle=self:GetAngles();
  355. self:DrawObject(0,0);
  356. System.Log( " DoPiece ");
  357. local dir={x=0, y=0, z=1};
  358. for idx,piece in pairs(self.pieces) do
  359. System.Log( " Piece #"..idx );
  360. piece:DrawObject(0,1);
  361. piece:EnablePhysics(1);
  362. piece:SetPos( pos );
  363. piece:SetAngles( angle );
  364. dir.x= (2-random(0,4));
  365. dir.y= (2-random(0,4));
  366. dir.z= 2;
  367. -- piece:AddImpulseObj(dir, self.explosionImpulse);
  368. piece:Activate( piece );
  369. end
  370. if (self.sound_engine) then
  371. Sound.StopSound(self.sound_engine);
  372. end
  373. self:Activate( 0 );
  374. -- Server:RemoveEntity( self.id );
  375. end
  376. --------------------------------------------------------------------------------------------------------------
  377. --------------------------------------------------------------------------------------------------------------
  378. --------------------------------------------------------------------------------------------------------------
  379. --
  380. --