Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [ Hp, Recharge, Time ] = ShieldRegen( HpMax, RechargeTime, Dps, Resist, Duration )
- %ShieldRegen( HpMax, RechargeTime, Dps, Resist, Duration, Delta );
- % Plots shield HP as a function of time
- % HpMax = Shield max HP
- % RechargeTime = Shield recharge time (see in game ship fitting window)
- % Dps = incoming dps
- % Resist = Shield resist against incoming dps
- % Duration = Time axis of resulting graph
- Delta = 0.01; %simulation time delta
- Eff =1/(1-Resist/100); %effectiveness from resists
- EDps = Dps / Eff; %Effective DPS
- n=1;
- Hp(1)=HpMax;
- Recharge(1)=0;
- Time = 0:Delta:Duration;
- ending = nan;
- for t=Delta:Delta:Duration;
- n=n+1;
- Hp(n) = min( [ Hp(n-1) + (Recharge(n-1)-EDps)*Delta, HpMax] );
- if Hp(n)>0
- Recharge(n) = 2 * HpMax .* 5 ./ RechargeTime .*( sqrt(Hp(n) ./ HpMax) - (Hp(n) ./ HpMax) );
- else
- Hp(n)=0;
- Recharge(n)=0;
- ending = min(ending, n*Delta);
- end
- end
- HP = max(Recharge);
- PeakEHP = HP*Eff;
- HpPercentage = 100*(Hp./HpMax);
- endingtime = ending + 50;
- figure('name', 'Shield regen');
- plot(Time, HpPercentage);
- axis([0, endingtime, 0, 100]);
- xlabel('Time (s)');
- ylabel('Shield Hp %');
- grid on;
- 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 )}'
- title( str );
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement