Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This function is expanded into multiple lines so I can explain my reasoning
- int revised_cth(int cth, int karma)
- {
- int scalar = min(cth,100-cth); //cth=50 will be affected more by karma than cth=10 or cth=90
- int modifier = karma*scalar/100; //scale our karma modifier accordingly
- int result = cth + modifier; //just add the modifier to our original cth
- result = max(5,min(95,result)); //cap within 5-95
- return result;
- }
- int update_karma(int cth, int karma, bool hit)
- {
- //If we miss, our karma goes up. If we hit, our karma goes down.
- //If we miss when we were likely to hit or we hit when we were likely to miss,
- // then our karma changes a lot.
- //If we hit when we were likely to hit or we miss when we were likely to miss,
- // then our karma doesn't change very much.
- if(hit)
- return karma - (100-cth); //chance to miss
- else
- return karma + cth;
- }
- /**
- * Input:
- * cth : chance to hit, 0-100.
- * karma : the player's karma rating before attacking
- * Output:
- * karma : the player's karma rating after attacking
- * return : whether or not this attack hit
- */
- bool attack(int cth, int& karma)
- {
- int rng = rand() % 100;
- bool hit = (rng < revised_cth(cth,karma));
- karma = update_karma(cth,karma,hit);
- return hit;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement