Пример #1
0
        public int testPossibleNow(int VillageID, BuildingQueue Q)
        {
            var CV = TD.Villages[VillageID];

            if (CV.Buildings.ContainsKey(Q.Bid) && CV.Buildings[Q.Bid].Gid == Q.Gid && CV.Buildings[Q.Bid].Level != 0)
            {
                return(Buildings.CheckLevelFull(Q.Gid, CV.Buildings[Q.Bid].Level, CV.isCapital) ? -1 : 0);
            }
            return(testPossibleNewNow(TD.Tribe, TD.Villages, CV, Q.Gid, Q.Bid));
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Tribe"></param>
        /// <param name="Villages"></param>
        /// <param name="CV"></param>
        /// <param name="Gid"></param>
        /// <param name="Bid"></param>
        /// <returns>0:directly, -1:impossible, >0:pre-upgrade gid</returns>
        static public int testPossibleNewNow(int Tribe, Dictionary <int, TVillage> Villages, TVillage CV, int Gid, int Bid)
        {
            //	不能在主村造的建筑
            List <int> CapitalNo = new List <int> {
                29, 30
            };
            //	只能在主村造的建筑
            List <int> NotCapitalNo = new List <int> {
                34, 35
            };
            //	可重复造的建筑
            List <int> Repeatable = new List <int> {
                10, 11, 23, 36, 38, 39
            };

            //TQueue Q = CV.Queue[QueueID];
            // Extend

            if (Gid == 36 && Tribe != 3)
            {
                return(-1);
            }
            if (Gid == 35 && Tribe != 2)
            {
                return(-1);
            }
            if (Gid == 41 && Tribe != 1)
            {
                return(-1);
            }

            if (Gid < 5)
            {
                return(0);
            }

            // Below are building new one
            if (CV.isCapital && CapitalNo.Contains(Gid))
            {
                return(-1);
            }
            if (!CV.isCapital && NotCapitalNo.Contains(Gid))
            {
                return(-1);
            }
            // Residence/Palace problem
            if (Gid == 26)
            {
                int PCount = 0;
                foreach (var x in Villages)
                {
                    if (x.Value.isBuildingInitialized == 2)
                    {
                        foreach (var y in x.Value.Buildings)
                        {
                            if (y.Value.Gid == 26 && y.Value.Level > 0)
                            {
                                PCount++;
                                break;
                            }
                            else if (y.Value.Gid == 25)
                            {
                                break;
                            }
                        }
                    }
                }
                if (PCount == 0)
                {
                    bool NotFound = true;
                    foreach (var x in Buildings.Depends[Gid])
                    {
                        int canUp = 0;
                        foreach (var y in CV.Buildings)
                        {
                            if (x.Gid == y.Value.Gid)
                            {
                                if (x.Level > y.Value.Level)
                                {
                                    canUp = y.Key;
                                }
                                else
                                {
                                    NotFound = false;
                                    break;
                                }
                            }
                        }
                        if (NotFound && canUp != 0)
                        {
                            return(canUp);
                        }
                    }
                    if (NotFound)
                    {
                        return(-1);
                    }
                    else
                    {
                        return(0);
                    }
                }
                else
                {
                    return(-1);
                }
            }

            // Check duplicate
            int toBuild = 0;

            if (Repeatable.Contains(Gid))
            {
                foreach (var x in CV.Buildings)
                {
                    if (x.Key == Bid)
                    {
                        continue;
                    }
                    if (x.Value.Gid == Gid)
                    {
                        if (Buildings.CheckLevelFull(x.Value.Gid, x.Value.Level, CV.isCapital))
                        {
                            toBuild = 0;
                            break;
                        }
                        else
                        {
                            toBuild = x.Key;
                        }
                    }
                }
                if (toBuild != 0)
                {
                    return(toBuild);
                }
                else
                {
                    return(0);
                }
            }
            // Check duplicate for non-repeatable
            foreach (var x in CV.Buildings)
            {
                if (x.Value.Gid == Gid && x.Key != Bid)
                {
                    return(-1);
                }
            }

            // Check depend
            if (!Buildings.Depends.ContainsKey(Gid))
            {
                return(0);
            }
            bool gNotFound = false;

            foreach (var x in Buildings.Depends[Gid])
            {
                bool NotFound = true;
                int  canUp    = 0;
                foreach (var y in CV.Buildings)
                {
                    if (x.Gid == y.Value.Gid)
                    {
                        if (x.Level > y.Value.Level)
                        {
                            canUp = y.Key;
                        }
                        else
                        {
                            NotFound = false;
                            break;
                        }
                    }
                }
                if (NotFound && canUp != 0)
                {
                    return(canUp);
                }
                gNotFound = gNotFound || NotFound;
                if (gNotFound)
                {
                    break;
                }
            }
            return(gNotFound ? -1 : 0);
        }