ovenindoor.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. class OvenIndoor extends FireplaceBase
  2. {
  3. protected float m_SmokePosX;
  4. protected float m_SmokePosY;
  5. protected float m_SmokePosZ;
  6. protected int m_FirePointIndex = 1; //limited to 1 decimal place (1-9)
  7. static const string OVENPOINT_ACTION_SELECTION = "oven_action";
  8. static const string OVENPOINT_FIRE_POSITION = "oven_point";
  9. static const string OVENPOINT_PLACE_ROT = "oven_rot";
  10. static const string OVENPOINT_SMOKE_POSITION = "oven_smoke";
  11. void OvenIndoor()
  12. {
  13. //Particles - default for FireplaceBase
  14. PARTICLE_FIRE_START = ParticleList.OVEN_FIRE_START;
  15. PARTICLE_SMALL_FIRE = ParticleList.OVEN_SMALL_FIRE;
  16. PARTICLE_NORMAL_FIRE = ParticleList.OVEN_NORMAL_FIRE;
  17. PARTICLE_SMALL_SMOKE = ParticleList.HOUSE_SMALL_SMOKE;
  18. PARTICLE_NORMAL_SMOKE = ParticleList.HOUSE_NORMAL_SMOKE;
  19. PARTICLE_FIRE_END = ParticleList.OVEN_FIRE_END;
  20. PARTICLE_STEAM_END = ParticleList.BARREL_FIRE_STEAM_2END;
  21. //register sync variables
  22. RegisterNetSyncVariableFloat( "m_SmokePosX", 0, 0, 2 );
  23. RegisterNetSyncVariableFloat( "m_SmokePosY", 0, 0, 2 );
  24. RegisterNetSyncVariableFloat( "m_SmokePosZ", 0, 0, 2 );
  25. RegisterNetSyncVariableInt( "m_FirePointIndex", 0, 9 );
  26. m_LightDistance = 50;
  27. SetRoofAbove(true);
  28. m_UTSSettings.m_EnableOnTemperatureControl = true;
  29. m_UTSSettings.m_ActiveTemperatureThreshold = 250.0;
  30. m_UTSSettings.m_InactiveTemperatureThreshold = 975.0;
  31. }
  32. //================================================================
  33. // ONSTORESAVE/LOAD/AFTERLOAD
  34. //================================================================
  35. override void OnStoreSave( ParamsWriteContext ctx )
  36. {
  37. super.OnStoreSave( ctx );
  38. //fire point name
  39. ctx.Write( m_FirePointIndex );
  40. //smoke position
  41. ctx.Write( m_SmokePosX );
  42. ctx.Write( m_SmokePosY );
  43. ctx.Write( m_SmokePosZ );
  44. }
  45. override bool OnStoreLoad( ParamsReadContext ctx, int version )
  46. {
  47. if ( !super.OnStoreLoad( ctx, version ) )
  48. return false;
  49. //--- Fireplace Indoor data ---
  50. //fire point name
  51. if ( !ctx.Read( m_FirePointIndex ) )
  52. {
  53. m_FirePointIndex = 1; //set default
  54. return false;
  55. }
  56. //smoke position
  57. if ( !ctx.Read( m_SmokePosX ) )
  58. {
  59. m_SmokePosX = 0; //set default
  60. return false;
  61. }
  62. if ( !ctx.Read( m_SmokePosY ) )
  63. {
  64. m_SmokePosY = 0; //set default
  65. return false;
  66. }
  67. if ( !ctx.Read( m_SmokePosZ ) )
  68. {
  69. m_SmokePosZ = 0; //set default
  70. return false;
  71. }
  72. //---
  73. return true;
  74. }
  75. //================================================================
  76. // FIRE POINT (HOUSE)
  77. // LIMITED TO 1 DECIMAL PLACE (0-9)
  78. //================================================================
  79. static int GetFirePointIndex( string action_selection )
  80. {
  81. int index_location = action_selection.Length() - 1;
  82. return action_selection.Substring( index_location, 1 ).ToInt();
  83. }
  84. void SetFirePointIndex( int fire_point_index )
  85. {
  86. m_FirePointIndex = fire_point_index;
  87. }
  88. static bool CanPlaceFireplaceInSelectedSpot( Object building, int fire_point_index, out vector fire_point_pos_world, out vector fire_point_rot_world )
  89. {
  90. //Get fire point index position
  91. vector fire_point_pos = building.GetSelectionPositionMS( OVENPOINT_FIRE_POSITION + fire_point_index.ToString() );
  92. vector fire_point_rot = building.GetSelectionPositionMS( OVENPOINT_PLACE_ROT + fire_point_index.ToString() );
  93. fire_point_pos_world = building.ModelToWorld( fire_point_pos );
  94. fire_point_rot_world = building.ModelToWorld( fire_point_rot );
  95. //check if there is any FireplaceIndoor objects near selected fire point
  96. ref array<Object> nearest_objects = new array<Object>;
  97. ref array<CargoBase> proxy_cargos = new array<CargoBase>;
  98. GetGame().GetObjectsAtPosition3D( fire_point_pos_world, 1, nearest_objects, proxy_cargos );
  99. for ( int i = 0; i < nearest_objects.Count(); ++i )
  100. {
  101. Object object = nearest_objects.Get( i );
  102. if ( object.IsInherited( OvenIndoor ) )
  103. {
  104. return false;
  105. }
  106. }
  107. return true;
  108. }
  109. void SetSmokePointPosition( vector smoke_point_pos )
  110. {
  111. m_SmokePosX = smoke_point_pos[0];
  112. m_SmokePosY = smoke_point_pos[1];
  113. m_SmokePosZ = smoke_point_pos[2];
  114. }
  115. //================================================================
  116. // PARTICLES
  117. //================================================================
  118. override protected vector GetSmokeEffectPosition()
  119. {
  120. return Vector( m_SmokePosX, m_SmokePosY, m_SmokePosZ );
  121. }
  122. //small smoke
  123. override void ParticleSmallSmokeStart()
  124. {
  125. PlayParticle( m_ParticleSmallSmoke, PARTICLE_SMALL_SMOKE, GetSmokeEffectPosition(), true );
  126. }
  127. //normal smoke
  128. override void ParticleNormalSmokeStart()
  129. {
  130. PlayParticle( m_ParticleNormalSmoke, PARTICLE_NORMAL_SMOKE, GetSmokeEffectPosition(), true );
  131. }
  132. //================================================================
  133. // STATE
  134. //================================================================
  135. override bool IsIndoorOven()
  136. {
  137. return true;
  138. }
  139. override bool CanReleaseAttachment(EntityAI attachment)
  140. {
  141. if (!super.CanReleaseAttachment(attachment))
  142. {
  143. return false;
  144. }
  145. ItemBase item = ItemBase.Cast(attachment);
  146. if (IsKindling(item) || IsFuel(item))
  147. {
  148. return !IsBurning();
  149. }
  150. return true;
  151. }
  152. override void EEItemAttached(EntityAI item, string slot_name)
  153. {
  154. super.EEItemAttached(item, slot_name);
  155. ItemBase item_base = ItemBase.Cast(item);
  156. if (IsKindling(item_base) || IsFuel(item_base))
  157. {
  158. AddToFireConsumables(item_base);
  159. }
  160. // direct cooking/smoking slots
  161. bool edible_base_attached = false;
  162. switch (slot_name)
  163. {
  164. case "DirectCookingA":
  165. m_DirectCookingSlots[0] = item_base;
  166. edible_base_attached = true;
  167. break;
  168. case "SmokingA":
  169. m_SmokingSlots[0] = item_base;
  170. edible_base_attached = true;
  171. break;
  172. case "SmokingB":
  173. m_SmokingSlots[1] = item_base;
  174. edible_base_attached = true;
  175. break;
  176. }
  177. RefreshFireplaceVisuals();
  178. }
  179. override void EEItemDetached(EntityAI item, string slot_name)
  180. {
  181. super.EEItemDetached(item, slot_name);
  182. ItemBase item_base = ItemBase.Cast(item);
  183. if (IsKindling(item_base) || IsFuel(item_base))
  184. {
  185. RemoveFromFireConsumables(GetFireConsumableByItem(item_base));
  186. }
  187. CheckForDestroy();
  188. // direct cooking/smoking slots
  189. switch (slot_name)
  190. {
  191. case "DirectCookingA":
  192. m_DirectCookingSlots[0] = null;
  193. break;
  194. case "SmokingA":
  195. m_SmokingSlots[0] = null;
  196. break;
  197. case "SmokingB":
  198. m_SmokingSlots[1] = null;
  199. break;
  200. }
  201. // cookware-specifics (remove audio visuals and clear references)
  202. if (item_base.IsCookware())
  203. {
  204. ClearCookingEquipment(item_base);
  205. item_base.RemoveAudioVisualsOnClient();
  206. }
  207. if (item_base.IsLiquidContainer()) //boiling bottle effects stop
  208. item_base.RemoveAudioVisualsOnClient();
  209. RefreshFireplaceVisuals();
  210. }
  211. //================================================================
  212. // CONDITIONS
  213. //================================================================
  214. //this into/outo parent.Cargo
  215. override bool CanPutInCargo( EntityAI parent )
  216. {
  217. return false;
  218. }
  219. override bool CanRemoveFromCargo( EntityAI parent )
  220. {
  221. return true;
  222. }
  223. //hands
  224. override bool CanPutIntoHands( EntityAI parent )
  225. {
  226. return false;
  227. }
  228. override bool CanRemoveFromHands( EntityAI parent )
  229. {
  230. return false;
  231. }
  232. // Item-to-item fire distribution
  233. override bool HasFlammableMaterial()
  234. {
  235. return true;
  236. }
  237. override bool CanBeIgnitedBy( EntityAI igniter = NULL )
  238. {
  239. if ( HasAnyKindling() && !GetHierarchyParent() )
  240. {
  241. return true;
  242. }
  243. return false;
  244. }
  245. override bool CanIgniteItem( EntityAI ignite_target = NULL )
  246. {
  247. if ( IsBurning() )
  248. {
  249. return true;
  250. }
  251. return false;
  252. }
  253. override bool IsIgnited()
  254. {
  255. return IsBurning();
  256. }
  257. override void OnIgnitedTarget( EntityAI target_item )
  258. {
  259. }
  260. override void OnIgnitedThis( EntityAI fire_source )
  261. {
  262. //start fire
  263. StartFire();
  264. }
  265. override bool IsThisIgnitionSuccessful( EntityAI item_source = NULL )
  266. {
  267. //check kindling
  268. if ( !HasAnyKindling() )
  269. {
  270. return false;
  271. }
  272. //check wetness
  273. if ( IsWet() )
  274. {
  275. return false;
  276. }
  277. return true;
  278. }
  279. }