]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/effects/all.qc
Merge branch 'master' into terencehill/tooltips_cleanup
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / effects / all.qc
1 #include "all.qh"
2
3 #ifdef CSQC
4 void Read_Effect(bool is_new)
5 {
6         int net_name = (Effects_COUNT >= 255) ? ReadShort() : ReadByte();
7
8         entity eff = Effects[net_name];
9
10         vector v, vel = '0 0 0';
11         int eff_cnt = 1;
12         bool eff_trail = eff.eent_eff_trail;
13         v_x = ReadCoord();
14         v_y = ReadCoord();
15         v_z = ReadCoord();
16
17         bool use_vel = ReadByte();
18         if(use_vel)
19         {
20                 vel_x = ReadCoord();
21                 vel_y = ReadCoord();
22                 vel_z = ReadCoord();
23         }
24
25         if(!eff_trail)
26                 eff_cnt = ReadByte();
27
28         if(is_new)
29         {
30                 if(eff_trail)
31                         WarpZone_TrailParticles(world, particleeffectnum(eff), v, vel);
32                 else
33                         pointparticles(particleeffectnum(eff), v, vel, eff_cnt);
34         }
35 }
36 #endif
37
38 #ifdef SVQC
39 bool Net_Write_Effect(entity this, entity client, int sf)
40 {
41         WriteByte(MSG_ENTITY, ENT_CLIENT_EFFECT);
42         (Effects_COUNT >= 255)
43         ? WriteShort(MSG_ENTITY, self.m_id)
44         : WriteByte(MSG_ENTITY, self.m_id);
45         WriteCoord(MSG_ENTITY, self.eent_net_location_x);
46         WriteCoord(MSG_ENTITY, self.eent_net_location_y);
47         WriteCoord(MSG_ENTITY, self.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(self.eent_net_velocity)
51         {
52                 WriteByte(MSG_ENTITY, true);
53                 WriteCoord(MSG_ENTITY, self.eent_net_velocity_x);
54                 WriteCoord(MSG_ENTITY, self.eent_net_velocity_y);
55                 WriteCoord(MSG_ENTITY, self.eent_net_velocity_z);
56         }
57         else { WriteByte(MSG_ENTITY, false); }
58
59         if(!self.eent_eff_trail) { WriteByte(MSG_ENTITY, self.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 = spawn();
68         net_eff.owner = eff;
69         net_eff.classname = "net_effect";
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         net_eff.think = SUB_Remove;
78         net_eff.nextthink = time + 0.2; // don't need to keep this long
79
80         Net_LinkEntity(net_eff, false, 0, Net_Write_Effect);
81 }
82
83 void Send_Effect_(string eff_name, vector eff_loc, vector eff_vel, int eff_cnt)
84 {
85         // problem with this is, we might not have all the available effects for it
86         FOREACH(Effects, it.eent_eff_name == eff_name, LAMBDA(
87                 Send_Effect(it, eff_loc, eff_vel, eff_cnt);
88                 return;
89         ));
90         // revert to engine handling
91         pointparticles(_particleeffectnum(eff_name), eff_loc, eff_vel, eff_cnt);
92 }
93 #endif