aboutsummaryrefslogtreecommitdiff
path: root/src/parsec/g_wfx.cpp
blob: 1f8f02fbee3e6864692c85e9c85983b65111ae95 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
/*
 * PARSEC - Weapons Effects
 *
 * $Author: uberlinuxguy $ - $Date: 2004/09/26 03:43:37 $
 *
 * Orginally written by:
 *   Copyright (c) Markus Hadwiger     <msh@parsec.org>   1997-1999
 *   Copyright (c) Michael Woegerbauer <maiki@parsec.org> 1999-2000
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */ 

// C library
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// compilation flags/debug support
#include "config.h"
#include "debug.h"

// general definitions
#include "general.h"
#include "objstruc.h"

// global externals
#include "globals.h"

// subsystem headers
#include "aud_defs.h"
#include "net_defs.h"
#include "vid_defs.h"

// mathematics header
#include "utl_math.h"

// particle types
#include "parttype.h"

// local module header
#include "g_wfx.h"

// proprietary module headers
#include "con_aux.h"
#include "e_color.h"
#include "e_record.h"
#include "h_supp.h"
#include "obj_ctrl.h"
#include "obj_game.h"
#include "part_ani.h"
#include "part_api.h"
#include "part_def.h"



// flags
#define SECOND_HELIX



// lightning energy properties
#define MIN_LIGHTNING_ENERGY				10
#define LIGHTNING_ENERGY_CONSUMPTION		7000          // 65536 = 1.0

// properties of lightning particles
#define LIGHTNING_BM_INDX					BM_LIGHTNING1 //BM_FIREBALL2 //BM_LIGHTNING1
#define LIGHTNING_REF_Z						9.0f // 30.0f // 150.0f
#define LIGHTNING_PARTICLE_COLOR			255
#define LIGHTNING_SIZZLE_SPEED				60

// spread energy properties
#define MIN_SPREAD_ENERGY					10
#define SPREAD_ENERGY_CONSUMPTION			2

// helix energy properties
#define MIN_HELIX_ENERGY					10
#define HELIX_ENERGY_CONSUMPTION			2

// properties of spreadfire particles
#define SPREADFIRE_PARTICLE_COLOR			174
#define SPREADFIRE_BM_INDX					BM_FIREBALL1
#define SPREADFIRE_REF_Z					20.0f //400.0f

// photon properties
#define MIN_PHOTON_ENERGY                    10
#define PHOTON_ENERGY_CONSUMPTION           0x6000  // 0x10000 = 1.0

#define PHOTON_ROT_PITCH					0x0015  //0x01a0
#define PHOTON_ROT_YAW						-0x0022 //-0x02a0
#define PHOTON_ROT_ROLL						0x000d  //0x0100

#define PHOTON_SPHERE_PARTICLES				256
#define PHOTON_COLOR						123
#define PHOTON_REF_Z						75.0
#define PHOTON_CONTRACTION_TIME				50
#define PHOTON_CONTRACTION_SPEED			FIXED_TO_GEOMV( 0xA000 )
#define PHOTON_MAX_LOADING_TIME				1800
#define PHOTON_NUMLOADS						32



// string constants -----------------------------------------------------------
//
static char no_spreadfire_str[]		= "no spreadfire gun";
static char no_helixcannon_str[]	= "no helix cannon";
static char no_lightning_str[]		= "no lightning device";
static char no_photoncannon_str[]   = "no photon cannon";
static char low_energy_str[]		= "low energy";


// reference z values for particles -------------------------------------------
//
float	spreadfire_ref_z			= 1.0f;
float lightning_ref_z				= 1.0f;
float photon_ref_z                = 1.0f;


// helix props ----------------------------------------------------------------
//
bams_t  HelixBamsInc			= 0x1500;
int     HelixRefFrames			= 10;                     // create one particle every ... frames
geomv_t HelixRadius				= INT_TO_GEOMV( 10 );


// init reference z values for particles according to resolution --------------
//
void WFX_InitParticleSizes( float resoscale )
{
	spreadfire_ref_z = resoscale * SPREADFIRE_REF_Z;
	lightning_ref_z  = resoscale * LIGHTNING_REF_Z;
    photon_ref_z     = resoscale * PHOTON_REF_Z;
}


// create one load of spreadfire particles ------------------------------------
//
PRIVATE
int ShootSpreadfire( ShipObject *shippo, int owner )
{
	ASSERT( shippo != NULL );

	int bitmap	  = SPREADFIRE_BM_INDX;
	int color	  = SPREADFIRE_PARTICLE_COLOR;
	float ref_z = spreadfire_ref_z;
	int sizebound = partbitmap_size_bound;
	int lifetime  = shippo->SpreadLifeTime;

	pextinfo_s extinfo;
	pextinfo_s *pextinfo = NULL;

	if ( AUX_SPREADFIRE_PARTICLES_EXTINFO ) {

		// alter basic attributes
		ref_z    *= 2;
		bitmap    = iter_texrgba | iter_specularadd;
		sizebound = PRT_NO_SIZEBOUND;

		// fetch pdef
		pdef_s *pdef;
		pdef = PDEF_pflare01();
		if ( pdef == NULL ) {
			MSGOUT( "spreadfire particles invalid." );
			return FALSE;
		}

		// create pextinfo
		pextinfo = &extinfo;
		PRT_InitParticleExtInfo( pextinfo, pdef, NULL, NULL );
	}

	if ( shippo->CurEnergy < MIN_SPREAD_ENERGY + SPREAD_ENERGY_CONSUMPTION ) {
		if ( shippo == MyShip ) {
			ShowMessage( low_energy_str );
			AUD_LowEnergy();
		}
		return FALSE;
	}
	shippo->CurEnergy -= SPREAD_ENERGY_CONSUMPTION;

	// first particle ---
	Vertex3 object_space;
	object_space.X = shippo->Spread_X[ 0 ];
	object_space.Y = shippo->Spread_Y;
	object_space.Z = shippo->Spread_Z;

	Vertex3 world_space;
	MtxVctMUL( shippo->ObjPosition, &object_space, &world_space );

	Vector3 dirvec;
	fixed_t speed = shippo->SpreadSpeed + shippo->CurSpeed;
	DirVctMUL( shippo->ObjPosition, FIXED_TO_GEOMV( speed ), &dirvec );

	particle_s particle;
	PRT_InitParticle( particle, bitmap, color, sizebound,
					  ref_z, &world_space, &dirvec,
					  lifetime, owner, pextinfo );
	PRT_CreateLinearParticle( particle );

	// second particle ---
	object_space.X = shippo->Spread_X[ 3 ];
	MtxVctMUL( shippo->ObjPosition, &object_space, &world_space );

	PRT_InitParticle( particle, bitmap, color, sizebound,
					  ref_z, &world_space, &dirvec,
					  lifetime, owner, pextinfo );
	PRT_CreateLinearParticle( particle );

	// play sound
	AUD_Laser( NULL );

	return TRUE;
}


// create particles of particle weapon originating from specified position ----
//
int WFX_ShootParticleWeapon( ShipObject *shippo, int type )
{
	ASSERT( shippo != NULL );

	// check if enough space in RE_List
	if ( !NET_RmEvAllowed( RE_PARTICLEOBJECT ) )
		return FALSE;

	if ( type == PARTICLEGUN_SPREADFIRE ) {

		if ( !OBJ_DeviceAvailable( shippo, WPMASK_ALIAS_SPREADFIRE ) ) {
			ShowMessage( no_spreadfire_str );
			return FALSE;
		}

		// just return if not able to create spreadfire particles
		if ( !ShootSpreadfire( shippo, LocalPlayerId ) ) {
			return FALSE;
		}

		// insert remote event
		Vertex3 dummyorigin;
		NET_RmEvParticleObject( POBJ_SPREADFIRE, dummyorigin );

		// record create event if recording active
		Record_SpreadFireFiring();

		return TRUE;
	}

	return FALSE;
}


// remote player shot spreadfire ----------------------------------------------
//
void WFX_RemoteShootSpreadfire( int playerid )
{
	// fetch pointer to remote player's ship
	ShipObject *shippo = NET_FetchOwnersShip( playerid );
	ASSERT( shippo != NULL );
	ASSERT( shippo != MyShip );

	// currently same as local
	ShootSpreadfire( shippo, playerid );
}



// ----------------------------------------------------------------------------
// HELIX STUFF
// ----------------------------------------------------------------------------


// create helix particles for current frame -----------------------------------
//
int WFX_MaintainHelix( ShipObject *shippo, int playerid )
{
	ASSERT( shippo != NULL );

	int bitmap	  = SPREADFIRE_BM_INDX;
	int color	  = SPREADFIRE_PARTICLE_COLOR;
	float ref_z = spreadfire_ref_z;
	int sizebound = partbitmap_size_bound;
	int lifetime  = shippo->HelixLifeTime;

	pextinfo_s extinfo;
	pextinfo_s *pextinfo = NULL;

	if ( AUX_SPREADFIRE_PARTICLES_EXTINFO ) {

		// alter basic attributes
		ref_z    *= 2;
		bitmap    = iter_texrgba | iter_specularadd;
		sizebound = PRT_NO_SIZEBOUND;

		// fetch pdef
		pdef_s *pdef;
		pdef = PDEF_pflare06();
		if ( pdef == NULL ) {
			MSGOUT( "helix particles invalid." );
			shippo->WeaponsActive &= ~WPMASK_CANNON_HELIX;
			AUD_HelixOff( shippo );
			return FALSE;
		}

		// create pextinfo
		pextinfo = &extinfo;
		PRT_InitParticleExtInfo( pextinfo, pdef, NULL, NULL );
	}

	// calc number of particles according to time passed (remember remainder)
	refframe_t numrefframes		  = CurScreenRefFrames + shippo->helix_refframes_delta;
	int numparticles			  = numrefframes / HelixRefFrames;
	shippo->helix_refframes_delta = numrefframes % HelixRefFrames;

	Vector3 dirvec;
	fixed_t speed = shippo->HelixSpeed + shippo->CurSpeed;
	DirVctMUL( shippo->ObjPosition, FIXED_TO_GEOMV( speed ), &dirvec );

	for ( int curp = 0; curp < numparticles; curp++ ) {

		// check if enough energy to shoot helix
		if ( shippo->CurEnergy < MIN_HELIX_ENERGY + HELIX_ENERGY_CONSUMPTION ) {

			WFX_DeactivateHelix( shippo );

			if ( shippo == MyShip ) {
				ShowMessage( low_energy_str );
				AUD_LowEnergy();
			}

			return FALSE;
		}
		shippo->CurEnergy -= HELIX_ENERGY_CONSUMPTION;

		sincosval_s resultp;
		GetSinCos( shippo->HelixCurBams, &resultp );

		// create oldest particle first
		int		invcurp = numparticles - curp - 1;
		fixed_t timefrm = invcurp * HelixRefFrames + shippo->helix_refframes_delta;
		fixed_t timepos = timefrm * shippo->HelixSpeed;

		// create one full frame set back because the current frame will
		// be added by the linear particle animation code in the same frame
		timepos -= speed * CurScreenRefFrames;

		Vector3 pofsvec;
		pofsvec.X = GEOMV_MUL( HelixRadius, resultp.sinval );
		pofsvec.Y = GEOMV_MUL( HelixRadius, resultp.cosval );
		pofsvec.Z = FIXED_TO_GEOMV( timepos );

		// first particle ---
		Vertex3 object_space;
		object_space.X = shippo->Helix_X + pofsvec.X;
		object_space.Y = shippo->Helix_Y + pofsvec.Y;
		object_space.Z = shippo->Helix_Z + pofsvec.Z;

		Vertex3 world_space;
		MtxVctMUL( shippo->ObjPosition, &object_space, &world_space );

		particle_s particle;
		PRT_InitParticle( particle, bitmap, color, sizebound,
						  ref_z, &world_space, &dirvec,
						  lifetime, playerid, pextinfo );
		particle.flags |= PARTICLE_COLLISION;
		PRT_CreateLinearParticle( particle );

		// second particle ---
		object_space.X = shippo->Helix_X - pofsvec.X;
#ifdef SECOND_HELIX
		object_space.Y = shippo->Helix_Y - pofsvec.Y;
#else
		object_space.Y = shippo->Helix_Y + pofsvec.Y;
#endif
		MtxVctMUL( shippo->ObjPosition, &object_space, &world_space );

		PRT_InitParticle( particle, bitmap, color, sizebound,
					  	  ref_z, &world_space, &dirvec,
					  	  lifetime, playerid, pextinfo );
		particle.flags |= PARTICLE_COLLISION;
		particle.flags |= PARTICLE_IS_HELIX;
		PRT_CreateLinearParticle( particle );

		shippo->HelixCurBams = ( shippo->HelixCurBams + HelixBamsInc ) & 0xffff;
	}

	return TRUE;
}


// activate helix cannon of local ship ----------------------------------------
//
int	WFX_ActivateHelix( ShipObject *shippo )
{
	ASSERT( shippo != NULL );
	ASSERT( shippo == MyShip );
	ASSERT( ( shippo->WeaponsActive & WPMASK_CANNON_HELIX ) == 0 );

	// check if enough space in RE_List
	if ( !NET_RmEvAllowed( RE_WEAPONSTATE ) )
		return FALSE;

	// check if helix available
	if ( !OBJ_DeviceAvailable( shippo, WPMASK_CANNON_HELIX ) ) {
		ShowMessage( no_helixcannon_str );
		return FALSE;
	}

	// check if enough energy to shoot helix
	if ( shippo->CurEnergy < MIN_HELIX_ENERGY + HELIX_ENERGY_CONSUMPTION ) {
		ShowMessage( low_energy_str );
		AUD_LowEnergy();
		return FALSE;
	}

	// set active flag
	shippo->WeaponsActive |= WPMASK_CANNON_HELIX;

	// send remote event to switch helix on
	NET_RmEvWeaponState( WPMASK_CANNON_HELIX, WPSTATE_ON, shippo->CurEnergy, shippo->Specials );

	// record activation event if recording active
	Record_HelixActivation();

	// play sound
	AUD_Helix( shippo );

	return TRUE;
}


// deactivate helix cannon of specified ship ----------------------------------
//
void WFX_DeactivateHelix( ShipObject *shippo )
{
	ASSERT( shippo != NULL );
	ASSERT( shippo->WeaponsActive & WPMASK_CANNON_HELIX );

	// local ship is special case
	if ( shippo == MyShip ) {

		// check if enough space in RE_List
		if ( !NET_RmEvAllowed( RE_WEAPONSTATE ) )
			return;

		// send remote event to switch helix off
		NET_RmEvWeaponState( WPMASK_CANNON_HELIX, WPSTATE_OFF, shippo->CurEnergy, shippo->Specials );

		// record deactivation event if recording active
		Record_HelixDeactivation();
	}

	// reset activation flag
	shippo->WeaponsActive &= ~WPMASK_CANNON_HELIX;

	// stop sound
	AUD_HelixOff( shippo );
}


// remote player activated helix cannon ---------------------------------------
//
void WFX_RemoteActivateHelix( int playerid )
{
	// fetch pointer to remote player's ship
	ShipObject *shippo = NET_FetchOwnersShip( playerid );
	ASSERT( shippo != NULL );
	ASSERT( shippo != MyShip );

	// make sure helix cannon is active
	if ( ( shippo->WeaponsActive & WPMASK_CANNON_HELIX ) == 0 ) {

		// avoid additional stuff that would be done
		// by WFX_ActivateHelix()
		shippo->WeaponsActive |= WPMASK_CANNON_HELIX;
		AUD_Helix( shippo );
	}
}


// remote player deactivated helix cannon -------------------------------------
//
void WFX_RemoteDeactivateHelix( int playerid )
{
	// fetch pointer to remote player's ship
	ShipObject *shippo = NET_FetchOwnersShip( playerid );
	ASSERT( shippo != NULL );
	ASSERT( shippo != MyShip );

	// make sure helix cannon is inactive
	if ( shippo->WeaponsActive & WPMASK_CANNON_HELIX ) {

		// sound will also be switched off by this
		WFX_DeactivateHelix( shippo );
	}
}


// ensure that helix cannon is inactive for local ship ------------------------
//
void WFX_EnsureHelixInactive( ShipObject *shippo )
{
	ASSERT( shippo != NULL );
	ASSERT( shippo == MyShip );

	if ( shippo->WeaponsActive & WPMASK_CANNON_HELIX ) {
		shippo->WeaponsActive &= ~WPMASK_CANNON_HELIX;
		AUD_HelixOff( shippo );
	}

	ASSERT( ( shippo->WeaponsActive & WPMASK_CANNON_HELIX ) == 0 );
}



// ----------------------------------------------------------------------------
// LIGHTNING STUFF
// ----------------------------------------------------------------------------


// create two lightning beams -------------------------------------------------
//
PRIVATE
lightning_pcluster_s *CreateLightningParticles( ShipObject *shippo, int owner )
{
	ASSERT( shippo != NULL );

	// create appearance
	int bitmap	  = LIGHTNING_BM_INDX;
	int color	  = LIGHTNING_PARTICLE_COLOR;
	float ref_z = lightning_ref_z;
	int sizebound = partbitmap_size_bound;

	pextinfo_s extinfo;

	if ( AUX_LIGHTNING_PARTICLES_EXTINFO ) {

		// alter basic attributes
		ref_z    *= 2;
		bitmap    = iter_texrgba | iter_specularadd;
		sizebound = PRT_NO_SIZEBOUND;

		// fetch pdef
		pdef_s *pdef = PDEF_plight01();
		if ( pdef == NULL ) {
			MSGOUT( "lightning particles invalid." );
			return NULL;
		}

		// create pextinfo
		PRT_InitParticleExtInfo( &extinfo, pdef, NULL, NULL );
	}

	// create cluster
	dword clustertype = CT_LIGHTNING;

	if ( AUX_LIGHTNING_PARTICLES_EXTINFO )
		clustertype |= CT_EXTINFO_STORAGE;

	lightning_pcluster_s *cluster = (lightning_pcluster_s *)
		PRT_NewCluster( clustertype, LIGHTNING_LENGTH * 2, 0 );

	// fill in basic fields
	cluster->animtype	 = SAT_LIGHTNING;
	cluster->sizzlespeed = LIGHTNING_SIZZLE_SPEED;

	Vertex3 startpos;

	startpos.X = shippo->Beam_X[ 0 ];
	startpos.Y = shippo->Beam_Y;
	startpos.Z = shippo->Beam_Z;
	cluster->beamstart1 = startpos;

	startpos.X = shippo->Beam_X[ 3 ];
	cluster->beamstart2 = startpos;

	// create particles

	int curp = 0;
	if ( AUX_LIGHTNING_PARTICLES_EXTINFO ) {
		for ( curp = 0; curp < LIGHTNING_LENGTH; curp++ ) {

			pextinfo_s *curextinfo =
				(pextinfo_s *)( cluster->rep + cluster->maxnumel ) + curp;
			memcpy( curextinfo, &extinfo, sizeof( pextinfo_s ) );

			PRT_InitClusterParticle( cluster, curp, bitmap, color,
									 sizebound, ref_z,
						 	 		 &cluster->beamstart1, NULL,
						 	 		 INFINITE_LIFETIME, owner,
									 curextinfo );
		}

		for ( ; curp < LIGHTNING_LENGTH * 2; curp++ ) {

			pextinfo_s *curextinfo =
				(pextinfo_s *)( cluster->rep + cluster->maxnumel ) + curp;
			memcpy( curextinfo, &extinfo, sizeof( pextinfo_s ) );

			PRT_InitClusterParticle( cluster, curp, bitmap, color,
									 sizebound, ref_z,
						 	 		 &cluster->beamstart2, NULL,
						 	 		 INFINITE_LIFETIME, owner,
									 curextinfo );
		}

	} else {
		
		for ( curp = 0; curp < LIGHTNING_LENGTH; curp++ )
			PRT_InitClusterParticle( cluster, curp, bitmap, color,
									 sizebound, ref_z,
						 	 		 &cluster->beamstart1, NULL,
						 	 		 INFINITE_LIFETIME, owner,
									 NULL );
		for ( ; curp < LIGHTNING_LENGTH * 2; curp++ )
			PRT_InitClusterParticle( cluster, curp, bitmap, color,
									 sizebound, ref_z,
						 	 		 &cluster->beamstart2, NULL,
						 	 		 INFINITE_LIFETIME, owner,
									 NULL );
	}

	// attach lightning particle cluster to ship
	PRT_AttachClusterToObject( shippo, cluster );

	return cluster;
}


// activate lightning device of local ship ------------------------------------
//
int	WFX_ActivateLightning( ShipObject *shippo )
{
	ASSERT( shippo != NULL );
	ASSERT( shippo == MyShip );
	ASSERT( ( shippo->WeaponsActive & WPMASK_CANNON_LIGHTNING ) == 0 );

	// check if enough space in RE_List
	if ( !NET_RmEvAllowed( RE_WEAPONSTATE ) )
		return FALSE;

	// check if lightning device available
	if ( !OBJ_DeviceAvailable( shippo, WPMASK_CANNON_LIGHTNING ) ) {
		ShowMessage( no_lightning_str );
		return FALSE;
	}

	dword energy_consumption = shippo->CurEnergyFrac +
		( CurScreenRefFrames * LIGHTNING_ENERGY_CONSUMPTION );

	// check if enough energy to shoot lightning
	if ( (dword)shippo->CurEnergy < ( MIN_LIGHTNING_ENERGY + ( energy_consumption >> 16 ) ) ) {
		ShowMessage( low_energy_str );
		AUD_LowEnergy();
		return FALSE;
	}

	// attach lightning particle cluster
	ASSERT( PRT_ObjectHasAttachedClustersOfType( shippo, SAT_LIGHTNING ) == NULL );
	if ( CreateLightningParticles( shippo, LocalPlayerId ) == NULL ) {
		return FALSE;
	}

	// set activation flag
	shippo->WeaponsActive |= WPMASK_CANNON_LIGHTNING;

	// send remote event to switch lightning on
	NET_RmEvWeaponState( WPMASK_CANNON_LIGHTNING, WPSTATE_ON, shippo->CurEnergy, shippo->Specials );

	// record activation event if recording active
	Record_LightningActivation();

	// play sound
	AUD_Lightning( shippo );

	// signify that lightning is now active
	return TRUE;
}


// deactivate lightning device of specified ship ------------------------------
//
void WFX_DeactivateLightning( ShipObject *shippo )
{
	ASSERT( shippo != NULL );
	ASSERT( shippo->WeaponsActive & WPMASK_CANNON_LIGHTNING );

	// local ship is special case
	if ( shippo == MyShip ) {

		// check if enough space in RE_List
		if ( !NET_RmEvAllowed( RE_WEAPONSTATE ) )
			return;

		// send remote event to switch lightning off
		NET_RmEvWeaponState( WPMASK_CANNON_LIGHTNING, WPSTATE_OFF, shippo->CurEnergy, shippo->Specials );

		// record deactivation event if recording active
		Record_LightningDeactivation();
	}

	// remove lightning particles
	PRT_DeleteAttachedClustersOfType( shippo, SAT_LIGHTNING );

	// reset activation flag
	shippo->WeaponsActive &= ~WPMASK_CANNON_LIGHTNING;

	// stop sound
	AUD_LightningOff( shippo );
}


// remote player activated lightning device -----------------------------------
//
void WFX_RemoteActivateLightning( int playerid )
{
	// fetch pointer to remote player's ship
	ShipObject *shippo = NET_FetchOwnersShip( playerid );
	ASSERT( shippo != NULL );
	ASSERT( shippo != MyShip );

	// make sure lightning device is active
	if ( ( shippo->WeaponsActive & WPMASK_CANNON_LIGHTNING ) == 0 ) {

		// avoid additional stuff that would be done
		// by WFX_ActivateLightning()
		if ( CreateLightningParticles( shippo, playerid ) != NULL ) {
			shippo->WeaponsActive |= WPMASK_CANNON_LIGHTNING;
			AUD_Lightning( shippo );
		}
	}
}


// remote player deactivated lightning device ---------------------------------
//
void WFX_RemoteDeactivateLightning( int playerid )
{
	// fetch pointer to remote player's ship
	ShipObject *shippo = NET_FetchOwnersShip( playerid );
	ASSERT( shippo != NULL );
	ASSERT( shippo != MyShip );

	// make sure lightning device is inactive
	if ( ( shippo->WeaponsActive & WPMASK_CANNON_LIGHTNING ) != 0 ) {

		// sound will also be switched off by this
		WFX_DeactivateLightning( shippo );
	}
}


// ensure that lightning is inactive for local ship ---------------------------
//
void WFX_EnsureLightningInactive( ShipObject *shippo )
{
	ASSERT( shippo != NULL );
	ASSERT( shippo == MyShip );

	if ( PRT_DeleteAttachedClustersOfType( shippo, SAT_LIGHTNING ) != 0 ) {
		shippo->WeaponsActive &= ~WPMASK_CANNON_LIGHTNING;
		AUD_LightningOff( shippo );
	}

	ASSERT( ( shippo->WeaponsActive & WPMASK_CANNON_LIGHTNING ) == 0 );
}


// check whether to turn off lightning due to too little energy ---------------
//
void WFX_MaintainLightning( ShipObject *shippo )
{
	ASSERT( shippo != NULL );
	ASSERT( shippo->WeaponsActive & WPMASK_CANNON_LIGHTNING );

	dword energy_consumption = shippo->CurEnergyFrac +
		( CurScreenRefFrames * LIGHTNING_ENERGY_CONSUMPTION );

	// check if enough energy to shoot lightning
	if ( (dword)shippo->CurEnergy < ( MIN_LIGHTNING_ENERGY + ( energy_consumption >> 16 ) ) ) {

		WFX_DeactivateLightning( shippo );

		if ( shippo == MyShip ) {
			ShowMessage( low_energy_str );
			AUD_LowEnergy();
		}

	} else {

		shippo->CurEnergyFrac = ( energy_consumption & 0xffff );
		shippo->CurEnergy    -= ( energy_consumption >> 16 );
	}
}


// ensure that no particle weapons are active for local ship ------------------
//
void WFX_EnsureParticleWeaponsInactive( ShipObject *shippo )
{
	ASSERT( shippo != NULL );
	ASSERT( shippo == MyShip );

	// ensure lightning and helix are destroyed
	WFX_EnsureLightningInactive( shippo );
	WFX_EnsureHelixInactive( shippo );
}



// ----------------------------------------------------------------------------
// PHOTON CANNON STUFF
// ----------------------------------------------------------------------------


// calc animation of photon sphere --------------------------------------------
//
void WFX_CalcPhotonSphereAnimation( photon_sphere_pcluster_s *cluster )
{
	ASSERT( cluster != NULL );
    ASSERT( ( cluster->type & CT_TYPEMASK ) == CT_PHOTON_SPHERE );

    ShipObject *shippo = (ShipObject *) cluster->baseobject;

    float part_prf = ( cluster->max_loading_time / cluster->maxnumel );
	Vertex3 old_center;
	geomv_t contraction;

    if ( !cluster->firing ) {

        // determine maximum remaining loading time
        int working_time = cluster->max_loading_time - cluster->alive;

        // determine actual loading time
        if ( working_time > CurScreenRefFrames ) {
            working_time = CurScreenRefFrames;
        }
        cluster->alive += working_time;

        dword energy_consumption = shippo->CurEnergyFrac +
            ( working_time * PHOTON_ENERGY_CONSUMPTION );

        // check if enough energy to build
        if ( (dword)shippo->CurEnergy < ( MIN_PHOTON_ENERGY + energy_consumption >> 16 ) ) {
            cluster->alive = (int)(cluster->alive -( working_time - ( shippo->CurEnergy - MIN_PHOTON_ENERGY ) /
                            FIXED_TO_FLOAT( PHOTON_ENERGY_CONSUMPTION ) ));
            shippo->CurEnergy = MIN_PHOTON_ENERGY - 1;
            WFX_DeactivatePhoton( shippo );
        } else {
            shippo->CurEnergyFrac = ( energy_consumption & 0xffff );
            shippo->CurEnergy    -= ( energy_consumption >> 16 );
        }

        // calculate number of visible particles
        if ( ( cluster->alive < cluster->max_loading_time ) ) {
            cluster->numel = (int)( cluster->alive / part_prf );
            if ( cluster->numel == 0 ) {
                // at least one particle must be visible
                cluster->numel = 1;
            }
        }
        else {
            cluster->numel = cluster->maxnumel;

            //NOTE:
            // CurScreenRefFrames get added some lines below anyway,
            // so we must not add them here
            cluster->cur_contraction_time -= working_time;

            WFX_DeactivatePhoton( shippo );
        }
    }

    if ( cluster->firing ) {

        // increase counter
        cluster->cur_contraction_time += CurScreenRefFrames;

        // create linear particles

        // number of particles in full load
        int single_load = ( cluster->maxnumel / cluster->numloads );
        int old_numel = cluster->numel;

        // number of full loads to be created
        int numloads = ( cluster->cur_contraction_time / cluster->contraction_time );
        // minimize on full loads available
        if ( numloads > ( old_numel / single_load ) ) {
            numloads = ( old_numel / single_load );
        }

        // set particle properties
        int bitmap    = iter_texrgba | iter_specularadd;
        int color     = PHOTON_COLOR;
        float ref_z = photon_ref_z;
        int sizebound = PRT_NO_SIZEBOUND;
        int lifetime  = shippo->PhotonLifeTime;
        int playerid  = GetObjectOwner( shippo );

        // fetch pdef
        static int pdefid = -1;
        pdef_s *pdef = ( pdefid != -1 ) ?
            PRT_AcquireParticleDefinitionById( pdefid ) :
            PRT_AcquireParticleDefinition( "photon1", &pdefid );

        // create extinfo
        pextinfo_s extinfo;
        PRT_InitParticleExtInfo( &extinfo, pdef, NULL, NULL );

        // set speed and direction vector
        Vector3 dirvec;
        fixed_t speed = shippo->PhotonSpeed + shippo->CurSpeed;
        DirVctMUL( shippo->ObjPosition, FIXED_TO_GEOMV( speed ), &dirvec );

        // radius of load
        geomv_t radius = shippo->BoundingSphere - GEOMV_MUL( cluster->contraction_speed, cluster->contraction_time );

        fixed_t timefrm;
        fixed_t timepos;
        Vertex3 object_space;
		int cur_load = 0;

        // create full loads
        for ( cur_load = 0; cur_load < numloads; cur_load++ ) {
			timefrm = cluster->cur_contraction_time - ( ( cur_load + 1 ) * cluster->contraction_time );
			timepos = timefrm * shippo->PhotonSpeed;

			// create one full frame set back because the current frame will
			// be added by the linear particle animation code in the same frame
			timepos -= speed * CurScreenRefFrames;

            for ( int i = 0 ; i < single_load; i++ ) {
                CalcSphereParticlePosition( object_space, radius, SAT_SPHERETYPE_NORMAL );
                object_space.Z += FIXED_TO_GEOMV( 0x10000 * cluster->contraction_time )
                                + FIXED_TO_GEOMV( timepos );

                Vertex3 world_space;
                MtxVctMUL( shippo->ObjPosition, &object_space, &world_space );

                particle_s particle;
                PRT_InitParticle( particle, bitmap, color, sizebound,
                                ref_z, &world_space, &dirvec,
                                lifetime, playerid, &extinfo );
                particle.flags |= PARTICLE_COLLISION;
                particle.flags |= PARTICLE_IS_PHOTON;
                PRT_CreateLinearParticle( particle );
            }

            // play firing sample
            AUD_PhotonFiring( shippo );
        }

        // check if last load should be created
        if ( ( cluster->cur_contraction_time / cluster->contraction_time ) > ( old_numel / single_load ) ) {
			timefrm = cluster->cur_contraction_time - ( ( cur_load + 1 ) * cluster->contraction_time );
			timepos = timefrm * shippo->PhotonSpeed;

			// create one full frame set back because the current frame will
			// be added by the linear particle animation code in the same frame
			timepos -= speed * CurScreenRefFrames;

            for ( int i = 0 ; i < ( old_numel % single_load ); i++ ) {
                CalcSphereParticlePosition( object_space, radius, SAT_SPHERETYPE_NORMAL );
                object_space.Z += FIXED_TO_GEOMV( 0x10000 * cluster->contraction_time )
                                + FIXED_TO_GEOMV( timepos );

                Vertex3 world_space;
                MtxVctMUL( shippo->ObjPosition, &object_space, &world_space );

                particle_s particle;
                PRT_InitParticle( particle, bitmap, color, sizebound,
                                ref_z, &world_space, &dirvec,
                                lifetime, playerid, &extinfo );
                particle.flags |= PARTICLE_COLLISION;
                particle.flags |= PARTICLE_IS_PHOTON;
                PRT_CreateLinearParticle( particle );
            }

            // play firing sample
            AUD_PhotonFiring( shippo );
        }

        // calculate remaining visible sphere particles
        cluster->numel -= ( cluster->cur_contraction_time / cluster->contraction_time ) * single_load;
        if ( cluster->numel < 0 ) {
            cluster->numel = 0;
        }

        int next_numel = cluster->numel - single_load;
        if ( next_numel < 0 ) {
            next_numel = 0;
        }

        if ( cluster->numel == 0 ) {
            // cluster will be deleted automatically
        }
        else {
            // contract and rotate appropriate amount of particles

            // set old and new center values
            old_center.X = cluster->center.X;
            old_center.Y = cluster->center.Y;
            old_center.Z = ( cluster->cur_contraction_time / cluster->contraction_time ) ? 0 : cluster->center.Z;
            cluster->center.Z = FIXED_TO_GEOMV( 0x10000
                    * ( cluster->cur_contraction_time % cluster->contraction_time ) );

            contraction = ( cluster->cur_contraction_time < cluster->contraction_time )
                                    ? ( cluster->contraction_speed * CurScreenRefFrames )
                                    : ( cluster->contraction_speed * ( cluster->cur_contraction_time % cluster->contraction_time ) );

            bams_t pitch = cluster->pitch * CurScreenRefFrames;
            bams_t yaw   = cluster->yaw   * CurScreenRefFrames;
            bams_t roll  = cluster->roll  * CurScreenRefFrames;
	    int pid = 0;
            for ( pid = ( cluster->numel - 1 ); pid >= next_numel; pid-- ) {

                cluster->rep[ pid ].position.X -= old_center.X;
                cluster->rep[ pid ].position.Y -= old_center.Y;
                cluster->rep[ pid ].position.Z -= old_center.Z;

                //FIXME ?:
                // particles may not be contained in
                // ship-bounding-sphere any more
                CalcSphereParticleRotation( cluster->rep[ pid ].position,
                                            pitch, yaw, roll );
                CalcSphereContraction( cluster->rep[ pid ].position, contraction );

                // move particles forward
                cluster->rep[ pid ].position.X += cluster->center.X;
                cluster->rep[ pid ].position.Y += cluster->center.Y;
                cluster->rep[ pid ].position.Z += cluster->center.Z;
            }
            for ( pid = next_numel - 1; pid >= 0; pid-- ) {
                CalcSphereParticleRotation( cluster->rep[ pid ].position,
                                            pitch, yaw, roll );
            }
            // update cluster radius ?
            cluster->bdsphere -= contraction;
        }

        cluster->cur_contraction_time %= cluster->contraction_time;
    }
    else {
        bams_t pitch = cluster->pitch * CurScreenRefFrames;
        bams_t yaw   = cluster->yaw   * CurScreenRefFrames;
        bams_t roll  = cluster->roll  * CurScreenRefFrames;

        for ( int pid = 0; pid < cluster->numel; pid++ ) {
            CalcSphereParticleRotation( cluster->rep[ pid ].position,
                                        pitch, yaw, roll );
        }
    }
}


