예제 #1
0
int plAvBrainCritter::IPickBehavior(const std::string& behavior) const
{
    // make sure the behavior exists
    std::map<std::string, std::vector<int> >::const_iterator behaviorIterator = fUserBehaviors.find(behavior);
    if (behaviorIterator == fUserBehaviors.end())
    {
        if (behavior != kDefaultIdleBehName)
            return IPickBehavior(kDefaultIdleBehName); // do an idle if the behavior is invalid
        return -1; // can't recover from being unable to find an idle!
    }
    else
    {
        unsigned numBehaviors = behaviorIterator->second.size();
        if (numBehaviors == 0)
        {
            if (behavior != kDefaultIdleBehName)
                return IPickBehavior(kDefaultIdleBehName); // do an idle if the behavior is invalid
            return -1; // can't recover from being unable to find an idle!
        }

        // pick our behavior
        unsigned index = sRandom.RandRangeI(0, numBehaviors - 1);
        return behaviorIterator->second[index];
    }
}
예제 #2
0
void plAvBrainCritter::IStartBehavior()
{
    if ((fNextMode >= fBehaviors.Count()) || (fNextMode < 0))
        return; // invalid fNextMode

    // fade in our behavior
    CritterBehavior* behavior = (CritterBehavior*)fBehaviors[fNextMode];
    behavior->SetStrength(1.f, fFadingNextBehavior ? behavior->FadeInLength() : 0.f);

    // if we start at a random point, do so
    if (behavior->RandomStartPoint())
    {
        float newStart = sRandom.RandZeroToOne() * behavior->GetAnimLength();
        behavior->SetAnimTime(newStart);
    }

    // clean up the internal variables
    fCurMode = fNextMode;
    fNextMode = -1;
}
hsBool plDynaRippleVSMgr::IRippleFromShape(const plPrintShape* shape, hsBool force)
{
    if( !ICheckRTMat() )
        return false;

    if( !shape )
        return false;

    hsBool retVal = false;

    plDynaDecalInfo& info = IGetDecalInfo(uintptr_t(shape), shape->GetKey());

    const hsMatrix44& shapeL2W = shape->GetOwner()->GetLocalToWorld();

    plConst(float) kMinDist(2.0f);
    plConst(float) kMinTime(1.5f);
    double t = hsTimer::GetSysSeconds();
    float dt = float(t - info.fLastTime) * sRand.RandZeroToOne();
    hsBool longEnough = (dt >= kMinTime);
    hsPoint3 xlate = shapeL2W.GetTranslate();
    hsBool farEnough = (hsVector3(&info.fLastPos, &xlate).Magnitude() > kMinDist);
    if( force || longEnough || farEnough )
    {
        hsPoint3 pos = shapeL2W.GetTranslate();

        // We'll perturb the position a little so it doesn't look quite so regular,
        // but we perturb it more if we're just standing still
        hsVector3 randPert(sRand.RandMinusOneToOne(), sRand.RandMinusOneToOne(), 0);
        randPert.Normalize();
        if( !farEnough )
        {
            plConst(float) kRandPert = 0.5f;
            randPert *= kRandPert;
        }
        else
        {
            plConst(float) kRandPert = 0.15f;
            randPert *= kRandPert;
        }
        pos += randPert;

        // Are we potentially touching the water?
        float waterHeight = fWaveSetBase->GetHeight();
        if( (pos.fZ - fScale.fZ * shape->GetHeight() < waterHeight)
            &&(pos.fZ + fScale.fZ * shape->GetHeight() > waterHeight) )
        {

            hsVector3 dir(fWaveSetBase->GetWindDir());
            hsVector3 up(0.f, 0.f, 1.f);

            float wid = hsMaximum(shape->GetWidth(), shape->GetLength());
            
            plConst(float) kMaxWaterDepth(1000.f);

            hsVector3 size(wid * fScale.fX, wid * fScale.fY, kMaxWaterDepth);
            fCutter->SetLength(size);
            fCutter->Set(pos, dir, up);


            hsBool hit = ICutoutTargets(t);
            if( hit )
            {
                info.fLastTime = t;
                info.fLastPos = shapeL2W.GetTranslate();
                retVal = true;
            }
            else
            {
                retVal = false; // No-effect else just for break points.
            }
        }
    }
    return retVal;
}
hsBool plDynaTorpedoMgr::IHandleShot(plBulletMsg* bull)
{
    float partyTime = fPartyTime;

    plConst(int) kNumShots(3);
    int i;
    for( i = 0; i < kNumShots; i++ )
    {
        hsVector3 up = IRandomUp(bull->Dir());
        hsVector3 pert = bull->Dir() % up;

        plConst(float) kMaxPert(1.f);
        float maxPert = i ? kMaxPert * bull->Radius() : 0;
        pert *= sRand.RandMinusOneToOne() * maxPert * fScale.fX;

        pert += up * (sRand.RandMinusOneToOne() * maxPert * fScale.fY);

        hsPoint3 pos = bull->From() + bull->Dir() * (bull->Range() * 0.5f);
        pos += pert;

        float scaleX = bull->Radius() * fScale.fX * fInitUVW.fX;
        float scaleY = bull->Radius() * fScale.fY * fInitUVW.fY;

#if 0
        plConst(float) kMinScale(0.5f);
        if( i )
        {
            scaleX *= sRand.RandRangeF(kMinScale, 1.f);
            scaleY *= sRand.RandRangeF(kMinScale, 1.f);
        }
#elif 0
        float div = 1.f / (1.f + float(i));
        scaleX *= div;
        scaleY *= div;
#else
        plConst(float) kMinScale(0.25f);
        plConst(float) kMaxScale(0.75f);
        if( i ) 
        {
            float scale = sRand.RandRangeF(kMinScale, kMaxScale);
            scaleX *= scale;
            scaleY *= scale;
        }
#endif

        fCutter->SetLength(hsVector3(scaleX, scaleY, bull->Range()));
        fCutter->Set(pos, up, -bull->Dir());

        plDynaDecalInfo& info = IGetDecalInfo(uintptr_t(this), GetKey());

        if( bull->PartyTime() > 0 )
            fPartyTime = bull->PartyTime();

        double secs = hsTimer::GetSysSeconds();

        if( ICutoutTargets(secs) )
            info.fLastTime = secs;

        fPartyTime = 0;
    
    }
    fPartyTime = partyTime;

    return true;
}