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