src/hcode/btech/mech.c3i.c File Reference

#include "mech.h"
#include "mech.events.h"
#include "p.mech.c3i.h"
#include "p.mech.c3.misc.h"
#include "p.mech.utils.h"
#include "p.mech.los.h"
#include "p.mech.contacts.h"

Include dependency graph for mech.c3i.c:

Go to the source code of this file.

Defines

#define C3_POS_IN_NETWORK   -1
#define C3_POS_NO_ROOM   -2

Functions

int getFreeC3iNetworkPos (MECH *mech, MECH *mechToAdd)
void replicateC3iNetwork (MECH *mechSrc, MECH *mechDest)
void addMechToC3iNetwork (MECH *mech, MECH *mechToAdd)
void clearMechFromC3iNetwork (dbref refToClear, MECH *mech)
void clearC3iNetwork (MECH *mech, int tClearFromOthers)
void validateC3iNetwork (MECH *mech)
void mech_c3i_join_leave (dbref player, void *data, char *buffer)
void mech_c3i_message (dbref player, MECH *mech, char *buffer)
void mech_c3i_targets (dbref player, MECH *mech, char *buffer)
void mech_c3i_network (dbref player, MECH *mech, char *buffer)


Define Documentation

#define C3_POS_IN_NETWORK   -1

Definition at line 23 of file mech.c3i.c.

#define C3_POS_NO_ROOM   -2

Definition at line 24 of file mech.c3i.c.


Function Documentation

void addMechToC3iNetwork ( MECH mech,
MECH mechToAdd 
)

Definition at line 72 of file mech.c3i.c.

References C3I_NETWORK_SIZE, debugC3(), getFreeC3iNetworkPos(), GetMechToMechID(), getOtherMechInNetwork(), Good_obj, mech_notify(), MECHALL, MechC3iNetworkElem, MechC3iNetworkSize, MECH::mynum, replicateC3iNetwork(), tprintf(), and validateC3iNetwork().

Referenced by mech_c3i_join_leave().

00073 {
00074         MECH *otherMech;
00075         MECH *otherNotifyMech;
00076         dbref otherRef;
00077         int i;
00078         int wPos = -1;
00079 
00080         debugC3(tprintf("ADD: %d to the C3i network of %d", mechToAdd->mynum,
00081                                         mech->mynum));
00082 
00083         /* Find a position to add the new mech into my network */
00084         wPos = getFreeC3iNetworkPos(mech, mechToAdd);
00085 
00086         /* If we have a number that's less than 0, then we have an invalid position. Either we're already in the network or there's not enough room */
00087         if(wPos < 0)
00088                 return;
00089 
00090         /* Well, we have a valid position, so let's put this mech in the network */
00091         MechC3iNetworkElem(mech, wPos) = mechToAdd->mynum;
00092         MechC3iNetworkSize(mech) += 1;
00093 
00094         mech_notify(mech, MECHALL,
00095                                 tprintf("%s connects to your C3i network.",
00096                                                 GetMechToMechID(mech, mechToAdd)));
00097 
00098         /* Now let's replicate the new network across the system so that everyone has the same network settings */
00099         for(i = 0; i < C3I_NETWORK_SIZE; i++) {
00100                 otherRef = MechC3iNetworkElem(mech, i);
00101 
00102                 otherMech = getOtherMechInNetwork(mech, i, 0, 0, 0, 0);
00103 
00104                 if(!otherMech)
00105                         continue;
00106 
00107                 if(!Good_obj(otherMech->mynum))
00108                         continue;
00109 
00110                 if(otherRef != mechToAdd->mynum) {
00111                         otherNotifyMech = getOtherMechInNetwork(mech, i, 1, 1, 1, 0);
00112 
00113                         if(otherNotifyMech)
00114                                 mech_notify(otherNotifyMech, MECHALL,
00115                                                         tprintf("%s connects to your C3i network.",
00116                                                                         GetMechToMechID(otherNotifyMech,
00117                                                                                                         mechToAdd)));
00118                 }
00119 
00120                 replicateC3iNetwork(mech, otherMech);
00121         }
00122 
00123         /* Last, but not least, one final validation of the network */
00124         validateC3iNetwork(mech);
00125 }

void clearC3iNetwork ( MECH mech,
int  tClearFromOthers 
)

Definition at line 145 of file mech.c3i.c.

References C3I_NETWORK_SIZE, clearMechFromC3iNetwork(), debugC3(), getOtherMechInNetwork(), Good_obj, MechC3iNetworkElem, MechC3iNetworkSize, MECH::mynum, and tprintf().

