src/hcode/btech/mech.tag.c

Go to the documentation of this file.
00001 /*
00002  * Author: Cord Awtry <kipsta@mediaone.net>
00003  *
00004  *  Copyright (c) 2001 Cord Awtry
00005  *       All rights reserved
00006  */
00007 
00008 #include "mech.h"
00009 #include "mech.events.h"
00010 #include "p.mech.tag.h"
00011 #include "p.mech.los.h"
00012 #include "p.mech.utils.h"
00013 
00014 #define TAGRECYCLE_TICK 30
00015 #define TAG_SHORT 5
00016 #define TAG_MED   10
00017 #define TAG_LONG  15
00018 
00019 static void tag_recycle_event(MUXEVENT * e)
00020 {
00021         MECH *mech = (MECH *) e->data;
00022         int data = (int) e->data2;
00023         MECH *target;
00024 
00025         if(isTAGDestroyed(mech))
00026                 return;
00027 
00028         if(data == 0) {
00029                 mech_notify(mech, MECHALL,
00030                                         "%cgYour TAG system has finished recycling.%cn");
00031                 return;
00032         }
00033 
00034         target = getMech(TAGTarget(mech));
00035 
00036         if(!target)
00037                 return;
00038 
00039         if(TaggedBy(target) != mech->mynum)
00040                 return;
00041 
00042         mech_notify(mech, MECHALL,
00043                                 "%cgYour TAG system has achieved a stable lock.%cn");
00044 }
00045 
00046 void mech_tag(dbref player, void *data, char *buffer)
00047 {
00048         MECH *mech = (MECH *) data, *target;
00049         MAP *objMap;
00050         char *args[2];
00051         dbref refTarget;
00052         int LOS = 1;
00053         float range = 0.0;
00054 
00055         cch(MECH_USUALO);
00056 
00057         DOCHECK(!HasTAG(mech), "This unit is not equipped with TAG!");
00058         DOCHECK(isTAGDestroyed(mech), "Your TAG system is destroyed!");
00059         DOCHECK(TagRecycling(mech), "Your TAG system is recycling!");
00060         DOCHECK(mech_parseattributes(buffer, args, 2) != 1,
00061                         "Invalid number of arguments to function!");
00062 
00063         objMap = getMap(mech->mapindex);
00064 
00065         /* Clear our TAG */
00066         if(!strcmp(args[0], "-")) {
00067                 refTarget = TAGTarget(mech);
00068 
00069                 DOCHECK(refTarget <= 0, "You are not currently tagging anything!");
00070 
00071                 stopTAG(mech);
00072 
00073                 return;
00074         }
00075 
00076         /* TAG something... anything :) */
00077         refTarget = FindTargetDBREFFromMapNumber(mech, args[0]);
00078         target = getMech(refTarget);
00079 
00080         if(target) {
00081                 range = FlMechRange(objMap, mech, target);
00082 
00083                 LOS =
00084                         InLineOfSight_NB(mech, target, MechX(target), MechY(target),
00085                                                          range);
00086         } else
00087                 refTarget = 0;
00088 
00089         DOCHECK(refTarget < 1 ||
00090                         !LOS, "That is not a valid TAG targetID. Try again.");
00091         DOCHECK(MechTeam(mech) == MechTeam(target),
00092                         "You can't TAG friendly units!");
00093         DOCHECK(mech == target, "You can't TAG yourself!");
00094         DOCHECK(range > TAG_LONG,
00095                         tprintf("Out of range! TAG ranges are %d/%d/%d", TAG_SHORT,
00096                                         TAG_MED, TAG_LONG));
00097 
00098         /*
00099          * This should actually make a roll...
00100          */
00101 
00102         /*
00103            if ( checkAllSections(mech,INARC_HAYWIRE_ATTACHED) )
00104            BTH += 1;
00105          */
00106 
00107         mech_printf(mech, MECHALL, "You light up %s with your TAG.",
00108                                 GetMechToMechID(mech, target));
00109 
00110         TaggedBy(target) = mech->mynum;
00111         TAGTarget(mech) = target->mynum;
00112 
00113         MECHEVENT(mech, EVENT_TAG_RECYCLE, tag_recycle_event, TAGRECYCLE_TICK, 1);
00114 }
00115 
00116 int isTAGDestroyed(MECH * mech)
00117 {
00118         if((MechSpecials2(mech) & TAG_TECH) &&
00119            (MechCritStatus(mech) & TAG_DESTROYED))
00120                 return 1;
00121 
00122         if(HasC3m(mech) && (MechCritStatus(mech) & C3_DESTROYED))
00123                 return 1;
00124 
00125         return 0;
00126 }
00127 
00128 void stopTAG(MECH * mech)
00129 {
00130         MECH *target;
00131 
00132         target = getMech(TAGTarget(mech));
00133 
00134         if(target)
00135                 if(TaggedBy(target) == mech->mynum)
00136                         TaggedBy(target) = 0;
00137 
00138         if(TAGTarget(mech) > 0) {
00139                 TAGTarget(mech) = 0;
00140 
00141                 mech_notify(mech, MECHALL, "Your TAG connection has been broken.");
00142 
00143                 MECHEVENT(mech, EVENT_TAG_RECYCLE, tag_recycle_event,
00144                                   TAGRECYCLE_TICK, 0);
00145         }
00146 }
00147 
00148 void checkTAG(MECH * mech)
00149 {
00150         MECH *target;
00151         dbref refTarget;
00152         float range;
00153         int LOS = 1;
00154 
00155         refTarget = TAGTarget(mech);
00156 
00157         if(refTarget <= 0)
00158                 return;
00159 
00160         target = getMech(refTarget);
00161 
00162         if(!target) {
00163                 stopTAG(mech);
00164                 return;
00165         }
00166 
00167         if(TaggedBy(target) != mech->mynum) {
00168                 stopTAG(mech);
00169                 return;
00170         }
00171 
00172         range = FlMechRange(getMap(mech->mapindex), mech, target);
00173         LOS = InLineOfSight_NB(mech, target, MechX(target), MechY(target), range);
00174 
00175         if(!LOS || (range > TAG_LONG)) {
00176                 stopTAG(mech);
00177                 return;
00178         }
00179 }

Generated on Mon May 28 04:25:23 2007 for BattletechMUX by  doxygen 1.4.7