void mouse_editor()
{
	EditSpeed  = 2;
	int Counter;
	ENTITY* dummy;
	for(Counter = 1;Counter <= 66049; Counter++)
	{
		CONTACT* c = ent_getvertex(newterrain,NULL,Counter);
		
		c.v = NULL;
		vec_set(dt_marker[Counter].pos.x, c.x);
		vec_set(dt_marker[Counter].pos.z, c.z);
		vec_set(dt_marker[Counter].pos.y, c.y);
		dt_marker[Counter].vertex_id = Counter;
		dt_marker[Counter].dist = 100000;
		dt_marker[Counter].normalize = 0;
	}
		
	
	mouse_range = 10000000;
	var current_vertex = 1;
	
	var TR_EDIT_RANGE = 1;
	var TR_Range_WERT = 8;
	VECTOR* DT_TEMP = vector(0,0,0);
	
	while(1)
	{
		scala_object = (range / 1000) *100;
		my.scale_x = scala_object;
		my.scale_y = scala_object;
		my.scale_z = scala_object;
		
		var i;
		if(hit)
		{		
				DT_TEMP.x = mouse_pos.x;
				DT_TEMP.y = mouse_pos.y;				
				DT_TEMP.z = 10000000;
				
				vec_for_screen (DT_TEMP,camera);
				c_trace (camera.x,DT_TEMP,IGNORE_ME | IGNORE_PASSABLE | SCAN_TEXTURE|IGNORE_MODELS);
				
				switch(Edit_type)
				{
					case 1:
						ent_morph(edit_ball,"earth.mdl");
						my.x = hit.x;
						my.y = hit.y;
						my.z = hit.z;
						reset(my,INVISIBLE);
					break;
					case 2:
						ent_morph(edit_ball,"earth.mdl");
						my.x = hit.x;
						my.y = hit.y;
						my.z = hit.z;
						set(my,INVISIBLE);
					break;
					case 3:
						ent_morph(edit_ball,"ped_ja.tga");
						if(mouse_ent)
						{
							my.x = mouse_ent.x;
							my.y = mouse_ent.y;
							my.z = mouse_ent.z;
						}
					
						my.scale_x = 1;
						my.scale_y = 1;
						my.scale_z = 1;
						my.pan = 0.001;
						my.tilt = -90;
						my.roll =0.001;
						reset(my,INVISIBLE);
					break;
					default:
						set(my,INVISIBLE);
					break;
					
				}
				

	
			for(i = 1; i<= 66049; i++)
			{
				dt_marker[i].dist = vec_dist(vector(dt_marker[i].pos.x,dt_marker[i].pos.y,0), vector(my.x,my.y,0));
				if(dt_marker[i].dist < range)
				{
					dt_marker[i].normalize = (range - dt_marker[i].dist) / range;
				}
			}
			
			if(mouse_left && !mouse_panel && temporaere == !mouse_ent)
			{
				
				switch(Edit_type)
				{
					case 1:
					
						
						for(i = 1; i< 66049; i++)
						{
							if(dt_marker[i].dist < range)
							{
								
								CONTACT* t = ent_getvertex(newterrain,NULL,dt_marker[i].vertex_id);
									t.v = NULL;
							
										switch(Editor_Mode)
										{
											case 1:
												if(key_shiftl)
												{
													if(t.z > 0)
													{
														t.z -= sinv(dt_marker[i].normalize * 90) * EditSpeed * time_step;
													}
													else
													{
														t.z = 0;
													}
												}
												else
												{
													t.z += sinv(dt_marker[i].normalize * 90) * EditSpeed * time_step;
												}
											break;
											case 2:
											
													
											break;
											case 3:
													t.z = terrain_high;
											break;
											default:
											break;
											
										}
									ent_setvertex(newterrain,t,i);	
								}
						}	
					break;
					case 2:
							if(aas_window)
							{
								LBG_destroy_window (aas_window);
							}
//							if(mouse_ent.skill99 == 5501 || mouse_ent.skill99 == 5502 || mouse_ent.skill99 == 5503 )
//							{
//								while(mouse_left)
//								{
//									if(mouse_ent.skill99 == 5501)
//									{
//										while(mouse_left)
//										{
//											move_obj_z +=mouse_force.y * time_step;
//											wait(1);
//										}
										
//									}
//									if(mouse_ent.skill99 == 5502)
//									{
//										while(mouse_left)
//										{
//											move_obj_y -=mouse_force.x * time_step;
//												wait(1);
//										}
//									}
//									if(mouse_ent.skill99 == 5503)
//									{
//										while(mouse_left)
//										{
//											move_obj_x +=mouse_force.x * time_step;
//												wait(1);
//										}
//									}
//									wait(1);
//								}
//								move_obj_x = 0;
//								move_obj_y = 0;
//								move_obj_z = 0;
								
//							}
//							else
//							{
								if(!listbox1.marked_item)
								{
									LBG_listbox_set_marked(listbox1,mouse_ent.skill21);
									//LBG_update_listbox (listbox1);
									OBJ_Selected();
									//while(mouse_left){wait(1);}
								}
								
								if(mouse_ent.skill21 != listbox1.marked_item.skill_x)
								{
									
									LBG_listbox_set_marked(listbox1,mouse_ent.skill21);
									//LBG_update_listbox (listbox1);
									
									OBJ_Selected();
									
								}
								
								while(mouse_left){wait(1);}
//							}
					
					
					break;
					case 3:
					
						//ped_map_editor // ein permanentes fenster für jede ped parzelle zum eintragen der NPC shop id
						
					break;
					
				}
			}
			
			
			
			
		}
		
		
	wait(1);	
	}
}

void start_edit_ent()
{
	edit_ball = ent_create("earth.mdl",nullvector,mouse_editor);
}



void mouse_movement()
{
	var i = ent_status(newterrain, 0);
	set (my, INVISIBLE);
	mouse_mode = 4;
	
	 //start_edit_ent();
	
	while(1)
	{
		camera.x = my.x;
		camera.y = my.y;
		camera.z = my.z;
		
		if(mouse_right)
		{
			camera.tilt += mouse_force.y * time_step * 7;
			camera.pan -= mouse_force.x * time_step * 7 ;	
		}
		
		my.pan = camera.pan;
		my.tilt = camera.tilt; 
		if(!mouse_panel)
		{		
			c_move(my,vector(mickey.z*15*time_step,0,0),nullvector,IGNORE_WORLD|IGNORE_MODELS|IGNORE_MAPS);
		}
		wait(1);
	}
}

