Пример #1
0
    //Create the overhead UI
    public void Overheads(string name, Color color)
    {
        this.prefab    = Resources.Load("Prefabs/Overheads") as GameObject;
        this.overheads = Instantiate(this.prefab).GetComponent <Overheads>();
        this.resources = this.overheads.resources;

        this.overheads.name   = name;
        this.overheads.color  = color;
        this.overheads.player = this;
    }
Пример #2
0
        /// <summary>
        /// Return the interest rate calculation model
        /// </summary>
        /// <param name="cashflow">The base model</param>
        public FinanceActivityCalculateInterest GetInterestRates(ActivityFolder cashflow)
        {
            // Find the interest amount
            int row = Overheads.RowNames.FindIndex(s => s == "Int_rate");

            // If the interest is 0, ignore the model
            if (Overheads.GetData <int>(row, 0) == 0)
            {
                return(null);
            }

            return(new FinanceActivityCalculateInterest(cashflow));
        }
Пример #3
0
        /// <summary>
        /// Return a collection of the annual expenses from the IAT data
        /// </summary>
        /// <param name="cashflow">The base model</param>
        public ActivityFolder GetAnnualExpenses(ActivityFolder cashflow)
        {
            var annual = new ActivityFolder(cashflow)
            {
                Name = "AnnualExpenses"
            };

            // Names of the expenses
            var rows = Overheads.RowNames;

            // Amounts of the expenses
            var amounts = Overheads.GetColData <double>(0);

            // Look at each row in the overheads table
            foreach (string row in rows)
            {
                // The overheads table contains more than just annual data,
                // so stop at the "Int_rate" row (table is ordered)
                if (row == "Int_rate")
                {
                    break;
                }

                // Find the upkeep amount
                int    index  = rows.FindIndex(s => s == row);
                double amount = amounts.ElementAt(index);

                // Only need to add the element if its a non-zero expenditure
                if (amount > 0)
                {
                    annual.Add(new FinanceActivityPayExpense(annual)
                    {
                        Name   = row.Replace("_", ""),
                        Amount = amount
                    });
                }
            }
            // If there are no annual expenses, ignore this folder
            if (annual.Children.Count == 0)
            {
                return(null);
            }
            return(annual);
        }
Пример #4
0
        /// <summary>
        /// Gets the monthly living expenses from the IAT data
        /// </summary>
        /// <param name="cashflow">The model to attach the data to</param>
        public ActivityFolder GetMonthlyExpenses(ActivityFolder cashflow)
        {
            var monthly = new ActivityFolder(cashflow)
            {
                Name = "MonthlyExpenses"
            };

            // Find the monthly living cost
            double amount = Overheads.GetData <double>(13, 0);

            // Only include if non-zero
            if (amount == 0)
            {
                return(null);
            }

            monthly.Add(new FinanceActivityPayExpense(monthly)
            {
                Name   = "LivingCost",
                Amount = amount
            });

            return(monthly);
        }
