bottle_base.c 8.9 KB

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