You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Computer.c 2.3 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #include <stdlib.h>
  2. #include "types.h"
  3. #include "util.h"
  4. #include "Bill.h"
  5. #include "Computer.h"
  6. #include "Horde.h"
  7. #include "Network.h"
  8. #include "Game.h"
  9. #include "OS.h"
  10. #include "UI.h"
  11. #define OS_OFFSET 4 /* offset of screen from 0,0 */
  12. #define BORDER(size) (size / 10) /* at least this far from a side */
  13. #define MIN_PC 6 /* type >= MIN_PC means the computer is a PC */
  14. static const char *cpuname[] = {"toaster", "maccpu", "nextcpu", "sgicpu",
  15. "suncpu", "os2cpu", "bsdcpu"};
  16. #define NUM_SYS (sizeof(cpuname) / sizeof(cpuname[0]))
  17. static Picture *pictures[NUM_SYS]; /* array of cpu pictures */
  18. static int width, height;
  19. static int
  20. determineOS(Computer *computer) {
  21. if (computer->type < MIN_PC)
  22. return computer->type;
  23. else
  24. return OS_randpc();
  25. }
  26. int
  27. Computer_setup(Computer *computer, int index) {
  28. int j, counter = 0, flag;
  29. int x, y;
  30. int screensize = Game_screensize();
  31. int border = BORDER(screensize);
  32. do {
  33. if (++counter > 4000)
  34. return 0;
  35. x = RAND(border, screensize - border - width);
  36. y = RAND(border, screensize - border - height);
  37. flag = 1;
  38. /* check for conflicting computer placement */
  39. for (j = 0; j < index && flag; j++) {
  40. Computer *c = Network_get_computer(j);
  41. int twidth = width - BILL_OFFSET_X + Bill_width();
  42. if (UI_intersect(x, y, twidth, height,
  43. c->x, c->y, twidth, height))
  44. flag = 0;
  45. }
  46. } while (!flag);
  47. computer->x = x;
  48. computer->y = y;
  49. computer->type = RAND(1, NUM_SYS - 1);
  50. computer->os = determineOS(computer);
  51. computer->busy = 0;
  52. computer->stray = NULL;
  53. return 1;
  54. }
  55. int
  56. Computer_on(Computer *computer, int locx, int locy) {
  57. return (abs(locx - computer->x) < width &&
  58. abs(locy - computer->y) < height);
  59. }
  60. int
  61. Computer_compatible(Computer *computer, int system) {
  62. return (computer->type == system ||
  63. (computer->type >= MIN_PC && OS_ispc(system)));
  64. }
  65. void
  66. Computer_draw(Computer *computer) {
  67. UI_draw(pictures[computer->type], computer->x, computer->y);
  68. if (computer->os != OS_OFF)
  69. OS_draw(computer->os,
  70. computer->x + OS_OFFSET, computer->y + OS_OFFSET);
  71. }
  72. void
  73. Computer_load_pix() {
  74. unsigned int i;
  75. for (i = 0; i < NUM_SYS; i++)
  76. UI_load_picture(cpuname[i], 1, &pictures[i]);
  77. width = UI_picture_width(pictures[0]);
  78. height = UI_picture_height(pictures[0]);
  79. }
  80. int
  81. Computer_width() {
  82. return width;
  83. }
  84. int
  85. Computer_height() {
  86. return height;
  87. }