1
0
Fork 0

POC of more companies

pull/12767/head
Andrii Dokhniak 2024-05-30 20:24:55 +02:00
parent d7eb29d292
commit 143581b9e0
7 changed files with 38 additions and 92 deletions

View File

@ -44,7 +44,7 @@ enum CargoCompanyBits {
CCB_CARGO_TYPE_START = 19, ///< Start bit of the cargo type field.
CCB_CARGO_TYPE_LENGTH = 6, ///< Number of bits of the cargo type field.
CCB_COMPANY_START = 25, ///< Start bit of the company field.
CCB_COMPANY_LENGTH = 4, ///< Number of bits of the company field.
CCB_COMPANY_LENGTH = 8, ///< Number of bits of the company field.
};
static_assert(NUM_CARGO <= (1 << CCB_CARGO_TYPE_LENGTH));

View File

@ -7,6 +7,7 @@
/** @file company_cmd.cpp Handling of companies. */
#include "gfx_type.h"
#include "stdafx.h"
#include "company_base.h"
#include "company_func.h"
@ -448,27 +449,6 @@ bad_town_name:;
}
}
/** Sorting weights for the company colours. */
static const uint8_t _colour_sort[COLOUR_END] = {2, 2, 3, 2, 3, 2, 3, 2, 3, 2, 2, 2, 3, 1, 1, 1};
/** Similar colours, so we can try to prevent same coloured companies. */
static const Colours _similar_colour[COLOUR_END][2] = {
{ COLOUR_BLUE, COLOUR_LIGHT_BLUE }, // COLOUR_DARK_BLUE
{ COLOUR_GREEN, COLOUR_DARK_GREEN }, // COLOUR_PALE_GREEN
{ INVALID_COLOUR, INVALID_COLOUR }, // COLOUR_PINK
{ COLOUR_ORANGE, INVALID_COLOUR }, // COLOUR_YELLOW
{ INVALID_COLOUR, INVALID_COLOUR }, // COLOUR_RED
{ COLOUR_DARK_BLUE, COLOUR_BLUE }, // COLOUR_LIGHT_BLUE
{ COLOUR_PALE_GREEN, COLOUR_DARK_GREEN }, // COLOUR_GREEN
{ COLOUR_PALE_GREEN, COLOUR_GREEN }, // COLOUR_DARK_GREEN
{ COLOUR_DARK_BLUE, COLOUR_LIGHT_BLUE }, // COLOUR_BLUE
{ COLOUR_BROWN, COLOUR_ORANGE }, // COLOUR_CREAM
{ COLOUR_PURPLE, INVALID_COLOUR }, // COLOUR_MAUVE
{ COLOUR_MAUVE, INVALID_COLOUR }, // COLOUR_PURPLE
{ COLOUR_YELLOW, COLOUR_CREAM }, // COLOUR_ORANGE
{ COLOUR_CREAM, INVALID_COLOUR }, // COLOUR_BROWN
{ COLOUR_WHITE, INVALID_COLOUR }, // COLOUR_GREY
{ COLOUR_GREY, INVALID_COLOUR }, // COLOUR_WHITE
};
/**
* Generate a company colour.
@ -476,53 +456,13 @@ static const Colours _similar_colour[COLOUR_END][2] = {
*/
static Colours GenerateCompanyColour()
{
Colours colours[COLOUR_END];
int num_colours = COLOUR_END - COLOUR_BEGIN;
/* Initialize array */
for (uint i = 0; i < COLOUR_END; i++) colours[i] = static_cast<Colours>(i);
/* And randomize it */
for (uint i = 0; i < 100; i++) {
uint r = Random();
Swap(colours[GB(r, 0, 4)], colours[GB(r, 4, 4)]);
int companies = 0;
for (const Company *_ : Company::Iterate()) {
companies++;
}
/* Bubble sort it according to the values in table 1 */
for (uint i = 0; i < COLOUR_END; i++) {
for (uint j = 1; j < COLOUR_END; j++) {
if (_colour_sort[colours[j - 1]] < _colour_sort[colours[j]]) {
Swap(colours[j - 1], colours[j]);
}
}
}
/* Move the colours that look similar to each company's colour to the side */
for (const Company *c : Company::Iterate()) {
Colours pcolour = c->colour;
for (uint i = 0; i < COLOUR_END; i++) {
if (colours[i] == pcolour) {
colours[i] = INVALID_COLOUR;
break;
}
}
for (uint j = 0; j < 2; j++) {
Colours similar = _similar_colour[pcolour][j];
if (similar == INVALID_COLOUR) break;
for (uint i = 1; i < COLOUR_END; i++) {
if (colours[i - 1] == similar) Swap(colours[i - 1], colours[i]);
}
}
}
/* Return the first available colour */
for (uint i = 0; i < COLOUR_END; i++) {
if (colours[i] != INVALID_COLOUR) return colours[i];
}
NOT_REACHED();
return Colours(companies % num_colours);
}
/**

View File

@ -18,21 +18,27 @@
enum Owner : uint8_t {
/* All companies below MAX_COMPANIES are playable
* companies, above, they are special, computer controlled 'companies' */
OWNER_BEGIN = 0x00, ///< First owner
COMPANY_FIRST = 0x00, ///< First company, same as owner
MAX_COMPANIES = 0x0F, ///< Maximum number of companies
OWNER_TOWN = 0x0F, ///< A town owns the tile, or a town is expanding
OWNER_NONE = 0x10, ///< The tile has no ownership
OWNER_WATER = 0x11, ///< The tile/execution is done by "water"
OWNER_DEITY = 0x12, ///< The object is owned by a superuser / goal script
OWNER_BEGIN = 0x00, ///< First owner
COMPANY_FIRST = 0x00, ///< First company, same as owner
MAX_COMPANIES = 0xF0, ///< Maximum number of companies
OLD_MAX_COMPANIES = 0x0F, ///< Maximum number of companies
OWNER_TOWN = 0xF1, ///< A town owns the tile, or a town is expanding
OLD_OWNER_TOWN = 0x0F,
OWNER_NONE = 0xF2, ///< The tile has no ownership
OLD_OWNER_NONE = 0x10, ///< The tile has no ownership
OWNER_WATER = 0xF3, ///< The tile/execution is done by "water"
OLD_OWNER_WATER = 0x11, ///< The tile/execution is done by "water"
OWNER_DEITY = 0xF4, ///< The object is owned by a superuser / goal script
OWNER_END, ///< Last + 1 owner
INVALID_OWNER = 0xFF, ///< An invalid owner
INVALID_COMPANY = 0xFF, ///< An invalid company
INVALID_OWNER = 0xFF, ///< An invalid owner
INVALID_COMPANY = 0xFF, ///< An invalid company
/* 'Fake' companies used for networks */
COMPANY_INACTIVE_CLIENT = 253, ///< The client is joining
COMPANY_NEW_COMPANY = 254, ///< The client wants a new company
COMPANY_SPECTATOR = 255, ///< The client is spectating
COMPANY_INACTIVE_CLIENT = 0xF7, ///< The client is joining
COMPANY_NEW_COMPANY = 0xF8, ///< The client wants a new company
COMPANY_SPECTATOR = 0xF9, ///< The client is spectating
};
DECLARE_POSTFIX_INCREMENT(Owner)
DECLARE_ENUM_AS_ADDABLE(Owner)

