コード例 #1
0
        private void GrowTowardsTarget()
        {
            bool succeeded = false;

            List <BallastFloraBranch> newList = new List <BallastFloraBranch>(TargetBranches);

            foreach (BallastFloraBranch branch in newList)
            {
                if (branch.FailedGrowthAttempts > 8 || !branch.CanGrowMore())
                {
                    continue;
                }

                // Get what side gets us closest to the target
                TileSide side = GetClosestSide(branch, Target.WorldPosition);

                if (branch.IsSideBlocked(side))
                {
                    continue;
                }

                succeeded |= Behavior.TryGrowBranch(branch, side, out List <BallastFloraBranch> newBranches);
                TargetBranches.AddRange(newBranches);

                foreach (BallastFloraBranch newBranch in newBranches)
                {
                    Rectangle worldRect = newBranch.Rect;
                    worldRect.Location = Behavior.GetWorldPosition().ToPoint() + worldRect.Location;
                    if (Behavior.BranchContainsTarget(newBranch, Target))
                    {
                        Behavior.ClaimTarget(Target, newBranch);
                        isFinished = true;
                        return;
                    }
                }
            }

            if (!succeeded)
            {
                if (!Behavior.IgnoredTargets.ContainsKey(Target))
                {
                    Behavior.IgnoredTargets.Add(Target, 1);
                }

                isFinished = true;
            }
        }