src/water_cmd.cpp
branchgamebalance
changeset 9911 0b8b245a2391
parent 9910 0b2aebc8283e
child 9912 1ac8aac92385
equal deleted inserted replaced
9910:0b2aebc8283e 9911:0b8b245a2391
    23 #include "depot.h"
    23 #include "depot.h"
    24 #include "vehicle_gui.h"
    24 #include "vehicle_gui.h"
    25 #include "train.h"
    25 #include "train.h"
    26 #include "water_map.h"
    26 #include "water_map.h"
    27 #include "newgrf.h"
    27 #include "newgrf.h"
       
    28 #include "newgrf_canal.h"
    28 
    29 
    29 static const SpriteID _water_shore_sprites[] = {
    30 static const SpriteID _water_shore_sprites[] = {
    30 	0,
    31 	0,
    31 	SPR_SHORE_TILEH_1,
    32 	SPR_SHORE_TILEH_1,
    32 	SPR_SHORE_TILEH_2,
    33 	SPR_SHORE_TILEH_2,
   371 /** draw a canal styled water tile with dikes around */
   372 /** draw a canal styled water tile with dikes around */
   372 void DrawCanalWater(TileIndex tile)
   373 void DrawCanalWater(TileIndex tile)
   373 {
   374 {
   374 	uint wa;
   375 	uint wa;
   375 
   376 
       
   377 	/* Test for custom graphics, else use the default */
       
   378 	SpriteID dikes_base = GetCanalSprite(CF_DIKES, tile);
       
   379 	if (dikes_base == 0) dikes_base = SPR_CANALS_BASE + 57;
       
   380 
   376 	/* determine the edges around with water. */
   381 	/* determine the edges around with water. */
   377 	wa = IsWateredTile(TILE_ADDXY(tile, -1, 0)) << 0;
   382 	wa = IsWateredTile(TILE_ADDXY(tile, -1, 0)) << 0;
   378 	wa += IsWateredTile(TILE_ADDXY(tile, 0, 1)) << 1;
   383 	wa += IsWateredTile(TILE_ADDXY(tile, 0, 1)) << 1;
   379 	wa += IsWateredTile(TILE_ADDXY(tile, 1, 0)) << 2;
   384 	wa += IsWateredTile(TILE_ADDXY(tile, 1, 0)) << 2;
   380 	wa += IsWateredTile(TILE_ADDXY(tile, 0, -1)) << 3;
   385 	wa += IsWateredTile(TILE_ADDXY(tile, 0, -1)) << 3;
   381 
   386 
   382 	if (!(wa & 1)) DrawGroundSprite(SPR_CANALS_BASE + 57, PAL_NONE);
   387 	if (!(wa & 1)) DrawGroundSprite(dikes_base,     PAL_NONE);
   383 	if (!(wa & 2)) DrawGroundSprite(SPR_CANALS_BASE + 58, PAL_NONE);
   388 	if (!(wa & 2)) DrawGroundSprite(dikes_base + 1, PAL_NONE);
   384 	if (!(wa & 4)) DrawGroundSprite(SPR_CANALS_BASE + 59, PAL_NONE);
   389 	if (!(wa & 4)) DrawGroundSprite(dikes_base + 2, PAL_NONE);
   385 	if (!(wa & 8)) DrawGroundSprite(SPR_CANALS_BASE + 60, PAL_NONE);
   390 	if (!(wa & 8)) DrawGroundSprite(dikes_base + 3, PAL_NONE);
   386 
   391 
   387 	/* right corner */
   392 	/* right corner */
   388 	switch (wa & 0x03) {
   393 	switch (wa & 0x03) {
   389 		case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 4, PAL_NONE); break;
   394 		case 0: DrawGroundSprite(dikes_base + 4, PAL_NONE); break;
   390 		case 3: if (!IsWateredTile(TILE_ADDXY(tile, -1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 8, PAL_NONE); break;
   395 		case 3: if (!IsWateredTile(TILE_ADDXY(tile, -1, 1))) DrawGroundSprite(dikes_base + 8, PAL_NONE); break;
   391 	}
   396 	}
   392 
   397 
   393 	/* bottom corner */
   398 	/* bottom corner */
   394 	switch (wa & 0x06) {
   399 	switch (wa & 0x06) {
   395 		case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 5, PAL_NONE); break;
   400 		case 0: DrawGroundSprite(dikes_base + 5, PAL_NONE); break;
   396 		case 6: if (!IsWateredTile(TILE_ADDXY(tile, 1, 1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 9, PAL_NONE); break;
   401 		case 6: if (!IsWateredTile(TILE_ADDXY(tile, 1, 1))) DrawGroundSprite(dikes_base + 9, PAL_NONE); break;
   397 	}
   402 	}
   398 
   403 
   399 	/* left corner */
   404 	/* left corner */
   400 	switch (wa & 0x0C) {
   405 	switch (wa & 0x0C) {
   401 		case  0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 6, PAL_NONE); break;
   406 		case  0: DrawGroundSprite(dikes_base + 6, PAL_NONE); break;
   402 		case 12: if (!IsWateredTile(TILE_ADDXY(tile, 1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 10, PAL_NONE); break;
   407 		case 12: if (!IsWateredTile(TILE_ADDXY(tile, 1, -1))) DrawGroundSprite(dikes_base + 10, PAL_NONE); break;
   403 	}
   408 	}
   404 
   409 
   405 	/* upper corner */
   410 	/* upper corner */
   406 	switch (wa & 0x09) {
   411 	switch (wa & 0x09) {
   407 		case 0: DrawGroundSprite(SPR_CANALS_BASE + 57 + 7, PAL_NONE); break;
   412 		case 0: DrawGroundSprite(dikes_base + 7, PAL_NONE); break;
   408 		case 9: if (!IsWateredTile(TILE_ADDXY(tile, -1, -1))) DrawGroundSprite(SPR_CANALS_BASE + 57 + 11, PAL_NONE); break;
   413 		case 9: if (!IsWateredTile(TILE_ADDXY(tile, -1, -1))) DrawGroundSprite(dikes_base + 11, PAL_NONE); break;
   409 	}
   414 	}
   410 }
   415 }
   411 
   416 
   412 struct LocksDrawTileStruct {
   417 struct LocksDrawTileStruct {
   413 	int8 delta_x, delta_y, delta_z;
   418 	int8 delta_x, delta_y, delta_z;
   419 
   424 
   420 static void DrawWaterStuff(const TileInfo *ti, const WaterDrawTileStruct *wdts,
   425 static void DrawWaterStuff(const TileInfo *ti, const WaterDrawTileStruct *wdts,
   421 	SpriteID palette, uint base
   426 	SpriteID palette, uint base
   422 )
   427 )
   423 {
   428 {
   424 	DrawGroundSprite(wdts++->image, PAL_NONE);
   429 	SpriteID image;
       
   430 	SpriteID water_base = GetCanalSprite(CF_WATERSLOPE, ti->tile);
       
   431 	SpriteID locks_base = GetCanalSprite(CF_LOCKS, ti->tile);
       
   432 
       
   433 	/* If no custom graphics, use defaults */
       
   434 	if (water_base == 0) water_base = SPR_CANALS_BASE + 5;
       
   435 	if (locks_base == 0) {
       
   436 		locks_base = SPR_CANALS_BASE + 9;
       
   437 	} else {
       
   438 		/* If using custom graphics, ignore the variation on height */
       
   439 		base = 0;
       
   440 	}
       
   441 
       
   442 	image = wdts++->image;
       
   443 	if (image < 4) image += water_base;
       
   444 	DrawGroundSprite(image, PAL_NONE);
   425 
   445 
   426 	for (; wdts->delta_x != 0x80; wdts++) {
   446 	for (; wdts->delta_x != 0x80; wdts++) {
   427 		SpriteID image = wdts->image + base;
   447 		SpriteID image = wdts->image;
   428 		SpriteID pal;
   448 		SpriteID pal;
       
   449 
       
   450 		if (image < 24) image += locks_base;
       
   451 		image += base;
   429 
   452 
   430 		if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
   453 		if (HASBIT(_transparent_opt, TO_BUILDINGS)) {
   431 			SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
   454 			SETBIT(image, PALETTE_MODIFIER_TRANSPARENT);
   432 			pal = PALETTE_TO_TRANSPARENT;
   455 			pal = PALETTE_TO_TRANSPARENT;
   433 		} else {
   456 		} else {