Beispiel #1
0
        /// <summary>
        /// The user clicked on an item in the list of languages and strings.
        /// </summary>
        private void LstWallLanguages_MouseClick(object sender, MouseEventArgs e)
        {
            LblWallPrice.Visible = true;
            LblWallName.Visible  = true;

            //A floor or wall has only 1 string table.
            STR StringTable = m_CurrentIff.StringTables[0];

            foreach (ListViewItem Item in LstWallLanguages.Items)
            {
                //We only support selecting one item at a time.
                if (Item.Selected)
                {
                    TxtWallName.Visible = true;
                    TxtWallName.Clear();

                    TxtWallPrice.Visible = true;
                    TxtWallPrice.Clear();

                    TxtWallStrings.Visible = true;
                    TxtWallStrings.Clear();

                    LanguageCodes SelectedCode = (LanguageCodes)Enum.Parse(typeof(LanguageCodes), Item.Text);
                    m_CurrentLanguage   = SelectedCode;
                    TxtWallName.Text    = StringTable.GetString(SelectedCode, ObjectStringIndices.Name);
                    TxtWallPrice.Text   = StringTable.GetString(SelectedCode, ObjectStringIndices.Price);
                    TxtWallStrings.Text = StringTable.GetString(SelectedCode, ObjectStringIndices.Description);
                }
            }
        }
Beispiel #2
0
        public void SetAvatarType(STR data)
        {
            if (data == null)
            {
                AvatarType = VMAvatarType.Adult;
            }
            else
            {
                var type = data.GetString(0);
                if (type == "adult")
                {
                    AvatarType = VMAvatarType.Adult;
                }
                else if (type == "child")
                {
                    AvatarType = VMAvatarType.Child;
                }
                else if (type == "cat")
                {
                    AvatarType = VMAvatarType.Cat;
                }
                else if (type == "dog")
                {
                    AvatarType = VMAvatarType.Dog;
                }
            }

            Avatar = new SimAvatar(FSO.Content.Content.Get().AvatarSkeletons.Get(data.GetString(0) + ".skel"));
            if (UseWorld)
            {
                switch (AvatarType)
                {
                case VMAvatarType.Adult:
                    Avatar.Head      = FSO.Content.Content.Get().AvatarOutfits.Get(0x000003a00000000D); //default to bob newbie, why not
                    Avatar.Body      = FSO.Content.Content.Get().AvatarOutfits.Get("mab002_slob.oft");
                    Avatar.Handgroup = Avatar.Body;
                    break;

                case VMAvatarType.Cat:
                    Avatar.Body = FSO.Content.Content.Get().AvatarOutfits.Get("uaa002cat_calico.oft");
                    break;

                case VMAvatarType.Dog:
                    Avatar.Body = FSO.Content.Content.Get().AvatarOutfits.Get("uaa012dog_scottish.oft");     //;)
                    break;

                case VMAvatarType.Child:
                    break;
                }
            }
        }
Beispiel #3
0
        public VMAvatar(GameObject obj)
            : base(obj)
        {
            PlatformState = new VMTSOAvatarState(); //todo: ts1 switch
            BodyStrings   = Object.Resource.Get <STR>(Object.OBJ.BodyStringID);

            SetAvatarType(BodyStrings);
            SkinTone = AppearanceType.Light;

            if (UseWorld)
            {
                WorldUI = new AvatarComponent();
                var avatarc = (AvatarComponent)WorldUI;
                avatarc.Avatar = Avatar;
                var type = BodyStrings.GetString(0);
                if (type != "adult" && type != "child")
                {
                    avatarc.IsPet = true;
                }
            }


            MotiveDecay = new VMAvatarMotiveDecay();
            for (int i = 0; i < 16; i++)
            {
                MotiveChanges[i]        = new VMMotiveChange();
                MotiveChanges[i].Motive = (VMMotive)i;
            }
        }
        private void StringList_SelectedIndexChanged(object sender,EventArgs e)
        {
            //change selected string
            var ind = SelectedStringInd;

            bool enableMod = (ind != -1);

            RemoveButton.Enabled = enableMod;
            UpButton.Enabled     = enableMod;
            DownButton.Enabled   = enableMod;
            NameBox.Enabled      = enableMod;

            OwnChange = true;
            if (ind == -1)
            {
                ActiveItem   = null;
                NameBox.Text = "";
            }
            else
            {
                ActiveItem      = ActiveSLOT.Chronological[ind];
                NameBox.Enabled = (ActiveSLOTLabel != null);
                NameBox.Text    = ActiveSLOTLabel?.GetString(ind) ?? "";
            }
            UpdateSLOTItem();
            OwnChange = false;
        }
