* Pointers cannot be saved to a savegame, so this functions gets * the index of the item, and if not available, it hussles with * pointers (looks really bad :() * Remember that a nullptr item has value 0, and all * indices have +1, so vehicle 0 is saved as index 1. * @param obj The object that we want to get the index of * @param rt SLRefType type of the object the index is being sought of
| 1224 | * @return Return the pointer converted to an index of the type pointed to |
| 1225 | */ |
| 1226 | static size_t ReferenceToInt(const void *obj, SLRefType rt) |
| 1227 | { |
| 1228 | assert(_sl.action == SLA_SAVE); |
| 1229 | |
| 1230 | if (obj == nullptr) return 0; |
| 1231 | |
| 1232 | switch (rt) { |
| 1233 | case REF_VEHICLE_OLD: // Old vehicles we save as new ones |
| 1234 | case REF_VEHICLE: return ((const Vehicle*)obj)->index + 1; |
| 1235 | case REF_STATION: return ((const Station*)obj)->index + 1; |
| 1236 | case REF_TOWN: return ((const Town*)obj)->index + 1; |
| 1237 | case REF_ROADSTOPS: return ((const RoadStop*)obj)->index + 1; |
| 1238 | case REF_ENGINE_RENEWS: return ((const EngineRenew*)obj)->index + 1; |
| 1239 | case REF_CARGO_PACKET: return ((const CargoPacket*)obj)->index + 1; |
| 1240 | case REF_ORDERLIST: return ((const OrderList*)obj)->index + 1; |
| 1241 | case REF_STORAGE: return ((const PersistentStorage*)obj)->index + 1; |
| 1242 | case REF_LINK_GRAPH: return ((const LinkGraph*)obj)->index + 1; |
| 1243 | case REF_LINK_GRAPH_JOB: return ((const LinkGraphJob*)obj)->index + 1; |
| 1244 | default: NOT_REACHED(); |
| 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | /** |
| 1249 | * Pointers cannot be loaded from a savegame, so this function |
no test coverage detected