src/newgrf_industrytiles.cpp
branchnoai
changeset 10294 7798ae816af8
parent 10249 58810805030e
child 10355 ee4b5f7a5bf2
equal deleted inserted replaced
10292:7856e972f8aa 10294:7798ae816af8
    13 #include "newgrf_commons.h"
    13 #include "newgrf_commons.h"
    14 #include "newgrf_spritegroup.h"
    14 #include "newgrf_spritegroup.h"
    15 #include "newgrf_callbacks.h"
    15 #include "newgrf_callbacks.h"
    16 #include "newgrf_industries.h"
    16 #include "newgrf_industries.h"
    17 #include "newgrf_industrytiles.h"
    17 #include "newgrf_industrytiles.h"
       
    18 #include "newgrf_sound.h"
    18 #include "newgrf_text.h"
    19 #include "newgrf_text.h"
    19 #include "industry_map.h"
    20 #include "industry_map.h"
    20 #include "clear_map.h"
    21 #include "clear_map.h"
    21 #include "sprite.h"
    22 #include "sprite.h"
    22 #include "transparency.h"
    23 #include "transparency.h"
    23 #include "functions.h"
    24 #include "functions.h"
    24 #include "town.h"
    25 #include "town.h"
    25 #include "command_func.h"
    26 #include "command_func.h"
       
    27 #include "animated_tile_func.h"
    26 
    28 
    27 #include "table/sprites.h"
    29 #include "table/sprites.h"
    28 #include "table/strings.h"
    30 #include "table/strings.h"
    29 
    31 
    30 static uint32 GetGRFParameter(IndustryGfx indtile_id, byte parameter)
    32 static uint32 GetGRFParameter(IndustryGfx indtile_id, byte parameter)
   334 					break;
   336 					break;
   335 				default:
   337 				default:
   336 					frame = callback_res & 0xFF;
   338 					frame = callback_res & 0xFF;
   337 					break;
   339 					break;
   338 			}
   340 			}
       
   341 
       
   342 			/* If the lower 7 bits of the upper byte of the callback
       
   343 			 * result are not empty, it is a sound effect. */
       
   344 			if (GB(callback_res, 8, 7) != 0) PlayTileSound(itspec->grf_prop.grffile, GB(callback_res, 8, 7), tile);
   339 		}
   345 		}
   340 	}
   346 	}
   341 
   347 
   342 	if (!frame_set_by_callback) {
   348 	if (!frame_set_by_callback) {
   343 		if (frame < num_frames) {
   349 		if (frame < num_frames) {
   353 
   359 
   354 	SetIndustryAnimationState(tile, frame);
   360 	SetIndustryAnimationState(tile, frame);
   355 	MarkTileDirtyByTile(tile);
   361 	MarkTileDirtyByTile(tile);
   356 }
   362 }
   357 
   363 
   358 static void ChangeIndustryTileAnimationFrame(TileIndex tile, IndustryAnimationTrigger iat, uint32 random_bits, IndustryGfx gfx, Industry *ind)
   364 static void ChangeIndustryTileAnimationFrame(const IndustryTileSpec *itspec, TileIndex tile, IndustryAnimationTrigger iat, uint32 random_bits, IndustryGfx gfx, Industry *ind)
   359 {
   365 {
   360 	uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_ANIM_START_STOP, random_bits, iat, gfx, ind, tile);
   366 	uint16 callback_res = GetIndustryTileCallback(CBID_INDTILE_ANIM_START_STOP, random_bits, iat, gfx, ind, tile);
   361 	if (callback_res == CALLBACK_FAILED) return;
   367 	if (callback_res == CALLBACK_FAILED) return;
   362 
   368 
   363 	switch (callback_res & 0xFF) {
   369 	switch (callback_res & 0xFF) {
   367 		default:
   373 		default:
   368 			SetIndustryAnimationState(tile, callback_res & 0xFF);
   374 			SetIndustryAnimationState(tile, callback_res & 0xFF);
   369 			AddAnimatedTile(tile);
   375 			AddAnimatedTile(tile);
   370 			break;
   376 			break;
   371 	}
   377 	}
       
   378 
       
   379 	/* If the lower 7 bits of the upper byte of the callback
       
   380 	 * result are not empty, it is a sound effect. */
       
   381 	if (GB(callback_res, 8, 7) != 0) PlayTileSound(itspec->grf_prop.grffile, GB(callback_res, 8, 7), tile);
   372 }
   382 }
   373 
   383 
   374 bool StartStopIndustryTileAnimation(TileIndex tile, IndustryAnimationTrigger iat, uint32 random)
   384 bool StartStopIndustryTileAnimation(TileIndex tile, IndustryAnimationTrigger iat, uint32 random)
   375 {
   385 {
   376 	IndustryGfx gfx = GetIndustryGfx(tile);
   386 	IndustryGfx gfx = GetIndustryGfx(tile);
   377 	const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx);
   387 	const IndustryTileSpec *itspec = GetIndustryTileSpec(gfx);
   378 
   388 
   379 	if (!HasBit(itspec->animation_triggers, iat)) return false;
   389 	if (!HasBit(itspec->animation_triggers, iat)) return false;
   380 
   390 
   381 	Industry *ind = GetIndustryByTile(tile);
   391 	Industry *ind = GetIndustryByTile(tile);
   382 	ChangeIndustryTileAnimationFrame(tile, iat, random, gfx, ind);
   392 	ChangeIndustryTileAnimationFrame(itspec, tile, iat, random, gfx, ind);
   383 	return true;
   393 	return true;
   384 }
   394 }
   385 
   395 
   386 bool StartStopIndustryTileAnimation(const Industry *ind, IndustryAnimationTrigger iat)
   396 bool StartStopIndustryTileAnimation(const Industry *ind, IndustryAnimationTrigger iat)
   387 {
   397 {