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