-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathafxMagicSpell.cpp
2709 lines (2326 loc) · 75.5 KB
/
afxMagicSpell.cpp
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
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
// Copyright (C) 2015 Faust Logic, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
#include "afx/arcaneFX.h"
#include "console/engineAPI.h"
#include "T3D/gameBase/gameConnection.h"
#include "sfx/sfxSystem.h"
#include "math/mathIO.h"
#include "T3D/containerQuery.h"
#include "afx/afxChoreographer.h"
#include "afx/afxPhrase.h"
#include "afx/afxMagicSpell.h"
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
// afxMagicSpellData::ewValidator
//
// When any of the effect list fields (addCastingEffect, etc.) are set, this validator
// intercepts the value and adds it to the appropriate effects list. One validator is
// created for each effect list and an id is used to identify which list to add the effect
// to.
//
void afxMagicSpellData::ewValidator::validateType(SimObject* object, void* typePtr)
{
afxMagicSpellData* spelldata = dynamic_cast<afxMagicSpellData*>(object);
afxEffectBaseData** ew = (afxEffectBaseData**)(typePtr);
if (spelldata && ew)
{
switch (id)
{
case CASTING_PHRASE:
spelldata->mCasting_fx_list.push_back(*ew);
break;
case LAUNCH_PHRASE:
spelldata->mLaunch_fx_list.push_back(*ew);
break;
case DELIVERY_PHRASE:
spelldata->mDelivery_fx_list.push_back(*ew);
break;
case IMPACT_PHRASE:
spelldata->mImpact_fx_list.push_back(*ew);
break;
case LINGER_PHRASE:
spelldata->mLinger_fx_list.push_back(*ew);
break;
}
*ew = 0;
}
}
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
class SpellFinishStartupEvent : public SimEvent
{
public:
void process(SimObject* obj)
{
afxMagicSpell* spell = dynamic_cast<afxMagicSpell*>(obj);
if (spell)
spell->finish_startup();
}
};
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
// afxMagicSpellData
IMPLEMENT_CO_DATABLOCK_V1(afxMagicSpellData);
ConsoleDocClass( afxMagicSpellData,
"@brief Defines the properties of an afxMagicSpell.\n\n"
"@ingroup afxChoreographers\n"
"@ingroup AFX\n"
"@ingroup Datablocks\n"
);
IMPLEMENT_CALLBACK( afxMagicSpellData, onDamage, void,
(afxMagicSpell* spell, const char* label, const char* flaver, U32 target_id, F32 amount, U8 n, Point3F pos, F32 ad_amount, F32 radius, F32 impulse),
(spell, label, flaver, target_id, amount, n, pos, ad_amount, radius, impulse),
"Called when the spell deals damage.\n"
"@param spell the spell object\n" );
IMPLEMENT_CALLBACK( afxMagicSpellData, onDeactivate, void, (afxMagicSpell* spell), (spell),
"Called when the spell ends naturally.\n"
"@param spell the spell object\n" );
IMPLEMENT_CALLBACK( afxMagicSpellData, onInterrupt, void, (afxMagicSpell* spell, ShapeBase* caster), (spell, caster),
"Called when the spell ends unnaturally due to an interruption.\n"
"@param spell the spell object\n" );
IMPLEMENT_CALLBACK( afxMagicSpellData, onLaunch, void,
(afxMagicSpell* spell, ShapeBase* caster, SceneObject* target, afxMagicMissile* missile),
(spell, caster, target, missile),
"Called when the spell's casting stage ends and the delivery stage begins.\n"
"@param spell the spell object\n" );
IMPLEMENT_CALLBACK( afxMagicSpellData, onImpact, void,
(afxMagicSpell* spell, ShapeBase* caster, SceneObject* impacted, Point3F pos, Point3F normal),
(spell, caster, impacted, pos, normal),
"Called at the spell's missile impact marking the end of the deliver stage and the start of the linger stage.\n"
"@param spell the spell object\n" );
IMPLEMENT_CALLBACK( afxMagicSpellData, onPreactivate, bool,
(SimObject* param_holder, ShapeBase* caster, SceneObject* target, SimObject* extra),
(param_holder, caster, target, extra),
"Called during spell casting before spell instance is fully created.\n");
IMPLEMENT_CALLBACK( afxMagicSpellData, onActivate, void,
(afxMagicSpell* spell, ShapeBase* caster, SceneObject* target),
(spell, caster, target),
"Called when the spell starts.\n"
"@param spell the spell object\n" );
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
afxMagicSpellData::afxMagicSpellData()
{
mCasting_dur = 0.0f;
mDelivery_dur = 0.0f;
mLinger_dur = 0.0f;
mNum_casting_loops = 1;
mNum_delivery_loops = 1;
mNum_linger_loops = 1;
mExtra_casting_time = 0.0f;
mExtra_delivery_time = 0.0f;
mExtra_linger_time = 0.0f;
// interrupt flags
mDo_move_interrupts = true;
mMove_interrupt_speed = 2.0f;
// delivers projectile spells
mMissile_db = 0;
mLaunch_on_server_signal = false;
mPrimary_target_types = PlayerObjectType;
// dummy entry holds effect-wrapper pointer while a special validator
// grabs it and adds it to an appropriate effects list
mDummy_fx_entry = NULL;
// marked true if datablock ids need to
// be converted into pointers
mDo_id_convert = false;
}
afxMagicSpellData::afxMagicSpellData(const afxMagicSpellData& other, bool temp_clone) : afxChoreographerData(other, temp_clone)
{
mCasting_dur = other.mCasting_dur;
mDelivery_dur = other.mDelivery_dur;
mLinger_dur = other.mLinger_dur;
mNum_casting_loops = other.mNum_casting_loops;
mNum_delivery_loops = other.mNum_delivery_loops;
mNum_linger_loops = other.mNum_linger_loops;
mExtra_casting_time = other.mExtra_casting_time;
mExtra_delivery_time = other.mExtra_delivery_time;
mExtra_linger_time = other.mExtra_linger_time;
mDo_move_interrupts = other.mDo_move_interrupts;
mMove_interrupt_speed = other.mMove_interrupt_speed;
mMissile_db = other.mMissile_db;
mLaunch_on_server_signal = other.mLaunch_on_server_signal;
mPrimary_target_types = other.mPrimary_target_types;
mDummy_fx_entry = other.mDummy_fx_entry;
mDo_id_convert = other.mDo_id_convert;
mCasting_fx_list = other.mCasting_fx_list;
mLaunch_fx_list = other.mLaunch_fx_list;
mDelivery_fx_list = other.mDelivery_fx_list;
mImpact_fx_list = other.mImpact_fx_list;
mLinger_fx_list = other.mLinger_fx_list;
}
void afxMagicSpellData::reloadReset()
{
mCasting_fx_list.clear();
mLaunch_fx_list.clear();
mDelivery_fx_list.clear();
mImpact_fx_list.clear();
mLinger_fx_list.clear();
}
#define myOffset(field) Offset(field, afxMagicSpellData)
void afxMagicSpellData::initPersistFields()
{
static ewValidator _castingPhrase(CASTING_PHRASE);
static ewValidator _launchPhrase(LAUNCH_PHRASE);
static ewValidator _deliveryPhrase(DELIVERY_PHRASE);
static ewValidator _impactPhrase(IMPACT_PHRASE);
static ewValidator _lingerPhrase(LINGER_PHRASE);
// for each effect list, dummy_fx_entry is set and then a validator adds it to the appropriate effects list
addGroup("Casting Stage");
addField("castingDur", TypeF32, myOffset(mCasting_dur),
"...");
addField("numCastingLoops", TypeS32, myOffset(mNum_casting_loops),
"...");
addField("extraCastingTime", TypeF32, myOffset(mExtra_casting_time),
"...");
addFieldV("addCastingEffect", TYPEID<afxEffectBaseData>(), Offset(mDummy_fx_entry, afxMagicSpellData), &_castingPhrase,
"...");
endGroup("Casting Stage");
addGroup("Delivery Stage");
addField("deliveryDur", TypeF32, myOffset(mDelivery_dur),
"...");
addField("numDeliveryLoops", TypeS32, myOffset(mNum_delivery_loops),
"...");
addField("extraDeliveryTime", TypeF32, myOffset(mExtra_delivery_time),
"...");
addFieldV("addLaunchEffect", TYPEID<afxEffectBaseData>(), Offset(mDummy_fx_entry, afxMagicSpellData), &_launchPhrase,
"...");
addFieldV("addDeliveryEffect", TYPEID<afxEffectBaseData>(), Offset(mDummy_fx_entry, afxMagicSpellData), &_deliveryPhrase,
"...");
endGroup("Delivery Stage");
addGroup("Linger Stage");
addField("lingerDur", TypeF32, myOffset(mLinger_dur),
"...");
addField("numLingerLoops", TypeS32, myOffset(mNum_linger_loops),
"...");
addField("extraLingerTime", TypeF32, myOffset(mExtra_linger_time),
"...");
addFieldV("addImpactEffect", TYPEID<afxEffectBaseData>(), Offset(mDummy_fx_entry, afxMagicSpellData), &_impactPhrase,
"...");
addFieldV("addLingerEffect", TYPEID<afxEffectBaseData>(), Offset(mDummy_fx_entry, afxMagicSpellData), &_lingerPhrase,
"...");
endGroup("Linger Stage");
// interrupt flags
addField("allowMovementInterrupts", TypeBool, myOffset(mDo_move_interrupts),
"...");
addField("movementInterruptSpeed", TypeF32, myOffset(mMove_interrupt_speed),
"...");
// delivers projectile spells
addField("missile", TYPEID<afxMagicMissileData>(), myOffset(mMissile_db),
"...");
addField("launchOnServerSignal", TypeBool, myOffset(mLaunch_on_server_signal),
"...");
addField("primaryTargetTypes", TypeS32, myOffset(mPrimary_target_types),
"...");
Parent::initPersistFields();
// disallow some field substitutions
onlyKeepClearSubstitutions("missile"); // subs resolving to "~~", or "~0" are OK
disableFieldSubstitutions("addCastingEffect");
disableFieldSubstitutions("addLaunchEffect");
disableFieldSubstitutions("addDeliveryEffect");
disableFieldSubstitutions("addImpactEffect");
disableFieldSubstitutions("addLingerEffect");
}
bool afxMagicSpellData::onAdd()
{
if (Parent::onAdd() == false)
return false;
if (mMissile_db != NULL && mDelivery_dur == 0.0)
mDelivery_dur = -1;
return true;
}
void afxMagicSpellData::pack_fx(BitStream* stream, const afxEffectList& fx, bool packed)
{
stream->writeInt(fx.size(), EFFECTS_PER_PHRASE_BITS);
for (int i = 0; i < fx.size(); i++)
writeDatablockID(stream, fx[i], packed);
}
void afxMagicSpellData::unpack_fx(BitStream* stream, afxEffectList& fx)
{
fx.clear();
S32 n_fx = stream->readInt(EFFECTS_PER_PHRASE_BITS);
for (int i = 0; i < n_fx; i++)
fx.push_back((afxEffectWrapperData*)(uintptr_t)readDatablockID(stream));
}
void afxMagicSpellData::packData(BitStream* stream)
{
Parent::packData(stream);
stream->write(mCasting_dur);
stream->write(mDelivery_dur);
stream->write(mLinger_dur);
//
stream->write(mNum_casting_loops);
stream->write(mNum_delivery_loops);
stream->write(mNum_linger_loops);
//
stream->write(mExtra_casting_time);
stream->write(mExtra_delivery_time);
stream->write(mExtra_linger_time);
stream->writeFlag(mDo_move_interrupts);
stream->write(mMove_interrupt_speed);
writeDatablockID(stream, mMissile_db, mPacked);
stream->write(mLaunch_on_server_signal);
stream->write(mPrimary_target_types);
pack_fx(stream, mCasting_fx_list, mPacked);
pack_fx(stream, mLaunch_fx_list, mPacked);
pack_fx(stream, mDelivery_fx_list, mPacked);
pack_fx(stream, mImpact_fx_list, mPacked);
pack_fx(stream, mLinger_fx_list, mPacked);
}
void afxMagicSpellData::unpackData(BitStream* stream)
{
Parent::unpackData(stream);
stream->read(&mCasting_dur);
stream->read(&mDelivery_dur);
stream->read(&mLinger_dur);
//
stream->read(&mNum_casting_loops);
stream->read(&mNum_delivery_loops);
stream->read(&mNum_linger_loops);
//
stream->read(&mExtra_casting_time);
stream->read(&mExtra_delivery_time);
stream->read(&mExtra_linger_time);
mDo_move_interrupts = stream->readFlag();
stream->read(&mMove_interrupt_speed);
mMissile_db = (afxMagicMissileData*)(uintptr_t)readDatablockID(stream);
stream->read(&mLaunch_on_server_signal);
stream->read(&mPrimary_target_types);
mDo_id_convert = true;
unpack_fx(stream, mCasting_fx_list);
unpack_fx(stream, mLaunch_fx_list);
unpack_fx(stream, mDelivery_fx_list);
unpack_fx(stream, mImpact_fx_list);
unpack_fx(stream, mLinger_fx_list);
}
bool afxMagicSpellData::writeField(StringTableEntry fieldname, const char* value)
{
if (!Parent::writeField(fieldname, value))
return false;
// don't write the dynamic array fields
if( fieldname == StringTable->insert("addCastingEffect") )
return false;
if( fieldname == StringTable->insert("addLaunchEffect") )
return false;
if( fieldname == StringTable->insert("addDeliveryEffect") )
return false;
if( fieldname == StringTable->insert("addImpactEffect") )
return false;
if( fieldname == StringTable->insert("addLingerEffect") )
return false;
return true;
}
inline void expand_fx_list(afxEffectList& fx_list, const char* tag)
{
for (S32 i = 0; i < fx_list.size(); i++)
{
SimObjectId db_id = SimObjectId((uintptr_t)fx_list[i]);
if (db_id != 0)
{
// try to convert id to pointer
if (!Sim::findObject(db_id, fx_list[i]))
{
Con::errorf(ConsoleLogEntry::General,
"afxMagicSpellData::preload() -- bad datablockId: 0x%x (%s)",
db_id, tag);
}
}
}
}
bool afxMagicSpellData::preload(bool server, String &errorStr)
{
if (!Parent::preload(server, errorStr))
return false;
// Resolve objects transmitted from server
if (!server)
{
if (mDo_id_convert)
{
SimObjectId missile_id = SimObjectId((uintptr_t)mMissile_db);
if (missile_id != 0)
{
// try to convert id to pointer
if (!Sim::findObject(missile_id, mMissile_db))
{
Con::errorf(ConsoleLogEntry::General,
"afxMagicSpellData::preload() -- bad datablockId: 0x%x (missile)",
missile_id);
}
}
expand_fx_list(mCasting_fx_list, "casting");
expand_fx_list(mLaunch_fx_list, "launch");
expand_fx_list(mDelivery_fx_list, "delivery");
expand_fx_list(mImpact_fx_list, "impact");
expand_fx_list(mLinger_fx_list, "linger");
mDo_id_convert = false;
}
}
return true;
}
void afxMagicSpellData::gatherConstraintDefs(Vector<afxConstraintDef>& defs)
{
afxConstraintDef::gather_cons_defs(defs, mCasting_fx_list);
afxConstraintDef::gather_cons_defs(defs, mLaunch_fx_list);
afxConstraintDef::gather_cons_defs(defs, mDelivery_fx_list);
afxConstraintDef::gather_cons_defs(defs, mImpact_fx_list);
afxConstraintDef::gather_cons_defs(defs, mLinger_fx_list);
if (mMissile_db)
mMissile_db->gather_cons_defs(defs);
}
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//
DefineEngineMethod(afxMagicSpellData, reset, void, (),,
"Resets a spell datablock during reload.\n\n"
"@ingroup AFX")
{
object->reloadReset();
}
DefineEngineMethod(afxMagicSpellData, pushCastingEffect, void, (afxEffectBaseData* effect),,
"Pushes an effect (wrapper or group) to a spell's casting phase.\n\n"
"@ingroup AFX")
{
if (!effect)
{
Con::errorf(ConsoleLogEntry::General,
"afxMagicSpellData::pushCastingEffect() -- "
"missing afxEffectWrapperData.");
return;
}
object->mCasting_fx_list.push_back(effect);
}
DefineEngineMethod(afxMagicSpellData, pushLaunchEffect, void, (afxEffectBaseData* effect),,
"Pushes an effect (wrapper or group) to a spell's launch phase.\n\n"
"@ingroup AFX")
{
if (!effect)
{
Con::errorf(ConsoleLogEntry::General,
"afxMagicSpellData::pushLaunchEffect() -- "
"failed to find afxEffectWrapperData.");
return;
}
object->mLaunch_fx_list.push_back(effect);
}
DefineEngineMethod(afxMagicSpellData, pushDeliveryEffect, void, (afxEffectBaseData* effect),,
"Pushes an effect (wrapper or group) to a spell's delivery phase.\n\n"
"@ingroup AFX")
{
if (!effect)
{
Con::errorf(ConsoleLogEntry::General,
"afxMagicSpellData::pushDeliveryEffect() -- "
"missing afxEffectWrapperData.");
return;
}
object->mDelivery_fx_list.push_back(effect);
}
DefineEngineMethod(afxMagicSpellData, pushImpactEffect, void, (afxEffectBaseData* effect),,
"Pushes an effect (wrapper or group) to a spell's impact phase.\n\n"
"@ingroup AFX")
{
if (!effect)
{
Con::errorf(ConsoleLogEntry::General,
"afxMagicSpellData::pushImpactEffect() -- "
"missing afxEffectWrapperData.");
return;
}
object->mImpact_fx_list.push_back(effect);
}
DefineEngineMethod(afxMagicSpellData, pushLingerEffect, void, (afxEffectBaseData* effect),,
"Pushes an effect (wrapper or group) to a spell's linger phase.\n\n"
"@ingroup AFX")
{
if (!effect)
{
Con::errorf(ConsoleLogEntry::General,
"afxMagicSpellData::pushLingerEffect() -- "
"missing afxEffectWrapperData.");
return;
}
object->mLinger_fx_list.push_back(effect);
}
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
// afxMagicSpell
IMPLEMENT_GLOBAL_CALLBACK( onCastingStart, void, (), (),
"A callout called on clients by spells when the casting stage begins.\n"
"@ingroup AFX\n" );
IMPLEMENT_GLOBAL_CALLBACK( onCastingProgressUpdate, void, (F32 frac), (frac),
"A callout called periodically on clients by spells to indicate casting progress.\n"
"@ingroup AFX\n" );
IMPLEMENT_GLOBAL_CALLBACK( onCastingEnd, void, (), (),
"A callout called on clients by spells when the casting stage ends.\n"
"@ingroup AFX\n" );
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
// CastingPhrase_C
// Subclass of afxPhrase for the client casting phrase.
// This subclass adds handling of the casting progress
// bar in cases where the caster is the client's control
// object.
//
class CastingPhrase_C : public afxPhrase
{
typedef afxPhrase Parent;
ShapeBase* mCaster;
bool mNotify_castbar;
F32 mCastbar_progress;
public:
/*C*/ CastingPhrase_C(ShapeBase* caster, bool notify_castbar);
virtual void start(F32 startstamp, F32 timestamp);
virtual void update(F32 dt, F32 timestamp);
virtual void stop(F32 timestamp);
virtual void interrupt(F32 timestamp);
};
CastingPhrase_C::CastingPhrase_C(ShapeBase* c, bool notify)
: afxPhrase(false, true)
{
mCaster = c;
mNotify_castbar = notify;
mCastbar_progress = 0.0f;
}
void CastingPhrase_C::start(F32 startstamp, F32 timestamp)
{
Parent::start(startstamp, timestamp); //START
if (mNotify_castbar)
{
mCastbar_progress = 0.0f;
onCastingStart_callback();
}
}
void CastingPhrase_C::update(F32 dt, F32 timestamp)
{
Parent::update(dt, timestamp);
if (!mNotify_castbar)
return;
if (mDur > 0 && mNum_loops > 0)
{
F32 nfrac = (timestamp - mStartTime)/(mDur*mNum_loops);
if (nfrac - mCastbar_progress > 1.0f/200.0f)
{
mCastbar_progress = (nfrac < 1.0f) ? nfrac : 1.0f;
onCastingProgressUpdate_callback(mCastbar_progress);
}
}
}
void CastingPhrase_C::stop(F32 timestamp)
{
Parent::stop(timestamp);
if (mCastbar_progress)
{
onCastingEnd_callback();
mNotify_castbar = false;
}
}
void CastingPhrase_C::interrupt(F32 timestamp)
{
Parent::interrupt(timestamp);
if (mNotify_castbar)
{
onCastingEnd_callback();
mNotify_castbar = false;
}
}
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
// some enum to name converters for debugging purposes
#ifdef USE_FOR_DEBUG_MESSAGES
static char* name_from_state(U8 s)
{
switch (s)
{
case afxMagicSpell::INACTIVE_STATE:
return "inactive";
case afxMagicSpell::CASTING_STATE:
return "casting";
case afxMagicSpell::DELIVERY_STATE:
return "delivery";
case afxMagicSpell::LINGER_STATE:
return "linger";
case afxMagicSpell::CLEANUP_STATE:
return "cleanup";
case afxMagicSpell::DONE_STATE:
return "done";
}
return "unknown";
}
static char* name_from_event(U8 e)
{
switch (e)
{
case afxMagicSpell::NULL_EVENT:
return "null";
case afxMagicSpell::ACTIVATE_EVENT:
return "activate";
case afxMagicSpell::LAUNCH_EVENT:
return "launch";
case afxMagicSpell::IMPACT_EVENT:
return "impact";
case afxMagicSpell::SHUTDOWN_EVENT:
return "shutdown";
case afxMagicSpell::DEACTIVATE_EVENT:
return "deactivate";
case afxMagicSpell::INTERRUPT_PHASE_EVENT:
return "interrupt_phase";
case afxMagicSpell::INTERRUPT_SPELL_EVENT:
return "interrupt_spell";
}
return "unknown";
}
#endif
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
// afxMagicSpell
IMPLEMENT_CO_NETOBJECT_V1(afxMagicSpell);
ConsoleDocClass( afxMagicSpell,
"@brief A magic spell effects choreographer.\n\n"
"@ingroup afxChoreographers\n"
"@ingroup AFX\n"
);
// static
StringTableEntry afxMagicSpell::CASTER_CONS;
StringTableEntry afxMagicSpell::TARGET_CONS;
StringTableEntry afxMagicSpell::MISSILE_CONS;
StringTableEntry afxMagicSpell::CAMERA_CONS;
StringTableEntry afxMagicSpell::LISTENER_CONS;
StringTableEntry afxMagicSpell::IMPACT_POINT_CONS;
StringTableEntry afxMagicSpell::IMPACTED_OBJECT_CONS;
void afxMagicSpell::init()
{
// setup static predefined constraint names
if (CASTER_CONS == 0)
{
CASTER_CONS = StringTable->insert("caster");
TARGET_CONS = StringTable->insert("target");
MISSILE_CONS = StringTable->insert("missile");
CAMERA_CONS = StringTable->insert("camera");
LISTENER_CONS = StringTable->insert("listener");
IMPACT_POINT_CONS = StringTable->insert("impactPoint");
IMPACTED_OBJECT_CONS = StringTable->insert("impactedObject");
}
// afxMagicSpell is always in scope, however effects
// do their own scoping in that they will shut off if
// their position constraint leaves scope.
//
// note -- ghosting is delayed until constraint
// initialization is done.
//
//mNetFlags.set(Ghostable | ScopeAlways);
mNetFlags.clear(Ghostable | ScopeAlways);
mDatablock = NULL;
mExeblock = NULL;
mMissile_db = NULL;
mCaster = NULL;
mTarget = NULL;
mCaster_field = NULL;
mTarget_field = NULL;
mCaster_scope_id = 0;
mTarget_scope_id = 0;
mTarget_is_shape = false;
mConstraints_initialized = false;
mScoping_initialized = false;
mSpell_state = (U8) INACTIVE_STATE;
mSpell_elapsed = 0;
// define named constraints
constraint_mgr->defineConstraint(OBJECT_CONSTRAINT, CASTER_CONS);
constraint_mgr->defineConstraint(OBJECT_CONSTRAINT, TARGET_CONS);
constraint_mgr->defineConstraint(OBJECT_CONSTRAINT, MISSILE_CONS);
constraint_mgr->defineConstraint(CAMERA_CONSTRAINT, CAMERA_CONS);
constraint_mgr->defineConstraint(POINT_CONSTRAINT, LISTENER_CONS);
constraint_mgr->defineConstraint(POINT_CONSTRAINT, IMPACT_POINT_CONS);
constraint_mgr->defineConstraint(OBJECT_CONSTRAINT, IMPACTED_OBJECT_CONS);
for (S32 i = 0; i < NUM_PHRASES; i++)
{
mPhrases[i] = NULL;
mTfactors[i] = 1.0f;
}
mNotify_castbar = false;
mOverall_time_factor = 1.0f;
mCamera_cons_obj = 0;
mMarks_mask = 0;
mMissile = NULL;
mMissile_is_armed = false;
mImpacted_obj = NULL;
mImpact_pos.zero();
mImpact_norm.set(0,0,1);
mImpacted_scope_id = 0;
mImpacted_is_shape = false;
}
afxMagicSpell::afxMagicSpell()
{
started_with_newop = true;
init();
}
afxMagicSpell::afxMagicSpell(ShapeBase* caster, SceneObject* target)
{
started_with_newop = false;
init();
mCaster = caster;
if (caster)
{
mCaster_field = caster;
deleteNotify(caster);
processAfter(caster);
}
mTarget = target;
if (target)
{
mTarget_field = target;
deleteNotify(target);
}
}
afxMagicSpell::~afxMagicSpell()
{
for (S32 i = 0; i < NUM_PHRASES; i++)
{
if (mPhrases[i])
{
mPhrases[i]->interrupt(mSpell_elapsed);
delete mPhrases[i];
}
}
if (mMissile)
mMissile->deleteObject();
if (mMissile_db && mMissile_db->isTempClone())
{
delete mMissile_db;
mMissile_db = 0;
}
if (mDatablock && mDatablock->isTempClone())
{
delete mDatablock;
mDatablock = 0;
}
}
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
// STANDARD OVERLOADED METHODS //
bool afxMagicSpell::onNewDataBlock(GameBaseData* dptr, bool reload)
{
mDatablock = dynamic_cast<afxMagicSpellData*>(dptr);
if (!mDatablock || !Parent::onNewDataBlock(dptr, reload))
return false;
if (isServerObject() && started_with_newop)
{
// copy dynamic fields from the datablock but
// don't replace fields with a value
assignDynamicFieldsFrom(dptr, arcaneFX::sParameterFieldPrefix, true);
}
mExeblock = mDatablock;
mMissile_db = mDatablock->mMissile_db;
if (isClientObject())
{
// make a temp datablock clone if there are substitutions
if (mDatablock->getSubstitutionCount() > 0)
{
afxMagicSpellData* orig_db = mDatablock;
mDatablock = new afxMagicSpellData(*orig_db, true);
mExeblock = orig_db;
mMissile_db = mDatablock->mMissile_db;
// Don't perform substitutions yet, the spell's dynamic fields haven't
// arrived yet and the substitutions may refer to them. Hold off and do
// in in the onAdd() method.
}
}
else if (started_with_newop)
{
// make a temp datablock clone if there are substitutions
if (mDatablock->getSubstitutionCount() > 0)
{
afxMagicSpellData* orig_db = mDatablock;
mDatablock = new afxMagicSpellData(*orig_db, true);
mExeblock = orig_db;
orig_db->performSubstitutions(mDatablock, this, ranking);
mMissile_db = mDatablock->mMissile_db;
}
}
return true;
}
void afxMagicSpell::processTick(const Move* m)
{
Parent::processTick(m);
// don't process moves or client ticks
if (m != 0 || isClientObject())
return;
process_server();
}
void afxMagicSpell::advanceTime(F32 dt)
{
Parent::advanceTime(dt);
process_client(dt);
}
bool afxMagicSpell::onAdd()
{
if (!Parent::onAdd())
return false ;
if (isClientObject())
{
if (mDatablock->isTempClone())
{
afxMagicSpellData* orig_db = (afxMagicSpellData*)mExeblock;
orig_db->performSubstitutions(mDatablock, this, ranking);
mMissile_db = mDatablock->mMissile_db;
mNotify_castbar = (mNotify_castbar && (mDatablock->mCasting_dur > 0.0f));
}
}
else if (started_with_newop && !postpone_activation)
{
if (!activationCallInit())
return false;
activate();
}
return true ;
}
void afxMagicSpell::onRemove()
{
Parent::onRemove();
}
void afxMagicSpell::onDeleteNotify(SimObject* obj)
{
// caster deleted?
ShapeBase* shape = dynamic_cast<ShapeBase*>(obj);
if (shape == mCaster)
{
clearProcessAfter();
mCaster = NULL;
mCaster_field = NULL;
mCaster_scope_id = 0;
}
// target deleted?
SceneObject* scene_obj = dynamic_cast<SceneObject*>(obj);
if (scene_obj == mTarget)
{
mTarget = NULL;
mTarget_field = NULL;
mTarget_scope_id = 0;
mTarget_is_shape = false;
}
// impacted_obj deleted?
if (scene_obj == mImpacted_obj)
{
mImpacted_obj = NULL;
mImpacted_scope_id = 0;
mImpacted_is_shape = false;
}
// missile deleted?
afxMagicMissile* missile = dynamic_cast<afxMagicMissile*>(obj);
if (missile != NULL && missile == mMissile)
{
mMissile = NULL;
}
// something else
Parent::onDeleteNotify(obj);
}
// static
void afxMagicSpell::initPersistFields()
{
addField("caster", TYPEID<SimObject>(), Offset(mCaster_field, afxMagicSpell),
"...");
addField("target", TYPEID<SimObject>(), Offset(mTarget_field, afxMagicSpell),
"...");
Parent::initPersistFields();
}
//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
void afxMagicSpell::pack_constraint_info(NetConnection* conn, BitStream* stream)
{
// pack caster's ghost index or scope id if not yet ghosted
if (stream->writeFlag(mCaster != NULL))
{
S32 ghost_idx = conn->getGhostIndex(mCaster);
if (stream->writeFlag(ghost_idx != -1))
stream->writeRangedU32(U32(ghost_idx), 0, NetConnection::MaxGhostCount);