Changeset - r7165:b30ba7925dc4
[Not reviewed]
master
0 5 0
rubidium - 17 years ago 2007-07-04 18:27:21
rubidium@openttd.org
(svn r10439) -Codechange: initial steps for customized industry productions.
5 files changed with 35 insertions and 21 deletions:
0 comments (0 inline, 0 general)
src/economy.cpp
Show inline comments
 
@@ -1231,15 +1231,24 @@ static void DeliverGoodsToIndustry(TileI
 
		}
 
	}
 

	
 
	/* 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);
 
		}
 
	}
 
}
 

	
 
static bool CheckSubsidised(Station *from, Station *to, CargoID cargo_type)
 
{
 
	Subsidy *s;
src/industry.h
Show inline comments
 
@@ -75,13 +75,14 @@ DECLARE_ENUM_AS_BIT_SET(IndustyBehaviour
 
 */
 
struct Industry {
 
	TileIndex xy;                       ///< coordinates of the primary tile the industry is built one
 
	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
 
	uint16 this_month_transported[2];   ///< stats of this month's transport per cargo
 
	byte last_month_pct_transported[2]; ///< percentage transported per cargo in the last full month
 
	uint16 last_month_production[2];    ///< total units produced per cargo in the last full month
src/industry_cmd.cpp
Show inline comments
 
@@ -374,15 +374,15 @@ static CommandCost ClearTile_Industry(Ti
 
static void TransportIndustryGoods(TileIndex tile)
 
{
 
	Industry *i = GetIndustryByTile(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;
 

	
 
		i->this_month_production[0] += cw;
 

	
 
@@ -397,15 +397,15 @@ static void TransportIndustryGoods(TileI
 
				SetIndustryGfx(tile, newgfx);
 
				MarkTileDirtyByTile(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;
 

	
 
		i->this_month_production[1] += cw;
 

	
 
		am = MoveGoodsToStation(i->xy, i->width, i->height, indspec->produced_cargo[1], cw);
 
@@ -940,13 +940,13 @@ static void ChopLumberMillTrees(Industry
 
{
 
	TileIndex tile = i->xy;
 

	
 
	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)
 
{
 
	uint32 r;
 
	uint num;
 
@@ -963,14 +963,14 @@ static void ProduceIndustryGoods(Industr
 

	
 
	i->counter--;
 

	
 
	/* 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);
 
		} else if ((indbehav & INDUSTRYBEH_CUT_TREES) && (i->counter & 0x1FF) == 0) {
 
			ChopLumberMillTrees(i);
 
		}
 
@@ -1388,14 +1388,17 @@ static void DoCreateNewIndustry(Industry
 
	i->town = t;
 
	i->owner = owner;
 

	
 
	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;
 
	i->this_month_transported[1] = 0;
 
	i->last_month_pct_transported[0] = 0;
 
	i->last_month_pct_transported[1] = 0;
 
@@ -1895,13 +1898,14 @@ static const SaveLoad _industry_desc[] =
 
	SLE_CONDVAR(Industry, xy,                         SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
 
	SLE_CONDVAR(Industry, xy,                         SLE_UINT32,                  6, SL_MAX_VERSION),
 
	    SLE_VAR(Industry, width,                      SLE_UINT8),
 
	    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),
 
	    SLE_ARR(Industry, this_month_production,      SLE_UINT16, 2),
 
	    SLE_ARR(Industry, this_month_transported,     SLE_UINT16, 2),
 
	    SLE_ARR(Industry, last_month_pct_transported, SLE_UINT8,  2),
src/newgrf_industries.cpp
Show inline comments
 
@@ -120,14 +120,14 @@ uint32 IndustryGetVariable(const Resolve
 

	
 
	switch (variable) {
 
		case 0x40:
 
		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;
 
			}
 
		}
 
		/* TODO: somehow determine whether we're in water or not */
 
		case 0x43: return GetClosestWaterDistance(tile, true); // Manhattan distance of closes dry/water tile
 
@@ -170,16 +170,16 @@ uint32 IndustryGetVariable(const Resolve
 
		case 0x85: break; // not supported
 
		case 0x86: return industry->width;
 
		case 0x87: return industry->height;// xy dimensions
 
		/*  */
 
		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:
 
		case 0x91:
 
		case 0x92: return indspec->accepts_cargo[variable - 0x90];
 
		case 0x93: return industry->prod_level;
src/oldloader.cpp
Show inline comments
 
@@ -667,14 +667,14 @@ static const OldChunks industry_chunk[] 
 
	OCL_SVAR(   OC_TILE, Industry, xy ),
 
	OCL_VAR ( OC_UINT32,   1, &_old_town_index ),
 
	OCL_SVAR(  OC_UINT8, Industry, width ),
 
	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] ),
 

	
 
	OCL_NULL( 3 ),  ///< used to be industry's accepts_cargo
 

	
0 comments (0 inline, 0 general)