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