mirror of https://github.com/OpenTTD/OpenTTD
(svn r21170) -Codechange: Store industry management data in the save game (some of it is used in the very near future).
parent
67549a206c
commit
4d419b9f3e
|
@ -146,7 +146,10 @@ void ReleaseDisastersTargetingIndustry(IndustryID);
|
||||||
/** Data for managing the number of industries of a single industry type. */
|
/** Data for managing the number of industries of a single industry type. */
|
||||||
struct IndustryTypeBuildData {
|
struct IndustryTypeBuildData {
|
||||||
uint32 probability; ///< Relative probability of building this industry.
|
uint32 probability; ///< Relative probability of building this industry.
|
||||||
|
byte min_number; ///< Smallest number of industries that should exist (either \c 0 or \c 1).
|
||||||
uint16 target_count; ///< Desired number of industries of this type.
|
uint16 target_count; ///< Desired number of industries of this type.
|
||||||
|
uint16 max_wait; ///< Starting number of turns to wait (copied to #wait_count).
|
||||||
|
uint16 wait_count; ///< Number of turns to wait before trying to build again.
|
||||||
|
|
||||||
void GetIndustryTypeData(IndustryType it);
|
void GetIndustryTypeData(IndustryType it);
|
||||||
};
|
};
|
||||||
|
@ -156,6 +159,7 @@ struct IndustryTypeBuildData {
|
||||||
*/
|
*/
|
||||||
struct IndustryBuildData {
|
struct IndustryBuildData {
|
||||||
IndustryTypeBuildData builddata[NUM_INDUSTRYTYPES]; ///< Industry build data for every industry type.
|
IndustryTypeBuildData builddata[NUM_INDUSTRYTYPES]; ///< Industry build data for every industry type.
|
||||||
|
uint32 wanted_inds; ///< Number of wanted industries (bits 31-16), and a fraction (bits 15-0).
|
||||||
|
|
||||||
void SetupTargetCount();
|
void SetupTargetCount();
|
||||||
void TryBuildNewIndustry();
|
void TryBuildNewIndustry();
|
||||||
|
|
|
@ -113,8 +113,54 @@ static void Ptrs_INDY()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern const ChunkHandler _industry_chunk_handlers[] = {
|
/** Description of the data to save and load in #IndustryBuildData. */
|
||||||
{ 'INDY', Save_INDY, Load_INDY, Ptrs_INDY, NULL, CH_ARRAY},
|
static const SaveLoad _industry_builder_desc[] = {
|
||||||
{ 'IIDS', Save_IIDS, Load_IIDS, NULL, NULL, CH_ARRAY},
|
SLEG_VAR(_industry_builder.wanted_inds, SLE_UINT32),
|
||||||
{ 'TIDS', Save_TIDS, Load_TIDS, NULL, NULL, CH_ARRAY | CH_LAST},
|
SLEG_END()
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Load/save industry builder. */
|
||||||
|
static void LoadSave_IBLD()
|
||||||
|
{
|
||||||
|
SlGlobList(_industry_builder_desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Description of the data to save and load in #IndustryTypeBuildData. */
|
||||||
|
static const SaveLoad _industrytype_builder_desc[] = {
|
||||||
|
SLE_VAR(IndustryTypeBuildData, probability, SLE_UINT32),
|
||||||
|
SLE_VAR(IndustryTypeBuildData, min_number, SLE_UINT8),
|
||||||
|
SLE_VAR(IndustryTypeBuildData, target_count, SLE_UINT16),
|
||||||
|
SLE_VAR(IndustryTypeBuildData, max_wait, SLE_UINT16),
|
||||||
|
SLE_VAR(IndustryTypeBuildData, wait_count, SLE_UINT16),
|
||||||
|
SLE_END()
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Save industry-type build data. */
|
||||||
|
static void Save_ITBL()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < NUM_INDUSTRYTYPES; i++) {
|
||||||
|
SlSetArrayIndex(i);
|
||||||
|
SlObject(_industry_builder.builddata + i, _industrytype_builder_desc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Load industry-type build data. */
|
||||||
|
static void Load_ITBL()
|
||||||
|
{
|
||||||
|
int index;
|
||||||
|
for (int i = 0; i < NUM_INDUSTRYTYPES; i++) {
|
||||||
|
index = SlIterateArray();
|
||||||
|
assert(index == i);
|
||||||
|
SlObject(_industry_builder.builddata + i, _industrytype_builder_desc);
|
||||||
|
}
|
||||||
|
index = SlIterateArray();
|
||||||
|
assert(index == -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern const ChunkHandler _industry_chunk_handlers[] = {
|
||||||
|
{ 'INDY', Save_INDY, Load_INDY, Ptrs_INDY, NULL, CH_ARRAY},
|
||||||
|
{ 'IIDS', Save_IIDS, Load_IIDS, NULL, NULL, CH_ARRAY},
|
||||||
|
{ 'TIDS', Save_TIDS, Load_TIDS, NULL, NULL, CH_ARRAY},
|
||||||
|
{ 'IBLD', LoadSave_IBLD, LoadSave_IBLD, NULL, NULL, CH_RIFF},
|
||||||
|
{ 'ITBL', Save_ITBL, Load_ITBL, NULL, NULL, CH_ARRAY | CH_LAST},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue