void Serialize(MegaloScriptModel model, IO.BitStream s, Proto.MegaloScriptProtoVariableReference protoType)
        {
            s.Stream(ref Type, protoType.TypeBitLength);
            if (Type < 0 || Type >= protoType.Members.Count)
            {
                throw new System.IO.InvalidDataException(string.Format(Util.InvariantCultureInfo,
                                                                       "{0}/{1}: Encountered invalid {2} type data",
                                                                       s.StreamName, model.MegaloVariant.BaseVariant.Header.Title, mReferenceKind));
            }

            var member = protoType.Members[Type];

            if (member.HasDataType)
            {
                MegaloScriptEnumValue.SerializeValue(model, s, member.EnumValueType, ref DataType);
            }
            else
            {
                DataType = TypeExtensions.kNone;
            }

            if (member.HasDataValue)
            {
                SerializeData(model, s, member.ValueType);
            }
            else
            {
                Data = TypeExtensions.kNone;
            }
        }
        public void Serialize <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s)
            where TDoc : class
            where TCursor : class
        {
            if ((model.TagElementStreamSerializeFlags & MegaloScriptModelTagElementStreamFlags.EmbedObjects) != 0)
            {
                s.StreamElements("E", mElements, model, MegaloScriptModelObjectHandle.SerializeForEmbed);
            }
            else
            {
                s.StreamElements("E", mElements, model, MegaloScriptModelObjectHandle.Serialize);
            }

            if (s.IsReading)
            {
                // auto-create union groups if needed
                if (model.TagElementStreamSerializeFlags.EmbedObjectsWriteSansIds())
                {
                    MegaloScriptUnionGroup.PostprocessConditionsForEmbedObjectsWriteSansIds(model, s, mElements);
                }
                else
                {
                    MegaloScriptUnionGroup.ReadPostprocessConditions(model, s, mElements);
                }
            }
        }
示例#3
0
        void Read <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s,
                                  bool embedValues)
            where TDoc : class
            where TCursor : class
        {
            int param_index = 0;

            foreach (var node in s.ElementsByName("Param"))
            {
                using (s.EnterCursorBookmark(node))
                {
                    if (embedValues)
                    {
                        MegaloScriptValueBase.SerializeValueForEmbed(model, s, ref mValueIds[param_index]);
                    }
                    else
                    {
                        s.StreamCursor(ref mValueIds[param_index]);
                    }

                    Contract.Assert(mValueIds[param_index].IsNotNone());
                    param_index++;

                    if (param_index == mValueIds.Length)
                    {
                        break;
                    }
                }
            }
        }
        static void SerializeTriggerExecutionOrder <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s,
                                                                   MegaloScriptModel model, ref int triggerIndex)
            where TDoc : class
            where TCursor : class
        {
            if (model.TagElementStreamSerializeFlags.EmbedObjects())
            {
                var id_resolving_ctxt = new TriggerIndexNameResolvingContext(model);
                var id_resolver       = TriggerIndexNameResolvingContext.IdResolver;
                var name_resolver     = TriggerIndexNameResolvingContext.NameResolver;

                s.StreamCursorIdAsString(ref triggerIndex, id_resolving_ctxt, id_resolver, name_resolver);
            }
            else
            {
                s.StreamCursor(ref triggerIndex);

                if (model.Triggers.SlotIsFreeOrInvalidIndex(triggerIndex))
                {
                    var ex = new System.IO.InvalidDataException(string.Format(
                                                                    "Couldn't define execution order for invalid trigger index {0}", triggerIndex));
                    s.ThrowReadException(ex);
                }
            }

            if (!model.Triggers[triggerIndex].TriggerType.IsUpdatedOnGameTick())
            {
                var ex = new System.IO.InvalidDataException(string.Format(
                                                                "Trigger '{0}' can't have its execution explicitly ordered",
                                                                triggerIndex.ToString()
                                                                ));
                s.ThrowReadException(ex);
            }
        }
