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