Advertisement
GraionDilach

AttachEffect 2

Oct 9th, 2011
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 9.12 KB | None | 0 0
  1. Crash addresses vary (sometimes 0000000, sometimes a random hex address), the stack is always the same, always wants to return to last version's line 126... UnInit would crash? O_O
  2.  
  3. Only happen at unit death.
  4.  
  5. Index: Ext/Techno/Body.cpp
  6. ===================================================================
  7. --- Ext/Techno/Body.cpp (revision 1164)
  8. +++ Ext/Techno/Body.cpp (working copy)
  9. @@ -435,6 +435,23 @@
  10.     }
  11.  }
  12.  
  13. +void TechnoExt::TransferAttachedEffects(TechnoClass *From, TechnoClass *To) {
  14. +       auto FromExt = TechnoExt::ExtMap.Find(From);
  15. +       auto ToExt = TechnoExt::ExtMap.Find(To);
  16. +       if (FromExt->AttachedEffects.Count != 0) {
  17. +           ToExt->AttachedEffects.Clear();
  18. +
  19. +           for (int i=0; i<FromExt->AttachedEffects.Count; i++){
  20. +           ToExt->AttachedEffects.AddItem(FromExt->AttachedEffects.GetItem(i));
  21. +               if (ToExt->AttachedEffects.GetItem(i)->Animation) {
  22. +                   ToExt->AttachedEffects.GetItem(i)->Animation->SetOwnerObject(To);
  23. +               }
  24. +           }
  25. +           FromExt->AttachedEffects.Clear();
  26. +       }
  27. +  
  28. +}
  29. +
  30.  bool TechnoExt::ExtData::IsDeactivated() const {
  31.     return this->AttachedToObject->Deactivated;
  32.  }
  33. Index: Ext/Techno/Body.h
  34. ===================================================================
  35. --- Ext/Techno/Body.h   (revision 1164)
  36. +++ Ext/Techno/Body.h   (working copy)
  37. @@ -20,6 +20,8 @@
  38.  #include "../WeaponType/Body.h"
  39.  #include "../TechnoType/Body.h"
  40.  
  41. +#include "../../Misc/AttachEffect.h"
  42. +
  43.  #include "../_Container.hpp"
  44.  
  45.  //#include "../../Misc/JammerClass.h"
  46. @@ -58,6 +60,8 @@
  47.         // issue #617 powered units
  48.         PoweredUnitClass* PoweredUnit;
  49.  
  50. +       DynamicVectorClass <AttachEffectClass *> AttachedEffects;
  51. +
  52.         ExtData(const DWORD Canary, TT* const OwnerObject) : Extension<TT>(Canary, OwnerObject),
  53.             idxSlot_Wave (0),
  54.             idxSlot_Beam (0),
  55. @@ -125,6 +129,7 @@
  56.  
  57.     static void TransferMindControl(TechnoClass *From, TechnoClass *To);
  58.     static void TransferIvanBomb(TechnoClass *From, TechnoClass *To);
  59. +   static void TransferAttachedEffects(TechnoClass *From, TechnoClass *To);
  60.    
  61.     static void Destroy(TechnoClass* pTechno, TechnoClass* pKiller = NULL, HouseClass* pKillerHouse = NULL, WarheadTypeClass* pWarhead = NULL);
  62.  /*
  63. Index: Ext/Techno/Hooks.cpp
  64. ===================================================================
  65. --- Ext/Techno/Hooks.cpp    (revision 1164)
  66. +++ Ext/Techno/Hooks.cpp    (working copy)
  67. @@ -64,6 +64,21 @@
  68.         pData->PoweredUnit->Update();
  69.     }
  70.  
  71. +   //updating attached effects
  72. +   if (pData->AttachedEffects.Count) {
  73. +       for (int i=pData->AttachedEffects.Count; i>0; --i) {
  74. +           auto Effect = pData->AttachedEffects.GetItem(i-1);
  75. +           --Effect->ActualDuration;
  76. +           if(!Effect->ActualDuration) {
  77. +               Debug::Log("[AttachEffect] Removing %d. item from %s", i-1, Source->GetTechnoType()->ID);
  78. +               Effect->Destroy();
  79. +               delete Effect;
  80. +               pData->AttachedEffects.RemoveItem(i-1);
  81. +           }
  82. +
  83. +       }
  84. +   }
  85. +
  86.     return 0;
  87.  }
  88.  
  89. @@ -135,6 +150,7 @@
  90.         }
  91.     }
  92.  
  93. +
  94.     /*  using 0x6F9E7C instead makes this function override the original game one's entirely -
  95.         don't activate that unless you handle _everything_ originally handled by the game */
  96.     return 0;
  97. @@ -737,5 +753,17 @@
  98.         TechnoExt->PoweredUnit = NULL;
  99.     }
  100.  
  101. +   //attached effects
  102. +   if (TechnoExt->AttachedEffects.Count){
  103. +       for (int i=TechnoExt->AttachedEffects.Count; i>0; --i) {
  104. +           Debug::Log("[AttachEffect] Removing %d. item from %s\n", i-1, pThis->GetTechnoType()->ID);
  105. +           TechnoExt->AttachedEffects.GetItem(i-1)->Destroy();
  106. +           delete TechnoExt->AttachedEffects.GetItem(i-1);
  107. +       }
  108. +       Debug::Log("[AttachEffect] Deleting array of %s\n", pThis->GetTechnoType()->ID);
  109. +       TechnoExt->AttachedEffects.Clear();
  110. +
  111. +   }
  112. +
  113.     return 0;
  114.  }
  115. Index: Ext/WarheadType/Body.cpp
  116. ===================================================================
  117. --- Ext/WarheadType/Body.cpp    (revision 1164)
  118. +++ Ext/WarheadType/Body.cpp    (working copy)
  119. @@ -93,6 +93,8 @@
  120.     this->KillDriver = pINI->ReadBool(section, "KillDriver", this->KillDriver);
  121.  
  122.     this->Malicious.Read(&exINI, section, "Malicious");
  123. +
  124. +   this->AttachedEffect.Read(&exINI, section);
  125.  };
  126.  
  127.  void Container<WarheadTypeExt>::InvalidatePointer(void *ptr) {
  128. Index: Ext/WarheadType/Body.h
  129. ===================================================================
  130. --- Ext/WarheadType/Body.h  (revision 1164)
  131. +++ Ext/WarheadType/Body.h  (working copy)
  132. @@ -19,6 +19,8 @@
  133.  
  134.  #include <Conversions.h>
  135.  
  136. +#include "../../Misc/AttachEffect.h"
  137. +
  138.  #include "../_Container.hpp"
  139.  
  140.  #include "../../Utilities/Template.h"
  141. @@ -75,6 +77,8 @@
  142.  
  143.         Valueable<bool> Malicious;
  144.  
  145. +       AttachEffectTypeClass AttachedEffect;
  146. +
  147.         ExtData(const DWORD Canary, TT* const OwnerObject) : Extension<TT>(Canary, OwnerObject),
  148.             MindControl_Permanent (false),
  149.             Ripple_Radius (0),
  150. @@ -88,7 +92,8 @@
  151.             InfDeathAnim (NULL),
  152.             PreImpactAnim (-1),
  153.             KillDriver (false),
  154. -           Malicious (true)
  155. +           Malicious (true),
  156. +           AttachedEffect()
  157.             {
  158.                 for(int i = 0; i < 11; ++i) {
  159.                     VersesData vs;
  160. Index: Ext/WarheadType/Hooks.cpp
  161. ===================================================================
  162. --- Ext/WarheadType/Hooks.cpp   (revision 1164)
  163. +++ Ext/WarheadType/Hooks.cpp   (working copy)
  164. @@ -56,6 +56,12 @@
  165.         pWHExt->applyEMP(&coords, Bullet->Owner);
  166.         WarheadTypeExt::applyOccupantDamage(Bullet);
  167.         pWHExt->applyKillDriver(Bullet);
  168. +
  169. +       if (!!pWHExt->AttachedEffect.Duration && Bullet->Target){
  170. +           TechnoClass *Target = generic_cast<TechnoClass *>(Bullet->Target);
  171. +           pWHExt->AttachedEffect.Attach(Target);
  172. +       }
  173. +      
  174.     }
  175.  
  176.  /*
  177. Index: Misc/AttachEffect.cpp
  178. ===================================================================
  179. --- Misc/AttachEffect.cpp   (revision 0)
  180. +++ Misc/AttachEffect.cpp   (revision 0)
  181. @@ -0,0 +1,49 @@
  182. +#include "AttachEffect.h"
  183. +#include "../Ext/Techno/Body.h"
  184. +#include "../Ext/TechnoType/Body.h"
  185. +#include "../Ext/WarheadType/Body.h"
  186. +
  187. +/*
  188. +Attached Effects system
  189. +Graion Dilach, 2011-09-24+
  190. +Proper documentation gets done if proper code there is.
  191. +*/
  192. +
  193. +void AttachEffectTypeClass::Attach(TechnoClass* Target) {
  194. +   if (!Target) {return;}
  195. +
  196. +   TechnoExt::ExtData *TargetExt = TechnoExt::ExtMap.Find(Target);
  197. +
  198. +
  199. +   if (!this->Cumulative && TargetExt->AttachedEffects.Count > 0) {
  200. +       for (int i=0; i < TargetExt->AttachedEffects.Count; i++) {
  201. +           if (this->ID == TargetExt->AttachedEffects.GetItem(i)->Type->ID){
  202. +               TargetExt->AttachedEffects.GetItem(i)->ActualDuration = TargetExt->AttachedEffects.GetItem(i)->Type->Duration;
  203. +               return;
  204. +           }
  205. +       }
  206. +   }
  207. +
  208. +   //there goes the actual attaching
  209. +   auto Attaching = new AttachEffectClass(this, this->Duration);
  210. +   TargetExt->AttachedEffects.AddItem(Attaching);
  211. +   Debug::Log("[AttachEffect] Creating new item on %s, slot %d...\n", Target->GetTechnoType()->ID, TargetExt->AttachedEffects.GetItemIndex(&Attaching));
  212. +   //meh, instead of index, turns out pointer adress, whatever
  213. +
  214. +
  215. +   // animation
  216. +   GAME_ALLOC(AnimClass, Attaching->Animation, this->AnimType, &Target->Location);
  217. +   Attaching->Animation->SetOwnerObject(Target);
  218. +   // inb4 void pointers, hardcode the iteration to infinitely looped
  219. +   Attaching->Animation->RemainingIterations=-1;
  220. +  
  221. +}
  222. +
  223. +void AttachEffectClass::Destroy(){
  224. +   if (this->Animation){
  225. +           this->Animation->SetOwnerObject(NULL);
  226. +           this->Animation->TimeToDie = true;
  227. +           this->Animation->UnInit();
  228. +           this->Animation = NULL;
  229. +   }
  230. +}
  231. \ No newline at end of file
  232. Index: Misc/AttachEffect.h
  233. ===================================================================
  234. --- Misc/AttachEffect.h (revision 0)
  235. +++ Misc/AttachEffect.h (revision 0)
  236. @@ -0,0 +1,51 @@
  237. +#ifndef ATTACHEFFECT_H_
  238. +#define ATTACHEFFECT_H_
  239. +
  240. +#include <vector>
  241. +#include <TechnoClass.h>
  242. +
  243. +#include "../Utilities/Template.h"
  244. +
  245. +
  246. +class AttachEffectTypeClass {
  247. +public:
  248. +
  249. +   const char* ID;
  250. +   Valueable<int> Duration;
  251. +   Valueable<bool> Cumulative;
  252. +
  253. +   Valueable<AnimTypeClass *> AnimType;
  254. +  
  255. +   virtual void Attach(TechnoClass* Target);
  256. +
  257. +   AttachEffectTypeClass(){
  258. +       this->Cumulative = false;
  259. +       this->Duration = 0;
  260. +   };
  261. +
  262. +   void Read(INI_EX *exINI, const char * section) {
  263. +      
  264. +       this->ID = section;
  265. +       this->Duration.Read(exINI, section, "AttachEffect.Duration");
  266. +       this->Cumulative.Read(exINI, section, "AttachEffect.Cumulative");
  267. +       this->AnimType.Parse(exINI, section, "AttachEffect.Animation");
  268. +
  269. +   }
  270. +};
  271. +
  272. +class AttachEffectClass {
  273. +public:
  274. +   AttachEffectClass(AttachEffectTypeClass* AEType, int Timer){
  275. +   this->Type = AEType;
  276. +   this->ActualDuration = Timer;
  277. +   }
  278. +
  279. +   AttachEffectTypeClass * Type;
  280. +   AnimClass * Animation;
  281. +   int ActualDuration;
  282. +
  283. +   void Destroy();
  284. +};
  285. +
  286. +
  287. +#endif
  288. \ No newline at end of file
  289. Index: Misc/Bugfixes.cpp
  290. ===================================================================
  291. --- Misc/Bugfixes.cpp   (revision 1164)
  292. +++ Misc/Bugfixes.cpp   (working copy)
  293. @@ -905,6 +905,7 @@
  294.  
  295.     TechnoExt::TransferMindControl(pUnit, pStructure);
  296.     TechnoExt::TransferIvanBomb(pUnit, pStructure);
  297. +   TechnoExt::TransferAttachedEffects(pUnit, pStructure);
  298.  
  299.     pStructure->QueueMission(mission_Construction, 0);
  300.  
  301. @@ -925,6 +926,7 @@
  302.  
  303.     TechnoExt::TransferMindControl(pStructure, pUnit);
  304.     TechnoExt::TransferIvanBomb(pStructure, pUnit);
  305. +   TechnoExt::TransferAttachedEffects(pStructure, pUnit);
  306.  
  307.     return 0;
  308.  }
  309.  
  310.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement