-
Notifications
You must be signed in to change notification settings - Fork 54
/
Script.c
1297 lines (1166 loc) · 30.8 KB
/
Script.c
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
/*
Clonk
Author: Randrian
The protoganist of the game. Witty and nimble if skillfully controlled ;-)
*/
// selectable by HUD and some performance optimizations for the HUD updates
#include Library_HUDAdapter
// standard controls
#include Library_ClonkControl
#include Library_CarryHeavyControl
// manager for aiming
#include Library_AimManager
#include Clonk_Animations
static const CLONK_MESH_TRANSFORM_SLOT_Turn = 0; // for turning the clonk
static const CLONK_MESH_TRANSFORM_SLOT_Rotation_Scaling = 1; // for adjusting the rotation while scaling
static const CLONK_MESH_TRANSFORM_SLOT_Translation_Hook = 2; // for adjusting the rotation while scaling
static const CLONK_MESH_TRANSFORM_SLOT_Rotation_Hook = 3; // for adjusting the rotation while scaling
static const CLONK_MESH_TRANSFORM_SLOT_Rotation_Ladder = 5; // for adjusting the rotation while climbing a rope ladder
static const CLONK_MESH_TRANSFORM_SLOT_Scale = 6; // for scaling the size of the clonk
static const CLONK_MESH_TRANSFORM_SLOT_Translation_Dive = 7; // for adjusting the position while diving
// ladder climbing
#include Library_CanClimbLadder
/* Initialization */
func Construction()
{
_inherited(...);
AddEffect("IntTurn", this, 1, 1, this);
AddEffect("IntEyes", this, 1, 35+Random(4), this);
AttachBackpack();
this.hand_display = {};
this.hand_display.hand_mesh = [0,0];
this.hand_display.hand_action = 0;
this.hand_display.both_handed = false;
this.hand_display.on_back = false;
SetSkin(0);
SetAction("Walk");
SetDir(Random(2));
// Broadcast for rules
GameCallEx("OnClonkCreation", this);
}
/* When adding to the crew of a player */
protected func Recruitment(int iPlr)
{
//The clonk's appearance
//Player settings can be overwritten for individual Clonks. In your clonk file: "ExtraData=1;Skin=iX" (X = chosen skin)
var skin = GetCrewExtraData("Skin");
if (skin == nil) skin = GetPlrClonkSkin(iPlr);
if(skin != nil) SetSkin(skin);
else SetSkin(Random(GetSkinCount()));
// Broadcast for crew
GameCallEx("OnClonkRecruitment", this, iPlr);
return _inherited(iPlr,...);
}
protected func DeRecruitment(int iPlr) {
// Broadcast for crew
GameCallEx("OnClonkDeRecruitment", this, iPlr);
return _inherited(iPlr,...);
}
protected func ControlCommand(szCommand, pTarget, iTx, iTy, pTarget2, Data)
{
// RejectConstruction Callback for building via Drag'n'Drop form a building menu
// TODO: Check if we still need this with the new system
if(szCommand == "Construct")
{
if(Data->~RejectConstruction(iTx - GetX(), iTy - GetY(), this) )
{
return 1;
}
}
// No overloaded command
return _inherited(szCommand, pTarget, iTx, iTy, pTarget2, Data, ...);
}
/* Transformation */
public func Redefine(idTo)
{
// save data of activity
var phs=GetPhase(),act=GetAction();
// Transform
ChangeDef(idTo);
// restore action
var chg=SetAction(act);
if (!chg) SetAction("Walk");
if (chg) SetPhase(phs);
// Done
return 1;
}
/* Events */
protected func CatchBlow()
{
if (GetAction() == "Dead") return;
if (!Random(5)) PlaySoundHurt();
}
protected func OnEnergyChange(int change, int cause, int caused_by)
{
if (change < 0 && GetCursor(GetOwner()) == this)
PlayRumble(GetOwner(), Min(300 + 1000 * -change / this.MaxEnergy, 1000), 150);
return _inherited(change, cause, caused_by, ...);
}
protected func Grab(object pTarget, bool fGrab)
{
if (fGrab)
Sound("Clonk::Action::Grab");
else
Sound("Clonk::Action::UnGrab");
}
protected func Get()
{
Sound("Clonk::Action::Grab");
}
protected func Put()
{
Sound("Clonk::Action::Grab");
}
protected func Death(int killed_by)
{
// this must be done first, before any goals do funny stuff with the clonk
_inherited(killed_by,...);
// Info-broadcasts for dying clonks.
GameCallEx("OnClonkDeath", this, killed_by);
// The broadcast could have revived the clonk.
if (GetAlive())
return;
// Some effects on dying.
if (!this.silent_death)
{
PlaySkinSound("Die*");
DeathAnnounce();
// When killed by a team member, the other Clonk randomly plays a sound.
if (!Random(5) && killed_by != NO_OWNER && killed_by != GetOwner() && !Hostile(killed_by, GetOwner()))
{
var other_cursor = GetCursor(killed_by);
if (other_cursor)
other_cursor->~PlaySoundTaunt();
}
}
CloseEyes(1);
return true;
}
protected func Destruction(...)
{
_inherited(...);
// If the clonk wasn't dead yet, he will be now.
// Always kill clonks first. This will ensure relaunch scripts, enemy kill counters, etc. are called
// even if clonks die in some weird way that causes direct removal
// (To prevent a death callback, you can use SetAlive(false); RemoveObject();)
if (GetAlive()) { this.silent_death=true; Kill(); }
return true;
}
protected func DeepBreath()
{
Sound("Clonk::Action::Breathing");
}
public func Incineration()
{
PlaySoundShock();
return _inherited(...);
}
protected func CheckStuck()
{
// Prevents getting stuck on middle vertex
if(!GetXDir()) if(Abs(GetYDir()) < 5)
if(GBackSolid(0, 3))
SetPosition(GetX(), GetY() + 1);
}
public func Eat(object food)
{
Heal(food->NutritionalValue());
food->RemoveObject();
Sound("Clonk::Action::Munch?");
SetAction("Eat");
}
// Called when an object was dug free.
func DigOutObject(object obj)
{
// Some materials can only be transported/collected with a bucket.
if (obj->~IsBucketMaterial())
{
// Assume we might already be carrying a filled bucket and the object is stackable, try it!
var handled = obj->~MergeWithStacksIn(this);
if (!handled)
{
// Otherwise, force into empty buckets!
var empty_bucket = FindObject(Find_Container(this), Find_Func("IsBucket"), Find_Func("IsBucketEmpty"));
if (empty_bucket)
{
obj->Enter(empty_bucket);
handled = true;
}
}
// Those objects can only be carried with a bucket, sadly...
if (!handled)
obj->RemoveObject();
// Object might have been removed now.
return;
}
// Collect fragile objects when dug out
if (obj->GetDefFragile())
return Collect(obj,nil,nil,true);
return false;
}
// Building material bridges (like loam bridge)
func Bridge()
{
var proc = GetProcedure();
// Clonk must stand on ground. Allow during SCALE; but Clonk won't keep animation if he's not actually near the ground
if (proc != "WALK" && proc != "SCALE")
return false;
if (proc == "WALK")
SetAction("BridgeStand");
else
SetAction("BridgeScale");
SetComDir(COMD_Stop);
SetXDir(0);
SetYDir(0);
return true;
}
/* Status */
// TODO: Make this more sophisticated, readd turn animation and other
// adaptions
public func IsClonk() { return true; }
public func IsPrey() { return true; }
public func IsJumping(){return WildcardMatch(GetAction(), "*Jump*");}
public func IsWalking(){return GetProcedure() == "WALK";}
public func IsSwimming(){return GetProcedure() == "SWIM";}
public func IsBridging(){return WildcardMatch(GetAction(), "Bridge*");}
// Clonks act as containers for the interaction menu as long as they are alive.
public func IsContainer() { return GetAlive(); }
// You can not interact with dead Clonks.
// This would be the place to show a death message etc.
public func RejectInteractionMenu(object to)
{
if (!GetAlive())
return Format("$MsgDeadClonk$", GetName());
return _inherited(to, ...);
}
public func GetSurroundingEntryMessage(object for_clonk)
{
if (!GetAlive()) return Format("{{Clonk_Grave}} %s", Clonk_Grave->GetInscriptionForClonk(this));
}
/* Carry items on the clonk */
local iHandMesh;
local fHandAction;
local fBothHanded;
// Mesh attachment handling
local hand_display;
/* Features 4 properties:
hand_mesh: Array of attachment numbers for items on the clonk.
hand_action: Determines whether the clonk's hands are busy if items can be used.
one of three ints: -1, 0 or 1
-1: no items are drawn on the clonk but they are usable
0: items are drawn and can be used
+1: items are not drawn and cannot be used
both_handed: The first item held is held with both hands, so draw the second one differently.
on_back: The first item is currently on the clonk's back, so draw the second one differently (if it also goes on the back).
*/
func OnSelectionChanged(int oldslot, int newslot, bool secondaryslot)
{
AttachHandItem(secondaryslot);
return _inherited(oldslot, newslot, secondaryslot);
}
func OnSlotEmpty(int slot)
{
AttachHandItem(slot);
return _inherited(slot);
}
func OnSlotFull(int slot)
{
AttachHandItem(slot);
return _inherited(slot);
}
public func DetachObject(object obj)
{
if(GetHandItem(0) == obj)
DetachHandItem(0);
if(GetHandItem(1) == obj)
DetachHandItem(1);
}
func DetachHandItem(bool secondary)
{
if(this.hand_display.hand_mesh[secondary])
{
DetachMesh(this.hand_display.hand_mesh[secondary]);
var anim = "Close2Hand";
if (secondary) anim = "Close1Hand";
PlayAnimation(anim, CLONK_ANIM_SLOT_Hands + secondary, Anim_Const(0));
}
this.hand_display.hand_mesh[secondary] = 0;
}
func AttachHandItem(bool secondary)
{
DetachHandItem(secondary);
UpdateAttach();
}
func UpdateAttach()
{
StopAnimation(GetRootAnimation(6));
if (this.hand_display.hand_mesh)
{
DetachHandItem(0);
DetachHandItem(1);
}
DoUpdateAttach(0);
DoUpdateAttach(1);
}
func DoUpdateAttach(int sec)
{
var obj = GetHandItem(sec);
var other_obj = GetHandItem(!sec);
if(!obj) return;
var attach_mode = obj->~GetCarryMode(this, sec);
if(attach_mode == CARRY_None) return;
if(!sec)
{
this.hand_display.both_handed = false;
this.hand_display.on_back = false;
}
if(this.hand_display.hand_mesh[sec])
{
DetachMesh(this.hand_display.hand_mesh[sec]);
this.hand_display.hand_mesh[sec] = 0;
}
var bone = "main";
var bone2;
if(obj->~GetCarryBone()) bone = obj->~GetCarryBone(this, sec);
if(obj->~GetCarryBone2()) bone2 = obj->~GetCarryBone2(this, sec);
else bone2 = bone;
var nohand = false;
if(!HasHandAction(sec, 1)) nohand = true;
var trans = obj->~GetCarryTransform(this, sec, nohand, this.hand_display.on_back);
var pos_hand = "pos_hand2";
if(sec) pos_hand = "pos_hand1";
var pos_back = "pos_back1";
if(sec) pos_back = "pos_back2";
var closehand = "Close2Hand";
if(sec) closehand = "Close1Hand";
var pos_belt = "skeleton_leg_upper.R";
if (sec) pos_belt = "skeleton_leg_upper.L";
var special = obj->~GetCarrySpecial(this);
var special_other;
if(other_obj) special_other = other_obj->~GetCarrySpecial(this, sec);
if(special)
{
this.hand_display.hand_mesh[sec] = AttachMesh(obj, special, bone, trans);
attach_mode = 0;
}
if(attach_mode == CARRY_Hand)
{
if(HasHandAction(sec, 1))
{
this.hand_display.hand_mesh[sec] = AttachMesh(obj, pos_hand, bone, trans);
PlayAnimation(closehand, CLONK_ANIM_SLOT_Hands + sec, Anim_Const(GetAnimationLength(closehand)));
}
}
else if(attach_mode == CARRY_HandBack)
{
if(HasHandAction(sec, 1))
{
this.hand_display.hand_mesh[sec] = AttachMesh(obj, pos_hand, bone, trans);
PlayAnimation(closehand, CLONK_ANIM_SLOT_Hands + sec, Anim_Const(GetAnimationLength(closehand)));
}
else
{
this.hand_display.hand_mesh[sec] = AttachMesh(obj, pos_back, bone2, trans);
if (!sec)
this.hand_display.on_back = true;
}
}
else if(attach_mode == CARRY_HandAlways)
{
this.hand_display.hand_mesh[sec] = AttachMesh(obj, pos_hand, bone, trans);
PlayAnimation(closehand, CLONK_ANIM_SLOT_Hands + sec, Anim_Const(GetAnimationLength(closehand)));
}
else if(attach_mode == CARRY_Back)
{
this.hand_display.hand_mesh[sec] = AttachMesh(obj, pos_back, bone2, trans);
if (!sec)
this.hand_display.on_back = true;
}
else if(attach_mode == CARRY_BothHands)
{
if(sec) return;
if(HasHandAction(sec, 1) && !sec && !special_other)
{
this.hand_display.hand_mesh[sec] = AttachMesh(obj, "pos_tool1", bone, trans);
PlayAnimation("CarryArms", CLONK_ANIM_SLOT_Hands + sec, Anim_Const(obj->~GetCarryPhase(this)));
this.hand_display.both_handed = true;
}
}
else if(attach_mode == CARRY_Spear)
{
// This is a one sided animation, so switch to back if not in the main hand
if(HasHandAction(sec, 1) && !sec)
{
this.hand_display.hand_mesh[sec] = AttachMesh(obj, pos_hand, bone, trans);
PlayAnimation("CarrySpear", CLONK_ANIM_SLOT_Hands + sec, Anim_Const(0));
}
else
{
this.hand_display.hand_mesh[sec] = AttachMesh(obj, pos_back, bone2, trans);
if (!sec)
this.hand_display.on_back = true;
}
}
else if(attach_mode == CARRY_Blunderbuss)
{
if(HasHandAction(sec, 1) && !sec)
{
this.hand_display.hand_mesh[sec] = AttachMesh(obj, "pos_hand2", bone, trans);
PlayAnimation("CarryMusket", CLONK_ANIM_SLOT_Hands + sec, Anim_Const(0), Anim_Const(1000));
this.hand_display.both_handed = true;
}
else
{
this.hand_display.hand_mesh[sec] = AttachMesh(obj, pos_back, bone2, trans);
if (!sec)
this.hand_display.on_back = true;
}
}
else if(attach_mode == CARRY_Grappler)
{
if(HasHandAction(sec, 1) && !sec)
{
this.hand_display.hand_mesh[sec] = AttachMesh(obj, "pos_hand2", bone, trans);
PlayAnimation("CarryCrossbow", CLONK_ANIM_SLOT_Hands + sec, Anim_Const(0), Anim_Const(1000));
this.hand_display.both_handed = true;
}
else
{
this.hand_display.hand_mesh[sec] = AttachMesh(obj, pos_back, bone2, trans);
if (!sec)
this.hand_display.on_back = true;
}
}
else if(attach_mode == CARRY_Belt)
{
// Do some extra transforms for this kind of carrying
if (trans)
trans = Trans_Mul(trans, Trans_Rotate(160,0,0,1), Trans_Rotate(5,0,1), Trans_Rotate(30,1), Trans_Translate(-2500,0,700), Trans_Scale(700));
else
trans = Trans_Mul(Trans_Rotate(160,0,0,1), Trans_Rotate(5,0,1), Trans_Rotate(30,1), Trans_Translate(-2500,0,800), Trans_Scale(700));
this.hand_display.hand_mesh[sec] = AttachMesh(obj, pos_belt, bone, trans);
}
else if(attach_mode == CARRY_Sword)
{
this.hand_display.hand_mesh[sec] = AttachMesh(obj, "skeleton_hips", bone, trans);
}
}
public func GetHandMesh(object obj)
{
if(GetHandItem(0) == obj)
return this.hand_display.hand_mesh[0];
if(GetHandItem(1) == obj)
return this.hand_display.hand_mesh[1];
}
static const CARRY_None = 0;
static const CARRY_Hand = 1;
static const CARRY_HandBack = 2;
static const CARRY_HandAlways = 3;
static const CARRY_Back = 4;
static const CARRY_BothHands = 5;
static const CARRY_Spear = 6;
static const CARRY_Blunderbuss = 7;
static const CARRY_Grappler = 8;
static const CARRY_Belt = 9;
static const CARRY_Sword = 10;
func HasHandAction(sec, just_wear, bool force_landscape_letgo)
{
// Check if the clonk is currently able to use hands
// sec: Needs both hands (e.g. CarryHeavy?)
// just_wear: ???
// force_landscape_letgo: Also allow from actions where hands are currently grabbing the landscape (scale, hangle)
if(sec && this.hand_display.both_handed)
return false;
if(just_wear)
{
if( HasActionProcedure(force_landscape_letgo) && !this.hand_display.hand_action )
// For wear purpose this.hand_display.hand_action==-1 also blocks
return true;
}
else
{
if( HasActionProcedure(force_landscape_letgo) && (!this.hand_display.hand_action || this.hand_display.hand_action == -1) )
return true;
}
return false;
}
func HasActionProcedure(bool force_landscape_letgo)
{
// Check if the clonk is currently in an action where he could use his hands
// if force_landscape_letgo is true, also allow during scale/hangle assuming the clonk will let go
var action = GetAction();
if (action == "Walk" || action == "Jump" || action == "WallJump" || action == "Kneel" || action == "Ride" || action == "BridgeStand")
return true;
if (force_landscape_letgo) if (action == "Scale" || action == "Hangle")
return true;
return false;
}
public func ReadyToAction(fNoArmCheck)
{
if(!fNoArmCheck)
return HasActionProcedure();
return HasHandAction(0);
}
public func SetHandAction(bool fNewValue)
{
if(fNewValue > 0)
this.hand_display.hand_action = 1; // 1 means can't use items and doesn't draw items in hand
else if(fNewValue < 0)
this.hand_display.hand_action = -1; // just don't draw items in hand can still use them
else
this.hand_display.hand_action = 0;
UpdateAttach();
}
public func GetHandAction()
{
if(this.hand_display.hand_action == 1)
return true;
return false;
}
/* Enable the Clonk to pick up stuff from its surrounding in the interaction menu */
public func OnInteractionMenuOpen(object menu)
{
_inherited(menu, ...);
// Allow picking up stuff from the surrounding only if not in a container itself.
if (!Contained())
{
var surrounding = CreateObject(Helper_Surrounding);
surrounding->InitFor(this, menu);
}
}
/* Mesh transformations */
local mesh_transformation_list;
func SetMeshTransformation(array transformation, int layer)
{
if(!mesh_transformation_list) mesh_transformation_list = [];
if(GetLength(mesh_transformation_list) < layer)
SetLength(mesh_transformation_list, layer+1);
mesh_transformation_list[layer] = transformation;
var all_transformations = nil;
for(var trans in mesh_transformation_list)
{
if(!trans) continue;
if(all_transformations)
all_transformations = Trans_Mul(trans, all_transformations);
else
all_transformations = trans;
}
SetProperty("MeshTransformation", all_transformations);
}
/* Backpack */
local backpack;
func AttachBackpack()
{
//Places a backpack onto the clonk
backpack = AttachMesh(BackpackGraphic, "skeleton_body", "main",
Trans_Mul(Trans_Rotate(180,1,0,0), Trans_Scale(700,400,700), Trans_Translate(4000,-1000,0)));
}
func RemoveBackpack()
{
if(backpack)
{
DetachMesh(backpack);
backpack = nil;
}
else return false;
}
// calback from engine
func OnMaterialChanged(int new, int old)
{
if(!GetAlive()) return;
var newdens = GetMaterialVal("Density","Material",new);
var olddens = GetMaterialVal("Density","Material",old);
var newliquid = (newdens >= C4M_Liquid) && (newdens < C4M_Solid);
var oldliquid = (olddens >= C4M_Liquid) && (olddens < C4M_Solid);
// into water
if(newliquid && !oldliquid)
AddEffect("Bubble", this, 1, 8, this);
// out of water
else if(!newliquid && oldliquid)
RemoveEffect("Bubble", this);
}
func FxBubbleTimer(pTarget, effect, iTime)
{
if(GBackLiquid(0,-5))
{
var mouth_off = GetCon()/11;
var iRot = GetSwimRotation();
var mouth_off_x = Sin(iRot, mouth_off), mouth_off_y = Cos(iRot, mouth_off);
// Search for bubbles to breath from
var bubble = FindObject(Find_Func("CanBeBreathed", this), Find_AtRect(mouth_off_x-mouth_off/2, mouth_off_y, mouth_off, mouth_off/3));
if (bubble)
{
bubble->~OnClonkBreath(this);
}
else if (!Random(6))
{
// Make your own bubbles
Bubble(1, mouth_off_x, mouth_off_y);
}
}
}
public func QueryCatchBlow(object obj)
{
var fx;
var index = 0;
// Blocked by object effects?
while (fx = GetEffect("*", obj, index++))
if (EffectCall(obj, fx, "QueryHitClonk", this))
return true;
// Blocked by Clonk effects?
index = 0;
while (fx = GetEffect("*Control*", this, index++))
if (EffectCall(this, fx, "QueryCatchBlow", obj))
return true;
// Default blocking.
return _inherited(obj, ...);
}
local gender, skin, skin_name;
func SetSkin(int new_skin)
{
// Remember skin
skin = new_skin;
//Adventurer
if(skin == 0)
{ SetGraphics(skin_name = nil);
gender = 0; }
//Steampunk
if(skin == 1)
{ SetGraphics(skin_name = "Steampunk");
gender = 1; }
//Alchemist
if(skin == 2)
{ SetGraphics(skin_name = "Alchemist");
gender = 0; }
//Farmer
if(skin == 3)
{ SetGraphics(skin_name = "Farmer");
gender = 1; }
RemoveBackpack(); //add a backpack
AttachBackpack();
//refreshes animation (whatever that means?)
// Go back to original action afterwards and hope
// that noone calls SetSkin during more compex activities
var prev_action = GetAction();
SetAction("Jump");
SetAction(prev_action);
return skin;
}
func GetSkinCount() { return 4; }
func GetSkin() { return skin; }
func GetSkinName() { return skin_name; }
// Returns the skin name as used to select the right sound subfolder.
public func GetSoundSkinName()
{
if (skin_name == nil) return "Adventurer";
return skin_name;
}
public func PlaySkinSound(string sound, ...)
{
Sound(Format("Clonk::Skin::%s::%s", GetSoundSkinName(), sound), ...);
}
/*
Helper functions to play some sounds. This are encapsulated here in case sound names change.
*/
public func PlaySoundConfirm(...)
{
if (GetSoundSkinName() != "Farmer")
PlaySkinSound("Confirm*", ...);
}
public func PlaySoundDecline(...)
{
if (GetSoundSkinName() != "Farmer")
PlaySkinSound("Decline*", ...);
}
// Doubtful sound, e.g. when trying a clearly impossible action.
public func PlaySoundDoubt(...)
{
if (GetSoundSkinName() != "Farmer")
PlaySkinSound("Doubt*", ...);
}
public func PlaySoundHurt(...) { PlaySkinSound("Hurt*", ...); }
// Sound that is supposed to be funny in situations where the Clonk maybe did something "evil" like killing a teammate.
public func PlaySoundTaunt(...)
{
if (GetSoundSkinName() == "Alchemist")
PlaySkinSound("EvilConfirm*", ...);
else if (GetSoundSkinName() == "Steampunk")
PlaySkinSound("Laughter*", ...);
}
// Surprised sounds, e.g. when catching fire.
public func PlaySoundShock(...)
{
if (GetSoundSkinName() == "Steampunk" || GetSoundSkinName() == "Adventurer")
PlaySkinSound("Shock*", ...);
}
public func PlaySoundScream() { PlaySkinSound("Scream*"); }
// General idle sounds, played when also playing an idle animation.
public func PlaySoundIdle(...)
{
if (GetSoundSkinName() == "Steampunk")
PlaySkinSound("Singing*", ...);
}
//Portrait definition of this Clonk for messages
func GetPortrait()
{
return this.portrait ?? { Source = GetID(), Name = Format("Portrait%s", skin_name ?? ""), Color = GetColor() };
}
func SetPortrait(proplist custom_portrait)
{
this.portrait = custom_portrait;
return true;
}
// Callback from the engine when a command failed.
public func CommandFailure(string command, object target)
{
// Don't play a sound when an exit command fails (this is a hotfix, because exiting fails all the time).
if (command == "Exit")
return;
// Otherwise play a sound that the clonk is doubting this command.
PlaySoundDoubt();
return;
}
/* Magic */
local magic_energy;
public func GetMagicEnergy(int precision)
{
if (precision == nil) precision = 1000;
if (precision)
return magic_energy / precision;
else
return magic_energy;
}
public func GetMaxMagicEnergy(int precision)
{
if (precision == nil) precision = 1000;
if (precision)
return this.MaxMagic / precision;
else
return this.MaxMagic;
}
public func SetMagicEnergy(int val, int precision)
{
if (precision == nil) precision = 1000;
magic_energy = BoundBy(val * precision, 0, this.MaxMagic);
this->~OnMagicEnergyChange(val);
return true;
}
// Adjusts the magic energy but only if change can be applied completely. Returns true if successful, false otherwise.
// Use partial to bypass the completeness check
public func DoMagicEnergy(int change, bool partial, int precision)
{
if (precision == nil) precision = 1000;
change = change * precision;
// Can't apply fully?
if (!Inside(magic_energy + change, 0, this.MaxMagic) && !partial)
return false;
magic_energy = BoundBy(magic_energy + change, 0, this.MaxMagic);
this->~OnMagicEnergyChange(change);
return true;
}
/* Max energy */
func SetMaxEnergy(int new_max_energy)
{
// Update max energy, inform HUD adapter and clamp current energy
MaxEnergy = new_max_energy;
var current_energy = GetEnergy();
if (current_energy > MaxEnergy/1000)
DoEnergy(MaxEnergy - current_energy*1000, true);
else
OnEnergyChange();
return true;
}
/* Scenario saving */
func SaveScenarioObject(props)
{
if (!inherited(props, ...)) return false;
// Skins override mesh material
if (skin)
{
props->Remove("MeshMaterial");
props->AddCall("Skin", this, "SetSkin", skin);
}
// Direction is randomized at creation and there's no good way to find
// out if the user wanted that specific direction. So just always save
// it, because that's what scenario designer usually wants.
if (!props->HasProp("Dir")) props->AddCall("Dir", this, "SetDir", GetConstantNameByValueSafe(GetDir(),"DIR_"));
// Custom portraits for dialogues
if (this.portrait) props->AddCall("Portrait", this, "SetPortrait", this.portrait);
return true;
}
/* Act Map */
local ActMap = {
Walk = {
Prototype = Action,
Name = "Walk",
Procedure = DFA_WALK,
Accel = 16,
Decel = 48,
Speed = 200,
Directions = 2,
FlipDir = 0,
Length = 1,
Delay = 0,
X = 0,
Y = 0,
Wdt = 8,
Hgt = 20,
StartCall = "StartWalk",
AbortCall = "StopWalk",
// InLiquidAction = "Swim",
},
Stand = {
Prototype = Action,
Name = "Stand",
Procedure = DFA_THROW,
Directions = 2,
FlipDir = 0,
Length = 1,
Delay = 0,
X = 0,
Y = 0,
Wdt = 8,
Hgt = 20,
StartCall = "StartStand",
InLiquidAction = "Swim",
},
Kneel = {
Prototype = Action,
Name = "Kneel",
Procedure = DFA_KNEEL,
Directions = 2,
FlipDir = 0,
Length = 1,
Delay = 0,
X = 0,
Y = 0,
Wdt = 8,
Hgt = 20,
// StartCall = "StartKneel",
InLiquidAction = "Swim",
},
Roll = {
Prototype = Action,
Name = "Roll",
Procedure = DFA_NONE,
Directions = 2,
FlipDir = 0,
Length = 1,
Delay = 0,
X = 0,
Y = 0,
Wdt = 8,
Hgt = 20,
StartCall = "OnStartRoll",
AbortCall = "OnAbortRoll",
NextAction = "Walk",
InLiquidAction = "Swim",
},
Scale = {
Prototype = Action,
Name = "Scale",
Procedure = DFA_SCALE,
Speed = 60,
Accel = 20,
Directions = 2,
Length = 1,
Delay = 0,
X = 0,
Y = 20,
Wdt = 8,
Hgt = 20,
OffX = 0,
OffY = 0,
StartCall = "StartScale",
AbortCall = "StopScale",
},