Group effects in a folder
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / effects / effects.qc
1 #ifdef CSQC
2 void Read_Effect(bool is_new)
3 {
4         int net_name = (EFFECT_COUNT >= 255) ? ReadShort() : ReadByte();
5
6         entity eff = effects_ent[net_name];
7
8         vector v, vel = '0 0 0';
9         int eff_cnt = 1;
10         bool eff_trail = eff.eent_eff_trail;
11         v_x = ReadCoord();
12         v_y = ReadCoord();
13         v_z = ReadCoord();
14
15         bool use_vel = ReadByte();
16         if(use_vel)
17         {
18                 vel_x = ReadCoord();
19                 vel_y = ReadCoord();
20                 vel_z = ReadCoord();
21         }
22
23         if(!eff_trail)
24                 eff_cnt = ReadByte();
25
26         if(is_new)
27         {
28                 if(eff_trail)
29                         WarpZone_TrailParticles(world, particleeffectnum(eff), v, vel);
30                 else
31                         pointparticles(particleeffectnum(eff), v, vel, eff_cnt);
32         }
33 }
34 #endif
35
36 #ifdef SVQC
37 bool Net_Write_Effect(entity client, int sf)
38 {SELFPARAM();
39         WriteByte(MSG_ENTITY, ENT_CLIENT_EFFECT);
40         (EFFECT_COUNT >= 255)
41         ? WriteShort(MSG_ENTITY, self.m_id)
42         : WriteByte(MSG_ENTITY, self.m_id);
43         WriteCoord(MSG_ENTITY, self.eent_net_location_x);
44         WriteCoord(MSG_ENTITY, self.eent_net_location_y);
45         WriteCoord(MSG_ENTITY, self.eent_net_location_z);
46
47         // attempt to save a tiny bit more bandwidth by not sending velocity if it isn't set
48         if(self.eent_net_velocity)
49         {
50                 WriteByte(MSG_ENTITY, true);
51                 WriteCoord(MSG_ENTITY, self.eent_net_velocity_x);
52                 WriteCoord(MSG_ENTITY, self.eent_net_velocity_y);
53                 WriteCoord(MSG_ENTITY, self.eent_net_velocity_z);
54         }
55         else { WriteByte(MSG_ENTITY, false); }
56
57         if(!self.eent_eff_trail) { WriteByte(MSG_ENTITY, self.eent_net_count); }
58         return true;
59 }
60
61 void Send_Effect(entity eff, vector eff_loc, vector eff_vel, int eff_cnt)
62 {
63         if(!eff) { return; }
64         if(!eff.eent_eff_trail && !eff_cnt) { return; } // effect has no count!
65         entity net_eff = spawn();
66         net_eff.owner = eff;
67         net_eff.classname = "net_effect";
68         //net_eff.eent_broadcast = broadcast;
69         net_eff.m_id = eff.m_id;
70         net_eff.eent_net_velocity = eff_vel;
71         net_eff.eent_net_location = eff_loc;
72         net_eff.eent_net_count = eff_cnt;
73         net_eff.eent_eff_trail = eff.eent_eff_trail;
74
75         net_eff.think = SUB_Remove;
76         net_eff.nextthink = time + 0.2; // don't need to keep this long
77
78         Net_LinkEntity(net_eff, false, 0, Net_Write_Effect);
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_ent, 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