landscape.c
changeset 183 ec2b02ea4c88
parent 159 139cf78bfb28
child 473 77f0ef57e7cf
equal deleted inserted replaced
182:1641047f1d9f 183:ec2b02ea4c88
    12 byte _map3_hi[TILES_X * TILES_Y];
    12 byte _map3_hi[TILES_X * TILES_Y];
    13 byte _map_owner[TILES_X * TILES_Y];
    13 byte _map_owner[TILES_X * TILES_Y];
    14 byte _map2[TILES_X * TILES_Y];
    14 byte _map2[TILES_X * TILES_Y];
    15 byte _map_extra_bits[TILES_X * TILES_Y/4];
    15 byte _map_extra_bits[TILES_X * TILES_Y/4];
    16 
    16 
    17 extern const TileTypeProcs 
    17 extern const TileTypeProcs
    18 	_tile_type_clear_procs,
    18 	_tile_type_clear_procs,
    19 	_tile_type_rail_procs,
    19 	_tile_type_rail_procs,
    20 	_tile_type_road_procs,
    20 	_tile_type_road_procs,
    21 	_tile_type_town_procs,
    21 	_tile_type_town_procs,
    22 	_tile_type_trees_procs,
    22 	_tile_type_trees_procs,
    65 	if (min >= b) min = b;
    65 	if (min >= b) min = b;
    66 	c = _map_type_and_height[tile+TILE_XY(0,1)] & 0xF;
    66 	c = _map_type_and_height[tile+TILE_XY(0,1)] & 0xF;
    67 	if (min >= c) min = c;
    67 	if (min >= c) min = c;
    68 	d = _map_type_and_height[tile+TILE_XY(1,1)] & 0xF;
    68 	d = _map_type_and_height[tile+TILE_XY(1,1)] & 0xF;
    69 	if (min >= d) min = d;
    69 	if (min >= d) min = d;
    70 	
    70 
    71 	r = 0;
    71 	r = 0;
    72 	if ((a-=min)!=0) { r += (--a << 4) + 8; }
    72 	if ((a-=min)!=0) { r += (--a << 4) + 8; }
    73 	if ((c-=min)!=0) { r += (--c << 4) + 4; }
    73 	if ((c-=min)!=0) { r += (--c << 4) + 4; }
    74 	if ((d-=min)!=0) { r += (--d << 4) + 2; }
    74 	if ((d-=min)!=0) { r += (--d << 4) + 2; }
    75 	if ((b-=min)!=0) { r += (--b << 4) + 1; }
    75 	if ((b-=min)!=0) { r += (--b << 4) + 1; }
   134 	switch(corners) {
   134 	switch(corners) {
   135 	case 1:
   135 	case 1:
   136 		if (x - y >= 0)
   136 		if (x - y >= 0)
   137 			z = (x - y) >> 1;
   137 			z = (x - y) >> 1;
   138 		break;
   138 		break;
   139 	
   139 
   140 	case 2:
   140 	case 2:
   141 		y^=0xF;
   141 		y^=0xF;
   142 		if ( (x - y) >= 0)
   142 		if ( (x - y) >= 0)
   143 			z = (x - y) >> 1;
   143 			z = (x - y) >> 1;
   144 		break;
   144 		break;
   211 		break;
   211 		break;
   212 
   212 
   213 	case 29:
   213 	case 29:
   214 		z = 1 + (((x^0xF)+(y^0xF))>>1);
   214 		z = 1 + (((x^0xF)+(y^0xF))>>1);
   215 		break;
   215 		break;
   216 		
   216 
   217 	case 30:
   217 	case 30:
   218 		z = 1 + (((x^0xF)+(y^0xF))>>1);
   218 		z = 1 + (((x^0xF)+(y^0xF))>>1);
   219 		break;
   219 		break;
   220 	}
   220 	}
   221 
   221 
   268 	if(hasFoundation( &ti2, true )) sprite_base += 22;		// foundation in NW direction
   268 	if(hasFoundation( &ti2, true )) sprite_base += 22;		// foundation in NW direction
   269 	FindLandscapeHeight(&ti2, ti->x-1, ti->y);
   269 	FindLandscapeHeight(&ti2, ti->x-1, ti->y);
   270 	if(hasFoundation( &ti2, false )) sprite_base += 22*2;	// foundation in NE direction
   270 	if(hasFoundation( &ti2, false )) sprite_base += 22*2;	// foundation in NE direction
   271 
   271 
   272 	if (f < 15) {
   272 	if (f < 15) {
   273 		// leveled foundation	
   273 		// leveled foundation
   274 		if( sprite_base < SPR_SLOPES_BASE ) sprite_base = 990; // use original slope sprites
   274 		if( sprite_base < SPR_SLOPES_BASE ) sprite_base = 990; // use original slope sprites
   275 
   275 
   276 		AddSortableSpriteToDraw(f-1 + sprite_base, ti->x, ti->y, 16, 16, 7, ti->z);
   276 		AddSortableSpriteToDraw(f-1 + sprite_base, ti->x, ti->y, 16, 16, 7, ti->z);
   277 		ti->z += 8;
   277 		ti->z += 8;
   278 		ti->tileh = 0;
   278 		ti->tileh = 0;
   279 		OffsetGroundSprite(31, 1);
   279 		OffsetGroundSprite(31, 1);
   280 	} else {
   280 	} else {
   281 		// inclined foundation
   281 		// inclined foundation
   282 		sprite_base += 14;
   282 		sprite_base += 14;
   283 		
   283 
   284 		AddSortableSpriteToDraw(
   284 		AddSortableSpriteToDraw(
   285 			HASBIT( (1<<1) | (1<<2) | (1<<4) | (1<<8), ti->tileh) ? sprite_base + (f - 15) : 	ti->tileh + 0x3DE - 1,
   285 			HASBIT( (1<<1) | (1<<2) | (1<<4) | (1<<8), ti->tileh) ? sprite_base + (f - 15) : 	ti->tileh + 0x3DE - 1,
   286 			ti->x, ti->y, 1, 1, 1, ti->z
   286 			ti->x, ti->y, 1, 1, 1, ti->z
   287 		);
   287 		);
   288 		
   288 
   289 		ti->tileh = _inclined_tileh[f - 15];
   289 		ti->tileh = _inclined_tileh[f - 15];
   290 		OffsetGroundSprite(31, 9);
   290 		OffsetGroundSprite(31, 9);
   291 	}
   291 	}
   292 }
   292 }
   293 
   293 
   378 			if (flags & DC_EXEC) {
   378 			if (flags & DC_EXEC) {
   379 				if ( ret>0 && (money -= ret) < 0) {
   379 				if ( ret>0 && (money -= ret) < 0) {
   380 					_additional_cash_required = ret;
   380 					_additional_cash_required = ret;
   381 					return cost - ret;
   381 					return cost - ret;
   382 				}
   382 				}
   383 				DoCommandByTile(TILE_FROM_XY(x,y), 0, 0, flags, CMD_LANDSCAPE_CLEAR);	
   383 				DoCommandByTile(TILE_FROM_XY(x,y), 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   384 
   384 
   385 				// draw explosion animation...
   385 				// draw explosion animation...
   386 				if ((x==sx || x==ex) && (y==sy || y==ey)) {
   386 				if ((x==sx || x==ex) && (y==sy || y==ey)) {
   387 					// big explosion in each corner, or small explosion for single tiles
   387 					// big explosion in each corner, or small explosion for single tiles
   388 					CreateEffectVehicleAbove(x + 8,y + 8, 2, sy==ey && sx==ex ? EV_DEMOLISH : EV_CRASHED_SMOKE);
   388 					CreateEffectVehicleAbove(x + 8,y + 8, 2, sy==ey && sx==ex ? EV_DEMOLISH : EV_CRASHED_SMOKE);
   545 
   545 
   546 	direction = (byte)(r >> 22) & 3;
   546 	direction = (byte)(r >> 22) & 3;
   547 	w = p[2];
   547 	w = p[2];
   548 	h = p[1];
   548 	h = p[1];
   549 	if (direction & 1) { w = p[1]; h = p[2]; }
   549 	if (direction & 1) { w = p[1]; h = p[2]; }
   550 	p += 8;	
   550 	p += 8;
   551 
   551 
   552 	if (flag & 4) {
   552 	if (flag & 4) {
   553 		if (!(flag & 2)) {
   553 		if (!(flag & 2)) {
   554 			if (!(flag & 1)) {
   554 			if (!(flag & 1)) {
   555 				if (x + y > 190)
   555 				if (x + y > 190)
   642 		do {
   642 		do {
   643 			if ((i = *data++) == MDORD_LAST) {
   643 			if ((i = *data++) == MDORD_LAST) {
   644 				SetMapExtraBits(tile, 1);
   644 				SetMapExtraBits(tile, 1);
   645 				break;
   645 				break;
   646 			}
   646 			}
   647 			mt = _map_type_and_height[tile + i];
   647 			mt = _map_type_and_height[TILE_MASK(tile + i)];
   648 		} while ((mt & 0xC) == 0 && (mt >> 4) != MP_WATER);
   648 		} while ((mt & 0xC) == 0 && (mt >> 4) != MP_WATER);
   649 	} while (++tile != TILES_X*TILES_Y);
   649 	} while (++tile != TILES_X*TILES_Y);
   650 	
   650 
   651 	for(i=0; i!=256; i++)
   651 	for(i=0; i!=256; i++)
   652 		RunTileLoop();
   652 		RunTileLoop();
   653 
   653 
   654 	tile = 0;
   654 	tile = 0;
   655 	do {
   655 	do {
   657 		do {
   657 		do {
   658 			if ((i = *data++) == MDORD_LAST) {
   658 			if ((i = *data++) == MDORD_LAST) {
   659 				SetMapExtraBits(tile, 2);
   659 				SetMapExtraBits(tile, 2);
   660 				break;
   660 				break;
   661 			}
   661 			}
   662 		} while ( !IS_TILETYPE(tile+i, MP_CLEAR) || (_map5[tile + i]&0x1C) != 0x14);
   662 		} while ( !IS_TILETYPE(TILE_MASK(tile+i), MP_CLEAR) || (_map5[TILE_MASK(tile + i)]&0x1C) != 0x14);
   663 	} while (++tile != TILES_X*TILES_Y);
   663 	} while (++tile != TILES_X*TILES_Y);
   664 }
   664 }
   665 
   665 
   666 void GenerateLandscape()
   666 void GenerateLandscape()
   667 {
   667 {
   668 	int i,flag;
   668 	int i,flag;
   669 	uint32 r;
   669 	uint32 r;
   670 	
   670 
   671 	if (_opt.landscape == LT_HILLY) {
   671 	if (_opt.landscape == LT_HILLY) {
   672 		i = ((Random() & 0x7F) + 950) * LANDSCAPE_SIZE_FACTOR;
   672 		i = ((Random() & 0x7F) + 950) * LANDSCAPE_SIZE_FACTOR;
   673 		do {
   673 		do {
   674 			GenerateTerrain(2, 0);
   674 			GenerateTerrain(2, 0);
   675 		} while (--i);
   675 		} while (--i);
   676 		
   676 
   677 		r = Random();
   677 		r = Random();
   678 		flag = (r & 3) | 4;
   678 		flag = (r & 3) | 4;
   679 		i = (((r >> 16) & 0x7F) + 450) * LANDSCAPE_SIZE_FACTOR;
   679 		i = (((r >> 16) & 0x7F) + 450) * LANDSCAPE_SIZE_FACTOR;
   680 		do {
   680 		do {
   681 			GenerateTerrain(4, flag);
   681 			GenerateTerrain(4, flag);
   683 	} else if (_opt.landscape == LT_DESERT) {
   683 	} else if (_opt.landscape == LT_DESERT) {
   684 		i = ((Random()&0x7F) + 170) * LANDSCAPE_SIZE_FACTOR;
   684 		i = ((Random()&0x7F) + 170) * LANDSCAPE_SIZE_FACTOR;
   685 		do {
   685 		do {
   686 			GenerateTerrain(0, 0);
   686 			GenerateTerrain(0, 0);
   687 		} while (--i);
   687 		} while (--i);
   688 		
   688 
   689 		r = Random();
   689 		r = Random();
   690 		flag = (r & 3) | 4;
   690 		flag = (r & 3) | 4;
   691 		i = (((r >> 16) & 0xFF) + 1700) * LANDSCAPE_SIZE_FACTOR;
   691 		i = (((r >> 16) & 0xFF) + 1700) * LANDSCAPE_SIZE_FACTOR;
   692 		do {
   692 		do {
   693 			GenerateTerrain(0, flag);
   693 			GenerateTerrain(0, flag);
   695 
   695 
   696 		flag ^= 2;
   696 		flag ^= 2;
   697 
   697 
   698 		i = ((Random() & 0x7F) + 410) * LANDSCAPE_SIZE_FACTOR;
   698 		i = ((Random() & 0x7F) + 410) * LANDSCAPE_SIZE_FACTOR;
   699 		do {
   699 		do {
   700 			GenerateTerrain(3, flag);	
   700 			GenerateTerrain(3, flag);
   701 		} while (--i);
   701 		} while (--i);
   702 	} else {
   702 	} else {
   703 		i = ((Random() & 0x7F) + (3 - _opt.diff.quantity_sea_lakes)*256 + 100) * LANDSCAPE_SIZE_FACTOR;
   703 		i = ((Random() & 0x7F) + (3 - _opt.diff.quantity_sea_lakes)*256 + 100) * LANDSCAPE_SIZE_FACTOR;
   704 		do {
   704 		do {
   705 			GenerateTerrain(_opt.diff.terrain_type, 0);
   705 			GenerateTerrain(_opt.diff.terrain_type, 0);
   751 uint TileAddWrap(TileIndex tile, int addx, int addy)
   751 uint TileAddWrap(TileIndex tile, int addx, int addy)
   752 {
   752 {
   753 	int x, y;
   753 	int x, y;
   754 	x = GET_TILE_X(tile) + addx;
   754 	x = GET_TILE_X(tile) + addx;
   755 	y = GET_TILE_Y(tile) + addy;
   755 	y = GET_TILE_Y(tile) + addy;
   756 	
   756 
   757 	// Are we about to wrap?
   757 	// Are we about to wrap?
   758 	if (x > 0 && x < TILE_X_MAX && y > 0 && y < TILE_Y_MAX)
   758 	if (x > 0 && x < TILE_X_MAX && y > 0 && y < TILE_Y_MAX)
   759 		return tile + TILE_XY(addx, addy);
   759 		return tile + TILE_XY(addx, addy);
   760 
   760 
   761 	return TILE_WRAPPED;
   761 	return TILE_WRAPPED;