if (scheme == LS_DEFAULT && colour == INVALID_COLOUR) return CMD_ERROR;
Company *c = Company::Get(_current_company);
/* Ensure no two companies have the same primary colour */
if (scheme == LS_DEFAULT && primary) {
for (const Company *cc : Company::Iterate()) {
if (cc != c && cc->colour == colour) return CMD_ERROR;
}
}
if (flags & DC_EXEC) {
if (primary) {
if (scheme != LS_DEFAULT) SB(c->livery[scheme].in_use, 0, 1, colour != INVALID_COLOUR);
if (colour == INVALID_COLOUR) colour = (Colours)c->livery[LS_DEFAULT].colour1;
c->livery[scheme].colour1 = colour;
/* If setting the first colour of the default scheme, adjust the
* original and cached company colours too. */
if (scheme == LS_DEFAULT) {
for (int i = 1; i < LS_END; i++) {
if (!HasBit(c->livery[i].in_use, 0)) c->livery[i].colour1 = colour;
}
UpdateCompanyLiveries(c);
_company_colours[_current_company] = colour;
c->colour = colour;
CompanyAdminUpdate(c);
}
} else {
if (scheme != LS_DEFAULT) SB(c->livery[scheme].in_use, 1, 1, colour != INVALID_COLOUR);
if (colour == INVALID_COLOUR) colour = (Colours)c->livery[LS_DEFAULT].colour2;
c->livery[scheme].colour2 = colour;
if (scheme == LS_DEFAULT) {
for (int i = 1; i < LS_END; i++) {
if (!HasBit(c->livery[i].in_use, 1)) c->livery[i].colour2 = colour;
}
UpdateCompanyGroupLiveries(c);
}
}
if (c->livery[scheme].in_use != 0) {
/* If enabling a scheme, set the default scheme to be in use too */
c->livery[LS_DEFAULT].in_use = 1;
} else {
/* Else loop through all schemes to see if any are left enabled.
* If not, disable the default scheme too. */
c->livery[LS_DEFAULT].in_use = 0;
for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
if (c->livery[scheme].in_use != 0) {
c->livery[LS_DEFAULT].in_use = 1;
break;
}
}
}
ResetVehicleColourMap();
MarkWholeScreenDirty();
/* All graph related to companies use the company colour. */
InvalidateWindowData(WC_INCOME_GRAPH, 0);
InvalidateWindowData(WC_OPERATING_PROFIT, 0);
src/company_func.h
➞
Show inline comments
@@ -3,48 +3,49 @@
* 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/>.
*/
/** @file company_func.h Functions related to companies. */