fireplaceindoor.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. class FireplaceIndoor : 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 FIREPOINT_ACTION_SELECTION = "fireplace_action";
  8. static const string FIREPOINT_FIRE_POSITION = "fireplace_point";
  9. static const string FIREPOINT_PLACE_ROT = "fireplace_rot";
  10. static const string FIREPOINT_SMOKE_POSITION = "fireplace_smoke";
  11. void FireplaceIndoor()
  12. {
  13. //Particles - default for FireplaceBase
  14. PARTICLE_FIRE_START = ParticleList.HOUSE_FIRE_START;
  15. PARTICLE_SMALL_FIRE = ParticleList.HOUSE_SMALL_FIRE;
  16. PARTICLE_NORMAL_FIRE = ParticleList.HOUSE_NORMAL_FIRE;
  17. PARTICLE_SMALL_SMOKE = ParticleList.HOUSE_SMALL_SMOKE;
  18. PARTICLE_NORMAL_SMOKE = ParticleList.HOUSE_NORMAL_SMOKE;
  19. PARTICLE_FIRE_END = ParticleList.HOUSE_FIRE_END;
  20. PARTICLE_STEAM_END = ParticleList.HOUSE_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( FIREPOINT_FIRE_POSITION + fire_point_index.ToString() );
  92. vector fire_point_rot = building.GetSelectionPositionMS( FIREPOINT_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, 0.25, 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( FireplaceIndoor ) )
  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 IsFireplaceIndoor()
  136. {
  137. return true;
  138. }
  139. override void EEItemAttached(EntityAI item, string slot_name)
  140. {
  141. super.EEItemAttached(item, slot_name);
  142. ItemBase item_base = ItemBase.Cast(item);
  143. if ( IsKindling(item_base) || IsFuel(item_base))
  144. {
  145. AddToFireConsumables(item_base);
  146. }
  147. // direct cooking slots, smoking slots
  148. bool edible_base_attached = false;
  149. switch ( slot_name )
  150. {
  151. case "DirectCookingA":
  152. m_DirectCookingSlots[0] = item_base;
  153. edible_base_attached = true;
  154. break;
  155. case "DirectCookingB":
  156. m_DirectCookingSlots[1] = item_base;
  157. edible_base_attached = true;
  158. break;
  159. case "DirectCookingC":
  160. m_DirectCookingSlots[2] = item_base;
  161. edible_base_attached = true;
  162. break;
  163. case "SmokingA":
  164. m_SmokingSlots[0] = item_base;
  165. edible_base_attached = true;
  166. break;
  167. case "SmokingB":
  168. m_SmokingSlots[1] = item_base;
  169. edible_base_attached = true;
  170. break;
  171. case "SmokingC":
  172. m_SmokingSlots[2] = item_base;
  173. edible_base_attached = true;
  174. break;
  175. case "SmokingD":
  176. m_SmokingSlots[3] = item_base;
  177. edible_base_attached = true;
  178. break;
  179. }
  180. RefreshFireplaceVisuals();
  181. }
  182. override void EEItemDetached(EntityAI item, string slot_name)
  183. {
  184. super.EEItemDetached(item, slot_name);
  185. ItemBase item_base = ItemBase.Cast(item);
  186. if (IsKindling(item_base) || IsFuel(item_base))
  187. {
  188. RemoveFromFireConsumables(GetFireConsumableByItem(item_base));
  189. }
  190. CheckForDestroy();
  191. // direct cooking/smoking slots
  192. switch (slot_name)
  193. {
  194. case "DirectCookingA":
  195. m_DirectCookingSlots[0] = null;
  196. break;
  197. case "DirectCookingB":
  198. m_DirectCookingSlots[1] = null;
  199. break;
  200. case "DirectCookingC":
  201. m_DirectCookingSlots[2] = null;
  202. break;
  203. case "SmokingA":
  204. m_SmokingSlots[0] = null;
  205. break;
  206. case "SmokingB":
  207. m_SmokingSlots[1] = null;
  208. break;
  209. case "SmokingC":
  210. m_SmokingSlots[2] = null;
  211. break;
  212. case "SmokingD":
  213. m_SmokingSlots[3] = null;
  214. break;
  215. }
  216. // cookware-specifics (remove audio visuals and clear references)
  217. if (item_base.IsCookware())
  218. {
  219. ClearCookingEquipment(item_base);
  220. item_base.RemoveAudioVisualsOnClient();
  221. }
  222. if (item_base.IsLiquidContainer()) //boiling bottle effects stop
  223. item_base.RemoveAudioVisualsOnClient();
  224. RefreshFireplaceVisuals();
  225. }
  226. //================================================================
  227. // CONDITIONS
  228. //================================================================
  229. //this into/outo parent.Cargo
  230. override bool CanPutInCargo( EntityAI parent )
  231. {
  232. return false;
  233. }
  234. override bool CanRemoveFromCargo( EntityAI parent )
  235. {
  236. return true;
  237. }
  238. //cargo item into/outo this.Cargo
  239. override bool CanReceiveItemIntoCargo( EntityAI item )
  240. {
  241. return super.CanReceiveItemIntoCargo( item );
  242. }
  243. //hands
  244. override bool CanPutIntoHands( EntityAI parent )
  245. {
  246. return false;
  247. }
  248. override bool CanRemoveFromHands( EntityAI parent )
  249. {
  250. return false;
  251. }
  252. // Item-to-item fire distribution
  253. override bool HasFlammableMaterial()
  254. {
  255. return true;
  256. }
  257. override bool CanBeIgnitedBy( EntityAI igniter = NULL )
  258. {
  259. if ( HasAnyKindling() && !GetHierarchyParent() )
  260. {
  261. return true;
  262. }
  263. return false;
  264. }
  265. override bool CanIgniteItem( EntityAI ignite_target = NULL )
  266. {
  267. if ( IsBurning() )
  268. {
  269. return true;
  270. }
  271. return false;
  272. }
  273. override bool IsIgnited()
  274. {
  275. return IsBurning();
  276. }
  277. override void OnIgnitedTarget( EntityAI target_item )
  278. {
  279. }
  280. override void OnIgnitedThis( EntityAI fire_source )
  281. {
  282. //start fire
  283. StartFire();
  284. }
  285. override bool IsThisIgnitionSuccessful( EntityAI item_source = NULL )
  286. {
  287. SetIgniteFailure( false );
  288. Param1<bool> failure;
  289. //check kindling
  290. if ( !HasAnyKindling() )
  291. {
  292. return false;
  293. }
  294. //check wetness
  295. if ( IsWet() )
  296. {
  297. SetIgniteFailure( true );
  298. failure = new Param1<bool>( GetIgniteFailure() );
  299. GetGame().RPCSingleParam( this, FirePlaceFailure.WET, failure, true );
  300. return false;
  301. }
  302. return true;
  303. }
  304. }