2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-01-07 09:19:53 +00:00
|
|
|
/** @file autoreplace_func.h Functions related to autoreplacing. */
|
|
|
|
|
|
|
|
#ifndef AUTOREPLACE_FUNC_H
|
|
|
|
#define AUTOREPLACE_FUNC_H
|
|
|
|
|
2010-01-15 16:41:15 +00:00
|
|
|
#include "command_type.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_base.h"
|
2008-01-07 09:19:53 +00:00
|
|
|
|
|
|
|
void RemoveAllEngineReplacement(EngineRenewList *erl);
|
2019-04-10 21:07:06 +00:00
|
|
|
EngineID EngineReplacement(EngineRenewList erl, EngineID engine, GroupID group, bool *replace_when_old = nullptr);
|
2012-04-17 19:44:02 +00:00
|
|
|
CommandCost AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, bool replace_when_old, DoCommandFlag flags);
|
2009-02-09 21:20:05 +00:00
|
|
|
CommandCost RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, GroupID group, DoCommandFlag flags);
|
2008-01-07 09:19:53 +00:00
|
|
|
|
|
|
|
/**
|
2008-09-30 20:39:50 +00:00
|
|
|
* Remove all engine replacement settings for the given company.
|
|
|
|
* @param c the company.
|
2008-01-07 09:19:53 +00:00
|
|
|
*/
|
2008-09-30 20:39:50 +00:00
|
|
|
static inline void RemoveAllEngineReplacementForCompany(Company *c)
|
2008-01-07 09:19:53 +00:00
|
|
|
{
|
2008-09-30 20:39:50 +00:00
|
|
|
RemoveAllEngineReplacement(&c->engine_renew_list);
|
2008-01-07 09:19:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-09-30 20:39:50 +00:00
|
|
|
* Retrieve the engine replacement for the given company and original engine type.
|
|
|
|
* @param c company.
|
2008-01-07 09:19:53 +00:00
|
|
|
* @param engine Engine type.
|
2009-09-19 09:51:14 +00:00
|
|
|
* @param group The group related to this replacement.
|
2012-04-17 19:44:02 +00:00
|
|
|
* @param[out] replace_when_old Set to true if the replacement should be done when old.
|
2008-01-07 09:19:53 +00:00
|
|
|
* @return The engine type to replace with, or INVALID_ENGINE if no
|
|
|
|
* replacement is in the list.
|
|
|
|
*/
|
2019-04-10 21:07:06 +00:00
|
|
|
static inline EngineID EngineReplacementForCompany(const Company *c, EngineID engine, GroupID group, bool *replace_when_old = nullptr)
|
2008-01-07 09:19:53 +00:00
|
|
|
{
|
2012-04-17 19:44:02 +00:00
|
|
|
return EngineReplacement(c->engine_renew_list, engine, group, replace_when_old);
|
2008-01-07 09:19:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-09-30 20:39:50 +00:00
|
|
|
* Check if a company has a replacement set up for the given engine.
|
|
|
|
* @param c Company.
|
2009-09-19 09:51:14 +00:00
|
|
|
* @param engine Engine type to be replaced.
|
|
|
|
* @param group The group related to this replacement.
|
2008-01-07 09:19:53 +00:00
|
|
|
* @return true if a replacement was set up, false otherwise.
|
|
|
|
*/
|
2008-09-30 20:39:50 +00:00
|
|
|
static inline bool EngineHasReplacementForCompany(const Company *c, EngineID engine, GroupID group)
|
2008-01-07 09:19:53 +00:00
|
|
|
{
|
2008-09-30 20:39:50 +00:00
|
|
|
return EngineReplacementForCompany(c, engine, group) != INVALID_ENGINE;
|
2008-01-07 09:19:53 +00:00
|
|
|
}
|
|
|
|
|
2012-04-17 19:44:02 +00:00
|
|
|
/**
|
|
|
|
* Check if a company has a replacement set up for the given engine when it gets old.
|
|
|
|
* @param c Company.
|
|
|
|
* @param engine Engine type to be replaced.
|
|
|
|
* @param group The group related to this replacement.
|
|
|
|
* @return True if a replacement when old was set up, false otherwise.
|
|
|
|
*/
|
|
|
|
static inline bool EngineHasReplacementWhenOldForCompany(const Company *c, EngineID engine, GroupID group)
|
|
|
|
{
|
|
|
|
bool replace_when_old;
|
|
|
|
EngineReplacement(c->engine_renew_list, engine, group, &replace_when_old);
|
|
|
|
return replace_when_old;
|
|
|
|
}
|
|
|
|
|
2008-01-07 09:19:53 +00:00
|
|
|
/**
|
2008-09-30 20:39:50 +00:00
|
|
|
* Add an engine replacement for the company.
|
|
|
|
* @param c Company.
|
2008-01-07 09:19:53 +00:00
|
|
|
* @param old_engine The original engine type.
|
|
|
|
* @param new_engine The replacement engine type.
|
2009-09-19 09:51:14 +00:00
|
|
|
* @param group The group related to this replacement.
|
2012-04-17 19:44:02 +00:00
|
|
|
* @param replace_when_old Replace when old or always?
|
2008-01-07 09:19:53 +00:00
|
|
|
* @param flags The calling command flags.
|
|
|
|
* @return 0 on success, CMD_ERROR on failure.
|
|
|
|
*/
|
2012-04-17 19:44:02 +00:00
|
|
|
static inline CommandCost AddEngineReplacementForCompany(Company *c, EngineID old_engine, EngineID new_engine, GroupID group, bool replace_when_old, DoCommandFlag flags)
|
2008-01-07 09:19:53 +00:00
|
|
|
{
|
2012-04-17 19:44:02 +00:00
|
|
|
return AddEngineReplacement(&c->engine_renew_list, old_engine, new_engine, group, replace_when_old, flags);
|
2008-01-07 09:19:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-09-30 20:39:50 +00:00
|
|
|
* Remove an engine replacement for the company.
|
|
|
|
* @param c Company.
|
2008-01-07 09:19:53 +00:00
|
|
|
* @param engine The original engine type.
|
2009-09-19 09:51:14 +00:00
|
|
|
* @param group The group related to this replacement.
|
2008-01-07 09:19:53 +00:00
|
|
|
* @param flags The calling command flags.
|
|
|
|
* @return 0 on success, CMD_ERROR on failure.
|
|
|
|
*/
|
2009-02-09 21:20:05 +00:00
|
|
|
static inline CommandCost RemoveEngineReplacementForCompany(Company *c, EngineID engine, GroupID group, DoCommandFlag flags)
|
2008-01-07 09:19:53 +00:00
|
|
|
{
|
2008-09-30 20:39:50 +00:00
|
|
|
return RemoveEngineReplacement(&c->engine_renew_list, engine, group, flags);
|
2008-01-07 09:19:53 +00:00
|
|
|
}
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
bool CheckAutoreplaceValidity(EngineID from, EngineID to, CompanyID company);
|
2008-08-10 15:02:21 +00:00
|
|
|
|
2008-01-07 09:19:53 +00:00
|
|
|
#endif /* AUTOREPLACE_FUNC_H */
|