Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. //This function is expanded into multiple lines so I can explain my reasoning
  2. int revised_cth(int cth, int karma)
  3. {
  4. int scalar = min(cth,100-cth); //cth=50 will be affected more by karma than cth=10 or cth=90
  5. int modifier = karma*scalar/100; //scale our karma modifier accordingly
  6. int result = cth + modifier; //just add the modifier to our original cth
  7. result = max(5,min(95,result)); //cap within 5-95
  8. return result;
  9. }
  10.  
  11. int update_karma(int cth, int karma, bool hit)
  12. {
  13. //If we miss, our karma goes up. If we hit, our karma goes down.
  14. //If we miss when we were likely to hit or we hit when we were likely to miss,
  15. // then our karma changes a lot.
  16. //If we hit when we were likely to hit or we miss when we were likely to miss,
  17. // then our karma doesn't change very much.
  18. if(hit)
  19. return karma - (100-cth); //chance to miss
  20. else
  21. return karma + cth;
  22. }
  23.  
  24. /**
  25. * Input:
  26. * cth : chance to hit, 0-100.
  27. * karma : the player's karma rating before attacking
  28. * Output:
  29. * karma : the player's karma rating after attacking
  30. * return : whether or not this attack hit
  31. */
  32. bool attack(int cth, int& karma)
  33. {
  34. int rng = rand() % 100;
  35. bool hit = (rng < revised_cth(cth,karma));
  36.  
  37. karma = update_karma(cth,karma,hit);
  38.  
  39. return hit;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement