]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/effects/all.qc
Merge branch 'master' into TimePath/debug_draw
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / effects / all.qc
1 #include "all.qh"
2
3 REGISTER_NET_TEMP(net_effect, bool isNew)
4 #ifdef CSQC
5 {
6         int net_name = (Effects_COUNT >= 255) ? ReadShort() : ReadByte();
7
8         entity eff = Effects[net_name];
9
10         vector vel = '0 0 0';
11         int eff_cnt = 1;
12         bool eff_trail = eff.eent_eff_trail;
13         vector v;
14         v_x = ReadCoord();
15         v_y = ReadCoord();
16         v_z = ReadCoord();
17
18         bool use_vel = ReadByte();
19         if(use_vel)
20         {
21                 vel_x = ReadCoord();
22                 vel_y = ReadCoord();
23                 vel_z = ReadCoord();
24         }
25
26         if(!eff_trail)
27                 eff_cnt = ReadByte();
28
29         if(eff_trail)
30                 WarpZone_TrailParticles(world, particleeffectnum(eff), v, vel);
31         else
32                 pointparticles(particleeffectnum(eff), v, vel, eff_cnt);
33 }
34 #endif
35
36 #ifdef SVQC
37 bool Net_Write_Effect(entity this, entity client, int sf)
38 {
39         int channel = MSG_ONE;
40         msg_entity = client;
41         WriteHeader(channel, net_effect);
42         (Effects_COUNT >= 255)
43         ? WriteShort(channel, this.m_id)
44         : WriteByte(channel, this.m_id);
45         WriteCoord(channel, this.eent_net_location_x);
46         WriteCoord(channel, this.eent_net_location_y);
47         WriteCoord(channel, this.eent_net_location_z);
48
49         // attempt to save a tiny bit more bandwidth by not sending velocity if it isn't set
50         if(this.eent_net_velocity)
51         {
52                 WriteByte(channel, true);
53                 WriteCoord(channel, this.eent_net_velocity_x);
54                 WriteCoord(channel, this.eent_net_velocity_y);
55                 WriteCoord(channel, this.eent_net_velocity_z);
56         }
57         else { WriteByte(channel, false); }
58
59         if(!this.eent_eff_trail) { WriteByte(channel, this.eent_net_count); }
60         return true;
61 }
62
63 void Send_Effect(entity eff, vector eff_loc, vector eff_vel, int eff_cnt)
64 {
65         if(!eff) { return; }
66         if(!eff.eent_eff_trail && !eff_cnt) { return; } // effect has no count!
67         entity net_eff = new(net_effect);
68         make_pure(net_eff);
69         net_eff.owner = eff;
70         //net_eff.eent_broadcast = broadcast;
71         net_eff.m_id = eff.m_id;
72         net_eff.eent_net_velocity = eff_vel;
73         net_eff.eent_net_location = eff_loc;
74         net_eff.eent_net_count = eff_cnt;
75         net_eff.eent_eff_trail = eff.eent_eff_trail;
76
77         entity e; FOR_EACH_REALCLIENT(e) Net_Write_Effect(net_eff, e, 0);
78         remove(net_eff);
79 }
80
81 void Send_Effect_(string eff_name, vector eff_loc, vector eff_vel, int eff_cnt)
82 {
83         // problem with this is, we might not have all the available effects for it
84         FOREACH(Effects, it.eent_eff_name == eff_name, LAMBDA(
85                 Send_Effect(it, eff_loc, eff_vel, eff_cnt);
86                 return;
87         ));
88         // revert to engine handling
89         pointparticles(_particleeffectnum(eff_name), eff_loc, eff_vel, eff_cnt);
90 }
91 #endif