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