protected Element[] RenderModel(Model model, Element visibleTo, Element location, Element scale, IWorkshopTree reevaluation, IndexedVar store, Element rotation)
        {
            List <Element> actions   = new List <Element>();
            int            waitEvery = rotation.ConstantSupported <Vertex>() ? 25 : 10;

            for (int i = 0; i < model.Lines.Length; i++)
            {
                actions.Add(CreateLine(model.Lines[i], visibleTo, location, scale, reevaluation, rotation));

                // Get the last created effect and append it to the store array.
                if (store != null)
                {
                    actions.AddRange(
                        store.SetVariable(Element.Part <V_Append>(store.GetVariable(), new V_LastCreatedEntity()))
                        );
                }

                // Add a wait every 12 effects to prevent high server load.
                if (i % waitEvery == 0)
                {
                    actions.Add(A_Wait.MinimumWait);
                }
            }
            return(actions.ToArray());
        }
Esempio n. 2
0
        protected override MethodResult Get()
        {
            IndexedVar player = TranslateContext.VarCollection.AssignVar(Scope, "OptimisedSphereHitbox: player", TranslateContext.IsGlobal, null);
            IndexedVar position = TranslateContext.VarCollection.AssignVar(Scope, "OptimisedSphereHitbox: position", TranslateContext.IsGlobal, null);

            Element[] actions = ArrayBuilder<Element>.Build
            (
                player.SetVariable((Element)Parameters[0]),
                position.SetVariable((Element)Parameters[1])
            );

            Element radius = (Element)Parameters[2];
            Element eyePos = Element.Part<V_EyePosition>(player.GetVariable());
            Element range = Element.Part<V_DistanceBetween>(eyePos, position.GetVariable());
            Element direction = Element.Part<V_FacingDirectionOf>(player.GetVariable());
            Element raycast = Element.Part<V_RayCastHitPosition>(eyePos,
                Element.Part<V_Add>(
                    eyePos,
                    Element.Part<V_Multiply>(direction, range)
                    ),
                    new V_AllPlayers(),
                    new V_Null(),
                    new V_False()
                );
            Element distance = Element.Part<V_DistanceBetween>(position.GetVariable(), raycast);
            Element compare = Element.Part<V_Compare>(distance, EnumData.GetEnumValue(Operators.LessThanOrEqual), radius);

            return new MethodResult(actions, compare);
        }
Esempio n. 3
0
        protected override MethodResult Get()
        {
            IndexedVar player   = IndexedVar.AssignInternalVar(TranslateContext.VarCollection, Scope, "OptimisedSphereHitbox: player", TranslateContext.IsGlobal);
            IndexedVar position = IndexedVar.AssignInternalVar(TranslateContext.VarCollection, Scope, "OptimisedSphereHitbox: position", TranslateContext.IsGlobal);

            Element[] actions = ArrayBuilder <Element> .Build
                                (
                player.SetVariable((Element)Parameters[0]),
                position.SetVariable((Element)Parameters[1])
                                );

            Element radius    = (Element)Parameters[2];
            Element eyePos    = Element.Part <V_EyePosition>(player.GetVariable());
            Element range     = Element.Part <V_DistanceBetween>(eyePos, position.GetVariable());
            Element direction = Element.Part <V_FacingDirectionOf>(player.GetVariable());
            Element raycast   = Element.Part <V_RayCastHitPosition>(eyePos,
                                                                    (
                                                                        eyePos +
                                                                        direction * range
                                                                    ),
                                                                    new V_AllPlayers(),
                                                                    new V_Null(),
                                                                    new V_False()
                                                                    );
            Element distance = Element.Part <V_DistanceBetween>(position.GetVariable(), raycast);
            Element compare  = distance <= radius;

            return(new MethodResult(actions, compare));
        }
        override protected MethodResult Get()
        {
            string     text      = (string)((ConstantObject)Parameters[0]).Value;
            Element    visibleTo = (Element)Parameters[1];
            Element    location  = (Element)Parameters[2];
            Element    rotation  = (Element)Parameters[3];
            Element    scale     = (Element)Parameters[4];
            EnumMember effectRev = (EnumMember)Parameters[5];
            bool       getIds    = (bool)((ConstantObject)Parameters[6]).Value;

            Model model = new Model(Letter.Create(text, false, ParameterLocations[0]));

            List <Element> actions = new List <Element>();

            IndexedVar effects = null;

            if (getIds)
            {
                effects = TranslateContext.VarCollection.AssignVar(Scope, "Model Effects", TranslateContext.IsGlobal, null);
                actions.AddRange(effects.SetVariable(new V_EmptyArray()));
            }

            actions.AddRange(RenderModel(model, visibleTo, location, scale, effectRev, effects, rotation));

            return(new MethodResult(actions.ToArray(), effects?.GetVariable()));
        }