Referenced by HandleMechCrit(), mech_c3i_join_leave(), mech_Rsetmapindex(), replicateC3iNetwork(), and validateC3iNetwork().

00146 {
00147         MECH *otherMech;
00148         int i;
00149 
00150         debugC3(tprintf("CLEAR: %d's C3i network", mech->mynum));
00151 
00152         for(i = 0; i < C3I_NETWORK_SIZE; i++) {
00153                 otherMech = getOtherMechInNetwork(mech, i, 0, 0, 0, 0);
00154 
00155                 MechC3iNetworkElem(mech, i) = -1;
00156 
00157                 if(tClearFromOthers) {
00158                         if(!otherMech)
00159                                 continue;
00160 
00161                         if(!Good_obj(otherMech->mynum))
00162                                 continue;
00163 
00164                         clearMechFromC3iNetwork(mech->mynum, otherMech);
00165                 }
00166         }
00167 
00168         MechC3iNetworkSize(mech) = 0;
00169 }

void clearMechFromC3iNetwork ( dbref  refToClear,
MECH mech 
)

Definition at line 127 of file mech.c3i.c.

References C3I_NETWORK_SIZE, debugC3(), MechC3iNetworkElem, MechC3iNetworkSize, MECH::mynum, tprintf(), and validateC3iNetwork().

Referenced by clearC3iNetwork().

00128 {
00129         int i;
00130 
00131         debugC3(tprintf("CLEAR: %d from the C3i network of %d", refToClear,
00132                                         mech->mynum));
00133 
00134         if(!MechC3iNetworkSize(mech))
00135                 return;
00136 
00137         for(i = 0; i < C3I_NETWORK_SIZE; i++) {
00138                 if(MechC3iNetworkElem(mech, i) == refToClear)
00139                         MechC3iNetworkElem(mech, i) = -1;
00140         }
00141 
00142         validateC3iNetwork(mech);
00143 }

int getFreeC3iNetworkPos ( MECH mech,
MECH mechToAdd 
)

Definition at line 26 of file mech.c3i.c.

References C3_POS_IN_NETWORK, C3_POS_NO_ROOM, C3I_NETWORK_SIZE, MechC3iNetworkElem, MECH::mynum, and validateC3iNetwork().

Referenced by addMechToC3iNetwork().

00027 {
00028         int i;
00029         dbref otherRef;
00030 
00031         validateC3iNetwork(mech);
00032 
00033         for(i = 0; i < C3I_NETWORK_SIZE; i++) {
00034                 otherRef = MechC3iNetworkElem(mech, i);
00035 
00036                 if(otherRef > 0) {
00037                         if(otherRef == mechToAdd->mynum)
00038                                 return C3_POS_IN_NETWORK;
00039                 } else
00040                         return i;
00041         }
00042 
00043         return C3_POS_NO_ROOM;
00044 }

void mech_c3i_join_leave ( dbref  player,
void *  data,
char *  buffer 
)

Definition at line 218 of file mech.c3i.c.

References addMechToC3iNetwork(), AnyECMDisturbed, args, C3I_NETWORK_SIZE, C3iDestroyed, cch, clearC3iNetwork(), Destroyed, DOCHECK, FindTargetDBREFFromMapNumber(), getMap(), getMech(), GetMechToMechID(), HasC3i, InLineOfSight(), MECH::mapindex, mech_notify(), mech_parseattributes(), MECH_USUALO, MECHALL, MechC3iNetworkSize, MechTeam, MechX, MechY, Started, tprintf(), and validateC3iNetwork().

