mirror of https://github.com/OpenTTD/OpenTTD.git
Compare commits
5 Commits
7c33af7f47
...
7eeafa98a7
Author | SHA1 | Date |
---|---|---|
Jonathan G Rennison | 7eeafa98a7 | |
Peter Nelson | bf8de188ec | |
Peter Nelson | 72c55128d2 | |
Peter Nelson | a6d401debf | |
Jonathan G Rennison | 9403013a2c |
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "../stdafx.h"
|
#include "../stdafx.h"
|
||||||
#include "demands.h"
|
#include "demands.h"
|
||||||
|
#include "../core/math_func.hpp"
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
#include "../safeguards.h"
|
#include "../safeguards.h"
|
||||||
|
@ -207,23 +208,26 @@ void DemandCalculator::CalcDemand(LinkGraphJob &job, Tscaler scaler)
|
||||||
int32_t supply = scaler.EffectiveSupply(job[from_id], job[to_id]);
|
int32_t supply = scaler.EffectiveSupply(job[from_id], job[to_id]);
|
||||||
assert(supply > 0);
|
assert(supply > 0);
|
||||||
|
|
||||||
/* Scale the distance by mod_dist around max_distance */
|
constexpr int32_t divisor_scale = 16;
|
||||||
int32_t distance = this->max_distance - (this->max_distance -
|
|
||||||
(int32_t)DistanceMaxPlusManhattan(job[from_id].base.xy, job[to_id].base.xy)) *
|
int32_t scaled_distance = this->base_distance;
|
||||||
this->mod_dist / 100;
|
if (this->mod_dist > 0) {
|
||||||
|
const int32_t distance = DistanceMaxPlusManhattan(job[from_id].base.xy, job[to_id].base.xy);
|
||||||
|
/* Scale distance around base_distance by (mod_dist * (100 / 1024)).
|
||||||
|
* mod_dist may be > 1024, so clamp result to be non-negative */
|
||||||
|
scaled_distance = std::max(0, this->base_distance + (((distance - this->base_distance) * this->mod_dist) / 1024));
|
||||||
|
}
|
||||||
|
|
||||||
/* Scale the accuracy by distance around accuracy / 2 */
|
/* Scale the accuracy by distance around accuracy / 2 */
|
||||||
int32_t divisor = this->accuracy * (this->mod_dist - 50) / 100 +
|
const int32_t divisor = divisor_scale + ((this->accuracy * scaled_distance * divisor_scale) / (this->base_distance * 2));
|
||||||
this->accuracy * distance / this->max_distance + 1;
|
assert(divisor >= divisor_scale);
|
||||||
|
|
||||||
assert(divisor > 0);
|
|
||||||
|
|
||||||
uint demand_forw = 0;
|
uint demand_forw = 0;
|
||||||
if (divisor <= supply) {
|
if (divisor <= (supply * divisor_scale)) {
|
||||||
/* At first only distribute demand if
|
/* At first only distribute demand if
|
||||||
* effective supply / accuracy divisor >= 1
|
* effective supply / accuracy divisor >= 1
|
||||||
* Others are too small or too far away to be considered. */
|
* Others are too small or too far away to be considered. */
|
||||||
demand_forw = supply / divisor;
|
demand_forw = (supply * divisor_scale) / divisor;
|
||||||
} else if (++chance > this->accuracy * num_demands * num_supplies) {
|
} else if (++chance > this->accuracy * num_demands * num_supplies) {
|
||||||
/* After some trying, if there is still supply left, distribute
|
/* After some trying, if there is still supply left, distribute
|
||||||
* demand also to other nodes. */
|
* demand also to other nodes. */
|
||||||
|
@ -256,7 +260,7 @@ void DemandCalculator::CalcDemand(LinkGraphJob &job, Tscaler scaler)
|
||||||
* @param job Job to calculate the demands for.
|
* @param job Job to calculate the demands for.
|
||||||
*/
|
*/
|
||||||
DemandCalculator::DemandCalculator(LinkGraphJob &job) :
|
DemandCalculator::DemandCalculator(LinkGraphJob &job) :
|
||||||
max_distance(DistanceMaxPlusManhattan(TileXY(0,0), TileXY(Map::MaxX(), Map::MaxY())))
|
base_distance(IntSqrt(DistanceMaxPlusManhattan(TileXY(0,0), TileXY(Map::MaxX(), Map::MaxY()))))
|
||||||
{
|
{
|
||||||
const LinkGraphSettings &settings = job.Settings();
|
const LinkGraphSettings &settings = job.Settings();
|
||||||
CargoID cargo = job.Cargo();
|
CargoID cargo = job.Cargo();
|
||||||
|
@ -264,9 +268,15 @@ DemandCalculator::DemandCalculator(LinkGraphJob &job) :
|
||||||
this->accuracy = settings.accuracy;
|
this->accuracy = settings.accuracy;
|
||||||
this->mod_dist = settings.demand_distance;
|
this->mod_dist = settings.demand_distance;
|
||||||
if (this->mod_dist > 100) {
|
if (this->mod_dist > 100) {
|
||||||
/* Increase effect of mod_dist > 100 */
|
/* Increase effect of mod_dist > 100.
|
||||||
|
* Quadratic:
|
||||||
|
* 100 --> 100
|
||||||
|
* 150 --> 308
|
||||||
|
* 200 --> 933
|
||||||
|
* 255 --> 2102
|
||||||
|
*/
|
||||||
int over100 = this->mod_dist - 100;
|
int over100 = this->mod_dist - 100;
|
||||||
this->mod_dist = 100 + over100 * over100;
|
this->mod_dist = 100 + ((over100 * over100) / 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (settings.GetDistributionType(cargo)) {
|
switch (settings.GetDistributionType(cargo)) {
|
||||||
|
|
|
@ -14,7 +14,7 @@ public:
|
||||||
DemandCalculator(LinkGraphJob &job);
|
DemandCalculator(LinkGraphJob &job);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int32_t max_distance; ///< Maximum distance possible on the map.
|
int32_t base_distance; ///< Base distance for scaling purposes.
|
||||||
int32_t mod_dist; ///< Distance modifier, determines how much demands decrease with distance.
|
int32_t mod_dist; ///< Distance modifier, determines how much demands decrease with distance.
|
||||||
int32_t accuracy; ///< Accuracy of the calculation.
|
int32_t accuracy; ///< Accuracy of the calculation.
|
||||||
|
|
||||||
|
|
|
@ -4846,7 +4846,6 @@ static ChangeInfoResult RoadStopChangeInfo(uint id, int numinfo, int prop, ByteR
|
||||||
|
|
||||||
uint32_t classid = buf->ReadDWord();
|
uint32_t classid = buf->ReadDWord();
|
||||||
rs->cls_id = RoadStopClass::Allocate(BSWAP32(classid));
|
rs->cls_id = RoadStopClass::Allocate(BSWAP32(classid));
|
||||||
rs->spec_id = id + i;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -308,25 +308,15 @@ bool Convert8bitBooleanCallback(const struct GRFFile *grffile, uint16_t cbid, ui
|
||||||
*/
|
*/
|
||||||
template <size_t Tcnt>
|
template <size_t Tcnt>
|
||||||
struct GRFFilePropsBase {
|
struct GRFFilePropsBase {
|
||||||
GRFFilePropsBase() : local_id(0), grffile(nullptr)
|
uint16_t local_id = 0; ///< id defined by the grf file for this entity
|
||||||
{
|
const struct GRFFile *grffile = nullptr; ///< grf file that introduced this entity
|
||||||
/* The lack of some compilers to provide default constructors complying to the specs
|
std::array<const struct SpriteGroup *, Tcnt> spritegroup{}; ///< pointers to the different sprites of the entity
|
||||||
* requires us to zero the stuff ourself. */
|
|
||||||
memset(spritegroup, 0, sizeof(spritegroup));
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t local_id; ///< id defined by the grf file for this entity
|
|
||||||
const struct GRFFile *grffile; ///< grf file that introduced this entity
|
|
||||||
const struct SpriteGroup *spritegroup[Tcnt]; ///< pointer to the different sprites of the entity
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Data related to the handling of grf files. */
|
/** Data related to the handling of grf files. */
|
||||||
struct GRFFileProps : GRFFilePropsBase<1> {
|
struct GRFFileProps : GRFFilePropsBase<1> {
|
||||||
/** Set all default data constructor for the props. */
|
/** Set all default data constructor for the props. */
|
||||||
GRFFileProps(uint16_t subst_id = 0) :
|
constexpr GRFFileProps(uint16_t subst_id = 0) : subst_id(subst_id), override(subst_id) {}
|
||||||
GRFFilePropsBase<1>(), subst_id(subst_id), override(subst_id)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t subst_id;
|
uint16_t subst_id;
|
||||||
uint16_t override; ///< id of the entity been replaced by
|
uint16_t override; ///< id of the entity been replaced by
|
||||||
|
|
|
@ -53,7 +53,7 @@ const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, Eng
|
||||||
void SetCustomEngineSprites(EngineID engine, uint8_t cargo, const SpriteGroup *group)
|
void SetCustomEngineSprites(EngineID engine, uint8_t cargo, const SpriteGroup *group)
|
||||||
{
|
{
|
||||||
Engine *e = Engine::Get(engine);
|
Engine *e = Engine::Get(engine);
|
||||||
assert(cargo < lengthof(e->grf_prop.spritegroup));
|
assert(cargo < std::size(e->grf_prop.spritegroup));
|
||||||
|
|
||||||
if (e->grf_prop.spritegroup[cargo] != nullptr) {
|
if (e->grf_prop.spritegroup[cargo] != nullptr) {
|
||||||
GrfMsg(6, "SetCustomEngineSprites: engine {} cargo {} already has group -- replacing", engine, cargo);
|
GrfMsg(6, "SetCustomEngineSprites: engine {} cargo {} already has group -- replacing", engine, cargo);
|
||||||
|
@ -1062,7 +1062,7 @@ VehicleResolverObject::VehicleResolverObject(EngineID engine_type, const Vehicle
|
||||||
if (this->root_spritegroup == nullptr) {
|
if (this->root_spritegroup == nullptr) {
|
||||||
const Engine *e = Engine::Get(engine_type);
|
const Engine *e = Engine::Get(engine_type);
|
||||||
CargoID cargo = v != nullptr ? v->cargo_type : SpriteGroupCargo::SG_PURCHASE;
|
CargoID cargo = v != nullptr ? v->cargo_type : SpriteGroupCargo::SG_PURCHASE;
|
||||||
assert(cargo < lengthof(e->grf_prop.spritegroup));
|
assert(cargo < std::size(e->grf_prop.spritegroup));
|
||||||
this->root_spritegroup = e->grf_prop.spritegroup[cargo] != nullptr ? e->grf_prop.spritegroup[cargo] : e->grf_prop.spritegroup[SpriteGroupCargo::SG_DEFAULT];
|
this->root_spritegroup = e->grf_prop.spritegroup[cargo] != nullptr ? e->grf_prop.spritegroup[cargo] : e->grf_prop.spritegroup[SpriteGroupCargo::SG_DEFAULT];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,7 +127,6 @@ struct RoadStopSpec {
|
||||||
*/
|
*/
|
||||||
GRFFilePropsBase<NUM_CARGO + 3> grf_prop;
|
GRFFilePropsBase<NUM_CARGO + 3> grf_prop;
|
||||||
RoadStopClassID cls_id; ///< The class to which this spec belongs.
|
RoadStopClassID cls_id; ///< The class to which this spec belongs.
|
||||||
int spec_id; ///< The ID of this spec inside the class.
|
|
||||||
StringID name; ///< Name of this stop
|
StringID name; ///< Name of this stop
|
||||||
|
|
||||||
RoadStopAvailabilityType stop_type = ROADSTOPTYPE_ALL;
|
RoadStopAvailabilityType stop_type = ROADSTOPTYPE_ALL;
|
||||||
|
|
|
@ -504,7 +504,7 @@ uint32_t Waypoint::GetNewGRFVariable(const ResolverObject &, uint8_t variable, [
|
||||||
|
|
||||||
/* virtual */ const SpriteGroup *StationResolverObject::ResolveReal(const RealSpriteGroup *group) const
|
/* virtual */ const SpriteGroup *StationResolverObject::ResolveReal(const RealSpriteGroup *group) const
|
||||||
{
|
{
|
||||||
if (this->station_scope.st == nullptr || this->station_scope.statspec->cls_id == STAT_CLASS_WAYP) {
|
if (this->station_scope.st == nullptr || !Station::IsExpected(this->station_scope.st)) {
|
||||||
return group->loading[0];
|
return group->loading[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue