]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_tuba.qc
slightly improved tuba note handling
[divverent/nexuiz.git] / data / qcsrc / server / w_tuba.qc
1 //#define TUBA_NOTE(n) strcat("weapons/tuba_note", ftos(n), ".wav")
2 .float tuba_notecount;
3 .entity tuba_note;
4 .float tuba_smoketime;
5
6 float Tuba_GetNote(entity pl, float hittype)
7 {
8         float note;
9         float movestate;
10         movestate = 5;
11         if(pl.movement_x < 0) movestate -= 3;
12         if(pl.movement_x > 0) movestate += 3;
13         if(pl.movement_y < 0) movestate -= 1;
14         if(pl.movement_y > 0) movestate += 1;
15         switch(movestate)
16         {
17         // layout: originally I wanted
18         //   eb e  e#=f
19         //   B  c  d
20         //   Gb G  G#
21         // but then you only use forward and right key. So to make things more
22         // interesting, I swapped B with e#. Har har har...
23         //   eb e  B
24         // f=e# c  d
25         //   Gb G  G#
26                 case 1: note = -6; break; // Gb
27                 case 2: note = -5; break; // G
28                 case 3: note = -4; break; // G#
29                 case 4: note = +5; break; // e#
30                 case 5: note =  0; break; // c
31                 case 6: note = +2; break; // d
32                 case 7: note = +3; break; // eb
33                 case 8: note = +4; break; // e
34                 case 9: note = -1; break; // B
35         }
36         if(pl.BUTTON_CROUCH)
37                 note -= 12;
38         if(pl.BUTTON_JUMP)
39                 note += 12;
40         if(hittype & HITTYPE_SECONDARY)
41                 note += 7;
42         
43         // we support two kinds of tubas, those tuned in Eb and those tuned in C
44         // kind of tuba currently is player slot number, or team number if in
45         // teamplay
46         // that way, holes in the range of notes are "plugged"
47         if(teams_matter)
48         {
49                 if(pl.team == COLOR_TEAM2 || pl.team == COLOR_TEAM4)
50                         note += 3;
51         }
52         else
53         {
54                 if(pl.clientcolors & 1)
55                         note += 3;
56         }
57         
58         // total range of notes:
59         //                       0
60         //                 ***  ** ****
61         //                        ***  ** ****
62         //     ***  ** ****
63         //            ***  ** ****
64         //     ***  ********************* ****
65         //     -18.........................+12
66         //        ***  ********************* ****
67         //     -18............................+15
68         //     with jump: ... +24
69         //     ... +27
70         return note;
71 }
72
73 float W_Tuba_NoteSendEntity(entity to, float sf)
74 {
75         WriteByte(MSG_ENTITY, ENT_CLIENT_TUBANOTE);
76         WriteByte(MSG_ENTITY, (sf & 1) | ((self.cnt + 42) * 2));
77         if(sf & 1)
78         {
79                 WriteCoord(MSG_ENTITY, self.origin_x);
80                 WriteCoord(MSG_ENTITY, self.origin_y);
81                 WriteCoord(MSG_ENTITY, self.origin_z);
82         }
83         return TRUE;
84 }
85
86 void W_Tuba_NoteThink()
87 {
88         self.nextthink = time;
89         if(self.owner.origin != self.origin)
90         {
91                 setorigin(self, self.owner.origin);
92                 self.SendFlags |= 1;
93         }
94         if(time > self.teleport_time)
95         {
96                 self.owner.tuba_note = world;
97                 remove(self);
98         }
99 }
100
101 void W_Tuba_Attack(float hittype)
102 {
103         vector o;
104         float c, n;
105         W_SetupShot(self, FALSE, 2, "", cvar("g_balance_tuba_damage"));
106         if(self.tuba_notecount)
107         {
108                 self.tuba_notecount = FALSE;
109                 c = CHAN_WEAPON;
110         }
111         else
112         {
113                 self.tuba_notecount = TRUE;
114                 c = CHAN_WEAPON2;
115         }
116
117         n = Tuba_GetNote(self, hittype);
118
119         if(self.tuba_note)
120         {
121                 if(self.tuba_note.cnt != n)
122                 {
123                         /*
124                         self.tuba_note.cnt = n;
125                         self.tuba_note.SendFlags |= 2;
126                         */
127                         remove(self.tuba_note);
128                         self.tuba_note = world;
129                 }
130         }
131
132         if not(self.tuba_note)
133         {
134                 self.tuba_note = spawn();
135                 self.tuba_note.owner = self;
136                 self.tuba_note.cnt = n;
137                 self.tuba_note.think = W_Tuba_NoteThink;
138                 self.tuba_note.nextthink = time;
139                 Net_LinkEntity(self.tuba_note, FALSE, 0, W_Tuba_NoteSendEntity);
140         }
141
142         self.tuba_note.teleport_time = time + cvar("g_balance_tuba_refire") * 2; // so it can get prolonged safely
143
144         //sound(self, c, TUBA_NOTE(n), bound(0, VOL_BASE * cvar("g_balance_tuba_volume"), 1), cvar("g_balance_tuba_attenuation"));
145         RadiusDamage(self, self, cvar("g_balance_tuba_damage"), cvar("g_balance_tuba_edgedamage"), cvar("g_balance_tuba_radius"), world, cvar("g_balance_tuba_force"), hittype | WEP_TUBA, world);
146
147         o = gettaginfo(self.exteriorweaponentity, 0);
148         if(time > self.tuba_smoketime)
149         {
150                 pointparticles(particleeffectnum("smoke_ring"), o + v_up * 45 + v_right * -6 + v_forward * 8, v_up * 100, 1);
151                 self.tuba_smoketime = time + 0.25;
152         }
153 }
154
155 void spawnfunc_weapon_tuba (void)
156 {
157         if(!sv_cheats && !cvar("developer"))
158         {
159                 print("The @!#%'n Tuba awaits you... not.\n");
160                 remove(self);
161                 return;
162         }
163         weapon_defaultspawnfunc(WEP_TUBA);
164 }
165
166 float w_tuba(float req)
167 {
168         if (req == WR_AIM)
169         {
170                 // bots cannot play the Tuba well yet
171                 // I think they should start with the recorder first
172                 if(vlen(self.origin - self.enemy.origin) < cvar("g_balance_tuba_radius"))
173                 {
174                         if(random() > 0.5)
175                                 self.BUTTON_ATCK = 1;
176                         else
177                                 self.BUTTON_ATCK2 = 1;
178                 }
179         }
180         else if (req == WR_THINK)
181         {
182                 if (self.BUTTON_ATCK)
183                 if (weapon_prepareattack(0, cvar("g_balance_tuba_refire")))
184                 {
185                         W_Tuba_Attack(0);
186                         //weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_tuba_animtime"), w_ready);
187                         weapon_thinkf(WFRAME_IDLE, cvar("g_balance_tuba_animtime"), w_ready);
188                 }
189                 if (self.BUTTON_ATCK2)
190                 if (weapon_prepareattack(1, cvar("g_balance_tuba_refire")))
191                 {
192                         W_Tuba_Attack(HITTYPE_SECONDARY);
193                         //weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_tuba_animtime"), w_ready);
194                         weapon_thinkf(WFRAME_IDLE, cvar("g_balance_tuba_animtime"), w_ready);
195                 }
196                 if(self.tuba_note)
197                 {
198                         if(!self.BUTTON_ATCK && !self.BUTTON_ATCK2)
199                         {
200                                 remove(self.tuba_note);
201                                 self.tuba_note = world;
202                         }
203                 }
204         }
205         else if (req == WR_PRECACHE)
206         {
207                 precache_model ("models/weapons/g_tuba.md3");
208                 precache_model ("models/weapons/v_tuba.md3");
209                 precache_model ("models/weapons/h_tuba.dpm");
210
211                 //float i;
212                 //for(i = -18; i <= +27; ++i)
213                 //      precache_sound(TUBA_NOTE(i));
214         }
215         else if (req == WR_SETUP)
216                 weapon_setup(WEP_TUBA);
217         else if (req == WR_CHECKAMMO1)
218                 return TRUE; // TODO use fuel?
219         else if (req == WR_CHECKAMMO2)
220                 return TRUE; // TODO use fuel?
221         else if (req == WR_SUICIDEMESSAGE)
222         {
223                 w_deathtypestring = "hurt his own ears with the @!#%'n Tuba";
224         }
225         else if (req == WR_KILLMESSAGE)
226         {
227                 w_deathtypestring = "died of #'s great playing on the @!#%'n Tuba";
228         }
229         return TRUE;
230 };