Esempio n. 5
0
        override protected MethodResult Get()
        {
            if (((VarRef)Parameters[0]).Var is ModelVar == false)
            {
                throw SyntaxErrorException.InvalidVarRefType(((VarRef)Parameters[0]).Var.Name, VarType.Model, ParameterLocations[0]);
            }

            //throw new SyntaxErrorException("Variable must reference a model.", ParameterLocations[0]);

            ModelVar   modelVar  = (ModelVar)((VarRef)Parameters[0]).Var;
            Element    visibleTo = (Element)Parameters[1];
            Element    location  = (Element)Parameters[2];
            Element    scale     = (Element)Parameters[3];
            EnumMember effectRev = (EnumMember)Parameters[4];
            bool       getIds    = (bool)((ConstantObject)Parameters[5]).Value;

            List <Element> actions = new List <Element>();

            IndexedVar effects = null;

            if (getIds)
            {
                effects = TranslateContext.VarCollection.AssignVar(Scope, "Model Effects", TranslateContext.IsGlobal, null);
                actions.AddRange(effects.SetVariable(new V_EmptyArray()));
            }

            actions.AddRange(RenderModel(modelVar.Model, visibleTo, location, scale, effectRev, effects));

            return(new MethodResult(actions.ToArray(), effects?.GetVariable()));
        }
        protected override MethodResult Get()
        {
            Element effectArray    = (Element)Parameters[0];
            int     destroyPerLoop = 1;

            if (Parameters[1] != null)
            {
                destroyPerLoop = (int)(double)((ConstantObject)Parameters[1]).Value;
            }

            List <Element> actions = new List <Element>();

            IndexedVar index = TranslateContext.VarCollection.AssignVar(Scope, "DestroyEffectArray index", TranslateContext.IsGlobal, null);

            actions.AddRange(index.SetVariable(new V_Number(0)));

            Element[] destroyActions = new Element[destroyPerLoop];
            for (int i = 0; i < destroyPerLoop; i++)
            {
                if (i == 0)
                {
                    destroyActions[i] = Element.Part <A_DestroyEffect>(Element.Part <V_ValueInArray>(effectArray, index.GetVariable()));
                }
                else
                {
                    destroyActions[i] = Element.Part <A_DestroyEffect>(Element.Part <V_ValueInArray>(effectArray, Element.Part <V_Add>(index.GetVariable(), new V_Number(i))));
                }
            }

            actions.AddRange(
                Element.While(
                    TranslateContext.ContinueSkip,
                    new V_Compare(
                        index.GetVariable(),
                        Operators.LessThan,
                        Element.Part <V_CountOf>(effectArray)
                        ),
                    ArrayBuilder <Element> .Build
                    (
                        destroyActions,
                        index.SetVariable(Element.Part <V_Add>(index.GetVariable(), new V_Number(destroyPerLoop)))
                    )
                    )
                );

            return(new MethodResult(actions.ToArray(), null));
        }
        protected override MethodResult Get()
        {
            IndexedVar player       = TranslateContext.VarCollection.AssignVar(Scope, "IsAIAccurate: player", TranslateContext.IsGlobal, null);
            IndexedVar originalHero = TranslateContext.VarCollection.AssignVar(Scope, "IsAIAccurate: originalHero", TranslateContext.IsGlobal, null);
            IndexedVar isAI         = TranslateContext.VarCollection.AssignVar(Scope, "IsAIAccurate: isAI", TranslateContext.IsGlobal, null);

            Element[] actions = ArrayBuilder <Element> .Build
                                (
                player.SetVariable((Element)Parameters[0]),
                originalHero.SetVariable(Element.Part <V_HeroOf>(player.GetVariable())),
                Element.Part <A_SkipIf>(Element.Part <V_Not>(Element.Part <V_Compare>(originalHero.GetVariable(), EnumData.GetEnumValue(Operators.Equal), new V_Null())), new V_Number(2)),
                isAI.SetVariable(new V_False()),
                Element.Part <A_Skip>(new V_Number(4)),
                Element.Part <A_ForcePlayerHero>(player.GetVariable(), EnumData.GetEnumValue(Hero.Ashe)),
                isAI.SetVariable(Element.Part <V_Compare>(Element.Part <V_HeroOf>(player.GetVariable()), EnumData.GetEnumValue(Operators.NotEqual), EnumData.GetEnumValue(Hero.Ashe))),
                Element.Part <A_ForcePlayerHero>(player.GetVariable(), originalHero.GetVariable()),
                Element.Part <A_StopForcingHero>(player.GetVariable())
                                );

            Element result = isAI.GetVariable();

            return(new MethodResult(actions, result));
        }
        protected override MethodResult Get()
        {
            IndexedVar player = TranslateContext.VarCollection.AssignVar(Scope, "IsAIUnintrusive: player", TranslateContext.IsGlobal, null);

            Element[] actions = ArrayBuilder <Element> .Build
                                (
                player.SetVariable((Element)Parameters[0]),
                Element.Part <A_Communicate>(player.GetVariable(), EnumData.GetEnumValue(Communication.VoiceLineUp))
                                );

            Element result = Element.Part <V_Not>(Element.Part <V_IsCommunicating>(player.GetVariable(), EnumData.GetEnumValue(Communication.VoiceLineUp)));

            return(new MethodResult(actions, result));
        }
        protected override MethodResult Get()
        {
            IndexedVar array = IndexedVar.AssignInternalVar(TranslateContext.VarCollection, Scope, "OptimisedRangeOfArray: array", TranslateContext.IsGlobal);

            Element[] actions = ArrayBuilder <Element> .Build
                                (
                array.SetVariable((Element)Parameters[0])
                                );

            Element min = Element.Part <V_FirstOf>(Element.Part <V_SortedArray>(array.GetVariable(), new V_ArrayElement()));
            Element max = Element.Part <V_LastOf>(Element.Part <V_SortedArray>(array.GetVariable(), new V_ArrayElement()));

            return(new MethodResult(actions, max - min));
        }
