-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzapspell.pp
493 lines (415 loc) · 11.7 KB
/
zapspell.pp
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
unit zapspell;
{This unit handles two distinct things: Spells and Item}
{effects.}
interface
uses crt,rpgdice,rpgtext,rpgmenus,texmodel,texmaps,texfx,statusfx,spells,critters,dcchars,gamebook,dccombat,looker,plotbase;
Procedure ProcessSpell(SC: ScenarioPtr; S: SpellDescPtr);
Function CastSpell(SC: ScenarioPtr; UseMenu: Boolean): Boolean;
implementation
Const
BColor = Blue;
IColor = LightMagenta;
SColor = Magenta;
MX1 = 16;
MY1 = 5;
MX2 = 65;
MY2 = 17;
DY1 = 17;
DY2 = 21;
Function ShootAttack(SC: ScenarioPtr; S: SpellDescPtr): Boolean;
{This spell shoots something, just like a missile attack.}
var
TP: Point;
AR: AttackRequest;
begin
DCAppendMessage('Select Target: ');
TP := SelectPoint(SC,True,True,SC^.PC^.Target);
{Check to make sure a target was selected, and also}
{the the player isn't trying to shoot himself.}
if TP.X = -1 then Exit(False);
if (TP.X = SC^.PC^.M^.X) and (TP.Y = SC^.PC^.M^.Y) then Exit(False);
AR.HitRoll := S^.P1;
AR.Damage := S^.Step;
AR.Range := S^.P2;
AR.Attacker := SC^.PC^.M;
AR.Tx := TP.X;
AR.TY := TP.Y;
AR.DF := DF_Mystic;
AR.C := S^.C;
AR.ATT := S^.Att;
AR.Desc := S^.cdesc;
ProcessAttack(SC,AR);
ShootAttack := True;
end;
Function CloseAttack(SC: ScenarioPtr; S: SpellDescPtr): Boolean;
{This spell zaps something, just like a melee attack.}
var
D,Err: Integer;
AR: AttackRequest;
begin
DCAppendMessage('Direction?');
{Select a direction. Make sure an appropriate direction was chosen.}
Val(RPGkey,D,Err);
if (Err <> 0) or (D = 5) then Exit(False);
AR.HitRoll := S^.P1;
AR.Damage := S^.Step;
AR.Range := -1;
AR.Attacker := SC^.PC^.M;
AR.Tx := SC^.PC^.M^.X + VecDir[D,1];
AR.TY := SC^.PC^.M^.Y + VecDir[D,2];
AR.DF := DF_Mystic;
AR.C := S^.C;
AR.ATT := S^.Att;
AR.Desc := S^.cdesc;
ProcessAttack(SC,AR);
CloseAttack := True;
end;
Function Residual(SC: ScenarioPtr; S: SpellDescPtr): Boolean;
{Add a residual type to the PC's status list.}
begin
SetNAtt( SC^.PC^.SF , NAG_StatusChange , S^.Step , S^.P1 * 10 );
{Just in case this is a FarSight type spell, do an update.}
if S^.Step = SEF_VisionBonus then begin
SC^.gb^.pov.range := PCVisionRange(SC^.PC);
UpdatePOV(SC^.gb^.POV,SC^.gb);
ApplyPOV(SC^.gb^.POV,SC^.gb);
end;
{Display message.}
if S^.Step >= 0 then DCAppendMessage('Done.')
else DCAppendMessage('You are '+LowerCase(NegSFName[Abs(S^.Step)])+'!');
Residual := True;
end;
Function Healing(SC: ScenarioPtr; S: SpellDescPtr): Boolean;
{Restore HP to the PC.}
var
dhp: integer; {Delta HP}
msg: string;
begin
dhp := SC^.PC^.HP;
{Restore HP; make sure it doesn't go over HPMax.}
SC^.PC^.HP := SC^.PC^.HP + RollStep(S^.Step);
if SC^.PC^.HP > SC^.PC^.HPMax then SC^.PC^.HP := SC^.PC^.HPMax;
PCStatLine(SC);
dhp := SC^.PC^.HP - dhp;
Str(dhp,msg);
msg := msg + ' hit points restored.';
DCAppendMessage(msg);
Healing := True;
end;
Function MagicMap(SC: ScenarioPtr; S: SpellDescPtr): Boolean;
{Go through every map tile within range. If the tile is}
{a floor, and the % chance is rolled, reveal that tile.}
var
X,Y: Integer;
begin
for X := (SC^.PC^.M^.X-S^.P1) to (SC^.PC^.M^.X+S^.P1) do begin
for Y := (SC^.PC^.M^.Y-S^.P1) to (SC^.PC^.M^.Y+S^.P1) do begin
if OnTheMap(X,Y) then begin
{Only terrain which is within the cutoff range may be sensed.}
if (TerrPass[GetTerr(SC^.gb,X,Y)]>=S^.P2) and (Random(100)<S^.Step) then begin
SC^.gb^.map[X,Y].visible := True;
end;
end;
end;
end;
DCAppendMessage('You sense distant locations.');
DisplayMap(SC^.gb);
MagicMap := True;
end;
Function StatAttack(SC: ScenarioPtr; S: SpellDescPtr): Boolean;
{Affect every enemy model within range with a given}
{status change condition.}
var
itworked: Boolean;
X,Y: Integer;
C: CritterPtr;
V: Integer;
begin
itworked := false;
{Determine the accuracy of the attack, also its Value and}
{Duration. Use defaults if these values can't be found.}
V := RollStep( AAVal(S^.ATT,AA_Value) );
if V < 5 then V := 5;
for X := (SC^.PC^.M^.X-S^.P1) to (SC^.PC^.M^.X+S^.P1) do begin
for Y := (SC^.PC^.M^.Y-S^.P1) to (SC^.PC^.M^.Y+S^.P1) do begin
if ModelPresent(SC^.gb^.mog,X,Y) then begin
C := LocateCritter(FindModelXY(SC^.gb^.mlist,X,Y),SC^.CList);
if C <> Nil then begin
if RollStep(S^.P2) > RollStep(MonMan[C^.Crit].Mystic) then begin
if SetCritterStatus( C , S^.Step , v ) then begin
MapSplat(SC^.gb,'*',S^.C,X,Y,False);
itworked := true;
end;
end;
end;
end;
end;
end;
if itworked then begin
DCAppendMessage('Done.');
Delay(FrameDelay);
DisplayMap(SC^.gb);
{Give the PC a few points for successfully using}
{this spell.}
DoleExperience(SC,Random(3));
end else DCAppendMessage('Failed!');
StatAttack := True;
end;
Function CureStatus(SC: ScenarioPtr; S: SpellDescPtr): Boolean;
{Cure the PC of status S.}
begin
if NAttValue( SC^.PC^.SF , NAG_StatusChange , S^.Step ) = 0 then begin
DCAppendMessage('No effect!');
CureStatus := False;
end else begin
SetNAtt( SC^.PC^.SF , NAG_StatusChange , S^.Step , 0 );
DCAppendMessage('Cured!');
CureStatus := True;
PCStatLine( SC );
end;
end;
Function Teleport(SC: ScenarioPtr; S: SpellDescPtr): Boolean;
{Allow the player to teleport, either randomly or}
{controlledly.}
Function GoodSpot(X,Y: Integer): Boolean;
{Check spot X,Y and see if this is a good place to}
{teleport to.}
var
it: Boolean;
begin
if TerrPass[sc^.gb^.map[X,Y].terr] < 1 then it := False
else if SC^.gb^.mog[X,Y] then it := False
else it := True;
GoodSpot := it;
end;
var
X,Y,D,Tries: Integer;
begin
{Select destination point.}
Tries := 0;
repeat
D := Random(8)+1;
if D > 4 then Inc(D);
X := SC^.PC^.M^.X + VecDir[D,1]*S^.Step + Random(5)-Random(5);
Y := SC^.PC^.M^.Y + VecDir[D,2]*S^.Step + Random(5)-Random(5);
Inc(Tries);
until OnTheMap(X,Y) or (Tries = 5);
if OnTheMap(X,Y) then begin
while (tries < 1000) and not GoodSpot(X,Y) do begin
Inc(Tries);
X := X + Random(10) - Random(10);
if X > XMax then X := XMax
else if X < 1 then X := 1;
Y := Y + Random(10) - Random(10);
if Y > YMax then Y := YMax
else if Y < 1 then Y := 1;
end;
if GoodSpot(X,Y) then begin
MoveModel(SC^.PC^.M,SC^.gb,X,Y);
DCAppendMessage('Done.');
end else DCAppendMessage('Failed.');
end else begin
DCAppendMessage('Failed!');
end;
Teleport := True;
end;
Function SenseAura(SC: ScenarioPtr; S: SpellDescPtr): Boolean;
{The PC gets to see every monster currently on screen.}
var
M: ModelPtr;
success: Boolean;
begin
ClearMapArea;
success := false;
{Scan through every model in the list, looking for models}
{to display.}
M := SC^.gb^.mlist;
while M <> Nil do begin
if OnTheScreen(SC^.gb,M^.X,M^.Y) and (M^.Kind = S^.Step) then begin
MapSplat(SC^.gb,M^.gfx,M^.color,M^.X,M^.Y,True);
success := true;
end;
M := M^.Next;
end;
if success then
DCAppendMessage('Done.')
else
DCAppendMessage('Failed.');
GamePause;
{Restore the map display.}
DisplayMap(SC^.gb);
SenseAura := True;
end;
Procedure ProcessSpell(SC: ScenarioPtr; S: SpellDescPtr);
{The PC is invoking spell S. This may be through psi}
{powers or through the use of an item. Whatever the case,}
{determine the results.}
begin
Case S^.eff of
EFF_ShootAttack: ShootAttack(SC,S);
EFF_CloseAttack: CloseAttack(SC,S);
EFF_Residual: Residual(SC,S);
EFF_Healing: Healing(SC,S);
EFF_MagicMap: MagicMap(SC,S);
EFF_StatAttack: StatAttack(SC,S);
EFF_CureStatus: CureStatus(SC,S);
EFF_Teleport: Teleport(SC,S);
EFF_SenseAura: SenseAura(SC,S);
end;
end;
Procedure SetQuickLink(SC: ScenarioPtr; SCode: Integer);
{Assign a letter to one of the PC's spells, for quick}
{casting later.}
const
instr: PChar = 'Select a letter to represent this spell.';
qmerr: PChar = 'Invalid character.';
var
S: SpellMemPtr;
C: Char;
begin
{Display instructions}
GameMessage(instr,MX1,MY2,MX2,MY2+2,IColor,BColor);
C := RPGKey;
if (Upcase(C) >= 'A') and (Upcase(C) <= 'Z') then begin
{Make sure no other spellmem has this key linked.}
S := SC^.PC^.Spell;
while S <> Nil do begin
if S^.mnem = C then S^.mnem := ' ';
S := S^.Next;
end;
S := LocateSpellMem(SC^.PC^.Spell,SCode);
if S <> Nil then begin
S^.mnem := C;
end;
end else begin
GameMessage(qmerr,MX1,MY2,MX2,MY2+2,IColor,BColor);
ReadKey;
end;
end;
Function ChooseSpell(SC: ScenarioPtr): Integer;
{Create a menu from the PC's spell list. Query for a spell.}
{Return whatever spell was chosen, or -1 for Cancel.}
const
instr: PChar = '[SPACE] to cast, [/] to quickmark';
QMval = -10;
var
RPM: RPGMenuPtr;
S: SpellMemPtr;
it: Integer;
begin
DCPointMessage(' which spell?');
repeat
{Display instructions}
GameMessage(instr,MX1,DY2,MX2,DY2+2,IColor,BColor);
{Create the menu.}
RPM := CreateRPGMenu(BColor,SColor,IColor,MX1,MY1,MX2,MY2);
RPM^.DX1 := MX1;
RPM^.DY1 := DY1;
RPM^.DX2 := MX2;
RPM^.DY2 := DY2;
AddRPGMenuKey(RPM,'/',QMval);
S := SC^.PC^.Spell;
while S <> Nil do begin
if S^.mnem = ' ' then
AddRPGMenuItem(RPM,SpellMan[S^.code].Name,S^.code,SpellMan[S^.code].Desc)
else begin
AddRPGMenuItem(RPM,SpellMan[S^.code].Name + ' ['+S^.mnem+']',S^.code,SpellMan[S^.code].Desc);
AddRPGMenuKey(RPM,S^.mnem,S^.code);
end;
S := S^.Next;
end;
RPMSortAlpha(RPM);
{Make a menu selection.}
it := SelectMenu(RPM,RPMNoCleanup);
{Check to see if the PC wants to QuickMark a spell.}
if it = QMval then begin
SetQuickLink(SC,RPMLocateByPosition(RPM,RPM^.selectitem)^.value);
end;
DisposeRPGMenu(RPM);
until it <> QMval;
{Redisplay the map.}
DisplayMap(SC^.GB);
DCPointMessage(' ');
ChooseSpell := it;
end;
Function QuickSpell(SC: ScenarioPtr): Integer;
{Locate a spell based on its quicklink char.}
var
A: Char;
it: Integer;
S: SpellMemPtr;
begin
DCPointMessage(' which spell? [a-z/A-Z] code, or [*] for menu');
A := RPGKey;
DCPointMessage(' ');
if A = '*' then
it := ChooseSpell(SC)
else if (Upcase(A) >= 'A') and (Upcase(A) <= 'Z') then begin
it := -1;
S := SC^.PC^.Spell;
while S <> Nil do begin
if S^.mnem = A then it := S^.code;
S := S^.Next;
end;
end else begin
it := -1;
end;
QuickSpell := it;
end;
Function CastSpell(SC: ScenarioPtr; UseMenu: Boolean): Boolean;
{The PC wants to use a psychic ability. Select one of the}
{character's powers and then process it.}
var
S: Integer; {The spell being cast.}
M: Integer; {Avaliable Mojo}
SD: SpellDesc;
begin
{Exit immediately if the player has no spells or no mojo.}
if (SC^.PC^.Spell = Nil) or (SC^.PC^.MP < 1) then Exit(False);
DCGameMessage('Invoke');
{Choose a spell}
if UseMenu then
S := ChooseSpell(SC)
else
S:= QuickSpell(SC);
{If the menu selection wasn't cancelled...}
if S <> -1 then begin
{reduce mojo by appropriate amount.}
M := SC^.PC^.MP;
SC^.PC^.MP := SC^.PC^.MP - SpellMan[S].Cost;
if SC^.PC^.MP < 0 then SC^.PC^.MP := 0;
if Random(SpellMan[S].Cost) < M then begin
{Fill in the SpellDesc record with spell data + PC stats}
SD := SpellMan[S];
DCAppendMessage(SD.Name+' - ');
{Alter SD for PC's stats depending upon type of spell.}
case SpellMan[S].Eff of
EFF_ShootAttack,EFF_CloseAttack: begin
SD.Step := SD.Step + PCPsiForce(SC^.PC);
SD.P1 := SD.P1 + PCPsiSkill(SC^.PC);
end;
EFF_Residual: begin
SD.P2 := SD.P2 + PCPsiForce(SC^.PC);
end;
EFF_Healing: begin
SD.Step := SD.Step + PCPsiForce(SC^.PC);
end;
EFF_MagicMap: begin
SD.Step := SD.Step + PCPSiForce(SC^.PC);
end;
EFF_StatAttack: begin
SD.P2 := SD.P2 + PCPsiSkill(SC^.PC);
end;
end;
{process the spell.}
ProcessSpell(SC,@SD);
end else begin
{Spellcasting failed due to a lack of Mojo.}
DCAppendMessage('Failed!');
end;
PCStatLine(SC);
end;
{Return TRUE if a spell was selected, FALSE if Cancel was selected.}
CastSpell := S <> -1;
end;
end.