00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "mech.h"
00016 #include "mech.events.h"
00017 #include "p.mech.c3i.h"
00018 #include "p.mech.c3.misc.h"
00019 #include "p.mech.utils.h"
00020 #include "p.mech.los.h"
00021 #include "p.mech.contacts.h"
00022
00023 #define C3_POS_IN_NETWORK -1
00024 #define C3_POS_NO_ROOM -2
00025
00026 int getFreeC3iNetworkPos(MECH * mech, MECH * mechToAdd)
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 }
00045
00046 void replicateC3iNetwork(MECH * mechSrc, MECH * mechDest)
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 }
00071
00072 void addMechToC3iNetwork(MECH * mech, MECH * mechToAdd)
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
00084 wPos = getFreeC3iNetworkPos(mech, mechToAdd);
00085
00086
00087 if(wPos < 0)
00088 return;
00089
00090
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
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
00124 validateC3iNetwork(mech);
00125 }
00126
00127 void clearMechFromC3iNetwork(dbref refToClear, MECH * mech)
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 }
00144
00145 void clearC3iNetwork(MECH * mech, int tClearFromOthers)
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 }
00170
00171 void validateC3iNetwork(MECH * mech)
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 }
00217
00218 void mech_c3i_join_leave(dbref player, void *data, char *buffer)
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
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
00256
00257 DOCHECK(MechC3iNetworkSize(mech) > 0,
00258 "You are already in a C3i network!");
00259
00260 objMap = getMap(mech->mapindex);
00261
00262
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
00283 validateC3iNetwork(target);
00284 DOCHECK(MechC3iNetworkSize(target) >= C3I_NETWORK_SIZE,
00285 "That unit's C3i network is operating at maximum capacity!");
00286
00287
00288 mech_notify(mech, MECHALL, tprintf("You connect to %s's C3i network.",
00289 GetMechToMechID(mech, target)));
00290
00291 addMechToC3iNetwork(target, mech);
00292 }
00293
00294 void mech_c3i_message(dbref player, MECH * mech, char *buffer)
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 }
00313
00314 void mech_c3i_targets(dbref player, MECH * mech, char *buffer)
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 }
00330
00331 void mech_c3i_network(dbref player, MECH * mech, char *buffer)
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 }