MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / Load

Method Load

src/saveload/order_sl.cpp:164–214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

162 ORDRChunkHandler() : ChunkHandler('ORDR', CH_READONLY) {}
163
164 void Load() const override
165 {
166 if (IsSavegameVersionBefore(SLV_5, 2)) {
167 /* Version older than 5.2 did not have a ->next pointer. Convert them
168 * (in the old days, the orderlist was 5000 items big) */
169 size_t len = SlGetFieldLength();
170
171 if (IsSavegameVersionBefore(SLV_5)) {
172 /* Pre-version 5 had another layout for orders
173 * (uint16_t instead of uint32_t) */
174 len /= sizeof(uint16_t);
175 std::vector<uint16_t> orders(len);
176
177 SlCopy(&orders[0], len, SLE_UINT16);
178
179 for (size_t i = 0; i < len; ++i) {
180 auto &item = AllocateOldOrder(i);
181 item.order.AssignOrder(UnpackVersion4Order(orders[i]));
182 }
183 } else if (IsSavegameVersionBefore(SLV_5, 2)) {
184 len /= sizeof(uint32_t);
185 std::vector<uint32_t> orders(len);
186
187 SlCopy(&orders[0], len, SLE_UINT32);
188
189 for (size_t i = 0; i < len; ++i) {
190 auto &item = AllocateOldOrder(i);
191 item.order = Order(GB(orders[i], 0, 8), GB(orders[i], 8, 8), GB(orders[i], 16, 16));
192 }
193 }
194
195 /* Update all the next pointer. The orders were built like this:
196 * While the order is valid, the previous order will get its next pointer set */
197 for (uint32_t num = 1; const OldOrderSaveLoadItem &item : _old_order_saveload_pool) {
198 if (!item.order.IsType(OT_NOTHING) && num > 1) {
199 OldOrderSaveLoadItem *prev = GetOldOrder(num - 1);
200 if (prev != nullptr) prev->next = num;
201 }
202 ++num;
203 }
204 } else {
205 const std::vector<SaveLoad> slt = SlCompatTableHeader(GetOrderDescription(), _order_sl_compat);
206
207 int index;
208
209 while ((index = SlIterateArray()) != -1) {
210 auto &item = AllocateOldOrder(index);
211 SlObject(&item, slt);
212 }
213 }
214 }
215};
216
217template <typename T>

Callers 1

LoadCheckMethod · 0.45

Calls 13

IsSavegameVersionBeforeFunction · 0.85
SlGetFieldLengthFunction · 0.85
SlCopyFunction · 0.85
UnpackVersion4OrderFunction · 0.85
GBFunction · 0.85
GetOldOrderFunction · 0.85
SlCompatTableHeaderFunction · 0.85
GetOrderDescriptionFunction · 0.85
SlIterateArrayFunction · 0.85
SlObjectFunction · 0.85
AssignOrderMethod · 0.80
IsTypeMethod · 0.80

Tested by

no test coverage detected