コード例 #1
0
ファイル: mech.c3i.c プロジェクト: fstltna/Battletech-MUX
void mech_c3i_join_leave(dbref player, void *data, char *buffer)
{
    MECH *mech = (MECH *) data, *target;
    MAP *objMap;
    char *args[2];
    dbref refTarget;
    int LOS = 1;
    float range = 0.0;

    cch(MECH_USUALO);

    DOCHECK(mech_parseattributes(buffer, args, 2) != 1,
	"Invalid number of arguments to function!");

    DOCHECK(!HasC3i(mech), "This unit is not equipped with C3i!");
    DOCHECK(C3iDestroyed(mech), "Your C3i system is destroyed!");
    DOCHECK(AnyECMDisturbed(mech),
	"Your C3i system is not currently operational!");

    validateC3iNetwork(mech);

    /* Clear our C3i Network */
    if (!strcmp(args[0], "-")) {
	if (MechC3iNetworkSize(mech) <= 0) {
	    mech_notify(mech, MECHALL,
		"You are not connected to a C3i network!");

	    return;
	}

	clearC3iNetwork(mech, 1);

	mech_notify(mech, MECHALL, "You disconnect from the C3i network.");

	return;
    }

    /* Well, if we're here then we wanna connect to a network */
    /* Let's check to see if we're already in one... can't be in two at the same time */
    DOCHECK(MechC3iNetworkSize(mech) > 0,
	"You are already in a C3i network!");

    objMap = getMap(mech->mapindex);

    /* Find who we're trying to connect to */
    refTarget = FindTargetDBREFFromMapNumber(mech, args[0]);
    target = getMech(refTarget);

    if (target) {
	LOS =
	    InLineOfSight(mech, target, MechX(target), MechY(target),
	    range);
    } else
	refTarget = 0;

    DOCHECK((refTarget < 1) ||
	!LOS, "That is not a valid targetID. Try again.");
    DOCHECK(MechTeam(mech) != MechTeam(target),
	"You can't use the C3i network of unfriendly units!");
    DOCHECK(mech == target, "You can't connect to yourself!");
    DOCHECK(Destroyed(target), "That unit is destroyed!");
    DOCHECK(!Started(target), "That unit is not started!");
    DOCHECK(!HasC3i(target),
	"That unit does not appear to be equipped with C3i!");

    /* validate the network of our target */
    validateC3iNetwork(target);
    DOCHECK(MechC3iNetworkSize(target) >= C3I_NETWORK_SIZE,
	"That unit's C3i network is operating at maximum capacity!");

    /* Connect us up */
    mech_notify(mech, MECHALL, tprintf("You connect to %s's C3i network.",
	    GetMechToMechID(mech, target)));

    addMechToC3iNetwork(target, mech);
}
コード例 #2
0
ファイル: mech.ecm.c プロジェクト: chazu/btmux
void checkECM(MECH * objMech)
{
	MAP *objMapmap;
	MECH *objOtherMech;
	float range = 0.0;

	int wFriendlyECM = 0;
	int wFriendlyECCM = 0;
	int wUnFriendlyECM = 0;
	int wUnFriendlyECCM = 0;

	int wFriendlyAngelECM = 0;
	int wFriendlyAngelECCM = 0;
	int wUnFriendlyAngelECM = 0;
	int wUnFriendlyAngelECCM = 0;

	int wFriendlyECMDelta = 0;
	int wFriendlyECCMDelta = 0;

	int tCheckECM = 0;
	int tCheckECCM = 0;

	int wIter = 0;
	int tMark = 0;

	if(!(objMapmap = FindObjectsData(objMech->mapindex)))	/* get our map */
		return;

	for(wIter = 0; wIter < objMapmap->first_free; wIter++) {
		if(!(objOtherMech = FindObjectsData(objMapmap->mechsOnMap[wIter])))
			continue;

		if((range = FaMechRange(objOtherMech, objMech)) > ECM_RANGE)
			continue;

		if(MechTeam(objOtherMech) == MechTeam(objMech)) {
			if(ECMEnabled(objOtherMech))
				wFriendlyECM++;

			if(ECCMEnabled(objOtherMech))
				wFriendlyECCM++;

			if(AngelECMEnabled(objOtherMech))
				wFriendlyAngelECM++;

			if(AngelECCMEnabled(objOtherMech))
				wFriendlyAngelECCM++;

			if(range <= 0.5) {
				if(PerECMEnabled(objOtherMech))
					wFriendlyECM++;

				if(PerECCMEnabled(objOtherMech))
					wFriendlyECCM++;
			}
		} else {
			if(ECMEnabled(objOtherMech))
				wUnFriendlyECM++;

			if(ECCMEnabled(objOtherMech))
				wUnFriendlyECCM++;

			if(AngelECMEnabled(objOtherMech))
				wUnFriendlyAngelECM++;

			if(AngelECCMEnabled(objOtherMech))
				wUnFriendlyAngelECCM++;

			if(range <= 0.5) {
				if(PerECMEnabled(objOtherMech))
					wUnFriendlyECM++;

				if(PerECCMEnabled(objOtherMech))
					wUnFriendlyECCM++;
			}
		}
	}

	if((MechStatus2(objMech) & STH_ARMOR_ON) ||
	   checkAllSections(objMech, INARC_ECM_ATTACHED))
		wUnFriendlyECM += 1000;

	/* Generate our deltas */
	wFriendlyECMDelta =
		wFriendlyECM + (2 * wFriendlyAngelECM) - wUnFriendlyECCM -
		(2 * wUnFriendlyAngelECCM);
	wFriendlyECCMDelta =
		wFriendlyECCM + (2 * wFriendlyAngelECCM) - wUnFriendlyECM -
		(2 * wUnFriendlyAngelECM);

	tCheckECM = ((wFriendlyECM != 0) || (wFriendlyAngelECM != 0) ||
				 (wUnFriendlyECCM != 0) || (wUnFriendlyAngelECCM != 0));
	tCheckECCM = ((wFriendlyECCM != 0) || (wFriendlyAngelECCM != 0) ||
				  (wUnFriendlyECM != 0) || (wUnFriendlyAngelECM != 0));

	/* SendDebug(tprintf("Checking unit %d. ECMDelta: %d. ECCMDelta: %d. CheckECM: %d. CheckECCM: %d",objMech->mynum,wFriendlyECMDelta,wFriendlyECCMDelta,tCheckECM,tCheckECCM)); */

	/* Now we do our checks... */
	/* Let's first see if we should just reset our flags... 'cause there's no ECM or ECCM around */
	if(!tCheckECM) {
		if(ECMCountered(objMech)) {
			sendECMNotification(objMech, ECM_NOTIFY_UNCOUNTERED);
			UnSetECMCountered(objMech);
			tMark = 1;
		}

		if(ECMProtected(objMech) || AngelECMProtected(objMech)) {
			UnSetECMProtected(objMech);
			UnSetAngelECMProtected(objMech);
			tMark = 1;
		}
	}

	if(!tCheckECCM) {
		if(AnyECMDisturbed(objMech)) {
			sendECMNotification(objMech, ECM_NOTIFY_UNDISTURBED);
			UnSetECMDisturbed(objMech);
			UnSetAngelECMDisturbed(objMech);
			tMark = 1;
		}
	}

	/* Sanity check so we don't bother to do all the other checks */
	if(!tCheckECM && !tCheckECCM) {
		if(tMark)
			MarkForLOSUpdate(objMech);

		return;
	}

	/* Now we see if our ECM has been countered */
	if(tCheckECM) {
		if(wFriendlyECMDelta <= 0) {	/* They have the same or more ECCM than we have ECM */
			if(!ECMCountered(objMech)) {
				sendECMNotification(objMech, ECM_NOTIFY_COUNTERED);
				SetECMCountered(objMech);
				UnSetECMProtected(objMech);
				UnSetAngelECMProtected(objMech);
			}
		} else {
			if(ECMCountered(objMech)) {
				sendECMNotification(objMech, ECM_NOTIFY_UNCOUNTERED);
				UnSetECMCountered(objMech);
			}

			if(wFriendlyECM > 0)
				SetECMProtected(objMech);
			else
				UnSetECMProtected(objMech);

			if(wFriendlyAngelECM > 0)
				SetAngelECMProtected(objMech);
			else
				UnSetAngelECMProtected(objMech);
		}
	}

	/* Now we see if we're under an enemy ECM umbrella */
	if(tCheckECCM) {
		if(wFriendlyECCMDelta < 0) {	/* They have more ECM than we have ECCM */
			if(!AnyECMDisturbed(objMech)) {
				sendECMNotification(objMech, ECM_NOTIFY_DISTURBED);

				if(wUnFriendlyECM > 0)
					SetECMDisturbed(objMech);
				else
					UnSetECMDisturbed(objMech);

				if(wUnFriendlyAngelECM > 0)
					SetAngelECMDisturbed(objMech);
				else
					UnSetAngelECMDisturbed(objMech);

				MarkForLOSUpdate(objMech);
			}
		} else {
			if(AnyECMDisturbed(objMech)) {
				sendECMNotification(objMech, ECM_NOTIFY_UNDISTURBED);

				UnSetECMDisturbed(objMech);
				UnSetAngelECMDisturbed(objMech);
				MarkForLOSUpdate(objMech);
			}
		}
	}
}
コード例 #3
0
ファイル: mech.c3.misc.c プロジェクト: chazu/btmux
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;
}