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

Function CmdSetCompanyColour

src/company_cmd.cpp:1094–1171  ·  view source on GitHub ↗

* Change the company's company-colour * @param flags operation to perform * @param scheme scheme to set * @param primary set first/second colour * @param colour new colour for vehicles, property, etc. * @return the cost of this operation or an error */

Source from the content-addressed store, hash-verified

1092 * @return the cost of this operation or an error
1093 */
1094CommandCost CmdSetCompanyColour(DoCommandFlags flags, LiveryScheme scheme, bool primary, Colours colour)
1095{
1096 if (scheme >= LS_END || (colour >= COLOUR_END && colour != INVALID_COLOUR)) return CMD_ERROR;
1097
1098 /* Default scheme can't be reset to invalid. */
1099 if (scheme == LS_DEFAULT && colour == INVALID_COLOUR) return CMD_ERROR;
1100
1101 Company *c = Company::Get(_current_company);
1102
1103 /* Ensure no two companies have the same primary colour */
1104 if (scheme == LS_DEFAULT && primary) {
1105 for (const Company *cc : Company::Iterate()) {
1106 if (cc != c && cc->colour == colour) return CMD_ERROR;
1107 }
1108 }
1109
1110 if (flags.Test(DoCommandFlag::Execute)) {
1111 if (primary) {
1112 if (scheme != LS_DEFAULT) c->livery[scheme].in_use.Set(Livery::Flag::Primary, colour != INVALID_COLOUR);
1113 if (colour == INVALID_COLOUR) colour = c->livery[LS_DEFAULT].colour1;
1114 c->livery[scheme].colour1 = colour;
1115
1116 /* If setting the first colour of the default scheme, adjust the
1117 * original and cached company colours too. */
1118 if (scheme == LS_DEFAULT) {
1119 UpdateCompanyLiveries(c);
1120 _company_colours[_current_company] = colour;
1121 c->colour = colour;
1122 CompanyAdminUpdate(c);
1123 }
1124 } else {
1125 if (scheme != LS_DEFAULT) c->livery[scheme].in_use.Set(Livery::Flag::Secondary, colour != INVALID_COLOUR);
1126 if (colour == INVALID_COLOUR) colour = c->livery[LS_DEFAULT].colour2;
1127 c->livery[scheme].colour2 = colour;
1128
1129 if (scheme == LS_DEFAULT) {
1130 UpdateCompanyLiveries(c);
1131 }
1132 }
1133
1134 if (c->livery[scheme].in_use.Any({Livery::Flag::Primary, Livery::Flag::Secondary})) {
1135 /* If enabling a scheme, set the default scheme to be in use too */
1136 c->livery[LS_DEFAULT].in_use.Set(Livery::Flag::Primary);
1137 } else {
1138 /* Else loop through all schemes to see if any are left enabled.
1139 * If not, disable the default scheme too. */
1140 c->livery[LS_DEFAULT].in_use.Reset({Livery::Flag::Primary, Livery::Flag::Secondary});
1141 for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
1142 if (c->livery[scheme].in_use.Any({Livery::Flag::Primary, Livery::Flag::Secondary})) {
1143 c->livery[LS_DEFAULT].in_use.Set(Livery::Flag::Primary);
1144 break;
1145 }
1146 }
1147 }
1148
1149 ResetVehicleColourMap();
1150 MarkWholeScreenDirty();
1151

Callers

nothing calls this directly

Calls 13

UpdateCompanyLiveriesFunction · 0.85
CompanyAdminUpdateFunction · 0.85
ResetVehicleColourMapFunction · 0.85
MarkWholeScreenDirtyFunction · 0.85
BuildOwnerLegendFunction · 0.85
UpdateObjectColoursFunction · 0.85
CommandCostClass · 0.85
TestMethod · 0.80
AnyMethod · 0.80
InvalidateNewGRFCacheMethod · 0.80
InvalidateWindowDataFunction · 0.70
SetMethod · 0.45

Tested by

no test coverage detected