Beispiel #5
0
 public OpStaticNamedPropertyProvider(STR strRes, int startValue)
 {
     Map = new Dictionary <int, string>();
     for (int i = 0; i < strRes.Length; i++)
     {
         Map.Add(i + startValue, strRes.GetString(i));
     }
 }
Beispiel #6
0
        /// <summary>
        /// Get an animation
        /// </summary>
        /// <param name="scope"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Animation GetAnimation(VMStackFrame context, VMAnimationScope scope, ushort id)
        {
            STR  animTable = null;
            bool child     = ((VMAvatar)context.Caller).GetPersonData(VMPersonDataVariable.PersonsAge) < 18 && context.VM.TS1;

            //a2o, c2o, a2c, c2a

            switch (scope)
            {
            case VMAnimationScope.Object:
                var obj        = context.CodeOwner;
                var anitableID = (ushort)(obj.OBJ.AnimationTableID + (child ? 1 : 0));
                animTable = obj.Resource.Get <STR>(anitableID);
                if (animTable == null)
                {
                    animTable = obj.Resource.Get <STR>((ushort)(child ? 130 : 129));
                }
                break;

            case VMAnimationScope.Misc:
                animTable = context.Global.Resource.Get <STR>((ushort)(child ? 157 : 156));
                break;

            case VMAnimationScope.PersonStock:
                animTable = context.Global.Resource.Get <STR>(130);
                break;

            case VMAnimationScope.Global:
                animTable = context.Global.Resource.Get <STR>(128);
                break;

            case VMAnimationScope.StackObject:
                var obj2        = context.StackObject.Object;
                var anitableID2 = (ushort)(obj2.OBJ.AnimationTableID + (child ? 1 : 0));
                animTable = obj2.Resource.Get <STR>(anitableID2);
                if (animTable == null)
                {
                    animTable = obj2.Resource.Get <STR>((ushort)(child ? 130 : 129));
                }
                break;
            }

            if (animTable == null)
            {
                return(null);
            }

            var animationName = animTable.GetString(id);

            if (animationName != null)
            {
                return(FSO.Content.Content.Get().AvatarAnimations.Get(animationName + ".anim"));
            }
            else
            {
                return(null);
            }
        }
Beispiel #7
0
 public void UpdateStrings()
 {
     StringList.SelectedItems.Clear();
     StringList.Items.Clear();
     for (int i = 0; i < ActiveString.Length; i++)
     {
         StringList.Items.Add(new ListViewItem(new string[] { Convert.ToString(i), ActiveString.GetString(i, ActiveLanguage) }));
     }
     StringList_SelectedIndexChanged(StringList, new EventArgs());
 }
Beispiel #8
0
        private List <ScopeDataDefinition> DataListFromSTR(STR strings, short startValue, string[] descriptions)
        {
            var result = new List <ScopeDataDefinition>();

            for (int i = 0; i < strings.Length; i++)
            {
                result.Add(new ScopeDataDefinition(strings.GetString(i), startValue++, (descriptions == null)?"No Description Available.":descriptions[i]));
            }
            return(result);
        }
