// View plain text
//fieldspread.txt
//This terrain script, when active, will cause a particular type of
//field to spread like quickfire anywhere that it is in the town. 
//NOTE: This will slow the game down significantly, especially in 
//	larger towns
//
//Memory Cell 0: The type of field to spread. 
//Memory Cells 1,2: The coordinates of a SDF. When the flag is 1, the 
//			script will run, otherwise it will not.
//
beginterrainscript; 

variables;
	short x,y,f,tsize,tick;
body;

beginstate INIT_STATE;
	f = get_memory_cell(0);
	tsize=current_town_size();
	if(tsize==0)
		tsize=64;
	if(tsize==1)
		tsize=48;
	if(tsize==2)
		tsize=32;
	if(tsize>64)
		tsize=0;
	set_script_mode(3);
	tick = get_current_tick();
	break;

beginstate START_STATE;
	if((get_current_tick() != tick) && (get_flag(get_memory_cell(1),get_memory_cell(2)) == 1)){
		tick = get_current_tick();
		x=0;
		while(x0;
			while(yif(is_field_on_space(x,y,f)){
					put_field_on_space(x,y - 1,f);
					put_field_on_space(x - 1,y,f);
				}
				y=y+1;
			}
			x=x+1;
		}
		x=tsize;
		while(x>=0){
			y = tsize;
			while(y >= 0){
				if(is_field_on_space(x,y,f)){
					put_field_on_space(x,y + 1,f);
					put_field_on_space(x + 1,y,f);
				}
				y = y - 1;
			}
			x = x - 1;
		}
	}
break