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