// create particle sphere for photon cannon -----------------------------------
//
PRIVATE
photon_sphere_pcluster_s *CreatePhotonSphere( ShipObject *shippo )
{
	ASSERT( shippo != NULL );
	ASSERT( OBJECT_TYPE_SHIP( shippo ) );

	// fetch pdef
	static int pdefid = -1;
	pdef_s *pdef = ( pdefid != -1 ) ?
		PRT_AcquireParticleDefinitionById( pdefid ) :
		PRT_AcquireParticleDefinition( "photon1", &pdefid );
	if ( pdef == NULL ) {
        MSGOUT( "photon particles invalid." );
        return NULL;
	}

	// create extinfo
    pextinfo_s extinfo;
	PRT_InitParticleExtInfo( &extinfo, pdef, NULL, NULL );

	// determine cluster type and hints
    dword clustertype = CT_PHOTON_SPHERE;
	clustertype |= CT_EXTINFO_STORAGE;
	clustertype |= CT_CLUSTER_GLOBAL_EXTINFO;
	clustertype |= CT_HINT_PARTICLES_HAVE_EXTINFO;
	clustertype |= CT_HINT_PARTICLES_IDENTICAL;

    // create new cluster
    int clustersiz = PHOTON_SPHERE_PARTICLES;
	photon_sphere_pcluster_s *cluster = (photon_sphere_pcluster_s *)
		PRT_NewCluster( clustertype, clustersiz, 0 );

	// fill in basic fields
	cluster->animtype				= SAT_PHOTON;
	cluster->bdsphere				= shippo->BoundingSphere;
	cluster->contraction_time		= PHOTON_CONTRACTION_TIME;
	cluster->cur_contraction_time	= 0;
	cluster->contraction_speed		= PHOTON_CONTRACTION_SPEED;
	cluster->max_loading_time		= PHOTON_MAX_LOADING_TIME;
	cluster->firing					= FALSE;
	cluster->numloads				= PHOTON_NUMLOADS;
	cluster->alive					= 0;
	cluster->center.X				= 0;
	cluster->center.Y				= 0;
	cluster->center.Z				= 0;
	cluster->pitch					= PHOTON_ROT_PITCH;
	cluster->yaw					= PHOTON_ROT_YAW;
	cluster->roll					= PHOTON_ROT_ROLL;

	// set particle properties
	for ( int curp = 0; curp < clustersiz; curp++ ) {

		Vertex3 particlepos;
        CalcSphereParticlePosition( particlepos, shippo->BoundingSphere, SAT_SPHERETYPE_NORMAL );

		// copy extinfo into cluster
		pextinfo_s *curextinfo = (pextinfo_s *)( cluster->rep + clustersiz ) + curp;
		memcpy( curextinfo, &extinfo, sizeof( pextinfo_s ) );

		// init particle in cluster
        cluster->rep[ curp ].owner		= GetObjectOwner( shippo );
        cluster->rep[ curp ].flags		= PARTICLE_ACTIVE;
        cluster->rep[ curp ].lifetime	= INFINITE_LIFETIME;
        cluster->rep[ curp ].extinfo	= curextinfo;
        cluster->rep[ curp ].bitmap		= iter_texrgba | iter_specularadd;
        cluster->rep[ curp ].color		= PHOTON_COLOR;
        cluster->rep[ curp ].sizebound	= PRT_NO_SIZEBOUND;
        cluster->rep[ curp ].ref_z		= photon_ref_z;
        cluster->rep[ curp ].position	= particlepos;
        cluster->rep[ curp ].velocity.X	= GEOMV_0;
		cluster->rep[ curp ].velocity.Y	= GEOMV_0;
		cluster->rep[ curp ].velocity.Z	= GEOMV_0;

        // increase number of elements
        Particles->numel++;
    }

	// at least one particle has to be visible
    cluster->numel = 1;

    // attach sphere's particle cluster to object
	PRT_AttachClusterToObject( shippo, (objectbase_pcluster_s *)cluster );

    return cluster;
}


