woodbase.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. enum EHarvestType
  2. {
  3. NORMAL,
  4. BARK
  5. }
  6. class WoodBase extends Plant
  7. {
  8. static bool m_IsCuttable;
  9. static int m_PrimaryDropsAmount = -1;
  10. static int m_SecondaryDropsAmount = -1;
  11. static float m_ToolDamage = -1.0;
  12. static float m_CycleTimeOverride = -1.0;
  13. static string m_PrimaryOutput = ""; //some nonsensical item for debugging purposes
  14. static string m_SecondaryOutput = ""; //some nonsensical item for debugging purposes
  15. static string m_BarkType = "";
  16. /*
  17. bool m_IsCuttable;
  18. int m_PrimaryDropsAmount = -1;
  19. int m_SecondaryDropsAmount = -1;
  20. float m_ToolDamage = -1.0;
  21. float m_CycleTimeOverride = -1.0;
  22. string m_PrimaryOutput = ""; //some nonsensical item for debugging purposes
  23. string m_SecondaryOutput = ""; //some nonsensical item for debugging purposes
  24. string m_BarkType = "";
  25. */
  26. void WoodBase()
  27. {
  28. //InitMiningValues();
  29. }
  30. void InitMiningValues()
  31. {
  32. //m_IsCuttable = false;
  33. };
  34. override bool IsWoodBase()
  35. {
  36. return true;
  37. }
  38. override bool IsCuttable()
  39. {
  40. return ConfigGetBool("isCuttable");
  41. }
  42. bool HasPlayerCollisionParticle()
  43. {
  44. return true;
  45. }
  46. bool HasPlayerCollisionSound()
  47. {
  48. return true;
  49. }
  50. int GetPrimaryDropsAmount()
  51. {
  52. return ConfigGetInt("primaryDropsAmount");
  53. }
  54. int GetSecondaryDropsAmount()
  55. {
  56. return ConfigGetInt("secondaryDropsAmount");
  57. }
  58. float GetToolDamage()
  59. {
  60. return ConfigGetFloat("toolDamage");
  61. }
  62. float GetCycleTimeOverride()
  63. {
  64. return ConfigGetFloat("cycleTimeOverride");
  65. }
  66. string GetPrimaryOutput()
  67. {
  68. return ConfigGetString("primaryOutput");
  69. }
  70. string GetSecondaryOutput()
  71. {
  72. return ConfigGetString("secondaryOutput");
  73. }
  74. string GetBarkType()
  75. {
  76. return ConfigGetString("barkType");
  77. }
  78. int GetAmountOfDrops(ItemBase item)
  79. {
  80. if ( GetPrimaryDropsAmount() > 0 )
  81. {
  82. if ( IsTree() && item && ( item.KindOf("Knife") || item.IsInherited(Screwdriver) ) )
  83. {
  84. return -1;
  85. }
  86. else
  87. {
  88. return GetPrimaryDropsAmount();
  89. }
  90. }
  91. else
  92. {
  93. if ( item && ( item.KindOf("Knife") || item.IsInherited(Screwdriver) ) )
  94. {
  95. return -1;
  96. }
  97. else if ( item && item.KindOf("Axe") )
  98. {
  99. return 3;
  100. }
  101. else
  102. {
  103. return 100;
  104. }
  105. }
  106. }
  107. int GetAmountOfDropsEx(ItemBase item, EHarvestType type)
  108. {
  109. if ( GetPrimaryDropsAmount() > 0 )
  110. {
  111. if ( IsTree() && item && type == EHarvestType.BARK )
  112. {
  113. return -1;
  114. }
  115. else
  116. {
  117. return GetPrimaryDropsAmount();
  118. }
  119. }
  120. else
  121. {
  122. if ( item && type == EHarvestType.BARK )
  123. {
  124. return -1;
  125. }
  126. else if ( item && type == EHarvestType.NORMAL )
  127. {
  128. return 3;
  129. }
  130. else
  131. {
  132. return 100;
  133. }
  134. }
  135. }
  136. void GetMaterialAndQuantityMap(ItemBase item, out map<string,int> output_map)
  137. {
  138. if ( IsTree() && item && ( item.KindOf("Knife") || item.IsInherited(Screwdriver) ) && GetBarkType() != "" )
  139. {
  140. output_map.Insert(GetBarkType(),1);
  141. }
  142. else
  143. {
  144. output_map.Insert(GetPrimaryOutput(),1);
  145. }
  146. }
  147. void GetMaterialAndQuantityMapEx(ItemBase item, out map<string,int> output_map, EHarvestType type)
  148. {
  149. if ( IsTree() && item && type == EHarvestType.BARK && GetBarkType() != "" )
  150. {
  151. output_map.Insert(GetBarkType(),1);
  152. }
  153. else
  154. {
  155. output_map.Insert(GetPrimaryOutput(),1);
  156. }
  157. }
  158. float GetDamageToMiningItemEachDrop(ItemBase item)
  159. {
  160. if (GetToolDamage() > -1)
  161. return GetToolDamage();
  162. if ( IsTree() )
  163. {
  164. if ( item && item.KindOf("Knife") )
  165. {
  166. return 20;
  167. }
  168. else if ( item && item.KindOf("Axe") )
  169. {
  170. return 20;
  171. }
  172. else
  173. {
  174. return 0;
  175. }
  176. }
  177. else
  178. {
  179. if ( item && item.KindOf("Knife") )
  180. {
  181. return 30;
  182. }
  183. else if ( item && item.KindOf("Axe") )
  184. {
  185. return 30;
  186. }
  187. else
  188. {
  189. return 0;
  190. }
  191. }
  192. }
  193. float GetDamageToMiningItemEachDropEx(ItemBase item, EHarvestType type)
  194. {
  195. if (GetToolDamage() > -1)
  196. return GetToolDamage();
  197. if ( IsTree() )
  198. {
  199. if ( item && type == EHarvestType.BARK )
  200. {
  201. return 20;
  202. }
  203. else if ( item && type == EHarvestType.NORMAL )
  204. {
  205. return 20;
  206. }
  207. else
  208. {
  209. return 0;
  210. }
  211. }
  212. else
  213. {
  214. if ( item && type == EHarvestType.BARK )
  215. {
  216. return 30;
  217. }
  218. else if ( item && type == EHarvestType.NORMAL )
  219. {
  220. return 30;
  221. }
  222. else
  223. {
  224. return 0;
  225. }
  226. }
  227. }
  228. override bool CanBeActionTarget()
  229. {
  230. return super.CanBeActionTarget() && !IsDamageDestroyed();
  231. }
  232. }
  233. class TreeEffecterParameters : EffecterParameters
  234. {
  235. float m_Radius;
  236. void TreeEffecterParameters(string type, float lifespan, int radius)
  237. {
  238. m_Radius = radius;
  239. }
  240. }
  241. class TreeEffecter : EffecterBase
  242. {
  243. protected ref array<EffectParticleGeneral> m_Effects = null;
  244. private float m_Radius = -1;
  245. private float m_RadiusSync = -1;
  246. void TreeEffecter()
  247. {
  248. if (!GetGame().IsServer() || !GetGame().IsMultiplayer())
  249. {
  250. m_Effects = new array<EffectParticleGeneral>;
  251. }
  252. RegisterNetSyncVariableFloat("m_RadiusSync");
  253. }
  254. override void Init(int id, EffecterParameters parameters)
  255. {
  256. super.Init(id, parameters);
  257. TreeEffecterParameters par = TreeEffecterParameters.Cast(parameters);
  258. SetRadius(par.m_Radius);
  259. }
  260. void SetRadius(float radius)
  261. {
  262. m_RadiusSync = radius;
  263. Process();
  264. }
  265. override void OnVariablesSynchronized()
  266. {
  267. if (m_RadiusSync != m_Radius)
  268. {
  269. array<Object> objects = new array<Object>;
  270. array<CargoBase> proxies = new array<CargoBase>;
  271. EffectParticleGeneral newEffect;
  272. foreach (EffectParticleGeneral oldEffect : m_Effects)
  273. {
  274. SEffectManager.DestroyEffect(oldEffect);
  275. }
  276. m_Effects.Clear();
  277. GetGame().GetObjectsAtPosition(GetWorldPosition(), m_RadiusSync, objects, proxies);
  278. for (int i = 0; i < objects.Count(); i++)
  279. {
  280. WoodBase plant = WoodBase.Cast(objects[i]);
  281. if (plant)
  282. {
  283. string particle;
  284. int particleID;
  285. string configPath = "CfgNonAIVehicles " + plant.GetType() + " FxFallingParticleEffect particle";
  286. GetGame().ConfigGetText(configPath, particle);
  287. if (particle != "")
  288. {
  289. particleID = ParticleList.RegisterParticle(particle);
  290. }
  291. if (particleID > 0)
  292. {
  293. LOD lod = plant.GetLODByName(LOD.NAME_MEMORY);
  294. Selection selection = lod.GetSelectionByName("ptcFalling");
  295. if (selection)
  296. {
  297. vector selectionPos;
  298. for (int j = 0; j < selection.GetVertexCount(); j++)
  299. {
  300. newEffect = new EffectParticleGeneral();
  301. newEffect.SetParticle(particleID);
  302. selectionPos = selection.GetVertexPosition(lod, j);
  303. SEffectManager.PlayInWorld(newEffect, plant.GetPosition() + selectionPos);
  304. m_Effects.Insert(newEffect);
  305. }
  306. //play accompanying sounds
  307. selectionPos = ModelToWorld(selectionPos);
  308. EffectSound sound = SEffectManager.PlaySoundEnviroment("snow_fallen_trees_SoundSet", selectionPos);
  309. sound.SetAutodestroy(true);
  310. }
  311. }
  312. }
  313. }
  314. }
  315. if (m_CommandSync != m_Command)
  316. {
  317. foreach (EffectParticleGeneral effect : m_Effects)
  318. {
  319. switch (m_CommandSync)
  320. {
  321. case EffecterCommands.START:
  322. if (effect && !effect.IsPlaying())
  323. {
  324. effect.SetParticle(effect.m_LastParticleID);
  325. effect.Start();
  326. }
  327. break;
  328. case EffecterCommands.STOP:
  329. if (effect && effect.IsPlaying())
  330. {
  331. effect.Stop();
  332. }
  333. break;
  334. case EffecterCommands.REACTIVATE0:
  335. case EffecterCommands.REACTIVATE1:
  336. if (effect)
  337. {
  338. effect.SetParticle(effect.m_LastParticleID);
  339. }
  340. if (!effect.IsPlaying())
  341. {
  342. effect.Start();
  343. }
  344. break;
  345. default:
  346. break;
  347. }
  348. }
  349. m_Command = m_CommandSync;
  350. }
  351. }
  352. void ~TreeEffecter()
  353. {
  354. if (m_Effects)
  355. {
  356. foreach (EffectParticleGeneral effect : m_Effects)
  357. {
  358. SEffectManager.DestroyEffect(effect);
  359. }
  360. }
  361. }
  362. }