Пример #5
0
        private void AddTileToRenderList(GameObject obj, int worldX, int worldY, bool useObjectHandles, int maxZ)
        {
            for (; obj != null; obj = obj.Right)
            {
                if (obj.CurrentRenderIndex == _renderIndex || obj.IsDisposed)
                {
                    continue;
                }

                if (_updateDrawPosition && obj.CurrentRenderIndex != _renderIndex || obj.IsPositionChanged)
                {
                    obj.UpdateRealScreenPosition(_offset);
                }

                //obj.UseInRender = 0xFF;

                float drawX = obj.RealScreenPosition.X;
                float drawY = obj.RealScreenPosition.Y;

                if (drawX < _minPixel.X || drawX > _maxPixel.X)
                {
                    break;
                }

                int z          = obj.Z;
                int maxObjectZ = obj.PriorityZ;

                bool mounted  = false;
                bool ismobile = false;

                StaticTiles itemData     = default;
                bool        changinAlpha = false;

                switch (obj)
                {
                case Mobile mob:
                    maxObjectZ += Constants.DEFAULT_CHARACTER_HEIGHT;
                    ismobile    = true;
                    mounted     = mob.IsMounted;
                    break;

                default:

                    if (GameObjectHelper.TryGetStaticData(obj, out itemData))
                    {
                        if (obj is Static st)
                        {
                            if (StaticFilters.IsCave(st.OriginalGraphic))
                            {
                                if (Engine.Profile.Current.EnableCaveBorder && !st.IsBordered())
                                {
                                    st.SetBorder(true);
                                }
                                else if (!Engine.Profile.Current.EnableCaveBorder && st.IsBordered())
                                {
                                    st.SetBorder(false);
                                }
                            }
                            else if (StaticFilters.IsTree(st.OriginalGraphic))
                            {
                                if (Engine.Profile.Current.TreeToStumps && st.Graphic != Constants.TREE_REPLACE_GRAPHIC)
                                {
                                    st.SetGraphic(Constants.TREE_REPLACE_GRAPHIC);
                                }
                                else if (st.OriginalGraphic != st.Graphic && !Engine.Profile.Current.TreeToStumps)
                                {
                                    st.RestoreOriginalGraphic();
                                }
                            }
                        }

                        if (_noDrawRoofs && itemData.IsRoof)
                        {
                            if (_alphaChanged)
                            {
                                changinAlpha = obj.ProcessAlpha(0);
                            }
                            else
                            {
                                changinAlpha = obj.AlphaHue != 0;
                            }


                            if (!changinAlpha)
                            {
                                continue;
                            }
                        }

                        if ((Engine.Profile.Current.TreeToStumps && itemData.IsFoliage) || (Engine.Profile.Current.HideVegetation && StaticFilters.IsVegetation(obj.Graphic)))
                        {
                            continue;
                        }

                        maxObjectZ += itemData.Height;
                    }
                    break;
                }

                if (maxObjectZ > maxZ)
                {
                    break;
                }

                obj.CurrentRenderIndex = _renderIndex;

                bool iscorpse = !ismobile && obj is Item item && item.IsCorpse;

                if (!ismobile && !iscorpse && itemData.IsInternal)
                {
                    continue;
                }

                bool island = !ismobile && !iscorpse && obj is Land;

                if (!island && z >= _maxZ)
                {
                    if (!changinAlpha)
                    {
                        if (_alphaChanged)
                        {
                            changinAlpha = obj.ProcessAlpha(0);
                        }
                        else
                        {
                            changinAlpha = obj.AlphaHue != 0;
                        }

                        if (!changinAlpha)
                        {
                            continue;
                        }
                    }
                }

                int testMinZ = (int)drawY + z * 4;
                int testMaxZ = (int)drawY;

                if (island)
                {
                    Land t = obj as Land;
                    if (t.IsStretched)
                    {
                        testMinZ -= t.MinZ * 4;
                    }
                    else
                    {
                        testMinZ = testMaxZ;
                    }
                }
                else
                {
                    testMinZ = testMaxZ;
                }

                if (testMinZ < _minPixel.Y || testMaxZ > _maxPixel.Y)
                {
                    continue;
                }


                if (obj.Overheads != null && obj.Overheads.Count != 0)
                {
                    int offY;

                    if (ismobile && !mounted || iscorpse)
                    {
                        offY = -22;
                    }
                    else
                    {
                        switch (obj)
                        {
                        case Multi _:
                        case Static _: offY = -44;

                            break;
                        //case Item _:
                        //    offY = 44;

                        //break;
                        default: offY = 0;

                            break;
                        }
                    }

                    for (int i = 0; i < obj.Overheads.Count; i++)
                    {
                        TextOverhead v = obj.Overheads[i];
                        v.Bounds.X      = (v.Texture.Width >> 1) - 22;
                        v.Bounds.Y      = offY + v.Texture.Height;
                        v.Bounds.Width  = v.Texture.Width;
                        v.Bounds.Height = v.Texture.Height;
                        Overheads.AddOverhead(v);
                        offY += v.Texture.Height;

                        if (_alphaChanged)
                        {
                            if (v.TimeToLive > 0 && v.TimeToLive <= Constants.TIME_FADEOUT_TEXT)
                            {
                                if (!v.IsOverlapped)
                                {
                                    v.ProcessAlpha(0);
                                }
                            }
                            else if (!v.IsOverlapped && v.AlphaHue != 0xFF)
                            {
                                v.ProcessAlpha(0xFF);
                            }
                        }
                    }
                }


                if (ismobile || iscorpse)
                {
                    AddOffsetCharacterTileToRenderList(obj, useObjectHandles);
                }
                else if (itemData.IsFoliage)
                {
                    if (obj is Static st)
                    {
                        bool check = World.Player.X <= worldX && World.Player.Y <= worldY;

                        if (!check)
                        {
                            check = World.Player.Y <= worldY && World.Player.Position.X <= worldX + 1;

                            if (!check)
                            {
                                check = World.Player.X <= worldX && World.Player.Y <= worldY + 1;
                            }
                        }

                        if (check)
                        {
                            Rectangle rect = new Rectangle((int)drawX - st.FrameInfo.X,
                                                           (int)drawY - st.FrameInfo.Y,
                                                           st.FrameInfo.Width,
                                                           st.FrameInfo.Height);


                            check = rect.InRect(World.Player.GetOnScreenRectangle());
                        }

                        st.CharacterIsBehindFoliage = check;
                    }
                    else if (obj is Multi m)
                    {
                        bool check = World.Player.X <= worldX && World.Player.Y <= worldY;

                        if (!check)
                        {
                            check = World.Player.Y <= worldY && World.Player.Position.X <= worldX + 1;

                            if (!check)
                            {
                                check = World.Player.X <= worldX && World.Player.Y <= worldY + 1;
                            }
                        }

                        if (check)
                        {
                            Rectangle rect = new Rectangle((int)drawX - m.FrameInfo.X,
                                                           (int)drawY - m.FrameInfo.Y,
                                                           m.FrameInfo.Width,
                                                           m.FrameInfo.Height);


                            check = rect.InRect(World.Player.GetOnScreenRectangle());
                        }

                        m.CharacterIsBehindFoliage = check;
                    }
                }

                if (_alphaChanged && !changinAlpha)
                {
                    if (itemData.IsTranslucent)
                    {
                        obj.ProcessAlpha(178);
                    }
                    else if (!itemData.IsFoliage && obj.AlphaHue != 0xFF)
                    {
                        obj.ProcessAlpha(0xFF);
                    }
                }

                if (_renderListCount >= _renderList.Length)
                {
                    int newsize = _renderList.Length + 1000;
                    Array.Resize(ref _renderList, newsize);
                }

                if (useObjectHandles)
                {
                    obj.UseObjectHandles = (ismobile || iscorpse || obj is Item it && !it.IsLocked && !it.IsMulti) && !obj.ClosedObjectHandles;
                    _objectHandlesCount++;
                }
                else if (obj.ClosedObjectHandles)
                {
                    obj.ClosedObjectHandles = false;
                    obj.ObjectHandlesOpened = false;
                }
                else if (obj.UseObjectHandles)
                {
                    obj.ObjectHandlesOpened = false;
                    obj.UseObjectHandles    = false;
                }


                _renderList[_renderListCount] = obj;
                //obj.UseInRender = (byte) _renderIndex;
                _renderListCount++;
            }
        }
