Beispiel #1
0
void replicateC3iNetwork(MECH * mechSrc, MECH * mechDest)
{
    int i;
    dbref otherRef;

    debugC3(tprintf("REPLICATE: %d's C3i network to %d", mechSrc->mynum,
	    mechDest->mynum));

    clearC3iNetwork(mechDest, 0);

    MechC3iNetworkElem(mechDest, 0) = mechSrc->mynum;
    MechC3iNetworkSize(mechDest) = 1;

    for (i = 0; i < C3I_NETWORK_SIZE; i++) {
	otherRef = MechC3iNetworkElem(mechSrc, i);

	if (otherRef != mechDest->mynum) {
	    MechC3iNetworkElem(mechDest, MechC3iNetworkSize(mechDest)) =
		otherRef;
	    MechC3iNetworkSize(mechDest) += 1;
	}
    }

    validateC3iNetwork(mechDest);
}
Beispiel #2
0
void addMechToC3iNetwork(MECH * mech, MECH * mechToAdd)
{
    MECH *otherMech;
    MECH *otherNotifyMech;
    dbref otherRef;
    int i;
    int wPos = -1;

    debugC3(tprintf("ADD: %d to the C3i network of %d", mechToAdd->mynum,
	    mech->mynum));

    /* Find a position to add the new mech into my network */
    wPos = getFreeC3iNetworkPos(mech, mechToAdd);

    /* 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 */
    if (wPos < 0)
	return;

    /* Well, we have a valid position, so let's put this mech in the network */
    MechC3iNetworkElem(mech, wPos) = mechToAdd->mynum;
    MechC3iNetworkSize(mech) += 1;

    mech_notify(mech, MECHALL,
	tprintf("%s connects to your C3i network.",
	    GetMechToMechID(mech, mechToAdd)));

    /* Now let's replicate the new network across the system so that everyone has the same network settings */
    for (i = 0; i < C3I_NETWORK_SIZE; i++) {
	otherRef = MechC3iNetworkElem(mech, i);

	otherMech = getOtherMechInNetwork(mech, i, 0, 0, 0, 0);

	if (!otherMech)
	    continue;

	if (!Good_obj(otherMech->mynum))
	    continue;

	if (otherRef != mechToAdd->mynum) {
	    otherNotifyMech = getOtherMechInNetwork(mech, i, 1, 1, 1, 0);

	    if (otherNotifyMech)
		mech_notify(otherNotifyMech, MECHALL,
		    tprintf("%s connects to your C3i network.",
			GetMechToMechID(otherNotifyMech, mechToAdd)));
	}

	replicateC3iNetwork(mech, otherMech);
    }

    /* Last, but not least, one final validation of the network */
    validateC3iNetwork(mech);
}
Beispiel #3
0
void clearC3iNetwork(MECH * mech, int tClearFromOthers)
{
    MECH *otherMech;
    int i;

    debugC3(tprintf("CLEAR: %d's C3i network", mech->mynum));

    for (i = 0; i < C3I_NETWORK_SIZE; i++) {
	otherMech = getOtherMechInNetwork(mech, i, 0, 0, 0, 0);

	MechC3iNetworkElem(mech, i) = -1;

	if (tClearFromOthers) {
	    if (!otherMech)
		continue;

	    if (!Good_obj(otherMech->mynum))
		continue;

	    clearMechFromC3iNetwork(mech->mynum, otherMech);
	}
    }

    MechC3iNetworkSize(mech) = 0;
}
Beispiel #4
0
void clearMechFromC3iNetwork(dbref refToClear, MECH * mech)
{
    int i;

    debugC3(tprintf("CLEAR: %d from the C3i network of %d", refToClear,
	    mech->mynum));

    if (!MechC3iNetworkSize(mech))
	return;

    for (i = 0; i < C3I_NETWORK_SIZE; i++) {
	if (MechC3iNetworkElem(mech, i) == refToClear)
	    MechC3iNetworkElem(mech, i) = -1;
    }

    validateC3iNetwork(mech);
}
Beispiel #5
0
void validateC3iNetwork(MECH * mech)
{
    MECH *otherMech;
    dbref myTempNetwork[C3I_NETWORK_SIZE];
    int i;
    int networkSize = 0;

    debugC3(tprintf("VALIDATE: %d's C3i network", mech->mynum));

    if (!HasC3i(mech) || Destroyed(mech) || C3iDestroyed(mech)) {
	clearC3iNetwork(mech, 1);

	return;
    }

    if (MechC3iNetworkSize(mech) < 0) {
	clearC3iNetwork(mech, 1);

	return;
    }

    for (i = 0; i < C3I_NETWORK_SIZE; i++) {
	otherMech = getOtherMechInNetwork(mech, i, 0, 0, 0, 0);

	if (!otherMech)
	    continue;

	if (!Good_obj(otherMech->mynum))
	    continue;

	debugC3(tprintf("VALIDATE INFO: %d is now in %d's C3i network",
		otherMech->mynum, mech->mynum));

	myTempNetwork[networkSize++] = otherMech->mynum;
    }

    clearC3iNetwork(mech, 0);

    for (i = 0; i < networkSize; i++)
	MechC3iNetworkElem(mech, i) = myTempNetwork[i];

    MechC3iNetworkSize(mech) = networkSize;

    debugC3(tprintf("VALIDATE INFO: %d's C3i network is %d elements",
	    mech->mynum, MechC3iNetworkSize(mech)));
}
Beispiel #6
0
int getFreeC3iNetworkPos(MECH * mech, MECH * mechToAdd)
{
    int i;
    dbref otherRef;

    validateC3iNetwork(mech);

    for (i = 0; i < C3I_NETWORK_SIZE; i++) {
	otherRef = MechC3iNetworkElem(mech, i);

	if (otherRef > 0) {
	    if (otherRef == mechToAdd->mynum)
		return C3_POS_IN_NETWORK;
	} else
	    return i;
    }

    return C3_POS_NO_ROOM;
}
Beispiel #7
0
MECH *getOtherMechInNetwork(MECH * mech, int wIdx, int tCheckECM,
							int tCheckStarted, int tCheckUncon, int tIsC3)
{
	MECH *tempMech;
	dbref refOtherMech;
	int networkSize;

	networkSize =
		(tIsC3 ? MechC3NetworkSize(mech) : MechC3iNetworkSize(mech));

	if((wIdx >= networkSize) || (wIdx < 0))
		return NULL;

	refOtherMech =
		(tIsC3 ? MechC3NetworkElem(mech, wIdx) : MechC3iNetworkElem(mech,
																	wIdx));

	if(refOtherMech > 0) {
		tempMech = getMech(refOtherMech);

		if(!tempMech)
			return NULL;

		if(MechTeam(tempMech) != MechTeam(mech))
			return NULL;

		if(tempMech->mapindex != mech->mapindex)
			return NULL;

		if(Destroyed(tempMech))
			return NULL;

		if(tIsC3) {
			if(!HasC3(tempMech))	/* Sanity check */
				return NULL;

			if(C3Destroyed(tempMech))
				return NULL;
		} else {
			if(!HasC3i(tempMech))	/* Sanity check */
				return NULL;

			if(C3iDestroyed(tempMech))
				return NULL;
		}

		if(tCheckECM)
			if(AnyECMDisturbed(tempMech))
				return NULL;

		if(tCheckStarted)
			if(!Started(tempMech))
				return NULL;

		if(tCheckUncon)
			if(Uncon(tempMech))
				return NULL;

		return tempMech;
	}

	return NULL;
}