+ for other[Edens] = addr[Edens] + 1; other[Edens] < dims[Edens]; other[Edens]++ {
+ for other[Location] = 0; other[Location] < dims[Location]; other[Location]++ {
+ UpdateCell(table, my_index, EncodeIndex(dims, other), 0)
+ }
+ }
+ other[Location] = addr[Location]
+ other[Edens] = addr[Edens]
+}
+
+func FillCellBySelling(data planet_data, dims []int, table []State, addr []int) {
+ if addr[Hold] > 0 {
+ // Can't sell and still have cargo
+ return
+ }
+ if addr[UnusedCargo] > 0 {
+ // Can't sell everything and still have 'unused' holds
+ return
+ }
+ my_index := EncodeIndex(dims, addr)
+ other := make([]int, NumDimensions)
+ copy(other, addr)
+ planet := data.i2p[addr[Location]]
+ for other[Hold] = 0; other[Hold] < dims[Hold]; other[Hold]++ {
+ commodity := data.i2c[other[Hold]]
+ if !data.Commodities[commodity].CanSell {
+ // TODO: Dump cargo
+ continue
+ }
+ relative_price, available := data.Planets[planet].RelativePrices[commodity]
+ if !available {
+ continue
+ }
+ base_price := data.Commodities[commodity].BasePrice
+ absolute_price := float64(base_price) * float64(relative_price) / 100.0
+ sell_price := int(absolute_price * 0.9)
+
+ for other[UnusedCargo] = 0; other[UnusedCargo] < dims[UnusedCargo]; other[UnusedCargo]++ {
+
+ quantity := *hold - (other[UnusedCargo] + other[Cloaks] + other[Edens])
+ sale_value := quantity * sell_price
+ UpdateCell(table, my_index, EncodeIndex(dims, other), sale_value)
+ }
+ }
+ other[UnusedCargo] = addr[UnusedCargo]
+}
+
+func FillCellByBuying(data planet_data, dims []int, table []State, addr []int) {
+ if addr[Hold] == 0 {
+ // Can't buy and then have nothing
+ return
+ }
+ my_index := EncodeIndex(dims, addr)
+ other := make([]int, NumDimensions)
+ copy(other, addr)
+ planet := data.i2p[addr[Location]]
+ commodity := data.i2c[addr[Hold]]
+ if !data.Commodities[commodity].CanSell {
+ return
+ }
+ relative_price, available := data.Planets[planet].RelativePrices[commodity]
+ if !available {
+ return
+ }
+ base_price := data.Commodities[commodity].BasePrice
+ absolute_price := int(float64(base_price) * float64(relative_price) / 100.0)
+ quantity := *hold - (addr[UnusedCargo] + addr[Cloaks] + addr[Edens])
+ total_price := quantity * absolute_price
+ other[Hold] = 0
+ other[UnusedCargo] = 0
+ UpdateCell(table, my_index, EncodeIndex(dims, other), -total_price)
+ other[UnusedCargo] = addr[UnusedCargo]
+ other[Hold] = addr[Hold]
+}
+
+func FillCellByMisc(data planet_data, dims []int, table []State, addr []int) {
+ my_index := EncodeIndex(dims, addr)
+ other := make([]int, NumDimensions)
+ copy(other, addr)