Beispiel #1
0
        private void BalanceSourceTime(Data travianData, int VillageID)
        {
            // TODO: FIXME
            int        total        = ResourceAmount.TotalAmount;
            int        slots        = NoCrop ? 3 : 4;
            TResAmount targetAmount = new TResAmount(0, 0, 0, 0);

            if (travianData != null &&
                travianData.Villages.ContainsKey(VillageID) &&
                travianData.Villages[VillageID].isBuildingInitialized == 2)
            {
                TVillage TV = travianData.Villages[VillageID];
                int[]    fulltime = new int[slots];
                int      maxtime = 0, total2 = 0, totalproduce = 0, total3 = 0;

                for (int i = 0; i < fulltime.Length; i++)
                {
                    fulltime[i] = Convert.ToInt32(TV.Resource[i].LeftTime.TotalSeconds);

                    maxtime = Math.Max(maxtime, fulltime[i]);
                }

                for (int i = 0; i < fulltime.Length; i++)
                {
                    targetAmount.Resources[i] = Convert.ToInt32(Convert.ToInt64(TV.Resource[i].Produce) * (maxtime - fulltime[i]) / 3600);

                    total2       += targetAmount.Resources[i];
                    totalproduce += TV.Resource[i].Produce;
                }
                if (total2 > total)
                {
                    for (int i = 0; i < fulltime.Length; i++)
                    {
                        targetAmount.Resources[i] = Convert.ToInt32(targetAmount.Resources[i] * Convert.ToDouble(total) / total2);
                        total3 += targetAmount.Resources[i];
                    }
                }
                else
                {
                    double seconds = Convert.ToDouble(total - total2) / totalproduce;
                    for (int i = 0; i < fulltime.Length; i++)
                    {
                        targetAmount.Resources[i] += Convert.ToInt32(TV.Resource[i].Produce * seconds);
                        total3 += targetAmount.Resources[i];
                    }
                }
                targetAmount.Resources[slots - 1] += total - total3;
                targetAmount.NoNegative();
            }
            ResourceAmount = targetAmount;
        }
Beispiel #2
0
        /// <summary>
        /// Estimate the target village capacity when transportantion arrives, based on
        /// its current resource amount, production rate, distance, and merchant speed.
        /// </summary>
        /// <param name="travianData">Contains game info</param>
        /// <param name="VillageID">Where the merchant starts, for computing distance</param>
        /// <returns>Estimated capacity</returns>
        private TResAmount GetTargetCapacity(Data travianData, int VillageID)
        {
            if (travianData != null &&
                travianData.Villages.ContainsKey(this.TargetVillageID) &&
                travianData.Villages.ContainsKey(VillageID))
            {
                TVillage source      = travianData.Villages[VillageID];
                TVillage destination = travianData.Villages[this.TargetVillageID];
                if (destination.isBuildingInitialized == 2)
                {
                    TResource[] VR        = destination.Resource;
                    int[]       resources = new int[VR.Length];
                    int         speed     = travianData.MarketSpeed == 0 ? 24 : travianData.MarketSpeed;
                    double      timecost  = source.Coord * destination.Coord / speed;
                    for (int i = 0; i < resources.Length; i++)
                    {
                        resources[i] = VR[i].Capacity * this.LimitRate / 100;
                        if (destination.Market.UpperLimit != null)
                        {
                            resources[i] = destination.Market.UpperLimit.Resources[i];
                        }

                        resources[i] -= VR[i].CurrAmount + (int)(VR[i].Produce * timecost);
                    }

                    TResAmount capacity = new TResAmount(resources);
                    foreach (TMInfo transfer in destination.Market.MarketInfo)
                    {
                        if (transfer.MType == TMType.OtherCome)
                        {
                            capacity -= transfer.CarryAmount;
                        }
                    }

                    capacity.NoNegative();
                    return(capacity);
                }
            }

            return(null);
        }
