Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. function [ Hp, Recharge, Time ] = ShieldRegen( HpMax, RechargeTime, Dps, Resist, Duration )
  2. %ShieldRegen( HpMax, RechargeTime, Dps, Resist, Duration, Delta );
  3. % Plots shield HP as a function of time
  4. % HpMax = Shield max HP
  5. % RechargeTime = Shield recharge time (see in game ship fitting window)
  6. % Dps = incoming dps
  7. % Resist = Shield resist against incoming dps
  8. % Duration = Time axis of resulting graph
  9.  
  10. Delta = 0.01; %simulation time delta
  11. Eff =1/(1-Resist/100); %effectiveness from resists
  12. EDps = Dps / Eff; %Effective DPS
  13.  
  14. n=1;
  15. Hp(1)=HpMax;
  16. Recharge(1)=0;
  17. Time = 0:Delta:Duration;
  18. ending = nan;
  19.  
  20. for t=Delta:Delta:Duration;
  21. n=n+1;
  22. Hp(n) = min( [ Hp(n-1) + (Recharge(n-1)-EDps)*Delta, HpMax] );
  23.  
  24. if Hp(n)>0
  25. Recharge(n) = 2 * HpMax .* 5 ./ RechargeTime .*( sqrt(Hp(n) ./ HpMax) - (Hp(n) ./ HpMax) );
  26. else
  27. Hp(n)=0;
  28. Recharge(n)=0;
  29. ending = min(ending, n*Delta);
  30. end
  31.  
  32.  
  33. end
  34.  
  35.  
  36. HP = max(Recharge);
  37. PeakEHP = HP*Eff;
  38. HpPercentage = 100*(Hp./HpMax);
  39. endingtime = ending + 50;
  40.  
  41. figure('name', 'Shield regen');
  42. plot(Time, HpPercentage);
  43. axis([0, endingtime, 0, 100]);
  44. xlabel('Time (s)');
  45. ylabel('Shield Hp %');
  46. grid on;
  47. str = { sprintf('Incoming damage: %d dps', Dps), sprintf('Shield: Max HP %d, resist %.1f %%, recharge time %d s', HpMax, Resist, RechargeTime), sprintf('Max recharge %.0f EHP/s', PeakEHP )}'
  48. title( str );
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement