Changeset - r7102:73f11fdf011b
[Not reviewed]
master
0 2 0
belugas - 17 years ago 2007-06-28 02:14:40
belugas@openttd.org
(svn r10369) -Codechange: Add the IndustryType parameter to the GetIndustryCallback function.
Sometimes, the industry might not be able to provide its type, since it does not exists at all
2 files changed with 3 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/newgrf_industries.cpp
Show inline comments
 
@@ -155,111 +155,111 @@ uint32 IndustryGetVariable(const Resolve
 
		 * 0x10 if randomly created or from a map pre-newindustry.
 
		 * Else, the company who funded it */
 
		case 0xA7: return 0x10;
 

	
 
		case 0xB0: // Date when built since 1920 (in days)
 
		case 0xB3: // Construction type
 
		case 0xB4: break; // Date last cargo accepted since 1920 (in days)
 

	
 
		/* Industry structure access*/
 
		case 0x80: return industry->xy;
 
		case 0x81: return GB(industry->xy, 8, 8);
 
		/* Pointer to the town the industry is associated with */
 
		case 0x82:
 
		case 0x83:
 
		case 0x84:
 
		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 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;
 
		/* amount of cargo produced so far THIS month. */
 
		case 0x94: return industry->this_month_production[0];
 
		case 0x95: return GB(industry->this_month_production[0], 8, 8);
 
		case 0x96: return industry->this_month_production[1];
 
		case 0x97: return GB(industry->this_month_production[1], 8, 8);
 
		/* amount of cargo transported so far THIS month. */
 
		case 0x98: return industry->this_month_transported[0];
 
		case 0x99: return GB(industry->this_month_transported[0], 8, 8);
 
		case 0x9A: return industry->this_month_transported[1];
 
		case 0x9B: return GB(industry->this_month_transported[0], 8, 8);
 
		/* fraction of cargo transported LAST month. */
 
		case 0x9C:
 
		case 0x9D: return industry->last_month_pct_transported[variable - 0x9C];
 
		/* amount of cargo produced LAST month. */
 
		case 0x9E: return industry->last_month_production[0];
 
		case 0x9F: return GB(industry->last_month_production[0], 8, 8);
 
		case 0xA0: return industry->last_month_production[1];
 
		case 0xA1: return GB(industry->last_month_production[1], 8, 8);
 
		/* amount of cargo transported last month. */
 
		case 0xA2: return industry->last_month_transported[0];
 
		case 0xA3: return GB(industry->last_month_transported[0], 8, 8);
 
		case 0xA4: return industry->last_month_transported[1];
 
		case 0xA5: return GB(industry->last_month_transported[0], 8, 8);
 

	
 
		case 0xA6: return industry->type;
 

	
 
		case 0xA8: return industry->random_color;
 
		case 0xA9: return industry->last_prod_year; // capped?
 
		case 0xAA: return industry->counter;
 
		case 0xAB: return GB(industry->counter, 8, 8);
 
		case 0xAC: return industry->was_cargo_delivered;
 
	}
 

	
 
	DEBUG(grf, 1, "Unhandled industry property 0x%X", variable);
 

	
 
	*available = false;
 
	return (uint32)-1;
 
}
 

	
 
static const SpriteGroup *IndustryResolveReal(const ResolverObject *object, const SpriteGroup *group)
 
{
 
	/* IndustryTile do not have 'real' groups */
 
	return NULL;
 
}
 

	
 
static void NewIndustryResolver(ResolverObject *res, TileIndex tile, Industry *indus)
 
{
 
	res->GetRandomBits = IndustryTileGetRandomBits;
 
	res->GetTriggers   = IndustryTileGetTriggers;
 
	res->SetTriggers   = IndustryTileSetTriggers;
 
	res->GetVariable   = IndustryGetVariable;
 
	res->ResolveReal   = IndustryResolveReal;
 

	
 
	res->u.industry.tile = tile;
 
	res->u.industry.ind  = indus;
 
	res->u.industry.gfx  = INVALID_INDUSTRYTILE;
 

	
 
	res->callback        = 0;
 
	res->callback_param1 = 0;
 
	res->callback_param2 = 0;
 
	res->last_value      = 0;
 
	res->trigger         = 0;
 
	res->reseed          = 0;
 
}
 

	
 
uint16 GetIndustryCallback(uint16 callback, uint32 param1, uint32 param2, Industry *industry, TileIndex tile)
 
uint16 GetIndustryCallback(uint16 callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile)
 
{
 
	ResolverObject object;
 
	const SpriteGroup *group;
 

	
 
	NewIndustryResolver(&object, tile, industry);
 
	object.callback = callback;
 
	object.callback_param1 = param1;
 
	object.callback_param2 = param2;
 

	
 
	group = Resolve(GetIndustrySpec(industry->type)->grf_prop.spritegroup, &object);
 
	group = Resolve(GetIndustrySpec(type)->grf_prop.spritegroup, &object);
 
	if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED;
 

	
 
	return group->g.callback.result;
 
}
src/newgrf_industries.h
Show inline comments
 
/* $Id$ */
 

	
 
/** @file newgrf_industries.h */
 

	
 
#ifndef NEWGRF_INDUSTRIES_H
 
#define NEWGRF_INDUSTRIES_H
 

	
 
#include "industry.h"
 
#include "newgrf_spritegroup.h"
 

	
 
/* in newgrf_industry.cpp */
 
uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available);
 
uint16 GetIndustryCallback(uint16 callback, uint32 param1, uint32 param2, Industry *industry, TileIndex tile);
 
uint16 GetIndustryCallback(uint16 callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile);
 
uint32 GetIndustryIDAtOffset(TileIndex new_tile, TileIndex old_tile, const Industry *i);
 

	
 
/* in newgrf_industrytiles.cpp*/
 
uint32 IndustryTileGetRandomBits(const ResolverObject *object);
 
uint32 IndustryTileGetTriggers(const ResolverObject *object);
 
void IndustryTileSetTriggers(const ResolverObject *object, int triggers);
 

	
 
#endif /* NEWGRF_INDUSTRIES_H */
0 comments (0 inline, 0 general)