equal
deleted
inserted
replaced
29 { |
29 { |
30 Order *order; |
30 Order *order; |
31 |
31 |
32 /* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
32 /* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
33 * TODO - This is just a temporary stage, this will be removed. */ |
33 * TODO - This is just a temporary stage, this will be removed. */ |
34 for (order = GetOrder(start_item); order != NULL; order = (order->index + 1 < GetOrderPoolSize()) ? GetOrder(order->index + 1) : NULL) order->index = start_item++; |
34 for (order = GetOrder(start_item); order != NULL; order = (order->index + 1U < GetOrderPoolSize()) ? GetOrder(order->index + 1U) : NULL) order->index = start_item++; |
35 } |
35 } |
36 |
36 |
37 /* Initialize the order-pool */ |
37 DEFINE_POOL(Order, Order, OrderPoolNewBlock, NULL) |
38 MemoryPool _order_pool = { "Orders", ORDER_POOL_MAX_BLOCKS, ORDER_POOL_BLOCK_SIZE_BITS, sizeof(Order), &OrderPoolNewBlock, NULL, 0, 0, NULL }; |
|
39 |
38 |
40 /** |
39 /** |
41 * |
40 * |
42 * Unpacks a order from savegames made with TTD(Patch) |
41 * Unpacks a order from savegames made with TTD(Patch) |
43 * |
42 * |
120 { |
119 { |
121 Order *order; |
120 Order *order; |
122 |
121 |
123 /* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
122 /* We don't use FOR_ALL here, because FOR_ALL skips invalid items. |
124 * TODO - This is just a temporary stage, this will be removed. */ |
123 * TODO - This is just a temporary stage, this will be removed. */ |
125 for (order = GetOrder(0); order != NULL; order = (order->index + 1 < GetOrderPoolSize()) ? GetOrder(order->index + 1) : NULL) { |
124 for (order = GetOrder(0); order != NULL; order = (order->index + 1U < GetOrderPoolSize()) ? GetOrder(order->index + 1U) : NULL) { |
126 if (!IsValidOrder(order)) { |
125 if (!IsValidOrder(order)) { |
127 OrderID index = order->index; |
126 OrderID index = order->index; |
128 |
127 |
129 memset(order, 0, sizeof(*order)); |
128 memset(order, 0, sizeof(*order)); |
130 order->index = index; |
129 order->index = index; |
135 return order; |
134 return order; |
136 } |
135 } |
137 } |
136 } |
138 |
137 |
139 /* Check if we can add a block to the pool */ |
138 /* Check if we can add a block to the pool */ |
140 if (AddBlockToPool(&_order_pool)) return AllocateOrder(); |
139 if (AddBlockToPool(&_Order_pool)) return AllocateOrder(); |
141 |
140 |
142 return NULL; |
141 return NULL; |
143 } |
142 } |
144 |
143 |
145 /** |
144 /** |
1176 return false; |
1175 return false; |
1177 } |
1176 } |
1178 |
1177 |
1179 void InitializeOrders(void) |
1178 void InitializeOrders(void) |
1180 { |
1179 { |
1181 CleanPool(&_order_pool); |
1180 CleanPool(&_Order_pool); |
1182 AddBlockToPool(&_order_pool); |
1181 AddBlockToPool(&_Order_pool); |
1183 |
1182 |
1184 _backup_orders_tile = 0; |
1183 _backup_orders_tile = 0; |
1185 } |
1184 } |
1186 |
1185 |
1187 static const SaveLoad _order_desc[] = { |
1186 static const SaveLoad _order_desc[] = { |
1225 assert (len <= lengthof(orders)); |
1224 assert (len <= lengthof(orders)); |
1226 |
1225 |
1227 SlArray(orders, len, SLE_UINT16); |
1226 SlArray(orders, len, SLE_UINT16); |
1228 |
1227 |
1229 for (i = 0; i < len; ++i) { |
1228 for (i = 0; i < len; ++i) { |
1230 if (!AddBlockIfNeeded(&_order_pool, i)) |
1229 if (!AddBlockIfNeeded(&_Order_pool, i)) |
1231 error("Orders: failed loading savegame: too many orders"); |
1230 error("Orders: failed loading savegame: too many orders"); |
1232 |
1231 |
1233 AssignOrder(GetOrder(i), UnpackVersion4Order(orders[i])); |
1232 AssignOrder(GetOrder(i), UnpackVersion4Order(orders[i])); |
1234 } |
1233 } |
1235 } else if (CheckSavegameVersionOldStyle(5, 2)) { |
1234 } else if (CheckSavegameVersionOldStyle(5, 2)) { |
1239 assert (len <= lengthof(orders)); |
1238 assert (len <= lengthof(orders)); |
1240 |
1239 |
1241 SlArray(orders, len, SLE_UINT32); |
1240 SlArray(orders, len, SLE_UINT32); |
1242 |
1241 |
1243 for (i = 0; i < len; ++i) { |
1242 for (i = 0; i < len; ++i) { |
1244 if (!AddBlockIfNeeded(&_order_pool, i)) |
1243 if (!AddBlockIfNeeded(&_Order_pool, i)) |
1245 error("Orders: failed loading savegame: too many orders"); |
1244 error("Orders: failed loading savegame: too many orders"); |
1246 |
1245 |
1247 AssignOrder(GetOrder(i), UnpackOrder(orders[i])); |
1246 AssignOrder(GetOrder(i), UnpackOrder(orders[i])); |
1248 } |
1247 } |
1249 } |
1248 } |
1260 int index; |
1259 int index; |
1261 |
1260 |
1262 while ((index = SlIterateArray()) != -1) { |
1261 while ((index = SlIterateArray()) != -1) { |
1263 Order *order; |
1262 Order *order; |
1264 |
1263 |
1265 if (!AddBlockIfNeeded(&_order_pool, index)) |
1264 if (!AddBlockIfNeeded(&_Order_pool, index)) |
1266 error("Orders: failed loading savegame: too many orders"); |
1265 error("Orders: failed loading savegame: too many orders"); |
1267 |
1266 |
1268 order = GetOrder(index); |
1267 order = GetOrder(index); |
1269 SlObject(order, _order_desc); |
1268 SlObject(order, _order_desc); |
1270 } |
1269 } |