]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/target_music.qc
Even more floats to bool/int
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / target_music.qc
1 #if defined(CSQC)
2 #elif defined(MENUQC)
3 #elif defined(SVQC)
4         #include "../dpdefs/progsdefs.qh"
5     #include "../dpdefs/dpextensions.qh"
6     #include "../common/constants.qh"
7     #include "constants.qh"
8     #include "defs.qh"
9 #endif
10
11 .float lifetime;
12 // values:
13 //   volume
14 //   noise
15 //   targetname
16 //   lifetime
17 //   fade_time
18 //   fade_rate
19 // when triggered, the music is overridden for activator until lifetime (or forever, if lifetime is 0)
20 // when targetname is not set, THIS ONE is default
21 void target_music_sendto(float to, float is)
22 {
23         WriteByte(to, SVC_TEMPENTITY);
24         WriteByte(to, TE_CSQC_TARGET_MUSIC);
25         WriteShort(to, num_for_edict(self));
26         WriteByte(to, self.volume * 255.0 * is);
27         WriteByte(to, self.fade_time * 16.0);
28         WriteByte(to, self.fade_rate * 16.0);
29         WriteByte(to, self.lifetime);
30         WriteString(to, self.noise);
31 }
32 void target_music_reset()
33 {
34         if(self.targetname == "")
35                 target_music_sendto(MSG_ALL, 1);
36 }
37 void target_music_use()
38 {
39         if(!activator)
40                 return;
41         if(IS_REAL_CLIENT(activator))
42         {
43                 msg_entity = activator;
44                 target_music_sendto(MSG_ONE, 1);
45         }
46         entity head;
47         FOR_EACH_SPEC(head) if(head.enemy == activator) { msg_entity = head; target_music_sendto(MSG_ONE, 1); }
48 }
49 void spawnfunc_target_music()
50 {
51         self.use = target_music_use;
52         self.reset = target_music_reset;
53         if(!self.volume)
54                 self.volume = 1;
55         if(self.targetname == "")
56                 target_music_sendto(MSG_INIT, 1);
57         else
58                 target_music_sendto(MSG_INIT, 0);
59 }
60 void TargetMusic_RestoreGame()
61 {
62         for(self = world; (self = find(self, classname, "target_music")); )
63         {
64                 if(self.targetname == "")
65                         target_music_sendto(MSG_INIT, 1);
66                 else
67                         target_music_sendto(MSG_INIT, 0);
68         }
69 }
70 // values:
71 //   volume
72 //   noise
73 //   targetname
74 //   fade_time
75 // spawnflags:
76 //   1 = START_OFF
77 // when triggered, it is disabled/enabled for everyone
78 float trigger_music_SendEntity(entity to, int sf)
79 {
80         WriteByte(MSG_ENTITY, ENT_CLIENT_TRIGGER_MUSIC);
81         sf &= ~0x80;
82         if(self.cnt)
83                 sf |= 0x80;
84         WriteByte(MSG_ENTITY, sf);
85         if(sf & 4)
86         {
87                 WriteCoord(MSG_ENTITY, self.origin.x);
88                 WriteCoord(MSG_ENTITY, self.origin.y);
89                 WriteCoord(MSG_ENTITY, self.origin.z);
90         }
91         if(sf & 1)
92         {
93                 if(self.model != "null")
94                 {
95                         WriteShort(MSG_ENTITY, self.modelindex);
96                         WriteCoord(MSG_ENTITY, self.mins.x);
97                         WriteCoord(MSG_ENTITY, self.mins.y);
98                         WriteCoord(MSG_ENTITY, self.mins.z);
99                         WriteCoord(MSG_ENTITY, self.maxs.x);
100                         WriteCoord(MSG_ENTITY, self.maxs.y);
101                         WriteCoord(MSG_ENTITY, self.maxs.z);
102                 }
103                 else
104                 {
105                         WriteShort(MSG_ENTITY, 0);
106                         WriteCoord(MSG_ENTITY, self.maxs.x);
107                         WriteCoord(MSG_ENTITY, self.maxs.y);
108                         WriteCoord(MSG_ENTITY, self.maxs.z);
109                 }
110                 WriteByte(MSG_ENTITY, self.volume * 255.0);
111                 WriteByte(MSG_ENTITY, self.fade_time * 16.0);
112                 WriteByte(MSG_ENTITY, self.fade_rate * 16.0);
113                 WriteString(MSG_ENTITY, self.noise);
114         }
115         return 1;
116 }
117 void trigger_music_reset()
118 {
119         self.cnt = !(self.spawnflags & 1);
120         self.SendFlags |= 0x80;
121 }
122 void trigger_music_use()
123 {
124         self.cnt = !self.cnt;
125         self.SendFlags |= 0x80;
126 }
127 void spawnfunc_trigger_music()
128 {
129         if(self.model != "")
130                 setmodel(self, self.model);
131         if(!self.volume)
132                 self.volume = 1;
133         if(!self.modelindex)
134         {
135                 setorigin(self, self.origin + self.mins);
136                 setsize(self, '0 0 0', self.maxs - self.mins);
137         }
138         trigger_music_reset();
139
140         self.use = trigger_music_use;
141         self.reset = trigger_music_reset;
142
143         Net_LinkEntity(self, false, 0, trigger_music_SendEntity);
144 }