]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/effects.qc
Boolinterize
[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         if(eff_trail)
43                 WarpZone_TrailParticles(world, particleeffectnum(eff.eent_eff_name), v, vel);
44         else
45                 pointparticles(particleeffectnum(eff.eent_eff_name), v, vel, eff_cnt);
46 }
47 #endif
48
49 #ifdef SVQC
50 bool Net_Write_Effect(entity client, int sf)
51 {
52         WriteByte(MSG_ENTITY, ENT_CLIENT_EFFECT);
53 #if EFFECTS_COUNT >= 255
54         WriteShort(MSG_ENTITY, self.eent_net_name);
55 #else
56         WriteByte(MSG_ENTITY, self.eent_net_name);
57 #endif
58         WriteCoord(MSG_ENTITY, self.eent_net_location_x);
59         WriteCoord(MSG_ENTITY, self.eent_net_location_y);
60         WriteCoord(MSG_ENTITY, self.eent_net_location_z);
61
62         // attempt to save a tiny bit more bandwidth by not sending velocity if it isn't set
63         if(self.eent_net_velocity)
64         {
65                 WriteByte(MSG_ENTITY, true);
66                 WriteCoord(MSG_ENTITY, self.eent_net_velocity_x);
67                 WriteCoord(MSG_ENTITY, self.eent_net_velocity_y);
68                 WriteCoord(MSG_ENTITY, self.eent_net_velocity_z);
69         }
70         else { WriteByte(MSG_ENTITY, false); }
71
72         if(!self.eent_eff_trail) { WriteByte(MSG_ENTITY, self.eent_net_count); }
73         return true;
74 }
75
76 // problem with this is, we might not have all the available effects for it
77 int Effect_NameToID(string eff_name)
78 {
79         int i;
80         for(i = EFFECT_FIRST; i < MAX_EFFECTS; ++i)
81         {
82                 if((effects_ent[i - 1]).eent_eff_name == eff_name)
83                         return (effects_ent[i - 1]).eent_net_name;
84         }
85
86         return 0;
87 }
88
89 void Send_Effect(string eff_name, vector eff_loc, vector eff_vel, int eff_cnt)
90 {
91         int eff_id = Effect_NameToID(eff_name);
92
93         if(!eff_id)
94         {
95                 // revert to engine handling?
96                 pointparticles(particleeffectnum(eff_name), eff_loc, eff_vel, eff_cnt);
97                 return;
98         }
99
100         entity eff = effects_ent[eff_id - 1];
101         if(!eff) { return; }
102         if(!eff.eent_eff_trail && !eff_cnt) { return; } // effect has no count!
103         entity net_eff = spawn();
104         net_eff.owner = eff;
105         net_eff.classname = "net_effect";
106         //net_eff.eent_broadcast = broadcast;
107         net_eff.eent_net_name = eff_id;
108         net_eff.eent_net_velocity = eff_vel;
109         net_eff.eent_net_location = eff_loc;
110         net_eff.eent_net_count = eff_cnt;
111         net_eff.eent_eff_trail = eff.eent_eff_trail;
112
113         net_eff.think = SUB_Remove;
114         net_eff.nextthink = time + 0.2; // don't need to keep this long
115
116         Net_LinkEntity(net_eff, false, 0, Net_Write_Effect);
117 }
118 #endif