Beispiel #9
0
 public VMOutfitReference(STR str, bool head)
 {
     OftData = new Outfit();
     if (head)
     {
         OftData.ReadHead(str.GetString(2));
     }
     else
     {
         OftData.Read(str);
     }
 }
        public static string GetAnimationName(EditorScope escope, VMAnimationScope scope, ushort id)
        {
            STR animTable = GetAnimTable(escope, scope);

            if (animTable == null)
            {
                return("Unknown animation (bad source)");
            }

            var animationName = animTable.GetString(id);

            return((animationName == null)?"Unknown animation #" + id:animationName);
        }
        public void SetAvatarType(STR data)
        {
            if (data == null)
            {
                AvatarType = VMAvatarType.Adult;
            }
            else
            {
                var type = data.GetString(0);
                if (type == "adult")
                {
                    AvatarType = VMAvatarType.Adult;
                }
                else if (type == "child")
                {
                    AvatarType = VMAvatarType.Child;
                }
                else if (type == "cat")
                {
                    AvatarType = VMAvatarType.Cat;
                }
                else if (type == "dog")
                {
                    AvatarType = VMAvatarType.Dog;
                }
            }



            switch (AvatarType)
            {
            case VMAvatarType.Adult:
                Avatar           = new SimAvatar(FSO.Content.Content.Get().AvatarSkeletons.Get("adult.skel"));
                Avatar.Head      = FSO.Content.Content.Get().AvatarOutfits.Get(SetAvatarRandomOutfit(1));
                Avatar.Body      = FSO.Content.Content.Get().AvatarOutfits.Get(SetAvatarRandomOutfit(0));
                Avatar.Handgroup = Avatar.Body;

                break;

            case VMAvatarType.Cat:
                var skel = FSO.Content.Content.Get().AvatarSkeletons.Get("cat.skel");
                Avatar      = new SimAvatar(skel);
                Avatar.Body = FSO.Content.Content.Get().AvatarOutfits.Get("uaa002cat_calico.oft");
                break;

            case VMAvatarType.Dog:
                Avatar      = new SimAvatar(FSO.Content.Content.Get().AvatarSkeletons.Get("dog.skel"));
                Avatar.Body = FSO.Content.Content.Get().AvatarOutfits.Get("uaa012dog_scottish.oft");     //;)
                break;
            }
        }
        public override VMPrimitiveExitCode Execute(VMStackFrame context, VMPrimitiveOperand args)
        {
            var operand = (VMRunTreeByNameOperand)args;
            if (context.StackObject == null) return VMPrimitiveExitCode.GOTO_FALSE;

            string name;
            STR res = null;
            if (operand.StringScope == 1)
            {//global
                res = context.Global.Resource.Get<STR>(operand.StringTable);
            }
            else
            {//local
                if (context.Routine.ID >= 8192 && context.ScopeResource.SemiGlobal != null) res = context.ScopeResource.SemiGlobal.Get<STR>(operand.StringTable);
                if (res == null) res = context.ScopeResource.Get<STR>(operand.StringTable); 
            }
            if (res == null) return VMPrimitiveExitCode.GOTO_FALSE;
            name = res.GetString(operand.StringID-1);

            if (context.StackObject.TreeByName == null) return VMPrimitiveExitCode.GOTO_FALSE;
            if (context.StackObject.TreeByName.ContainsKey(name))
            {
                var tree = context.StackObject.TreeByName[name];

                if (operand.Destination == 2)
                {
                    context.Thread.ExecuteSubRoutine(context, tree.bhav, context.StackObject.Object, new VMSubRoutineOperand(context.Thread.TempRegisters));
                    return VMPrimitiveExitCode.CONTINUE;
                    //push onto my stack - acts like a subroutine.
                }
                else if (operand.Destination == 0)
                {
                    return context.Caller.Thread.RunInMyStack(tree.bhav, context.StackObject.Object, context.Thread.TempRegisters, context.StackObject)
                        ? VMPrimitiveExitCode.GOTO_TRUE : VMPrimitiveExitCode.GOTO_FALSE;
                    //run in my stack
                }
                else
                {
                    return context.StackObject.Thread.RunInMyStack(tree.bhav, context.StackObject.Object, context.Thread.TempRegisters, context.StackObject)
                        ? VMPrimitiveExitCode.GOTO_TRUE : VMPrimitiveExitCode.GOTO_FALSE;
                    //run in stack obj's stack
                }
                //found it! now lets call the tree ;)
            }
            else
            {
                return VMPrimitiveExitCode.GOTO_FALSE;
            }
        }
        private TS1Curve[] CurveFromSTR(STR str, bool cache)
        {
            var length = str.Length;
            var result = new TS1Curve[length];

            for (int i = 0; i < length; i++)
            {
                result[i] = new TS1Curve(str.GetString(i));
                if (cache)
                {
                    result[i].BuildCache(-100, 100);
                }
            }
            return(result);
        }
        public void SetAvatarType(STR data)
        {
            if (data == null)
            {
                AvatarType = VMAvatarType.Adult;
            }
            else
            {
                var type = data.GetString(0);
                if (type == "adult")
                {
                    AvatarType = VMAvatarType.Adult;
                }
                else if (type == "child")
                {
                    AvatarType = VMAvatarType.Child;
                }
                else if (type == "cat")
                {
                    AvatarType = VMAvatarType.Cat;
                }
                else if (type == "dog")
                {
                    AvatarType = VMAvatarType.Dog;
                }
            }

            switch (AvatarType)
            {
            case VMAvatarType.Adult:
                Avatar           = new SimAvatar(TSO.Content.Content.Get().AvatarSkeletons.Get("adult.skel"));
                Avatar.Head      = TSO.Content.Content.Get().AvatarOutfits.Get("mah010_baldbeard01.oft"); //default to bob newbie, why not
                Avatar.Body      = TSO.Content.Content.Get().AvatarOutfits.Get("mab002_slob.oft");
                Avatar.Handgroup = Avatar.Body;
                break;

            case VMAvatarType.Cat:
                var skel = TSO.Content.Content.Get().AvatarSkeletons.Get("cat.skel");
                Avatar      = new SimAvatar(skel);
                Avatar.Body = TSO.Content.Content.Get().AvatarOutfits.Get("uaa002cat_calico.oft");
                break;

            case VMAvatarType.Dog:
                Avatar      = new SimAvatar(TSO.Content.Content.Get().AvatarSkeletons.Get("dog.skel"));
                Avatar.Body = TSO.Content.Content.Get().AvatarOutfits.Get("uaa012dog_scottish.oft");     //;)
                break;
            }
        }
Beispiel #15
0
 public void UpdateStrings()
 {
     StringList.SelectedItems.Clear();
     StringList.Items.Clear();
     for (int i = 0; i < ActiveSLOT.Chronological.Count; i++)
     {
         var type = ActiveSLOT.Chronological[i].Type;
         StringList.Items.Add(new ListViewItem(new string[] {
             Convert.ToString(i),
             (ActiveSLOTLabel == null) ? "SLOT" : ActiveSLOTLabel.GetString(i),
             SLOTTypes.FirstOrDefault(x => x.Value == type)?.Name ?? type.ToString(),
             (ActiveSLOTLabel == null) ? "" : ActiveSLOTLabel.GetComment(i)
         }));
     }
     StringList_SelectedIndexChanged(StringList,new EventArgs());
 }
Beispiel #16
0
        public void RefreshAnimTable()
        {
            InternalChange = true;

            MyList.Items.Clear();
            if (AnimTable != null)
            {
                for (int i = 0; i < AnimTable.Length; i++)
                {
                    MyList.Items.Add((i == 0) ? "Stop Animation" : AnimTable.GetString(i, STRLangCode.EnglishUS));
                }

                MyList.SelectedItem = SelectedAnim;
            }

            InternalChange = false;
        }
Beispiel #17
0
        /// <summary>
        /// Get an animation
        /// </summary>
        /// <param name="scope"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Animation GetAnimation(VMStackFrame context, VMAnimationScope scope, ushort id)
        {
            STR animTable = null;

            switch (scope)
            {
            case VMAnimationScope.Object:
                var obj        = context.CodeOwner;
                var anitableID = obj.OBJ.AnimationTableID;
                animTable = obj.Resource.Get <STR>(anitableID);
                if (animTable == null)
                {
                    animTable = obj.Resource.Get <STR>(129);
                }
                break;

            case VMAnimationScope.Misc:
                animTable = context.Global.Resource.Get <STR>(156);
                break;

            case VMAnimationScope.PersonStock:
                animTable = context.Global.Resource.Get <STR>(130);
                break;

            case VMAnimationScope.Global:
                animTable = context.Global.Resource.Get <STR>(128);
                break;
            }

            if (animTable == null)
            {
                return(null);
            }

            var animationName = animTable.GetString(id);

            if (animationName != null)
            {
                return(FSO.Content.Content.Get().AvatarAnimations.Get(animationName + ".anim"));
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// Get an animation
        /// </summary>
        /// <param name="scope"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Animation GetAnimation(VMStackFrame context, VMAnimationScope scope, ushort id)
        {
            STR animTable = null;

            switch (scope)
            {
            case VMAnimationScope.Object:
                var obj        = context.Callee.Object;
                var anitableID = obj.OBJ.AnimationTableID;
                anitableID = 129;

                /*
                 * Fridge has an animtable of 0
                 * if (anitableID == 0){
                 *  return null;
                 * }*/
                //if (anitableID == 0){
                //    anitableID = 129;
                //}
                //129
                animTable = obj.Resource.Get <STR>(anitableID);
                break;

            case VMAnimationScope.Misc:
                animTable = context.Global.Resource.Get <STR>(156);
                break;

            case VMAnimationScope.PersonStock:
                animTable = context.Global.Resource.Get <STR>(130);
                break;

            case VMAnimationScope.Global:
                animTable = context.Global.Resource.Get <STR>(128);
                break;
            }

            if (animTable == null)
            {
                return(null);
            }

            var animationName = animTable.GetString(id);

            return(TSO.Content.Content.Get().AvatarAnimations.Get(animationName + ".anim"));
        }
        public static void ShowDialog(VMStackFrame context, VMDialogOperand operand, STR source)
        {
            VMDialogInfo info = new VMDialogInfo
            {
                Block    = (operand.Flags & VMDialogFlags.Continue) == 0,
                Caller   = context.Caller,
                Icon     = context.StackObject,
                Operand  = operand,
                Message  = ParseDialogString(context, source.GetString(Math.Max(0, operand.MessageStringID - 1)), source),
                Title    = (operand.TitleStringID == 0) ? "" : ParseDialogString(context, source.GetString(operand.TitleStringID - 1), source),
                IconName = (operand.IconNameStringID == 0) ? "" : ParseDialogString(context, source.GetString(operand.IconNameStringID - 1), source),

                Yes    = (operand.YesStringID == 0) ? null : ParseDialogString(context, source.GetString(operand.YesStringID - 1), source),
                No     = (operand.NoStringID == 0) ? null : ParseDialogString(context, source.GetString(operand.NoStringID - 1), source),
                Cancel = (operand.CancelStringID == 0) ? null : ParseDialogString(context, source.GetString(operand.CancelStringID - 1), source),
            };

            context.VM.SignalDialog(info);
        }
Beispiel #20
0
        public override VMPrimitiveExitCode Execute(VMStackFrame context, VMPrimitiveOperand args)
        {
            var operand = (VMChangeActionStringOperand)args;
            STR table   = null;

            switch (operand.Scope)
            {
            case 0:
                table = context.ScopeResource.Get <STR>(operand.StringTable);
                break;

            case 1:
                table = context.Callee.SemiGlobal.Get <STR>(operand.StringTable);
                break;

            case 2:
                table = context.Global.Resource.Get <STR>(operand.StringTable);
                break;
            }

            if (table != null)
            {
                var newName = VMDialogHandler.ParseDialogString(context, table.GetString(operand.StringID - 1), table);
                if (context.Thread.IsCheck && context.Thread.ActionStrings != null)
                {
                    context.Thread.ActionStrings.Add(new VMPieMenuInteraction()
                    {
                        Name   = newName,
                        Param0 = context.StackObjectID
                    });
                }
                else
                {
                    context.Thread.ActiveAction.Name = newName;
                }
            }
            return(VMPrimitiveExitCode.GOTO_TRUE);
        }
        public void Read(STR bodyStrings)
        {
            var bodies = bodyStrings.GetString(1).Split(';');

            TS1AppearanceID = ToApr(bodies.FirstOrDefault());
            TS1TextureID    = ToTex(bodies.FirstOrDefault());

            LiteralHandgroup = new HandGroup()
            {
                //TS1HandSet = true,
                LightSkin = new HandSet()
                {
                    LeftHand = new Hand()
                    {
                        Idle = new Gesture()
                        {
                            Name = ToApr(bodyStrings.GetString(17)), TexName = ToTex(bodyStrings.GetString(17))
                        },
                        Pointing = new Gesture()
                        {
                            Name = ToApr(bodyStrings.GetString(19)), TexName = ToTex(bodyStrings.GetString(19))
                        },
                        Fist = new Gesture()
                        {
                            Name = ToApr(bodyStrings.GetString(21)), TexName = ToTex(bodyStrings.GetString(21))
                        }
                    },
                    RightHand = new Hand()
                    {
                        Idle = new Gesture()
                        {
                            Name = ToApr(bodyStrings.GetString(18)), TexName = ToTex(bodyStrings.GetString(18))
                        },
                        Pointing = new Gesture()
                        {
                            Name = ToApr(bodyStrings.GetString(20)), TexName = ToTex(bodyStrings.GetString(20))
                        },
                        Fist = new Gesture()
                        {
                            Name = ToApr(bodyStrings.GetString(22)), TexName = ToTex(bodyStrings.GetString(22))
                        }
                    }
                }
            };
        }
 public void ReadHead(STR bodyStrings)
 {
     TS1AppearanceID = ToApr(bodyStrings.GetString(2));
     TS1TextureID    = ToTex(bodyStrings.GetString(2));
 }
        public void SetAvatarBodyStrings(STR data, VMContext context)
        {
            if (data == null)
            {
                return;
            }

            var body     = data.GetString(1);
            var randBody = data.GetString(10);

            var gender = data.GetString(12);
            var genVar = (int)VMPersonDataVariable.Gender;

            try
            {
                if (randBody != "")
                {
                    var bodySpl = randBody.Split(';');
                    DefaultSuits.Daywear = Convert.ToUInt64(bodySpl[context.NextRandom((ulong)bodySpl.Length - 1)], 16);
                }
                else if (body != "")
                {
                    DefaultSuits.Daywear = Convert.ToUInt64(body, 16);
                }

                BodyOutfit = DefaultSuits.Daywear;

                var head     = data.GetString(2);
                var randHead = data.GetString(9);

                if (randHead != "")
                {
                    var headSpl = randHead.Split(';');
                    HeadOutfit = Convert.ToUInt64(headSpl[context.NextRandom((ulong)headSpl.Length - 1)], 16);
                }
                else if (head != "")
                {
                    HeadOutfit = Convert.ToUInt64(head, 16);
                }
            }
            catch
            {
                //head or body invalid, resort to default.
                HeadOutfit = SetAvatarRandomOutfit(1);
                BodyOutfit = SetAvatarRandomOutfit(0);
            }


            if (gender.Equals("male", StringComparison.InvariantCultureIgnoreCase))
            {
                PersonData[genVar] = 0;
            }
            else if (gender.Equals("female", StringComparison.InvariantCultureIgnoreCase))
            {
                PersonData[genVar] = 1;
            }
            else if (gender.Equals("dogmale", StringComparison.InvariantCultureIgnoreCase))
            {
                PersonData[genVar] = 8;
            }
            else if (gender.Equals("dogfemale", StringComparison.InvariantCultureIgnoreCase))
            {
                PersonData[genVar] = 9;
            }
            else if (gender.Equals("catmale", StringComparison.InvariantCultureIgnoreCase))
            {
                PersonData[genVar] = 16;
            }
            else if (gender.Equals("catfemale", StringComparison.InvariantCultureIgnoreCase))
            {
                PersonData[genVar] = 17;
            }

            var names = data.GetString(11);

            if (names != "")
            {
                var nameSpl = names.Split(';');
                Name = nameSpl[context.NextRandom((ulong)nameSpl.Length)];
            }

            PersonData[(int)VMPersonDataVariable.PersonsAge] = Convert.ToInt16(data.GetString(13));

            var skinTone = data.GetString(14);

            if (skinTone.Equals("lgt", StringComparison.InvariantCultureIgnoreCase))
            {
                SkinTone = AppearanceType.Light;
            }
            else if (skinTone.Equals("med", StringComparison.InvariantCultureIgnoreCase))
            {
                SkinTone = AppearanceType.Medium;
            }
            else if (skinTone.Equals("drk", StringComparison.InvariantCultureIgnoreCase))
            {
                SkinTone = AppearanceType.Dark;
            }
        }
Beispiel #24
0
        public static object GetSuit(VMStackFrame context, VMSuitScope scope, ushort id)
        {
            STR suitTable = null;

            var avatar = (VMAvatar)context.Caller;

            switch (scope)
            {
            case VMSuitScope.Object:
                suitTable = context.CodeOwner.Resource.Get <STR>(304);
                break;

            case VMSuitScope.Global:
                suitTable = context.Global.Resource.Get <STR>(304);
                break;

            case VMSuitScope.Person:
                //get outfit from person
                if (context.VM.TS1)
                {
                    return(GetPersonSuitTS1((VMAvatar)context.Caller, id));
                }

                var  type = (VMPersonSuits)id;
                bool male = (avatar.GetPersonData(VMPersonDataVariable.Gender) == 0);
                switch (type)
                {
                //todo: (tail etc), cockroach head

                case VMPersonSuits.DefaultDaywear:
                    return(avatar.DefaultSuits.Daywear.ID);

                case VMPersonSuits.Naked:
                    return((ulong)(male ? 0x24E0000000D : 0x10000000D));

                case VMPersonSuits.DefaultSwimwear:
                    return(avatar.DefaultSuits.Swimwear.ID);

                case VMPersonSuits.JobOutfit:
                    if (context.VM.TS1)
                    {
                        return(null);
                    }
                    var job = avatar.GetPersonData(VMPersonDataVariable.OnlineJobID);
                    if (job < 1 || job > 5)
                    {
                        return(null);
                    }
                    var level = Math.Max(0, Math.Min(3, (avatar.GetPersonData(VMPersonDataVariable.OnlineJobGrade) - 1) / 4));
                    return((ulong)(JobOutfits[male?0:1][job - 1][level]));

                case VMPersonSuits.DefaultSleepwear:
                    return(avatar.DefaultSuits.Sleepwear.ID);

                case VMPersonSuits.SkeletonPlus:
                    return((ulong)(0x5750000000D));

                case VMPersonSuits.SkeletonMinus:
                    return((ulong)(0x5740000000D));

                case VMPersonSuits.TeleporterMishap:
                    return((ulong)(male ? 0x2900000000D : 0x4A0000000D));


                case VMPersonSuits.DynamicDaywear:
                    return(avatar.DynamicSuits.Daywear);

                case VMPersonSuits.DynamicSleepwear:
                    return(avatar.DynamicSuits.Sleepwear);

                case VMPersonSuits.DynamicSwimwear:
                    return(avatar.DynamicSuits.Swimwear);

                case VMPersonSuits.DynamicCostume:
                    return(avatar.DynamicSuits.Costume);

                case VMPersonSuits.DecorationHead:
                    return(avatar.Decoration.Head);

                case VMPersonSuits.DecorationBack:
                    return(avatar.Decoration.Back);

                case VMPersonSuits.DecorationShoes:
                    return(avatar.Decoration.Shoes);

                case VMPersonSuits.DecorationTail:
                    return(avatar.Decoration.Tail);
                }

                return(null);
            }

            if (suitTable != null)
            {
                var suitFile = suitTable.GetString(id) + ".apr";

                return(suitFile);
                //var apr = FSO.Content.Content.Get().AvatarAppearances.Get(suitFile);
                //return apr;
            }
            return(null);
        }
Beispiel #25
0
        public static void SaveOBJ(string destPath, STR locations)
        {
            var exportedFlr = new HashSet <ushort>();
            var gd          = GameFacade.GraphicsDevice;
            var mtlBuilder  = new StringBuilder();

            Directory.CreateDirectory(destPath);

            //var mtlMem = new MemoryStream();
            //var mtlIO = new StreamWriter(mtlMem);
            var mtlIO = new StreamWriter(new FileStream(Path.Combine(destPath, "neighbourhood.mtl"), FileMode.Create, FileAccess.Write, FileShare.None));

            var path     = Path.Combine(destPath, "neighbourhood.obj");
            var filename = Path.GetFileNameWithoutExtension(path);

            using (var io = new StreamWriter(new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None)))
            {
                io.WriteLine("# Generated by the Simitone Neighbourhood Exporter.");
                io.WriteLine("# The purpose is to allow users to mesh neighbourhood surroundings using");
                io.WriteLine("# the projected physical positions and terrain profiles of lots as a starting point.");

                io.WriteLine("mtllib neighbourhood.mtl");
                io.WriteLine("s 1");

                int indCount = 1;
                for (int i = 0; i < locations.Length; i++)
                {
                    var loc   = locations.GetString(i).Split(',');
                    var num   = int.Parse(loc[0].TrimStart());
                    var pos2d = new Vector2(int.Parse(loc[1].TrimStart()), int.Parse(loc[2].TrimStart()));

                    var house = Content.Get().Neighborhood.GetHouse(num);

                    World world = new FSO.LotView.World(GameFacade.GraphicsDevice);

                    world.Opacity = 1;
                    GameFacade.Scenes.Add(world);

                    var globalLink = new VMTS1GlobalLinkStub();
                    var driver     = new VMServerDriver(globalLink);

                    var vm = new VM(new VMContext(world), driver, new UIHeadlineRendererProvider());
                    vm.ListenBHAVChanges();
                    vm.Init();

                    vm.SetGlobalValue(11, (short)num);

                    var activator = new VMTS1Activator(vm, vm.Context.World, (short)num);
                    var blueprint = activator.LoadFromIff(house);

                    var floorVerts = blueprint.Terrain.GetVertices(gd);
                    blueprint.FloorGeom.FullReset(gd, false);
                    var groundfloor = blueprint.FloorGeom.Floors[0];

                    //we need to calculate the
                    var minHeight = int.MaxValue;
                    var heights   = vm.Context.Architecture.Terrain.Heights;
                    for (int j = 0; j < heights.Length; j++)
                    {
                        if ((j % blueprint.Width) == 0 || (j % blueprint.Width) == blueprint.Width - 1 || j < blueprint.Width || j >= (blueprint.Height - 1) * blueprint.Width)
                        {
                            continue;
                        }
                        var h = heights[j];
                        if (h != 0 && h < minHeight)
                        {
                            minHeight = h;
                        }
                    }
                    if (minHeight == int.MaxValue)
                    {
                        minHeight = 0;
                    }
                    var scale = (locations.Length > 30 ? 1f : 2f) * 1.4142135623730950488016887242097f;
                    var baseV = new Vector3(pos2d.X + pos2d.Y * 2, 0, pos2d.Y * 2 - pos2d.X) / scale;
                    baseV.Y -= (minHeight * 3 / 160f) * 3;

                    var ctr = blueprint.GetFineBounds().Location.ToVector2() + blueprint.GetFineBounds().Size.ToVector2() / 2;

                    var voff = baseV + new Vector3(ctr.X, 0, ctr.Y) * 3f / -1;

                    voff.X = (int)(voff.X / 3) * 3;
                    voff.Z = (int)(voff.Z / 3) * 3;

                    SetOutsideTime(GameFacade.GraphicsDevice, vm, world, 0.5f, false);
                    world.State.PrepareLighting();
                    var facade = new LotFacadeGenerator();
                    facade.FLOOR_TILES        = blueprint.Width;
                    facade.GROUND_SUBDIV      = blueprint.Width;
                    facade.FLOOR_RES_PER_TILE = 4;
                    facade.LotName            = "p" + num.ToString();
                    facade.Generate(GameFacade.GraphicsDevice, world, blueprint);
                    facade.AppendOBJ(io, filename, indCount, voff / 3);
                    facade.AppendMTL(mtlIO, Path.GetDirectoryName(path));
                    indCount = facade.LastIndex;

                    /*
                     * foreach (var group in groundfloor.GroupForTileType)
                     * {
                     *  if (!exportedFlr.Contains(group.Key) && group.Key != 0 && group.Key < 65000)
                     *  {
                     *      //get and export this floor's texture. add it as a material as well.
                     *      var floor = Content.Get().WorldFloors.Get(group.Key).Near.Frames[0].GetTexture(gd);
                     *      using (var flrStream = new FileStream(Path.Combine(destPath, "flr_" + group.Key + ".png"), FileMode.Create, FileAccess.Write, FileShare.None))
                     *          floor.SaveAsPng(flrStream, floor.Width, floor.Height);
                     *
                     *      //add as material
                     *      GenerateMTL("flr_" + group.Key, mtlBuilder);
                     *  }
                     *  //write out verts and indices.
                     *
                     *
                     *  var indices = group.Value.BuildIndexData();
                     *  var done = new Dictionary<int, int>(); //index remap
                     *
                     *  if (group.Key == 0)
                     *  {
                     *      //grass... export as grass colour
                     *      io.WriteLine("usemtl " + "grass");
                     *      io.WriteLine("o " + "lot_" + num + "_grass");
                     *
                     *  }
                     *  else
                     *  {
                     *      //export with floor textured material
                     *      io.WriteLine("usemtl " + "flr_" + group.Key);
                     *      io.WriteLine("o " + "lot_" + num + "_" + group.Key);
                     *  }
                     *
                     *  var indexStr = new StringBuilder();
                     *  indexStr.Append("f ");
                     *
                     *  for (int j = 0; j < indices.Length; j++)
                     *  {
                     *      var index = indices[j];
                     *      int remapped = index;
                     *      if (!done.TryGetValue(index, out remapped))
                     *      {
                     *          remapped = indCount;
                     *          done.Add(index, indCount++);
                     *          //append a vertex
                     *          var vert = floorVerts[index];
                     *          vert.Position += voff;
                     *          io.Write("v " + vert.Position.X.ToString(CultureInfo.InvariantCulture) + " " + vert.Position.Y.ToString(CultureInfo.InvariantCulture) + " " + vert.Position.Z.ToString(CultureInfo.InvariantCulture));
                     *          io.WriteLine((group.Key == 0) ? " " + vert.Color.X.ToString(CultureInfo.InvariantCulture) + " " + vert.Color.Y.ToString(CultureInfo.InvariantCulture) + " " + vert.Color.Z.ToString(CultureInfo.InvariantCulture) : "");
                     *          io.WriteLine("vt " + vert.GrassInfo.Y.ToString(CultureInfo.InvariantCulture) + " " + (1 - vert.GrassInfo.Z).ToString(CultureInfo.InvariantCulture));
                     *      }
                     *      indexStr.Append(remapped + "/" + remapped);
                     *      if (j % 3 == 2)
                     *      {
                     *          indexStr.AppendLine();
                     *          if (j != indices.Length - 1) indexStr.Append("f ");
                     *      }
                     *      else indexStr.Append(" ");
                     *  }
                     *
                     *  io.WriteLine(indexStr);
                     * }
                     */

                    GameFacade.Scenes.Remove(world);
                    world.Dispose();
                }
            }

            mtlIO.Close();
        }