1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

[UT2004] Deep Bug Search: Bot ammo empties without use...

Discussion in 'Programming' started by Call me Erdrik, Jun 7, 2005.

  1. Call me Erdrik

    Call me Erdrik Arch Mage

    Joined:
    Nov 24, 1999
    Messages:
    334
    Likes Received:
    0
    Ok. I've been working on new DarkMagic Code, and have most of the core
    completed. The biggest problem Im having is with the bots and their ammo. ( Mana )
    All weapons in Dark Magic a dynamicly growing spells that are given to the
    player as he/she gains exp, thru kills and use. And all these spells use the
    same ammo type: Mana. The main Spell class which all other spells are
    subclassed uses a tick function to regen the mana dependent on the Level of
    the player. Everything works fine for a normal Player, but the mana is being
    drained with bots, as if they were constantly firing the spell over and over
    again. But the spell is not cast, and I put logs into the casting function which
    did NOT show up in the log file which means that the mana is being drained
    else where. After many hours of searching I came up with nuthin'.

    SO I turn to the community for help. Here is the code for casting spells:
    Code:
    //=================================================
    // DMUTSpells: Main Class of all spells subclass of Weapon
    //=================================================
    Function Bool RateOfFiring()
    {
    	If ( Level.TimeSeconds > (LastFireTime + (RateOfFire+1 * 1.5)) )
    	{
    		Return True;
    	} Else Return False;
    }
    
    function bool BotFire(bool bFinished, optional name FiringMode)
    {
    	local vector Start;
    	local rotator Dir;
    	local int newmode;
    	local Controller C;
    	local bool bAttack;
    
    	B = Bot(Instigator.Controller);
    	log(B.PlayerReplicationInfo.PlayerName$" Tried to Fire at:  "$B.Enemy.Controller.PlayerReplicationInfo.PlayerName$" /R="$SeekRange$"    Mana="$Ammo[1].AmmoAmount$"/C="$ManaCost);
    
    	bAttack = False;
    	C = Instigator.Controller;
    	//newMode = BestMode();
    		C.bFire = 1;
    		C.bAltFire = 0;
    /*	}
    	else
    	{
    		C.bFire = 0;
    		C.bAltFire = 1;
    	}*/
    
    	// decide if bot should be locked on
    	if ( B != None && B.Enemy != None )
    	{
    		if (	
    			(B.Target == B.Enemy) 
    			&& (VSize(B.Enemy.Location - B.Pawn.Location) < (SeekRange )) 
    			&& (Level.TimeSeconds - B.LastSeenTime < 0.4) 
    			&& (Level.TimeSeconds - B.AcquireTime > LockRequiredTime) 
    			&& CanAttack( B.Enemy )
    		   )
    		{
    			bAttack = True;
    			bLockedOn = true;
    			SeekTarget = B.Enemy;
    		} Else
    			{
    				StopFire(1);
    			}
    	}//log(instigator.controller$"	bLockedOn?	"$bLockedOn$"	SeekTarget?	"$SeekTarget);
    
    	if ( bFinished )
    		return true;
    
    	if ( FireMode[1].IsFiring() || ArC != None )
    	{
    		if (BotMode == 1)
    			return true;
    		else
    			StopFire(1);
    	}
    
    	if ( !ReadyToFire(1) || ClientState != WS_ReadyToFire || !DMUTPRI(instigator.PlayerReplicationinfo).bCanCast )
    		return false;
    
    	BotMode = NewMode;
    	bBreakLock = true;
     	// FIXME: Temp for testing until Bot mana problems fixed
    	if ( ArC == None /*&& Ammo[1].AmmoAmount > Manacost*/ && RateOfFiring() && bAttack )
    	{
    		getaxes(rotation, X, Y, Z);
    		Start = Instigator.location + 32 *X;
    		Dir = instigator.controller.Rotation;
    		StartCasting(Start, Dir);
    		bRoFReady = False;
    	}
    	return True;
    }
    
    //=================
    // Arcanus Casting does all the casting and effects
    //=================
    function StartCasting(Vector Start, Rotator Dir)
    {
    
    	local Int SL, MC;
    	local float DangBdist;
    
    	ExpCurve = (CurrentExperience / NextlevelGain) * SpellLevel;
    
    	// Check if spell should be cast at a lower level, ie not enough mana.
    	SL = GetSpellLevel();
    	MC = GetManacost();
    
    	        if ( B != None )
    	        {
    			DangBdist = VSize(B.Enemy.Location - B.Pawn.Location);
    			log(B.PlayerReplicationInfo.PlayerName$" Is Casting at:  "$B.Enemy.Controller.PlayerReplicationInfo.PlayerName$" / D="$DangBdist$" /R="$SeekRange$"    Mana="$Ammo[1].AmmoAmount$"/C="$MC);
    		}
    
    	//If ( B == None )
    	//{
    	//	log(Self.ItemName$": SL: "$SL$": Mana :"$Ammo[1].AmmoAmount$": NewCost :"$MC);
    	//	log("...");
    	//}
    	if ( bLockRequired && Ammo[1].AmmoAmount > MC )
    	{
    	    if (bLockedOn && SeekTarget != None)
    	    {
    		//Spawn a "Arcanus Casting" to add the casting SFXs the
    		//"Arcanus Casting" will cast the actual spell so all 
    		//variables need to be stored in the "Arcanus Casting".
    	        ArC = Spawn(class'DMUTArcanusCasting',,, Start, Dir);
    	        ArC.SeekTarget = SeekTarget;
    	        ArC.SpellLevel = SL;
    		ArC.EffectClass1 = DMUTPRI(Instigator.PlayerReplicationInfo).SpellCircle.Default.CastClass;
    		ArC.EffectClass2 = DMUTPRI(Instigator.PlayerReplicationInfo).SpellCircle.Default.CastClass.Default.CastClass;
    		ArC.ExpCurve = ExpCurve;
    		ArC.Manacost = MC;
    		ArC.FireModeSet = FireMode[1];
    		ArC.Start = Start;
    		ArC.Spell = Self;
    		ArC.SetBase(Instigator);
    		ArC.SetMOdes();
    	        if ( B != None )
    	        {
    			//log("LOCKED");
    			bLockedOn = false;
    			SeekTarget = None;
    		}
    	    }
    	}
    	else if ( !bLockRequired && Ammo[1].AmmoAmount > MC )
    	{
    		//If a Lock on is not required of the spell.
            	ArC = Spawn(class'DMUTArcanusCasting',,, Start, Dir);
            	ArC.SpellLevel = SL;
    		ArC.EffectClass1 = DMUTPRI(Instigator.PlayerReplicationInfo).SpellCircle.Default.CastClass;
    		ArC.EffectClass2 = DMUTPRI(Instigator.PlayerReplicationInfo).SpellCircle.Default.CastClass.Default.CastClass;
    		ArC.ExpCurve = ExpCurve;
    		ArC.Manacost = MC;
    		ArC.FireModeSet = FireMode[1];
    		ArC.Start = Start;
    		ArC.Dir = Dir;
    		ArC.Spell = Self;
    		ArC.SetBase(Instigator);
    		ArC.SetMOdes();
    	}
    }
    
    function Tick(float dt)
    {
    	local Pawn Other;
    	local Vector StartTrace;
    	local Rotator Aim;
    	local float BestDist, BestAim;
    	local DMUTPRI DMPRIMana;
    
    	AIRating = (SpellLevel * 0.05) + (Priority * 0.05);
    	bGoodEnch = True;
    
        if (Instigator == None || Instigator.Weapon != self)
            return;
    
    	if ( Role < ROLE_Authority )
    		return;
    	//---------------------------------------------------
    	//Mana Regeneration
    	// ...
    	//---------------------------------------------------
        	if (Level.TimeSeconds > 0 )
        	{
    		//mana regeneration FIXME: maybe slower regen?? -cme FIXED
    		ammoChargetime++;
    		DMPRIMana = DMUTPRI(instigator.PlayerReplicationinfo);
    		if ( Ammo[1].AmmoAmount < 100 && DMPRIMana != None)
    		{
    			if (ammoChargetime > 25 - ( DMPRIMana.pLevel * 2 ) )
    			{
    				ammoChargetime = 0;
    				if (Ammo[1] != None)
    					Ammo[1].AddAmmo(1);
    				else if (Ammo[0] != None && Ammo[1] == None)
    					Ammo[0].AddAmmo(1);
    			}
    		} Else if ( DMPRIMana!= None )
    		{
    			if (ammoChargetime > 45 - ( DMPRIMana.pLevel * 2 ) )
    			{
    				ammoChargetime = 0;
    				if (Ammo[1] != None)
    					Ammo[1].AddAmmo(1);
    				else if (Ammo[0] != None && Ammo[1] == None)
    					Ammo[0].AddAmmo(1);
    			}
    		}
    		B = Bot(Instigator.Controller); // FIXME: Temp for testing until Bot mana problems fixed
    		If ( B != None )
    			ammoChargetime+=10;
    	}
    
    	// bots can't target??!? investigat... Bots match target in StartCasting Fixed -cme
        if ( !Instigator.IsHumanControlled() )
            return;
    
        if (Level.TimeSeconds > 0)
        {
            if (bBreakLock)
            {
                bBreakLock = false;
                bLockedOn = false;
                SeekTarget = None;
            }
    
            StartTrace = Instigator.Location + Instigator.EyePosition();
            Aim = Instigator.GetViewRotation();
    
    	// the closer LockAim is to 1 more accuracy is required.
            BestAim = LockAim;
            Other = Instigator.Controller.PickTarget(BestAim, BestDist, Vector(Aim), StartTrace, SeekRange );
    
            if ( CanLockOnTo(Other) )
            {
                if (Other == SeekTarget)
                {
                    LockTime += SeekCheckFreq;
                    if (!bLockedOn && LockTime >= LockRequiredTime)
                    {
    			bLockedOn = true;
    			// add a lockon sound 
    			// perferably a setable Default Property
    		}
                }
                else
                {
                    SeekTarget = Other;
                    LockTime = 0.0;
                }
                UnLockTime = 0.0;
            }
            else
            {
                if (SeekTarget != None)
                {
                    UnLockTime += SeekCheckFreq;
                    if (UnLockTime >= UnLockRequiredTime)
                    {
                        SeekTarget = None;
                        if (bLockedOn)
                        {
                            bLockedOn = false;
                        }
                    }
                }
                else
                     bLockedOn = false;
             }
    
            SeekCheckTime = Level.TimeSeconds + SeekCheckFreq;
    
        }
    	If ( ArC == None )
    	{
    		If ( RateOfFiring() )
    		{
    			bRoFReady = True;
    		}
    	}
    }
    
    In the BotFire function I have logged the casting bot. StartCasting is ONLY
    called in BotFire for bots. I spectated a match and the bot had no target
    and no spell was cast, but the mana periodicly drained as if he was casting.
    Does anyone know where else this drain in ammo could be occuring?

    Thnx in advance for any help provided. :)
     

Share This Page