rail_cmd.c
changeset 59 fb1a20aefeae
parent 58 b9fdcc9b5c90
child 84 1e0721c29bad
equal deleted inserted replaced
58:b9fdcc9b5c90 59:fb1a20aefeae
   916 				_map3_hi[tile] = (_map3_hi[tile] & ~3) | ((_map3_hi[tile] + 1) & 3);
   916 				_map3_hi[tile] = (_map3_hi[tile] & ~3) | ((_map3_hi[tile] + 1) & 3);
   917 		} else {
   917 		} else {
   918 			/* If CmdBuildManySignals is called with copying signals, just copy the style of the first signal
   918 			/* If CmdBuildManySignals is called with copying signals, just copy the style of the first signal
   919 			* given as parameter by CmdBuildManySignals */
   919 			* given as parameter by CmdBuildManySignals */
   920 			switch (track) {
   920 			switch (track) {
   921 			case 2: case 4: _map3_lo[tile] = (p2&0xC0) | _map3_lo[tile]&~0xC0; break;
   921 			case 2: case 4: _map3_lo[tile] = (p2&0xC0) | (_map3_lo[tile]&~0xC0); break;
   922 			case 3: case 5: _map3_lo[tile] = (p2&0x30) | _map3_lo[tile]&~0x30; break;
   922 			case 3: case 5: _map3_lo[tile] = (p2&0x30) | (_map3_lo[tile]&~0x30); break;
   923 			default : _map3_lo[tile] = (p2&0xF0) | _map3_lo[tile]&0xF;
   923 			default : _map3_lo[tile] = (p2&0xF0) | (_map3_lo[tile]&0xF);
   924 			}
   924 			}
   925 			// convert between signal<->semaphores when dragging
   925 			// convert between signal<->semaphores when dragging
   926 			HASBIT(p1, 3) ? SETBIT(_map3_hi[tile], 2) : CLRBIT(_map3_hi[tile], 2);
   926 			HASBIT(p1, 3) ? SETBIT(_map3_hi[tile], 2) : CLRBIT(_map3_hi[tile], 2);
   927 		}
   927 		}
   928 		
   928 		
   934 }
   934 }
   935 
   935 
   936 /*	Build many signals by dragging: AutoSignals
   936 /*	Build many signals by dragging: AutoSignals
   937 		x,y= start tile
   937 		x,y= start tile
   938 		p1 = end tile
   938 		p1 = end tile
   939 		p2 = (byte 0)		- 0 = build, 1 = remove signals
   939 		p2 = (byte 0)			- 0 = build, 1 = remove signals
   940 		p2 = (byte 3)		- 0 = signals, 1 = semaphores
   940 		p2 = (byte 3)			- 0 = signals, 1 = semaphores
   941 		p2 = (byte 7-4)	- track-orientation
   941 		p2 = (byte 7-4)		- track-orientation
   942 		p2 = (byte 8-)	- track style
   942 		p2 = (byte 8-)		- track style
       
   943 		p2 = (byte 24-31)	- user defined signals_density
   943  */
   944  */
   944 int32 CmdBuildManySignals(int x, int y, uint32 flags, uint32 p1, uint32 p2)
   945 int32 CmdBuildManySignals(int x, int y, uint32 flags, uint32 p1, uint32 p2)
   945 {
   946 {
   946 	int ex, ey, railbit;
   947 	int ex, ey, railbit;
   947 	bool error = true;
   948 	bool error = true;
   949 	int32 ret, total_cost, signal_ctr;
   950 	int32 ret, total_cost, signal_ctr;
   950 	byte m5, semaphores = (HASBIT(p2, 3)) ? 8 : 0;
   951 	byte m5, semaphores = (HASBIT(p2, 3)) ? 8 : 0;
   951 	int mode = (p2 >> 4)&0xF;
   952 	int mode = (p2 >> 4)&0xF;
   952 	// for vertical/horizontal tracks, double the given signals density
   953 	// for vertical/horizontal tracks, double the given signals density
   953 	// since the original amount will be too dense (shorter tracks)
   954 	// since the original amount will be too dense (shorter tracks)
   954 	byte signal_density = (mode == 1 || mode == 2) ? _patches.drag_signals_density : _patches.drag_signals_density * 2;
   955 	byte signal_density = (mode == 1 || mode == 2) ? (p2 >> 24) : (p2 >> 24) * 2;
   955 	byte signals = p2 >> 8;
   956 	byte signals = (p2 >> 8)&0xFF;
   956 	mode = p2 & 0x1;  // build/remove signals
   957 	mode = p2 & 0x1;  // build/remove signals
   957 
   958 
   958 	/* unpack end tile */
   959 	/* unpack end tile */
   959 	ex = GET_TILE_X(p1)*16;
   960 	ex = GET_TILE_X(p1)*16;
   960 	ey = GET_TILE_Y(p1)*16;
   961 	ey = GET_TILE_Y(p1)*16;
   972 			switch (signals) {
   973 			switch (signals) {
   973 				case 0x20: case 8: /* east corner (N-S), south corner (W-E) */
   974 				case 0x20: case 8: /* east corner (N-S), south corner (W-E) */
   974 					if (_map3_lo[tile]&0x30) 
   975 					if (_map3_lo[tile]&0x30) 
   975 						signals = _map3_lo[tile]&0x30;
   976 						signals = _map3_lo[tile]&0x30;
   976 					else
   977 					else
   977 						signals = 0x30 | _map3_lo[tile]&0xC0;
   978 						signals = 0x30 | (_map3_lo[tile]&0xC0);
   978 					break;
   979 					break;
   979 				case 0x10: case 4: /* west corner (N-S), north corner (W-E) */
   980 				case 0x10: case 4: /* west corner (N-S), north corner (W-E) */
   980 					if (_map3_lo[tile]&0xC0) 
   981 					if (_map3_lo[tile]&0xC0) 
   981 						signals = _map3_lo[tile]&0xC0;
   982 						signals = _map3_lo[tile]&0xC0;
   982 					else
   983 					else
   983 						signals = 0xC0 | _map3_lo[tile]&0x30;
   984 						signals = 0xC0 | (_map3_lo[tile]&0x30);
   984 					break;
   985 					break;
   985 			}
   986 			}
   986 		}
   987 		}
   987 
   988 
   988 		semaphores = (_map3_hi[tile] & ~3) ? 8 : 0; // copy signal/semaphores style (independent of CTRL)
   989 		semaphores = (_map3_hi[tile] & ~3) ? 8 : 0; // copy signal/semaphores style (independent of CTRL)