protected override void DoPaintEvent(BaseScreen screen)
        {
            ExtRect crt = ClientRect;

            CtlCommon.DrawCtlBorder(screen, crt);
            crt.Inflate(-1, -1);
            DrawGauge(screen, crt, Pos, Max, Colors.Black, Colors.Gray, Colors.Gold);
        }
Example #2
0
 private void PrepareShopReturn()
 {
     try {
         NWCreature self      = (NWCreature)fSelf;
         Building   house     = self.FindHouse();
         ExtRect    houseArea = house.Area.Clone();
         if (!houseArea.Contains(self.PosX, self.PosY) && !(FindGoalByKind(GoalKind.gk_ShopReturn) is ShopReturnGoal))
         {
             houseArea.Inflate(-1, -1);
             ShopReturnGoal srGoal = (ShopReturnGoal)CreateGoal(GoalKind.gk_ShopReturn);
             srGoal.Position = RandomHelper.GetRandomPoint(houseArea);
         }
     } catch (Exception ex) {
         Logger.Write("TraderBrain.prepareReturn(): " + ex.Message);
     }
 }
Example #3
0
        public void CalcBounds(int lines, ChartRenderer renderer)
        {
            try
            {
                InitInfo(lines);
                DefineExpands();

                int maxwid = 0;
                for (int k = 0; k < lines; k++)
                {
                    int wt = renderer.GetTextWidth(Lines[k], fModel.DrawFont);
                    if (maxwid < wt)
                    {
                        maxwid = wt;
                    }
                }

                int pad2side = (fModel.NodePadding * 2);

                fWidth  = pad2side + maxwid;
                fHeight = pad2side + renderer.GetTextHeight(fModel.DrawFont) * lines;

                if (fPortrait != null)
                {
                    ExtRect portRt = ExtRect.Create(0, 0, fHeight - 1, fHeight - 1);
                    portRt.Inflate(3, 3);

                    int   rtW   = portRt.GetWidth();
                    int   rtH   = portRt.GetHeight();
                    int   imgW  = fPortrait.Width;
                    int   imgH  = fPortrait.Height;
                    float ratio = SysUtils.ZoomToFit(imgW, imgH, rtW, rtH);
                    imgW = (int)Math.Round(imgW * ratio);
                    imgH = (int)Math.Round(imgH * ratio);

                    PortraitArea   = ExtRect.CreateBounds(portRt.Left, portRt.Top, imgW, imgH);
                    fPortraitWidth = imgW;

                    fWidth += imgW;
                }
            }
            catch (Exception ex)
            {
                Logger.LogWrite("TreeChartPerson.CalcBounds(): " + ex.Message);
            }
        }
