agrip/d5k.mqc

Go to the documentation of this file.
00001 /*  Copyright 2004-2005 Matthew Tylee Atkinson
00002 
00003     This program is free software; you can redistribute it and/or modify
00004     it under the terms of the GNU General Public License as published by
00005     the Free Software Foundation; either version 2 of the License, or
00006     (at your option) any later version.
00007 
00008     This program is distributed in the hope that it will be useful,
00009     but WITHOUT ANY WARRANTY; without even the implied warranty of
00010     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011     GNU General Public License for more details.
00012 
00013     You should have received a copy of the GNU General Public License
00014     along with this program; if not, write to the Free Software
00015     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00016 
00017     See file, 'COPYING', for details.
00018 */
00019 
00020 /* $AGRIP-START */
00021 /* AGRIP Detector 5000 Object */
00022 
00023 
00024 // PROTOTYPES
00025 
00026 void snap_d5k_constructor();
00027 void snap_d5k_starter();
00028 void snap_d5k_main();
00029 
00030 
00031 // IMPLEMENTATIONS
00032 
00039 void snap_d5k_constructor()
00040 {
00041     local entity new_agd5k;
00042                                                                                            
00043     new_agd5k = spawn();
00044                                                                                            
00045     // Set up new nav object...
00046     new_agd5k.movetype = MOVETYPE_NONE;
00047     new_agd5k.solid = SOLID_NOT;
00048                                                                                            
00049     /*  Give it the preferences the user specified...
00050         To save memory, we're using existing (and empty for this entity) fields... */
00051     
00052     // Interval (seconds) between uses of the nav object...
00053     new_agd5k.health = stof(infokey(self, "agv_d5k_interval"));
00054     
00055     // Detection range...
00056     new_agd5k.frags = stof(infokey(self, "agv_d5k_objdist"));
00057     
00058     // Volume throttle for the sound this object will make...
00059     new_agd5k.items = stof(infokey(self, "agv_d5k_volume_throttle"));
00060     if( new_agd5k.items > 1 || new_agd5k.items < 0 )
00061         new_agd5k.items = 1;
00062 
00063     // Connect the nav object and player...
00064     new_agd5k.owner = self;
00065     self.agrip_d5k = new_agd5k;
00066                                                                                            
00067     // Give it life!
00068     new_agd5k.think = snap_d5k_main;
00069     new_agd5k.nextthink = time + 0.1;
00070 };
00071 
00078 void snap_d5k_starter()
00079 {
00080     // Search for entities near to player...
00081     self.goalentity = findradius(self.owner.origin, self.frags);
00082 
00083     self.think = snap_d5k_main;
00084     self.nextthink = time + 0.1;
00085 
00086     //dprint("-------------------------\n");
00087 };
00088 
00102 void snap_d5k_main()
00103 {
00104     local float sound_vol, matched;
00105     local vector switch_origin;
00106 
00107     matched = false;
00108 
00109     if(self.goalentity)
00110     {
00111         if( self.goalentity.classname != "func_button" )
00112         {
00113             // Work out what volume of sound we are going 
00114             sound_vol = vlen(self.goalentity.origin - self.owner.origin) / self.frags;
00115             sound_vol = ( 1 - sound_vol ) * self.items;
00116             
00117             //snap_misc_showpoint(self.goalentity.origin, "progs/s_light.spr", 3);
00118         }
00119         else
00120         {
00121             /* Must work out its origin first...
00122             switch_origin_x = ( self.goalentity.maxs_x + self.goalentity.mins_x ) / 2;
00123             switch_origin_y = ( self.goalentity.maxs_y + self.goalentity.mins_y ) / 2;
00124             switch_origin_z = ( self.goalentity.maxs_z + self.goalentity.mins_z ) / 2;*/
00125 
00126             switch_origin = self.goalentity.mins - '0 0 1';
00127             if( pointcontents(switch_origin) != CONTENT_EMPTY )
00128                     switch_origin = self.goalentity.maxs + '0 0 1';
00129             
00130             // Work out what volume of sound we are going 
00131             sound_vol = vlen(switch_origin - self.owner.origin) / self.frags;
00132             sound_vol = ( 1 - sound_vol ) * self.items;
00133 
00134             //snap_misc_showpoint(switch_origin, "progs/s_light.spr", 3);
00135         }
00136         
00137         // If we have moved away from the item since the scan and it is
00138         // now out of detection range, sound_vol would be -ve.
00139         // Also, we shouldn't sound things that would be too quiet to hear.
00140         if( sound_vol > 0.2 )
00141         {
00142             // Make sound based on classname...
00143     
00144             // ARMOR...
00145             if( (  self.goalentity.classname == "item_armor1"
00146                 || self.goalentity.classname == "item_armor2"
00147                 || self.goalentity.classname == "item_armorInv" )
00148                 && snap_misc_ownervisible(self.goalentity.origin) )
00149             {
00150                 matched = true;
00151                 safe_soundtoclient(self.owner, self.goalentity, CHAN_ITEM, "items/armor1.wav", sound_vol, ATTN_NORM);
00152             }
00153             // HEALTH...
00154             else if( self.goalentity.classname == "item_health" 
00155                   && snap_misc_ownervisible(self.goalentity.origin) )
00156             {
00157                 matched = true;
00158                     safe_soundtoclient(self.owner, self.goalentity, CHAN_ITEM, "items/health1.wav", sound_vol, ATTN_NORM);
00159             }
00160             // AMMO...
00161             else if( (  self.goalentity.classname == "item_shells"
00162                      || self.goalentity.classname == "item_spikes"
00163                      || self.goalentity.classname == "item_rockets"
00164                      || self.goalentity.classname == "item_cells" )
00165                      && snap_misc_ownervisible(self.goalentity.origin) )
00166             {
00167                 matched = true;
00168                 safe_soundtoclient(self.owner, self.goalentity, CHAN_ITEM, "weapons/lock4.wav", sound_vol, ATTN_NORM);
00169             }
00170             // DROPPED BACKPACK...
00171             else if( self.goalentity.classname == "" 
00172                   && snap_misc_ownervisible(self.goalentity.origin) )
00173             {
00174                 matched = true;
00175                 safe_soundtoclient(self.owner, self.goalentity, CHAN_ITEM, "d5k/backpack.wav", sound_vol, ATTN_NORM);
00176             }
00177             // SWITCH...
00178             // Note: Assume state = STATE_TOP if it isn't STATE_BOTTOM.
00179             else if( self.goalentity.classname == "func_button" 
00180                   && snap_misc_ownervisible(switch_origin) )
00181             {
00182                 matched = true;
00183 
00184                 if( self.goalentity.state == STATE_BOTTOM )
00185                 {
00186                         safe_soundtoclient(self.owner, self.goalentity, CHAN_ITEM, "buttons/switch04.wav", sound_vol, ATTN_NORM);
00187                 }
00188                 else if( self.skin )
00189                 {
00190                         safe_soundtoclient(self.owner, self.goalentity, CHAN_ITEM, "buttons/switch04.wav", sound_vol, ATTN_NORM);
00191                 }
00192             }
00193             // POWERUP (EnvSuit, Pentogram, RoS, Quad)...
00194             else if( self.goalentity.classname == "item_artifact_envirosuit" 
00195                       && snap_misc_ownervisible(self.goalentity.origin) )
00196             {
00197                 matched = true;
00198                 safe_soundtoclient(self.owner, self.goalentity, CHAN_ITEM, "items/suit.wav", sound_vol, ATTN_NORM);
00199             }
00200             else if( self.goalentity.classname == "item_artifact_invulnerability" 
00201                       && snap_misc_ownervisible(self.goalentity.origin) )
00202             {
00203                 matched = true;
00204                 safe_soundtoclient(self.owner, self.goalentity, CHAN_ITEM, "items/protect.wav", sound_vol, ATTN_NORM);
00205             }
00206             else if( self.goalentity.classname == "item_artifact_invisibility" 
00207                       && snap_misc_ownervisible(self.goalentity.origin) )
00208             {
00209                 matched = true;
00210                 safe_soundtoclient(self.owner, self.goalentity, CHAN_ITEM, "items/inv1.wav", sound_vol, ATTN_NORM);
00211             }
00212             else if( self.goalentity.classname == "item_artifact_super_damage" 
00213                       && snap_misc_ownervisible(self.goalentity.origin) )
00214             {
00215                 matched = true;
00216                 safe_soundtoclient(self.owner, self.goalentity, CHAN_ITEM, "items/damage3.wav", sound_vol, ATTN_NORM);
00217             }
00218             // KEY...
00219             else if( (  self.goalentity.classname == "item_key1"
00220                          || self.goalentity.classname == "item_key2" )
00221                          && snap_misc_ownervisible(self.goalentity.origin) )
00222             {
00223                 matched = true;
00224                 // AG_FIXME: sound change needed for key
00225                     safe_soundtoclient(self.owner, self.goalentity, CHAN_ITEM, "misc/talk.wav", sound_vol, ATTN_NORM);
00226             }
00227             // WEAPON...
00228             else if( (  self.goalentity.classname == "weapon_nailgun"
00229                          || self.goalentity.classname == "weapon_supernailgun"
00230                      || self.goalentity.classname == "weapon_supershotgun"
00231                          || self.goalentity.classname == "weapon_rocketlauncher"
00232                          || self.goalentity.classname == "weapon_grenadelauncher"
00233                          || self.goalentity.classname == "weapon_lightning" )
00234                          && snap_misc_ownervisible(self.goalentity.origin) )
00235             {
00236                 matched = true;
00237                     safe_soundtoclient(self.owner, self.goalentity, CHAN_ITEM, "weapons/pkup.wav", sound_vol, ATTN_NORM);
00238             }
00239         }
00240 
00241         if( matched )
00242         {
00243             self.nextthink = time + 0.5;
00244             // Debug.info
00245             /*dprint("CT: ");dprint(ftos(time));
00246             dprint(" NT: ");dprint(ftos(self.nextthink));
00247             dprint(" SV: ");dprint(ftos(sound_vol));
00248             dprint(" GE: ");dprint(self.goalentity.classname);
00249             dprint(" GEO: ");dprint(vtos(self.goalentity.origin));
00250             dprint(" M: ");dprint(ftos(matched));
00251             dprint("\n");*/
00252         }
00253         else
00254         {
00255             self.nextthink = time + 0.01;
00256         }
00257 
00258             // Go to next entity in chain retunred by findradius()...
00259             self.goalentity = self.goalentity.chain;
00260     }
00261     else
00262     {
00263         // Finished this scan... when do we do it all again?
00264         self.think = snap_d5k_starter;
00265         self.nextthink = time + self.health;
00266     }
00267 };
00268 
00269 /* $AGRIP-END */

Generated on Tue Jan 1 17:55:54 2008 for AudioQuake QuakeC by  doxygen 1.5.4