summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-07-04 18:27:21 +0000
committerrubidium <rubidium@openttd.org>2007-07-04 18:27:21 +0000
commit1bdb72ebd42cf18972b67b2bf73086d6fda47693 (patch)
tree055e7c9a0bb15c98a3fd1404abeba74e87f53ab1 /src
parent2d1a3d920c6c2d5ab4de0c7e73399ded3eece5b4 (diff)
downloadopenttd-1bdb72ebd42cf18972b67b2bf73086d6fda47693.tar.xz
(svn r10439) -Codechange: initial steps for customized industry productions.
Diffstat (limited to 'src')
-rw-r--r--src/economy.cpp13
-rw-r--r--src/industry.h3
-rw-r--r--src/industry_cmd.cpp24
-rw-r--r--src/newgrf_industries.cpp12
-rw-r--r--src/oldloader.cpp4
5 files changed, 35 insertions, 21 deletions
diff --git a/src/economy.cpp b/src/economy.cpp
index fe3d14913..c2c677dab 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -1234,9 +1234,18 @@ static void DeliverGoodsToIndustry(TileIndex xy, CargoID cargo_type, int num_pie
/* Found one? */
if (best != NULL) {
indspec = GetIndustrySpec(best->type);
+ uint16 callback = indspec->callback_flags;
best->was_cargo_delivered = true;
- best->cargo_waiting[0] = min(best->cargo_waiting[0] + (num_pieces * indspec->input_cargo_multiplier[accepted_cargo_index][0] / 256), 0xFFFF);
- best->cargo_waiting[1] = min(best->cargo_waiting[1] + (num_pieces * indspec->input_cargo_multiplier[accepted_cargo_index][1] / 256), 0xFFFF);
+
+ if (callback & (CBM_IND_PRODUCTION_CARGO_ARRIVAL | CBM_IND_PRODUCTION_256_TICKS)) {
+ best->incoming_cargo_waiting[accepted_cargo_index] = min(num_pieces + best->incoming_cargo_waiting[accepted_cargo_index], 0xFFFF);
+ if (callback & CBM_IND_PRODUCTION_CARGO_ARRIVAL) {
+ /** @todo Perform some magic */
+ }
+ } else {
+ best->produced_cargo_waiting[0] = min(best->produced_cargo_waiting[0] + (num_pieces * indspec->input_cargo_multiplier[accepted_cargo_index][0] / 256), 0xFFFF);
+ best->produced_cargo_waiting[1] = min(best->produced_cargo_waiting[1] + (num_pieces * indspec->input_cargo_multiplier[accepted_cargo_index][1] / 256), 0xFFFF);
+ }
}
}
diff --git a/src/industry.h b/src/industry.h
index 6486888d7..e2e5c3aa7 100644
--- a/src/industry.h
+++ b/src/industry.h
@@ -78,7 +78,8 @@ struct Industry {
byte width;
byte height;
const Town *town; ///< Nearest town
- uint16 cargo_waiting[2]; ///< amount of cargo produced per cargo
+ uint16 produced_cargo_waiting[2]; ///< amount of cargo produced per cargo
+ uint16 incoming_cargo_waiting[3]; ///< incoming cargo waiting to be processed
byte production_rate[2]; ///< production rate for each cargo
byte prod_level; ///< general production level
uint16 this_month_production[2]; ///< stats of this month's production per cargo
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 2e262d836..65eae2924 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -377,9 +377,9 @@ static void TransportIndustryGoods(TileIndex tile)
const IndustrySpec *indspec = GetIndustrySpec(i->type);
uint cw, am;
- cw = min(i->cargo_waiting[0], 255);
+ cw = min(i->produced_cargo_waiting[0], 255);
if (cw > indspec->minimal_cargo/* && i->produced_cargo[0] != 0xFF*/) {
- i->cargo_waiting[0] -= cw;
+ i->produced_cargo_waiting[0] -= cw;
/* fluctuating economy? */
if (_economy.fluct <= 0) cw = (cw + 1) / 2;
@@ -400,9 +400,9 @@ static void TransportIndustryGoods(TileIndex tile)
}
}
- cw = min(i->cargo_waiting[1], 255);
+ cw = min(i->produced_cargo_waiting[1], 255);
if (cw > indspec->minimal_cargo) {
- i->cargo_waiting[1] -= cw;
+ i->produced_cargo_waiting[1] -= cw;
if (_economy.fluct <= 0) cw = (cw + 1) / 2;
@@ -943,7 +943,7 @@ static void ChopLumberMillTrees(Industry *i)
if (!IsIndustryCompleted(tile)) return; ///< Can't proceed if not completed
if (CircularTileSearch(tile, 40, SearchLumberMillTrees, 0)) ///< 40x40 tiles to search
- i->cargo_waiting[0] = min(0xffff, i->cargo_waiting[0] + 45); ///< Found a tree, add according value to waiting cargo
+ i->produced_cargo_waiting[0] = min(0xffff, i->produced_cargo_waiting[0] + 45); ///< Found a tree, add according value to waiting cargo
}
static void ProduceIndustryGoods(Industry *i)
@@ -966,8 +966,8 @@ static void ProduceIndustryGoods(Industry *i)
/* produce some cargo */
if ((i->counter & 0xFF) == 0) {
IndustyBehaviour indbehav = indsp->behaviour;
- i->cargo_waiting[0] = min(0xffff, i->cargo_waiting[0] + i->production_rate[0]);
- i->cargo_waiting[1] = min(0xffff, i->cargo_waiting[1] + i->production_rate[1]);
+ i->produced_cargo_waiting[0] = min(0xffff, i->produced_cargo_waiting[0] + i->production_rate[0]);
+ i->produced_cargo_waiting[1] = min(0xffff, i->produced_cargo_waiting[1] + i->production_rate[1]);
if (indbehav & INDUSTRYBEH_PLANT_FIELDS) {
MaybePlantFarmField(i);
@@ -1391,8 +1391,11 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const Ind
r = Random();
i->random_color = GB(r, 8, 4);
i->counter = GB(r, 0, 12);
- i->cargo_waiting[0] = 0;
- i->cargo_waiting[1] = 0;
+ i->produced_cargo_waiting[0] = 0;
+ i->produced_cargo_waiting[1] = 0;
+ i->incoming_cargo_waiting[0] = 0;
+ i->incoming_cargo_waiting[1] = 0;
+ i->incoming_cargo_waiting[2] = 0;
i->this_month_production[0] = 0;
i->this_month_production[1] = 0;
i->this_month_transported[0] = 0;
@@ -1898,7 +1901,8 @@ static const SaveLoad _industry_desc[] = {
SLE_VAR(Industry, height, SLE_UINT8),
SLE_REF(Industry, town, REF_TOWN),
SLE_CONDNULL( 2, 2, 60), ///< used to be industry's produced_cargo
- SLE_ARR(Industry, cargo_waiting, SLE_UINT16, 2),
+ SLE_CONDARR(Industry, incoming_cargo_waiting, SLE_UINT16, 3, 70, SL_MAX_VERSION),
+ SLE_ARR(Industry, produced_cargo_waiting, SLE_UINT16, 2),
SLE_ARR(Industry, production_rate, SLE_UINT8, 2),
SLE_CONDNULL( 3, 2, 60), ///< used to be industry's accepts_cargo
SLE_VAR(Industry, prod_level, SLE_UINT8),
diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp
index 61f3ae224..8e0ba446d 100644
--- a/src/newgrf_industries.cpp
+++ b/src/newgrf_industries.cpp
@@ -123,8 +123,8 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte par
case 0x41:
case 0x42: { // waiting cargo, but only if those two callback flags are set
uint16 callback = indspec->callback_flags;
- if (callback & (CBM_IND_PRODUCTION_CARGO_ARRIVAL | callback & CBM_IND_PRODUCTION_256_TICKS)) {
- return max(industry->cargo_waiting[variable - 0x40], (uint16)0x7FFF);
+ if (callback & (CBM_IND_PRODUCTION_CARGO_ARRIVAL | CBM_IND_PRODUCTION_256_TICKS)) {
+ return max(industry->incoming_cargo_waiting[variable - 0x40], (uint16)0x7FFF);
} else {
return 0;
}
@@ -173,10 +173,10 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte par
/* */
case 0x88:
case 0x89: return indspec->produced_cargo[variable - 0x88];
- case 0x8A: return industry->cargo_waiting[0];
- case 0x8B: return GB(industry->cargo_waiting[0], 8, 8);
- case 0x8C: return industry->cargo_waiting[1];
- case 0x8D: return GB(industry->cargo_waiting[1], 8, 8);
+ case 0x8A: return industry->produced_cargo_waiting[0];
+ case 0x8B: return GB(industry->produced_cargo_waiting[0], 8, 8);
+ case 0x8C: return industry->produced_cargo_waiting[1];
+ case 0x8D: return GB(industry->produced_cargo_waiting[1], 8, 8);
case 0x8E:
case 0x8F: return industry->production_rate[variable - 0x8E];
case 0x90:
diff --git a/src/oldloader.cpp b/src/oldloader.cpp
index f361ea7e3..7cadd82d5 100644
--- a/src/oldloader.cpp
+++ b/src/oldloader.cpp
@@ -670,8 +670,8 @@ static const OldChunks industry_chunk[] = {
OCL_SVAR( OC_UINT8, Industry, height ),
OCL_NULL( 2 ), ///< used to be industry's produced_cargo
- OCL_SVAR( OC_UINT16, Industry, cargo_waiting[0] ),
- OCL_SVAR( OC_UINT16, Industry, cargo_waiting[1] ),
+ OCL_SVAR( OC_UINT16, Industry, produced_cargo_waiting[0] ),
+ OCL_SVAR( OC_UINT16, Industry, produced_cargo_waiting[1] ),
OCL_SVAR( OC_UINT8, Industry, production_rate[0] ),
OCL_SVAR( OC_UINT8, Industry, production_rate[1] ),