示例#5
0
        public override MegaloScriptValueBase Copy(MegaloScriptModel model)
        {
            var result = (MegaloScriptShapeValue)model.CreateValue(ValueType);

            result.ShapeType = ShapeType;

            switch (ShapeType)
            {
            case MegaloScriptShapeType.Sphere:
                result.Radius = Radius;
                break;

            case MegaloScriptShapeType.Cylinder:
                result.Radius = Radius;
                result.Top    = Top;
                result.Bottom = Bottom;
                break;

            case MegaloScriptShapeType.Box:
                result.Radius = Radius;
                result.Length = Length;
                result.Top    = Top;
                result.Bottom = Bottom;
                break;

            case MegaloScriptShapeType.None: break;

            default: throw new KSoft.Debug.UnreachableException(ShapeType.ToString());
            }

            return(result);
        }
示例#6
0
        protected override void SerializeValue <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s)
        {
            s.StreamAttributeEnum("shapeType", ref mShapeType);

            switch (ShapeType)
            {
            case MegaloScriptShapeType.Sphere:
                using (s.EnterCursorBookmark(kVar0ElementName)) mRadius.SerializeCustom(model, s);
                break;

            case MegaloScriptShapeType.Cylinder:
                using (s.EnterCursorBookmark(kVar0ElementName)) mRadius.SerializeCustom(model, s);
                using (s.EnterCursorBookmark(kVar2ElementName)) mTop.SerializeCustom(model, s);
                using (s.EnterCursorBookmark(kVar3ElementName)) mBottom.SerializeCustom(model, s);
                break;

            case MegaloScriptShapeType.Box:
                using (s.EnterCursorBookmark("Width")) mRadius.SerializeCustom(model, s);
                using (s.EnterCursorBookmark(kVar1ElementName)) mLength.SerializeCustom(model, s);
                using (s.EnterCursorBookmark(kVar2ElementName)) mTop.SerializeCustom(model, s);
                using (s.EnterCursorBookmark(kVar3ElementName)) mBottom.SerializeCustom(model, s);
                break;

            case MegaloScriptShapeType.None: break;

            default: throw new KSoft.Debug.UnreachableException(ShapeType.ToString());
            }
        }
示例#7
0
        void Write <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s,
                                   bool embedValues)
            where TDoc : class
            where TCursor : class
        {
            bool multiple_params  = mValueIds.Length > 1;
            bool write_extra_info = s.IsWriting && model.TagElementStreamSerializeFlags.HasParamFlags();

            for (int x = 0; x < mValueIds.Length; x++)
            {
                using (s.EnterCursorBookmark("Param"))
                {
                    if (write_extra_info)
                    {
                        ProtoData.ParameterList[x].WriteExtraModelInfo(model.Database, s, multiple_params, model.TagElementStreamSerializeFlags);
                    }

                    Contract.Assert(mValueIds[x].IsNotNone());
                    if (embedValues)
                    {
                        MegaloScriptValueBase.SerializeValueForEmbed(model, s, ref mValueIds[x]);
                    }
                    else
                    {
                        s.StreamCursor(ref mValueIds[x]);
                    }
                }
            }
        }
示例#8
0
        protected void SerializeFrameUpdate(MegaloScriptModel model, IO.BitStream s)
        {
            Util.MarkUnusedVariable(ref model);

            s.StreamNoneable(ref mFrameUpdateFrequency, 8);
            s.StreamNoneable(ref mFrameUpdateOffset, 8);
        }
示例#9
0
 protected void SerializeReferences <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s)
     where TDoc : class
     where TCursor : class
 {
     using (s.EnterCursorBookmark("Elements"))
         References.Serialize(model, s);
 }
示例#10
0
        public override void Serialize(MegaloScriptModel model, IO.BitStream s)
        {
            base.Serialize(model, s);

            model.Database.ObjectReferenceWithPlayerVarIndex.StreamPlayerVarIndex(s, ref mPlayerVarIndex,
                                                                                  Var.Type, model);
        }
