/** * Create a new company and sets all company variables default values * * @param is_ai is an AI company? * @param company CompanyID to use for the new company * @return the company struct */ Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY) { if (!Company::CanAllocateItem()) return NULL; /* we have to generate colour before this company is valid */ Colours colour = GenerateCompanyColour(); Company *c; if (company == INVALID_COMPANY) { c = new Company(STR_SV_UNNAMED, is_ai); } else { if (Company::IsValidID(company)) return NULL; c = new (company) Company(STR_SV_UNNAMED, is_ai); } c->colour = colour; ResetCompanyLivery(c); _company_colours[c->index] = (Colours)c->colour; c->money = c->current_loan = (100000ll * _economy.inflation_prices >> 16) / 50000 * 50000; c->share_owners[0] = c->share_owners[1] = c->share_owners[2] = c->share_owners[3] = INVALID_OWNER; c->avail_railtypes = GetCompanyRailtypes(c->index); c->avail_roadtypes = GetCompanyRoadtypes(c->index); c->inaugurated_year = _cur_year; RandomCompanyManagerFaceBits(c->face, (GenderEthnicity)Random(), false, false); // create a random company manager face SetDefaultCompanySettings(c->index); GeneratePresidentName(c); SetWindowDirty(WC_GRAPH_LEGEND, 0); SetWindowClassesDirty(WC_CLIENT_LIST_POPUP); SetWindowDirty(WC_CLIENT_LIST, 0); BuildOwnerLegend(); InvalidateWindowData(WC_SMALLMAP, 0, 1); if (is_ai && (!_networking || _network_server)) AI::StartNew(c->index); AI::BroadcastNewEvent(new ScriptEventCompanyNew(c->index), c->index); Game::NewEvent(new ScriptEventCompanyNew(c->index)); if (!is_ai) UpdateAllTownVirtCoords(); return c; }
/** * Change the company's company-colour * @param tile unused * @param flags operation to perform * @param p1 bitstuffed: * p1 bits 0-7 scheme to set * p1 bits 8-9 set in use state or first/second colour * @param p2 new colour for vehicles, property, etc. * @param text unused * @return the cost of this operation or an error */ CommandCost CmdSetCompanyColour(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { Colours colour = Extract<Colours, 0, 4>(p2); LiveryScheme scheme = Extract<LiveryScheme, 0, 8>(p1); byte state = GB(p1, 8, 2); if (scheme >= LS_END || state >= 3 || 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 && state == 0) { const Company *cc; FOR_ALL_COMPANIES(cc) { if (cc != c && cc->colour == colour) return CMD_ERROR; } } if (flags & DC_EXEC) { switch (state) { case 0: 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) { _company_colours[_current_company] = colour; c->colour = colour; CompanyAdminUpdate(c); } break; case 1: c->livery[scheme].colour2 = colour; break; case 2: c->livery[scheme].in_use = colour != 0; /* Now handle setting the default scheme's in_use flag. * This is different to the other schemes, as it signifies if any * scheme is active at all. If this flag is not set, then no * processing of vehicle types occurs at all, and only the default * colours will be used. */ /* If enabling a scheme, set the default scheme to be in use too */ if (colour != 0) { c->livery[LS_DEFAULT].in_use = true; break; } /* 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 = false; for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) { if (c->livery[scheme].in_use) { c->livery[LS_DEFAULT].in_use = true; break; } } break; default: break; } ResetVehicleColourMap(); MarkWholeScreenDirty(); /* All graph related to companies use the company colour. */ InvalidateWindowData(WC_INCOME_GRAPH, 0); InvalidateWindowData(WC_OPERATING_PROFIT, 0); InvalidateWindowData(WC_DELIVERED_CARGO, 0); InvalidateWindowData(WC_PERFORMANCE_HISTORY, 0); InvalidateWindowData(WC_COMPANY_VALUE, 0); /* The smallmap owner view also stores the company colours. */ BuildOwnerLegend(); InvalidateWindowData(WC_SMALLMAP, 0, 1); /* Company colour data is indirectly cached. */ Vehicle *v; FOR_ALL_VEHICLES(v) { if (v->owner == _current_company) v->InvalidateNewGRFCache(); } extern void UpdateObjectColours(const Company *c); UpdateObjectColours(c); } return CommandCost(); }