00219 {
00220         MECH *mech = (MECH *) data, *target;
00221         MAP *objMap;
00222         char *args[2];
00223         dbref refTarget;
00224         int LOS = 1;
00225         float range = 0.0;
00226 
00227         cch(MECH_USUALO);
00228 
00229         DOCHECK(mech_parseattributes(buffer, args, 2) != 1,
00230                         "Invalid number of arguments to function!");
00231 
00232         DOCHECK(!HasC3i(mech), "This unit is not equipped with C3i!");
00233         DOCHECK(C3iDestroyed(mech), "Your C3i system is destroyed!");
00234         DOCHECK(AnyECMDisturbed(mech),
00235                         "Your C3i system is not currently operational!");
00236 
00237         validateC3iNetwork(mech);
00238 
00239         /* Clear our C3i Network */
00240         if(!strcmp(args[0], "-")) {
00241                 if(MechC3iNetworkSize(mech) <= 0) {
00242                         mech_notify(mech, MECHALL,
00243                                                 "You are not connected to a C3i network!");
00244 
00245                         return;
00246                 }
00247 
00248                 clearC3iNetwork(mech, 1);
00249 
00250                 mech_notify(mech, MECHALL, "You disconnect from the C3i network.");
00251 
00252                 return;
00253         }
00254 
00255         /* Well, if we're here then we wanna connect to a network */
00256         /* Let's check to see if we're already in one... can't be in two at the same time */
00257         DOCHECK(MechC3iNetworkSize(mech) > 0,
00258                         "You are already in a C3i network!");
00259 
00260         objMap = getMap(mech->mapindex);
00261 
00262         /* Find who we're trying to connect to */
00263         refTarget = FindTargetDBREFFromMapNumber(mech, args[0]);
00264         target = getMech(refTarget);
00265 
00266         if(target) {
00267                 LOS =
00268                         InLineOfSight(mech, target, MechX(target), MechY(target), range);
00269         } else
00270                 refTarget = 0;
00271 
00272         DOCHECK((refTarget < 1) ||
00273                         !LOS, "That is not a valid targetID. Try again.");
00274         DOCHECK(MechTeam(mech) != MechTeam(target),
00275                         "You can't use the C3i network of unfriendly units!");
00276         DOCHECK(mech == target, "You can't connect to yourself!");
00277         DOCHECK(Destroyed(target), "That unit is destroyed!");
00278         DOCHECK(!Started(target), "That unit is not started!");
00279         DOCHECK(!HasC3i(target),
00280                         "That unit does not appear to be equipped with C3i!");
00281 
00282         /* validate the network of our target */
00283         validateC3iNetwork(target);
00284         DOCHECK(MechC3iNetworkSize(target) >= C3I_NETWORK_SIZE,
00285                         "That unit's C3i network is operating at maximum capacity!");
00286 
00287         /* Connect us up */
00288         mech_notify(mech, MECHALL, tprintf("You connect to %s's C3i network.",
00289                                                                            GetMechToMechID(mech, target)));
00290 
00291         addMechToC3iNetwork(target, mech);
00292 }

void mech_c3i_message ( dbref  player,
MECH mech,
char *  buffer 
)

Definition at line 294 of file mech.c3i.c.

References AnyECMDisturbed, C3iDestroyed, cch, DOCHECK, HasC3i, MECH_USUALO, MechC3iNetworkSize, sendNetworkMessage(), skipws, and validateC3iNetwork().

00295 {
00296         cch(MECH_USUALO);
00297 
00298         DOCHECK(!HasC3i(mech), "This unit is not equipped with C3i!");
00299         DOCHECK(C3iDestroyed(mech), "Your C3i system is destroyed!");
00300         DOCHECK(AnyECMDisturbed(mech),
00301                         "Your C3i system is not currently operational!");
00302 
00303         validateC3iNetwork(mech);
00304 
00305         DOCHECK(MechC3iNetworkSize(mech) <= 0,
00306                         "There are no other units in your C3i network!");
00307 
00308         skipws(buffer);
00309         DOCHECK(!*buffer, "What do you want to send on the C3i Network?");
00310 
00311         sendNetworkMessage(player, mech, buffer, 0);
00312 }

void mech_c3i_network ( dbref  player,
MECH mech,
char *  buffer 
)

Definition at line 331 of file mech.c3i.c.

References AnyECMDisturbed, C3iDestroyed, cch, DOCHECK, HasC3i, MECH_USUALO, MechC3iNetworkSize, showNetworkData(), and validateC3iNetwork().

00332 {
00333         cch(MECH_USUALO);
00334 
00335         DOCHECK(!HasC3i(mech), "This unit is not equipped with C3i!");
00336         DOCHECK(C3iDestroyed(mech), "Your C3i system is destroyed!");
00337         DOCHECK(AnyECMDisturbed(mech),
00338                         "Your C3i system is not currently operational!");
00339 
00340         validateC3iNetwork(mech);
00341 
00342         DOCHECK(MechC3iNetworkSize(mech) <= 0,
00343                         "There are no other units in your C3i network!");
00344 
00345         showNetworkData(player, mech, 0);
00346 }

void mech_c3i_targets ( dbref  player,
MECH mech,
char *  buffer 
)

Definition at line 314 of file mech.c3i.c.