示例#11
0
        protected override void SerializeValue <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s)
        {
            if ((model.TagElementStreamSerializeFlags & MegaloScriptModelTagElementStreamFlags.EmbedObjects) != 0)
            {
                using (s.EnterCursorBookmark("VT"))                 // have to nest or MegaloScriptModelObjectHandle will overwrite our Param ID with the VT's
                    MegaloScriptModelObjectHandle.SerializeForEmbed(s, model, ref mVirtualTriggerHandle);
            }
            else
            {
                if (s.IsReading)
                {
                    int id = TypeExtensions.kNone; s.ReadCursor(ref id);
                    if (id < 0)
                    {
                        throw new System.IO.InvalidDataException(string.Format(Util.InvariantCultureInfo,
                                                                               "VirtualTrigger value #{0} has an invalid value {1}", Id, id));
                    }

                    mVirtualTriggerHandle = model.VirtualTriggers[id].Handle;
                }
                else
                {
                    s.WriteCursor(VirtualTriggerHandle.Id);
                }
            }
        }
        /// <summary>Model helper only: Initialize the core properties of a variable reference</summary>
        /// <param name="model"></param>
        /// <param name="result">The initialized variable reference</param>
        /// <param name="refKind">The kind of variable reference to create</param>
        /// <param name="refTypeMember">Returns the proto member we've initialized the result to</param>
        /// <param name="refMemberName">The specific member of the variable reference to initialize to</param>
        /// <param name="dataTypeName">Only used if the reference member has a data type property</param>
        internal static void Initialize(MegaloScriptModel model,
                                        out MegaloScriptVariableReferenceData result, MegaloScriptVariableReferenceType refKind,
                                        out Proto.MegaloScriptProtoVariableReferenceMember refTypeMember,
                                        string refMemberName, string dataTypeName = null)
        {
            result.mReferenceKind = refKind;

            var protoType = model.Database.VariableRefTypes[refKind];

            result.Type = MegaloScriptVariableReferenceData.ToMemberIndex(protoType, refMemberName);

            refTypeMember = protoType.Members[result.Type];
            if (refTypeMember.HasDataType)
            {
                Contract.Assert(dataTypeName != null, "Reference type uses a data type parameter, but one wasn't defined");
                var id_resolving_ctxt = new Proto.MegaloScriptEnum.EnumNameResolvingContext(model.Database, refTypeMember.EnumValueType);
                result.DataType = Proto.MegaloScriptEnum.EnumNameResolvingContext.IdResolver(id_resolving_ctxt, dataTypeName);
            }
            else
            {
                result.DataType = TypeExtensions.kNone;
            }

            result.Data = TypeExtensions.kNone;
        }
        void SerializeData(MegaloScriptModel model, IO.BitStream s, Proto.MegaloScriptValueType valueType)
        {
            var base_type = valueType.BaseType;

            switch (base_type)
            {
            case Proto.MegaloScriptValueBaseType.Int:
                s.Stream(ref Data, valueType.BitLength, signExtend: true);
                break;

            case Proto.MegaloScriptValueBaseType.UInt:
            case Proto.MegaloScriptValueBaseType.Var:
                s.Stream(ref Data, valueType.BitLength);
                break;

            case Proto.MegaloScriptValueBaseType.Enum:
                MegaloScriptEnumValue.SerializeValue(model, s, valueType, ref Data);
                break;

            case Proto.MegaloScriptValueBaseType.Index:
                MegaloScriptIndexValue.SerializeValue(model, s, valueType, ref Data);
                break;

            default: throw new KSoft.Debug.UnreachableException(base_type.ToString());
            }
        }
