src/station_cmd.cpp
branchNewGRF_ports
changeset 10274 b3c58f3df92b
parent 10242 52b4a9006029
child 10346 a1e9f8871c05
equal deleted inserted replaced
10243:e9066a148720 10274:b3c58f3df92b
    41 #include "date_func.h"
    41 #include "date_func.h"
    42 #include "vehicle_func.h"
    42 #include "vehicle_func.h"
    43 #include "string_func.h"
    43 #include "string_func.h"
    44 #include "signal_func.h"
    44 #include "signal_func.h"
    45 #include "oldpool_func.h"
    45 #include "oldpool_func.h"
       
    46 #include "animated_tile_func.h"
    46 
    47 
    47 #include "table/sprites.h"
    48 #include "table/sprites.h"
    48 #include "table/strings.h"
    49 #include "table/strings.h"
    49 
    50 
    50 DEFINE_OLD_POOL_GENERIC(Station, Station)
    51 DEFINE_OLD_POOL_GENERIC(Station, Station)
  1125 		st->trainst_w = finalvalues[1];
  1126 		st->trainst_w = finalvalues[1];
  1126 		st->trainst_h = finalvalues[2];
  1127 		st->trainst_h = finalvalues[2];
  1127 
  1128 
  1128 		st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TRY);
  1129 		st->rect.BeforeAddRect(tile_org, w_org, h_org, StationRect::ADD_TRY);
  1129 
  1130 
       
  1131 		if (statspec != NULL) {
       
  1132 			/* Include this station spec's animation trigger bitmask
       
  1133 			 * in the station's cached copy. */
       
  1134 			st->cached_anim_triggers |= statspec->anim_triggers;
       
  1135 		}
       
  1136 
  1130 		tile_delta = (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
  1137 		tile_delta = (axis == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
  1131 		track = AxisToTrack(axis);
  1138 		track = AxisToTrack(axis);
  1132 
  1139 
  1133 		layout_ptr = (byte*)alloca(numtracks * plat_len);
  1140 		layout_ptr = (byte*)alloca(numtracks * plat_len);
  1134 		GetStationLayout(layout_ptr, numtracks, plat_len, statspec);
  1141 		GetStationLayout(layout_ptr, numtracks, plat_len, statspec);
  1141 			do {
  1148 			do {
  1142 				byte layout = *layout_ptr++;
  1149 				byte layout = *layout_ptr++;
  1143 				MakeRailStation(tile, st->owner, st->index, axis, layout & ~1, (RailType)GB(p2, 0, 4));
  1150 				MakeRailStation(tile, st->owner, st->index, axis, layout & ~1, (RailType)GB(p2, 0, 4));
  1144 				SetCustomStationSpecIndex(tile, specindex);
  1151 				SetCustomStationSpecIndex(tile, specindex);
  1145 				SetStationTileRandomBits(tile, GB(Random(), 0, 4));
  1152 				SetStationTileRandomBits(tile, GB(Random(), 0, 4));
       
  1153 				SetStationAnimationFrame(tile, 0);
  1146 
  1154 
  1147 				if (statspec != NULL) {
  1155 				if (statspec != NULL) {
  1148 					/* Use a fixed axis for GetPlatformInfo as our platforms / numtracks are always the right way around */
  1156 					/* Use a fixed axis for GetPlatformInfo as our platforms / numtracks are always the right way around */
  1149 					uint32 platinfo = GetPlatformInfo(AXIS_X, 0, plat_len, numtracks_orig, plat_len - w, numtracks_orig - numtracks, false);
  1157 					uint32 platinfo = GetPlatformInfo(AXIS_X, 0, plat_len, numtracks_orig, plat_len - w, numtracks_orig - numtracks, false);
  1150 
  1158 
  1151 					/* As the station is not yet completely finished, the station does not yet exist. */
  1159 					/* As the station is not yet completely finished, the station does not yet exist. */
  1152 					uint16 callback = GetStationCallback(CBID_STATION_TILE_LAYOUT, platinfo, 0, statspec, NULL, tile);
  1160 					uint16 callback = GetStationCallback(CBID_STATION_TILE_LAYOUT, platinfo, 0, statspec, NULL, tile);
  1153 					if (callback != CALLBACK_FAILED && callback < 8) SetStationGfx(tile, (callback & ~1) + axis);
  1161 					if (callback != CALLBACK_FAILED && callback < 8) SetStationGfx(tile, (callback & ~1) + axis);
       
  1162 
       
  1163 					/* Trigger station animation -- after building? */
       
  1164 					StationAnimationTrigger(st, tile, STAT_ANIM_BUILT);
  1154 				}
  1165 				}
  1155 
  1166 
  1156 				tile += tile_delta;
  1167 				tile += tile_delta;
  1157 			} while (--w);
  1168 			} while (--w);
  1158 			AddTrackToSignalBuffer(tile_org, track, _current_player);
  1169 			AddTrackToSignalBuffer(tile_org, track, _current_player);
  1370 		st->facilities &= ~FACIL_TRAIN;
  1381 		st->facilities &= ~FACIL_TRAIN;
  1371 
  1382 
  1372 		free(st->speclist);
  1383 		free(st->speclist);
  1373 		st->num_specs = 0;
  1384 		st->num_specs = 0;
  1374 		st->speclist  = NULL;
  1385 		st->speclist  = NULL;
       
  1386 		st->cached_anim_triggers = 0;
  1375 
  1387 
  1376 		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_TRAINS);
  1388 		InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_TRAINS);
  1377 		UpdateStationVirtCoordDirty(st);
  1389 		UpdateStationVirtCoordDirty(st);
  1378 		DeleteStationIfEmpty(st);
  1390 		DeleteStationIfEmpty(st);
  1379 	}
  1391 	}
  2480 		{ GFX_RADAR_METROPOLITAN_FIRST,  GFX_RADAR_METROPOLITAN_LAST,  3 },
  2492 		{ GFX_RADAR_METROPOLITAN_FIRST,  GFX_RADAR_METROPOLITAN_LAST,  3 },
  2481 		{ GFX_RADAR_DISTRICTWE_FIRST,    GFX_RADAR_DISTRICTWE_LAST,    3 },
  2493 		{ GFX_RADAR_DISTRICTWE_FIRST,    GFX_RADAR_DISTRICTWE_LAST,    3 },
  2482 		{ GFX_WINDSACK_INTERCON_FIRST,   GFX_WINDSACK_INTERCON_LAST,   1 }
  2494 		{ GFX_WINDSACK_INTERCON_FIRST,   GFX_WINDSACK_INTERCON_LAST,   1 }
  2483 	};
  2495 	};
  2484 
  2496 
       
  2497 	if (IsRailwayStation(tile)) {
       
  2498 		AnimateStationTile(tile);
       
  2499 		return;
       
  2500 	}
       
  2501 
  2485 	StationGfx gfx = GetStationGfx(tile);
  2502 	StationGfx gfx = GetStationGfx(tile);
  2486 
  2503 
  2487 	for (const AnimData *i = data; i != endof(data); i++) {
  2504 	for (const AnimData *i = data; i != endof(data); i++) {
  2488 		if (i->from <= gfx && gfx <= i->to) {
  2505 		if (i->from <= gfx && gfx <= i->to) {
  2489 			if ((_tick_counter & i->delay) == 0) {
  2506 			if ((_tick_counter & i->delay) == 0) {
  2727 	if (++_station_tick_ctr > GetMaxStationIndex()) _station_tick_ctr = 0;
  2744 	if (++_station_tick_ctr > GetMaxStationIndex()) _station_tick_ctr = 0;
  2728 
  2745 
  2729 	if (IsValidStationID(i)) StationHandleBigTick(GetStation(i));
  2746 	if (IsValidStationID(i)) StationHandleBigTick(GetStation(i));
  2730 
  2747 
  2731 	Station *st;
  2748 	Station *st;
  2732 	FOR_ALL_STATIONS(st) StationHandleSmallTick(st);
  2749 	FOR_ALL_STATIONS(st) {
       
  2750 		StationHandleSmallTick(st);
       
  2751 
       
  2752 		/* Run 250 tick interval trigger for station animation.
       
  2753 		 * Station index is included so that triggers are not all done
       
  2754 		 * at the same time. */
       
  2755 		if ((_tick_counter + st->index) % 250 == 0) {
       
  2756 			StationAnimationTrigger(st, st->xy, STAT_ANIM_250_TICKS);
       
  2757 		}
       
  2758 	}
  2733 }
  2759 }
  2734 
  2760 
  2735 void StationMonthlyLoop()
  2761 void StationMonthlyLoop()
  2736 {
  2762 {
  2737 	/* not used */
  2763 	/* not used */
  2758 
  2784 
  2759 static void UpdateStationWaiting(Station *st, CargoID type, uint amount)
  2785 static void UpdateStationWaiting(Station *st, CargoID type, uint amount)
  2760 {
  2786 {
  2761 	st->goods[type].cargo.Append(new CargoPacket(st->index, amount));
  2787 	st->goods[type].cargo.Append(new CargoPacket(st->index, amount));
  2762 	SetBit(st->goods[type].acceptance_pickup, GoodsEntry::PICKUP);
  2788 	SetBit(st->goods[type].acceptance_pickup, GoodsEntry::PICKUP);
       
  2789 
       
  2790 	StationAnimationTrigger(st, st->xy, STAT_ANIM_NEW_CARGO, type);
  2763 
  2791 
  2764 	InvalidateWindow(WC_STATION_VIEW, st->index);
  2792 	InvalidateWindow(WC_STATION_VIEW, st->index);
  2765 	st->MarkTilesDirty(true);
  2793 	st->MarkTilesDirty(true);
  2766 }
  2794 }
  2767 
  2795 
  3133 
  3161 
  3134 			st->fsmportsspeclist[i].spec = GetCustomFSMportsSpecByGrf(st->fsmportsspeclist[i].grfid, st->fsmportsspeclist[i].localidx);
  3162 			st->fsmportsspeclist[i].spec = GetCustomFSMportsSpecByGrf(st->fsmportsspeclist[i].grfid, st->fsmportsspeclist[i].localidx);
  3135 		}
  3163 		}
  3136 
  3164 
  3137 		for (CargoID c = 0; c < NUM_CARGO; c++) st->goods[c].cargo.InvalidateCache();
  3165 		for (CargoID c = 0; c < NUM_CARGO; c++) st->goods[c].cargo.InvalidateCache();
       
  3166 
       
  3167 		StationUpdateAnimTriggers(st);
  3138 	}
  3168 	}
  3139 }
  3169 }
  3140 
  3170 
  3141 static CommandCost TerraformTile_Station(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
  3171 static CommandCost TerraformTile_Station(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
  3142 {
  3172 {