View File

@ -166,7 +166,7 @@ struct ValuesInterval {
struct BaseGraphWindow : Window {
protected:
static const int GRAPH_MAX_DATASETS = 64;
static const int GRAPH_MAX_DATASETS = 300;
static const int GRAPH_BASE_COLOUR = GREY_SCALE(2);
static const int GRAPH_GRID_COLOUR = GREY_SCALE(3);
static const int GRAPH_AXIS_LINE_COLOUR = GREY_SCALE(1);

View File

@ -656,7 +656,7 @@ bool AfterLoadGame()
* walk through the whole map.. */
if (IsSavegameVersionBefore(SLV_4, 3)) {
for (auto t : Map::Iterate()) {
if (IsTileType(t, MP_WATER) && GetTileOwner(t) >= MAX_COMPANIES) {
if (IsTileType(t, MP_WATER) && GetTileOwner(t) >= OLD_MAX_COMPANIES) {
SetTileOwner(t, OWNER_WATER);
}
}
@ -986,7 +986,7 @@ bool AfterLoadGame()
case MP_ROAD:
t.m4() |= (t.m2() << 4);
if ((GB(t.m5(), 4, 2) == ROAD_TILE_CROSSING ? (Owner)t.m3() : GetTileOwner(t)) == OWNER_TOWN) {
if ((GB(t.m5(), 4, 2) == ROAD_TILE_CROSSING ? (Owner)t.m3() : GetTileOwner(t)) == OLD_OWNER_TOWN) {
SetTownIndex(t, CalcClosestTownFromTile(t)->index);
} else {
SetTownIndex(t, 0);
@ -1151,7 +1151,7 @@ bool AfterLoadGame()
Owner o = GetTileOwner(t);
SB(t.m7(), 0, 5, o); // road owner
SB(t.m3(), 4, 4, o == OWNER_NONE ? OWNER_TOWN : o); // tram owner
SB(t.m3(), 4, 4, o == OLD_OWNER_NONE ? OWNER_TOWN : o); // tram owner
}
SB(t.m6(), 2, 4, GB(t.m2(), 4, 4)); // bridge type
SB(t.m7(), 5, 1, GB(t.m4(), 7, 1)); // snow/desert
@ -1213,7 +1213,7 @@ bool AfterLoadGame()
GetRailType(t)
);
} else {
TownID town = IsTileOwner(t, OWNER_TOWN) ? ClosestTownFromTile(t, UINT_MAX)->index : 0;
TownID town = IsTileOwner(t, OLD_OWNER_TOWN) ? ClosestTownFromTile(t, UINT_MAX)->index : 0;
/* MakeRoadNormal */
SetTileType(t, MP_ROAD);
@ -1568,7 +1568,7 @@ bool AfterLoadGame()
* be OWNER_NONE. So replace OWNER_NONE with OWNER_WATER. */
if (IsSavegameVersionBefore(SLV_46)) {
for (Waypoint *wp : Waypoint::Iterate()) {
if ((wp->facilities & FACIL_DOCK) != 0 && IsTileOwner(wp->xy, OWNER_NONE) && TileHeight(wp->xy) == 0) SetTileOwner(wp->xy, OWNER_WATER);
if ((wp->facilities & FACIL_DOCK) != 0 && IsTileOwner(wp->xy, OLD_OWNER_NONE) && TileHeight(wp->xy) == 0) SetTileOwner(wp->xy, OWNER_WATER);
}
}
@ -1865,7 +1865,7 @@ bool AfterLoadGame()
if (IsBuoyTile(t) || IsDriveThroughStopTile(t) || IsTileType(t, MP_WATER)) {
Owner o = GetTileOwner(t);
if (o < MAX_COMPANIES && !Company::IsValidID(o)) {
if (o < OLD_MAX_COMPANIES && !Company::IsValidID(o)) {
Backup<CompanyID> cur_company(_current_company, o);
ChangeTileOwner(t, o, INVALID_OWNER);
cur_company.Restore();
@ -1880,7 +1880,7 @@ bool AfterLoadGame()
for (RoadTramType rtt : _roadtramtypes) {
/* update even non-existing road types to update tile owner too */
Owner o = GetRoadOwner(t, rtt);
if (o < MAX_COMPANIES && !Company::IsValidID(o)) SetRoadOwner(t, rtt, OWNER_NONE);
if (o < OLD_MAX_COMPANIES && !Company::IsValidID(o)) SetRoadOwner(t, rtt, OWNER_NONE);
}
if (IsLevelCrossing(t)) {
if (!Company::IsValidID(GetTileOwner(t))) FixOwnerOfRailTrack(t);
@ -1996,7 +1996,7 @@ bool AfterLoadGame()
/* signs with invalid owner left from older savegames */
for (Sign *si : Sign::Iterate()) {
if (si->owner != OWNER_NONE && !Company::IsValidID(si->owner)) si->owner = OWNER_NONE;
if (si->owner != OLD_OWNER_NONE && !Company::IsValidID(si->owner)) si->owner = OWNER_NONE;
}
/* Station can get named based on an industry type, but the current ones
@ -2025,7 +2025,7 @@ bool AfterLoadGame()
for (Town *t : Town::Iterate()) {
if (t->have_ratings == 0xFF) t->have_ratings = MAX_UVALUE(CompanyMask);
for (uint i = 8; i != MAX_COMPANIES; i++) t->ratings[i] = RATING_INITIAL;
for (uint i = 8; i != OLD_MAX_COMPANIES; i++) t->ratings[i] = RATING_INITIAL;
}
}
@ -2474,7 +2474,7 @@ bool AfterLoadGame()
if (IsSavegameVersionBefore(SLV_148)) {
for (Object *o : Object::Iterate()) {
Owner owner = GetTileOwner(o->location.tile);
o->colour = (owner == OWNER_NONE) ? static_cast<Colours>(GB(Random(), 0, 4)) : Company::Get(owner)->livery->colour1;
o->colour = (owner == OLD_OWNER_NONE) ? static_cast<Colours>(GB(Random(), 0, 4)) : Company::Get(owner)->livery->colour1;
}
}

View File

@ -62,7 +62,7 @@ struct SIGNChunkHandler : ChunkHandler {
}
/* Signs placed in scenario editor shall now be OWNER_DEITY */
if (IsSavegameVersionBefore(SLV_171) && si->owner == OWNER_NONE && _file_to_saveload.abstract_ftype == FT_SCENARIO) {
if (IsSavegameVersionBefore(SLV_171) && si->owner == OLD_OWNER_NONE && _file_to_saveload.abstract_ftype == FT_SCENARIO) {
si->owner = OWNER_DEITY;
}
}

View File

@ -7,6 +7,7 @@
/** @file vehiclelist.cpp Lists of vehicles. */
#include "cargomonitor.h"
#include "stdafx.h"
#include "train.h"
#include "vehicle_func.h"
@ -23,7 +24,6 @@
uint32_t VehicleListIdentifier::Pack() const
{
uint8_t c = this->company == OWNER_NONE ? 0xF : (uint8_t)this->company;
assert(c < (1 << 4));
assert(this->vtype < (1 << 2));
assert(this->index < (1 << 20));
assert(this->type < VLT_END);