mirror of https://github.com/OpenTTD/OpenTTD
Codechange: use ReferenceThroughBaseContainer for containers that are index by CompanyID
parent
1ffc950e22
commit
5401ab1f7b
|
@ -51,7 +51,7 @@ void UpdateObjectColours(const Company *c);
|
|||
|
||||
CompanyID _local_company; ///< Company controlled by the human player at this client. Can also be #COMPANY_SPECTATOR.
|
||||
CompanyID _current_company; ///< Company currently doing an action.
|
||||
Colours _company_colours[MAX_COMPANIES]; ///< NOSAVE: can be determined from company structs.
|
||||
ReferenceThroughBaseContainer<std::array<Colours, MAX_COMPANIES>> _company_colours; ///< NOSAVE: can be determined from company structs.
|
||||
CompanyManagerFace _company_manager_face; ///< for company manager face storage in openttd.cfg
|
||||
uint _cur_company_tick_index; ///< used to generate a name for one company that doesn't have a name yet per tick
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ CommandCost CheckTileOwnership(TileIndex tile);
|
|||
extern CompanyID _local_company;
|
||||
extern CompanyID _current_company;
|
||||
|
||||
extern Colours _company_colours[MAX_COMPANIES];
|
||||
extern ReferenceThroughBaseContainer<std::array<Colours, MAX_COMPANIES>> _company_colours;
|
||||
extern CompanyManagerFace _company_manager_face;
|
||||
|
||||
/**
|
||||
|
|
|
@ -100,7 +100,7 @@ const ScoreInfo _score_info[] = {
|
|||
{ 0, 0} // SCORE_TOTAL
|
||||
};
|
||||
|
||||
int64_t _score_part[MAX_COMPANIES][SCORE_END];
|
||||
ReferenceThroughBaseContainer<std::array<std::array<int64_t, SCORE_END>, MAX_COMPANIES>> _score_part;
|
||||
Economy _economy;
|
||||
Prices _price;
|
||||
static PriceMultipliers _price_base_multiplier;
|
||||
|
@ -203,7 +203,7 @@ int UpdateCompanyRatingAndValue(Company *c, bool update)
|
|||
Owner owner = c->index;
|
||||
int score = 0;
|
||||
|
||||
memset(_score_part[owner], 0, sizeof(_score_part[owner]));
|
||||
_score_part[owner] = {};
|
||||
|
||||
/* Count vehicles */
|
||||
{
|
||||
|
|
|
@ -23,7 +23,7 @@ void ResetPriceBaseMultipliers();
|
|||
void SetPriceBaseMultiplier(Price price, int factor);
|
||||
|
||||
extern const ScoreInfo _score_info[];
|
||||
extern int64_t _score_part[MAX_COMPANIES][SCORE_END];
|
||||
extern ReferenceThroughBaseContainer<std::array<std::array<int64_t, SCORE_END>, MAX_COMPANIES>> _score_part;
|
||||
extern Economy _economy;
|
||||
/* Prices and also the fractional part. */
|
||||
extern Prices _price;
|
||||
|
|
|
@ -407,8 +407,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyEconomy()
|
|||
NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyStats()
|
||||
{
|
||||
/* Fetch the latest version of the stats. */
|
||||
NetworkCompanyStats company_stats[MAX_COMPANIES];
|
||||
NetworkPopulateCompanyStats(company_stats);
|
||||
NetworkCompanyStatsArray company_stats = NetworkGetCompanyStats();
|
||||
|
||||
/* Go through all the companies. */
|
||||
for (const Company *company : Company::Iterate()) {
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
// #define DEBUG_FAILED_DUMP_COMMANDS
|
||||
|
||||
#include "network_type.h"
|
||||
#include "../core/convertible_through_base.hpp"
|
||||
#include "../console_type.h"
|
||||
#include "../gfx_type.h"
|
||||
#include "../openttd.h"
|
||||
|
@ -44,7 +45,8 @@ void NetworkDisconnect(bool close_admins = true);
|
|||
void NetworkGameLoop();
|
||||
void NetworkBackgroundLoop();
|
||||
std::string_view ParseFullConnectionString(const std::string &connection_string, uint16_t &port, CompanyID *company_id = nullptr);
|
||||
void NetworkPopulateCompanyStats(NetworkCompanyStats *stats);
|
||||
using NetworkCompanyStatsArray = ReferenceThroughBaseContainer<std::array<NetworkCompanyStats, MAX_COMPANIES>>;
|
||||
NetworkCompanyStatsArray NetworkGetCompanyStats();
|
||||
|
||||
void NetworkUpdateClientInfo(ClientID client_id);
|
||||
void NetworkClientsToSpectators(CompanyID cid);
|
||||
|
|
|
@ -1485,12 +1485,11 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_MOVE(Packet &p)
|
|||
}
|
||||
|
||||
/**
|
||||
* Populate the company stats.
|
||||
* @param stats the stats to update
|
||||
* Get the company stats.
|
||||
*/
|
||||
void NetworkPopulateCompanyStats(NetworkCompanyStats *stats)
|
||||
NetworkCompanyStatsArray NetworkGetCompanyStats()
|
||||
{
|
||||
memset(stats, 0, sizeof(*stats) * MAX_COMPANIES);
|
||||
NetworkCompanyStatsArray stats = {};
|
||||
|
||||
/* Go through all vehicles and count the type of vehicles */
|
||||
for (const Vehicle *v : Vehicle::Iterate()) {
|
||||
|
@ -1518,6 +1517,8 @@ void NetworkPopulateCompanyStats(NetworkCompanyStats *stats)
|
|||
if (s->facilities.Test(StationFacility::Dock)) npi->num_station[NETWORK_VEH_SHIP]++;
|
||||
}
|
||||
}
|
||||
|
||||
return stats;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -347,7 +347,7 @@ bool ScriptObject::DoCommandProcessResult(const CommandCost &res, Script_Suspend
|
|||
}
|
||||
|
||||
|
||||
/* static */ Randomizer ScriptObject::random_states[OWNER_END];
|
||||
/* static */ ScriptObject::RandomizerArray ScriptObject::random_states;
|
||||
|
||||
Randomizer &ScriptObject::GetRandomizer(Owner owner)
|
||||
{
|
||||
|
|
|
@ -330,7 +330,8 @@ private:
|
|||
static std::tuple<bool, bool, bool, bool> DoCommandPrep();
|
||||
static bool DoCommandProcessResult(const CommandCost &res, Script_SuspendCallbackProc *callback, bool estimate_only, bool asynchronous);
|
||||
static CommandCallbackData *GetDoCommandCallback();
|
||||
static Randomizer random_states[OWNER_END]; ///< Random states for each of the scripts (game script uses OWNER_DEITY)
|
||||
using RandomizerArray = ReferenceThroughBaseContainer<std::array<Randomizer, OWNER_END>>;
|
||||
static RandomizerArray random_states; ///< Random states for each of the scripts (game script uses OWNER_DEITY)
|
||||
};
|
||||
|
||||
namespace ScriptObjectInternal {
|
||||
|
|
|
@ -602,7 +602,7 @@ struct GameSettings {
|
|||
ConstructionSettings construction; ///< construction of things in-game
|
||||
AISettings ai; ///< what may the AI do?
|
||||
ScriptSettings script; ///< settings for scripts
|
||||
class AIConfig *ai_config[MAX_COMPANIES]; ///< settings per company
|
||||
ReferenceThroughBaseContainer<std::array<class AIConfig *, MAX_COMPANIES>> ai_config; ///< settings per company
|
||||
class GameConfig *game_config; ///< settings for gamescript
|
||||
PathfinderSettings pf; ///< settings for all pathfinders
|
||||
OrderSettings order; ///< settings related to orders
|
||||
|
|
|
@ -181,7 +181,7 @@ static IndustryType _smallmap_industry_highlight = IT_INVALID;
|
|||
/** State of highlight blinking */
|
||||
static bool _smallmap_industry_highlight_state;
|
||||
/** For connecting company ID to position in owner list (small map legend) */
|
||||
static uint _company_to_list_pos[MAX_COMPANIES];
|
||||
static ReferenceThroughBaseContainer<std::array<uint32_t, MAX_COMPANIES>> _company_to_list_pos;
|
||||
|
||||
/**
|
||||
* Fills an array for the industries legends.
|
||||
|
|
|
@ -4426,8 +4426,8 @@ uint MoveGoodsToStation(CargoType type, uint amount, Source source, const Statio
|
|||
return UpdateStationWaiting(first_station, type, amount, source);
|
||||
}
|
||||
|
||||
uint company_best[OWNER_NONE + 1] = {}; // best rating for each company, including OWNER_NONE
|
||||
uint company_sum[OWNER_NONE + 1] = {}; // sum of ratings for each company
|
||||
ReferenceThroughBaseContainer<std::array<uint32_t, OWNER_END>> company_best = {}; // best rating for each company, including OWNER_NONE
|
||||
ReferenceThroughBaseContainer<std::array<uint32_t, OWNER_END>> company_sum = {}; // sum of ratings for each company
|
||||
uint best_rating = 0;
|
||||
uint best_sum = 0; // sum of best ratings for each company
|
||||
|
||||
|
|
|
@ -69,10 +69,10 @@ struct Town : TownPool::PoolItem<&_town_pool> {
|
|||
|
||||
/* Company ratings. */
|
||||
CompanyMask have_ratings; ///< which companies have a rating
|
||||
uint8_t unwanted[MAX_COMPANIES]; ///< how many months companies aren't wanted by towns (bribe)
|
||||
ReferenceThroughBaseContainer<std::array<uint8_t, MAX_COMPANIES>> unwanted; ///< how many months companies aren't wanted by towns (bribe)
|
||||
CompanyID exclusivity; ///< which company has exclusivity
|
||||
uint8_t exclusive_counter; ///< months till the exclusivity expires
|
||||
int16_t ratings[MAX_COMPANIES]; ///< ratings of each company for this town
|
||||
ReferenceThroughBaseContainer<std::array<int16_t, MAX_COMPANIES>> ratings; ///< ratings of each company for this town
|
||||
|
||||
TransportedCargoStat<uint32_t> supplied[NUM_CARGO]; ///< Cargo statistics about supplied cargo.
|
||||
TransportedCargoStat<uint16_t> received[NUM_TAE]; ///< Cargo statistics about received cargotypes.
|
||||
|
|
Loading…
Reference in New Issue