response.c 995 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * response.c -- handles:
  3. *
  4. * What else?!
  5. *
  6. */
  7. #include "common.h"
  8. #include "response.h"
  9. #include "main.h"
  10. #include "responses.h"
  11. static response_t response_totals[RES_TYPES + 1];
  12. void
  13. init_responses()
  14. {
  15. for (response_t i = 0; i <= RES_TYPES; i++)
  16. response_totals[i] = 0;
  17. }
  18. static void
  19. count_responses(response_t type)
  20. {
  21. response_t total = 0;
  22. for (total = 0; res[type][total]; total++)
  23. ;
  24. response_totals[type] = total;
  25. /* printf("Type: %d has %d total responses!\n", type, response_totals[type]); */
  26. }
  27. const char *
  28. response(response_t type)
  29. {
  30. if (!type)
  31. type = randint(RES_TYPES) + 1;
  32. /* wait to count the totals until it's used for the first time */
  33. if (!response_totals[type])
  34. count_responses(type);
  35. return res[type][randint(response_totals[type])];
  36. }
  37. const char *
  38. r_banned()
  39. {
  40. if (!offensive_bans)
  41. return response(RES_BANNED);
  42. if (randint(1))
  43. return response(RES_BANNED);
  44. else
  45. return response(RES_BANNED_OFFENSIVE);
  46. }