src/newgrf_house.cpp
branchnoai
changeset 10294 7798ae816af8
parent 9869 6404afe43575
child 10355 ee4b5f7a5bf2
equal deleted inserted replaced
10292:7856e972f8aa 10294:7798ae816af8
    19 #include "newgrf_sound.h"
    19 #include "newgrf_sound.h"
    20 #include "newgrf_commons.h"
    20 #include "newgrf_commons.h"
    21 #include "transparency.h"
    21 #include "transparency.h"
    22 #include "functions.h"
    22 #include "functions.h"
    23 #include "player_func.h"
    23 #include "player_func.h"
       
    24 #include "animated_tile_func.h"
       
    25 #include "date_func.h"
    24 
    26 
    25 #include "table/strings.h"
    27 #include "table/strings.h"
    26 #include "table/sprites.h"
    28 #include "table/sprites.h"
    27 #include "table/town_land.h"
    29 #include "table/town_land.h"
    28 
    30 
   426 					break;
   428 					break;
   427 			}
   429 			}
   428 
   430 
   429 			/* If the lower 7 bits of the upper byte of the callback
   431 			/* If the lower 7 bits of the upper byte of the callback
   430 			 * result are not empty, it is a sound effect. */
   432 			 * result are not empty, it is a sound effect. */
   431 			if (GB(callback_res, 8, 7) != 0) PlayHouseSound(GB(callback_res, 8, 7), tile);
   433 			if (GB(callback_res, 8, 7) != 0) PlayTileSound(hs->grffile, GB(callback_res, 8, 7), tile);
   432 		}
   434 		}
   433 	}
   435 	}
   434 
   436 
   435 	if (!frame_set_by_callback) {
   437 	if (!frame_set_by_callback) {
   436 		if (frame < num_frames) {
   438 		if (frame < num_frames) {
   446 
   448 
   447 	SetHouseAnimationFrame(tile, frame);
   449 	SetHouseAnimationFrame(tile, frame);
   448 	MarkTileDirtyByTile(tile);
   450 	MarkTileDirtyByTile(tile);
   449 }
   451 }
   450 
   452 
   451 void ChangeHouseAnimationFrame(TileIndex tile, uint16 callback_result)
   453 void ChangeHouseAnimationFrame(const GRFFile *file, TileIndex tile, uint16 callback_result)
   452 {
   454 {
   453 	switch (callback_result & 0xFF) {
   455 	switch (callback_result & 0xFF) {
   454 		case 0xFD: /* Do nothing. */         break;
   456 		case 0xFD: /* Do nothing. */         break;
   455 		case 0xFE: AddAnimatedTile(tile);    break;
   457 		case 0xFE: AddAnimatedTile(tile);    break;
   456 		case 0xFF: DeleteAnimatedTile(tile); break;
   458 		case 0xFF: DeleteAnimatedTile(tile); break;
   459 			AddAnimatedTile(tile);
   461 			AddAnimatedTile(tile);
   460 			break;
   462 			break;
   461 	}
   463 	}
   462 	/* If the lower 7 bits of the upper byte of the callback
   464 	/* If the lower 7 bits of the upper byte of the callback
   463 	 * result are not empty, it is a sound effect. */
   465 	 * result are not empty, it is a sound effect. */
   464 	if (GB(callback_result, 8, 7) != 0) PlayHouseSound(GB(callback_result, 8, 7), tile);
   466 	if (GB(callback_result, 8, 7) != 0) PlayTileSound(file, GB(callback_result, 8, 7), tile);
   465 }
   467 }
   466 
   468 
   467 bool CanDeleteHouse(TileIndex tile)
   469 bool CanDeleteHouse(TileIndex tile)
   468 {
   470 {
   469 	const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile));
   471 	const HouseSpec *hs = GetHouseSpecs(GetHouseType(tile));
   487 
   489 
   488 	if (HasBit(hs->callback_mask, CBM_HOUSE_ANIMATION_START_STOP)) {
   490 	if (HasBit(hs->callback_mask, CBM_HOUSE_ANIMATION_START_STOP)) {
   489 		uint32 param = (hs->extra_flags & SYNCHRONISED_CALLBACK_1B) ? (GB(Random(), 0, 16) | random_bits << 16) : Random();
   491 		uint32 param = (hs->extra_flags & SYNCHRONISED_CALLBACK_1B) ? (GB(Random(), 0, 16) | random_bits << 16) : Random();
   490 		uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_START_STOP, param, 0, GetHouseType(tile), GetTownByTile(tile), tile);
   492 		uint16 callback_res = GetHouseCallback(CBID_HOUSE_ANIMATION_START_STOP, param, 0, GetHouseType(tile), GetTownByTile(tile), tile);
   491 
   493 
   492 		if (callback_res != CALLBACK_FAILED) ChangeHouseAnimationFrame(tile, callback_res);
   494 		if (callback_res != CALLBACK_FAILED) ChangeHouseAnimationFrame(hs->grffile, tile, callback_res);
   493 	}
   495 	}
   494 }
   496 }
   495 
   497 
   496 bool NewHouseTileLoop(TileIndex tile)
   498 bool NewHouseTileLoop(TileIndex tile)
   497 {
   499 {
   523 	}
   525 	}
   524 
   526 
   525 	/* Check callback 21, which determines if a house should be destroyed. */
   527 	/* Check callback 21, which determines if a house should be destroyed. */
   526 	if (HasBit(hs->callback_mask, CBM_HOUSE_DESTRUCTION)) {
   528 	if (HasBit(hs->callback_mask, CBM_HOUSE_DESTRUCTION)) {
   527 		uint16 callback_res = GetHouseCallback(CBID_HOUSE_DESTRUCTION, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
   529 		uint16 callback_res = GetHouseCallback(CBID_HOUSE_DESTRUCTION, 0, 0, GetHouseType(tile), GetTownByTile(tile), tile);
   528 		if (callback_res != CALLBACK_FAILED && callback_res > 0) {
   530 		if (callback_res != CALLBACK_FAILED && GB(callback_res, 0, 8) > 0) {
   529 			ClearTownHouse(GetTownByTile(tile), tile);
   531 			ClearTownHouse(GetTownByTile(tile), tile);
   530 			return false;
   532 			return false;
   531 		}
   533 		}
   532 	}
   534 	}
   533 
   535