Esempio n. 10
0
        protected override MethodResult Get()
        {
            // Setup the continue skip.
            ContinueSkip continueSkip = TranslateContext.ContinueSkip;

            continueSkip.Setup();

            IndexedVar result = TranslateContext.VarCollection.AssignVar(Scope, $"{Name} result", TranslateContext.IsGlobal, null);

            Element[] actions = ArrayBuilder <Element> .Build(

                // Set the continue skip.
                continueSkip.SetSkipCountActions(continueSkip.GetSkipCount() + 4),

                // This will continue at (0) if the rule loops.
                new A_LoopIfConditionIsFalse(),
                // Set the result to true.
                result.SetVariable(new V_True()),
                Element.Part <A_Skip>(new V_Number(1)),

                // The rule will loop back here (0) if false.
                result.SetVariable(new V_False()),

                // Reset the continueskip
                continueSkip.ResetSkipActions()
                );

            if (TestingIfTrue)
            {
                return(new MethodResult(actions, result.GetVariable()));
            }
            else
            {
                return(new MethodResult(actions, Element.Part <V_Not>(result.GetVariable())));
            }
        }
        protected override MethodResult Get()
        {
            IndexedVar fraction = TranslateContext.VarCollection.AssignVar(Scope, "OptimisedLinearInterpolate: fraction", TranslateContext.IsGlobal, null);

            Element[] actions = ArrayBuilder <Element> .Build
                                (
                fraction.SetVariable((Element)Parameters[2])
                                );

            Element point1 = (Element)Parameters[0];
            Element point2 = (Element)Parameters[1];
            Element p1     = Element.Part <V_Multiply>(point1, Element.Part <V_Subtract>(new V_Number(1), fraction.GetVariable()));
            Element p2     = Element.Part <V_Multiply>(point2, fraction.GetVariable());

            return(new MethodResult(actions, Element.Part <V_Add>(p1, p2)));
        }
        protected override MethodResult Get()
        {
            IndexedVar point1 = IndexedVar.AssignInternalVar(TranslateContext.VarCollection, Scope, "OptimisedHorizontalDistance: point1", TranslateContext.IsGlobal);
            IndexedVar point2 = IndexedVar.AssignInternalVar(TranslateContext.VarCollection, Scope, "OptimisedHorizontalDistance: point2", TranslateContext.IsGlobal);

            Element[] actions = ArrayBuilder <Element> .Build
                                (
                point1.SetVariable((Element)Parameters[0]),
                point2.SetVariable((Element)Parameters[1])
                                );

            Element x   = Element.XOf(point1.GetVariable()) - Element.XOf(point2.GetVariable());
            Element z   = Element.ZOf(point1.GetVariable()) - Element.ZOf(point2.GetVariable());
            Element sum = Element.Part <V_RaiseToPower>(x, Element.Num(2)) + Element.Part <V_RaiseToPower>(z, Element.Num(2));

            return(new MethodResult(actions, Element.Part <V_SquareRoot>(sum)));
        }