References AnyECMDisturbed, C3iDestroyed, cch, DOCHECK, HasC3i, MECH_USUALO, MechC3iNetworkSize, showNetworkTargets(), and validateC3iNetwork().

00315 {
00316         cch(MECH_USUALO);
00317 
00318         DOCHECK(!HasC3i(mech), "This unit is not equipped with C3i!");
00319         DOCHECK(C3iDestroyed(mech), "Your C3i system is destroyed!");
00320         DOCHECK(AnyECMDisturbed(mech),
00321                         "Your C3i system is not currently operational!");
00322 
00323         validateC3iNetwork(mech);
00324 
00325         DOCHECK(MechC3iNetworkSize(mech) <= 0,
00326                         "There are no other units in your C3i network!");
00327 
00328         showNetworkTargets(player, mech, 0);
00329 }

void replicateC3iNetwork ( MECH mechSrc,
MECH mechDest 
)

Definition at line 46 of file mech.c3i.c.

References C3I_NETWORK_SIZE, clearC3iNetwork(), debugC3(), MechC3iNetworkElem, MechC3iNetworkSize, MECH::mynum, and tprintf().

Referenced by addMechToC3iNetwork().

00047 {
00048         int i;
00049         dbref otherRef;
00050 
00051         debugC3(tprintf("REPLICATE: %d's C3i network to %d", mechSrc->mynum,
00052                                         mechDest->mynum));
00053 
00054         clearC3iNetwork(mechDest, 0);
00055 
00056         MechC3iNetworkElem(mechDest, 0) = mechSrc->mynum;
00057         MechC3iNetworkSize(mechDest) = 1;
00058 
00059         for(i = 0; i < C3I_NETWORK_SIZE; i++) {
00060                 otherRef = MechC3iNetworkElem(mechSrc, i);
00061 
00062                 if(otherRef != mechDest->mynum) {
00063                         MechC3iNetworkElem(mechDest, MechC3iNetworkSize(mechDest)) =
00064                                 otherRef;
00065                         MechC3iNetworkSize(mechDest) += 1;
00066                 }
00067         }
00068 
00069         validateC3iNetwork(mechDest);
00070 }

void validateC3iNetwork ( MECH mech  ) 

Definition at line 171 of file mech.c3i.c.

References C3I_NETWORK_SIZE, C3iDestroyed, clearC3iNetwork(), debugC3(), Destroyed, getOtherMechInNetwork(), Good_obj, HasC3i, MechC3iNetworkElem, MechC3iNetworkSize, MECH::mynum, and tprintf().

Referenced by addMechToC3iNetwork(), clearMechFromC3iNetwork(), findC3Range(), getFreeC3iNetworkPos(), mech_c3i_join_leave(), mech_c3i_message(), mech_c3i_network(), and mech_c3i_targets().

00172 {
00173         MECH *otherMech;
00174         dbref myTempNetwork[C3I_NETWORK_SIZE];
00175         int i;
00176         int networkSize = 0;
00177 
00178         debugC3(tprintf("VALIDATE: %d's C3i network", mech->mynum));
00179 
00180         if(!HasC3i(mech) || Destroyed(mech) || C3iDestroyed(mech)) {
00181                 clearC3iNetwork(mech, 1);
00182 
00183                 return;
00184         }
00185 
00186         if(MechC3iNetworkSize(mech) < 0) {
00187                 clearC3iNetwork(mech, 1);
00188 
00189                 return;
00190         }
00191 
00192         for(i = 0; i < C3I_NETWORK_SIZE; i++) {
00193                 otherMech = getOtherMechInNetwork(mech, i, 0, 0, 0, 0);
00194 
00195                 if(!otherMech)
00196                         continue;
00197 
00198                 if(!Good_obj(otherMech->mynum))
00199                         continue;
00200 
00201                 debugC3(tprintf("VALIDATE INFO: %d is now in %d's C3i network",
00202                                                 otherMech->mynum, mech->mynum));
00203 
00204                 myTempNetwork[networkSize++] = otherMech->mynum;
00205         }
00206 
00207         clearC3iNetwork(mech, 0);
00208 
00209         for(i = 0; i < networkSize; i++)
00210                 MechC3iNetworkElem(mech, i) = myTempNetwork[i];
00211 
00212         MechC3iNetworkSize(mech) = networkSize;
00213 
00214         debugC3(tprintf("VALIDATE INFO: %d's C3i network is %d elements",
00215                                         mech->mynum, MechC3iNetworkSize(mech)));
00216 }


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