response.c 817 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. unsigned int i = 0;
  16. for (i = 0; i <= RES_TYPES; i++)
  17. response_totals[i] = 0;
  18. }
  19. static void
  20. count_responses(response_t type)
  21. {
  22. unsigned int total = 0;
  23. for (total = 0; res[type][total]; total++)
  24. ;
  25. response_totals[type] = total;
  26. /* printf("Type: %d has %d total responses!\n", type, response_totals[type]); */
  27. }
  28. char *
  29. response(response_t type)
  30. {
  31. if (!type)
  32. type = randint(RES_TYPES) + 1;
  33. /* wait to count the totals until it's used for the first time */
  34. if (!response_totals[type])
  35. count_responses(type);
  36. return res[type][randint(response_totals[type])];
  37. }