-
Notifications
You must be signed in to change notification settings - Fork 12
/
combat.zap
310 lines (271 loc) · 6.93 KB
/
combat.zap
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
.SEGMENT "0"
.FUNCT STRENGTH:ANY:3:3,CHR,TBL,OFF,?TMP1
GETB TBL,OFF >?TMP1
GETP CHR,P?STATUS
MUL ?TMP1,STACK
DIV STACK,100
RSTACK
.FUNCT END-COMBAT:ANY:0:1,DAMAGE
ASSIGNED? 'DAMAGE /?CND1
SET 'DAMAGE,TRUE-VALUE
?CND1: ZERO? DAMAGE /?CND3
CRLF
CRLF
ICALL1 DAMAGE-REPORT
?CND3: ICALL2 SCENE,FALSE-VALUE
ICALL2 MODE,TRAVEL-MODE
SET 'UPDATE-FLAG,TRUE-VALUE
RETURN UPDATE-FLAG
.FUNCT SURPRISE-COMBAT:ANY:0:0
CALL1 V-COMBAT
RSTACK
.FUNCT V-COMBAT:ANY:0:0,OFF,CMD,CHR,TOS,TDS,OOS,ODS,TBL
INC 'COMBAT-ROUND
GETPT OPPONENT,P?ATTACK >TBL
CALL STRENGTH,OPPONENT,TBL,COMBAT-COS >OOS
CALL STRENGTH,OPPONENT,TBL,COMBAT-CDS >ODS
SET 'OFF,0
?PRG1: IGRTR? 'OFF,PARTY-MAX /?REP2
GET PARTY,OFF >CHR
GETPT CHR,P?ATTACK >TBL
CALL STRENGTH,CHR,TBL,COMBAT-COS
ADD TOS,STACK >TOS
CALL STRENGTH,CHR,TBL,COMBAT-CDS
ADD TDS,STACK >TDS
JUMP ?PRG1
?REP2: PUT COMBAT-STRENGTHS,CS-PARTY-OFFENSE,TOS
PUT COMBAT-STRENGTHS,CS-PARTY-DEFENSE,TDS
PUT COMBAT-STRENGTHS,CS-OPPONENT-OFFENSE,OOS
PUT COMBAT-STRENGTHS,CS-OPPONENT-DEFENSE,ODS
ICALL2 SCENE-ACTION,STRENGTH-COMMAND
ICALL1 DESCRIBE-COMBAT
RTRUE
.FUNCT SCENE-ACTION:ANY:1:1,CMD
SET 'ACTION,CMD
GETP SCENE-OBJECT,P?ACTION
CALL STACK
RSTACK
.FUNCT ADD-PARTY-DEFENSE:ANY:1:1,NUM
GET COMBAT-STRENGTHS,CS-PARTY-DEFENSE
ADD STACK,NUM
PUT COMBAT-STRENGTHS,CS-PARTY-DEFENSE,STACK
RTRUE
.FUNCT ADD-PARTY-OFFENSE:ANY:1:1,NUM
GET COMBAT-STRENGTHS,CS-PARTY-OFFENSE
ADD STACK,NUM
PUT COMBAT-STRENGTHS,CS-PARTY-OFFENSE,STACK
RTRUE
.FUNCT COMBAT-RESULT:ANY:2:2,OS,DS
MUL OS,10
DIV STACK,DS
DIV STACK,4
CALL MIN,STACK,5
RSTACK
.FUNCT MIN:ANY:2:2,M,N
GRTR? N,M \?CCL3
RETURN M
?CCL3: RETURN N
.FUNCT DESCRIBE-COMBAT:ANY:0:0,NOTELL?,TOS,TDS,OOS,ODS,ORES,DRES,TMP
GET COMBAT-STRENGTHS,CS-PARTY-OFFENSE >TOS
GET COMBAT-STRENGTHS,CS-PARTY-DEFENSE >TDS
GET COMBAT-STRENGTHS,CS-OPPONENT-OFFENSE >OOS
GET COMBAT-STRENGTHS,CS-OPPONENT-DEFENSE >ODS
ZERO? DEBUG /?CND1
PRINTI "Off: "
PRINTN TOS
PRINTC 47
PRINTN ODS
PRINTI " Def: "
PRINTN TDS
PRINTC 47
PRINTN OOS
?CND1: CALL COMBAT-RESULT,TOS,ODS >OFFENSIVE-RESULT
CALL COMBAT-RESULT,OOS,TDS >DEFENSIVE-RESULT
CALL2 SCENE-ACTION,COMBAT-RESULT-COMMAND >NOTELL?
ZERO? NOTELL? \?CND3
ZERO? COMBAT-ROUND \?CCL7
PRINTI "Our party initially took an aggressive"
PRINTI " stance against the "
ICALL2 WPRINTD,OPPONENT
PRINTI ", who themselves were in "
MUL OOS,10
DIV STACK,ODS
DIV STACK,4
CALL MIN,STACK,8
GET AGGRESSION-TBL,STACK
PRINT STACK
PRINTI " posture."
JUMP ?CND5
?CCL7: PRINTI "We maintained our stance, as did the "
ICALL2 WPRINTD,OPPONENT
PRINTC 46
?CND5: PRINTI " The fighting was fierce, with "
ADD OFFENSIVE-RESULT,DEFENSIVE-RESULT
ZERO? STACK \?CCL10
PRINTI "neither side hurt in the slightest"
JUMP ?CND8
?CCL10: EQUAL? OFFENSIVE-RESULT,DEFENSIVE-RESULT \?CCL12
PRINTI "both sides suffering "
GET COMBAT-RESULT-TBL,OFFENSIVE-RESULT
PRINT STACK
PRINTI " injuries in what was, at best, a stand-off"
JUMP ?CND8
?CCL12: GRTR? OFFENSIVE-RESULT,DEFENSIVE-RESULT \?CCL14
PRINTI "the "
ICALL2 WPRINTD,OPPONENT
PRINTC 32
GRTR? DEFENSIVE-RESULT,3 \?CCL17
PRINTI "getting the worse beating, though we ourselves were bloodied considerably"
JUMP ?CND8
?CCL17: GRTR? OFFENSIVE-RESULT,3 \?CCL19
PRINTI "taking a beating at our hands, while we escaped with minor injury"
JUMP ?CND8
?CCL19: PRINTI "and ourselves each scoring a few hits, though we clearly had the upper hand"
JUMP ?CND8
?CCL14: PRINTI "our party "
GRTR? OFFENSIVE-RESULT,3 \?CCL22
PRINTI "suffering major injury; I suppose it was some consolation that we did a good deal of damage ourselves"
JUMP ?CND8
?CCL22: GRTR? DEFENSIVE-RESULT,3 \?CCL24
PRINTI "taking some major hits, and giving not as many back"
JUMP ?CND8
?CCL24: PRINTI "faring a bit worse than our opponent, though neither side had clearly gained the upper hand"
?CND8: PRINTC 46
?CND3: GRTR? DEFENSIVE-RESULT,0 \?CND25
ICALL DAMAGE-PARTY,DEFENSIVE-RESULT,NOTELL?
?CND25: GRTR? OFFENSIVE-RESULT,0 \TRUE
ICALL DAMAGE-OPPONENT,OFFENSIVE-RESULT,NOTELL?
RTRUE
.FUNCT DAMAGE-OPPONENT:ANY:2:2,ORES,NOTELL?,NST,TT,?TMP1
GETP OPPONENT,P?STATUS >?TMP1
GET OPPONENT-DAMAGE-TBL,ORES
MUL ?TMP1,STACK
DIV STACK,100 >NST
PUTP OPPONENT,P?STATUS,NST
GETP OPPONENT,P?RETREAT
LESS? NST,STACK \FALSE
CRLF
GETP OPPONENT,P?SPECIAL-ACTION
CALL STACK >?TMP1
ZERO? ?TMP1 /?CCL5
RETURN ?TMP1
?CCL5: CRLF
PRINTI "The "
ICALL2 WPRINTD,OPPONENT
PRINTI ", badly hurt, retreated out of sight. We had won the battle!"
CALL1 END-COMBAT
RSTACK
.FUNCT DAMAGE-PARTY:ANY:2:2,DRES,NOTELL?,OFF,DOFF,DTBL,DMAX,?TMP2
SET 'DOFF,1
ICALL1 DAMAGE-ORDER
GET DAMAGE-TBL,DRES >DTBL
GET DTBL,0 >DMAX
?PRG1: GRTR? DOFF,DMAX /?REP2
GRTR? DOFF,PARTY-MAX /?REP2
GET COMBAT-DAMAGE,OFF >?TMP2
GET DTBL,DOFF
ICALL DAMAGE-CHARACTER,?TMP2,STACK
ADD OFF,2 >OFF
INC 'DOFF
JUMP ?PRG1
?REP2: SET 'DOFF,0
SET 'OFF,100
SET 'DMAX,0
?PRG8: IGRTR? 'DOFF,PARTY-MAX /?REP9
GET PARTY,DOFF
GETP STACK,P?STATUS >DTBL
LESS? DTBL,OFF \?PRG8
SET 'DMAX,DOFF
SET 'OFF,DTBL
JUMP ?PRG8
?REP9: ZERO? NOTELL? \TRUE
CALL1 PARTY-STATUS >DOFF
LESS? DOFF,60 \FALSE
CRLF
CRLF
PRINTI "Our party was badly wounded, though still able to fight. ""Let's get out of here,"" I cried, ""before we're killed!"""
RTRUE
.FUNCT DAMAGE-STATUS:ANY:1:1,CHR
GETP CHR,P?STATUS
DIV STACK,20
GET DAMAGE-STATUS-TBL,STACK
RSTACK
.FUNCT DAMAGE-REPORT:ANY:0:0,OFF,CHR
PRINTI "The battle concluded, we took a moment to check on our condition. It appeared that "
?PRG1: IGRTR? 'OFF,PARTY-MAX \?CCL5
PRINTC 46
RTRUE
?CCL5: GET PARTY,OFF >CHR
EQUAL? CHR,TAG \?CCL8
PRINTC 73
JUMP ?CND6
?CCL8: ICALL2 WPRINTD,CHR
?CND6: PRINTI " was "
CALL2 DAMAGE-STATUS,CHR
PRINT STACK
SUB PARTY-MAX,1
EQUAL? OFF,STACK \?CCL11
PRINTI ", and "
JUMP ?PRG1
?CCL11: EQUAL? OFF,PARTY-MAX /?PRG1
PRINTI ", "
JUMP ?PRG1
.FUNCT DAMAGE-CHARACTER:ANY:2:2,CHR,TYP,NST
GETP CHR,P?STATUS
MUL TYP,STACK
DIV STACK,100 >NST
PUTP CHR,P?STATUS,NST
ZERO? DEBUG /FALSE
CRLF
PRINTI "Damage to "
ICALL2 WPRINTD,CHR
PRINTI ", status:"
PRINTN NST
RTRUE
.FUNCT PARTY-STATUS:ANY:0:0,CNT,SUM
?PRG1: IGRTR? 'CNT,PARTY-MAX /?REP2
GET PARTY,CNT
GETP STACK,P?STATUS
ADD SUM,STACK >SUM
JUMP ?PRG1
?REP2: DIV SUM,PARTY-MAX
RSTACK
.FUNCT DAMAGE-ORDER:ANY:0:0,POFF,DOFF,CHR,TBL,TMP,?TMP2
?PRG1: IGRTR? 'POFF,PARTY-MAX /?REP2
GET PARTY,POFF >CHR
PUT COMBAT-DAMAGE,DOFF,CHR
GETPT CHR,P?ATTACK >TBL
ADD DOFF,1 >?TMP2
CALL STRENGTH,CHR,TBL,COMBAT-CDS
PUT COMBAT-DAMAGE,?TMP2,STACK
ADD DOFF,2 >DOFF
JUMP ?PRG1
?REP2: MUL PARTY-MAX,2
CALL PAIR-SORT,COMBAT-DAMAGE,STACK
RSTACK
.FUNCT PAIR-SORT:ANY:2:2,TBL,MAX,OFF,T1,T2,TT,FLG,?TMP2
?PRG1: ADD OFF,3
GRTR? STACK,MAX \?CND3
ZERO? FLG /TRUE
SET 'OFF,0
SET 'FLG,FALSE-VALUE
?CND3: ADD OFF,1
GET TBL,STACK >?TMP2
ADD OFF,3
GET TBL,STACK
GRTR? ?TMP2,STACK \?CND8
SET 'FLG,TRUE-VALUE
MUL OFF,2
ADD TBL,STACK >TT
GET TT,0 >T1
GET TT,1 >T2
GET TT,2
PUT TT,0,STACK
GET TT,3
PUT TT,1,STACK
PUT TT,2,T1
PUT TT,3,T2
?CND8: ADD OFF,2 >OFF
JUMP ?PRG1
.ENDSEG
.ENDI