Changeset - r6533:e4ba06da0f4c
[Not reviewed]
master
0 3 0
belugas - 17 years ago 2007-04-26 20:20:12
belugas@openttd.org
(svn r9721) -Codechange: -Codechange: Cleanup of industry_cmd (Step-12). Dynamically build the legends (name and color) for industries in the smallmap_gui.
All the tiny fonts industry names should be removed from language files soon.
3 files changed with 43 insertions and 75 deletions:
0 comments (0 inline, 0 general)
src/industry.h
Show inline comments
 
@@ -131,24 +131,27 @@ struct IndustrySpec {
 
struct IndustryTileSpec {
 
	CargoID accepts_cargo[3];             ///< Cargo accepted by this tile
 
	Slope slopes_refused;                 ///< slope pattern on which this tile cannot be built
 
	byte anim_production;                 ///< Animation frame to start when goods are produced
 
	byte anim_next;                       ///< Next frame in an animation
 
	bool anim_state;                      ///< When true, the tile has to be drawn using the animation
 
                                         ///< state instead of the construction state
 
};
 

	
 
const IndustrySpec *GetIndustrySpec(IndustryType thistype);    ///< Array of industries default data
 
const IndustryTileSpec *GetIndustryTileSpec(IndustryGfx gfx);  ///< Array of industry tiles default data
 

	
 
/* smallmap_gui.cpp */
 
void BuildIndustriesLegend();
 

	
 
DECLARE_OLD_POOL(Industry, Industry, 3, 8000)
 

	
 
/**
 
 * Check if an Industry really exists.
 
 * @param industry to check
 
 * @return true if position is a valid one
 
 */
 
static inline bool IsValidIndustry(const Industry *industry)
 
{
 
	return industry->xy != 0;
 
}
 

	
src/newgrf.cpp
Show inline comments
 
@@ -29,24 +29,25 @@
 
#include "fontcache.h"
 
#include "date.h"
 
#include "currency.h"
 
#include "landscape.h"
 
#include "sound.h"
 
#include "newgrf_config.h"
 
#include "newgrf_house.h"
 
#include "newgrf_sound.h"
 
#include "newgrf_spritegroup.h"
 
#include "helpers.hpp"
 
#include "table/town_land.h"
 
#include "cargotype.h"
 
#include "industry.h"
 

	
 
/* TTDPatch extended GRF format codec
 
 * (c) Petr Baudis 2004 (GPL'd)
 
 * Changes by Florian octo Forster are (c) by the OpenTTD development team.
 
 *
 
 * Contains portions of documentation by TTDPatch team.
 
 * Thanks especially to Josef Drexler for the documentation as well as a lot
 
 * of help at #tycoon. Also thanks to Michael Blunck for is GRF files which
 
 * served as subject to the initial testing of this codec. */
 

	
 

	
 
static int _skip_sprites; // XXX
 
@@ -4760,24 +4761,27 @@ void InitDepotWindowBlockSizes();
 

	
 
static void AfterLoadGRFs()
 
{
 
	/* Pre-calculate all refit masks after loading GRF files. */
 
	CalculateRefitMasks();
 

	
 
	/* Set the block size in the depot windows based on vehicle sprite sizes */
 
	InitDepotWindowBlockSizes();
 

	
 
	/* Add all new houses to the house array. */
 
	FinaliseHouseArray();
 

	
 
	/* Create dynamic list of industry legends for smallmap_gui.cpp */
 
	BuildIndustriesLegend();
 

	
 
	/* Map cargo strings. This is a separate step because cargos are
 
	 * loaded before strings... */
 
	MapNewCargoStrings();
 
}
 

	
 
void LoadNewGRF(uint load_index, uint file_index)
 
{
 
	InitializeGRFSpecial();
 

	
 
	ResetNewGRFData();
 

	
 
	/* Load newgrf sprites
src/smallmap_gui.cpp
Show inline comments
 
@@ -82,90 +82,24 @@ static const LegendAndColour _legend_lan
 
};
 

	
 
static const LegendAndColour _legend_vehicles[] = {
 
	MK(0xB8, STR_00F5_TRAINS),
 
	MK(0xBF, STR_00F6_ROAD_VEHICLES),
 
	MK(0x98, STR_00F7_SHIPS),
 
	MK(0x0F, STR_00F8_AIRCRAFT),
 
	MS(0xD7, STR_00F9_TRANSPORT_ROUTES),
 
	MK(0xB5, STR_00EE_BUILDINGS_INDUSTRIES),
 
	MKEND()
 
};
 

	
 
static const LegendAndColour _legend_industries_normal[] = {
 
	MK(0xD7, STR_00FA_COAL_MINE),
 
	MK(0xB8, STR_00FB_POWER_STATION),
 
	MK(0x56, STR_00FC_FOREST),
 
	MK(0xC2, STR_00FD_SAWMILL),
 
	MK(0xBF, STR_00FE_OIL_REFINERY),
 
	MK(0x0F, STR_0105_BANK),
 

	
 
	MS(0x30, STR_00FF_FARM),
 
	MK(0xAE, STR_0100_FACTORY),
 
	MK(0x98, STR_0102_OIL_WELLS),
 
	MK(0x37, STR_0103_IRON_ORE_MINE),
 
	MK(0x0A, STR_0104_STEEL_MILL),
 
	MKEND()
 
};
 

	
 
static const LegendAndColour _legend_industries_hilly[] = {
 
	MK(0xD7, STR_00FA_COAL_MINE),
 
	MK(0xB8, STR_00FB_POWER_STATION),
 
	MK(0x56, STR_00FC_FOREST),
 
	MK(0x0A, STR_0106_PAPER_MILL),
 
	MK(0xBF, STR_00FE_OIL_REFINERY),
 
	MK(0x37, STR_0108_FOOD_PROCESSING_PLANT),
 
	MS(0x30, STR_00FF_FARM),
 

	
 
	MK(0xAE, STR_0101_PRINTING_WORKS),
 
	MK(0x98, STR_0102_OIL_WELLS),
 
	MK(0xC2, STR_0107_GOLD_MINE),
 
	MK(0x0F, STR_0105_BANK),
 
	MKEND()
 
};
 

	
 
static const LegendAndColour _legend_industries_desert[] = {
 
	MK(0xBF, STR_00FE_OIL_REFINERY),
 
	MK(0x98, STR_0102_OIL_WELLS),
 
	MK(0x0F, STR_0105_BANK),
 
	MK(0xB8, STR_0109_DIAMOND_MINE),
 
	MK(0x37, STR_0108_FOOD_PROCESSING_PLANT),
 
	MK(0x0A, STR_010A_COPPER_ORE_MINE),
 
	MK(0x30, STR_00FF_FARM),
 
	MS(0x56, STR_010B_FRUIT_PLANTATION),
 

	
 
	MK(0x27, STR_010C_RUBBER_PLANTATION),
 
	MK(0x25, STR_010D_WATER_SUPPLY),
 
	MK(0xD0, STR_010E_WATER_TOWER),
 
	MK(0xAE, STR_0100_FACTORY),
 
	MK(0xC2, STR_010F_LUMBER_MILL),
 
	MKEND()
 
};
 

	
 
static const LegendAndColour _legend_industries_candy[] = {
 
	MK(0x30, STR_0110_COTTON_CANDY_FOREST),
 
	MK(0xAE, STR_0111_CANDY_FACTORY),
 
	MK(0x27, STR_0112_BATTERY_FARM),
 
	MK(0x37, STR_0113_COLA_WELLS),
 
	MK(0xD0, STR_0114_TOY_SHOP),
 
	MK(0x0A, STR_0115_TOY_FACTORY),
 
	MS(0x25, STR_0116_PLASTIC_FOUNTAINS),
 

	
 
	MK(0xB8, STR_0117_FIZZY_DRINK_FACTORY),
 
	MK(0x98, STR_0118_BUBBLE_GENERATOR),
 
	MK(0xC2, STR_0119_TOFFEE_QUARRY),
 
	MK(0x0F, STR_011A_SUGAR_MINE),
 
	MKEND()
 
};
 

	
 
static const LegendAndColour _legend_routes[] = {
 
	MK(0xD7, STR_00EB_ROADS),
 
	MK(0x0A, STR_00EC_RAILROADS),
 
	MK(0xB5, STR_00EE_BUILDINGS_INDUSTRIES),
 
	MS(0x56, STR_011B_RAILROAD_STATION),
 

	
 
	MK(0xC2, STR_011C_TRUCK_LOADING_BAY),
 
	MK(0xBF, STR_011D_BUS_STATION),
 
	MK(0xB8, STR_011E_AIRPORT_HELIPORT),
 
	MK(0x98, STR_011F_DOCK),
 
	MKEND()
 
};
 
@@ -188,39 +122,58 @@ static const LegendAndColour _legend_veg
 

	
 
static const LegendAndColour _legend_land_owners[] = {
 
	MK(0xCA, STR_0126_WATER),
 
	MK(0x54, STR_0127_NO_OWNER),
 
	MK(0xB4, STR_0128_TOWNS),
 
	MK(0x20, STR_0129_INDUSTRIES),
 
	MKEND()
 
};
 
#undef MK
 
#undef MS
 
#undef MKEND
 

	
 
/** Allow room for all industries, plus a terminator entry
 
 * This is required in order to have the indutry slots all filled up */
 
static LegendAndColour _legend_from_industries[NUM_INDUSTRYTYPES+1];
 

	
 
enum { IND_OFFS = 6 };  ///< allow to "jump" to the industries corresponding to the landscape
 
/**
 
 * Fills an array for the industries legends.
 
 */
 
void BuildIndustriesLegend()
 
{
 
	const IndustrySpec *indsp;
 
	uint j = 0;
 

	
 
	/* Add each name */
 
	for (IndustryType i = 0; i < NUM_INDUSTRYTYPES; i++) {
 
		indsp = GetIndustrySpec(i);
 
		if (HASBIT(indsp->climate_availability, _opt.landscape)) {
 
			_legend_from_industries[j].legend = indsp->name;
 
			_legend_from_industries[j].colour = indsp->map_colour;
 
			_legend_from_industries[j].col_break = (j % 6) == 0;  // break is performed on the 7th item
 
			_legend_from_industries[j].end = false;
 
			j++;
 
		}
 
	}
 
	/* Terminate the list */
 
	_legend_from_industries[j].end = true;
 
}
 

	
 
static const LegendAndColour * const _legend_table[] = {
 
	_legend_land_contours,
 
	_legend_vehicles,
 
	NULL,
 
	_legend_from_industries,
 
	_legend_routes,
 
	_legend_vegetation,
 
	_legend_land_owners,
 

	
 
	_legend_industries_normal,
 
	_legend_industries_hilly,
 
	_legend_industries_desert,
 
	_legend_industries_candy,
 
};
 

	
 
#if defined(OTTD_ALIGNMENT)
 
	static inline void WRITE_PIXELS(Pixel* d, uint32 val)
 
	{
 
#	if defined(TTD_BIG_ENDIAN)
 
		d[0] = GB(val, 24, 8);
 
		d[1] = GB(val, 16, 8);
 
		d[2] = GB(val,  8, 8);
 
		d[3] = GB(val,  0, 8);
 
#	elif defined(TTD_LITTLE_ENDIAN)
 
		d[0] = GB(val,  0, 8);
 
@@ -791,33 +744,41 @@ void SmallMapCenterOnCurrentPos(Window *
 
static void SmallMapWindowProc(Window *w, WindowEvent *e)
 
{
 
	switch (e->event) {
 
		case WE_PAINT: {
 
			const LegendAndColour *tbl;
 
			int x, y, y_org;
 
			DrawPixelInfo new_dpi;
 

	
 
			/* draw the window */
 
			SetDParam(0, STR_00E5_CONTOURS + _smallmap_type);
 
			DrawWindowWidgets(w);
 

	
 
			/* draw the legend */
 
			tbl = _legend_table[(_smallmap_type != 2) ? _smallmap_type : (_opt.landscape + IND_OFFS)];
 
			tbl = _legend_table[_smallmap_type];
 

	
 
			x = 4;
 
			y_org = w->height - 44 - 11;
 
			y = y_org;
 
			for (;;) {
 
				GfxFillRect(x,     y + 1, x + 8, y + 5, 0);
 
				GfxFillRect(x + 1, y + 2, x + 7, y + 4, tbl->colour);
 

	
 
				if (_smallmap_type == 2) {
 
					/* Industry name must be formated, since it's not in tiny font in the specs.
 
					* So, draw with a parameter and use the STR_7065 string, which is tiny, black */
 
					SetDParam(0, tbl->legend);
 
					DrawString(x + 11, y, STR_7065, 0);
 
				} else {
 
				DrawString(x + 11, y, tbl->legend, 0);
 
				}
 

	
 
				tbl += 1;
 
				y += 6;
 

	
 
				if (tbl->end) { // end of the list
 
					break;
 
				} else if (tbl->col_break) {
 
					/*  break asked, continue at top, 123 pixels (one "row") to the right */
 
					x += 123;
 
					y = y_org;
 
				}
 
			}
0 comments (0 inline, 0 general)