Пример #6
0
 /// <summary>
 /// Sets the data for a FinanceType model using IAT data
 /// </summary>
 /// <param name="bank">The base model</param>
 public void SetBankData(FinanceType bank)
 {
     bank.Name                = "Bank";
     bank.OpeningBalance      = Overheads.GetData <double>(12, 0);
     bank.InterestRateCharged = Overheads.GetData <double>(11, 0);
 }
        private void AddTileToRenderList(GameObject obj, int worldX, int worldY, bool useObjectHandles, int maxZ)
        {
            for (; obj != null; obj = obj.Right)
            {
                if (obj.CurrentRenderIndex == _renderIndex || !obj.AllowedToDraw)
                {
                    continue;
                }

                if (UpdateDrawPosition && obj.CurrentRenderIndex != _renderIndex || obj.IsPositionChanged)
                {
                    obj.UpdateRealScreenPosition(_offset);
                }

                //obj.UseInRender = 0xFF;

                int drawX = obj.RealScreenPosition.X;
                int drawY = obj.RealScreenPosition.Y;

                if (drawX < _minPixel.X || drawX > _maxPixel.X)
                {
                    break;
                }

                int z          = obj.Z;
                int maxObjectZ = obj.PriorityZ;

                bool ismobile = false;

                StaticTiles itemData     = _emptyStaticTiles;
                bool        changinAlpha = false;
                bool        island       = false;

                switch (obj)
                {
                case Mobile _:
                    maxObjectZ += Constants.DEFAULT_CHARACTER_HEIGHT;
                    ismobile    = true;

                    break;

                case Land _:
                    island = true;
                    break;

                default:

                    if (GameObjectHelper.TryGetStaticData(obj, out itemData))
                    {
                        if (obj is Static st)
                        {
                            if (StaticFilters.IsTree(st.OriginalGraphic))
                            {
                                if (Engine.Profile.Current.TreeToStumps && st.Graphic != Constants.TREE_REPLACE_GRAPHIC)
                                {
                                    st.SetGraphic(Constants.TREE_REPLACE_GRAPHIC);
                                }
                                else if (st.OriginalGraphic != st.Graphic && !Engine.Profile.Current.TreeToStumps)
                                {
                                    st.RestoreOriginalGraphic();
                                }
                            }
                        }

                        if (_noDrawRoofs && itemData.IsRoof)
                        {
                            if (_alphaChanged)
                            {
                                changinAlpha = obj.ProcessAlpha(0);
                            }
                            else
                            {
                                changinAlpha = obj.AlphaHue != 0;
                            }


                            if (!changinAlpha)
                            {
                                continue;
                            }
                        }

                        if (Engine.Profile.Current.TreeToStumps && itemData.IsFoliage || Engine.Profile.Current.HideVegetation && StaticFilters.IsVegetation(obj.Graphic))
                        {
                            continue;
                        }

                        maxObjectZ += itemData.Height;
                    }

                    break;
                }

                if (maxObjectZ > maxZ)
                {
                    break;
                }

                obj.CurrentRenderIndex = _renderIndex;

                bool iscorpse = !ismobile && !island && obj is Item item && item.IsCorpse;

                if (!ismobile && !iscorpse && !island && itemData.IsInternal)
                {
                    continue;
                }

                if (!island && z >= _maxZ)
                {
                    if (!changinAlpha)
                    {
                        if (_alphaChanged)
                        {
                            changinAlpha = obj.ProcessAlpha(0);
                        }
                        else
                        {
                            changinAlpha = obj.AlphaHue != 0;
                        }

                        if (!changinAlpha)
                        {
                            continue;
                        }
                    }
                }

                int testMinZ = drawY + z * 4;
                int testMaxZ = drawY;

                if (island)
                {
                    Land t = obj as Land;

                    if (t.IsStretched)
                    {
                        testMinZ -= t.MinZ * 4;
                    }
                    else
                    {
                        testMinZ = testMaxZ;
                    }
                }
                else
                {
                    testMinZ = testMaxZ;
                }

                if (testMinZ < _minPixel.Y || testMaxZ > _maxPixel.Y)
                {
                    continue;
                }


                if (obj.OverheadMessageContainer != null && !obj.OverheadMessageContainer.IsEmpty)
                {
                    Overheads.AddOverhead(obj.OverheadMessageContainer);
                }

                if (ismobile || iscorpse)
                {
                    AddOffsetCharacterTileToRenderList(obj, useObjectHandles);
                }
                else if (!island && itemData.IsFoliage)
                {
                    bool check = World.Player.X <= worldX && World.Player.Y <= worldY;

                    if (!check)
                    {
                        check = World.Player.Y <= worldY && World.Player.Position.X <= worldX + 1;

                        if (!check)
                        {
                            check = World.Player.X <= worldX && World.Player.Y <= worldY + 1;
                        }
                    }

                    if (check)
                    {
                        _rectangleObj.X      = drawX - obj.FrameInfo.X;
                        _rectangleObj.Y      = drawY - obj.FrameInfo.Y;
                        _rectangleObj.Width  = obj.FrameInfo.Width;
                        _rectangleObj.Height = obj.FrameInfo.Height;

                        check = Exstentions.InRect(ref _rectangleObj, ref _rectanglePlayer);
                    }

                    switch (obj)
                    {
                    case Static st:
                        st.CharacterIsBehindFoliage = check;

                        break;

                    case Multi m:
                        m.CharacterIsBehindFoliage = check;

                        break;

                    case Item it:
                        it.CharacterIsBehindFoliage = check;

                        break;
                    }
                }

                if (_alphaChanged && !changinAlpha)
                {
                    if (itemData.IsTranslucent)
                    {
                        obj.ProcessAlpha(178);
                    }
                    else if (!itemData.IsFoliage && obj.AlphaHue != 0xFF)
                    {
                        obj.ProcessAlpha(0xFF);
                    }
                }

                if (_renderListCount >= _renderList.Length)
                {
                    int newsize = _renderList.Length + 1000;
                    //_renderList.Resize(newsize);
                    Array.Resize(ref _renderList, newsize);
                }


                if (useObjectHandles && NameOverHeadManager.IsAllowed(obj as Entity))
                {
                    obj.UseObjectHandles = (ismobile ||
                                            iscorpse ||
                                            obj is Item it && (!it.IsLocked || it.IsLocked && itemData.IsContainer) && !it.IsMulti) &&
                                           !obj.ClosedObjectHandles && _objectHandlesCount <= 400;
                    _objectHandlesCount++;
                }
                else if (obj.ClosedObjectHandles)
                {
                    obj.ClosedObjectHandles = false;
                    obj.ObjectHandlesOpened = false;
                }
                else if (obj.UseObjectHandles)
                {
                    obj.ObjectHandlesOpened = false;
                    obj.UseObjectHandles    = false;
                }

                //ref var weak = ref _renderList[_renderListCount];

                //if (weak == null)
                //    weak = new WeakReference<GameObject>(obj);
                //else
                //    weak.SetTarget(obj);

                _renderList[_renderListCount] = obj;
                //_renderList.Enqueue(obj);
                //obj.UseInRender = (byte) _renderIndex;
                _renderListCount++;
            }
        }