| 784 | } |
| 785 | |
| 786 | int |
| 787 | randrace(int rolenum) |
| 788 | { |
| 789 | int i, n = 0; |
| 790 | |
| 791 | /* Count the number of valid races */ |
| 792 | for (i = 0; races[i].noun; i++) |
| 793 | if (roles[rolenum].allow & races[i].allow & ROLE_RACEMASK) |
| 794 | n++; |
| 795 | |
| 796 | /* Pick a random race */ |
| 797 | /* Use a factor of 100 in case of bad random number generators */ |
| 798 | if (n) |
| 799 | n = rn2(n * 100) / 100; |
| 800 | for (i = 0; races[i].noun; i++) |
| 801 | if (roles[rolenum].allow & races[i].allow & ROLE_RACEMASK) { |
| 802 | if (n) |
| 803 | n--; |
| 804 | else |
| 805 | return i; |
| 806 | } |
| 807 | |
| 808 | /* This role has no permitted races? */ |
| 809 | return rn2(SIZE(races) - 1); |
| 810 | } |
| 811 | |
| 812 | int |
| 813 | str2race(const char *str) |
no test coverage detected