Beispiel #3
0
        private void BalanceSourceResource(Data travianData, int VillageID)
        {
            TResAmount targetAmount = new TResAmount(0, 0, 0, 0);

            if (travianData != null &&
                travianData.Villages.ContainsKey(VillageID) &&
                travianData.Villages[VillageID].isBuildingInitialized == 2)
            {
                TVillage village = travianData.Villages[VillageID];
                for (int i = 0; i < targetAmount.Resources.Length; i++)
                {
                    targetAmount.Resources[i] = village.Resource[i].CurrAmount;
                    if (village.Market.LowerLimit != null)
                    {
                        targetAmount.Resources[i] -= village.Market.LowerLimit.Resources[i];
                    }
                }

                targetAmount.NoNegative();
            }

            this.DoBalance(targetAmount);
        }
        /// <summary>
        /// Estimate the target village capacity when transportantion arrives, based on 
        /// its current resource amount, production rate, distance, and merchant speed.
        /// </summary>
        /// <param name="travianData">Contains game info</param>
        /// <param name="VillageID">Where the merchant starts, for computing distance</param>
        /// <returns>Estimated capacity</returns>
        private TResAmount GetTargetCapacity(Data travianData, int VillageID)
        {
            if(travianData != null &&
                travianData.Villages.ContainsKey(this.TargetVillageID) &&
                travianData.Villages.ContainsKey(VillageID))
            {
                TVillage source = travianData.Villages[VillageID];
                TVillage destination = travianData.Villages[this.TargetVillageID];
                if(destination.isBuildingInitialized == 2)
                {
                    TResource[] VR = destination.Resource;
                    int[] resources = new int[VR.Length];
                    int speed = travianData.MarketSpeed == 0 ? 24 : travianData.MarketSpeed;
                    double timecost = source.Coord * destination.Coord / speed;
                    for(int i = 0; i < resources.Length; i++)
                    {
                        resources[i] = VR[i].Capacity * this.LimitRate / 100;
                        if(destination.Market.UpperLimit != null)
                        {
                            resources[i] = destination.Market.UpperLimit.Resources[i];
                        }

                        resources[i] -= VR[i].CurrAmount + (int)(VR[i].Produce * timecost);
                    }

                    TResAmount capacity = new TResAmount(resources);
                    foreach(TMInfo transfer in destination.Market.MarketInfo)
                    {
                        if(transfer.MType == TMType.OtherCome)
                        {
                            capacity -= transfer.CarryAmount;
                        }
                    }

                    capacity.NoNegative();
                    return capacity;
                }
            }

            return null;
        }
        private void BalanceSourceTime(Data travianData, int VillageID)
        {
            // TODO: FIXME
            int total = ResourceAmount.TotalAmount;
            int slots = NoCrop ? 3 : 4;
            TResAmount targetAmount = new TResAmount(0, 0, 0, 0);
            if(travianData != null &&
                travianData.Villages.ContainsKey(VillageID) &&
                travianData.Villages[VillageID].isBuildingInitialized == 2)
            {
                TVillage TV = travianData.Villages[VillageID];
                int[] fulltime = new int[slots];
                int maxtime = 0, total2 = 0, totalproduce = 0, total3 = 0;

                for(int i = 0; i < fulltime.Length; i++)
                {
                    fulltime[i] = Convert.ToInt32(TV.Resource[i].LeftTime.TotalSeconds);

                    maxtime = Math.Max(maxtime, fulltime[i]);
                }

                for(int i = 0; i < fulltime.Length; i++)
                {
                    targetAmount.Resources[i] = Convert.ToInt32(Convert.ToInt64(TV.Resource[i].Produce) * (maxtime - fulltime[i]) / 3600);

                    total2 += targetAmount.Resources[i];
                    totalproduce += TV.Resource[i].Produce;
                }
                if(total2 > total)
                {
                    for(int i = 0; i < fulltime.Length; i++)
                    {
                        targetAmount.Resources[i] = Convert.ToInt32(targetAmount.Resources[i] * Convert.ToDouble(total) / total2);
                        total3 += targetAmount.Resources[i];
                    }
                }
                else
                {

                    double seconds = Convert.ToDouble(total - total2) / totalproduce;
                    for(int i = 0; i < fulltime.Length; i++)
                    {
                        targetAmount.Resources[i] += Convert.ToInt32(TV.Resource[i].Produce * seconds);
                        total3 += targetAmount.Resources[i];
                    }
                }
                targetAmount.Resources[slots - 1] += total - total3;
                targetAmount.NoNegative();

            }
            ResourceAmount = targetAmount;
        }
        private void BalanceSourceResource(Data travianData, int VillageID)
        {
            TResAmount targetAmount = new TResAmount(0, 0, 0, 0);
            if(travianData != null &&
                travianData.Villages.ContainsKey(VillageID) &&
                travianData.Villages[VillageID].isBuildingInitialized == 2)
            {
                TVillage village = travianData.Villages[VillageID];
                for(int i = 0; i < targetAmount.Resources.Length; i++)
                {
                    targetAmount.Resources[i] = village.Resource[i].CurrAmount;
                    if(village.Market.LowerLimit != null)
                    {
                        targetAmount.Resources[i] -= village.Market.LowerLimit.Resources[i];
                    }
                }

                targetAmount.NoNegative();
            }

            this.DoBalance(targetAmount);
        }