Exemplo n.º 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);
}
Exemplo n.º 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;
}
Exemplo n.º 3
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)));
}
Exemplo n.º 4
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);
}
Exemplo n.º 5
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);
}
Exemplo n.º 6
0
float findC3RangeWithNetwork(MECH * mech, MECH * mechTarget,
							 float realRange, dbref * myNetwork,
							 int networkSize, dbref * c3Ref)
{
	float c3Range = 0.0;
	float bestRange = 0.0;
	int i;
	int inLOS = 0;
	int mapX, mapY;
	float hexX, hexY, hexZ;
	MECH *otherMech;
	MAP *map;

	bestRange = realRange;
	*c3Ref = 0;

	if(networkSize == 0)
		return realRange;

	for(i = 0; i < networkSize; i++) {
		otherMech = getMechInTempNetwork(i, myNetwork, networkSize);

		if(!otherMech)
			continue;

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

		if(mechTarget) {
			if(otherMech == mechTarget)
				continue;

			debugC3(tprintf
					("C3RANGE-NETWORK (mech): Finding range from %d to %d.",
					 mech->mynum, mechTarget->mynum));

			c3Range = FaMechRange(otherMech, mechTarget);
			inLOS =
				InLineOfSight(otherMech, mechTarget, MechX(mechTarget),
							  MechY(mechTarget), c3Range);
		} else if((MechTargX(mech) > 0) && (MechTargY(mech) > 0)) {
			mapX = MechTargX(mech);
			mapY = MechTargY(mech);
			map = getMap(mech->mapindex);

			debugC3(tprintf
					("C3RANGE-NETWORK (hex): Finding range from %d to %d %d.",
					 mech->mynum, mapX, mapY));

			MechTargZ(mech) = Elevation(map, mapX, mapY);
			hexZ = ZSCALE * MechTargZ(mech);
			MapCoordToRealCoord(mapX, mapY, &hexX, &hexY);

			c3Range =
				FindRange(MechFX(otherMech), MechFY(otherMech),
						  MechFZ(otherMech), hexX, hexY, hexZ);
			inLOS = LOS_NB(otherMech, NULL, mapX, mapY, c3Range);
		} else {
			continue;
		}

		if(inLOS && (c3Range < bestRange)) {
			bestRange = c3Range;
			*c3Ref = otherMech->mynum;
		}
	}

	return bestRange;
}