001package com.fs.starfarer.api.impl.campaign.econ;
002
003import com.fs.starfarer.api.Global;
004import com.fs.starfarer.api.campaign.econ.CommodityOnMarketAPI;
005
006public class CommodityIconCounts {
007
008        protected CommodityOnMarketAPI com;
009        
010        public int available;
011        public int production;
012        public int demand;
013        public int nonDemandExport;
014        public int deficit;
015        public int imports;
016        public int demandMetWithLocal;
017        public int demandMet;
018        public int globalExport;
019        public int inFactionOnlyExport;
020        public int canNotExport;
021        public int extra;
022
023        public CommodityIconCounts(CommodityOnMarketAPI com) {
024                this.com = com;
025                
026//              int shippingGlobal = CommodityMarketData.getShippingCapacity(com.getMarket(), false);
027//              int shippingInFaction = CommodityMarketData.getShippingCapacity(com.getMarket(), true);
028                int shippingGlobal = Global.getSettings().getShippingCapacity(com.getMarket(), false);
029                int shippingInFaction = Global.getSettings().getShippingCapacity(com.getMarket(), true);
030                
031//              if (com.getId().equals("food") && com.getMarket().getId().equals("jangala")) {
032//                      System.out.println("efwefwef");
033//              }
034                
035                available = com.getAvailable();
036                production = com.getMaxSupply();
037//              if (com.getCommodity().isPrimary()) {
038//                      List<CommodityOnMarket> withSameDemandClass = ((Market)com.getMarket()).getCommoditiesWithClass(com.getDemandClass());
039//                      for (CommodityOnMarket other : withSameDemandClass) {
040//                              if (com == other) continue;
041//                              production += other.getMaxSupply();
042//                      }
043//              }
044                production = Math.min(production, available);
045                        
046                int export = 0;
047                demand = com.getMaxDemand();
048                export = (int) Math.min(production, shippingGlobal);
049                
050                extra = available - Math.max(export, demand);
051                if (extra < 0) extra = 0;
052                
053                deficit = demand - available;
054                demandMet = Math.min(available, demand);
055                
056                demandMetWithLocal = Math.min(available, production) - extra;
057                //imports = available - production - extra;
058                imports = available - production;
059                
060                
061                nonDemandExport = 0;
062                if (demandMetWithLocal > demand && demand > 0) {
063                        nonDemandExport = demandMetWithLocal - demand;
064                        demandMetWithLocal = demand;
065                }
066                
067                globalExport = production;
068                inFactionOnlyExport = 0;
069                canNotExport = 0;
070                
071
072//              if (com.getMarket().getName().equals("Stral") && com.getId().equals(Commodities.SUPPLIES)) {
073//                      System.out.println("wefwefe");
074//              }
075                
076                if (globalExport > shippingGlobal) {
077                        inFactionOnlyExport = globalExport - shippingGlobal;
078                        globalExport = shippingGlobal;
079                }
080                if (globalExport + inFactionOnlyExport > shippingInFaction) {
081                        canNotExport = globalExport + inFactionOnlyExport - shippingInFaction;
082                        inFactionOnlyExport -= canNotExport;
083                }
084                
085                int aboveMax = Math.max(demandMetWithLocal, globalExport) + canNotExport + inFactionOnlyExport - (available - imports);
086                if (aboveMax > 0) {
087                        inFactionOnlyExport -= aboveMax;
088                        if (inFactionOnlyExport < 0) {
089                                canNotExport += inFactionOnlyExport;
090                        }
091                }
092                
093                
094                if (inFactionOnlyExport < 0) inFactionOnlyExport = 0;
095                if (canNotExport < 0) canNotExport = 0;
096                if (nonDemandExport < 0) nonDemandExport = 0;
097                if (imports < 0) imports = 0;
098                if (deficit < 0) deficit = 0;
099                if (demandMetWithLocal < 0) demandMetWithLocal = 0;
100        }
101        
102}
103
104
105
106
107
108
109
110