void CHSWormHole::GateShip(CHSShip *cShip)
{
	if (!cShip)
		return;

	BOOL succeed;

	if (getrandom(100) <= m_stability)
		succeed = TRUE;
	else
		succeed = FALSE;
	
	cShip->NotifyConsoles("The ship enters the wormhole and an infinite amount of colors can be seen.", MSG_SENSOR);
	cShip->NotifySrooms("The ship shakes slightly as it enters a wormhole.");

	CHSUniverse *uDest;
	uDest = uaUniverses.FindUniverse(cShip->GetUID());
	if (uDest) {
			uDest->SendContactMessage("In the distance a ship gates a wormhole.", 
			DETECTED, cShip);
			uDest->SendContactMessage(
				tprintf("In the distance the %s gates a wormhole.",cShip->GetName()), IDENTIFIED, cShip);
	} 


	if (succeed)
	{
		if (m_destx)
			cShip->SetX(m_destx);
		if (m_desty)
			cShip->SetY(m_desty);
		if (m_destz)
			cShip->SetZ(m_destz);
		
		CHSUniverse *uSource;

		uDest = uaUniverses.FindUniverse(m_destuid);
		if (uDest)
		{
			// Grab the source universe
			uSource = uaUniverses.FindUniverse(cShip->GetUID());

			// Now pull it from one, and put it in another
			uSource->RemoveObject(cShip);
			cShip->SetUID(m_destuid);
			uDest->AddObject(cShip);
		}

		cShip->NotifyConsoles("The ship safely emerges on the other side of the wormhole.", MSG_SENSOR);
	} else {
		cShip->NotifyConsoles("The wormhole collapses and the structural integrity is comprimised.", MSG_SENSOR);
		cShip->ExplodeMe();
		if (!hsInterface.HasFlag(cShip->GetDbref(), TYPE_THING, THING_HSPACE_SIM))
				cShip->KillShipCrew("The ship explodes as the structural integrity fails!");
	}
}
Exemple #2
0
void CHSMTube::AttackObject(CHS3DObject * cSource,
                            CHS3DObject * cTarget,
                            CHSConsole * cConsole,
                            HS_INT32 iSysType, HS_INT32 hit_flag)
{
    HS_DBREF dbUser;

    // Grab the user of the console.
    dbUser = hsInterface.ConsoleUser(cConsole->m_objnum);

    if (cSource->GetType() == HST_SHIP)
    {
        CHSSysCloak *cCloak;
        CHSShip *ptr;

        ptr = (CHSShip *) cSource;

        // Look for the cloaking device.
        cCloak = (CHSSysCloak *) ptr->GetEngSystem(HSS_CLOAK);
        if (cCloak)
            if (cCloak->GetEngaged())
            {
                if (dbUser != HSNOTHING)
                    hsStdError(dbUser, "You cannot fire while cloaked.");
                return;
            }
    }

    // Can we attack that object?
    if (!CanAttackObject(cTarget))
    {
        if (dbUser != HSNOTHING)
            hsStdError(dbUser,
                       "You cannot attack that target with that weapon.");
    }

    // Create a missile object, and put it in space
    CHSMissile *cMiss;
    cMiss = new CHSMissile;
    cMiss->SetUID(cSource->GetUID());

    if (hit_flag == 0)
    {
        cMiss->SetAutoMiss();
    }

    // Add it to the universe
    CHSUniverse *uDest;
    uDest = cMiss->GetUniverse();
    if (!uDest)
    {
        if (dbUser != HSNOTHING)
        {
            hsInterface.Notify(dbUser,
                               "Error finding a universe to put the missile in.");
        }
        delete cMiss;
        return;
    }
    uDest->AddObject(cMiss);

    // Set missile coords
    cMiss->SetX(cSource->GetX());
    cMiss->SetY(cSource->GetY());
    cMiss->SetZ(cSource->GetZ());

    // Set missile heading
    cMiss->SetHeading(cConsole->GetXYHeading(), cConsole->GetZHeading());

    // Set missile type
    cMiss->SetWeaponData(this);

    // Set source info
    cMiss->SetSourceConsole(cConsole);
    cMiss->SetSourceObject(cSource);
    cMiss->SetTargetObject(cTarget);


#ifdef PENNMUSH
    HS_DBREF obj_num = hsInterface.CreateNewGameObject();
#else
    HS_DBREF obj_num = hsInterface.CreateNewGameObject(TYPE_THING);
#endif

    if (hsInterface.ValidObject(obj_num))
    {
        cMiss->SetDbref(obj_num);

        // Try to set the name of the missile properly but default
        // just in case
        if (NULL == m_pWeaponData)
        {
            hsInterface.SetObjectName(obj_num, "Missile");
        }
        else
        {
            hsInterface.SetObjectName(obj_num,
                                      static_cast < CHSMissileData * >(m_pWeaponData)->Name());
        }

        hsInterface.MoveObject(obj_num, uDest->GetID());
        hsInterface.SetToggle(obj_num, THING_HSPACE_OBJECT);
        hsInterface.SetObjectOwner(obj_num, hsInterface.GetGodDbref());

        // Missile objects are temporary, clear them if the game
        // is restarted while the missile is still in existance
        hsInterface.AtrAdd(obj_num, "STARTUP", "@destroy me",
                           hsInterface.GetGodDbref());
    }
    else
    {
        // Set missile HS_DBREF to some very high number that's
        // probably not duplicated.
        cMiss->SetDbref(hsInterface.GetRandom(10000) + 28534);
        hs_log("CHSMTube::AttackObject() -- Deprecated fake dbref method \
                utilized.");
    }

    if (dbUser != HSNOTHING)
    {
        hsStdError(dbUser, "Missile launched.");
    }

    m_loaded = false;
}