示例#14
0
        public override void Serialize(MegaloScriptModel model, IO.BitStream s)
        {
            s.Stream(ref mShapeType, 2, MegaloScriptShapeTypeBitStreamer.Instance);

            switch (ShapeType)
            {
            case MegaloScriptShapeType.Sphere:
                mRadius.SerializeCustom(model, s);
                break;

            case MegaloScriptShapeType.Cylinder:
                mRadius.SerializeCustom(model, s);
                mTop.SerializeCustom(model, s);
                mBottom.SerializeCustom(model, s);
                break;

            case MegaloScriptShapeType.Box:
                mRadius.SerializeCustom(model, s);
                mLength.SerializeCustom(model, s);
                mTop.SerializeCustom(model, s);
                mBottom.SerializeCustom(model, s);
                break;

            case MegaloScriptShapeType.None: break;

            default: throw new KSoft.Debug.UnreachableException(ShapeType.ToString());
            }
        }
示例#15
0
        int FromVariableIndexName(MegaloScriptVariableType type, string name)
        {
            int id = TypeExtensionsBlam.IndexOfByPropertyNotFoundResult;

            switch (type)
            {
            case MegaloScriptVariableType.Numeric:  id = MegaloScriptModel.FindNameIndex(Numerics, name); break;

            case MegaloScriptVariableType.Timer:    id = MegaloScriptModel.FindNameIndex(Timers, name); break;

            case MegaloScriptVariableType.Team:             id = MegaloScriptModel.FindNameIndex(Teams, name); break;

            case MegaloScriptVariableType.Player:   id = MegaloScriptModel.FindNameIndex(Players, name); break;

            case MegaloScriptVariableType.Object:   id = MegaloScriptModel.FindNameIndex(Objects, name); break;

            default: throw new KSoft.Debug.UnreachableException(type.ToString());
            }

            if (id == TypeExtensionsBlam.IndexOfByPropertyNotFoundResult)
            {
                throw new KeyNotFoundException(string.Format("Couldn't find {0} {1} variable named {2}",
                                                             SetType, type, name));
            }

            return(id);
        }
示例#16
0
 public void ChangeValue(MegaloScriptModel model,
                         MegaloScriptVariableReferenceData playerData, MegaloScriptVariableReferenceData playerAddOrRemoveData)
 {
     FilterType        = MegaloScriptPlayerFilterType.PlayerMask;
     Player            = playerData;
     PlayerAddOrRemove = playerAddOrRemoveData;
 }
示例#17
0
        protected override void SerializeValue <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s)
        {
            using (s.EnterCursorBookmark("Object"))
                base.SerializeValue(model, s);

            model.Database.ObjectReferenceWithPlayerVarIndex.StreamPlayerVarIndex(s, ref mPlayerVarIndex,
                                                                                  Var.Type, model);
        }
示例#18
0
        public override MegaloScriptValueBase Copy(MegaloScriptModel model)
        {
            var result = (MegaloScriptVarReferenceValue)model.CreateValue(ValueType);

            CopyVarTo(result);

            return(result);
        }
示例#19
0
        public override MegaloScriptValueBase Copy(MegaloScriptModel model)
        {
            var result = (MegaloScriptVirtualTriggerValue)model.CreateValue(ValueType);

            result.VirtualTriggerHandle = VirtualTriggerHandle;

            return(result);
        }
示例#20
0
        public void ChangeValue(MegaloScriptModel model, MegaloScriptPlayerFilterType filterType)
        {
            Contract.Requires(filterType != MegaloScriptPlayerFilterType.PlayerMask, "Wrong ChangeValue overload");

            FilterType        = filterType;
            Player            = MegaloScriptVariableReferenceData.Player;
            PlayerAddOrRemove = MegaloScriptVariableReferenceData.Custom;
        }
示例#21
0
        internal void InitializeForType(MegaloScriptModel model, string actionType)
        {
            var proto_action = model.Database.GetAction(actionType);

            ProtoData = proto_action;
            NotifyPropertyChanged(kProtoDataChanged);
            Arguments = new MegaloScriptArguments(model, ProtoData);
        }
