summaryrefslogtreecommitdiffstats
path: root/warp/bang.c
blob: fa2cdeac9c4c5b53dfc7fd7df97df5763fa1ca3a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* $Header: /cvsroot/src/games/warp/bang.c,v 1.1 2020/11/09 23:37:05 kamil Exp $ */

/* $Log: bang.c,v $
/* Revision 1.1  2020/11/09 23:37:05  kamil
/* Add Warp Kit, Version 7.0 by Larry Wall
/*
/* Warp is a real-time space war game that doesn't get boring very quickly.
/* Read warp.doc and the manual page for more information.
/*
/* games/warp originally distributed with 4.3BSD-Reno, is back to the BSD
/* world via NetBSD. Its remnants were still mentioned in games/Makefile.
/*
/* Larry Wall, the original author and the copyright holder, generously
/* donated the game and copyright to The NetBSD Foundation, Inc.
/*
/* Import the game sources as-is from 4.3BSD-Reno, with the cession
/* of the copyright and license to BSD-2-clause NetBSD-style.
/*
/* Signed-off-by: Larry Wall <larry@wall.org>
/* Signed-off-by: Kamil Rytarowski <kamil@netbsd.org>
/*
 * Revision 7.0.1.3  86/12/12  16:57:00  lwall
 * Made circular explosions.
 * 
 * Revision 7.0.1.2  86/10/20  14:36:02  lwall
 * Picked some lint.
 * 
 * Revision 7.0.1.1  86/10/16  10:49:45  lwall
 * Added Damage.  Fixed random bugs.
 * 
 * Revision 7.0  86/10/08  15:11:57  lwall
 * Split into separate files.  Added amoebas and pirates.
 * 
 */

#include "EXTERN.h"
#include "warp.h"
#include "object.h"
#include "move.h"
#include "sig.h"
#include "term.h"
#include "them.h"
#include "INTERN.h"
#include "bang.h"

void
bang_init()
{
    ;
}

void
make_plink(y,x)
Reg1 int x;
Reg2 int y;
{
    Reg3 OBJECT *obj;

    move(y+1,x*2,0);
    beg_qwrite();
    *filler = '@';
    qwrite();
    obj = occupant[y][x];
    if (obj) {
	if (numamoebas && obj->image == ' ')
	    qaddc(amb[y][x]);
	else
	    qaddc(obj->image);
    }
    else if (numamoebas)
	qaddc(amb[y][x]);
    else
	qaddspace();
    end_qwrite();
}

void
make_blast(y,x,mass,size)
Reg1 int x;
Reg2 int y;
int size;
long mass;
{
    bangy[nxtbang] = y;
    bangx[nxtbang] = x;
    bangm[nxtbang] = mass;
    bangs[nxtbang++] = size;
    assert(nxtbang <= XSIZE * YSIZE);
    if (numamoebas && amb[y][x] == '~') {
	if (mass > 10000)
	    modify_amoeba(y,x,1,'~', 10);
	else if (mass > 100)
	    modify_amoeba(y,x,1,'~', 5);
	bangs[nxtbang-1] = 0;		/* don't propagate */
	return;
    }
    else if (mass >= 0) {
	Reg3 OBJECT *obj;

	move(y+1,x*2,0);
	beg_qwrite();
	*filler = '@';
	qwrite();
	*filler = '#';
	qwrite();
	*filler = '@';
	qwrite();
	*filler = '#';
	qwrite();
	*filler = '@';
	qwrite();
	obj = occupant[y][x];
	if (obj) {
	    if (numamoebas && obj->image == ' ')
		qaddc(amb[y][x]);
	    else
		qaddc(obj->image);
	}
	else if (numamoebas)
	    qaddc(amb[y][x]);
	else
	    qaddspace();
	end_qwrite();
    }
}

void
do_bangs()
{
    Reg1 int x;
    Reg2 int y;
    Reg3 int i;
    Reg4 int j;
    Reg7 int k;
    Reg5 int lastxy;
    Reg6 OBJECT *obj;

    /* read blast list and update blast array */
    assert(nxtbang >= 0 && nxtbang <= XSIZE * YSIZE);
    for (i=0; i<nxtbang; i++) {
	if (bangm[i] != 32767)
	    bangm[i] *= 4;
	lastxy = bangs[i] << 1;
	if (lastxy >= MAXBDIST)
	    lastxy = MAXBDIST - 1;
	for (y=bangy[i]-bangs[i],x=bangx[i]-bangs[i],j=lastxy;
	  j>=0;
	  y++,x++,--j) {
	    yblasted[yy[j] = (y+YSIZE00) % YSIZE] |= 1;
	    xblasted[xx[j] = (x+XSIZE00) % XSIZE] |= 1;
	}
	blasted = TRUE;
	for (y=lastxy;y>=0;--y) {
	    for (x=lastxy;x>=0;--x) {
		if (lastxy > 2) {
		    j = abs(y-bangs[i]);
		    k = abs(x-bangs[i]);
		    if (j < k)		/* distance is long + 1/2 short */
			j += k + k;
		    else
			j += j + k;
		    if (--j > lastxy)
			continue;
		}
		if (bangm[i] != 32767 ||
		  !(obj=occupant[yy[y]][xx[x]]) || obj->type != Web)
		    blast[yy[y]][xx[x]] += bangm[i];
	    }
	}
    }
}