draw.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. /* $NetBSD: draw.c,v 1.3 2003/06/11 12:00:22 wiz Exp $ */
  2. /*
  3. * Copyright (c) 1983-2003, Regents of the University of California.
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are
  8. * met:
  9. *
  10. * + Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * + Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * + Neither the name of the University of California, San Francisco nor
  16. * the names of its contributors may be used to endorse or promote
  17. * products derived from this software without specific prior written
  18. * permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  21. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  22. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  23. * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #include <sys/cdefs.h>
  33. #ifndef lint
  34. __RCSID("$NetBSD: draw.c,v 1.3 2003/06/11 12:00:22 wiz Exp $");
  35. #endif /* not lint */
  36. # include "hunt.h"
  37. void
  38. drawmaze(pp)
  39. PLAYER *pp;
  40. {
  41. int x;
  42. char *sp;
  43. int y;
  44. char *endp;
  45. clrscr(pp);
  46. outstr(pp, pp->p_maze[0], WIDTH);
  47. for (y = 1; y < HEIGHT - 1; y++) {
  48. endp = &pp->p_maze[y][WIDTH];
  49. for (x = 0, sp = pp->p_maze[y]; sp < endp; x++, sp++)
  50. if (*sp != SPACE) {
  51. cgoto(pp, y, x);
  52. if (pp->p_x == x && pp->p_y == y)
  53. outch(pp, translate(*sp));
  54. else if (is_player(*sp))
  55. outch(pp, player_sym(pp, y, x));
  56. else
  57. outch(pp, *sp);
  58. }
  59. }
  60. cgoto(pp, HEIGHT - 1, 0);
  61. outstr(pp, pp->p_maze[HEIGHT - 1], WIDTH);
  62. drawstatus(pp);
  63. }
  64. /*
  65. * drawstatus - put up the status lines (this assumes the screen
  66. * size is 80x24 with the maze being 64x24)
  67. */
  68. void
  69. drawstatus(pp)
  70. PLAYER *pp;
  71. {
  72. int i;
  73. PLAYER *np;
  74. cgoto(pp, STAT_AMMO_ROW, STAT_LABEL_COL);
  75. outstr(pp, "Ammo:", 5);
  76. (void) sprintf(Buf, "%3d", pp->p_ammo);
  77. cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL);
  78. outstr(pp, Buf, 3);
  79. cgoto(pp, STAT_GUN_ROW, STAT_LABEL_COL);
  80. outstr(pp, "Gun:", 4);
  81. cgoto(pp, STAT_GUN_ROW, STAT_VALUE_COL);
  82. outstr(pp, (pp->p_ncshot < MAXNCSHOT) ? " ok" : " ", 3);
  83. cgoto(pp, STAT_DAM_ROW, STAT_LABEL_COL);
  84. outstr(pp, "Damage:", 7);
  85. (void) sprintf(Buf, "%2d/%2d", pp->p_damage, pp->p_damcap);
  86. cgoto(pp, STAT_DAM_ROW, STAT_VALUE_COL);
  87. outstr(pp, Buf, 5);
  88. cgoto(pp, STAT_KILL_ROW, STAT_LABEL_COL);
  89. outstr(pp, "Kills:", 6);
  90. (void) sprintf(Buf, "%3d", (pp->p_damcap - MAXDAM) / 2);
  91. cgoto(pp, STAT_KILL_ROW, STAT_VALUE_COL);
  92. outstr(pp, Buf, 3);
  93. cgoto(pp, STAT_PLAY_ROW, STAT_LABEL_COL);
  94. outstr(pp, "Player:", 7);
  95. for (i = STAT_PLAY_ROW + 1, np = Player; np < End_player; np++) {
  96. (void) sprintf(Buf, "%5.2f%c%-10.10s %c", np->p_ident->i_score,
  97. stat_char(np), np->p_ident->i_name,
  98. np->p_ident->i_team);
  99. cgoto(pp, i++, STAT_NAME_COL);
  100. outstr(pp, Buf, STAT_NAME_LEN);
  101. }
  102. # ifdef MONITOR
  103. cgoto(pp, STAT_MON_ROW, STAT_LABEL_COL);
  104. outstr(pp, "Monitor:", 8);
  105. for (i = STAT_MON_ROW + 1, np = Monitor; np < End_monitor; np++) {
  106. (void) sprintf(Buf, "%5.5s %-10.10s %c", " ",
  107. np->p_ident->i_name, np->p_ident->i_team);
  108. cgoto(pp, i++, STAT_NAME_COL);
  109. outstr(pp, Buf, STAT_NAME_LEN);
  110. }
  111. # endif
  112. }
  113. void
  114. look(pp)
  115. PLAYER *pp;
  116. {
  117. int x, y;
  118. x = pp->p_x;
  119. y = pp->p_y;
  120. check(pp, y - 1, x - 1);
  121. check(pp, y - 1, x );
  122. check(pp, y - 1, x + 1);
  123. check(pp, y , x - 1);
  124. check(pp, y , x );
  125. check(pp, y , x + 1);
  126. check(pp, y + 1, x - 1);
  127. check(pp, y + 1, x );
  128. check(pp, y + 1, x + 1);
  129. switch (pp->p_face) {
  130. case LEFTS:
  131. see(pp, LEFTS);
  132. see(pp, ABOVE);
  133. see(pp, BELOW);
  134. break;
  135. case RIGHT:
  136. see(pp, RIGHT);
  137. see(pp, ABOVE);
  138. see(pp, BELOW);
  139. break;
  140. case ABOVE:
  141. see(pp, ABOVE);
  142. see(pp, LEFTS);
  143. see(pp, RIGHT);
  144. break;
  145. case BELOW:
  146. see(pp, BELOW);
  147. see(pp, LEFTS);
  148. see(pp, RIGHT);
  149. break;
  150. # ifdef FLY
  151. case FLYER:
  152. break;
  153. # endif
  154. }
  155. cgoto(pp, y, x);
  156. }
  157. void
  158. see(pp, face)
  159. PLAYER *pp;
  160. int face;
  161. {
  162. char *sp;
  163. int y, x, i, cnt;
  164. x = pp->p_x;
  165. y = pp->p_y;
  166. switch (face) {
  167. case LEFTS:
  168. sp = &Maze[y][x];
  169. for (i = 0; See_over[(int)*--sp]; i++)
  170. continue;
  171. if (i == 0)
  172. break;
  173. cnt = i;
  174. x = pp->p_x - 1;
  175. --y;
  176. while (i--)
  177. check(pp, y, --x);
  178. i = cnt;
  179. x = pp->p_x - 1;
  180. ++y;
  181. while (i--)
  182. check(pp, y, --x);
  183. i = cnt;
  184. x = pp->p_x - 1;
  185. ++y;
  186. while (i--)
  187. check(pp, y, --x);
  188. break;
  189. case RIGHT:
  190. sp = &Maze[y][++x];
  191. for (i = 0; See_over[(int)*sp++]; i++)
  192. continue;
  193. if (i == 0)
  194. break;
  195. cnt = i;
  196. x = pp->p_x + 1;
  197. --y;
  198. while (i--)
  199. check(pp, y, ++x);
  200. i = cnt;
  201. x = pp->p_x + 1;
  202. ++y;
  203. while (i--)
  204. check(pp, y, ++x);
  205. i = cnt;
  206. x = pp->p_x + 1;
  207. ++y;
  208. while (i--)
  209. check(pp, y, ++x);
  210. break;
  211. case ABOVE:
  212. sp = &Maze[--y][x];
  213. if (!See_over[(int)*sp])
  214. break;
  215. do {
  216. --y;
  217. sp -= sizeof Maze[0];
  218. check(pp, y, x - 1);
  219. check(pp, y, x );
  220. check(pp, y, x + 1);
  221. } while (See_over[(int)*sp]);
  222. break;
  223. case BELOW:
  224. sp = &Maze[++y][x];
  225. if (!See_over[(int)*sp])
  226. break;
  227. do {
  228. y++;
  229. sp += sizeof Maze[0];
  230. check(pp, y, x - 1);
  231. check(pp, y, x );
  232. check(pp, y, x + 1);
  233. } while (See_over[(int)*sp]);
  234. break;
  235. }
  236. }
  237. void
  238. check(pp, y, x)
  239. PLAYER *pp;
  240. int y, x;
  241. {
  242. int index;
  243. int ch;
  244. PLAYER *rpp;
  245. index = y * sizeof Maze[0] + x;
  246. ch = ((char *) Maze)[index];
  247. if (ch != ((char *) pp->p_maze)[index]) {
  248. rpp = pp;
  249. cgoto(rpp, y, x);
  250. if (x == rpp->p_x && y == rpp->p_y)
  251. outch(rpp, translate(ch));
  252. else if (is_player(ch))
  253. outch(rpp, player_sym(rpp, y, x));
  254. else
  255. outch(rpp, ch);
  256. ((char *) rpp->p_maze)[index] = ch;
  257. }
  258. }
  259. /*
  260. * showstat
  261. * Update the status of players
  262. */
  263. void
  264. showstat(pp)
  265. PLAYER *pp;
  266. {
  267. PLAYER *np;
  268. int y;
  269. char c;
  270. y = STAT_PLAY_ROW + 1 + (pp - Player);
  271. c = stat_char(pp);
  272. # ifdef MONITOR
  273. for (np = Monitor; np < End_monitor; np++) {
  274. cgoto(np, y, STAT_SCAN_COL);
  275. outch(np, c);
  276. }
  277. # endif
  278. for (np = Player; np < End_player; np++) {
  279. cgoto(np, y, STAT_SCAN_COL);
  280. outch(np, c);
  281. }
  282. }
  283. /*
  284. * drawplayer:
  285. * Draw the player on the screen and show him to everyone who's scanning
  286. * unless he is cloaked.
  287. */
  288. void
  289. drawplayer(pp, draw)
  290. PLAYER *pp;
  291. FLAG draw;
  292. {
  293. PLAYER *newp;
  294. int x, y;
  295. x = pp->p_x;
  296. y = pp->p_y;
  297. Maze[y][x] = draw ? pp->p_face : pp->p_over;
  298. # ifdef MONITOR
  299. for (newp = Monitor; newp < End_monitor; newp++)
  300. check(newp, y, x);
  301. # endif
  302. for (newp = Player; newp < End_player; newp++) {
  303. if (!draw || newp == pp) {
  304. check(newp, y, x);
  305. continue;
  306. }
  307. if (newp->p_scan == 0) {
  308. newp->p_scan--;
  309. showstat(newp);
  310. }
  311. else if (newp->p_scan > 0) {
  312. if (pp->p_cloak < 0)
  313. check(newp, y, x);
  314. newp->p_scan--;
  315. }
  316. }
  317. if (!draw || pp->p_cloak < 0)
  318. return;
  319. if (pp->p_cloak-- == 0)
  320. showstat(pp);
  321. }
  322. void
  323. message(pp, s)
  324. PLAYER *pp;
  325. const char *s;
  326. {
  327. cgoto(pp, HEIGHT, 0);
  328. outstr(pp, s, strlen(s));
  329. ce(pp);
  330. }
  331. /*
  332. * translate:
  333. * Turn a character into the right direction character if we are
  334. * looking at the current player.
  335. */
  336. char
  337. translate(ch)
  338. char ch;
  339. {
  340. switch (ch) {
  341. case LEFTS:
  342. return '<';
  343. case RIGHT:
  344. return '>';
  345. case ABOVE:
  346. return '^';
  347. case BELOW:
  348. return 'v';
  349. }
  350. return ch;
  351. }
  352. /*
  353. * player_sym:
  354. * Return the player symbol
  355. */
  356. int
  357. player_sym(pp, y, x)
  358. const PLAYER *pp;
  359. int y, x;
  360. {
  361. PLAYER *npp;
  362. npp = play_at(y, x);
  363. if (npp->p_ident->i_team == ' ')
  364. return Maze[y][x];
  365. #ifdef MONITOR
  366. if (pp->p_ident->i_team == '*')
  367. return npp->p_ident->i_team;
  368. #endif
  369. if (pp->p_ident->i_team != npp->p_ident->i_team)
  370. return Maze[y][x];
  371. return pp->p_ident->i_team;
  372. }