Example #4
0
        public void Test_ExtRect()
        {
            ExtRect rt = ExtRect.Create(0, 0, 9, 9);

            Assert.AreEqual(0, rt.Left);
            Assert.AreEqual(0, rt.Top);
            Assert.AreEqual(9, rt.Right);
            Assert.AreEqual(9, rt.Bottom);
            Assert.AreEqual(10, rt.GetHeight());
            Assert.AreEqual(10, rt.GetWidth());

            rt = ExtRect.CreateBounds(0, 0, 10, 10);

            Assert.AreEqual(0, rt.Left);
            Assert.AreEqual(0, rt.Top);
            Assert.AreEqual(9, rt.Right);
            Assert.AreEqual(9, rt.Bottom);
            Assert.AreEqual(10, rt.GetHeight());
            Assert.AreEqual(10, rt.GetWidth());

            Assert.AreEqual("{X=0,Y=0,Width=10,Height=10}", rt.ToString());

            Assert.IsTrue(rt.Contains(5, 5));

            rt.Inflate(3, -2);
            Assert.AreEqual("{X=3,Y=-2,Width=4,Height=14}", rt.ToString());

            rt.Offset(2, 5);
            Assert.AreEqual("{X=5,Y=3,Width=4,Height=14}", rt.ToString());

            rt = rt.GetOffset(10, 10);
            Assert.AreEqual("{X=15,Y=13,Width=4,Height=14}", rt.ToString());

            Assert.IsTrue(rt.IntersectsWith(ExtRect.Create(16, 14, 20, 20)));

            rt = ExtRect.CreateEmpty();
            Assert.IsTrue(rt.IsEmpty());

            Assert.IsFalse(rt.Contains(5, 5));
        }
        public override void Execute()
        {
            NWCreature self = (NWCreature)Self;

            ExtRect r = Area.Clone();

            r.Inflate(-1, -1);

            if (!r.Contains(self.PosX, self.PosY))
            {
                ExtPoint pos = new ExtPoint();
                pos.X = RandomHelper.GetBoundedRnd(r.Left, r.Right);
                pos.Y = RandomHelper.GetBoundedRnd(r.Top, r.Bottom);
                ExtPoint next = self.GetStep(pos);
                if (!next.IsEmpty)
                {
                    Brain.StepTo(next.X, next.Y);
                }
            }

            IsComplete = false;
            //refComplete.argValue = this.Area.Contains(self.getPosX(), self.getPosY());
        }
        private bool CanBuild(ExtRect br, ExtRect area)
        {
            try {
                AbstractMap map = (AbstractMap)Owner;

                bool result = area.Contains(br);
                if (result)
                {
                    br.Inflate(+1, +1);

                    bool res = map.ForEachTile(br.Left, br.Top, br.Right, br.Bottom, CanBuildCheck);
                    if (!res)
                    {
                        return(false);
                    }

                    /*for (int y = br.Top; y <= br.Bottom; y++) {
                     *  for (int x = br.Left; x <= br.Right; x++) {
                     *      BaseTile tile = map.GetTile(x, y);
                     *      if (tile != null) {
                     *          int bg = tile.Background;
                     *          if (bg == PlaceID.pid_Floor || bg == PlaceID.pid_RnFloor) {
                     *              return false;
                     *          }
                     *      } else {
                     *          return false;
                     *      }
                     *  }
                     * }*/
                }

                return(true);
            } catch (Exception ex) {
                Logger.Write("Building.canBuild(): " + ex.Message);
                return(false);
            }
        }
        // FIXME: total check & tests
        public void Prepare()
        {
            NWField fld = (NWField)Owner;
            ExtRect r   = Area;

            r.Inflate(-1, -1);

            int id    = (int)ID;
            var blRec = StaticData.dbBuildings[id];

            if (ID >= BuildingID.bid_MerchantShop && ID <= BuildingID.bid_WoodsmanShop)
            {
                NWCreature merchant = (NWCreature)Holder;
                if (merchant == null)
                {
                    Item coins = new Item(fSpace, null);
                    coins.CLSID = GlobalVars.iid_Coin;
                    coins.Count = (ushort)RandomHelper.GetBoundedRnd(15000, 25000);
                    int x = RandomHelper.GetBoundedRnd(r.Left, r.Right);
                    int y = RandomHelper.GetBoundedRnd(r.Top, r.Bottom);
                    merchant          = fld.AddCreature(x, y, GlobalVars.nwrDB.FindEntryBySign(StaticData.dbSysCreatures[(int)blRec.Owner].Sign).GUID);
                    merchant.IsTrader = true;
                    merchant.AddItem(coins);
                    Holder = merchant;
                }
                else
                {
                    Item coins = (Item)merchant.Items.FindByCLSID(GlobalVars.iid_Coin);
                    if (coins != null)
                    {
                        coins.Count = (ushort)RandomHelper.GetBoundedRnd(15000, 25000);
                    }
                }

                ProbabilityTable <int> data = blRec.Wares;
                if (((data != null) ? data.Size() : 0) > 0)
                {
                    for (int y = r.Top; y <= r.Bottom; y++)
                    {
                        for (int x = r.Left; x <= r.Right; x++)
                        {
                            Item item = (Item)fld.FindItem(x, y);
                            if (item == null)
                            {
                                item       = new Item(fSpace, this);
                                item.CLSID = data.GetRandomItem();
                                item.SetPos(x, y);
                                item.Owner = merchant;
                                item.GenCount();
                                fld.Items.Add(item, false);
                            }
                            else
                            {
                                if (AuxUtils.Chance(20))
                                {
                                    item.CLSID = data.GetRandomItem();
                                    item.GenCount();
                                }
                            }
                        }
                    }
                }
            }
        }
Example #8
0
        public void CalcBounds(int lines, ChartRenderer renderer)
        {
            try {
                TreeChartOptions options = fModel.Options;

                InitInfo(lines);
                DefineExpands();

                int bh = renderer.GetTextHeight(fModel.BoldFont);
                int th = renderer.GetTextHeight(fModel.DrawFont);

                int maxwid = 0;
                int height = 0;
                for (int k = 0; k < lines; k++)
                {
                    IFont font;
                    if (options.BoldNames && k < NameLines)
                    {
                        height += bh;
                        font    = fModel.BoldFont;
                    }
                    else
                    {
                        height += th;
                        font    = fModel.DrawFont;
                    }

                    int wt = renderer.GetTextWidth(Lines[k], font);
                    if (maxwid < wt)
                    {
                        maxwid = wt;
                    }
                }

                int pad2side = (fModel.NodePadding * 2);

                fWidth  = pad2side + maxwid;
                fHeight = pad2side + height;

                if (fPortrait != null)
                {
                    ExtRect portRt = ExtRect.Create(0, 0, fHeight - 1, fHeight - 1);
                    portRt.Inflate(-3, -3);

                    int   rtW   = portRt.GetWidth();
                    int   rtH   = portRt.GetHeight();
                    int   imgW  = fPortrait.Width;
                    int   imgH  = fPortrait.Height;
                    float ratio = GfxHelper.ZoomToFit(imgW, imgH, rtW, rtH);
                    imgW = (int)Math.Round(imgW * ratio);
                    imgH = (int)Math.Round(imgH * ratio);

                    PortraitArea   = ExtRect.CreateBounds(portRt.Left, portRt.Top, imgW, imgH);
                    fPortraitWidth = imgW;

                    fWidth += imgW;
                }
            } catch (Exception ex) {
                Logger.WriteError("TreeChartPerson.CalcBounds()", ex);
            }
        }