(svn r756) Demystify and explain some piece of code regarding which house sprite to draw
authortron
Mon, 22 Nov 2004 10:09:37 +0000
changeset 480 d596ac391933
parent 479 061a8d8c2972
child 481 8db362a96e73
(svn r756) Demystify and explain some piece of code regarding which house sprite to draw
town_cmd.c
--- a/town_cmd.c	Sun Nov 21 23:20:11 2004 +0000
+++ b/town_cmd.c	Mon Nov 22 10:09:37 2004 +0000
@@ -52,12 +52,16 @@
 
 	/* Retrieve pointer to the draw town tile struct */
 	{
-		uint hash, t;
-		hash  = ti->x >> 4;
-		hash ^= hash>>2;
-		hash ^= (t=(ti->y >> 4));
-		hash -= t>>2;
-		dcts = &_town_draw_tile_data[((_map2[ti->tile]<<4)|(_map3_lo[ti->tile]>>6)|((hash&3)<<2))];
+		/* this "randomizes" on the (up to) 4 variants of a building */
+		byte gfx   = _map2[ti->tile];
+		byte stage = _map3_lo[ti->tile] >> 6;
+		uint variant;
+		variant  = ti->x >> 4;
+		variant ^= ti->x >> 6;
+		variant ^= ti->y >> 4;
+		variant -= ti->y >> 6;
+		variant &= 3;
+		dcts = &_town_draw_tile_data[gfx << 4 | variant << 2 | stage];
 	}
 
 	z = ti->z;