Esempio n. 13
0
        protected override MethodResult Get()
        {
            IndexedVar player = IndexedVar.AssignInternalVar(TranslateContext.VarCollection, Scope, "OptimisedIsOnScreen: player", TranslateContext.IsGlobal);
            IndexedVar point  = IndexedVar.AssignInternalVar(TranslateContext.VarCollection, Scope, "OptimisedIsOnScreen: point", TranslateContext.IsGlobal);

            Element[] actions = ArrayBuilder <Element> .Build
                                (
                player.SetVariable((Element)Parameters[0]),
                point.SetVariable((Element)Parameters[1])
                                );

            Element fov   = (Element)Parameters[2];
            Element los   = Element.Part <V_IsInLineOfSight>(Element.Part <V_EyePosition>(player.GetVariable()), point.GetVariable());
            Element angle = Element.Part <V_IsInViewAngle>(player.GetVariable(), point.GetVariable(), fov / 2);

            return(new MethodResult(actions, Element.Part <V_And>(los, angle)));
        }
        protected override MethodResult Get()
        {
            IndexedVar point1 = TranslateContext.VarCollection.AssignVar(Scope, "OptimisedHorizontalDistance: point1", TranslateContext.IsGlobal, null);
            IndexedVar point2 = TranslateContext.VarCollection.AssignVar(Scope, "OptimisedHorizontalDistance: point2", TranslateContext.IsGlobal, null);

            Element[] actions = ArrayBuilder <Element> .Build
                                (
                point1.SetVariable((Element)Parameters[0]),
                point2.SetVariable((Element)Parameters[1])
                                );

            Element x   = Element.Part <V_Subtract>(Element.Part <V_XOf>(point1.GetVariable()), Element.Part <V_XOf>(point2.GetVariable()));
            Element z   = Element.Part <V_Subtract>(Element.Part <V_ZOf>(point1.GetVariable()), Element.Part <V_ZOf>(point2.GetVariable()));
            Element sum = Element.Part <V_Add>(Element.Part <V_RaiseToPower>(x, new V_Number(2)), Element.Part <V_RaiseToPower>(z, new V_Number(2)));

            return(new MethodResult(actions, Element.Part <V_SquareRoot>(sum)));
        }
        protected override MethodResult Get()
        {
            IndexedVar player = TranslateContext.VarCollection.AssignVar(Scope, "SetHealth: player", TranslateContext.IsGlobal, null);
            IndexedVar health = TranslateContext.VarCollection.AssignVar(Scope, "SetHealth: health", TranslateContext.IsGlobal, null);

            Element[] actions = ArrayBuilder <Element> .Build
                                (
                player.SetVariable((Element)Parameters[0]),
                health.SetVariable((Element)Parameters[1]),
                Element.Part <A_SkipIf>(Element.Part <V_Not>(Element.Part <V_Compare>(Element.Part <V_Health>(player.GetVariable()), EnumData.GetEnumValue(Operators.LessThan), health.GetVariable())), new V_Number(2)),
                Element.Part <A_Heal>(player.GetVariable(), new V_Null(), Element.Part <V_Subtract>(health.GetVariable(), Element.Part <V_Health>(player.GetVariable()))),
                Element.Part <A_Skip>(new V_Number(2)),
                Element.Part <A_SkipIf>(Element.Part <V_Not>(Element.Part <V_Compare>(Element.Part <V_Health>(player.GetVariable()), EnumData.GetEnumValue(Operators.GreaterThan), health.GetVariable())), new V_Number(1)),
                Element.Part <A_Damage>(player.GetVariable(), new V_Null(), Element.Part <V_Subtract>(Element.Part <V_Health>(player.GetVariable()), health.GetVariable()))
                                );

            return(new MethodResult(actions, null));
        }
        protected override MethodResult Get()
        {
            IndexedVar array       = TranslateContext.VarCollection.AssignVar(Scope, "OptimisedSortedMedian: array", TranslateContext.IsGlobal, null);
            IndexedVar medianIndex = TranslateContext.VarCollection.AssignVar(Scope, "OptimisedSortedMedian: medianIndex", TranslateContext.IsGlobal, null);

            Element length      = Element.Part <V_CountOf>(array.GetVariable());
            Element condition   = Element.Part <V_Compare>(Element.Part <V_Modulo>(length, new V_Number(2)), EnumData.GetEnumValue(Operators.Equal), new V_Number(0));
            Element consequent  = Element.Part <V_Divide>(Element.Part <V_Add>(Element.Part <V_ValueInArray>(array.GetVariable(), Element.Part <V_Subtract>(medianIndex.GetVariable(), new V_Number(0.5))), Element.Part <V_ValueInArray>(array.GetVariable(), Element.Part <V_Add>(medianIndex.GetVariable(), new V_Number(0.5)))), new V_Number(2));
            Element alternative = Element.Part <V_ValueInArray>(array.GetVariable(), medianIndex.GetVariable());

            Element[] actions = ArrayBuilder <Element> .Build
                                (
                array.SetVariable(Element.Part <V_SortedArray>((Element)Parameters[0], new V_ArrayElement())),
                medianIndex.SetVariable(Element.Part <V_Divide>(Element.Part <V_Add>(length, new V_Number(1)), new V_Number(2)))
                                );

            return(new MethodResult(actions, Element.TernaryConditional(condition, consequent, alternative)));
        }
        private static Element[] UpdateVariable(IndexedVar var, IndexedVar destination, IndexedVar rate)
        {
            Element rateAdjusted = Element.Part <V_Multiply>(rate.GetVariable(), new V_Number(Constants.MINIMUM_WAIT));

            Element distance = Element.Part <V_DistanceBetween>(var.GetVariable(), destination.GetVariable());

            Element ratio = Element.Part <V_Divide>(rateAdjusted, distance);

            Element delta = Element.Part <V_Subtract>(destination.GetVariable(), var.GetVariable());

            Element result = Element.TernaryConditional(
                new V_Compare(distance, Operators.GreaterThan, rateAdjusted),
                Element.Part <V_Add>(var.GetVariable(), Element.Part <V_Multiply>(ratio, delta)),
                destination.GetVariable()
                );

            return(var.SetVariable(result));
        }
