-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathInterface3D.bb
More file actions
4456 lines (4065 loc) · 160 KB
/
Interface3D.bb
File metadata and controls
4456 lines (4065 loc) · 160 KB
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
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Global WContextMenu = 0
Global BInteract = 0
Global BAttack = 0
Global BExamine = 0
Global BTrade = 0
; Alphabetically sorted list of abilities
Dim KnownSpellSort(999)
; Creates a text input window and returns the handle
Function CreateTextInput(Title$, Prompt$, Numeric, ScriptHandle)
TI.TextInput = New TextInput
TI\ScriptHandle = ScriptHandle
TI\Win = GY_CreateWindow(Title$, 0.3, 0.55, 0.5, 0.17, True, False, True)
PromptLabel = GY_CreateLabel(TI\Win, 0.05, 0.2, Prompt$)
Gad.GY_Gadget = Object.GY_Gadget(PromptLabel)
Width# = GY_TextWidth#(Gad\EN, Prompt$)
TI\TextBox = GY_CreateTextField(TI\Win, Width# + 0.1, 0.2, 0.85 - Width#, Numeric, 150)
TI\AcceptButton = GY_CreateButton(TI\Win, 0.75, 0.7, 0.2, 0.18, LanguageString$(LS_Accept))
GY_GadgetAlpha(TI\Win, 1.0)
;GY_GadgetAlpha(TI\Win, 0.75)
GY_ActivateWindow(TI\Win)
GY_ActivateTextField(TI\TextBox)
InDialog = True
Return Handle(TI)
End Function
; Frees a text input dialog and all gadgets
Function FreeTextInput(Han)
TI.TextInput = Object.TextInput(Han)
If TI <> Null
GY_FreeGadget(TI\Win)
Delete(TI)
EndIf
End Function
; Creates a dialog window and returns the handle
Function CreateDialog(Title$, A.ActorInstance, ScriptHandle, BackgroundTexID = 65535)
; Play speech if applicable
If A <> Null Then PlayActorSound(A, Rand(Speech_Greet1, Speech_Greet2))
; Create dialog
D.Dialog = New Dialog
D\ActorInstance = A
D\ScriptHandle = ScriptHandle
If BackgroundTexID < 65535
D\Win = GY_CreateWindow(Title$, 0.02, 0.15, 0.32, 0.5, True, False, False, GetTexture(BackgroundTexID), False)
Else
D\Win = GY_CreateWindow(Title$, 0.02, 0.15, 0.32, 0.5, True, False, False)
EndIf
Y# = 0.07
For i = 0 To 13
D\TextLines[i] = GY_CreateLabel(D\Win, 0.02, Y#, String$(" ", 75)) ;75
GY_UpdateLabel(D\TextLines[i], "")
GY_DropGadget(D\TextLines[i])
Y# = Y# + 0.05
Next
GY_GadgetAlpha(D\Win, 1.0) ;0.75
GY_ActivateWindow(D\Win)
InDialog = True
Return Handle(D)
End Function
; Frees a dialog and everything in it
Function FreeDialog(Han)
D.Dialog = Object.Dialog(Han)
If D <> Null
; Play speech if applicable
If D\ActorInstance <> Null Then PlayActorSound(D\ActorInstance, Rand(Speech_Bye1, Speech_Bye2))
; Free dialog
GY_FreeGadget(D\Win)
Delete(D)
EndIf
End Function
; Adds an option to a dialog
Function AddDialogOption(Han, Opt$)
D.Dialog = Object.Dialog(Han)
If D <> Null
D\TotalOptions = D\TotalOptions + 1
DialogOutput(Han, Opt$, 0, 255, 0, D\TotalOptions)
EndIf
End Function
; Adds text to a dialog
Function DialogOutput(Han, T$, R = 255, G = 255, B = 255, Opt = 0)
D.Dialog = Object.Dialog(Han)
; Stale dialog handle: server can send P_Dialog "T" / "O" against
; a dialog the client has already freed (window-close race, dialog
; reuse). The unguarded D\TextLines[0] deref below was a crash on
; the next message in that flow.
If D = Null Then Return
; Word wrap
Gad.GY_Gadget = Object.GY_Gadget(D\TextLines[0])
If GY_TextWidth#(Gad\EN, T$) >= 0.4
For i = Len(T$) To 1 Step -1
If Mid$(T$, i, 1) = " "
If GY_TextWidth#(Gad\EN, Left$(T$, i - 1)) < 0.4
DialogOutput(Han, Left$(T$, i - 1), R, G, B, Opt)
DialogOutput(Han, Mid$(T$, i + 1), R, G, B, Opt)
Return
EndIf
EndIf
Next
For i = Len(T$) To 1 Step -1
If GY_TextWidth#(Gad\EN, Left$(T$, i - 1)) < 0.4
DialogOutput(Han, Left$(T$, i - 1), R, G, B, Opt)
DialogOutput(Han, Mid$(T$, i), R, G, B, Opt)
Return
EndIf
Next
Return
EndIf
; Add the line
If D <> Null
If D\LastLine <= 13
GY_UpdateLabel(D\TextLines[D\LastLine], T$, R, G, B)
D\TextText$[D\LastLine] = T$
D\TextR[D\LastLine] = R
D\TextG[D\LastLine] = G
D\TextB[D\LastLine] = B
D\OptionNum[D\LastLine] = Opt
D\LastLine = D\LastLine + 1
Else
For i = 0 To 12
GY_UpdateLabel(D\TextLines[i], D\TextText$[i + 1], D\TextR[i + 1], D\TextG[i + 1], D\TextB[i + 1])
D\TextText$[i] = D\TextText$[i + 1]
D\TextR[i] = D\TextR[i + 1]
D\TextG[i] = D\TextG[i + 1]
D\TextB[i] = D\TextB[i + 1]
D\OptionNum[i] = D\OptionNum[i + 1]
Next
GY_UpdateLabel(D\TextLines[13], T$, R, G, B)
D\TextText$[13] = T$
D\TextR[13] = R
D\TextG[13] = G
D\TextB[13] = B
D\OptionNum[13] = Opt
EndIf
EndIf
End Function
; Adds a new chat message
Function Output(Dat$, R = 255, G = 255, B = 255)
; Word wrap
MaxWidth# = Chat\Width#
If Chat\X# <= 0.5 Then MaxWidth# = MaxWidth# - 0.035
Gad.GY_Gadget = Object.GY_Gadget(ChatLines(0))
If GY_TextWidth#(Gad\EN, Dat$) >= MaxWidth#
For i = Len(Dat$) To 1 Step -1
If Mid$(Dat$, i, 1) = " "
If GY_TextWidth#(Gad\EN, Left$(Dat$, i - 1)) <= MaxWidth#
Output(Left$(Dat$, i - 1), R, G, B)
Output(Mid$(Dat$, i + 1), R, G, B)
Return
EndIf
EndIf
Next
For i = Len(Dat$) To 1 Step -1
If GY_TextWidth#(Gad\EN, Left$(Dat$, i - 1)) <= MaxWidth#
Output(Left$(Dat$, i - 1), R, G, B)
Output(Mid$(Dat$, i), R, G, B)
Return
EndIf
Next
Return
EndIf
; Add to history
If MaxHistoryLine < 1999
MaxHistoryLine = MaxHistoryLine + 1
Else
For i = 0 To 1998
ChatHistory$(i) = ChatHistory$(i + 1)
ChatHistoryColour(i) = ChatHistoryColour(i + 1)
Next
EndIf
ChatHistory$(MaxHistoryLine) = Dat$
ChatHistoryColour(MaxHistoryLine) = R Or (G Shl 8) Or (B Shl 16)
; Add to current chat text
CC.CurrentChat = New CurrentChat
CC\Dat$ = Dat$
CC\cR = R
CC\cG = G
CC\cB = B
CC\Timer = MilliSecs()
; Display
UpdateChatTextDisplay()
End Function
; Creates a new chat bubble
Dim BubbleLines$(9)
Dim BubbleLinesEN(9)
Function BubbleOutput(Label$, R, G, B, AI.ActorInstance, NoText = False)
; Normal output
If NoText = False
Name$ = Trim$(AI\Name$)
If Name$ = "" Then Name$ = AI\Actor\Race$
If R = 0 And G = 0 And B = 0
Output("<" + Name$ + "> " + Label$, 255, 255, 255)
Else
Output("<" + Name$ + "> " + Label$, R, G, B)
EndIf
EndIf
; Remove any chat bubbles already attached to this actor instance.
; After-cursor walk: the body Deletes Bb, which would corrupt
; the For-Each cursor on the next iteration. Documented in
; CLAUDE.md (#247).
Local Bb.Bubble = First Bubble
Local BbNext.Bubble = Null
While Bb <> Null
BbNext = After Bb
If Bb\ActorInstance = AI
FreeEntity(Bb\EN)
Delete(Bb)
EndIf
Bb = BbNext
Wend
; Create new bubble
Bb.Bubble = New Bubble
Bb\EN = CopyMesh(ChatBubbleEN)
EntityTexture(Bb\EN, ChatBubbleTex)
EntityFX(Bb\EN, 1 + 8)
EntityAutoFade(Bb\EN, 30.0, 35.0)
Bb\ActorInstance = AI
Bb\Timer = MilliSecs()
; Split text into lines
BubbleLines$(0) = Label$
TotalLines = 1
Pos = WordWrap(Label$, 30)
While Pos > 0
BubbleLines$(TotalLines - 1) = Left$(Label$, Pos)
If TotalLines = 10
BubbleLines$(9) = Left$(BubbleLines$(9), Len(BubbleLines$(9)) - 3) + "..."
Exit
EndIf
Label$ = Mid$(Label$, Pos + 1)
BubbleLines$(TotalLines) = Label$
TotalLines = TotalLines + 1
Pos = WordWrap(Label$, 30)
Wend
Bb\Height# = 0.2 + (Float#(TotalLines) * 0.36)
; Create text
MaxWidth# = 0.0
For i = 0 To TotalLines - 1
BubbleLinesEN(i) = GY_Create3DText(0.0, 0.0, Len(BubbleLines$(i)) / 2.9, 1.0, Len(BubbleLines$(i)), ChatBubbleFont, 0, 0)
GY_Set3DText(BubbleLinesEN(i), BubbleLines$(i))
EntityAutoFade(BubbleLinesEN(i), 30.0, 35.0)
EntityColor(BubbleLinesEN(i), R, G, B)
EntityParent(BubbleLinesEN(i), Bb\EN, False)
Width# = GY_TextWidth#(BubbleLinesEN(i), BubbleLines$(i))
If Width# > MaxWidth# Then MaxWidth# = Width#
Next
Bb\Width# = MaxWidth#
; Position and scale bubble
Surf = GetSurface(Bb\EN, 1)
BorderX# = 0.15 / Bb\Width#
BorderY# = 0.15 / Bb\Height#
BorderB# = 0.28 / Bb\Height#
VertexCoords(Surf, 0, -BorderX#, -(1.0 + BorderY#), 0.0)
VertexCoords(Surf, 1, 0.0, -(1.0 + BorderY#), 0.0)
VertexCoords(Surf, 2, 1.0, -(1.0 + BorderY#), 0.0)
VertexCoords(Surf, 3, 1.0 + BorderX#, -(1.0 + BorderY#), 0.0)
VertexCoords(Surf, 4, -BorderX#, -1.0, 0.0)
VertexCoords(Surf, 7, 1.0 + BorderX#, -1.0, 0.0)
VertexCoords(Surf, 8, -BorderX#, 0.0, 0.0)
VertexCoords(Surf, 11, 1.0 + BorderX#, 0.0, 0.0)
VertexCoords(Surf, 12, -BorderX#, BorderB#, 0.0)
VertexCoords(Surf, 13, 0.0, BorderB#, 0.0)
VertexCoords(Surf, 14, 1.0, BorderB#, 0.0)
VertexCoords(Surf, 15, 1.0 + BorderX#, BorderB#, 0.0)
ScaleEntity(Bb\EN, -Bb\Width#, -Bb\Height#, 1, True)
; Position and scale text lines
For i = 0 To TotalLines - 1
ScaleEntity(BubbleLinesEN(i), Len(BubbleLines$(i)) / -2.9, 0.36, 1, True)
PositionEntity(BubbleLinesEN(i), 0, -1.0, 0)
TranslateEntity(BubbleLinesEN(i), 0, Float#(i) * -0.36, 0.05, True)
Next
End Function
; Updates all labels in the chat text display
;Turns chat text in history mode to white Cysis145
Function UpdateChatTextDisplay()
; Draw history
If HistoryMode
CurrentLine = FirstHistoryLine
For i = 0 To MaxChatLine
R = ChatHistoryColour(CurrentLine) And 255
G = (ChatHistoryColour(CurrentLine) Shr 8) And 255
B = (ChatHistoryColour(CurrentLine) Shr 16) And 255
GY_UpdateLabel(ChatLines(i), ChatHistory$(CurrentLine), R, G, B) ;R, G, B)
CurrentLine = CurrentLine + 1
If CurrentLine = MaxHistoryLine + 1
For j = i + 1 To MaxChatLine
GY_UpdateLabel(ChatLines(j), "")
Next
Exit
EndIf
If CurrentLine > 1999 Then Return
Next
; Draw current messages
Else
Count = 0
For CC.CurrentChat = Each CurrentChat
GY_UpdateLabel(ChatLines(Count), CC\Dat$, CC\cR, CC\cG, CC\cB)
Count = Count + 1
If Count > MaxChatLine Then Return
Next
For i = Count To MaxChatLine
GY_UpdateLabel(ChatLines(i), "")
Next
EndIf
End Function
; Selects the player target from the entity clicked on
Function GetTarget$(EN)
; Is it an actor instance?
AI.ActorInstance = Object.ActorInstance(EntityName$(EN))
If AI <> Null Then Return "A"
; Is it a dropped item?
D.DroppedItem = Object.DroppedItem(EntityName$(EN))
If D <> Null Then Return "D"
; Must be scenery
Return ""
End Function
; Updates the standard components and handles player input
; --- Spell cooldown helpers ------------------------------------------
; SpellCharge[] is keyed by spell ID (0..999) -- see the field comment in
; Actors.bb and the authoritative server (ServerNet.bb P_SpellUpdate "F"
; gates on AI\SpellCharge[SpellID]; GameServer.bb decrements 0..999 by
; spell ID). The client action bar and spellbook previously keyed
; SpellCharge by a KnownSpells index (action bar non-memorise / spellbook)
; or a memorise slot (action bar memorise), so the client's predictive
; cooldown lived in a different slot than the server's authority and than
; the other client surface -- casting from one surface left the other
; reading "ready" (spurious LS_AbilityNotRecharged, or a click the server
; silently drops). Centralise the spell-ID-keyed, bound-checked access so
; every client cast site matches the server.
;
; A spell ID outside 0..999 is not castable server-side (the server wraps
; its cast path in the same 0..999 guard), so treat it as "ready" here --
; the cast packet is still sent and the authoritative server is the final
; arbiter. The bound check lives in a nested If inside the helper because
; BlitzForge `And` is non-short-circuit: `If id <= 999 And arr[id] ...`
; would still evaluate arr[id] for an out-of-range id.
Function SpellChargeReady(M.ActorInstance, SpellID)
If SpellID < 0 Or SpellID > 999 Then Return True
If M\SpellCharge[SpellID] <= 0 Then Return True
Return False
End Function
Function SetSpellCharge(M.ActorInstance, SpellID, Charge)
If SpellID < 0 Or SpellID > 999 Then Return
M\SpellCharge[SpellID] = Charge
End Function
; ---------------------------------------------------------------------
Function UpdateInterface()
; Gooey system
GY_Update()
; Screenshot
If KeyHit(74)
Num = 1
While FileType("Screenshot " + Str$(Num) + ".bmp") > 0
Num = Num + 1
Wend
SaveBuffer(BackBuffer(), "Screenshot " + Str$(Num) + ".bmp")
EndIf
; Escape used both to close windows and quit the game
EscapeHit = KeyHit(1)
; Toggle always run mode
If ControlHit(Key_AlwaysRun) Then AlwaysRun = Not AlwaysRun
; Cycle target
If ControlHit(Key_CycleTarget)
StartAI.ActorInstance = Object.ActorInstance(PlayerTarget)
If StartAI = Null Then StartAI = First ActorInstance
AI.ActorInstance = StartAI
Repeat
AI = After AI
If AI = Null Then AI = First ActorInstance
If AI = StartAI Then Exit
If AI\Actor\Aggressiveness < 3 And AI\RNID = 0
OldTarget = PlayerTarget
PlayerTarget = Handle(AI)
MaxLength# = MeshWidth#(AI\EN)
If MeshDepth#(AI\EN) > MaxLength# Then MaxLength# = (MeshDepth#(AI\EN) + MeshWidth#(AI\EN)) / 2.0
ScaleEntity(ActorSelectEN, MaxLength# * 0.03, 1.0, MaxLength# * 0.03)
ShowEntity(ActorSelectEN)
AttackTarget = False
Exit
EndIf
Forever
EndIf
; Hide movement marker after time expires {@@@~}
If MilliSecs() - ClickMarkerTimer > 3000 Then HideEntity(ClickMarkerEN)
;[~~~] automatic rotation behind character if mouse button 3 is hit cysis145
If MouseHit(3) = True
CamYaw# = EntityYaw#(Me\CollisionEN)
CamPitch# = 0.0
EndIf
; Get environment type
EType = Me\Actor\Environment
If Me\Mount <> Null Then EType = Me\Mount\Actor\Environment
; Keyboard controls
If ChatEntry\Alpha# < 0.5 And First TextInput = Null
; Jump
If ControlHit(Key_Jump) And PlayerHasTouchedDown = True
If Me\Mount = Null
Me\Y# = JumpStrength# * Gravity#
PlayAnimation(Me, 3, 0.05, Anim_Jump)
PlayerHasTouchedDown = False
RCE_Send(Connection, PeerToHost, P_Jump, "", True)
EndIf
EndIf
; Change camera mode
If ControlHit(Key_ChangeViewMode) And ViewMode = 2
CamMode = Not CamMode
CamYaw# = EntityYaw#(Me\CollisionEN)
CamPitch# = 0.0
EndIf
; Walk around / Fixed Bug where the player could still move once dead Cysis145
If InDialog = False And SMemorising = 0 And Me\Attributes\Value[HealthStat] > 0
; Forward [~~~]
If ControlDown(Key_Forward)
If Me\WalkingBackward = True
If Me\Mount = Null
If CurrentSeq(Me) = Anim_Walk Then Animate(Me\EN, 0)
Else
If CurrentSeq(Me\Mount) = Anim_Walk Then Animate(Me\Mount\EN, 0)
EndIf
EndIf
Me\IsRunning = ControlDown(Key_Run) Or AlwaysRun
NewX# = EntityX#(Me\CollisionEN) + (Sin#(EntityYaw#(Me\CollisionEN)) * (KeyboardMoveDistance# * (1.0 + Float#(Me\IsRunning))))
NewZ# = EntityZ#(Me\CollisionEN) - (Cos#(EntityYaw#(Me\CollisionEN)) * (KeyboardMoveDistance# * (1.0 + Float#(Me\IsRunning))))
SetDestination(Me, NewX#, NewZ#, EntityY#(Me\CollisionEN))
;If EnergyStat > -1 And Me\Mount = Null
; If Me\Attributes\Value[EnergyStat] <= 0 Then Me\IsRunning = False
;EndIf
AttackTarget = False
; Backward [~~~]
ElseIf ControlDown(Key_Back)
If Me\WalkingBackward = False
If Me\Mount = Null
If CurrentSeq(Me) = Anim_Walk Then Animate(Me\EN, 0)
Else
If CurrentSeq(Me\Mount) = Anim_Walk Then Animate(Me\Mount\EN, 0)
EndIf
EndIf
Me\IsRunning = False ;ControlDown(Key_Run) Or AlwaysRun
NewX# = EntityX#(Me\CollisionEN) + (Sin#(EntityYaw#(Me\CollisionEN)) * (-KeyboardMoveDistance#))
NewZ# = EntityZ#(Me\CollisionEN) - (Cos#(EntityYaw#(Me\CollisionEN)) * (-KeyboardMoveDistance#))
SetDestination(Me, NewX#, NewZ#, EntityY#(Me\CollisionEN))
Me\WalkingBackward = True
If Me\Mount <> Null Then Me\Mount\WalkingBackward = True
AttackTarget = False
EndIf
; Turn right [{}] straffing code goes here.
If ControlDown(Key_TurnRight)
PositionEntity(GPP, Me\DestX#, EntityY#(Me\CollisionEN), Me\DestZ#)
EntityParent(GPP, Me\CollisionEN)
TurnEntity(Me\CollisionEN, 0, -3.0 * Delta#, 0)
EntityParent(GPP, 0)
WasBack = Me\WalkingBackward
SetDestination(Me, EntityX#(GPP), EntityZ#(GPP), EntityY#(GPP))
Me\WalkingBackward = WasBack
If Me\Mount <> Null
Me\Mount\WalkingBackward = WasBack
RotateEntity(Me\Mount\CollisionEN, 0, EntityYaw#(Me\CollisionEN), 0)
EndIf
; Turn left
ElseIf ControlDown(Key_TurnLeft)
PositionEntity(GPP, Me\DestX#, EntityY#(Me\CollisionEN), Me\DestZ#)
EntityParent(GPP, Me\CollisionEN)
TurnEntity(Me\CollisionEN, 0, 3.0 * Delta#, 0)
EntityParent(GPP, 0)
WasBack = Me\WalkingBackward
SetDestination(Me, EntityX#(GPP), EntityZ#(GPP), EntityY#(GPP))
Me\WalkingBackward = WasBack
If Me\Mount <> Null
Me\Mount\WalkingBackward = WasBack
RotateEntity(Me\Mount\CollisionEN, 0, EntityYaw#(Me\CollisionEN), 0)
EndIf
EndIf
EndIf
; Breath bar ;disabled Cysis145
;If BreathStat > -1 And Me\Actor\Environment <> Environment_Swim
; If AttributeDisplays(BreathStat)\Component <> 0
; If Me\Underwater <> 0
; GY_GadgetAlpha(AttributeDisplays(BreathStat)\Component, AttributeDisplays(BreathStat)\Alpha#)
; GY_GadgetAlpha(AttributeDisplayNumbers(BreathStat), 1.0)
; Else
; GY_GadgetAlpha(AttributeDisplays(BreathStat)\Component, 0.0)
; GY_GadgetAlpha(AttributeDisplayNumbers(BreathStat), 0.0)
; EndIf
; EndIf
;EndIf
; Flying/swimming
If EType = Environment_Fly Or Me\Underwater <> 0
; Up
If ControlDown(Key_FlyUp)
If Me\Mount = Null
TranslateEntity(Me\CollisionEN, 0.0, 0.5 * Delta#, 0.0)
Else
TranslateEntity(Me\Mount\CollisionEN, 0.0, 0.5 * Delta#, 0.0)
EndIf
; Do not allow above water surface if swimming
If Me\Underwater <> 0
W.Water = Object.Water(Me\Underwater)
If EntityY#(Me\CollisionEN) > EntityY#(W\EN) - 0.5
PositionEntity(Me\CollisionEN, EntityX#(Me\CollisionEN), EntityY#(W\EN) - 0.505, EntityZ#(Me\CollisionEN))
EndIf
EndIf
QuitActive = False
; Down
ElseIf ControlDown(Key_FlyDown)
; Do not allow below water surface if flying
Allowed = True
If Me\Underwater = 0
For W.Water = Each Water
If EntityY#(Me\CollisionEN) <= EntityY#(W\EN) + 3.0
If Abs(EntityX#(Me\CollisionEN) - EntityX#(W\EN)) < (W\ScaleX# / 2.0)
If Abs(EntityZ#(Me\CollisionEN) - EntityZ#(W\EN)) < (W\ScaleZ# / 2.0)
Allowed = False
Exit
EndIf
EndIf
EndIf
Next
EndIf
If Allowed = True
If Me\Mount = Null
TranslateEntity(Me\CollisionEN, 0.0, -0.5 * Delta#, 0.0)
Else
TranslateEntity(Me\Mount\CollisionEN, 0.0, -0.5 * Delta#, 0.0)
EndIf
QuitActive = False
EndIf
EndIf
EndIf
EndIf
; Mouselook
If MouseDown(2)
; Look left/right in first person mode (rotate character)
If CamMode = 1
PositionEntity(GPP, Me\DestX#, EntityY#(Me\CollisionEN), Me\DestZ#)
EntityParent(GPP, Me\CollisionEN)
TurnEntity(Me\CollisionEN, 0, Float#(-GY_MouseXSpeed) * Delta#, 0)
EntityParent(GPP, 0)
SetDestination(Me, EntityX#(GPP), EntityZ#(GPP), EntityY#(GPP))
Invert# = InvertAxis1
;PositionEntity(GPP, Me\DestX#, EntityY#(Me\CollisionEN), Me\DestZ#)
; EntityParent(GPP, Me\CollisionEN)
; TurnEntity(Me\CollisionEN, 0, Float#(-GY_MouseXSpeed) * 0.3, 0) ;Delta#, 0)
; EntityParent(GPP, 0)
;
; If Me\WalkingBackward = False
; SetDestination(Me, EntityX#(GPP), EntityZ#(GPP), EntityY#(GPP))
; EndIf
; Invert# = InvertAxis1
; Look left/right in third person mode (rotate camera)
Else
CamYaw# = CamYaw# - (Float#(GY_MouseXSpeed) * Delta#)
If CamYaw# < -180.0
CamYaw# = CamYaw# + 360.0
ElseIf CamYaw# > 180.0
CamYaw# = CamYaw# - 360.0
EndIf
Invert# = InvertAxis3
EndIf
; Look up/down
CamPitch# = CamPitch# - (Float#(GY_MouseYSpeed) * Delta# * Invert#)
If CamPitch# > 85.0
CamPitch# = 85.0
ElseIf CamPitch# < -70.0
CamPitch# = -70.0
EndIf
EndIf
; Camera zoom controls
; Mousewheel [~~~]
MZSpeed = MouseZSpeed()
If MZSpeed <> 0
CamDist# = CamDist# - (Float#(MZSpeed) * 1.5); * Delta#)
If CamDist# < 5.0 Then CamDist# = 5.0 ;5.0
If CamDist# > 50.0 Then CamDist# = 50.0
EndIf
; Keyboard
If ControlDown(Key_CameraIn)
CamDist# = CamDist# - Delta#
If CamDist# < 3.0 Then CamDist# = 3.0
ElseIf ControlDown(Key_CameraOut)
CamDist# = CamDist# + Delta#
If CamDist# > 50.0 Then CamDist# = 50.0
EndIf
; Update context menu if it exists
If WContextMenu <> 0
If PlayerTarget > 0
AI.ActorInstance = Object.ActorInstance(PlayerTarget)
; Handle Interact button
If GY_ButtonHit(BInteract)
If AI <> Null
If EntityDistance#(AI\CollisionEN, Me\CollisionEN) < InteractRange
RCE_Send(Connection, PeerToHost, P_RightClick, RCE_StrFromInt$(AI\RuntimeID, 2), True)
else
SetDestination(Me, EntityX#(AI\CollisionEN), EntityZ#(AI\CollisionEN), EntityY#(AI\CollisionEN))
Me\IsRunning = True
If Me\Mount <> Null Then Me\Mount\IsRunning = True
EndIf
EndIf
GY_FreeGadget(WContextMenu)
WContextMenu = 0
EndIf
; Handle Attack button
If GY_ButtonHit(BAttack)
If AI <> Null
SetDestination(Me, EntityX#(AI\CollisionEN), EntityZ#(AI\CollisionEN), EntityY#(AI\CollisionEN))
Me\IsRunning = True
If Me\Mount <> Null Then Me\Mount\IsRunning = True
AttackTarget = True
EndIf
GY_FreeGadget(WContextMenu)
WContextMenu = 0
EndIf
; Handle Examine button
If GY_ButtonHit(BExamine)
If AI <> Null
RCE_Send(Connection, PeerToHost, P_Examine, RCE_StrFromInt$(AI\RuntimeID, 2), True)
EndIf
GY_FreeGadget(WContextMenu)
WContextMenu = 0
EndIf
; Handle Trade button
If GY_ButtonHit(BTrade)
If AI <> Null
RCE_Send(Connection, PeerToHost, P_Trade, RCE_StrFromInt$(AI\RuntimeID, 2), True)
EndIf
GY_FreeGadget(WContextMenu)
WContextMenu = 0
EndIf
; Close menu if clicked outside
If MouseHit(1) And GY_MouseOverGadget = False
GY_FreeGadget(WContextMenu)
WContextMenu = 0
EndIf
else
WContextMenu = 0
EndIf
EndIf
; Update these buttons if the mouse is not over a dialog or the action bar
If GY_MouseOverGadget = False And GY_MouseY# < 0.85 And (CurrentSeq(Me) >= Anim_LookRound Or Animating(Me\EN) = False) And InDialog = False And SMemorising = 0
; Talk to button down, remember the time (so we ignore presses which take more than 500ms)
If ControlDown(Key_TalkTo)
If RightWasDown = False Then RightDownTime = MilliSecs()
RightWasDown = True
Else
RightWasDown = False
EndIf
; Talk to button was clicked
If ControlHit(Key_TalkTo) And TradingVisible = False And MilliSecs() - RightDownTime < 500
ClickedTarget = False
; Selected target actor, show interaction window.
; Stale PlayerTarget handle: clear and fall through to the
; click-target-pick branch below rather than crash on
; AI\CollisionEN.
If PlayerTarget > 0
AI.ActorInstance = Object.ActorInstance(PlayerTarget)
If AI = Null
PlayerTarget = 0
Else
If CharInteractVisible
UpdateCharInteractionWindow()
Else
CreateCharInteractionWindow( AI )
;CysisLibs Outline
;Outline ActorSelectEN
EndIf
If EntityDistance#(AI\CollisionEN, Me\CollisionEN) < InteractRange
RCE_Send(Connection, PeerToHost, P_RightClick, RCE_StrFromInt$(AI\RuntimeID, 2), True)
EndIf
QuitActive = False
ClickedTarget = True
EndIf
EndIf
If ClickedTarget = False
SetPickModes(-1, 3, True)
Result = CameraPick(Cam, MouseX(), MouseY())
If Result <> 0
Target$ = GetTarget$(Result)
; Target is an actor
If Target$ = "A"
PlayerTarget = EntityName$(Result)
AI.ActorInstance = Object.ActorInstance(PlayerTarget)
; EntityName$ resolved to a non-actor handle, or
; the actor was freed between pick and now. Drop
; the selection rather than crash on AI\EN.
If AI = Null
PlayerTarget = 0
Else
MaxLength# = MeshWidth#(AI\EN)
If MeshDepth#(AI\EN) > MaxLength# Then MaxLength# = (MeshDepth#(AI\EN) + MeshWidth#(AI\EN)) / 2.0
ScaleEntity(ActorSelectEN, MaxLength# * 0.03, 1.0, MaxLength# * 0.03)
ShowEntity(ActorSelectEN)
If CharInteractVisible
UpdateCharInteractionWindow()
ElseIf CharInteract = Null
CreateCharInteractionWindow(AI)
;CysisLibs Outline
;Outline ActorSelectEN
EndIf
; If friendly and in range, close interact window and execute right click
If AI\FactionRatings[Me\HomeFaction] > 99 And EntityDistance#(AI\CollisionEN, Me\CollisionEN) < InteractRange
RCE_Send(Connection, PeerToHost, P_RightClick, RCE_StrFromInt$(AI\RuntimeID, 2), True)
EndIf
QuitActive = False
EndIf
EndIf
EndIf
EndIf
EndIf
; Select target (actor, dropped item or usable scenery)
UsedClick = False
If ControlDown(Key_Select)
SelectKeyWasDown = True
ElseIf SelectKeyWasDown = True
; Was this a double click?
IsDouble = False
If MilliSecs() - SelectKeyClickTime < 500 Then IsDouble = True
; Store time of click
SelectKeyClickTime = MilliSecs()
SelectKeyWasDown = False
; Pick a target
SetPickModes(0, 3, True, 1)
Result = CameraPick(Cam, MouseX(), MouseY())
If Result <> 0
Target$ = GetTarget$(Result)
; Target is another actor
If Target$ = "A"
UsedClick = True
; Single or double click selects the target
OldTarget = PlayerTarget
PlayerTarget = EntityName$(Result)
AI.ActorInstance = Object.ActorInstance(PlayerTarget)
; Stale Object lookup (actor picked but freed before
; we resolved). Drop the selection rather than crash
; on AI\EN / AI\Actor / AI\FactionRatings below.
If AI = Null
PlayerTarget = 0
Goto SkipActorSelect
EndIf
MaxLength# = MeshWidth#(AI\EN)
If MeshDepth#(AI\EN) > MaxLength# Then MaxLength# = (MeshDepth#(AI\EN) + MeshWidth#(AI\EN)) / 2.0
ScaleEntity(ActorSelectEN, MaxLength# * 0.03, 1.0, MaxLength# * 0.03)
ShowEntity(ActorSelectEN)
; Double clicking the target makes you run towards it and attack if in range [~~~]
If IsDouble = True And OldTarget = PlayerTarget
SetDestination(Me, PickedX#(), PickedZ#(), PickedY#())
Me\IsRunning = True
If Me\Mount <> Null Then Me\Mount\IsRunning = True
; Disable double-clicking for attacks [ref14] ****************************
; Check target is a combatant
If AI\Actor\Aggressiveness < 3
;Check faction rating
If Me\FactionRatings[AI\HomeFaction] <= 150 Then AttackTarget = True
EndIf
;*************************************************************************
Else
If CharInteractVisible
UpdateCharInteractionWindow()
Else
CreateCharInteractionWindow(AI)
EndIf
; Create context menu
If WContextMenu <> 0
GY_FreeGadget(WContextMenu)
WContextMenu = 0
EndIf
WContextMenu = GY_CreateWindowInter("Actions", GY_MouseX#, GY_MouseY#, 0.1, 0.08, True, True, False, CreateTexture(2, 2))
Y# = 0.0
; Interact button
Local interactLabel$ = "Interact"
If EntityDistance#(AI\CollisionEN, Me\CollisionEN) > InteractRange
interactLabel$ = "Move To"
EndIf
BInteract = GY_CreateButton(WContextMenu, Y#, 0.0, 1.0, 0.33, interactLabel$, False, 255, 255, 255, LoadTexture("Data\Textures\GUI\ToolTip.png"))
Y# = Y# + 0.33
; Attack button (only if target is attackable)
If AI\Actor\Aggressiveness < 3 And Me\FactionRatings[AI\HomeFaction] <= 150
BAttack = GY_CreateButton(WContextMenu, 0.0, Y#, 1.0, 0.33, "Attack", False, 255, 255, 255, LoadTexture("Data\Textures\GUI\ToolTip.png"))
Y# = Y# + 0.33
EndIf
; Examine button
BExamine = GY_CreateButton(WContextMenu, 0.0, Y#, 1.0, 0.33, "Examine", False, 255, 255, 255, LoadTexture("Data\Textures\GUI\ToolTip.png"))
Y# = Y# + 0.33
; Trade Button
If AI\Actor\TradeMode > 0
BTrade = GY_CreateButton(WContextMenu, 0.0, Y#, 1.0, 0.33, "Trade", False, 255, 255, 255, LoadTexture("Data\Textures\GUI\ToolTip.png"))
EndIf
AttackTarget = False
EndIf
.SkipActorSelect
;HideEntity(ClickMarkerEN) ;{@@@~}
; Target is a dropped item
ElseIf Target$ = "D"
; In range - pick it up if room in inventory
If EntityDistance#(Result, Me\EN) < 25.0
UsedClick = True
DItem.DroppedItem = Object.DroppedItem(EntityName$(Result))
; Stale handle: the dropped-item entity was picked but
; its Object lookup resolved to Null (entity name lost,
; server-side cleanup race). Skip the pickup flow rather
; than crash on DItem\Item below. The sibling scenery
; path at ~line 854 already has this guard.
FoundSlot = -1
If DItem <> Null
For i = 0 To Slots_Inventory
If Me\Inventory\Items[i] = Null
If DItem\Item <> Null
If SlotsMatch(DItem\Item\Item, i) And ActorHasSlot(Me\Actor, i, DItem\Item\Item) Then FoundSlot = i : Exit
EndIf
ElseIf (ItemInstancesIdentical(DItem\Item, Me\Inventory\Items[i]) And DItem\Item <> Null And i >= SlotI_Backpack)
If DItem\Item\Item\Stackable = True
If SlotsMatch(DItem\Item\Item, i) And ActorHasSlot(Me\Actor, i, DItem\Item\Item) Then FoundSlot = i : Exit
EndIf
EndIf
Next
EndIf
; Room, request it from server
If FoundSlot > -1
RCE_Send(Connection, PeerToHost, P_InventoryUpdate, "P" + RCE_StrFromInt$(DItem\ServerHandle, 4) + RCE_StrFromInt$(FoundSlot, 1), True)
; No room!
Else
Output(LanguageString$(LS_NoInventorySpace), 255, 0, 0)
EndIf
EndIf
; Target is scenery
ElseIf Target$ = ""
; If I am riding a mount, get off
If Me\Mount <> Null
RCE_Send(Connection, PeerToHost, P_Dismount, "", True)
; Otherwise check if I can use this scenery
Else
Sc.Scenery = Object.Scenery(EntityName$(Result))
If Sc <> Null
PositionEntity GPP, PickedX#(), PickedY#(), PickedZ#()
If EntityDistance#(Me\CollisionEN, GPP) < 10.0
UsedClick = True
; Animate now
If Sc\AnimationMode = 3 ;And Sc\SceneryID = 0 {##}
If AnimTime(Sc\EN) > 0.0
Animate(Sc\EN, 3, -1.0, 0, 1.0)
Else
Animate(Sc\EN, 3, 1.0, 0, 1.0)
EndIf
EndIf
; Ask server whether I own this scenery {##}
If Sc\SceneryID > 0
RCE_Send(Connection, PeerToHost, P_SelectScenery, RCE_StrFromInt$(Sc\SceneryID, 2) + RCE_StrFromInt$(Handle(Sc), 4), True)
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
; Move-to button is being held down {@@@~}
If ControlDown(Key_MoveTo)
MouseWasDown = True
; If the mouse still on the same scenery target, continue updating player destination
If InDialog = False And SMemorising = 0
SetPickModes(0, 3, True)
Result = CameraPick(Cam, MouseX(), MouseY())
If Result <> 0
Target$ = GetTarget$(Result)
If Target$ = ""
SetDestination(Me, PickedX#(), PickedZ#(), PickedY#())
If Target$ = ""
ShowEntity(ClickMarkerEN)
ClickMarkerTimer = MilliSecs()
PositionEntity(ClickMarkerEN, PickedX#(), PickedY#(), PickedZ#())
AlignToVector(ClickMarkerEN, PickedNX#(), PickedNY#(), PickedNZ#(), 2)
MoveEntity(ClickMarkerEN, 0, 0.085, 0)
EndIf
; If in first person view, "compress" angle to destination
If CamMode = 1
PositionEntity GPP, Me\DestX#, EntityY#(Me\CollisionEN), Me\DestZ#
Dist# = EntityDistance#(Me\CollisionEN, GPP)
If Abs(GY_MouseX# - 0.5) < 0.15 Then Angle# = 0.0 Else Angle# = DeltaYaw#(Me\CollisionEN, GPP) / 75.0
PositionEntity GPP, EntityX#(Me\CollisionEN), EntityY#(Me\CollisionEN), EntityZ#(Me\CollisionEN)
RotateEntity GPP, 0.0, (EntityYaw#(Me\CollisionEN) - Angle#) + 180.0, 0.0
TFormPoint(0.0, 0.0, Dist#, GPP, 0)
SetDestination(Me, TFormedX#(), TFormedZ#(), TFormedY#())
EndIf
EndIf
EndIf
EndIf
; Left mouse button was just clicked
ElseIf MouseWasDown = True
; Was this a double click?
IsDouble = False
If MilliSecs() - LastLeftClick < 500 Then IsDouble = True
; Store time of click
LastLeftClick = MilliSecs()
MouseWasDown = False
; Pick a target unless this click was already used by the Select control
If UsedClick = False Or Key_Select <> Key_MoveTo
SetPickModes(0)
Result = CameraPick(Cam, MouseX(), MouseY())
If Result <> 0
Target$ = GetTarget$(Result)
; Target is scenery
If Target$ = ""
If IsDouble = False