Example #1
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);
}
Example #2
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;
}
Example #3
0
void buildTempNetwork(MECH * mech, dbref * myNetwork, int *networkSize,
					  int tCheckECM, int tCheckStarted, int tCheckUncon,
					  int tIsC3)
{
	int tempNetworkSize = 0;
	int baseNetworkSize;
	MECH *otherMech;
	dbref myTempNetwork[C3_NETWORK_SIZE];
	int i;

	/* Re-init the network */
	for(i = 0; i < C3_NETWORK_SIZE; i++)
		myNetwork[i] = -1;

	*networkSize = 0;

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

	if(baseNetworkSize == 0)
		return;

	/*
	 * Build the base netork of all the mechs that fit the criteria we passed in
	 */
	for(i = 0; i < baseNetworkSize; i++) {
		otherMech =
			getOtherMechInNetwork(mech, i, tCheckECM, tCheckStarted,
								  tCheckUncon, tIsC3);

		if(!otherMech)
			continue;

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

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

	/*
	 * Once we're here, we're done with the C3i stuff, but we need to make sure that this is a valid C3 network
	 * still. For example, we may have lost a master due to death or something else, so we need to make sure we
	 * have enough masters left to actually do something.
	 *
	 * A valid network is one where there are MIN((((NUM_MASTERS * 4) - NUM_MASTERS) + ((MY_MASTERS * 4) - MY_MASTERS), 11) units in the network
	 */
	if(tIsC3) {
		if(tempNetworkSize > 0)
			tempNetworkSize =
				trimC3Network(mech, myTempNetwork, tempNetworkSize);
	}

	for(i = 0; i < tempNetworkSize; i++)
		myNetwork[i] = myTempNetwork[i];

	*networkSize = tempNetworkSize;
}
Example #4
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)));
}