newgrf_station.c
changeset 3764 ebcaf412fb3a
parent 3758 1ec9e4e26a9f
child 3765 e057e2b740d4
equal deleted inserted replaced
3763:460bbb4a8154 3764:ebcaf412fb3a
     3 /** @file newgrf_station.c Functions for dealing with station classes and custom stations. */
     3 /** @file newgrf_station.c Functions for dealing with station classes and custom stations. */
     4 
     4 
     5 #include "stdafx.h"
     5 #include "stdafx.h"
     6 #include "openttd.h"
     6 #include "openttd.h"
     7 #include "variables.h"
     7 #include "variables.h"
       
     8 #include "functions.h"
     8 #include "debug.h"
     9 #include "debug.h"
     9 #include "sprite.h"
    10 #include "sprite.h"
       
    11 #include "table/sprites.h"
    10 #include "table/strings.h"
    12 #include "table/strings.h"
    11 #include "station.h"
    13 #include "station.h"
    12 #include "station_map.h"
    14 #include "station_map.h"
    13 #include "newgrf_callbacks.h"
    15 #include "newgrf_callbacks.h"
    14 #include "newgrf_station.h"
    16 #include "newgrf_station.h"
   562 		}
   564 		}
   563 	}
   565 	}
   564 
   566 
   565 	return freeable;
   567 	return freeable;
   566 }
   568 }
       
   569 
       
   570 /** Draw representation of a station tile for GUI purposes.
       
   571  * @param x, y Position of image.
       
   572  * @param dir Direction.
       
   573  * @param railtype Rail type.
       
   574  * @param sclass, station Type of station.
       
   575  * @return True if the tile was drawn (allows for fallback to default graphic)
       
   576  */
       
   577 bool DrawStationTile(int x, int y, RailType railtype, Axis axis, StationClassID sclass, uint station)
       
   578 {
       
   579 	extern uint16 _custom_sprites_base;
       
   580 
       
   581 	const StationSpec *statspec;
       
   582 	const DrawTileSprites *sprites;
       
   583 	const DrawTileSeqStruct *seq;
       
   584 	const RailtypeInfo *rti = GetRailTypeInfo(railtype);
       
   585 	SpriteID relocation;
       
   586 	PalSpriteID image;
       
   587 	PalSpriteID colourmod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player));
       
   588 	uint tile = 2;
       
   589 
       
   590 	statspec = GetCustomStationSpec(sclass, station);
       
   591 	if (statspec == NULL) return false;
       
   592 
       
   593 	relocation = GetCustomStationRelocation(statspec, NULL, INVALID_TILE);
       
   594 
       
   595 	if (HASBIT(statspec->callbackmask, CBM_CUSTOM_LAYOUT)) {
       
   596 		uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0x2110000, 0, statspec, NULL, INVALID_TILE);
       
   597 		if (callback != CALLBACK_FAILED) tile = callback;
       
   598 	}
       
   599 
       
   600 	if (statspec->renderdata == NULL) {
       
   601 		sprites = GetStationTileLayout(tile + axis);
       
   602 		relocation -= 0x42D;
       
   603 	} else {
       
   604 		sprites = &statspec->renderdata[(tile < statspec->tiles) ? tile + axis : axis];
       
   605 	}
       
   606 
       
   607 	image = sprites->ground_sprite;
       
   608 	image += (image < _custom_sprites_base) ? rti->total_offset : rti->custom_ground_offset;
       
   609 
       
   610 	if (image & PALETTE_MODIFIER_COLOR) image &= SPRITE_MASK;
       
   611 	DrawSprite(image, x, y);
       
   612 
       
   613 	foreach_draw_tile_seq(seq, sprites->seq) {
       
   614 		Point pt;
       
   615 		image = seq->image + relocation;
       
   616 
       
   617 		if ((byte)seq->delta_z != 0x80) {
       
   618 			pt = RemapCoords(seq->delta_x, seq->delta_y, seq->delta_z);
       
   619 			DrawSprite((image & SPRITE_MASK) | colourmod, x + pt.x, y + pt.y);
       
   620 		}
       
   621 	}
       
   622 
       
   623 	return true;
       
   624 }
       
   625