agrip/marker.mqc

Go to the documentation of this file.
00001 /*  Copyright 2004 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 Waypoint Marker Object */
00022 
00023 
00024 // PROTOTYPES
00025 
00026 void snap_marker_constructor();
00027 void snap_marker_destructor(float quiet);
00028 void snap_marker_touch();
00029 
00030 
00031 // IMPLEMENTATIONS
00032 
00048 void snap_marker_constructor()
00049 {
00050     local entity new_agmarker;
00051     local string marker_number;
00052 
00053     // Limit number of markers...
00054     if( self.agrip_aux.health > 19 )
00055     {
00056         snap_misc_m2m("The Arena Masters are angered at your marker-spammage!\n");
00057         return;
00058     }
00059                                                                                            
00060     // Set up new marker object's physical properties...
00061     new_agmarker = spawn();
00062     new_agmarker.movetype = MOVETYPE_NONE;
00063     new_agmarker.solid = SOLID_TRIGGER;
00064     setorigin(new_agmarker, self.origin);
00065     setmodel(new_agmarker, "progs/s_light.spr");
00066 
00067     // Sound...
00068     new_agmarker.message = "nav/marker.wav";
00069     new_agmarker.health = 2;
00070 
00071     // Volume throttle for the sound this object will make...
00072     new_agmarker.frags = stof(infokey(self, "agv_marker_volume_throttle"));
00073     if( new_agmarker.frags > 1 || new_agmarker.frags < 0 )
00074         new_agmarker.frags = 0.3;
00075    
00076     // Connect the object and player...
00077     new_agmarker.owner = self;
00078 
00079     // Work out which number it is to be...
00080     self.agrip_aux.health = self.agrip_aux.health + 1;
00081     new_agmarker.items = self.agrip_aux.health;
00082 
00083     // Set up the classname...
00084     new_agmarker.classname = "agrip_marker";
00085 
00086     // Give it life...
00087     new_agmarker.ammo_shells = time;
00088     new_agmarker.ammo_rockets = 2;
00089     new_agmarker.think = snap_se_loopedsound;
00090     new_agmarker.touch = snap_marker_touch;
00091     new_agmarker.nextthink = time + 0.1;
00092 
00093     // Done!
00094     marker_number = ftos(new_agmarker.items);
00095     snap_misc_m2m("Marker number ");
00096     sprint(self, 1, marker_number);
00097     sprint(self, 1, " created.\n");
00098 };
00099 
00107 void snap_marker_destructor(float quiet)
00108 {
00109     local float exitflag;
00110     local entity find_start_ent;
00111     local entity found_ent;
00112     local string marker_number;
00113 
00114     // debug info
00115     /*dprint(self.netname);
00116     dprint(" md START.  num: ");
00117     dprint(ftos(self.agrip_aux.health));
00118     dprint("\n");*/
00119 
00120     if( self.agrip_aux.health == 0 )
00121     {
00122         // No markers...
00123         snap_misc_m2m("No waypoint markers to delete.\n");
00124         safe_soundtoclient(self, self, CHAN_AUTO, "deny.wav", 1, ATTN_NORM);
00125     }
00126     else
00127     {
00128         // Markers exist...
00129         find_start_ent = world;
00130    
00131         // Look for this player's last marker and remove it.
00132         // This could be called by the dietidy() hook, in which case don't spam
00133         // the player with messages saying each one has been remved.
00134         while( !exitflag )
00135         {
00136             found_ent = find(find_start_ent, classname, "agrip_marker");
00137 
00138             // debug info
00139             /*dprint(self.netname);
00140             dprint(" md PREMID.  num: ");
00141             dprint(ftos(self.agrip_aux.health));
00142             dprint("  thismkrnum: ");
00143             dprint(ftos(found_ent.items));
00144             dprint("  found_ent.owner.netname = ");
00145             dprint(found_ent.owner.netname);
00146             dprint("\n");*/
00147             
00148             if(    found_ent.owner == self
00149                 && found_ent.items == self.agrip_aux.health )
00150             {
00151                 // debug info
00152                 /*dprint(self.netname);
00153                 dprint(" md MID.  num: ");
00154                 dprint(ftos(self.agrip_aux.health));
00155                 dprint("  marker.items: ");
00156                 dprint(ftos(found_ent.items));
00157                 dprint("\n");*/
00158 
00159                 remove(found_ent);
00160                 if( !quiet )
00161                 {
00162                     marker_number = ftos(self.agrip_aux.health);
00163                     snap_misc_m2m("Waypoint marker ");
00164                     sprint(self, 1, marker_number);
00165                     sprint(self, 1, " deleted.\n");
00166                 }
00167                 self.agrip_aux.health = self.agrip_aux.health - 1;
00168                 exitflag = true;
00169             }
00170             else
00171             {
00172                 find_start_ent = found_ent;
00173             }
00174         }
00175     }
00176 
00177     // debug info
00178     /*dprint(self.netname);
00179     dprint(" md END.  num: ");
00180     dprint(ftos(self.agrip_aux.health));
00181     dprint("\n");*/
00182 };
00183 
00184 /*
00185     Tell the user they've found a marker.
00186 */
00187 void snap_marker_touch()
00188 {
00189     local string marker_number;
00190 
00191     if( other == self.owner && time > self.ammo_shells + self.ammo_rockets )
00192     {
00193         marker_number = ftos(self.items);
00194         sprint(other, 1, "!You found marker ", marker_number, ".\n");
00195         self.ammo_shells = time;
00196     }
00197 };
00198 
00199 /* $AGRIP-END */

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