mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-11 01:49:50 +00:00
(svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
This commit is contained in:
parent
44ddf033ed
commit
380d18fb69
@ -543,6 +543,7 @@ static void AiFindSubsidyPassengerRoute(FoundRoute *fr)
|
|||||||
static void AiFindRandomIndustryRoute(FoundRoute *fr)
|
static void AiFindRandomIndustryRoute(FoundRoute *fr)
|
||||||
{
|
{
|
||||||
Industry* i;
|
Industry* i;
|
||||||
|
const IndustrySpec *indsp;
|
||||||
uint32 r;
|
uint32 r;
|
||||||
CargoID cargo;
|
CargoID cargo;
|
||||||
|
|
||||||
@ -556,8 +557,9 @@ static void AiFindRandomIndustryRoute(FoundRoute *fr)
|
|||||||
if (i == NULL) return;
|
if (i == NULL) return;
|
||||||
|
|
||||||
// pick a random produced cargo
|
// pick a random produced cargo
|
||||||
cargo = i->produced_cargo[0];
|
indsp = GetIndustrySpec(i->type);
|
||||||
if (r & 1 && i->produced_cargo[1] != CT_INVALID) cargo = i->produced_cargo[1];
|
cargo = indsp->produced_cargo[0];
|
||||||
|
if (r & 1 && indsp->produced_cargo[1] != CT_INVALID) cargo = indsp->produced_cargo[1];
|
||||||
|
|
||||||
fr->cargo = cargo;
|
fr->cargo = cargo;
|
||||||
|
|
||||||
@ -567,12 +569,16 @@ static void AiFindRandomIndustryRoute(FoundRoute *fr)
|
|||||||
if (cargo != CT_GOODS && cargo != CT_FOOD) {
|
if (cargo != CT_GOODS && cargo != CT_FOOD) {
|
||||||
// pick a dest, and see if it can receive
|
// pick a dest, and see if it can receive
|
||||||
Industry* i2 = AiFindRandomIndustry();
|
Industry* i2 = AiFindRandomIndustry();
|
||||||
|
if (i2 == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (i2 == NULL || i == i2 || (
|
indsp = GetIndustrySpec(i2->type);
|
||||||
i2->accepts_cargo[0] != cargo &&
|
|
||||||
i2->accepts_cargo[1] != cargo &&
|
if (i == i2 ||
|
||||||
i2->accepts_cargo[2] != cargo)
|
(indsp->accepts_cargo[0] != cargo &&
|
||||||
) {
|
indsp->accepts_cargo[1] != cargo &&
|
||||||
|
indsp->accepts_cargo[2] != cargo)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -664,9 +670,10 @@ static bool AiCheckIfRouteIsGood(Player *p, FoundRoute *fr, byte bitmask)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const Industry* i = (const Industry*)fr->from;
|
const Industry* i = (const Industry*)fr->from;
|
||||||
|
const IndustrySpec *indsp = GetIndustrySpec(i->type);
|
||||||
|
|
||||||
if (i->pct_transported[fr->cargo != i->produced_cargo[0]] > 0x99 ||
|
if (i->pct_transported[fr->cargo != indsp->produced_cargo[0]] > 0x99 ||
|
||||||
i->total_production[fr->cargo != i->produced_cargo[0]] == 0) {
|
i->total_production[fr->cargo != indsp->produced_cargo[0]] == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -271,6 +271,7 @@ static bool AiNew_Check_City_or_Industry(Player *p, int ic, byte type)
|
|||||||
}
|
}
|
||||||
if (type == AI_INDUSTRY) {
|
if (type == AI_INDUSTRY) {
|
||||||
const Industry* i = GetIndustry(ic);
|
const Industry* i = GetIndustry(ic);
|
||||||
|
const IndustrySpec *indsp = GetIndustrySpec(i->type);
|
||||||
const Station* st;
|
const Station* st;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
@ -279,7 +280,7 @@ static bool AiNew_Check_City_or_Industry(Player *p, int ic, byte type)
|
|||||||
|
|
||||||
// No limits on delevering stations!
|
// No limits on delevering stations!
|
||||||
// Or for industry that does not give anything yet
|
// Or for industry that does not give anything yet
|
||||||
if (i->produced_cargo[0] == CT_INVALID || i->total_production[0] == 0) return true;
|
if (indsp->produced_cargo[0] == CT_INVALID || i->total_production[0] == 0) return true;
|
||||||
|
|
||||||
if (i->total_production[0] - i->total_transported[0] < AI_CHECKCITY_NEEDED_CARGO) return false;
|
if (i->total_production[0] - i->total_transported[0] < AI_CHECKCITY_NEEDED_CARGO) return false;
|
||||||
|
|
||||||
@ -302,13 +303,13 @@ static bool AiNew_Check_City_or_Industry(Player *p, int ic, byte type)
|
|||||||
// we want to know if this station gets the same good. If so,
|
// we want to know if this station gets the same good. If so,
|
||||||
// we want to know its rating. If it is too high, we are not going
|
// we want to know its rating. If it is too high, we are not going
|
||||||
// to build there
|
// to build there
|
||||||
if (i->produced_cargo[0] == CT_INVALID) continue;
|
if (indsp->produced_cargo[0] == CT_INVALID) continue;
|
||||||
// It does not take this cargo
|
// It does not take this cargo
|
||||||
if (!st->goods[i->produced_cargo[0]].last_speed) continue;
|
if (!st->goods[indsp->produced_cargo[0]].last_speed) continue;
|
||||||
// Is it around our industry
|
// Is it around our industry
|
||||||
if (DistanceManhattan(st->xy, i->xy) > 5) continue;
|
if (DistanceManhattan(st->xy, i->xy) > 5) continue;
|
||||||
// It does take this cargo.. what is his rating?
|
// It does take this cargo.. what is his rating?
|
||||||
if (st->goods[i->produced_cargo[0]].rating < AI_CHECKCITY_CARGO_RATING) continue;
|
if (st->goods[indsp->produced_cargo[0]].rating < AI_CHECKCITY_CARGO_RATING) continue;
|
||||||
j++;
|
j++;
|
||||||
// The rating is high.. a little chance that we still continue
|
// The rating is high.. a little chance that we still continue
|
||||||
// But if there are 2 stations of this size, we never go on...
|
// But if there are 2 stations of this size, we never go on...
|
||||||
@ -458,17 +459,19 @@ static void AiNew_State_LocateRoute(Player *p)
|
|||||||
}
|
}
|
||||||
} else if (p->ainew.tbt == AI_TRUCK) {
|
} else if (p->ainew.tbt == AI_TRUCK) {
|
||||||
const Industry* ind_from = GetIndustry(p->ainew.from_ic);
|
const Industry* ind_from = GetIndustry(p->ainew.from_ic);
|
||||||
|
const IndustrySpec *indsp_from = GetIndustrySpec(ind_from->type);
|
||||||
const Industry* ind_temp = GetIndustry(p->ainew.temp);
|
const Industry* ind_temp = GetIndustry(p->ainew.temp);
|
||||||
|
const IndustrySpec *indsp_temp = GetIndustrySpec(ind_temp->type);
|
||||||
bool found = false;
|
bool found = false;
|
||||||
int max_cargo = 0;
|
int max_cargo = 0;
|
||||||
uint i;
|
uint i;
|
||||||
|
|
||||||
// TODO: in max_cargo, also check other cargo (beside [0])
|
// TODO: in max_cargo, also check other cargo (beside [0])
|
||||||
// First we check if the from_ic produces cargo that this ic accepts
|
// First we check if the from_ic produces cargo that this ic accepts
|
||||||
if (ind_from->produced_cargo[0] != CT_INVALID && ind_from->total_production[0] != 0) {
|
if (indsp_from->produced_cargo[0] != CT_INVALID && ind_from->total_production[0] != 0) {
|
||||||
for (i = 0; i < lengthof(ind_temp->accepts_cargo); i++) {
|
for (i = 0; i < lengthof(indsp_temp->accepts_cargo); i++) {
|
||||||
if (ind_temp->accepts_cargo[i] == CT_INVALID) break;
|
if (indsp_temp->accepts_cargo[i] == CT_INVALID) break;
|
||||||
if (ind_from->produced_cargo[0] == ind_temp->accepts_cargo[i]) {
|
if (indsp_from->produced_cargo[0] == indsp_temp->accepts_cargo[i]) {
|
||||||
// Found a compatible industry
|
// Found a compatible industry
|
||||||
max_cargo = ind_from->total_production[0] - ind_from->total_transported[0];
|
max_cargo = ind_from->total_production[0] - ind_from->total_transported[0];
|
||||||
found = true;
|
found = true;
|
||||||
@ -478,11 +481,11 @@ static void AiNew_State_LocateRoute(Player *p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found && ind_temp->produced_cargo[0] != CT_INVALID && ind_temp->total_production[0] != 0) {
|
if (!found && indsp_temp->produced_cargo[0] != CT_INVALID && ind_temp->total_production[0] != 0) {
|
||||||
// If not check if the current ic produces cargo that the from_ic accepts
|
// If not check if the current ic produces cargo that the from_ic accepts
|
||||||
for (i = 0; i < lengthof(ind_from->accepts_cargo); i++) {
|
for (i = 0; i < lengthof(indsp_from->accepts_cargo); i++) {
|
||||||
if (ind_from->accepts_cargo[i] == CT_INVALID) break;
|
if (indsp_from->accepts_cargo[i] == CT_INVALID) break;
|
||||||
if (ind_temp->produced_cargo[0] == ind_from->accepts_cargo[i]) {
|
if (indsp_from->produced_cargo[0] == indsp_from->accepts_cargo[i]) {
|
||||||
// Found a compatbiel industry
|
// Found a compatbiel industry
|
||||||
found = true;
|
found = true;
|
||||||
max_cargo = ind_temp->total_production[0] - ind_temp->total_transported[0];
|
max_cargo = ind_temp->total_production[0] - ind_temp->total_transported[0];
|
||||||
@ -501,9 +504,9 @@ static void AiNew_State_LocateRoute(Player *p)
|
|||||||
distance <= max_cargo * AI_LOCATEROUTE_TRUCK_CARGO_DISTANCE) {
|
distance <= max_cargo * AI_LOCATEROUTE_TRUCK_CARGO_DISTANCE) {
|
||||||
p->ainew.to_ic = p->ainew.temp;
|
p->ainew.to_ic = p->ainew.temp;
|
||||||
if (p->ainew.from_deliver) {
|
if (p->ainew.from_deliver) {
|
||||||
p->ainew.cargo = ind_from->produced_cargo[0];
|
p->ainew.cargo = indsp_from->produced_cargo[0];
|
||||||
} else {
|
} else {
|
||||||
p->ainew.cargo = ind_temp->produced_cargo[0];
|
p->ainew.cargo = indsp_temp->produced_cargo[0];
|
||||||
}
|
}
|
||||||
p->ainew.state = AI_STATE_FIND_STATION;
|
p->ainew.state = AI_STATE_FIND_STATION;
|
||||||
|
|
||||||
|
@ -957,6 +957,7 @@ static void FindSubsidyPassengerRoute(FoundRoute *fr)
|
|||||||
static void FindSubsidyCargoRoute(FoundRoute *fr)
|
static void FindSubsidyCargoRoute(FoundRoute *fr)
|
||||||
{
|
{
|
||||||
Industry *i;
|
Industry *i;
|
||||||
|
const IndustrySpec *ind;
|
||||||
int trans, total;
|
int trans, total;
|
||||||
CargoID cargo;
|
CargoID cargo;
|
||||||
|
|
||||||
@ -964,14 +965,15 @@ static void FindSubsidyCargoRoute(FoundRoute *fr)
|
|||||||
|
|
||||||
fr->from = i = GetRandomIndustry();
|
fr->from = i = GetRandomIndustry();
|
||||||
if (i == NULL) return;
|
if (i == NULL) return;
|
||||||
|
ind = GetIndustrySpec(i->type);
|
||||||
|
|
||||||
/* Randomize cargo type */
|
/* Randomize cargo type */
|
||||||
if (Random()&1 && i->produced_cargo[1] != CT_INVALID) {
|
if (HASBIT(Random(), 0) && ind->produced_cargo[1] != CT_INVALID) {
|
||||||
cargo = i->produced_cargo[1];
|
cargo = ind->produced_cargo[1];
|
||||||
trans = i->pct_transported[1];
|
trans = i->pct_transported[1];
|
||||||
total = i->total_production[1];
|
total = i->total_production[1];
|
||||||
} else {
|
} else {
|
||||||
cargo = i->produced_cargo[0];
|
cargo = ind->produced_cargo[0];
|
||||||
trans = i->pct_transported[0];
|
trans = i->pct_transported[0];
|
||||||
total = i->total_production[0];
|
total = i->total_production[0];
|
||||||
}
|
}
|
||||||
@ -998,13 +1000,19 @@ static void FindSubsidyCargoRoute(FoundRoute *fr)
|
|||||||
} else {
|
} else {
|
||||||
/* The destination is an industry */
|
/* The destination is an industry */
|
||||||
Industry *i2 = GetRandomIndustry();
|
Industry *i2 = GetRandomIndustry();
|
||||||
|
if (i2 == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ind = GetIndustrySpec(i2->type);
|
||||||
|
|
||||||
/* The industry must accept the cargo */
|
/* The industry must accept the cargo */
|
||||||
if (i == i2 || i == NULL ||
|
if (i == i2 ||
|
||||||
(cargo != i2->accepts_cargo[0] &&
|
(cargo != ind->accepts_cargo[0] &&
|
||||||
cargo != i2->accepts_cargo[1] &&
|
cargo != ind->accepts_cargo[1] &&
|
||||||
cargo != i2->accepts_cargo[2]))
|
cargo != ind->accepts_cargo[2])) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
fr->distance = DistanceManhattan(i->xy, i2->xy);
|
fr->distance = DistanceManhattan(i->xy, i2->xy);
|
||||||
fr->to = i2;
|
fr->to = i2;
|
||||||
}
|
}
|
||||||
|
@ -67,10 +67,8 @@ struct Industry {
|
|||||||
byte width;
|
byte width;
|
||||||
byte height;
|
byte height;
|
||||||
const Town* town; ///< Nearest town
|
const Town* town; ///< Nearest town
|
||||||
CargoID produced_cargo[2]; ///< 2 production cargo slots
|
|
||||||
uint16 cargo_waiting[2]; ///< amount of cargo produced per cargo
|
uint16 cargo_waiting[2]; ///< amount of cargo produced per cargo
|
||||||
byte production_rate[2]; ///< production rate for each cargo
|
byte production_rate[2]; ///< production rate for each cargo
|
||||||
CargoID accepts_cargo[3]; ///< 3 input cargo slots
|
|
||||||
byte prod_level; ///< general production level
|
byte prod_level; ///< general production level
|
||||||
uint16 last_mo_production[2]; ///< stats of last month production per cargo
|
uint16 last_mo_production[2]; ///< stats of last month production per cargo
|
||||||
uint16 last_mo_transported[2]; ///< stats of last month transport per cargo
|
uint16 last_mo_transported[2]; ///< stats of last month transport per cargo
|
||||||
|
@ -55,26 +55,16 @@ DEFINE_OLD_POOL(Industry, Industry, IndustryPoolNewBlock, NULL)
|
|||||||
* Retrieve the type for this industry. Although it is accessed by a tile,
|
* Retrieve the type for this industry. Although it is accessed by a tile,
|
||||||
* it will return the general type of industry, and not the sprite index
|
* it will return the general type of industry, and not the sprite index
|
||||||
* as would do GetIndustryGfx.
|
* as would do GetIndustryGfx.
|
||||||
* The same information can be accessed by looking at Industry->type
|
|
||||||
* @param tile that is queried
|
* @param tile that is queried
|
||||||
* @pre IsTileType(tile, MP_INDUSTRY)
|
* @pre IsTileType(tile, MP_INDUSTRY)
|
||||||
* @return general type for this industry, as defined in industry.h
|
* @return general type for this industry, as defined in industry.h
|
||||||
**/
|
**/
|
||||||
IndustryType GetIndustryType(TileIndex tile)
|
IndustryType GetIndustryType(TileIndex tile)
|
||||||
{
|
{
|
||||||
IndustryGfx this_type = GetIndustryGfx(tile);
|
|
||||||
IndustryType iloop;
|
|
||||||
|
|
||||||
assert(IsTileType(tile, MP_INDUSTRY));
|
assert(IsTileType(tile, MP_INDUSTRY));
|
||||||
|
|
||||||
for (iloop = IT_COAL_MINE; iloop < NUM_INDUSTRYTYPES; iloop += 1) {
|
const Industry *ind = GetIndustry(GetIndustryIndex(tile));
|
||||||
if (IS_BYTE_INSIDE(this_type, industry_gfx_Solver[iloop].MinGfx,
|
return IsValidIndustry(ind) ? ind->type : IT_INVALID;
|
||||||
industry_gfx_Solver[iloop].MaxGfx + 1)) {
|
|
||||||
return iloop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return IT_INVALID; //we have not found equivalent, whatever the reason
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -355,7 +345,7 @@ static void TransportIndustryGoods(TileIndex tile)
|
|||||||
|
|
||||||
i->last_mo_production[0] += cw;
|
i->last_mo_production[0] += cw;
|
||||||
|
|
||||||
am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[0], cw);
|
am = MoveGoodsToStation(i->xy, i->width, i->height, indspec->produced_cargo[0], cw);
|
||||||
i->last_mo_transported[0] += am;
|
i->last_mo_transported[0] += am;
|
||||||
if (am != 0) {
|
if (am != 0) {
|
||||||
uint newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_production;
|
uint newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_production;
|
||||||
@ -377,7 +367,7 @@ static void TransportIndustryGoods(TileIndex tile)
|
|||||||
|
|
||||||
i->last_mo_production[1] += cw;
|
i->last_mo_production[1] += cw;
|
||||||
|
|
||||||
am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[1], cw);
|
am = MoveGoodsToStation(i->xy, i->width, i->height, indspec->produced_cargo[1], cw);
|
||||||
i->last_mo_transported[1] += am;
|
i->last_mo_transported[1] += am;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -752,7 +742,7 @@ static uint32 GetTileTrackStatus_Industry(TileIndex tile, TransportType mode)
|
|||||||
|
|
||||||
static void GetProducedCargo_Industry(TileIndex tile, CargoID *b)
|
static void GetProducedCargo_Industry(TileIndex tile, CargoID *b)
|
||||||
{
|
{
|
||||||
const Industry *i = GetIndustryByTile(tile);
|
const IndustrySpec *i = GetIndustrySpec(GetIndustryByTile(tile)->type);
|
||||||
|
|
||||||
b[0] = i->produced_cargo[0];
|
b[0] = i->produced_cargo[0];
|
||||||
b[1] = i->produced_cargo[1];
|
b[1] = i->produced_cargo[1];
|
||||||
@ -1333,7 +1323,7 @@ static bool CheckIfTooCloseToIndustry(TileIndex tile, int type)
|
|||||||
/* check if an industry that accepts the same goods is nearby */
|
/* check if an industry that accepts the same goods is nearby */
|
||||||
if (DistanceMax(tile, i->xy) <= 14 &&
|
if (DistanceMax(tile, i->xy) <= 14 &&
|
||||||
indspec->accepts_cargo[0] != CT_INVALID &&
|
indspec->accepts_cargo[0] != CT_INVALID &&
|
||||||
indspec->accepts_cargo[0] == i->accepts_cargo[0] && (
|
indspec->accepts_cargo[0] == indspec->accepts_cargo[0] && (
|
||||||
_game_mode != GM_EDITOR ||
|
_game_mode != GM_EDITOR ||
|
||||||
!_patches.same_industry_close ||
|
!_patches.same_industry_close ||
|
||||||
!_patches.multiple_industry_per_town
|
!_patches.multiple_industry_per_town
|
||||||
@ -1384,11 +1374,6 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const Ind
|
|||||||
i->width = i->height = 0;
|
i->width = i->height = 0;
|
||||||
i->type = type;
|
i->type = type;
|
||||||
|
|
||||||
i->produced_cargo[0] = indspec->produced_cargo[0];
|
|
||||||
i->produced_cargo[1] = indspec->produced_cargo[1];
|
|
||||||
i->accepts_cargo[0] = indspec->accepts_cargo[0];
|
|
||||||
i->accepts_cargo[1] = indspec->accepts_cargo[1];
|
|
||||||
i->accepts_cargo[2] = indspec->accepts_cargo[2];
|
|
||||||
i->production_rate[0] = indspec->production_rate[0];
|
i->production_rate[0] = indspec->production_rate[0];
|
||||||
i->production_rate[1] = indspec->production_rate[1];
|
i->production_rate[1] = indspec->production_rate[1];
|
||||||
|
|
||||||
@ -1638,7 +1623,7 @@ static void ExtChangeIndustryProduction(Industry *i)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default: /* INDUSTRY_PRODUCTION */
|
default: /* INDUSTRY_PRODUCTION */
|
||||||
for (j = 0; j < 2 && i->produced_cargo[j] != CT_INVALID; j++){
|
for (j = 0; j < 2 && indspec->produced_cargo[j] != CT_INVALID; j++){
|
||||||
uint32 r = Random();
|
uint32 r = Random();
|
||||||
int old_prod, new_prod, percent;
|
int old_prod, new_prod, percent;
|
||||||
int mag;
|
int mag;
|
||||||
@ -1664,7 +1649,7 @@ static void ExtChangeIndustryProduction(Industry *i)
|
|||||||
mag = abs(percent);
|
mag = abs(percent);
|
||||||
if (mag >= 10) {
|
if (mag >= 10) {
|
||||||
SetDParam(2, mag);
|
SetDParam(2, mag);
|
||||||
SetDParam(0, GetCargo(i->produced_cargo[j])->name);
|
SetDParam(0, GetCargo(indspec->produced_cargo[j])->name);
|
||||||
SetDParam(1, i->index);
|
SetDParam(1, i->index);
|
||||||
AddNewsItem(
|
AddNewsItem(
|
||||||
percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN,
|
percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN,
|
||||||
@ -1693,39 +1678,25 @@ static void UpdateIndustryStatistics(Industry *i)
|
|||||||
{
|
{
|
||||||
byte pct;
|
byte pct;
|
||||||
bool refresh = false;
|
bool refresh = false;
|
||||||
|
const IndustrySpec *indsp = GetIndustrySpec(i->type);
|
||||||
|
|
||||||
if (i->produced_cargo[0] != CT_INVALID) {
|
for (byte j = 0; j < lengthof(indsp->produced_cargo); j++) {
|
||||||
|
if (indsp->produced_cargo[j] != CT_INVALID) {
|
||||||
pct = 0;
|
pct = 0;
|
||||||
if (i->last_mo_production[0] != 0) {
|
if (i->last_mo_production[j] != 0) {
|
||||||
i->last_prod_year = _cur_year;
|
i->last_prod_year = _cur_year;
|
||||||
pct = min(i->last_mo_transported[0] * 256 / i->last_mo_production[0], 255);
|
pct = min(i->last_mo_transported[j] * 256 / i->last_mo_production[j], 255);
|
||||||
}
|
}
|
||||||
i->pct_transported[0] = pct;
|
i->pct_transported[j] = pct;
|
||||||
|
|
||||||
i->total_production[0] = i->last_mo_production[0];
|
i->total_production[0] = i->last_mo_production[0];
|
||||||
i->last_mo_production[0] = 0;
|
i->last_mo_production[0] = 0;
|
||||||
|
|
||||||
i->total_transported[0] = i->last_mo_transported[0];
|
i->total_transported[j] = i->last_mo_transported[j];
|
||||||
i->last_mo_transported[0] = 0;
|
i->last_mo_transported[j] = 0;
|
||||||
refresh = true;
|
refresh = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i->produced_cargo[1] != CT_INVALID) {
|
|
||||||
pct = 0;
|
|
||||||
if (i->last_mo_production[1] != 0) {
|
|
||||||
i->last_prod_year = _cur_year;
|
|
||||||
pct = min(i->last_mo_transported[1] * 256 / i->last_mo_production[1], 255);
|
|
||||||
}
|
}
|
||||||
i->pct_transported[1] = pct;
|
|
||||||
|
|
||||||
i->total_production[1] = i->last_mo_production[1];
|
|
||||||
i->last_mo_production[1] = 0;
|
|
||||||
|
|
||||||
i->total_transported[1] = i->last_mo_transported[1];
|
|
||||||
i->last_mo_transported[1] = 0;
|
|
||||||
refresh = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (refresh)
|
if (refresh)
|
||||||
InvalidateWindow(WC_INDUSTRY_VIEW, i->index);
|
InvalidateWindow(WC_INDUSTRY_VIEW, i->index);
|
||||||
@ -1920,10 +1891,10 @@ static const SaveLoad _industry_desc[] = {
|
|||||||
SLE_VAR(Industry, width, SLE_UINT8),
|
SLE_VAR(Industry, width, SLE_UINT8),
|
||||||
SLE_VAR(Industry, height, SLE_UINT8),
|
SLE_VAR(Industry, height, SLE_UINT8),
|
||||||
SLE_REF(Industry, town, REF_TOWN),
|
SLE_REF(Industry, town, REF_TOWN),
|
||||||
SLE_ARR(Industry, produced_cargo, SLE_UINT8, 2),
|
SLE_CONDNULL( 2, 2, 60), ///< used to be industry's produced_cargo
|
||||||
SLE_ARR(Industry, cargo_waiting, SLE_UINT16, 2),
|
SLE_ARR(Industry, cargo_waiting, SLE_UINT16, 2),
|
||||||
SLE_ARR(Industry, production_rate, SLE_UINT8, 2),
|
SLE_ARR(Industry, production_rate, SLE_UINT8, 2),
|
||||||
SLE_ARR(Industry, accepts_cargo, SLE_UINT8, 3),
|
SLE_CONDNULL( 3, 2, 60), ///< used to be industry's accepts_cargo
|
||||||
SLE_VAR(Industry, prod_level, SLE_UINT8),
|
SLE_VAR(Industry, prod_level, SLE_UINT8),
|
||||||
SLE_ARR(Industry, last_mo_production, SLE_UINT16, 2),
|
SLE_ARR(Industry, last_mo_production, SLE_UINT16, 2),
|
||||||
SLE_ARR(Industry, last_mo_transported, SLE_UINT16, 2),
|
SLE_ARR(Industry, last_mo_transported, SLE_UINT16, 2),
|
||||||
|
@ -287,8 +287,9 @@ static inline bool isProductionMaximum(const Industry *i, int pt) {
|
|||||||
|
|
||||||
static inline bool IsProductionAlterable(const Industry *i)
|
static inline bool IsProductionAlterable(const Industry *i)
|
||||||
{
|
{
|
||||||
|
const IndustrySpec *ind = GetIndustrySpec(i->type);
|
||||||
return ((_game_mode == GM_EDITOR || _cheats.setup_prod.value) &&
|
return ((_game_mode == GM_EDITOR || _cheats.setup_prod.value) &&
|
||||||
(i->accepts_cargo[0] == CT_INVALID || i->accepts_cargo[0] == CT_VALUABLES));
|
(ind->accepts_cargo[0] == CT_INVALID || ind->accepts_cargo[0] == CT_VALUABLES));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void IndustryViewWndProc(Window *w, WindowEvent *e)
|
static void IndustryViewWndProc(Window *w, WindowEvent *e)
|
||||||
@ -300,30 +301,31 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e)
|
|||||||
switch (e->event) {
|
switch (e->event) {
|
||||||
case WE_PAINT: {
|
case WE_PAINT: {
|
||||||
const Industry *i = GetIndustry(w->window_number);
|
const Industry *i = GetIndustry(w->window_number);
|
||||||
|
const IndustrySpec *ind = GetIndustrySpec(i->type);
|
||||||
|
|
||||||
SetDParam(0, w->window_number);
|
SetDParam(0, w->window_number);
|
||||||
DrawWindowWidgets(w);
|
DrawWindowWidgets(w);
|
||||||
|
|
||||||
if (i->accepts_cargo[0] != CT_INVALID) {
|
if (ind->accepts_cargo[0] != CT_INVALID) {
|
||||||
StringID str;
|
StringID str;
|
||||||
|
|
||||||
SetDParam(0, GetCargo(i->accepts_cargo[0])->name);
|
SetDParam(0, GetCargo(ind->accepts_cargo[0])->name);
|
||||||
str = STR_4827_REQUIRES;
|
str = STR_4827_REQUIRES;
|
||||||
if (i->accepts_cargo[1] != CT_INVALID) {
|
if (ind->accepts_cargo[1] != CT_INVALID) {
|
||||||
SetDParam(1, GetCargo(i->accepts_cargo[1])->name);
|
SetDParam(1, GetCargo(ind->accepts_cargo[1])->name);
|
||||||
str = STR_4828_REQUIRES;
|
str = STR_4828_REQUIRES;
|
||||||
if (i->accepts_cargo[2] != CT_INVALID) {
|
if (ind->accepts_cargo[2] != CT_INVALID) {
|
||||||
SetDParam(2, GetCargo(i->accepts_cargo[2])->name);
|
SetDParam(2, GetCargo(ind->accepts_cargo[2])->name);
|
||||||
str = STR_4829_REQUIRES;
|
str = STR_4829_REQUIRES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DrawString(2, 107, str, 0);
|
DrawString(2, 107, str, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i->produced_cargo[0] != CT_INVALID) {
|
if (ind->produced_cargo[0] != CT_INVALID) {
|
||||||
DrawString(2, 117, STR_482A_PRODUCTION_LAST_MONTH, 0);
|
DrawString(2, 117, STR_482A_PRODUCTION_LAST_MONTH, 0);
|
||||||
|
|
||||||
SetDParam(0, i->produced_cargo[0]);
|
SetDParam(0, ind->produced_cargo[0]);
|
||||||
SetDParam(1, i->total_production[0]);
|
SetDParam(1, i->total_production[0]);
|
||||||
|
|
||||||
SetDParam(2, i->pct_transported[0] * 100 >> 8);
|
SetDParam(2, i->pct_transported[0] * 100 >> 8);
|
||||||
@ -334,8 +336,8 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e)
|
|||||||
!isProductionMinimum(i, 0), !isProductionMaximum(i, 0));
|
!isProductionMinimum(i, 0), !isProductionMaximum(i, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i->produced_cargo[1] != CT_INVALID) {
|
if (ind->produced_cargo[1] != CT_INVALID) {
|
||||||
SetDParam(0, i->produced_cargo[1]);
|
SetDParam(0, ind->produced_cargo[1]);
|
||||||
SetDParam(1, i->total_production[1]);
|
SetDParam(1, i->total_production[1]);
|
||||||
SetDParam(2, i->pct_transported[1] * 100 >> 8);
|
SetDParam(2, i->pct_transported[1] * 100 >> 8);
|
||||||
DrawString(4 + (IsProductionAlterable(i) ? 30 : 0), 137, STR_482B_TRANSPORTED, 0);
|
DrawString(4 + (IsProductionAlterable(i) ? 30 : 0), 137, STR_482B_TRANSPORTED, 0);
|
||||||
@ -365,7 +367,8 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e)
|
|||||||
|
|
||||||
x = e->we.click.pt.x;
|
x = e->we.click.pt.x;
|
||||||
line = (e->we.click.pt.y - 127) / 10;
|
line = (e->we.click.pt.y - 127) / 10;
|
||||||
if (e->we.click.pt.y >= 127 && IS_INT_INSIDE(line, 0, 2) && i->produced_cargo[line] != CT_INVALID) {
|
if (e->we.click.pt.y >= 127 && IS_INT_INSIDE(line, 0, 2) &&
|
||||||
|
GetIndustrySpec(i->type)->produced_cargo[line] != CT_INVALID) {
|
||||||
if (IS_INT_INSIDE(x, 5, 25) ) {
|
if (IS_INT_INSIDE(x, 5, 25) ) {
|
||||||
/* Clicked buttons, decrease or increase production */
|
/* Clicked buttons, decrease or increase production */
|
||||||
if (x < 15) {
|
if (x < 15) {
|
||||||
@ -416,11 +419,13 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e)
|
|||||||
|
|
||||||
static void UpdateIndustryProduction(Industry *i)
|
static void UpdateIndustryProduction(Industry *i)
|
||||||
{
|
{
|
||||||
if (i->produced_cargo[0] != CT_INVALID)
|
const IndustrySpec *ind = GetIndustrySpec(i->type);
|
||||||
i->total_production[0] = 8 * i->production_rate[0];
|
|
||||||
|
|
||||||
if (i->produced_cargo[1] != CT_INVALID)
|
for (byte j = 0; j < lengthof(ind->produced_cargo); j++) {
|
||||||
i->total_production[1] = 8 * i->production_rate[1];
|
if (ind->produced_cargo[j] != CT_INVALID) {
|
||||||
|
i->total_production[j] = 8 * i->production_rate[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const Widget _industry_view_widgets[] = {
|
static const Widget _industry_view_widgets[] = {
|
||||||
@ -482,6 +487,8 @@ static int CDECL GeneralIndustrySorter(const void *a, const void *b)
|
|||||||
{
|
{
|
||||||
const Industry* i = *(const Industry**)a;
|
const Industry* i = *(const Industry**)a;
|
||||||
const Industry* j = *(const Industry**)b;
|
const Industry* j = *(const Industry**)b;
|
||||||
|
const IndustrySpec *ind_i = GetIndustrySpec(i->type);
|
||||||
|
const IndustrySpec *ind_j = GetIndustrySpec(j->type);
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
switch (_industry_sort_order >> 1) {
|
switch (_industry_sort_order >> 1) {
|
||||||
@ -495,10 +502,10 @@ static int CDECL GeneralIndustrySorter(const void *a, const void *b)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 2: /* Sort by Production */
|
case 2: /* Sort by Production */
|
||||||
if (i->produced_cargo[0] == CT_INVALID) {
|
if (ind_i->produced_cargo[0] == CT_INVALID) {
|
||||||
r = (j->produced_cargo[0] == CT_INVALID ? 0 : -1);
|
r = (ind_j->produced_cargo[0] == CT_INVALID ? 0 : -1);
|
||||||
} else {
|
} else {
|
||||||
if (j->produced_cargo[0] == CT_INVALID) {
|
if (ind_j->produced_cargo[0] == CT_INVALID) {
|
||||||
r = 1;
|
r = 1;
|
||||||
} else {
|
} else {
|
||||||
r =
|
r =
|
||||||
@ -509,23 +516,23 @@ static int CDECL GeneralIndustrySorter(const void *a, const void *b)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 3: /* Sort by transported fraction */
|
case 3: /* Sort by transported fraction */
|
||||||
if (i->produced_cargo[0] == CT_INVALID) {
|
if (ind_i->produced_cargo[0] == CT_INVALID) {
|
||||||
r = (j->produced_cargo[0] == CT_INVALID ? 0 : -1);
|
r = (ind_j->produced_cargo[0] == CT_INVALID ? 0 : -1);
|
||||||
} else {
|
} else {
|
||||||
if (j->produced_cargo[0] == CT_INVALID) {
|
if (ind_j->produced_cargo[0] == CT_INVALID) {
|
||||||
r = 1;
|
r = 1;
|
||||||
} else {
|
} else {
|
||||||
int pi;
|
int pi;
|
||||||
int pj;
|
int pj;
|
||||||
|
|
||||||
pi = i->pct_transported[0] * 100 >> 8;
|
pi = i->pct_transported[0] * 100 >> 8;
|
||||||
if (i->produced_cargo[1] != CT_INVALID) {
|
if (ind_i->produced_cargo[1] != CT_INVALID) {
|
||||||
int p = i->pct_transported[1] * 100 >> 8;
|
int p = i->pct_transported[1] * 100 >> 8;
|
||||||
if (p < pi) pi = p;
|
if (p < pi) pi = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
pj = j->pct_transported[0] * 100 >> 8;
|
pj = j->pct_transported[0] * 100 >> 8;
|
||||||
if (j->produced_cargo[1] != CT_INVALID) {
|
if (ind_j->produced_cargo[1] != CT_INVALID) {
|
||||||
int p = j->pct_transported[1] * 100 >> 8;
|
int p = j->pct_transported[1] * 100 >> 8;
|
||||||
if (p < pj) pj = p;
|
if (p < pj) pj = p;
|
||||||
}
|
}
|
||||||
@ -606,14 +613,15 @@ static void IndustryDirectoryWndProc(Window *w, WindowEvent *e)
|
|||||||
|
|
||||||
while (p < _num_industry_sort) {
|
while (p < _num_industry_sort) {
|
||||||
const Industry* i = _industry_sort[p];
|
const Industry* i = _industry_sort[p];
|
||||||
|
const IndustrySpec *ind = GetIndustrySpec(i->type);
|
||||||
|
|
||||||
SetDParam(0, i->index);
|
SetDParam(0, i->index);
|
||||||
if (i->produced_cargo[0] != CT_INVALID) {
|
if (ind->produced_cargo[0] != CT_INVALID) {
|
||||||
SetDParam(1, i->produced_cargo[0]);
|
SetDParam(1, ind->produced_cargo[0]);
|
||||||
SetDParam(2, i->total_production[0]);
|
SetDParam(2, i->total_production[0]);
|
||||||
|
|
||||||
if (i->produced_cargo[1] != CT_INVALID) {
|
if (ind->produced_cargo[1] != CT_INVALID) {
|
||||||
SetDParam(3, i->produced_cargo[1]);
|
SetDParam(3, ind->produced_cargo[1]);
|
||||||
SetDParam(4, i->total_production[1]);
|
SetDParam(4, i->total_production[1]);
|
||||||
SetDParam(5, i->pct_transported[0] * 100 >> 8);
|
SetDParam(5, i->pct_transported[0] * 100 >> 8);
|
||||||
SetDParam(6, i->pct_transported[1] * 100 >> 8);
|
SetDParam(6, i->pct_transported[1] * 100 >> 8);
|
||||||
|
@ -207,46 +207,6 @@ struct IndustryTypeSolver {
|
|||||||
IndustryGfx MaxGfx; ///< The last gfx index for the industry type
|
IndustryGfx MaxGfx; ///< The last gfx index for the industry type
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Mapping of industry gfx to industry type */
|
|
||||||
static const IndustryTypeSolver industry_gfx_Solver[IT_END] = {
|
|
||||||
{ 0, 6}, ///< IT_COAL_MINE
|
|
||||||
{ 7, 10}, ///< IT_POWER_STATION,
|
|
||||||
{ 11, 15}, ///< IT_SAWMILL,
|
|
||||||
{ 16, 17}, ///< IT_FOREST,
|
|
||||||
{ 18, 23}, ///< IT_OIL_REFINERY,
|
|
||||||
{ 24, 28}, ///< IT_OIL_RIG,
|
|
||||||
{ 29, 31}, ///< IT_OIL_WELL,
|
|
||||||
{ 32, 38}, ///< IT_FARM,
|
|
||||||
{ 39, 42}, ///< IT_FACTORY,
|
|
||||||
{ 43, 46}, ///< IT_PRINTING_WORKS,
|
|
||||||
{ 47, 51}, ///< IT_COPPER_MINE,
|
|
||||||
{ 52, 57}, ///< IT_STEEL_MILL,
|
|
||||||
{ 58, 59}, ///< IT_BANK_TEMP,
|
|
||||||
{ 60, 63}, ///< IT_FOOD_PROCESS,
|
|
||||||
{ 64, 71}, ///< IT_PAPER_MILL,
|
|
||||||
{ 72, 88}, ///< IT_GOLD_MINE,
|
|
||||||
{ 89, 90}, ///< IT_BANK_TROPIC_ARCTIC,
|
|
||||||
{ 91, 99}, ///< IT_DIAMOND_MINE,
|
|
||||||
{100, 115}, ///< IT_IRON_MINE,
|
|
||||||
{116, 116}, ///< IT_FRUIT_PLANTATION,
|
|
||||||
{117, 117}, ///< IT_RUBBER_PLANTATION,
|
|
||||||
{118, 119}, ///< IT_WATER_SUPPLY,
|
|
||||||
{120, 120}, ///< IT_WATER_TOWER,
|
|
||||||
{121, 124}, ///< IT_FACTORY_2,
|
|
||||||
{125, 128}, ///< IT_LUMBER_MILL,
|
|
||||||
{129, 130}, ///< IT_COTTON_CANDY,
|
|
||||||
{131, 134}, ///< IT_CANDY_FACTORY or sweet factory
|
|
||||||
{135, 136}, ///< IT_BATTERY_FARM,
|
|
||||||
{137, 137}, ///< IT_COLA_WELLS,
|
|
||||||
{138, 141}, ///< IT_TOY_SHOP,
|
|
||||||
{142, 147}, ///< IT_TOY_FACTORY,
|
|
||||||
{148, 155}, ///< IT_PLASTIC_FOUNTAINS,
|
|
||||||
{156, 159}, ///< IT_FIZZY_DRINK_FACTORY,
|
|
||||||
{160, 163}, ///< IT_BUBBLE_GENERATOR,
|
|
||||||
{164, 166}, ///< IT_TOFFEE_QUARRY,
|
|
||||||
{167, 174} ///< IT_SUGAR_MINE,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the animation loop number
|
* Get the animation loop number
|
||||||
* @param tile the tile to get the animation loop number of
|
* @param tile the tile to get the animation loop number of
|
||||||
|
@ -651,8 +651,7 @@ static const OldChunks industry_chunk[] = {
|
|||||||
OCL_VAR ( OC_UINT32, 1, &_old_town_index ),
|
OCL_VAR ( OC_UINT32, 1, &_old_town_index ),
|
||||||
OCL_SVAR( OC_UINT8, Industry, width ),
|
OCL_SVAR( OC_UINT8, Industry, width ),
|
||||||
OCL_SVAR( OC_UINT8, Industry, height ),
|
OCL_SVAR( OC_UINT8, Industry, height ),
|
||||||
OCL_SVAR( OC_UINT8, Industry, produced_cargo[0] ),
|
OCL_NULL( 2 ), ///< used to be industry's produced_cargo
|
||||||
OCL_SVAR( OC_UINT8, Industry, produced_cargo[1] ),
|
|
||||||
|
|
||||||
OCL_SVAR( OC_UINT16, Industry, cargo_waiting[0] ),
|
OCL_SVAR( OC_UINT16, Industry, cargo_waiting[0] ),
|
||||||
OCL_SVAR( OC_UINT16, Industry, cargo_waiting[1] ),
|
OCL_SVAR( OC_UINT16, Industry, cargo_waiting[1] ),
|
||||||
@ -660,9 +659,7 @@ static const OldChunks industry_chunk[] = {
|
|||||||
OCL_SVAR( OC_UINT8, Industry, production_rate[0] ),
|
OCL_SVAR( OC_UINT8, Industry, production_rate[0] ),
|
||||||
OCL_SVAR( OC_UINT8, Industry, production_rate[1] ),
|
OCL_SVAR( OC_UINT8, Industry, production_rate[1] ),
|
||||||
|
|
||||||
OCL_SVAR( OC_UINT8, Industry, accepts_cargo[0] ),
|
OCL_NULL( 3 ), ///< used to be industry's accepts_cargo
|
||||||
OCL_SVAR( OC_UINT8, Industry, accepts_cargo[1] ),
|
|
||||||
OCL_SVAR( OC_UINT8, Industry, accepts_cargo[2] ),
|
|
||||||
|
|
||||||
OCL_SVAR( OC_UINT8, Industry, prod_level ),
|
OCL_SVAR( OC_UINT8, Industry, prod_level ),
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user