示例#22
0
        public override MegaloScriptValueBase Copy(MegaloScriptModel model)
        {
            var result = (MegaloScriptIndexValue)model.CreateValue(ValueType);

            result.Value = Value;

            return(result);
        }
示例#23
0
        public void ChangeValue(MegaloScriptModel model, string varName)
        {
            Contract.Requires(!string.IsNullOrEmpty(varName));

            var id_resolving_ctxt = new MegaloScriptModelVariableSet.IndexNameResolvingContext(model, ValueType);

            Value = MegaloScriptModelVariableSet.IndexNameResolvingContext.IdResolver(id_resolving_ctxt, varName);
        }
示例#24
0
        protected virtual int SerializeImpl(MegaloScriptModel model, IO.BitStream s)
        {
            int type = s.IsReading ? TypeExtensions.kNone : ProtoData.DBID;

            model.Database.StreamActionType(s, ref type);

            return(type);
        }
示例#25
0
 public void Serialize(MegaloScriptModel model, IO.BitStream s)
 {
     s.StreamElements(Numerics, ProtoData.Traits[MegaloScriptVariableType.Numeric].CountBitLength, model, _model => _model.NewCustomVariable());
     s.StreamElements(Timers, ProtoData.Traits[MegaloScriptVariableType.Timer].CountBitLength, model, _model => _model.NewTimerVariable());
     s.StreamElements(Teams, ProtoData.Traits[MegaloScriptVariableType.Team].CountBitLength, model, _model => _model.NewTeamVariable());
     s.StreamElements(Players, ProtoData.Traits[MegaloScriptVariableType.Player].CountBitLength, model, _model => _model.NewPlayerVariable());
     s.StreamElements(Objects, ProtoData.Traits[MegaloScriptVariableType.Object].CountBitLength, model, _model => _model.NewObjectVariable());
 }
示例#26
0
        internal void InitializeForType(MegaloScriptModel model, int actionType)
        {
            Contract.Requires(actionType >= 0 && actionType < model.Database.Actions.Count);

            ProtoData = model.Database.Actions[actionType];
            NotifyPropertyChanged(kProtoDataChanged);
            Arguments = new MegaloScriptArguments(model, ProtoData);
        }
示例#27
0
        public void ChangeValue(MegaloScriptModel model, string flags)
        {
            //Contract.Requires(!string.IsNullOrEmpty(flags)); // #NOTE_BLAM: we assume null/empty means '0'

            var id_resolving_ctxt = new Proto.MegaloScriptEnum.FlagsNameResolvingContext(model.Database, ValueType);

            Value = Proto.MegaloScriptEnum.FlagsNameResolvingContext.IdResolver(id_resolving_ctxt, flags);
        }
 public override void Serialize(MegaloScriptModel model, IO.BitStream s)
 {
     s.Stream(ref mIconType, 5, NavpointIconTypeBitStreamer.Instance);
     if (mIconType == MegaloScriptNavpointIconType.Territory)
     {
         mNumeric.SerializeCustom(model, s);
     }
 }
        internal void SerializeTimer <TDoc, TCursor>(MegaloScriptModel model, IO.TagElementStream <TDoc, TCursor, string> s)
            where TDoc : class
            where TCursor : class
        {
            mReferenceKind = MegaloScriptVariableReferenceType.Timer;

            Serialize(model, s, model.Database.VariableRefTypes[mReferenceKind]);
        }
示例#30
0
        public void ChangeValue(MegaloScriptModel model, string enumMemberName)
        {
            Contract.Requires(!string.IsNullOrEmpty(enumMemberName));

            var id_resolving_ctxt = new Proto.MegaloScriptEnum.EnumNameResolvingContext(model.Database, ValueType);

            Value = Proto.MegaloScriptEnum.EnumNameResolvingContext.IdResolver(id_resolving_ctxt, enumMemberName);
        }