Esempio n. 18
0
        protected override MethodResult Get()
        {
            IndexedVar player = IndexedVar.AssignInternalVar(TranslateContext.VarCollection, Scope, "SetHealth: player", TranslateContext.IsGlobal);
            IndexedVar health = IndexedVar.AssignInternalVar(TranslateContext.VarCollection, Scope, "SetHealth: health", TranslateContext.IsGlobal);

            Element[] actions = ArrayBuilder <Element> .Build
                                (
                player.SetVariable((Element)Parameters[0]),
                health.SetVariable((Element)Parameters[1]),
                Element.Part <A_SkipIf>(!(Element.Part <V_Health>(player.GetVariable()) < health.GetVariable()), Element.Num(2)),
                Element.Part <A_Heal>(player.GetVariable(), new V_Null(), health.GetVariable() - Element.Part <V_Health>(player.GetVariable())),
                Element.Part <A_Skip>(Element.Num(2)),
                Element.Part <A_SkipIf>(!(Element.Part <V_Health>(player.GetVariable()) > health.GetVariable()), Element.Num(1)),
                Element.Part <A_Damage>(player.GetVariable(), new V_Null(), Element.Part <V_Health>(player.GetVariable()) - health.GetVariable())
                                );

            return(new MethodResult(actions, null));
        }
        protected override MethodResult Get()
        {
            IndexedVar array       = IndexedVar.AssignInternalVar(TranslateContext.VarCollection, Scope, "OptimisedSortedMedian: array", TranslateContext.IsGlobal);
            IndexedVar medianIndex = IndexedVar.AssignInternalVar(TranslateContext.VarCollection, Scope, "OptimisedSortedMedian: medianIndex", TranslateContext.IsGlobal);

            Element length      = Element.Part <V_CountOf>(array.GetVariable());
            Element condition   = Element.Part <V_Compare>(length % 2, EnumData.GetEnumValue(Operators.Equal), new V_Number(0));
            Element consequent  = (Element.Part <V_ValueInArray>(array.GetVariable(), medianIndex.GetVariable() - 0.5) + Element.Part <V_ValueInArray>(array.GetVariable(), medianIndex.GetVariable() + 0.5)) / 2;
            Element alternative = Element.Part <V_ValueInArray>(array.GetVariable(), medianIndex.GetVariable());

            Element[] actions = ArrayBuilder <Element> .Build
                                (
                array.SetVariable(Element.Part <V_SortedArray>((Element)Parameters[0], new V_ArrayElement())),
                medianIndex.SetVariable((length + 1) / 2)
                                );

            return(new MethodResult(actions, Element.TernaryConditional(condition, consequent, alternative, false)));
        }
        protected override MethodResult Get()
        {
            IndexedVar array = IndexedVar.AssignInternalVar(TranslateContext.VarCollection, Scope, "OptimisedBlendedIndex: array", TranslateContext.IsGlobal);
            IndexedVar index = IndexedVar.AssignInternalVar(TranslateContext.VarCollection, Scope, "OptimisedBlendedIndex: index", TranslateContext.IsGlobal);

            Element[] actions = ArrayBuilder <Element> .Build
                                (
                array.SetVariable((Element)Parameters[0]),
                index.SetVariable((Element)Parameters[1])
                                );

            Element condition   = Element.Part <V_Compare>(Element.Part <V_RoundToInteger>(index.GetVariable(), EnumData.GetEnumValue(Rounding.Down)), EnumData.GetEnumValue(Operators.Equal), index.GetVariable());
            Element consequent  = Element.Part <V_ValueInArray>(array.GetVariable(), index.GetVariable());
            Element alt1        = Element.Part <V_ValueInArray>(array.GetVariable(), Element.Part <V_RoundToInteger>(index.GetVariable(), EnumData.GetEnumValue(Rounding.Down))) * Element.Part <V_Subtract>(index.GetVariable(), Element.Part <V_RoundToInteger>(index.GetVariable(), EnumData.GetEnumValue(Rounding.Down)));
            Element alt2        = Element.Part <V_ValueInArray>(array.GetVariable(), Element.Part <V_RoundToInteger>(index.GetVariable(), EnumData.GetEnumValue(Rounding.Up))) * (Element.Part <V_RoundToInteger>(index.GetVariable(), EnumData.GetEnumValue(Rounding.Up)) - index.GetVariable());
            Element alternative = alt1 + alt2;

            return(new MethodResult(actions, Element.TernaryConditional(condition, consequent, alternative, false)));
        }
        override protected MethodResult Get(PathfinderInfo info)
        {
            if (((VarRef)Parameters[1]).Var is PathMapVar == false)
            {
                throw SyntaxErrorException.InvalidVarRefType(((VarRef)Parameters[1]).Var.Name, VarType.PathMap, ParameterLocations[1]);
            }

            Element    player  = (Element)Parameters[0];
            PathMapVar pathmap = (PathMapVar)((VarRef)Parameters[1]).Var;

            IndexedVar destination = IndexedVar.AssignInternalVarExt(TranslateContext.VarCollection, Scope, "Destination", TranslateContext.IsGlobal);

            TranslateContext.Actions.AddRange(destination.SetVariable((Element)Parameters[2]));

            DijkstraNormal algorithm = new DijkstraNormal(TranslateContext, pathmap, Element.Part <V_PositionOf>(player), destination.GetVariable());

            algorithm.Get();
            DijkstraBase.Pathfind(TranslateContext, info, algorithm.finalPath.GetVariable(), player, destination.GetVariable());
            return(new MethodResult(null, null));
        }
Esempio n. 22
0
        protected override MethodResult Get()
        {
            IndexedVar player = IndexedVar.AssignInternalVar(TranslateContext.VarCollection, Scope, "OptimisedEyeCastHitPosition: player", TranslateContext.IsGlobal);

            Element range     = (Element)Parameters[1];
            Element eyePos    = Element.Part <V_EyePosition>(player.GetVariable());
            Element direction = Element.Part <V_FacingDirectionOf>(player.GetVariable());
            Element raycast   = Element.Part <V_RayCastHitPosition>(eyePos,
                                                                    eyePos + direction * range,
                                                                    new V_Null(),
                                                                    new V_EventPlayer(),
                                                                    new V_False()
                                                                    );

            Element[] actions = ArrayBuilder <Element> .Build
                                (
                player.SetVariable((Element)Parameters[0])
                                );

            return(new MethodResult(actions, raycast));
        }
        protected override MethodResult Get(PathfinderInfo info)
        {
            if (((VarRef)Parameters[1]).Var is PathMapVar == false)
            {
                throw SyntaxErrorException.InvalidVarRefType(((VarRef)Parameters[1]).Var.Name, VarType.PathMap, ParameterLocations[1]);
            }

            IndexedVar players = IndexedVar.AssignInternalVarExt(TranslateContext.VarCollection, Scope, "Players", TranslateContext.IsGlobal);

            TranslateContext.Actions.AddRange(players.SetVariable((Element)Parameters[0]));

            PathMapVar pathmap = (PathMapVar)((VarRef)Parameters[1]).Var;

            IndexedVar destination = IndexedVar.AssignInternalVarExt(TranslateContext.VarCollection, Scope, "Destination", TranslateContext.IsGlobal);

            TranslateContext.Actions.AddRange(destination.SetVariable((Element)Parameters[2]));

            DijkstraMultiSource algorithm = new DijkstraMultiSource(TranslateContext, info, pathmap, players.GetVariable(), destination.GetVariable());

            algorithm.Get();
            return(new MethodResult(null, null));
        }
