]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/effects/all.qc
Merge branch 'master' into Mario/stats_eloranking
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / effects / all.qc
1 #include "all.qh"
2
3 REGISTER_NET_TEMP(net_effect)
4 #ifdef CSQC
5 NET_HANDLE(net_effect, bool isNew)
6 {
7         int net_name = (Effects_COUNT >= 255) ? ReadShort() : ReadByte();
8
9         entity eff = Effects_from(net_name);
10
11         vector vel = '0 0 0';
12         int eff_cnt = 1;
13         bool eff_trail = eff.eent_eff_trail;
14         vector v = ReadVector();
15
16         bool use_vel = ReadByte();
17         if(use_vel)
18                 vel = ReadVector();
19
20         if(!eff_trail)
21                 eff_cnt = ReadByte();
22
23         if(eff_trail)
24                 WarpZone_TrailParticles(NULL, particleeffectnum(eff), v, vel);
25         else
26                 pointparticles(eff, v, vel, eff_cnt);
27         return true;
28 }
29 #endif
30
31 #ifdef SVQC
32 bool Net_Write_Effect(entity this, entity client, int sf)
33 {
34         int channel = MSG_ONE;
35         msg_entity = client;
36         WriteHeader(channel, net_effect);
37         (Effects_COUNT >= 255)
38         ? WriteShort(channel, this.m_id)
39         : WriteByte(channel, this.m_id);
40         WriteVector(channel, this.eent_net_location);
41
42         // attempt to save a tiny bit more bandwidth by not sending velocity if it isn't set
43         if(this.eent_net_velocity)
44         {
45                 WriteByte(channel, true);
46                 WriteVector(channel, this.eent_net_velocity);
47         }
48         else { WriteByte(channel, false); }
49
50         if(!this.eent_eff_trail) { WriteByte(channel, this.eent_net_count); }
51         return true;
52 }
53
54 void Send_Effect(entity eff, vector eff_loc, vector eff_vel, int eff_cnt)
55 {
56         if(!eff) { return; }
57         if(!eff.eent_eff_trail && !eff_cnt) { return; } // effect has no count!
58         entity net_eff = new_pure(net_effect);
59         net_eff.owner = eff;
60         //net_eff.eent_broadcast = broadcast;
61         net_eff.m_id = eff.m_id;
62         net_eff.eent_net_velocity = eff_vel;
63         net_eff.eent_net_location = eff_loc;
64         net_eff.eent_net_count = eff_cnt;
65         net_eff.eent_eff_trail = eff.eent_eff_trail;
66
67         FOREACH_CLIENT(IS_REAL_CLIENT(it), Net_Write_Effect(net_eff, it, 0));
68         delete(net_eff);
69 }
70
71 void Send_Effect_(string eff_name, vector eff_loc, vector eff_vel, int eff_cnt)
72 {
73         // problem with this is, we might not have all the available effects for it
74         FOREACH(Effects, it.eent_eff_name == eff_name, {
75                 Send_Effect(it, eff_loc, eff_vel, eff_cnt);
76                 return;
77         });
78         // revert to engine handling TODO: send the effect name and draw it on the client side? not as light on networking, but resolves the use of server side effects
79         __pointparticles(_particleeffectnum(eff_name), eff_loc, eff_vel, eff_cnt);
80 }
81 #endif
82
83 #if ENABLE_EFFECTINFO
84         #include "effectinfo.qc"
85 #endif