woodbase.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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. int GetPrimaryDropsAmount()
  43. {
  44. return ConfigGetInt("primaryDropsAmount");
  45. }
  46. int GetSecondaryDropsAmount()
  47. {
  48. return ConfigGetInt("secondaryDropsAmount");
  49. }
  50. float GetToolDamage()
  51. {
  52. return ConfigGetFloat("toolDamage");
  53. }
  54. float GetCycleTimeOverride()
  55. {
  56. return ConfigGetFloat("cycleTimeOverride");
  57. }
  58. string GetPrimaryOutput()
  59. {
  60. return ConfigGetString("primaryOutput");
  61. }
  62. string GetSecondaryOutput()
  63. {
  64. return ConfigGetString("secondaryOutput");
  65. }
  66. string GetBarkType()
  67. {
  68. return ConfigGetString("barkType");
  69. }
  70. int GetAmountOfDrops(ItemBase item)
  71. {
  72. if ( GetPrimaryDropsAmount() > 0 )
  73. {
  74. if ( IsTree() && item && ( item.KindOf("Knife") || item.IsInherited(Screwdriver) ) )
  75. {
  76. return -1;
  77. }
  78. else
  79. {
  80. return GetPrimaryDropsAmount();
  81. }
  82. }
  83. else
  84. {
  85. if ( item && ( item.KindOf("Knife") || item.IsInherited(Screwdriver) ) )
  86. {
  87. return -1;
  88. }
  89. else if ( item && item.KindOf("Axe") )
  90. {
  91. return 3;
  92. }
  93. else
  94. {
  95. return 100;
  96. }
  97. }
  98. }
  99. int GetAmountOfDropsEx(ItemBase item, EHarvestType type)
  100. {
  101. if ( GetPrimaryDropsAmount() > 0 )
  102. {
  103. if ( IsTree() && item && type == EHarvestType.BARK )
  104. {
  105. return -1;
  106. }
  107. else
  108. {
  109. return GetPrimaryDropsAmount();
  110. }
  111. }
  112. else
  113. {
  114. if ( item && type == EHarvestType.BARK )
  115. {
  116. return -1;
  117. }
  118. else if ( item && type == EHarvestType.NORMAL )
  119. {
  120. return 3;
  121. }
  122. else
  123. {
  124. return 100;
  125. }
  126. }
  127. }
  128. void GetMaterialAndQuantityMap(ItemBase item, out map<string,int> output_map)
  129. {
  130. if ( IsTree() && item && ( item.KindOf("Knife") || item.IsInherited(Screwdriver) ) && GetBarkType() != "" )
  131. {
  132. output_map.Insert(GetBarkType(),1);
  133. }
  134. else
  135. {
  136. output_map.Insert(GetPrimaryOutput(),1);
  137. }
  138. }
  139. void GetMaterialAndQuantityMapEx(ItemBase item, out map<string,int> output_map, EHarvestType type)
  140. {
  141. if ( IsTree() && item && type == EHarvestType.BARK && GetBarkType() != "" )
  142. {
  143. output_map.Insert(GetBarkType(),1);
  144. }
  145. else
  146. {
  147. output_map.Insert(GetPrimaryOutput(),1);
  148. }
  149. }
  150. float GetDamageToMiningItemEachDrop(ItemBase item)
  151. {
  152. if (GetToolDamage() > -1)
  153. return GetToolDamage();
  154. if ( IsTree() )
  155. {
  156. if ( item && item.KindOf("Knife") )
  157. {
  158. return 20;
  159. }
  160. else if ( item && item.KindOf("Axe") )
  161. {
  162. return 20;
  163. }
  164. else
  165. {
  166. return 0;
  167. }
  168. }
  169. else
  170. {
  171. if ( item && item.KindOf("Knife") )
  172. {
  173. return 30;
  174. }
  175. else if ( item && item.KindOf("Axe") )
  176. {
  177. return 30;
  178. }
  179. else
  180. {
  181. return 0;
  182. }
  183. }
  184. }
  185. float GetDamageToMiningItemEachDropEx(ItemBase item, EHarvestType type)
  186. {
  187. if (GetToolDamage() > -1)
  188. return GetToolDamage();
  189. if ( IsTree() )
  190. {
  191. if ( item && type == EHarvestType.BARK )
  192. {
  193. return 20;
  194. }
  195. else if ( item && type == EHarvestType.NORMAL )
  196. {
  197. return 20;
  198. }
  199. else
  200. {
  201. return 0;
  202. }
  203. }
  204. else
  205. {
  206. if ( item && type == EHarvestType.BARK )
  207. {
  208. return 30;
  209. }
  210. else if ( item && type == EHarvestType.NORMAL )
  211. {
  212. return 30;
  213. }
  214. else
  215. {
  216. return 0;
  217. }
  218. }
  219. }
  220. override bool CanBeActionTarget()
  221. {
  222. return super.CanBeActionTarget() && !IsDamageDestroyed();
  223. }
  224. }
  225. class TreeEffecterParameters : EffecterParameters
  226. {
  227. float m_Radius;
  228. void TreeEffecterParameters(string type, float lifespan, int radius)
  229. {
  230. m_Radius = radius;
  231. }
  232. }
  233. class TreeEffecter : EffecterBase
  234. {
  235. ref array<WoodBase> m_Plants;
  236. protected ref array<EffectParticleGeneral> m_Effects = null;
  237. private float m_Radius = -1;
  238. private float m_RadiusSync = -1;
  239. void TreeEffecter()
  240. {
  241. if (!GetGame().IsServer() || !GetGame().IsMultiplayer())
  242. {
  243. m_Plants = new array<WoodBase>;
  244. m_Effects = new array<EffectParticleGeneral>;
  245. }
  246. RegisterNetSyncVariableFloat("m_RadiusSync");
  247. }
  248. override void Init(int id, EffecterParameters parameters)
  249. {
  250. super.Init(id, parameters);
  251. TreeEffecterParameters par = TreeEffecterParameters.Cast(parameters);
  252. SetRadius(par.m_Radius);
  253. }
  254. void SetRadius(float radius)
  255. {
  256. m_RadiusSync = radius;
  257. Process();
  258. }
  259. override void OnVariablesSynchronized()
  260. {
  261. if (m_RadiusSync != m_Radius)
  262. {
  263. array<Object> objects = new array<Object>;
  264. array<CargoBase> proxies = new array<CargoBase>;
  265. EffectParticleGeneral newEffect;
  266. foreach (EffectParticleGeneral oldEffect : m_Effects)
  267. {
  268. SEffectManager.DestroyEffect(oldEffect);
  269. }
  270. m_Effects.Clear();
  271. m_Plants.Clear();
  272. GetGame().GetObjectsAtPosition(GetWorldPosition(), m_RadiusSync, objects, proxies);
  273. for (int i = 0; i < objects.Count(); i++)
  274. {
  275. WoodBase plant = WoodBase.Cast(objects[i]);
  276. if (plant)
  277. {
  278. string particle;
  279. int particleID;
  280. string configPath = "CfgNonAIVehicles " + plant.GetType() + " FxFallingParticleEffect particle";
  281. GetGame().ConfigGetText(configPath, particle);
  282. if (particle != "")
  283. {
  284. particleID = ParticleList.RegisterParticle(particle);
  285. }
  286. else
  287. {
  288. particleID = ParticleList.TREE_FALLING_LEAF;
  289. }
  290. LOD lod = plant.GetLODByName(LOD.NAME_MEMORY);
  291. Selection selection = lod.GetSelectionByName("ptcFalling");
  292. if (selection)
  293. {
  294. vector selectionPos;
  295. for (int j = 0; j < selection.GetVertexCount(); j++)
  296. {
  297. newEffect = new EffectParticleGeneral();
  298. newEffect.SetParticle(particleID);
  299. selectionPos = selection.GetVertexPosition(lod, j);
  300. SEffectManager.PlayInWorld(newEffect, plant.GetPosition() + selectionPos);
  301. m_Effects.Insert(newEffect);
  302. }
  303. }
  304. else
  305. {
  306. newEffect = new EffectParticleGeneral();
  307. newEffect.SetParticle(particleID);
  308. SEffectManager.PlayInWorld(newEffect, plant.GetPosition());
  309. m_Effects.Insert(newEffect);
  310. }
  311. m_Plants.Insert(plant);
  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. }