Announcement

Collapse
No announcement yet.

Calculating Caravan and Freight Delivery Payments

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calculating Caravan and Freight Delivery Payments

    There have been several postings here over the years which describe formulae for caravan and freight delivery payments. Although most of the factors affecting the amount of payments have been identified, none of these formulae are able to predict the payment amount exactly in all cases. This is due to not recognizing that the order of application of the various bonuses and penalties is important and to the existance of a previously undescribed MapsizeFactor.


    The following procedure can be used to accurately calculate caravan and freight delivery payments.

    A base payment is first determined from the base trade of each city and the distance between them. The formula for this base payment is:

    Base Payment = ((Distance x MapSizeFactor + 10) x (Total Base Trade) ) /24

    This payment amount is then modified by a number of bonuses and penalties which must be applied in a specific order to derive the final delivery payment. The order of calculation and other information required is explained in the 10 steps that follow.

    [Note about Civ2 math: All Civ2 algorithms which I have investigated use integer math. This means that any remainder left after a division operation is discarded. For example, the result of both 17/8 and 23/8 would be 2. There is no rounding. ]

    Step 1) Calculate the Distance between the two cities. The distance between any two points on a Civ2 map can be determined from their X,Y coordinates, where X is a location on the East/West axis, and Y is on the North/South axis. The formula is:

    Distance = (Xdistance + Ydistance)/2 + ( | Xdistance - Ydistance | )/4

    If the coordinates of point A are (Xa, Ya) and the coordinates of point B are (Xb, Yb), then the absolute difference between Y coordinates is:

    Ydistance = |Ya - Yb|.

    Or, in other words, simply subtract the smaller Y value from the larger one.
    On a FLAT map, the Xdistance value is found the same way:

    Xdistance = |Xa - Xb|.

    On a ROUND map, however, there will be two values which express the horizontal distance between two points: |Xa - Xb| and (C - |Xa - Xb|) where C is the circumference of the map. These values represent the X distances between the two points obtained by traveling East or West respectively. The Xdistance value used in calculating Civ2 distances is the smaller of these two numbers. Thus:

    Xdistance = SmallerOf( |Xa - Xb| , (C - |Xa - Xb|) )

    This calculation is easier to do in practice than it is to formally describe.
    For example, given two points A(23, 71) and B( 84, 12) on a medium map (50 x 80),
    where the circumference is 100:

    Ydistance = 71 - 12 = 59.
    Xdistance = SmallerOf( 84 - 23 , 100 - (84-23) = SmallerOf( 61, 39) = 39
    Distance = (39 + 59)/2 + (|39 - 59|)/4 = 98/2 + 20/4 = 49 + 5 = 54


    Step 2) Add the base trade of the two cities. The base trade of a city is determined in the City Display by subtracting any existing trade routes from the total number of trade arrows shown for the city. For a foreign city, the base trade can only be accurately known by investigating the city with a diplomat or spy. However, an estimate can be made from the city size, type of government, and knowledge of the terrain surrounding the city.

    TotalBaseTrade = BaseTrade(City A) + BaseTrade(City B)

    Step 3) Calculate the Base Payment from the formula:

    Base Payment = ((Distance x MapSizeFactor + 10) x (Total Base Trade) ) /24

    The MapSizeFactor for a medium map is 1, for a small map it is 5/4, and for a large map it is 4/5. Note that the effect of the MapSizeFactor is that for equal distances, the delivery payments on a small map will be 20% higher than on a medium map and 50% higher than on a large map.

    Step 4) Apply the TwoContinentBonus. If the two cities are located on different continents (i.e. they have different continent numbers following their X,Y coordinates in the location field) then double the Base Payment derived in step 3.

    Step 5) Apply the SameCivPenalty. If the two cities belong to the same civilization, then halve the value from Step 4. (Remember when doing this division by 2 to discard any remainder.)

    Step 6) Apply the FreightBonus. If the delivery is by freight (as opposed to caravan) multiply the answer from Step 5 by 3/2. i.e., first multiply by 3 then divide by 2, discarding any remainder.

    Step 7) Apply the DemandBonus. If the commodity being delivered is demanded by the destination city, then the amount from Step 6 is multiplied by a factor based on the type of commodity involved

    Hides, Salt, Wool, Beads, Copper, Dye 2
    Cloth, Coal, Wine, Silver 5/2
    Silk, Spice, Gems, Gold 3
    Oil 7/2
    Uranium 4

    Again, the bonuses expressed by fractions are applied by first multiplying by the upper number and then dividing by the lower.

    Step 8) Calculate and apply the TransportationBonus. Unlike previous bonuses, the TransportationBonus consists of several factors which are first combined additively (expressed as a %) before being applied multiplicatively. These are the road, railroad, airport, and superhighways bonuses. Each has peculiarities which will be discussed.

    The Road (50%) and Railroad (100%) bonuses are applied when a valid road or railroad connection exists between the Source and Destination cities. However, determining the specific route required to qualify for the bonus is problematic. First of all, except when the cities are directly aligned on either a North/South or East/West axis, it is likely that the Source-to-Destination route and the Destination-to-Source routes will be different.

    Road and Rail bonuses are also used in determining the value of ongoing trade routes. For trade routes each city uses the Source-to-Destination route originating with itself. However, in determining the Road and Rail component of the TransportationBonus, it is the Destination-to-Source route that is used. This is somewhat obtuse and limits the value and frequency of this bonus.

    The Airport bonus is applied when both cities have an Airport improvement. If the cities are on the same continent, the Airport bonus is 50%. If the cities are on different continents the bonus is 100%. There is no bonus if only one city has an airport.

    The Superhighways bonus is 50% if only one city has the improvement and 100% if both cities have them. Additionally, of course, Superhighways will increase the BaseTrade of a city substantially, which in turn will increase the Base Payment calculated in Step 3. So Superhighways can appear to produce more than a 50% increase.

    All applicable transport bonuses are added together to determine the TransportationBonus which is then applied to the result from Step 7.
    Some examples:

    a) Two cities on the same continent, one has superhighways: 50% bonus = multiplier of 3/2.
    b) Two cities connected by railroad via the qualified route, one has superhighways: 150% bonus (rail + SH) = multiplier of 5/2.
    c) Two cities on different continents, both have airports and superhighways: 200% bonus = multiplier of 3.

    Step 9) Determine and apply the AgeModifier. The AgeModifier uses 4 key technologies to determine if your civilization is in the Ancient, Renaissance, Industrial, or Modern Age. Since it is possible, via trading with other civs, to acquire later techs without earlier ones, each of the following checks is made in sequence and the modifier applied appropriately.

    Invention and Navigation are used to determine if your civ has progressed from Ancient to Renaissance. If you have acquired neither of these technologies and have not yet passed the 200 turns mark, the amount calculated from Steps 1-8 is doubled.

    If your civ has acquired Railroad, your transition to the Industrial Age causes the payment amount to be reduced by one third. Unlike other modifiers, the 1/3 penalty is applied by dividing the Payment by 3 and then subtracting the result from the Payment. For example, one third of 17 is determined using integer math to be 5
    and the applied penalty results in a payment of 12.

    Flight signifies your civ's entry into the Modern Age and causes another 1/3 reduction penalty.

    Step 10) Apply the ScienceCap. Delivery of a caravan/freight produces not only a cash payment but, in addition, an equal number of beakers are added to your current research. The Delivery Payment, as calculated in steps 1-9, cannot exceed 2/3 of the total beaker cost (determined at the moment of delivery) of your current research if that cost exceeds 300 beakers. Prior to the 300 beaker point, the ScienceCap is 200 plus a random amount between 0 and 10. At lower tech acquisition levels, it is possible for a single caravan delivery payment to provide more beakers than the total cost of current research. The state of progress of your current research has no effect on the ScienceCap which is based solely on the total cost of research. Whether you need 1 more beaker or the total amount, you will receive all the beakers of the Delivery Payment up to the ScienceCap.
    Last edited by samson; October 17, 2002, 16:21.

  • #2
    I was just about to search for a thread like this, Have not read it all yet but it looks promising so far,
    /Chofritz

    Comment


    • #3
      samson,

      There was another post earlier today asking about this. If this was done just this afternoon in response, I'm very impressed!

      Seriously, one question I have is about Space Flight and whether or not it affects payouts. They really seem to tank after I discover Space Flight. Is this just my imagination, or has anyone else noticed this, too?

      Comment


      • #4
        I'm well impressed!

        You sound very difinitive - are there any areas of question left or are these all now proven facts?

        SG[1]
        "Our words are backed by empty wine bottles! - SG(2)
        "One of our Scouse Gits is missing." - -Jrabbit

        Comment


        • #5
          Step 8 Road and railroad bonus
          the road(RR) connection must be at the optimal path.
          (you can check the optimal path by using air units or units with flag threat all squares as road)

          Bonus is lost if the distance between cities exceeds 22 squares (If the same calculating algorithm is used as the algorithm from the go to command.

          Enemy units at the optimal path also avert these bonuses.

          Comment


          • #6
            Originally posted by Thoddy
            ...the optimal path....
            (you can check the optimal path by using air units or units with flag threat all squares as road)
            The Optimal Path... never understood why my caravans would travel through the woods /unroaded) when there is a fully developed railroad in the next square...
            googol... this is a number!
            "Silence Ming. I will let you know when I feel you are needed." - HappySunShine
            "Classic Eyes...But in reality, it works the other way around." - Ming

            Comment


            • #7
              SG - I believe this describes the algorithm used in the latest patched versions of Civ2. I have used it to correctly predict the exact amount of hundreds of deliveries in test and game situations that employ all combinations of factors. If anyone has a counter-example, please post the save here ... I will investigate it.

              Solo- I've had this sitting around for awhile. It just seemed to be an apt time to post it.

              Thoddy-

              The so called "optimal path" (Source-to-Destination) is used for determining whether to apply the ongoing Trade Route bonus. But for the Road/Railroad portion of the Delivery Bonus, it is the Destination-to-Source path which is used and this is usually not the same. While this is also an "optimal" path, it is chosen from the Destination City's POV, which is harder to determine when that city is foreign.

              Yes, both the trade-route and delivery Road/Railroad bonus are lost if non-allied foreign units occupy the path. They don't even have to be "enemies" per se. Peaceful, but non-allied units disrupt the route also.

              As for the 22 maximum squares, I have not seen this. In fact, I have a counterexample in my test suite. On a SMALL map, I have a city at a distance of 24 which does receive the Road/Rail bonus. I will investigate further to see if there is a maximum distance and whether it is dependent on other factors. Do you have example of this limit you could post as a save?

              Sometimes an "optimal" path does not exist, if it is disrupted by a lake, for example.

              There is another Road/Railroad bonus anomaly. Sometimes the road/railroad does not even need to be complete between the two cities. If a third city belonging to the same civ as the Source city is located along the "optimal" path and the road/railroad is complete between this city and the Destination city, the extension of the road from the intervening city to the Source city is not required. In other words, the Delivery Bonus algorithm seems to check for an "optimal" road/railroad from the Destination to Source but stops as soon as it encounters any city from the Source city's civ. This means a cheaper way of gaining the road/rail bonus for Delivery Payments is to build a city two squares from the Destination City on the optimal path and complete only that portion of the road/railroad. I can't claim that this always works but I know it works sometimes. And the distance to the Source city can be much greater than the distance to the intervening city. Note: this works for the Delivery Bonus and the Destination City's Trade Route bonus. It does not work for the Source City's Trade Route bonus.
              Last edited by samson; October 17, 2002, 11:46.

              Comment


              • #8
                Excel file

                I threw together this excel file a few minutes ago, it calculates the payoff. It's not very easy to use but If you have read samsons post you should be able to use it.

                The file was created on my macintosh and sometimes such files can not be opened on other computers, I'll give it a try anyway, please report any bugs in this thread. If there is any intrests I'll make it more user friendly.

                Since xls files are not accepted here I'll rename it .txt just change it to excel-format before you try to open it.

                I also have a question for samson:

                If the it is a salt-caravan should it be treated like undemanded goods (it is not in your list of commodities)? My experience say that it should give a 100% bonus but I could be wrong.


                If can open the file please report it here.
                Attached Files
                /Chofritz

                Comment


                • #9
                  Chofritz,

                  Yes, Salt when demanded receives 2x bonus, same as Hides, Beads. etc. Sorry about the omission, I'll edit the post.

                  As for your spread-sheet, a couple of things:

                  You've got the Airport bonus backwards. Different continents is 2, same continent should be 1.

                  Your Mapsizefactor cell treats an entry of 5/4 as a date. In any case, you shouldn't prompt for this value anyway. Just calculate the factor from the Circumference value entered into cell G1.

                  Also, it would be much more user-friendly, if you simply asked for the Commodity by name and whether it was demanded or not, then calculated the bonus.

                  Finally, the Gold Payment and the Science Payment are always the same. Sorry, if I didn't make that clear. If anyone has a counterexample to this claim, please post it.

                  Comment


                  • #10
                    Ok, thanks for your replies. Here is an improved version. Tell me if there is anything I missed to fix or if there are any bugs.
                    Attached Files
                    /Chofritz

                    Comment


                    • #11
                      Looks much better.

                      The only thing that is off a bit, is how you apply the 1/3 penalty for the discovery of Railroad and Flight. You are multiplying by 0.6667.

                      The algorithm used by the game calculates the 1/3 penalty by dividing the total-so-far by 3 (dropping the remainder) and then subtracting this penalty amount from the total-so-far. Your answer is sometimes off by 1 or 2 because of your approximation of the algorithm. You're so close, you might as well fix it and get the perfect answer.

                      Nice job, Chofritz.

                      Comment


                      • #12
                        Thoddy -

                        Okay, I see what you're talking about 22 squares. This isn't that same thing as a 'distance' of 22 the way the trade algorithm calculates distance.

                        If I place CityB 22 squares away from CityA in an exact NW direction connected by road, I get the road bonus. If I place it 23 squares away, I don't get the bonus. In this direction, 23 squares is a distance of 23.

                        However, if CityB is 16 squares away directly West, its distance is 24 and the road/railroad bonus is obtained.

                        So distance between points for calculation of trade is different than that used by the GOTO algorithm. Yet another bit of road/railroad funkiness.

                        Comment


                        • #13
                          Re: Calculating Caravan and Freight Delivery Payments

                          Originally posted by samson

                          Step 2) Add the base trade of the two cities. The base trade of a city is determined in the City Display by subtracting any existing trade routes from the total number of trade arrows shown for the city. For a foreign city, the base trade can only be accurately known by investigating the city with a diplomat or spy. However, an estimate can be made from the city size, type of government, and knowledge of the terrain surrounding the city.
                          So all city improvements and wonders count toward base trade, just not the trade routes?

                          I have found it very difficult to estimate foreign cities improvements, which could throw the total estimate way off. Just because they have the tech, they may not build it. Safest course is the dip/spy visit. Course, early in the game, can you afford to lose that many dips?

                          Comment


                          • #14
                            So all city improvements and wonders count toward base trade, just not the trade routes?
                            There is only one city improvement and one wonder that affect base trade: Superhighways and Colossus.

                            Colossus adds one trade arrow to each city square which is already producing at least one arrow, including the city center. This is the same effect that Republic and Democracy (and celebrating Monarchy, Commie, Fundy) governments have on a city.

                            Superhighways increases the trade of all squares which have roads or railroads by 50%. This is on a per square basis uses Civ2 integer math. Thus, a square with just one trade arrow is not improved by Superhighways, it must have at least two arrows to benefit. Also, remember that SH only effects squares with roads ... ocean squares or trade specials WITHOUT roads will not benefit. Despite these limitation, Superhighways is one of the most important city improvements in the game. In addition to increasing base trade, it also increases caravan delivery payments and the value of ongoing trade routes by 50%.


                            I have found it very difficult to estimate foreign cities improvements. Just because they have the tech, they may not build it. Safest course is the dip/spy visit. Course, early in the game, can you afford to lose that many dips
                            There's only two that affect trade bonuses: Superhighways and Airports, and neither of these appear early in the game. You only need to estimate the destination city's base trade.

                            Comment


                            • #15
                              Ok I have changed the formula so that it will always give the exact result. I also have a question that is abit off topic:

                              Earlier today I tried to get the maximum possible gold out of a delivery. But I encountered a problem, my research cost would limit me at 38xx(do not remember exact numbers) gold. What I did next was to enter cheatmode giving myself 100 future techs to increase the research cost but it didn't move, is there a maximum research cost?

                              BTW, the settings were large map and diety.

                              And I also wonder how big integers civ can handel since with all the tradebonuses the delivery would give me 0 gold which can't be right,
                              Attached Files
                              /Chofritz

                              Comment

                              Working...
                              X