// activate photon cannon of local ship ----------------------------------------
//
int WFX_ActivatePhoton( ShipObject *shippo )
{
	ASSERT( shippo != NULL );
	ASSERT( shippo == MyShip );
    ASSERT( ( shippo->WeaponsActive & WPMASK_CANNON_PHOTON ) == 0 );

	// check if enough space in RE_List
	if ( !NET_RmEvAllowed( RE_WEAPONSTATE ) ) {
		return FALSE;
	}

    // check if photon available
    if ( !OBJ_DeviceAvailable( shippo, WPMASK_CANNON_PHOTON ) ) {
        ShowMessage( no_photoncannon_str );
		return FALSE;
	}

    // check if enough energy to shoot photon
    if ( shippo->CurEnergy < MIN_PHOTON_ENERGY ) {
		ShowMessage( low_energy_str );
		AUD_LowEnergy();
		return FALSE;
	}

    // check if photon cannon still firing
    if ( PRT_ObjectHasAttachedClustersOfType( shippo, SAT_PHOTON ) ) {
        return FALSE;
    }

    // create particle sphere
    if ( !CreatePhotonSphere( shippo ) ) {
        ShowMessage( "could not create sphere" );
        return FALSE;
    }

    // set active flag
    shippo->WeaponsActive |= WPMASK_CANNON_PHOTON;

    // send remote event to switch photon on
    NET_RmEvWeaponState( WPMASK_CANNON_PHOTON, WPSTATE_ON, shippo->CurEnergy, shippo->Specials );

	// record activation event if recording active
	Record_PhotonActivation();

	// play sound
	AUD_PhotonLoading( shippo );

	return TRUE;
}


// deactivate photon cannon of specified ship ----------------------------------
//
void WFX_DeactivatePhoton( ShipObject *shippo )
{
	ASSERT( shippo != NULL );
    ASSERT( shippo->WeaponsActive & WPMASK_CANNON_PHOTON );

	// local ship is special case
	if ( shippo == MyShip ) {

		// check if enough space in RE_List
		if ( !NET_RmEvAllowed( RE_WEAPONSTATE ) ) {
			return;
		}

        // send remote event to switch photon off
        NET_RmEvWeaponState( WPMASK_CANNON_PHOTON, WPSTATE_OFF, shippo->CurEnergy, shippo->Specials );

		// record deactivation event if recording active
		Record_PhotonDeactivation();
	}

	// reset activation flag
    shippo->WeaponsActive &= ~WPMASK_CANNON_PHOTON;

    // start firing
    photon_sphere_pcluster_s* cluster = (photon_sphere_pcluster_s *)
		PRT_ObjectHasAttachedClustersOfType( shippo, SAT_PHOTON );
    cluster->firing = TRUE;

	// stop sound
    AUD_PhotonLoadingOff( shippo );
}


// remote player activated photon cannon --------------------------------------
//
void WFX_RemoteActivatePhoton( int playerid )
{
	// fetch pointer to remote player's ship
	ShipObject *shippo = NET_FetchOwnersShip( playerid );
	ASSERT( shippo != NULL );
	ASSERT( shippo != MyShip );

    // make sure photon cannon is active
    if ( ( shippo->WeaponsActive & WPMASK_CANNON_PHOTON ) == 0 ) {

		// avoid additional stuff that would be done
        // by WFX_ActivatePhoton()

        // check if photon cannon still firing
        if ( PRT_ObjectHasAttachedClustersOfType( shippo, SAT_PHOTON ) ) {
            return;
        }

        // create particle sphere
	    if ( !CreatePhotonSphere( shippo ) ) {
	        ShowMessage( "could not create sphere" );
	        return;
	    }

        shippo->WeaponsActive |= WPMASK_CANNON_PHOTON;

		// play sound
		AUD_PhotonLoading( shippo );
	}
}


// remote player deactivated photon cannon ------------------------------------
//
void WFX_RemoteDeactivatePhoton( int playerid )
{
	// fetch pointer to remote player's ship
	ShipObject *shippo = NET_FetchOwnersShip( playerid );
	ASSERT( shippo != NULL );
	ASSERT( shippo != MyShip );

    // make sure photon cannon is inactive
    if ( shippo->WeaponsActive & WPMASK_CANNON_PHOTON ) {

		// sound will also be switched off by this
        WFX_DeactivatePhoton( shippo );
	}
}


// ensure that photon cannon is inactive for local ship -----------------------
//
void WFX_EnsurePhotonInactive( ShipObject *shippo )
{
	ASSERT( shippo != NULL );
	ASSERT( shippo == MyShip );

    if ( shippo->WeaponsActive & WPMASK_CANNON_PHOTON ) {
        shippo->WeaponsActive &= ~WPMASK_CANNON_PHOTON;

		// stop sound
		AUD_PhotonLoadingOff( shippo );
	}

    ASSERT( ( shippo->WeaponsActive & WPMASK_CANNON_PHOTON ) == 0 );
}