Esempio n. 24
0
        protected MethodResult RenderText(string text, string font, double quality, double angle, Element visibleTo, Element location, double scale, IWorkshopTree effectRev, bool getIds, double angleRound)
        {
            quality = Math.Max(10 - quality, 0.1);

            Model model;

            using (FontFamily family = GetFontFamily(font, FontParameter == -1 ? MethodLocation : ParameterLocations[FontParameter]))
                model = Model.ImportString(text, family, quality, angle, scale, angleRound);

            List <Element> actions = new List <Element>();

            IndexedVar effects = null;

            if (getIds)
            {
                effects = TranslateContext.VarCollection.AssignVar(Scope, "Model Effects", TranslateContext.IsGlobal, null);
                actions.AddRange(effects.SetVariable(new V_EmptyArray()));
            }

            actions.AddRange(RenderModel(model, visibleTo, location, null, effectRev, effects));

            return(new MethodResult(actions.ToArray(), effects?.GetVariable()));
        }
        protected override MethodResult Get()
        {
            IndexedVar temp = TranslateContext.VarCollection.AssignVar(Scope, "GetMap: temp", TranslateContext.IsGlobal, null);

            Element[] actions = ArrayBuilder <Element> .Build
                                (
                temp.SetVariable(Element.Part <V_RoundToInteger>(
                                     Element.Part <V_Add>(
                                         Element.Part <V_DistanceBetween>(
                                             Element.Part <V_NearestWalkablePosition>(
                                                 Element.Part <V_Vector>(new V_Number(-500.000), new V_Number(0), new V_Number(0))
                                                 ),
                                             Element.Part <V_NearestWalkablePosition>(Element.Part <V_Vector>(new V_Number(500), new V_Number(0), new V_Number(0)))
                                             ),
                                         Element.Part <V_DistanceBetween>(
                                             Element.Part <V_NearestWalkablePosition>(Element.Part <V_Vector>(new V_Number(0), new V_Number(0), new V_Number(-500.000))),
                                             Element.Part <V_NearestWalkablePosition>(Element.Part <V_Vector>(new V_Number(0), new V_Number(0), new V_Number(500)))
                                             )
                                         ),
                                     EnumData.GetEnumValue(Rounding.Down)
                                     )),

                temp.SetVariable(Element.Part <V_IndexOfArrayValue>(
                                     Element.Part <V_Append>(
                                         Element.Part <V_Append>(
                                             Element.Part <V_Append>(
                                                 Element.Part <V_Append>(
                                                     Element.Part <V_Append>(
                                                         Element.Part <V_Append>(
                                                             Element.Part <V_Append>(
                                                                 Element.Part <V_Append>(
                                                                     Element.Part <V_Append>(
                                                                         Element.Part <V_Append>(
                                                                             Element.Part <V_Append>(
                                                                                 Element.Part <V_Append>(
                                                                                     Element.Part <V_Append>(
                                                                                         Element.Part <V_Append>(
                                                                                             Element.Part <V_Append>(
                                                                                                 Element.Part <V_Append>(
                                                                                                     Element.Part <V_Append>(
                                                                                                         Element.Part <V_Append>(
                                                                                                             Element.Part <V_Append>(
                                                                                                                 Element.Part <V_Append>(
                                                                                                                     Element.Part <V_Append>(
                                                                                                                         Element.Part <V_Append>(
                                                                                                                             Element.Part <V_Append>(
                                                                                                                                 Element.Part <V_Append>(
                                                                                                                                     Element.Part <V_Append>(
                                                                                                                                         Element.Part <V_Append>(
                                                                                                                                             Element.Part <V_Append>(
                                                                                                                                                 Element.Part <V_Append>(
                                                                                                                                                     Element.Part <V_Append>(
                                                                                                                                                         Element.Part <V_Append>(
                                                                                                                                                             Element.Part <V_Append>(
                                                                                                                                                                 Element.Part <V_Append>(
                                                                                                                                                                     Element.Part <V_Append>(
                                                                                                                                                                         Element.Part <V_Append>(
                                                                                                                                                                             Element.Part <V_Append>(
                                                                                                                                                                                 Element.Part <V_Append>(
                                                                                                                                                                                     Element.Part <V_Append>(
                                                                                                                                                                                         Element.Part <V_Append>(
                                                                                                                                                                                             Element.Part <V_Append>(
                                                                                                                                                                                                 Element.Part <V_Append>(
                                                                                                                                                                                                     Element.Part <V_Append>(
                                                                                                                                                                                                         Element.Part <V_Append>(Element.Part <V_EmptyArray>(), new V_Number(153)),
                                                                                                                                                                                                         new V_Number(468)),
                                                                                                                                                                                                     new V_Number(1196)),
                                                                                                                                                                                                 new V_Number(135)),
                                                                                                                                                                                             new V_Number(139)),
                                                                                                                                                                                         new V_Number(477)),
                                                                                                                                                                                     new V_Number(184)),
                                                                                                                                                                                 Element.Part <V_FirstOf>(
                                                                                                                                                                                     Element.Part <V_FilteredArray>(
                                                                                                                                                                                         Element.Part <V_Append>(
                                                                                                                                                                                             Element.Part <V_Append>(Element.Part <V_EmptyArray>(), new V_Number(343)),
                                                                                                                                                                                             new V_Number(347)),
                                                                                                                                                                                         Element.Part <V_Compare>(
                                                                                                                                                                                             Element.Part <V_ArrayElement>(),
                                                                                                                                                                                             EnumData.GetEnumValue(Operators.Equal),
                                                                                                                                                                                             temp.GetVariable()
                                                                                                                                                                                             )
                                                                                                                                                                                         )
                                                                                                                                                                                     )
                                                                                                                                                                                 ),
                                                                                                                                                                             new V_Number(366)
                                                                                                                                                                             ),
                                                                                                                                                                         Element.Part <V_FirstOf>(
                                                                                                                                                                             Element.Part <V_FilteredArray>(
                                                                                                                                                                                 Element.Part <V_Append>(
                                                                                                                                                                                     Element.Part <V_Append>(Element.Part <V_EmptyArray>(), new V_Number(433)),
                                                                                                                                                                                     new V_Number(436)
                                                                                                                                                                                     ),
                                                                                                                                                                                 Element.Part <V_Compare>(
                                                                                                                                                                                     Element.Part <V_ArrayElement>(),
                                                                                                                                                                                     EnumData.GetEnumValue(Operators.Equal),
                                                                                                                                                                                     temp.GetVariable()
                                                                                                                                                                                     )
                                                                                                                                                                                 )
                                                                                                                                                                             )
                                                                                                                                                                         ),
                                                                                                                                                                     new V_Number(403)),
                                                                                                                                                                 Element.Part <V_FirstOf>(
                                                                                                                                                                     Element.Part <V_FilteredArray>(
                                                                                                                                                                         Element.Part <V_Append>(
                                                                                                                                                                             Element.Part <V_Append>(Element.Part <V_EmptyArray>(), new V_Number(382)),
                                                                                                                                                                             new V_Number(384)
                                                                                                                                                                             ),
                                                                                                                                                                         Element.Part <V_Compare>(
                                                                                                                                                                             Element.Part <V_ArrayElement>(),
                                                                                                                                                                             EnumData.GetEnumValue(Operators.Equal),
                                                                                                                                                                             temp.GetVariable()
                                                                                                                                                                             )
                                                                                                                                                                         )
                                                                                                                                                                     )
                                                                                                                                                                 ),
                                                                                                                                                             new V_Number(993)),
                                                                                                                                                         new V_Number(386)),
                                                                                                                                                     Element.Part <V_FirstOf>(
                                                                                                                                                         Element.Part <V_FilteredArray>(
                                                                                                                                                             Element.Part <V_Append>(
                                                                                                                                                                 Element.Part <V_Append>(Element.Part <V_EmptyArray>(), new V_Number(331)),
                                                                                                                                                                 new V_Number(348)
                                                                                                                                                                 ),
                                                                                                                                                             Element.Part <V_Compare>(
                                                                                                                                                                 Element.Part <V_ArrayElement>(),
                                                                                                                                                                 EnumData.GetEnumValue(Operators.Equal),
                                                                                                                                                                 temp.GetVariable()
                                                                                                                                                                 )
                                                                                                                                                             )
                                                                                                                                                         )
                                                                                                                                                     ),
                                                                                                                                                 new V_Number(659)),
                                                                                                                                             new V_Number(145)),
                                                                                                                                         new V_Number(569)),
                                                                                                                                     new V_Number(384)),
                                                                                                                                 new V_Number(1150)),
                                                                                                                             new V_Number(371)),
                                                                                                                         new V_Number(179)),
                                                                                                                     new V_Number(497)),
                                                                                                                 new V_Number(374)),
                                                                                                             new V_Number(312)),
                                                                                                         new V_Number(324)),
                                                                                                     new V_Number(434)),
                                                                                                 new V_Number(297)),
                                                                                             new V_Number(276)),
                                                                                         new V_Number(330)),
                                                                                     new V_Number(376)),
                                                                                 new V_Number(347)),
                                                                             new V_Number(480)),
                                                                         new V_Number(310)),
                                                                     new V_Number(342)),
                                                                 new V_Number(360)),
                                                             new V_Number(364)),
                                                         new V_Number(372)),
                                                     new V_Number(370)),
                                                 new V_Number(450)),
                                             new V_Number(356)),
                                         new V_Number(305)),
                                     temp.GetVariable())
                                 )
                                );

            return(new MethodResult(actions, temp.GetVariable()));
        }
        protected override MethodResult Get()
        {
            var eventPlayer = new V_EventPlayer();

            IndexedVar a      = TranslateContext.VarCollection.AssignVar(Scope, "AngleOfVectors: a", TranslateContext.IsGlobal, null);
            IndexedVar b      = TranslateContext.VarCollection.AssignVar(Scope, "AngleOfVectors: b", TranslateContext.IsGlobal, null);
            IndexedVar c      = TranslateContext.VarCollection.AssignVar(Scope, "AngleOfVectors: c", TranslateContext.IsGlobal, null);
            IndexedVar ab     = TranslateContext.VarCollection.AssignVar(Scope, "AngleOfVectors: ab", TranslateContext.IsGlobal, null);
            IndexedVar bc     = TranslateContext.VarCollection.AssignVar(Scope, "AngleOfVectors: bc", TranslateContext.IsGlobal, null);
            IndexedVar abVec  = TranslateContext.VarCollection.AssignVar(Scope, "AngleOfVectors: abVec", TranslateContext.IsGlobal, null);
            IndexedVar bcVec  = TranslateContext.VarCollection.AssignVar(Scope, "AngleOfVectors: bcVec", TranslateContext.IsGlobal, null);
            IndexedVar abNorm = TranslateContext.VarCollection.AssignVar(Scope, "AngleOfVectors: abNorm", TranslateContext.IsGlobal, null);
            IndexedVar bcNorm = TranslateContext.VarCollection.AssignVar(Scope, "AngleOfVectors: bcNorm", TranslateContext.IsGlobal, null);

            Element zeroVec = Element.Part <V_Vector>(new V_Number(0), new V_Number(0), new V_Number(0));

            Element[] actions = ArrayBuilder <Element> .Build
                                (
                // Save A
                a.SetVariable((Element)Parameters[0], eventPlayer),
                // Save B
                b.SetVariable((Element)Parameters[1], eventPlayer),
                // save C
                c.SetVariable((Element)Parameters[2], eventPlayer),

                // get ab
                // ab[3] = { b[0] - a[0], b[1] - a[1], b[2] - a[2] };
                ab.SetVariable(
                    Element.Part <V_Vector>
                    (
                        Element.Part <V_Subtract>(Element.Part <V_XOf>(b.GetVariable()), Element.Part <V_XOf>(a.GetVariable())),
                        Element.Part <V_Subtract>(Element.Part <V_YOf>(b.GetVariable()), Element.Part <V_YOf>(a.GetVariable())),
                        Element.Part <V_Subtract>(Element.Part <V_ZOf>(b.GetVariable()), Element.Part <V_ZOf>(a.GetVariable()))
                    ), eventPlayer),

                // get bc
                // bc[3] = { c[0] - b[0], c[1] - b[1], c[2] - b[2] };
                bc.SetVariable(
                    Element.Part <V_Vector>
                    (
                        Element.Part <V_Subtract>(Element.Part <V_XOf>(c.GetVariable()), Element.Part <V_XOf>(b.GetVariable())),
                        Element.Part <V_Subtract>(Element.Part <V_YOf>(c.GetVariable()), Element.Part <V_YOf>(b.GetVariable())),
                        Element.Part <V_Subtract>(Element.Part <V_ZOf>(c.GetVariable()), Element.Part <V_ZOf>(b.GetVariable()))
                    ), eventPlayer),

                // get abVec
                // abVec = sqrt(ab[0] * ab[0] + ab[1] * ab[1] + ab[2] * ab[2]);
                abVec.SetVariable(
                    Element.Part <V_DistanceBetween>
                    (
                        ab.GetVariable(),
                        zeroVec
                    ), eventPlayer),

                // get bcVec
                // bcVec = sqrt(bc[0] * bc[0] + bc[1] * bc[1] + bc[2] * bc[2]);
                bcVec.SetVariable(
                    Element.Part <V_DistanceBetween>
                    (
                        bc.GetVariable(),
                        zeroVec
                    ), eventPlayer),

                // get abNorm
                // abNorm[3] = {ab[0] / abVec, ab[1] / abVec, ab[2] / abVec};
                abNorm.SetVariable(
                    Element.Part <V_Vector>
                    (
                        Element.Part <V_Divide>(Element.Part <V_XOf>(ab.GetVariable()), abVec.GetVariable()),
                        Element.Part <V_Divide>(Element.Part <V_YOf>(ab.GetVariable()), abVec.GetVariable()),
                        Element.Part <V_Divide>(Element.Part <V_ZOf>(ab.GetVariable()), abVec.GetVariable())
                    ), eventPlayer),

                // get bcNorm
                // bcNorm[3] = {bc[0] / bcVec, bc[1] / bcVec, bc[2] / bcVec};
                bcNorm.SetVariable(
                    Element.Part <V_Vector>
                    (
                        Element.Part <V_Divide>(Element.Part <V_XOf>(bc.GetVariable()), bcVec.GetVariable()),
                        Element.Part <V_Divide>(Element.Part <V_YOf>(bc.GetVariable()), bcVec.GetVariable()),
                        Element.Part <V_Divide>(Element.Part <V_ZOf>(bc.GetVariable()), bcVec.GetVariable())
                    ), eventPlayer)
                                );

            Element result = Element.Part <V_Divide>
                             (
                Element.Part <V_Multiply>
                (
                    Element.Part <V_ArccosineInRadians>
                    (
                        // get res
                        // res = abNorm[0] * bcNorm[0] + abNorm[1] * bcNorm[1] + abNorm[2] * bcNorm[2];
                        //target.SetVariable(
                        Element.Part <V_Add>
                        (
                            Element.Part <V_Add>
                            (
                                Element.Part <V_Multiply>(Element.Part <V_XOf>(abNorm.GetVariable()), Element.Part <V_XOf>(bcNorm.GetVariable())),
                                Element.Part <V_Multiply>(Element.Part <V_YOf>(abNorm.GetVariable()), Element.Part <V_YOf>(bcNorm.GetVariable()))
                            ),
                            Element.Part <V_Multiply>(Element.Part <V_ZOf>(abNorm.GetVariable()), Element.Part <V_ZOf>(bcNorm.GetVariable()))
                        )
                    ),
                    new V_Number(180)
                ),
                new V_Number(Math.PI)
                             );

            return(new MethodResult(actions, result));
        }