]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/w_tuba.qc
WAY better tuba thanks to CSQC magic.
[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.owner.tuba_note = world;
89         remove(self);
90 }
91
92 void W_Tuba_Attack(float hittype)
93 {
94         vector o;
95         float c, n;
96         W_SetupShot(self, FALSE, 2, "", cvar("g_balance_tuba_damage"));
97         if(self.tuba_notecount)
98         {
99                 self.tuba_notecount = FALSE;
100                 c = CHAN_WEAPON;
101         }
102         else
103         {
104                 self.tuba_notecount = TRUE;
105                 c = CHAN_WEAPON2;
106         }
107
108         n = Tuba_GetNote(self, hittype);
109
110         if(self.tuba_note)
111         {
112                 if(self.tuba_note.cnt != n)
113                 {
114                         /*
115                         self.tuba_note.cnt = n;
116                         self.tuba_note.SendFlags |= 2;
117                         */
118                         remove(self.tuba_note);
119                         self.tuba_note = world;
120                 }
121         }
122
123         if not(self.tuba_note)
124         {
125                 self.tuba_note = spawn();
126                 self.tuba_note.owner = self;
127                 self.tuba_note.cnt = n;
128                 self.tuba_note.think = W_Tuba_NoteThink;
129                 Net_LinkEntity(self.tuba_note, FALSE, 0, W_Tuba_NoteSendEntity);
130         }
131
132         self.tuba_note.nextthink = time + cvar("g_balance_tuba_refire") * 2; // so it can get prolonged safely
133         if(self.origin != self.tuba_note.origin)
134         {
135                 setorigin(self.tuba_note, self.origin);
136                 self.tuba_note.SendFlags |= 1;
137         }
138
139         //sound(self, c, TUBA_NOTE(n), bound(0, VOL_BASE * cvar("g_balance_tuba_volume"), 1), cvar("g_balance_tuba_attenuation"));
140         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);
141
142         o = gettaginfo(self.exteriorweaponentity, 0);
143         if(time > self.tuba_smoketime)
144         {
145                 pointparticles(particleeffectnum("smoke_ring"), o + v_up * 45 + v_right * -6 + v_forward * 8, v_up * 100, 1);
146                 self.tuba_smoketime = time + 0.25;
147         }
148 }
149
150 void spawnfunc_weapon_tuba (void)
151 {
152         if(!sv_cheats && !cvar("developer"))
153         {
154                 print("The @!#%'n Tuba awaits you... not.\n");
155                 remove(self);
156                 return;
157         }
158         weapon_defaultspawnfunc(WEP_TUBA);
159 }
160
161 float w_tuba(float req)
162 {
163         if (req == WR_AIM)
164         {
165                 // bots cannot play the Tuba well yet
166                 // I think they should start with the recorder first
167                 if(vlen(self.origin - self.enemy.origin) < cvar("g_balance_tuba_radius"))
168                 {
169                         if(random() > 0.5)
170                                 self.BUTTON_ATCK = 1;
171                         else
172                                 self.BUTTON_ATCK2 = 1;
173                 }
174         }
175         else if (req == WR_THINK)
176         {
177                 if (self.BUTTON_ATCK)
178                 if (weapon_prepareattack(0, cvar("g_balance_tuba_refire")))
179                 {
180                         W_Tuba_Attack(0);
181                         //weapon_thinkf(WFRAME_FIRE1, cvar("g_balance_tuba_animtime"), w_ready);
182                         weapon_thinkf(WFRAME_IDLE, cvar("g_balance_tuba_animtime"), w_ready);
183                 }
184                 if (self.BUTTON_ATCK2)
185                 if (weapon_prepareattack(1, cvar("g_balance_tuba_refire")))
186                 {
187                         W_Tuba_Attack(HITTYPE_SECONDARY);
188                         //weapon_thinkf(WFRAME_FIRE2, cvar("g_balance_tuba_animtime"), w_ready);
189                         weapon_thinkf(WFRAME_IDLE, cvar("g_balance_tuba_animtime"), w_ready);
190                 }
191                 if(self.tuba_note)
192                 {
193                         if(!self.BUTTON_ATCK && !self.BUTTON_ATCK2)
194                         {
195                                 remove(self.tuba_note);
196                                 self.tuba_note = world;
197                         }
198                 }
199         }
200         else if (req == WR_PRECACHE)
201         {
202                 precache_model ("models/weapons/g_tuba.md3");
203                 precache_model ("models/weapons/v_tuba.md3");
204                 precache_model ("models/weapons/h_tuba.dpm");
205
206                 //float i;
207                 //for(i = -18; i <= +27; ++i)
208                 //      precache_sound(TUBA_NOTE(i));
209         }
210         else if (req == WR_SETUP)
211                 weapon_setup(WEP_TUBA);
212         else if (req == WR_CHECKAMMO1)
213                 return TRUE; // TODO use fuel?
214         else if (req == WR_CHECKAMMO2)
215                 return TRUE; // TODO use fuel?
216         else if (req == WR_SUICIDEMESSAGE)
217         {
218                 w_deathtypestring = "hurt his own ears with the @!#%'n Tuba";
219         }
220         else if (req == WR_KILLMESSAGE)
221         {
222                 w_deathtypestring = "died of #'s great playing on the @!#%'n Tuba";
223         }
224         return TRUE;
225 };