bottle_base.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. enum SoundTypeBottle
  2. {
  3. POURING = 1,
  4. EMPTYING = 0,
  5. }
  6. class Bottle_Base extends Edible_Base
  7. {
  8. //Particles
  9. protected Particle m_ParticleCooking;
  10. protected int m_ParticlePlaying = ParticleList.INVALID;
  11. //Boiling
  12. //waiting for proper particle effects
  13. protected int PARTICLE_BOILING_EMPTY = ParticleList.COOKING_BOILING_EMPTY;
  14. protected int PARTICLE_BOILING_START = ParticleList.COOKING_BOILING_START;
  15. protected int PARTICLE_BOILING_DONE = ParticleList.COOKING_BOILING_DONE;
  16. //Baking
  17. protected int PARTICLE_BAKING_START = ParticleList.COOKING_BAKING_START;
  18. protected int PARTICLE_BAKING_DONE = ParticleList.COOKING_BAKING_DONE;
  19. //Drying
  20. protected int PARTICLE_DRYING_START = ParticleList.COOKING_DRYING_START;
  21. protected int PARTICLE_DRYING_DONE = ParticleList.COOKING_DRYING_DONE;
  22. //Burning
  23. protected int PARTICLE_BURNING_DONE = ParticleList.COOKING_BURNING_DONE;
  24. //Sounds
  25. protected EffectSound m_PouringLoopSound;
  26. protected EffectSound m_EmptyingLoopSound;
  27. //cooking data
  28. protected CookingMethodType m_CookingMethod;
  29. protected bool m_CookingIsDone;
  30. protected bool m_CookingIsEmpty;
  31. protected bool m_CookingIsBurned;
  32. //Boiling
  33. const string SOUND_BOILING_EMPTY = "Boiling_SoundSet";
  34. float m_LiquidEmptyRate;
  35. private const float QUANTITY_EMPTIED_PER_SEC_DEFAULT = 200; //default
  36. void Bottle_Base()
  37. {
  38. RegisterNetSyncVariableInt("m_CookingMethod", CookingMethodType.NONE, CookingMethodType.COUNT);
  39. RegisterNetSyncVariableBool("m_CookingIsDone");
  40. RegisterNetSyncVariableBool("m_CookingIsEmpty");
  41. RegisterNetSyncVariableBool("m_CookingIsBurned");
  42. m_LiquidEmptyRate = QUANTITY_EMPTIED_PER_SEC_DEFAULT;
  43. }
  44. void ~Bottle_Base()
  45. {
  46. SEffectManager.DestroyEffect(m_PouringLoopSound);
  47. SEffectManager.DestroyEffect(m_EmptyingLoopSound);
  48. }
  49. override void EEDelete( EntityAI parent )
  50. {
  51. super.EEDelete( parent );
  52. //remove audio visuals
  53. RemoveAudioVisuals();
  54. }
  55. override void EECargoIn(EntityAI item)
  56. {
  57. super.EECargoIn(item);
  58. MiscGameplayFunctions.SoakItemInsideParentContainingLiquidAboveThreshold(ItemBase.Cast(item), this);
  59. }
  60. override void OnFreezeStateChangeServer()
  61. {
  62. super.OnFreezeStateChangeServer();
  63. //soak CARGO items on unfreeze
  64. CargoBase cargo;
  65. if (!GetIsFrozen() && GetLiquidType() != 0 && Class.CastTo(cargo,GetInventory().GetCargo()))
  66. {
  67. int count = cargo.GetItemCount();
  68. for (int i = 0; i < count; ++i)
  69. {
  70. MiscGameplayFunctions.SoakItemInsideParentContainingLiquidAboveThreshold(ItemBase.Cast(cargo.GetItem(i)), this);
  71. }
  72. }
  73. }
  74. override int GetConsumptionPenaltyContext()
  75. {
  76. //! no penalty while drinking
  77. return EConsumptionPenaltyContext.NONE;
  78. }
  79. //================================================================
  80. // PARTICLES & SOUNDS
  81. //================================================================
  82. //Refreshes the audio and partcile effects on cooking pot
  83. //is_done - is the food baked, boiled, dried?
  84. //is_empty - is cooking quipment (cargo) empty?
  85. //is_burned - is any of the food items in the cargo in burned food stage?
  86. override void Synchronize()
  87. {
  88. SetSynchDirty();
  89. }
  90. override void OnRPC(PlayerIdentity sender, int rpc_type, ParamsReadContext ctx)
  91. {
  92. super.OnRPC(sender, rpc_type, ctx);
  93. Param1<bool> p = new Param1<bool>(false);
  94. if (!ctx.Read(p))
  95. return;
  96. bool play = p.param1;
  97. switch (rpc_type)
  98. {
  99. case SoundTypeBottle.POURING:
  100. if (play)
  101. PlayPouringLoopSound();
  102. else
  103. StopPouringLoopSound();
  104. break;
  105. case SoundTypeBottle.EMPTYING:
  106. if (play)
  107. PlayEmptyingLoopSound();
  108. else
  109. StopEmptyingLoopSound();
  110. break;
  111. }
  112. }
  113. override void OnVariablesSynchronized()
  114. {
  115. super.OnVariablesSynchronized();
  116. if (m_CookingMethod != CookingMethodType.NONE)
  117. {
  118. RefreshAudioVisuals(m_CookingMethod, m_CookingIsDone, m_CookingIsEmpty, m_CookingIsBurned);
  119. }
  120. else
  121. {
  122. RemoveAudioVisuals();
  123. }
  124. }
  125. override void RemoveAudioVisualsOnClient()
  126. {
  127. m_CookingMethod = CookingMethodType.NONE;
  128. Synchronize();
  129. }
  130. override void RefreshAudioVisualsOnClient( CookingMethodType cooking_method, bool is_done, bool is_empty, bool is_burned )
  131. {
  132. m_CookingMethod = cooking_method;
  133. m_CookingIsDone = is_done;
  134. m_CookingIsEmpty = is_empty;
  135. m_CookingIsBurned = is_burned;
  136. Synchronize();
  137. }
  138. //! Remnants of old, responsible for particles and some (empty) sounds. Cooked items take care of the rest themselves
  139. void RefreshAudioVisuals(CookingMethodType cooking_method, bool is_done, bool is_empty, bool is_burned)
  140. {
  141. string soundName = "";
  142. int particleId;
  143. switch (cooking_method)
  144. {
  145. case CookingMethodType.BOILING:
  146. soundName = SOUND_BOILING_EMPTY;
  147. if (is_empty)
  148. {
  149. particleId = PARTICLE_BOILING_EMPTY;
  150. }
  151. else
  152. {
  153. if (is_done)
  154. particleId = PARTICLE_BOILING_DONE;
  155. else
  156. particleId = PARTICLE_BOILING_START;
  157. }
  158. break;
  159. case CookingMethodType.BAKING:
  160. if (is_done)
  161. particleId = PARTICLE_BAKING_DONE;
  162. else
  163. particleId = PARTICLE_BAKING_START;
  164. break;
  165. case CookingMethodType.DRYING:
  166. if (is_done)
  167. particleId = PARTICLE_DRYING_DONE;
  168. else
  169. particleId = PARTICLE_DRYING_START;
  170. break;
  171. default:
  172. soundName = "";
  173. particleId = ParticleList.NONE;
  174. break;
  175. }
  176. //if at least one of the food items is burned
  177. if (is_burned)
  178. {
  179. particleId = PARTICLE_BURNING_DONE;
  180. }
  181. //play effects
  182. ParticleCookingStart(particleId);
  183. SoundCookingStart(soundName);
  184. }
  185. void RemoveAudioVisuals()
  186. {
  187. ParticleCookingStop();
  188. SoundCookingStop();
  189. }
  190. //particles
  191. void ParticleCookingStart(int particle_id)
  192. {
  193. #ifndef SERVER
  194. if (m_ParticlePlaying != particle_id)
  195. {
  196. //stop previous particles
  197. ParticleCookingStop();
  198. //create new
  199. vector localPos = MiscGameplayFunctions.GetSteamPosition(GetHierarchyParent());
  200. m_ParticleCooking = ParticleManager.GetInstance().PlayInWorld(particle_id, localPos);
  201. m_ParticlePlaying = particle_id;
  202. }
  203. #endif
  204. }
  205. void ParticleCookingStop()
  206. {
  207. if (m_ParticleCooking && GetGame() && !GetGame().IsDedicatedServer())
  208. {
  209. m_ParticleCooking.Stop();
  210. m_ParticleCooking = null;
  211. m_ParticlePlaying = ParticleList.INVALID;
  212. }
  213. }
  214. void PlayPouringLoopSound()
  215. {
  216. if (!m_PouringLoopSound || !m_PouringLoopSound.IsSoundPlaying())
  217. {
  218. m_PouringLoopSound = SEffectManager.PlaySoundOnObject(GetPouringSoundset(), this, 0, 0, true);
  219. }
  220. }
  221. void StopPouringLoopSound()
  222. {
  223. if (m_PouringLoopSound)
  224. m_PouringLoopSound.SoundStop();
  225. }
  226. void PlayEmptyingLoopSound()
  227. {
  228. if (!m_EmptyingLoopSound || !m_EmptyingLoopSound.IsSoundPlaying())
  229. {
  230. m_EmptyingLoopSound = SEffectManager.PlaySoundOnObject(GetEmptyingLoopSoundset(), this, 0, 0, true);
  231. }
  232. }
  233. void StopEmptyingLoopSound()
  234. {
  235. if (m_EmptyingLoopSound)
  236. m_EmptyingLoopSound.SoundStop();
  237. EffectSound sound = SEffectManager.PlaySoundOnObject(GetEmptyingEndSoundset(), this);
  238. sound.SetAutodestroy(true);
  239. }
  240. string GetEmptyingLoopSoundset()
  241. {
  242. vector pos = GetPosition();
  243. string surfaceType = GetGame().GetPlayer().GetSurfaceType();
  244. string soundSet = "";
  245. bool diggable = GetGame().IsSurfaceDigable(surfaceType);
  246. if (!diggable)
  247. {
  248. soundSet = GetEmptyingLoopSoundsetHard();
  249. }
  250. else if (diggable)
  251. {
  252. soundSet = GetEmptyingLoopSoundsetSoft();
  253. }
  254. else if (GetGame().SurfaceIsPond(pos[0], pos[2]) || GetGame().SurfaceIsSea(pos[0], pos[2]))
  255. {
  256. soundSet = GetEmptyingLoopSoundsetWater();
  257. }
  258. return soundSet;
  259. }
  260. string GetEmptyingEndSoundset()
  261. {
  262. vector pos = GetPosition();
  263. string surfaceType = GetGame().GetPlayer().GetSurfaceType();
  264. string soundSet = "";
  265. bool diggable = GetGame().IsSurfaceDigable(surfaceType);
  266. if (!diggable)
  267. {
  268. soundSet = GetEmptyingEndSoundsetHard();
  269. }
  270. else if (diggable)
  271. {
  272. soundSet = GetEmptyingEndSoundsetSoft();
  273. }
  274. else if (GetGame().SurfaceIsPond(pos[0], pos[2]) || GetGame().SurfaceIsSea(pos[0], pos[2]))
  275. {
  276. soundSet = GetEmptyingEndSoundsetWater();
  277. }
  278. return soundSet;
  279. }
  280. string GetPouringSoundset();
  281. string GetEmptyingLoopSoundsetHard();
  282. string GetEmptyingLoopSoundsetSoft();
  283. string GetEmptyingLoopSoundsetWater();
  284. string GetEmptyingEndSoundsetHard();
  285. string GetEmptyingEndSoundsetSoft();
  286. string GetEmptyingEndSoundsetWater();
  287. //! Returns base liquid empty rate (absolute)..preferrably use the 'GetLiquidThroughputCoef' instead
  288. float GetLiquidEmptyRate()
  289. {
  290. return m_LiquidEmptyRate;
  291. }
  292. override void SetActions()
  293. {
  294. super.SetActions();
  295. AddAction(ActionFillFuel);
  296. AddAction(ActionFillCoolant);
  297. AddAction(ActionFillGeneratorTank);
  298. AddAction(ActionExtinguishFireplaceByLiquid);
  299. AddAction(ActionFillBottleBase);
  300. AddAction(ActionFillBottleSnow);
  301. AddAction(ActionWaterGardenSlot);
  302. AddAction(ActionWaterPlant);
  303. AddAction(ActionForceDrink);
  304. AddAction(ActionDrainLiquid);
  305. AddAction(ActionPourLiquid);
  306. AddAction(ActionWashHandsItemContinuous);
  307. AddAction(ActionDrink);
  308. AddAction(ActionEmptyBottleBase);
  309. }
  310. override void OnDebugSpawn()
  311. {
  312. SetQuantityMax();
  313. }
  314. }