-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
npc.lisp
860 lines (766 loc) · 33 KB
/
npc.lisp
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
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
(in-package #:org.shirakumo.fraf.kandria)
(defclass npc-block-zone (ephemeral resizable sized-entity collider creatable)
((name :initform NIL)))
(defclass map-block-zone (ephemeral resizable sized-entity collider creatable)
((name :initform NIL)))
(define-shader-entity npc (inventory ai-entity animatable ephemeral dialog-entity profile)
((bsize :initform (vec 8 15))
(target :initform NIL :accessor target)
(companion :initform NIL :accessor companion)
(walk :initform NIL :accessor walk)
(lead-interrupt :initform (@ default-lead-interrupt) :accessor lead-interrupt)
(nametag-element :initform NIL :accessor nametag-element)))
(defmethod initialize-instance :after ((npc npc) &key)
(unless (nametag-element npc)
(setf (nametag-element npc) (make-instance 'nametag-element :value npc))))
(defmethod update-instance-for-different-class :before ((npc npc) (cur ai-entity) &key)
(unless (typep cur 'npc)
(when (nametag-element npc)
(hide (nametag-element npc)))))
(defmethod print-object ((npc npc) stream)
(print-unreadable-object (npc stream :type T)
(format stream "~s ~s" (state npc) (ai-state npc))))
(defmethod description ((npc npc))
(language-string 'talk-to))
(defmethod leave :after ((npc npc) (container container))
(when (nametag-element npc)
(hide (nametag-element npc))))
(defmethod (setf nametag) :after (tag (npc npc))
(when (nametag-element npc)
(alloy:mark-for-render (nametag-element npc))))
(defmethod capable-p ((npc npc) (edge jump-node)) T)
(defmethod primary-npc-p ((npc npc)) NIL)
(defmethod visible-on-map-p ((npc npc))
(let ((chunk (chunk npc)))
(and (primary-npc-p npc)
chunk
(unlocked-p chunk))))
(defmethod subregion ((entity located-entity))
;; KLUDGE: This is pretty bad lmao.
(let ((y (vy (location entity))))
(flet ((try (name result)
(let ((unit (node name +world+)))
(when (and unit (< (- (vy (location unit)) (vy (bsize unit))) y))
result))))
(or (try 'hub-station 'surface)
(try 'chunk-5637 'region1)
(try 'chunk-5576 'region2)
(try 'chunk-6017 'region3)))))
(define-unit-resolver-methods subregion (unit))
(defmethod description ((npc npc))
(language-string 'npc))
(defmethod movement-speed ((npc npc))
(case (state npc)
(:crawling (p! crawl))
(:climbing (p! climb-up))
(T (if (walk npc)
(p! slowwalk-limit)
(p! walk-limit)))))
(defmethod interactable-p ((npc npc))
(and (case (state npc)
(:normal T)
(:animated (eql 'idle (name (animation npc)))))
(= 0 (vx (velocity npc)))
(call-next-method)))
(defmethod interact :after ((thing npc) (player player))
(let ((pos (v+ (location thing) (vec (* 16 (direction thing)) 0))))
(when (and (null (scan-collision-for player +world+ pos))
(not (null (scan-collision-for player +world+ (v+ pos (vec 0 -16))))))
(move-to pos player)
(setf (pending-direction player) (- (direction thing))))))
(defmethod base-health ((npc npc))
1000)
(defmethod hurt ((npc npc) amount) NIL)
(defmethod hurt ((npc npc) (player player)))
(defmethod is-collider-for ((npc npc) (enemy enemy)) NIL)
(defmethod is-collider-for ((enemy enemy) (npc npc)) NIL)
(defmethod is-collider-for ((npc npc) (elevator elevator)) NIL)
(defmethod collides-p ((npc npc) (enemy enemy) hit) NIL)
(defmethod die ((npc npc))
(transition
:kind :black
(show-panel 'early-end-screen :message (language-string 'critical-npc-death-ending))))
(defmethod oob ((npc npc) (none null))
(warn "~a fell out of the world, TPing to player." npc)
(setf (location npc) 'player))
(defmethod target-blocked-p ((entity located-entity))
(do-fitting (entity (bvh (region +world+)) entity)
(when (typep entity 'npc-block-zone)
(return T))))
(defmethod target-blocked-p ((location vec2))
(do-fitting (entity (bvh (region +world+)) location)
(when (typep entity 'npc-block-zone)
(return T))))
(defmethod (setf state) :before (state (npc npc))
(unless (eq state (state npc))
(case state
(:crawling
(setf (vy (bsize npc)) 7)
(decf (vy (location npc)) 8)))
(case (state npc)
(:crawling
(incf (vy (location npc)) 8)
(setf (vy (bsize npc)) 15)))))
(defmethod (setf ai-state) :after (state (npc npc))
(when (and (nametag-element npc) (not (eql state :normal)))
(hide (nametag-element npc))))
(defmethod handle :before ((ev tick) (npc npc))
(case (state npc)
(:normal
(let ((vel (velocity npc)))
(setf (vy vel) (max (- (p! slowfall-limit)) (vy vel)))))))
(defmethod handle :after ((ev tick) (npc npc))
(let ((vel (velocity npc))
(collisions (collisions npc)))
(setf (playback-direction npc) +1)
(setf (playback-speed npc) 1.0)
(case (state npc)
(:climbing
(setf (animation npc) 'climb)
(cond
((< (vy vel) 0)
(setf (playback-direction npc) -1)
(setf (playback-speed npc) 1.5))
((= 0 (vy vel))
(setf (clock npc) 0.0))))
(:crawling
(cond ((< 0 (vx vel))
(setf (direction npc) +1))
((< (vx vel) 0)
(setf (direction npc) -1)))
(setf (animation npc) 'crawl)
(when (= 0 (vx vel))
(setf (clock npc) 0.0)))
(:normal
(cond ((< 0 (vx vel))
(setf (direction npc) +1))
((< (vx vel) 0)
(setf (direction npc) -1)))
(cond ((< 0 (vy vel))
(setf (animation npc) 'jump))
((null (svref collisions 2))
(cond ((< (air-time npc) 0.1))
((typep (svref collisions 1) 'ground)
(setf (animation npc) 'fall)
(setf (direction npc) +1)
(when (< (clock npc) 0.01)
(trigger 'slide npc :direction -1)))
((typep (svref collisions 3) 'ground)
(setf (animation npc) 'fall)
(setf (direction npc) -1)
(when (< (clock npc) 0.01)
(trigger 'slide npc :direction +1)))
(T
(ignore-errors
(setf (animation npc) 'fall)))))
((< (p! slowwalk-limit) (abs (vx vel)))
(setf (playback-speed npc) (/ (abs (vx vel)) (movement-speed npc)))
(setf (animation npc) 'run))
((< 0 (abs (vx vel)))
(setf (playback-speed npc) (/ (abs (vx vel)) (movement-speed npc)))
(setf (animation npc) 'walk))
;; KLUDGE: Ugh.
((not (eql :sit (ai-state npc)))
(setf (animation npc) 'stand)))))
(cond ((eql (name (animation npc)) 'slide)
(harmony:play (// 'sound 'slide)))
(T
(harmony:stop (// 'sound 'slide))))))
(defmethod handle-ai-states ((npc npc) ev)
;; KLUDGE: Apparently this can be nilled out?
(let ((companion (or (companion npc) (u 'player)))
(min-distance (* 2 +tile-size+))
(max-distance (* 5 +tile-size+)))
(case (ai-state npc)
(:normal
(when (path npc)
(execute-path npc ev))
(when (and (setting :gameplay :display-hud)
(nametag-element npc))
(if (< (vsqrdistance (location npc) (location (node 'player T))) (expt min-distance 2))
(show (nametag-element npc))
(hide (nametag-element npc)))))
(:move-to
(cond ((path npc)
(execute-path npc ev))
((< (vsqrdistance (location npc) (target npc)) (expt min-distance 2))
(setf (ai-state npc) :normal))
;; Retry if not too far
((< (vsqrdistance (location npc) (target npc)) (expt (* 20 +tile-size+) 2))
(move-to (target npc) npc))
(T
(place-on-ground npc (target npc))
(stop-following npc))))
(:lead
(let ((distance (vsqrdistance (location npc) (location companion))))
(flet ((complete ()
(setf (companion npc) NIL)
(setf (path npc) ())
(setf (ai-state npc) :normal)))
(cond ((and (< (expt (* 20 +tile-size+) 2) distance)
(not (eq (chunk npc) (chunk companion))))
(setf (ai-state npc) :lead-check))
((< (vsqrdistance (location npc) (target npc)) (expt min-distance 2))
(complete))
((null (path npc))
(unless (move-to (target npc) npc)
(cond ((~= (vx (location npc)) (vx (target npc)) 16)
(complete))
(T
(cerror "Clear the lead" "What the fuck? Don't know how to get to ~a from ~a" (target npc) (location npc))
(stop-following npc)))))
(T
(execute-path npc ev))))))
(:lead-check
(let ((distance (vsqrdistance (location npc) (location companion))))
(cond ((< distance (expt (* 10 +tile-size+) 2))
(interrupt-walk-n-talk NIL)
(setf (ai-state npc) :lead))
((close-to-path-p (location companion) (path npc) max-distance)
(interrupt-walk-n-talk NIL)
(setf (ai-state npc) :lead-teleport))
((path npc)
(setf (path npc) NIL)
(setf (gethash 'npc (name-map +world+)) npc)
(when (setting :gameplay :display-hud)
(show (make-instance 'quest-indicator :target npc)))
(interrupt-walk-n-talk (lead-interrupt npc))))))
(:lead-teleport
(setf (path npc) NIL)
(setf (state npc) :normal)
(cond ((not (svref (collisions companion) 2)))
((target-blocked-p companion)
(setf (gethash 'npc (name-map +world+)) npc)
(walk-n-talk (@ unsafe-region-interrupt))
(setf (ai-state npc) :lead-check))
(T
(vsetf (location npc)
(vx (location companion))
(+ (vy (location companion)) 4))
(if (move-to (target npc) npc)
(setf (ai-state npc) :lead)
(setf (ai-state npc) :lead-check)))))
(:follow
(let ((distance (vsqrdistance (location npc) (location companion))))
(cond ((< distance (expt max-distance 2))
(setf (vx (velocity npc)) 0)
(setf (path npc) NIL))
((path npc)
(execute-path npc ev))
(T
(setf (ai-state npc) :follow-check)))))
(:follow-check
(let ((distance (vsqrdistance (location npc) (location companion))))
(cond ((target-blocked-p companion)
;; TODO: make it customisable.
(setf (gethash 'npc (name-map +world+)) npc)
(walk-n-talk (@ unsafe-region-interrupt))
(setf (vx (velocity npc)) 0)
(setf (ai-state npc) :follow-wait)
(setf (state npc) :normal))
((< distance (expt (* 3 +tile-size+) 2))
(setf (ai-state npc) :follow))
((and (< (expt (* 40 +tile-size+) 2) distance)
(not (eq (chunk npc) (chunk companion))))
;; TODO: shout where are you, then timer it.
(setf (ai-state npc) :follow-teleport))
((= 0 (mod (fc ev) 100))
(when (move-to companion npc)
(setf (ai-state npc) :follow))))))
(:follow-teleport
;; TODO: Smart-teleport: search for places just outside view of the companion from
;; which the companion is reachable
(setf (path npc) NIL)
(setf (state npc) :normal)
(cond ((not (typep (svref (collisions companion) 2) 'block)))
((target-blocked-p companion)
(setf (gethash 'npc (name-map +world+)) npc)
(walk-n-talk (@ unsafe-region-interrupt))
(setf (ai-state npc) :follow-wait))
(T
(vsetf (location npc)
(vx (location companion))
(+ (vy (location companion)) 4))
(setf (ai-state npc) :follow))))
(:follow-wait
(let ((distance (vsqrdistance (location npc) (location companion))))
(when (and (< distance (expt (* 3 +tile-size+) 2))
(not (target-blocked-p companion)))
(setf (ai-state npc) :follow))))
(:cowering
(cond ((enemies-present-p (location npc))
(unless (find (state npc) '(:animated :stunned :dying))
(start-animation 'cower npc)))
((target npc)
(setf (state npc) :normal)
(lead (companion npc) (target npc) npc))
((companion npc)
(setf (state npc) :normal)
(follow (companion npc) npc)))))))
#++
(defmethod hurt :after ((npc npc) (enemy enemy))
(setf (state npc) :cowering))
(defmethod follow ((target located-entity) (npc npc))
(setf (walk npc) NIL)
(setf (path npc) NIL)
(setf (current-node npc) NIL)
(setf (companion npc) target)
(setf (ai-state npc) :follow))
(defmethod stop-following ((npc npc))
(setf (path npc) NIL)
(setf (companion npc) NIL)
(setf (target npc) NIL)
(setf (ai-state npc) :normal))
(defmethod lead (target (goal located-entity) npc)
(lead target (vcopy (location goal)) npc))
(defmethod lead ((target located-entity) (goal vec2) (npc npc))
(setf (walk npc) NIL)
(setf (path npc) NIL)
(setf (current-node npc) NIL)
(setf (target npc) goal)
(setf (companion npc) target)
(setf (ai-state npc) :lead))
(defmethod move-to :after ((target vec2) (npc npc))
(when (eql :normal (ai-state npc))
(setf (target npc) target)
(setf (ai-state npc) :move-to)))
(defmethod move :after (kind (npc npc) &key)
(setf (ai-state npc) :normal))
(defun place-to-reach (target entity)
(let ((test (in-view-tester (camera +world+)))
(tentative-path NIL))
(flet ((try (location)
(place-on-ground entity location)
(when (move-to target entity)
(when (or (null tentative-path)
(< (length (path entity)) (length tentative-path)))
(setf tentative-path (path entity))))))
(try (vec (vx test) (vy target)))
(try (vec (vz test) (vy target)))
(if tentative-path
(setf (path entity) tentative-path)
(place-on-ground entity target)))))
(defun ensure-nearby (place-thing &rest entities)
(let* ((place (ensure-unit place-thing))
(loc (location place))
(bsize (bsize place)))
(dolist (entity-thing entities)
(let ((entity (ensure-unit entity-thing)))
(cond ((null entity)
(v:warn :kandria "Trying to set ~a nearby ~a, but it could not be found!"
entity-thing place-thing))
((nearby-p place entity))
((not (in-view-p loc bsize))
(place-on-ground entity loc (vx bsize) (vy bsize)))
((typep entity 'npc)
;; Don't teleport if we're already visible and have a path.
(or (and (in-view-p (location entity) (bsize entity))
(move-to loc entity))
(progn
(case (ai-state entity)
((:follow :follow-check :follow-teleport :follow-wait)
(place-to-reach loc entity)
(setf (ai-state entity) :follow-check))
((:lead :lead-check :lead-teleport)
(setf (ai-state entity) :lead-check))
(T
(stop-following entity)
(place-to-reach loc entity)))
(setf (state entity) :normal))))
(T
(place-on-ground entity loc (vx bsize) (vy bsize))))))))
(define-shader-entity roaming-npc (npc)
((roam-time :initform (random* 5.0 2.0) :accessor roam-time)))
(defmethod interact :before ((entity roaming-npc) from)
;; KLUDGE: to make each npc act as the canonical npc from the dialogue
(setf (gethash 'npc (name-map +world+)) entity))
(defmethod move-to :after ((target vec2) (npc roaming-npc))
(setf (target npc) target)
(setf (walk npc) NIL)
(setf (state npc) :normal)
(setf (ai-state npc) :move-to))
(defmethod collides-p ((npc roaming-npc) (block stopper) hit)
(and (not (eql :move-to (ai-state npc)))
(chunk npc)
(not (eql 2 (car (tile (tv- (hit-location hit) #.(vec 0 16))
(chunk npc)))))))
(defmethod minimum-idle-time ((npc roaming-npc)) 5)
(defmethod idleable-p ((npc roaming-npc))
(and (call-next-method)
(eq :normal (ai-state npc))))
(defun crowding-level (npc)
(let* ((crowding-level 0.0)
(center (vx (location npc)))
(region (tvec (- center (* +tile-size+ 100))
(- (vy (location npc)) 32)
(+ center (* +tile-size+ 100))
(+ (vy (location npc)) 32))))
(do-fitting (entity (bvh (region +world+)) region crowding-level)
(when (and (not (eq entity npc)) (typep entity 'npc))
(let* ((dist (- (vx (location entity)) center))
(gauss (* (/ (* 4 (sqrt (* 2 PI)))) (exp (* -0.5 (/ (* dist dist) 16))))))
(incf crowding-level gauss))))))
(defun crowd-direction (npc)
(let* ((direction 0.0)
(center (vx (location npc)))
(region (tvec (- center (* +tile-size+ 100))
(- (vy (location npc)) 32)
(+ center (* +tile-size+ 100))
(+ (vy (location npc)) 32))))
(do-fitting (entity (bvh (region +world+)) region direction)
(when (and (not (eq entity npc)) (typep entity 'npc))
(let* ((dist (- (vx (location entity)) center)))
(when (<= 0.1 (abs dist))
(incf direction (* (expt (abs dist) -1.1) (float-sign dist)))))))))
(defmethod handle-ai-states ((npc roaming-npc) ev)
(when (and (setting :gameplay :display-hud)
(nametag-element npc))
(if (< (vsqrdistance (location npc) (location (node 'player T))) (expt 64 2))
(show (nametag-element npc))
(hide (nametag-element npc))))
(when (eql :normal (state npc))
(let* ((speed (movement-speed npc))
(avg-time 2.0)
(dt (dt ev))
(time (if (svref (collisions npc) 2)
(decf (roam-time npc) dt)
(roam-time npc)))
(vel (velocity npc)))
(flet ((normalize ()
(setf (roam-time npc) (random* 30 15))
(cond ((< 0.5 (random 1.0))
(setf (ai-state npc) :normal))
((find-animation 'sit npc NIL)
(setf (ai-state npc) :sit)
(setf (animation npc) 'sit))
(T
(setf (ai-state npc) :normal))))
(move-towards (target-vel)
(cond ((< 0 (vx vel))
(setf (direction npc) +1))
((< (vx vel) 0)
(setf (direction npc) -1)))
(when (< (vx vel) target-vel)
(incf (vx vel) (* dt 1)))
(when (< target-vel (vx vel))
(decf (vx vel) (* dt 1)))))
(case (ai-state npc)
(:normal
(when (svref (collisions npc) 2)
(setf (vx vel) 0.0))
(when (<= time 0.0)
(let ((level (crowding-level npc)))
(cond ((<= 0.3 level)
(setf (ai-state npc) :crowded)
(setf (walk npc) (< 0.1 (random 1.0)))
(setf (direction npc) (floor (float-sign (random* 0.0 1.0))))
(setf (roam-time npc) (random* (+ 0.5 level) 0.5)))
(T
(setf (ai-state npc) :lonely)
(setf (walk npc) (< 0.1 (random 1.0)))
(let ((dir (crowd-direction npc)))
(setf (direction npc) (floor (float-sign (if (<= dir 1) (random* 0.0 1.0) dir)))))
(setf (roam-time npc) (random* avg-time 1.0)))))))
(:sit
(setf (animation npc) 'sit)
(when (<= time 0.0)
(start-animation 'stand-up npc)
(setf (ai-state npc) :normal)))
(:lonely
(when (svref (collisions npc) (if (< 0 (direction npc)) 1 3))
(setf (direction npc) (* -1 (direction npc))))
(move-towards (* speed (direction npc)))
(cond ((<= time 0.0)
(normalize))
((<= time 0.5)
(let ((level (crowding-level npc)))
(cond ((<= 0.2 level)
(normalize))
(T
(let ((dir (crowd-direction npc)))
(setf (direction npc) (floor (float-sign (if (<= dir 1) (random* 0.0 1.0) dir)))))))))))
(:crowded
(move-towards (* speed (direction npc)))
(when (svref (collisions npc) (if (< 0 (direction npc)) 1 3))
(setf (vx vel) 0))
(cond ((<= time 0.0)
(normalize))))
(T
(call-next-method)))))))
(define-unit-resolver-methods (setf lead-interrupt) (thing unit))
(define-unit-resolver-methods (setf walk) (thing unit))
(define-unit-resolver-methods follow (unit unit))
(define-unit-resolver-methods stop-following (unit))
(define-unit-resolver-methods lead (unit unit unit))
;; PRIMARY NPCs
(define-shader-entity fi (npc creatable)
((name :initform 'fi)
(profile-sprite-data :initform (asset 'kandria 'fi-profile))
(nametag :initform (@ fi-nametag))
(pitch :initform 0.97))
(:default-initargs
:sprite-data (asset 'kandria 'fi)))
(defmethod primary-npc-p ((npc fi)) T)
(define-shader-entity catherine (npc creatable)
((name :initform 'catherine)
(profile-sprite-data :initform (asset 'kandria 'catherine-profile))
(nametag :initform (@ catherine-nametag))
(pitch :initform 1.02)
(lead-interrupt :initform (@ catherine-lead-interrupt)))
(:default-initargs
:sprite-data (asset 'kandria 'catherine)))
(defmethod primary-npc-p ((npc catherine)) T)
(defmethod stage :after ((npc catherine) (area staging-area))
(stage (// 'sound 'ambience-welding) area))
(defmethod movement-speed ((catherine catherine))
(* 1.01 (call-next-method)))
(defmethod capable-p ((catherine catherine) (edge crawl-node)) T)
(defmethod capable-p ((catherine catherine) (edge climb-node)) T)
(define-shader-entity jack (npc creatable)
((name :initform 'jack)
(profile-sprite-data :initform (asset 'kandria 'jack-profile))
(nametag :initform (@ jack-nametag))
(pitch :initform 0.95))
(:default-initargs
:sprite-data (asset 'kandria 'jack)))
(defmethod primary-npc-p ((npc jack)) T)
(defmethod movement-speed ((jack jack))
(* 0.8 (call-next-method)))
(defmethod (setf animation) ((_ (eql 'run)) (jack jack))
(setf (animation jack) 'walk))
(define-shader-entity trader (npc creatable)
((name :initform 'trader)
(profile-sprite-data :initform (asset 'kandria 'sahil-profile))
(nametag :initform (@ trader-nametag)))
(:default-initargs
:sprite-data (asset 'kandria 'sahil)))
(defmethod primary-npc-p ((npc trader)) T)
(define-shader-entity innis (npc creatable)
((name :initform 'innis)
(profile-sprite-data :initform (asset 'kandria 'innis-profile))
(nametag :initform (@ innis-nametag)))
(:default-initargs
:sprite-data (asset 'kandria 'innis)))
(defmethod primary-npc-p ((npc innis)) T)
(define-shader-entity islay (npc creatable)
((name :initform 'islay)
(profile-sprite-data :initform (asset 'kandria 'islay-profile))
(nametag :initform (@ islay-nametag)))
(:default-initargs
:sprite-data (asset 'kandria 'islay)))
(defmethod primary-npc-p ((npc islay)) T)
(define-shader-entity alex (npc creatable)
((name :initform 'alex)
(profile-sprite-data :initform (asset 'kandria 'alex-profile))
(nametag :initform (@ alex-nametag))
(pitch :initform 1.01))
(:default-initargs
:sprite-data (asset 'kandria 'alex)))
(defmethod primary-npc-p ((npc alex)) T)
(define-shader-entity paletted-npc (paletted-entity npc)
())
;; QUEST NPCs (don't roam)
(define-shader-entity synthesis (npc creatable)
((name :initform 'synthesis)
(profile-sprite-data :initform (asset 'kandria 'synthesis-profile))
(nametag :initform (@ unknown-nametag)))
(:default-initargs
:sprite-data (asset 'kandria 'synthesis)))
(define-shader-entity vinny (npc creatable)
((name :initform 'vinny)
(profile-sprite-data :initform (asset 'kandria 'vinny-profile))
(nametag :initform (@ unknown-nametag)))
(:default-initargs
:sprite-data (asset 'kandria 'vinny)))
(define-shader-entity cerebat-trader-quest (npc creatable)
((name :initform 'cerebat-trader-quest)
(profile-sprite-data :initform (asset 'kandria 'cerebat-trader-profile))
(nametag :initform (@ unknown-nametag)))
(:default-initargs
:sprite-data (asset 'kandria 'cerebat-trader)))
;; non-roaming engineer used in the questline
(define-shader-entity semi-engineer (npc creatable)
((name :initform 'semi-engineer)
(profile-sprite-data :initform (asset 'kandria 'engineer-profile))
(nametag :initform (@ unknown-nametag)))
(:default-initargs
:sprite-data (asset 'kandria 'villager-engineer)))
;; used for various sidequest NPCs, name set in the quest
(define-shader-entity villager-male (paletted-npc creatable)
((profile-sprite-data :initform (asset 'kandria 'villager-profile))
(nametag :initform (@ unknown-nametag))
(palette :initform (// 'kandria 'villager-male-palette))
(palette-index :initform 0))
(:default-initargs
:sprite-data (asset 'kandria 'villager-male)))
;; used for various sidequest NPCs, name set in the quest
(define-shader-entity villager-female (paletted-npc creatable)
((profile-sprite-data :initform (asset 'kandria 'villager-profile))
(nametag :initform (@ unknown-nametag))
(palette :initform (// 'kandria 'villager-female-palette))
(palette-index :initform 0))
(:default-initargs
:sprite-data (asset 'kandria 'villager-female)))
;; used for sidequest NPCs
(define-shader-entity npc-hunter (npc creatable)
((name :initform 'npc-hunter)
(profile-sprite-data :initform (asset 'kandria 'villager-profile))
(nametag :initform (@ hunter-nametag)))
(:default-initargs
:sprite-data (asset 'kandria 'villager-hunter)))
;; wraw drill sergeant (combat races)
(define-shader-entity npc-soldier (paletted-npc creatable)
((profile-sprite-data :initform (asset 'kandria 'villager-profile))
(nametag :initform (@ unknown-nametag))
(palette :initform (// 'kandria 'rogue-palette))
(palette-index :initform 0))
(:default-initargs
:sprite-data (asset 'kandria 'rogue)))
;; zombie template (sq4a)
(define-shader-entity npc-zombie (paletted-npc creatable)
((profile-sprite-data :initform (asset 'kandria 'villager-profile))
(nametag :initform (@ unknown-nametag))
(palette :initform (// 'kandria 'zombie-palette))
(palette-index :initform 0))
(:default-initargs
:sprite-data (asset 'kandria 'zombie)))
;; WORLD NPCs (they roam)
(define-shader-entity villager-hunter (roaming-npc creatable)
((name :initform (generate-name "HUNTER"))
(profile-sprite-data :initform (asset 'kandria 'villager-profile))
(nametag :initform (alexandria:random-elt (append (@ villager-female-nametags) (@ villager-male-nametags)))))
(:default-initargs
:default-interaction 'npc
:sprite-data (asset 'kandria 'villager-hunter)))
(define-shader-entity villager (paletted-npc roaming-npc)
((name :initform (generate-name "VILLAGER"))
(profile-sprite-data :initform (asset 'kandria 'villager-profile))
(nametag :initform (@ villager-nametag)))
(:default-initargs
:default-interaction 'npc))
(defmethod shared-initialize :after ((villager villager) slots &key)
(case (random 2)
(0
(setf (slot-value villager 'trial:sprite-data) (asset 'kandria 'villager-male))
;;(setf (slot-value villager 'profile-sprite-data) (asset 'kandria 'villager-male-profile))
(setf (palette villager) (// 'kandria 'villager-male-palette))
(setf (nametag villager) (alexandria:random-elt (@ villager-male-nametags))))
(1
(setf (slot-value villager 'trial:sprite-data) (asset 'kandria 'villager-female))
;;(setf (slot-value villager 'profile-sprite-data) (asset 'kandria 'villager-female-profile))
(setf (palette villager) (// 'kandria 'villager-female-palette))
(setf (nametag villager) (alexandria:random-elt (@ villager-female-nametags)))))
(setf (palette-index villager) (random 4)))
(defmethod stage :after ((villager villager) (area staging-area))
(stage (// 'kandria 'villager-male-palette) area)
(stage (// 'kandria 'villager-female-palette) area)
(stage (// 'kandria 'villager-male 'vertex-array) area)
(stage (// 'kandria 'villager-male 'texture) area)
(stage (// 'kandria 'villager-female 'vertex-array) area)
(stage (// 'kandria 'villager-female 'texture) area))
;; trader world NPCs (don't roam - don't have walk animation, and consistent with traders staying put)
(define-shader-entity cerebat-trader (npc creatable)
((name :initform (generate-name "TRADER"))
(profile-sprite-data :initform (asset 'kandria 'villager-profile))
(nametag :initform (alexandria:random-elt (append (@ villager-female-nametags) (@ villager-male-nametags)))))
(:default-initargs
:default-interaction 'npc
:sprite-data (asset 'kandria 'sahil)))
;; ZELAH special enemy
(define-shader-entity zelah (npc creatable)
((name :initform 'zelah)
(profile-sprite-data :initform (asset 'kandria 'zelah-profile))
(nametag :initform (@ zelah-nametag))
(level :initform 40)
(bsize :initform (vec 6 15)))
(:default-initargs :sprite-data (asset 'kandria 'zelah)))
(defmethod stage :after ((enemy zelah) (area staging-area))
(dolist (asset '(human-damage-1 human-damage-2 human-damage-3 human-damage-4
human-die))
(stage (// 'sound asset) area)))
(defmethod hurt ((npc zelah) (player player))
(walk-n-talk (@ zelah-attack-start))
(override-music 'battle)
(change-class npc 'zelah-enemy))
;; soldier template (used for some minor quest NPCs e.g. Zelah's bodyguards)
(define-shader-entity soldier (paletted-npc creatable)
((profile-sprite-data :initform (asset 'kandria 'villager-profile))
(nametag :initform (@ unknown-nametag))
(palette :initform (// 'kandria 'rogue-palette))
(palette-index :initform 0))
(:default-initargs
:default-interaction 'soldier
:sprite-data (asset 'kandria 'rogue)))
(defmethod hurt ((npc soldier) (player player))
(hurt (u 'zelah) (u 'player))
(change-class npc 'rogue))
;; roaming engineers used in the questline
(define-shader-entity semi-engineer-team (roaming-npc creatable)
((name :initform (generate-name "ENGINEER"))
(profile-sprite-data :initform (asset 'kandria 'engineer-profile))
(nametag :initform (alexandria:random-elt (append (@ villager-female-nametags) (@ villager-male-nametags)))))
(:default-initargs
:default-interaction 'semi-engineer-team
:sprite-data (asset 'kandria 'villager-engineer)))
;; engineer world NPCs
(define-shader-entity semi-engineer-base (roaming-npc creatable)
((name :initform (generate-name "ENGINEER"))
(profile-sprite-data :initform (asset 'kandria 'engineer-profile))
(nametag :initform (alexandria:random-elt (append (@ villager-female-nametags) (@ villager-male-nametags)))))
(:default-initargs
:default-interaction 'semi-engineer-base
:sprite-data (asset 'kandria 'villager-engineer)))
(define-random-draw bar
(villager 1.0)
(villager-hunter 0.3)
(semi-engineer-base 0.2)
(cerebat-trader 0.1)
(tame-wolf 0.1)
(tame-cat 0.1))
(define-random-draw semi
(villager 0.5)
(villager-hunter 0.1)
(semi-engineer-base 0.2)
(cerebat-trader 0.1)
(tame-wolf 0.1)
(tame-cat 0.1))
(define-random-draw cerebats
(villager 1.5)
(villager-hunter 0.75)
(cerebat-trader 1.0)
(tame-wolf 0.2)
(tame-cat 0.2))
(define-price-variants trader
(consumable-item)
;; EG: Fish get you 2x money if you sell, and cost 3x base price to buy back.
(fish :sell 2.0 :buy 3.0)
(scrap :sell 0.5 :buy 1.0)
(electronics :sell 1.0 :buy 5.0)
(ores :sell 1.5 :buy 1.5)
(liquids :sell 2.0 :buy 2.0)
(skins :sell 1.5 :buy 2.0)
(T :sell 1.0 :buy 1.0))
(define-price-variants islay
(consumable-item)
(fish :sell 0.5 :buy 1.0)
(scrap :sell 1.0 :buy 1.0)
(electronics :sell 3.0 :buy 4.0)
(ores :sell 0.5 :buy 1.5)
(liquids :sell 1.0 :buy 1.0)
(skins :sell 0.5 :buy 1.0)
(T :sell 1.0 :buy 1.0))
(define-price-variants cerebat-trader-quest
(consumable-item)
(fish :sell 0.3 :buy 0.5)
(scrap :sell 1.5 :buy 1.5)
(electronics :sell 1.0 :buy 2.0)
(ores :sell 1.0 :buy 2.0)
(liquids :sell 0.5 :buy 1.0)
(skins :sell 1.0 :buy 2.0)
(T :sell 1.0 :buy 1.0))
(define-price-variants vinny
(item:mushroom-good-1 :sell 2.0 :buy 3.0)
(item:mushroom-good-2 :sell 2.0 :buy 3.0)
(item:mushroom-bad-1 :sell 2.0 :buy 3.0)
(fish:shroomfish :sell 2.0 :buy 3.0)
(T :sell 0.2 :buy 3.0))