260 { |
260 { |
261 assert(e >= ROAD_ENGINES_INDEX && e < ROAD_ENGINES_INDEX + lengthof(_road_vehicle_info)); |
261 assert(e >= ROAD_ENGINES_INDEX && e < ROAD_ENGINES_INDEX + lengthof(_road_vehicle_info)); |
262 return &_road_vehicle_info[e - ROAD_ENGINES_INDEX]; |
262 return &_road_vehicle_info[e - ROAD_ENGINES_INDEX]; |
263 } |
263 } |
264 |
264 |
265 /************************************************************************ |
|
266 * Engine Replacement stuff |
|
267 ************************************************************************/ |
|
268 |
|
269 struct EngineRenew; |
|
270 /** |
|
271 * Memory pool for engine renew elements. DO NOT USE outside of engine.c. Is |
|
272 * placed here so the only exception to this rule, the saveload code, can use |
|
273 * it. |
|
274 */ |
|
275 DECLARE_OLD_POOL(EngineRenew, EngineRenew, 3, 8000) |
|
276 |
|
277 /** |
|
278 * Struct to store engine replacements. DO NOT USE outside of engine.c. Is |
|
279 * placed here so the only exception to this rule, the saveload code, can use |
|
280 * it. |
|
281 */ |
|
282 struct EngineRenew : PoolItem<EngineRenew, EngineRenewID, &_EngineRenew_pool> { |
|
283 EngineID from; |
|
284 EngineID to; |
|
285 EngineRenew *next; |
|
286 GroupID group_id; |
|
287 |
|
288 EngineRenew(EngineID from = INVALID_ENGINE, EngineID to = INVALID_ENGINE) : from(from), to(to), next(NULL) {} |
|
289 ~EngineRenew() { this->from = INVALID_ENGINE; } |
|
290 |
|
291 inline bool IsValid() const { return this->from != INVALID_ENGINE; } |
|
292 }; |
|
293 |
|
294 #define FOR_ALL_ENGINE_RENEWS_FROM(er, start) for (er = GetEngineRenew(start); er != NULL; er = (er->index + 1U < GetEngineRenewPoolSize()) ? GetEngineRenew(er->index + 1U) : NULL) if (er->IsValid()) |
|
295 #define FOR_ALL_ENGINE_RENEWS(er) FOR_ALL_ENGINE_RENEWS_FROM(er, 0) |
|
296 |
|
297 |
|
298 /** |
|
299 * A list to group EngineRenew directives together (such as per-player). |
|
300 */ |
|
301 typedef EngineRenew* EngineRenewList; |
|
302 |
|
303 /** |
|
304 * Remove all engine replacement settings for the player. |
|
305 * @param erl The renewlist for a given player. |
|
306 * @return The new renewlist for the player. |
|
307 */ |
|
308 void RemoveAllEngineReplacement(EngineRenewList *erl); |
|
309 |
|
310 /** |
|
311 * Retrieve the engine replacement in a given renewlist for an original engine type. |
|
312 * @param erl The renewlist to search in. |
|
313 * @param engine Engine type to be replaced. |
|
314 * @return The engine type to replace with, or INVALID_ENGINE if no |
|
315 * replacement is in the list. |
|
316 */ |
|
317 EngineID EngineReplacement(EngineRenewList erl, EngineID engine, GroupID group); |
|
318 |
|
319 /** |
|
320 * Add an engine replacement to the given renewlist. |
|
321 * @param erl The renewlist to add to. |
|
322 * @param old_engine The original engine type. |
|
323 * @param new_engine The replacement engine type. |
|
324 * @param flags The calling command flags. |
|
325 * @return 0 on success, CMD_ERROR on failure. |
|
326 */ |
|
327 CommandCost AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, uint32 flags); |
|
328 |
|
329 /** |
|
330 * Remove an engine replacement from a given renewlist. |
|
331 * @param erl The renewlist from which to remove the replacement |
|
332 * @param engine The original engine type. |
|
333 * @param flags The calling command flags. |
|
334 * @return 0 on success, CMD_ERROR on failure. |
|
335 */ |
|
336 CommandCost RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, GroupID group, uint32 flags); |
|
337 |
|
338 /** When an engine is made buildable or is removed from being buildable, add/remove it from the build/autoreplace lists |
|
339 * @param type The type of engine |
|
340 */ |
|
341 void AddRemoveEngineFromAutoreplaceAndBuildWindows(VehicleType type); |
|
342 |
|
343 /* Engine list manipulators - current implementation is only C wrapper of CBlobT<EngineID> class (helpers.cpp) */ |
265 /* Engine list manipulators - current implementation is only C wrapper of CBlobT<EngineID> class (helpers.cpp) */ |
344 void EngList_Create(EngineList *el); ///< Creates engine list |
266 void EngList_Create(EngineList *el); ///< Creates engine list |
345 void EngList_Destroy(EngineList *el); ///< Deallocate and destroy engine list |
267 void EngList_Destroy(EngineList *el); ///< Deallocate and destroy engine list |
346 uint EngList_Count(const EngineList *el); ///< Returns number of items in the engine list |
268 uint EngList_Count(const EngineList *el); ///< Returns number of items in the engine list |
347 void EngList_Add(EngineList *el, EngineID eid); ///< Append one item at the end of engine list |
269 void EngList_Add(EngineList *el, EngineID eid); ///< Append one item at the end of engine list |