bang.c revision 1.1 1 /* $Header: /tank/opengrok/rsync2/NetBSD/src/games/warp/bang.c,v 1.1 2020/11/09 23:37:05 kamil Exp $ */
2
3 /* $Log: bang.c,v $
4 /* Revision 1.1 2020/11/09 23:37:05 kamil
5 /* Add Warp Kit, Version 7.0 by Larry Wall
6 /*
7 /* Warp is a real-time space war game that doesn't get boring very quickly.
8 /* Read warp.doc and the manual page for more information.
9 /*
10 /* games/warp originally distributed with 4.3BSD-Reno, is back to the BSD
11 /* world via NetBSD. Its remnants were still mentioned in games/Makefile.
12 /*
13 /* Larry Wall, the original author and the copyright holder, generously
14 /* donated the game and copyright to The NetBSD Foundation, Inc.
15 /*
16 /* Import the game sources as-is from 4.3BSD-Reno, with the cession
17 /* of the copyright and license to BSD-2-clause NetBSD-style.
18 /*
19 /* Signed-off-by: Larry Wall <larry (at) wall.org>
20 /* Signed-off-by: Kamil Rytarowski <kamil (at) netbsd.org>
21 /*
22 * Revision 7.0.1.3 86/12/12 16:57:00 lwall
23 * Made circular explosions.
24 *
25 * Revision 7.0.1.2 86/10/20 14:36:02 lwall
26 * Picked some lint.
27 *
28 * Revision 7.0.1.1 86/10/16 10:49:45 lwall
29 * Added Damage. Fixed random bugs.
30 *
31 * Revision 7.0 86/10/08 15:11:57 lwall
32 * Split into separate files. Added amoebas and pirates.
33 *
34 */
35
36 #include "EXTERN.h"
37 #include "warp.h"
38 #include "object.h"
39 #include "move.h"
40 #include "sig.h"
41 #include "term.h"
42 #include "them.h"
43 #include "INTERN.h"
44 #include "bang.h"
45
46 void
47 bang_init()
48 {
49 ;
50 }
51
52 void
53 make_plink(y,x)
54 Reg1 int x;
55 Reg2 int y;
56 {
57 Reg3 OBJECT *obj;
58
59 move(y+1,x*2,0);
60 beg_qwrite();
61 *filler = '@';
62 qwrite();
63 obj = occupant[y][x];
64 if (obj) {
65 if (numamoebas && obj->image == ' ')
66 qaddc(amb[y][x]);
67 else
68 qaddc(obj->image);
69 }
70 else if (numamoebas)
71 qaddc(amb[y][x]);
72 else
73 qaddspace();
74 end_qwrite();
75 }
76
77 void
78 make_blast(y,x,mass,size)
79 Reg1 int x;
80 Reg2 int y;
81 int size;
82 long mass;
83 {
84 bangy[nxtbang] = y;
85 bangx[nxtbang] = x;
86 bangm[nxtbang] = mass;
87 bangs[nxtbang++] = size;
88 assert(nxtbang <= XSIZE * YSIZE);
89 if (numamoebas && amb[y][x] == '~') {
90 if (mass > 10000)
91 modify_amoeba(y,x,1,'~', 10);
92 else if (mass > 100)
93 modify_amoeba(y,x,1,'~', 5);
94 bangs[nxtbang-1] = 0; /* don't propagate */
95 return;
96 }
97 else if (mass >= 0) {
98 Reg3 OBJECT *obj;
99
100 move(y+1,x*2,0);
101 beg_qwrite();
102 *filler = '@';
103 qwrite();
104 *filler = '#';
105 qwrite();
106 *filler = '@';
107 qwrite();
108 *filler = '#';
109 qwrite();
110 *filler = '@';
111 qwrite();
112 obj = occupant[y][x];
113 if (obj) {
114 if (numamoebas && obj->image == ' ')
115 qaddc(amb[y][x]);
116 else
117 qaddc(obj->image);
118 }
119 else if (numamoebas)
120 qaddc(amb[y][x]);
121 else
122 qaddspace();
123 end_qwrite();
124 }
125 }
126
127 void
128 do_bangs()
129 {
130 Reg1 int x;
131 Reg2 int y;
132 Reg3 int i;
133 Reg4 int j;
134 Reg7 int k;
135 Reg5 int lastxy;
136 Reg6 OBJECT *obj;
137
138 /* read blast list and update blast array */
139 assert(nxtbang >= 0 && nxtbang <= XSIZE * YSIZE);
140 for (i=0; i<nxtbang; i++) {
141 if (bangm[i] != 32767)
142 bangm[i] *= 4;
143 lastxy = bangs[i] << 1;
144 if (lastxy >= MAXBDIST)
145 lastxy = MAXBDIST - 1;
146 for (y=bangy[i]-bangs[i],x=bangx[i]-bangs[i],j=lastxy;
147 j>=0;
148 y++,x++,--j) {
149 yblasted[yy[j] = (y+YSIZE00) % YSIZE] |= 1;
150 xblasted[xx[j] = (x+XSIZE00) % XSIZE] |= 1;
151 }
152 blasted = TRUE;
153 for (y=lastxy;y>=0;--y) {
154 for (x=lastxy;x>=0;--x) {
155 if (lastxy > 2) {
156 j = abs(y-bangs[i]);
157 k = abs(x-bangs[i]);
158 if (j < k) /* distance is long + 1/2 short */
159 j += k + k;
160 else
161 j += j + k;
162 if (--j > lastxy)
163 continue;
164 }
165 if (bangm[i] != 32767 ||
166 !(obj=occupant[yy[y]][xx[x]]) || obj->type != Web)
167 blast[yy[y]][xx[x]] += bangm[i];
168 }
169 }
170 }
171 }
172