extend(Field, createjs.Container);

function Field(_parent, _viewmod, _dim)
{	
	this.initialize();
	var th = this
//--------------------------------//

	
	var con = new createjs.Container()
	createTile()

	// var exShip = new Ship(this, _viewmod, 3)
	// exShip.setToCell(0, 0)

	var octopus = new createjs.Sprite(jsons["JSON1"])
	octopus.gotoAndStop("bg_octopus")
	setCoor(octopus, 28, 753)

	var symbol = new createjs.Sprite(jsons["JSON1"])
	symbol.gotoAndStop("bg_symbol")
	if(_dim == 16)
		setCoor(symbol, 833, -152)
	if(_dim == 12)
		setCoor(symbol, 625, -49)
	if(_dim == 10)
		setCoor(symbol, 507, -19)

	// dragAndDrop(octopus)
	// dragAndDrop(symbol)

	// this.addChild(octopus)
	// this.addChild(symbol)
	this.addChild(con)

	var change_cont = new createjs.Container()
	this.addChild(change_cont)
	// this.addChild(exShip)

	_viewmod.registerObservers(this)

	var third_step = true
	var second_step = true
	var first_step = true
// Обновление поля
	this.updateField = function(step, trans){
		var p = _viewmod.getData()
		if(p.scale_field != this.scaleX){
			this.scaleX = this.scaleY = p.scale_field
			this.x = WIDTHGAME/2 - con.getBounds().width * this.scaleX/2
			this.y = HEIGHTGAME/2 - this.getBounds().height * this.scaleX/2
		}
		// this.x = this.x / p.scale_field
		// this.y = this.y / p.scale_field
		// console.log(p)
		var layers = new Array()
		var all_objects = new Array()
		change_cont.removeAllChildren()
		var used_chest = new Array()
		used_chest = used_chest.concat(p.game_data.used_move_user)
		used_chest = used_chest.concat(p.game_data.used_move_bot)
		var __chests = new Array()
		for(var a=0; a<used_chest.length; a++){
			if(used_chest[a].getName() == "chest"){
				// __chests.push(used_chest[a])
			}
		}
		if(step == 1){
			// Обновление всех пользовательских кораблей
			all_objects = all_objects.concat(p.game_data.ships_user)
			all_objects = all_objects.concat(p.game_data.mines_user)
			all_objects = all_objects.concat(p.game_data.chest_user)
			// all_objects = all_objects.concat(p.game_data.chests)
			all_objects = all_objects.concat(p.game_data.rocks)
			// all_objects = all_objects.concat(p.game_data.ships_bot)
			// all_objects = all_objects.concat(p.game_data.mines_bot)
			// all_objects = all_objects.concat(p.game_data.chest_bot)
			setLayers(all_objects)
			for(var a = 0; a<all_objects.length; a++){
				createVisualObjects(all_objects[a])
				all_objects[a].setMouseEnabled(true)
			}
			if(first_step){
				first_step = false
				tw_tweenTo(this,  {x: WIDTHGAME/2 - con.getBounds().width * this.scaleX/2, y: .1, d:.5})
			}
		}
		if(step == 2){
			all_objects = all_objects.concat(p.game_data.used_move_user)
			all_objects = all_objects.concat(p.game_data.rocks)
			all_objects = all_objects.concat(p.game_data.periskop_view_user)
			all_objects = all_objects.concat(p.game_data.used_objects)
			all_objects = all_objects.concat(__chests)
			if(p.game_data.selected_objects)
				all_objects = all_objects.concat(p.game_data.selected_objects)
			setLayers(all_objects)
			if(p.game_data.periscopes)
				all_objects = p.game_data.periscopes.concat(all_objects)
			for(var a = 0; a<all_objects.length; a++){
				createVisualObjects(all_objects[a])
				all_objects[a].setMouseEnabled(true)
			}
			if(p.game_data.periskop2){
				playAnimPeriscope(p.game_data.periskop_active)
			}
			if(second_step){
				// console.log("asdw", p.center_target)
				second_step = false
				// if(_dim == 16)
					// __tweener.tweenTo(cur_ship, null, th)
					tw_tweenTo(this,  {x: WIDTHGAME/2 - con.getBounds().width * this.scaleX/2, y: .1, d:.5})//HEIGHTGAME/2 - con.getBounds().height * this.scaleX/2
				// if(_dim == 12)
				// 	tw_tweenTo(this, {x: -172, y: -69, d:.5})
				// if(_dim == 10)
				// 	tw_tweenTo(this, {x: -74, y: -29, d:.5})
			}
			third_step = true
		}
		if(step == 3){
			all_objects = all_objects.concat(p.game_data.rocks)
			all_objects = all_objects.concat(__chests)
			if(p.game_data.current_stage == "user"){
				all_objects = all_objects.concat(p.game_data.used_move_user)
				// all_objects = all_objects.concat(p.game_data.ships_bot)
				// all_objects = all_objects.concat(p.game_data.mines_bot)
			}else{
				all_objects = all_objects.concat(p.game_data.used_move_bot)
				all_objects = all_objects.concat(p.game_data.ships_user)
				all_objects = all_objects.concat(p.game_data.mines_user)
				all_objects = all_objects.concat(p.game_data.chest_user)
			}
			setLayers(all_objects)
			for(var a = 0; a<all_objects.length; a++){
				createVisualObjects(all_objects[a])
				all_objects[a].setMouseEnabled(false)

			}
			if(p.game_data.flying_money)
				flyMoney()
			var ships = createsShips()
			// console.log(p.game_data.current_stage)
			if(p.game_data.current_stage == "user"){
				ships.user.alpha = 1
				ships.bot.alpha = .5
			}else if(p.game_data.current_stage == "bot"){
				ships.bot.alpha = 1
				ships.user.alpha = .5
			}
			if(p.modal){
				t_setPause(timer)
				return
			}else
				t_delInPause(timer)
			if(!third_step)
				return
			var objs, curT, cur_ship
			if(p.game_data.current_stage == "user"){
				objs = p.game_data.ships_bot
				objs = objs.concat(p.game_data.mines_bot)
				objs = objs.concat(p.game_data.chest_bot)
				// objs = objs.concat(p.game_data.chests)
				curT = p.game_data.user_targets
				cur_ship = ships.user
			}else if(p.game_data.current_stage == "bot"){				
				objs = p.game_data.ships_user
				objs = objs.concat(p.game_data.mines_user)
				objs = objs.concat(p.game_data.chest_user)
				// objs = objs.concat(p.game_data.chests)
				curT = p.game_data.bot_targets
				// console.log(curT)
				cur_ship = ships.bot
			}
			if(cur_ship)
				_parent.removeEvents()
				__tweener.tweenTo(cur_ship, null, th, function(){
					_parent.addEvents()
					startFight(p.game_data.current_stage, curT, objs)
				})
			third_step = false
			second_step = true
			if(!p.game_data.current_stage)
				_viewmod.nextStep()
		}
	}

// Удаления перетаскивания поля (обработчика событий)
	this.removeDragAndDrop = function(){
		_parent.removeEvents()
	}

// Добавление перетаскивания поля (обработчика событий)
	this.addDragAndDrop = function(){
		_parent.addEvents()
	}

// PRIVATE//
	// 
	function createTile(){
		// setCoor(bg_tiles, 0, 332)
		var numCell = _dim
		for(var a = 0; a< numCell/2; a++)
			for(var b = 0; b<numCell/2; b++){
				var bg_tiles = new createjs.Sprite(jsons["JSON1"])
				bg_tiles.gotoAndStop('bg_tiles2x2')
				bg_tiles.x = 0/__koefDisplay + (80/__koefDisplay * a) + (80/__koefDisplay * b)
				bg_tiles.y = 441/__koefDisplay + (-60/__koefDisplay * b) + (60/__koefDisplay * a)
				con.addChild(bg_tiles)
				// dragAndDrop(bg_tiles)
			}

		// var bg_tiles1 = new createjs.Sprite(jsons["JSON1"])
		// bg_tiles1.gotoAndStop('bg_tiles')
		// th.addChild(bg_tiles1)
	}

	// Настройка слойности объектов
	function setLayers(obj){
		var ret = obj
		for(c=0; c<ret.length; c++)
			if(ret[c].getVisual() && ret[c].getVisual()[0]){
				var buf = ret[c].getVisual()
				for(var d=0; d<buf.length; d++){
					ret.push(buf[d])
				}
				ret.splice(c, 1)
			}

		var mas_changed = new Array()
		var num_call = 0
		var rek = function(){
			if(num_call>=100){
				// console.log("stackoverflow")
				return
			}
			num_call++
			for(var a=0; a<ret.length; a++){
				for(var b=a+1; b<ret.length; b++){
					var takes1 = ret[a].getTakes()
					var takes2 = ret[b].getTakes()
					var name1 = ret[a].getName()
					var name2 = ret[b].getName()
					if(checkLayers(takes1, takes2, name1, name2)){
						mas_changed.push([ret[a], ret[b]])
						swap(ret, a, b)
						rek()
					}
				}
			}
		}
		rek()
		return ret
	}
	// Проверка положения двух объектов относительно друг друга (если true - меняем местами)
	function checkLayers(takes1, takes2, name1, name2){
		for(var a=0; a< takes1.length; a++)
			for(var b=0; b< takes2.length; b++){
				if(takes1[a].j == takes2[b].j && takes1[a].i == takes2[b].i){
					// console.log(name1, name2)
					if(name2 == "empty" || name2 == "debris" || name2 == "chest" || name2 == "mine")
						return true
					else
						return false
				}

				if(takes1[a].j == takes2[b].j && takes1[a].i > takes2[b].i)
					return true

				if(takes1[a].i == takes2[b].i && takes1[a].j < takes2[b].j)
					return true
					
				if(takes1[a].i != takes2[b].i && takes1[a].j != takes2[b].j && takes1[a].i > takes2[b].i && takes1[a].j < takes2[b].j)
					return true
			}
	}

	// Создание кораблей
	function createsShips(){
		var ship_user = new createjs.Sprite(jsons["JSON1"])
		ship_user.gotoAndStop('3ship')
		ship_user.scaleX = -1
		if(_dim == 16)
			setCoor(ship_user, 1108, 61)
		if(_dim == 12)
			setCoor(ship_user, 871, 145)
		if(_dim == 10)
			setCoor(ship_user, 764, 180)

		var ship_bot = new createjs.Sprite(jsons["JSON1"])
		ship_bot.gotoAndStop('3ship')
		if(_dim == 16)
			setCoor(ship_bot, 154, 64)
		if(_dim == 12)
			setCoor(ship_bot, 68, 153)
		if(_dim == 10)
			setCoor(ship_bot, 42, 180)
		change_cont.addChildAt(ship_user, 0)
		change_cont.addChildAt(ship_bot, 0)

		// dragAndDrop(ship_user)
		// dragAndDrop(ship_bot)

		return {user: ship_user, bot: ship_bot}
	}

	var num_act
	var turn, timer
	// Старт боя
	function startFight(player, o, search){
		t_delInTicker(timer)
		// console.log("stratFight", player, o)
		var coors
		if(_dim == 16)
			coors = player == "user" ? {x:1019, y:127} : {x:296, y:130}
		if(_dim == 12)
			coors = player == "user" ? {x:769, y:214} : {x:214, y:222}
		if(_dim == 10)
			coors = player == "user" ? {x:662, y:249} : {x:183, y:246}
		// console.log(o)
		turn = new Array()
		num_act = 0
		for(var a=0; a< o.length; a++){
			if(o[a].length == 1)
				turn.push({fun: shot, par:[player, o[a][0].i, o[a][0].j, search, null, coors.x, coors.y, 1]})
			if(o[a].length == 3)
				turn.push({fun: megaShot, par: [player, o[a], search]})
			if(o[a].length == 4)
				turn.push({fun: dropBomb, par:[player, o[a], search, 1]})
			if(o[a].length == 5)
				turn.push({fun: runTorpedo, par:[player, o[a], search, 1]})
		}
		next_act()
	}
	function next_act(){
		t_delayOn(1, function(){
			if(!turn[num_act]){
				third_step = true
				_viewmod.changeCurrentPlayer()
				return
			}
			turn[num_act].fun.apply(null, turn[num_act].par)
			num_act ++ 			
		})
	}
	// Взрыв ячейки
	function explosionCell(player, i, j, search, delay, not_sound, num){
		if(delay){	
			timer = t_delayOn(delay, next_act)
		}
		var shoot = false
		var afterShotAnim = function(i, j, player, num){
			// console.log("afterShotAnim")
			_viewmod.shot(i, j, player)
		}
		console.log(searchObj(player, i, j, search))
		if(!searchObj(player, i, j, search)){
			createAnim(i, j, "empty", null, not_sound, afterShotAnim, [i, j, player, num])
			shoot = true
		}else if(searchObj(player, i, j, search) == "mine"){
			createAnim(i, j, "mine", null, not_sound, afterShotAnim, [i, j, player, num])
			shoot = true
		}else if(searchObj(player, i, j, search) == "ship"){
			createAnim(i, j, "ship", null, not_sound, afterShotAnim, [i, j, player, num])
			shoot = true
		}
		// console.log("SHOOOOOOT")
		if(!shoot)
			afterShotAnim(i, j, player, num)
	}

	// Обычный выстрел
	function shot(player, i, j, search, don_tmove_cont, _x, _y, delay, mega_shot, num){
		var bomb = new Bomb()
		setCoor(bomb, _x, _y)
		// th.addChild(bomb)

		// dragAndDrop(bomb)
		var end_x = field_params.startX_bomb + (field_params.dx * j) + (field_params.dx * i)
		var end_y = field_params.startY_bomb + (-field_params.dy * j) + (field_params.dy * i)
		_parent.removeEvents()
		__tweener.tweenTo(bomb, {x: end_x, y: end_y, call: function(){
			_parent.addEvents()
			explosionCell(player, i, j, search, delay, null, num)
		}}, th, null, true, don_tmove_cont, function(){
			// console.log("addChildBomb")
			th.addChild(bomb)
			bomb.playSmoke()
			if(!mega_shot)
				createAnim(i, j, "shot", player)
			else if(don_tmove_cont){
			// 	// console.log("multi")
				createAnim(null, null, "megashot", player)
			// }else{
				// console.log(don_tmove_cont)
			}
			MusicCTRL.play("sound1");
		})
	}
	// Мульти бомба
	function megaShot(player, mas, search){
		var coors
		if(_dim == 16)
			coors = player == "user" ? [{x:1056, y:108}, {x:1073, y:130}, {x:1117, y:149}] : [{x:228, y:108}, {x:205, y:131}, {x:160, y:147}]
		if(_dim == 12)
			coors = player == "user" ? [{x:728, y:218}, {x:748, y:242}, {x:790, y:260}] : [{x:227, y:223}, {x:204, y:245}, {x:162, y:266}]
		if(_dim == 10)
			coors = player == "user" ? [{x:576, y:273}, {x:597, y:299}, {x:643, y:318}] : [{x:186, y:273}, {x:165, y:296}, {x:119, y:315}]
	
		for(var a=0; a<mas.length; a++){
			var tr = a == 0 ? false : true
			var de = a == 0 ? 1 : 0
			shot(player, mas[a].i, mas[a].j, search, tr, coors[a].x, coors[a].y, de, true, a+1)
		}
	}
	// Динамит
	function dropBomb(player, mas, search, delay){
		var balloon = new createjs.Sprite(jsons["JSON1"])
		balloon.gotoAndStop("plane")
		var bottle = new createjs.Sprite(jsons["JSON1"])
		bottle.gotoAndStop("plane_bomb")
		if(player == "user"){
			var out_x = field_params.startX_baloon + (field_params.dx * -10) + (field_params.dx * mas[0].i)
			var out_y = field_params.startY_baloon + (-field_params.dy * -10) + (field_params.dy * mas[0].i)
			var end_x = field_params.startX_baloon + (field_params.dx * mas[0].j) + (field_params.dx * mas[0].i)
			var end_y = field_params.startY_baloon + (-field_params.dy * mas[0].j) + (field_params.dy * mas[0].i)
			var start_x = field_params.startX_baloon + (field_params.dx * _dim) + (field_params.dx * mas[0].i)
			var start_y = field_params.startY_baloon + (-field_params.dy * _dim) + (field_params.dy * mas[0].i)
			var _x = field_params.startX_bottle + (field_params.dx * mas[0].j) + (field_params.dx * mas[0].i)
			var _y = field_params.startY_bottle + (-field_params.dy * mas[0].j) + (field_params.dy * mas[0].i)
		}else if(player == "bot"){
			var out_x = field_params.startX_baloon + (field_params.dx * mas[0].j) + (field_params.dx * (_dim + 10))
			var out_y = field_params.startY_baloon + (-field_params.dy * mas[0].j) + (field_params.dy * (_dim + 10))
			var end_x = field_params.startX_baloon + (field_params.dx * mas[0].j) + (field_params.dx * (mas[0].i + 2) + 15/__koefDisplay)
			var end_y = field_params.startY_baloon + (-field_params.dy * mas[0].j) + (field_params.dy * (mas[0].i + 2) + 15/__koefDisplay)
			var start_x = field_params.startX_baloon + (field_params.dx * mas[0].j) + (field_params.dx * 0)
			var start_y = field_params.startY_baloon + (-field_params.dy * mas[0].j) + (field_params.dy * 0)
			var _x = field_params.startX_bottle_r + (field_params.dx * mas[0].j) + (field_params.dx * mas[0].i)
			var _y = field_params.startY_bottle_r + (-field_params.dy * mas[0].j) + (field_params.dy * mas[0].i)
			balloon.scaleX = -1
			bottle.scaleX = -1
		}
		balloon.x = start_x
		balloon.y = start_y
		th.addChild(balloon)
		var time = distXY(start_x, start_y, end_x, end_y)/300*__koefDisplay
		_parent.removeEvents()
		__tweener.tweenTo(balloon, {x: end_x, y: end_y, d: time, call: function(){
			bottle.x = _x
			bottle.y = _y - 158/__koefDisplay
			// dragAndDrop(bottle)
			th.addChild(bottle)
			th.addChild(balloon)
			var time = distXY(end_x, end_y, out_x, out_y)/300*__koefDisplay
			tw_tweenTo(bottle, {x: _x, y: _y, d: .5, call: function(){
				th.removeChild(bottle)
				for(var a=0; a< mas.length; a++){
					var de = a == 0 ? 1 : false
					explosionCell(player, mas[a].i, mas[a].j, search, null, de)
				}
			}})
				tw_tweenTo(balloon, {x: out_x, y: out_y, d: time, call: function(){
					th.removeChild(balloon)
					_parent.addEvents()
					next_act()
				}, everyTick: function(){
					var co = balloon.parent.localToGlobal(balloon.x, balloon.y)
					if(co.x < 0 - balloon.getBounds().width || co.x > WIDTHGAME + balloon.getBounds().width || co.y < 0 || co.y > HEIGHTGAME){
						tw_removeTween(balloon)
						th.removeChild(balloon)
						_parent.addEvents()
						// next_act()
					}
				}}, th)

				t_delayOn(2, function(){
					next_act()
				})
		} }, th)
	}

	// Поиск объекта по ячейке
	function searchObj(player, i, j, search){
		for(var a=0; a< search.length; a++){
			var t = search[a].getTakes()
			for(var b = 0; b<t.length; b++){
				if(t[b].i == i && t[b].j == j && t.length > search[a].getHits().length)
					return search[a].getName()
			}
		}
	}

	function createAnim(i, j, name, player, not_sound, cb, pars){
		if(name == "empty"){
			if(!not_sound)
				MusicCTRL.play("sound5");
			var an = new createjs.Sprite(jsons["JSON4"])
			an.gotoAndPlay("miss_water_splash")
			var _x = field_params.startX_anim_miss + (field_params.dx * j) + (field_params.dx * i)
			var _y = field_params.startY_anim_miss + (-field_params.dy * j) + (field_params.dy * i)
			setCoor_forHits(an, _x, _y)
		}else if(name == "mine"){
			if(!not_sound)
				MusicCTRL.play("sound2");
			var an = new createjs.Sprite(jsons["JSON3"])
			an.gotoAndPlay("water_exp-mine-treassure")
			var _x = field_params.startX_anim_miss + (field_params.dx * j) + (field_params.dx * i)
			var _y = field_params.startY_anim_miss + (-field_params.dy * j) + (field_params.dy * i)
			setCoor_forHits(an, _x, _y)
		}else if(name == "ship"){
			if(!not_sound)
				MusicCTRL.play("sound2");
			var an = new createjs.Sprite(jsons["JSON3"])
			an.gotoAndPlay("exp_small-hit-ship")
			var _x = field_params.startX_dim + (field_params.dx * j) + (field_params.dx * i)
			var _y = field_params.startY_dim + (-field_params.dy * j) + (field_params.dy * i)
			setCoor_forHits(an, _x, _y)
		}else if(name == "shot"){
			var an = new createjs.Sprite(jsons["JSON3"])
			an.gotoAndPlay("cannon")
			if(player == "user"){
				an.scaleX = -1
				if(_dim == 16)
					setCoor(an, 1078, 22)
				if(_dim == 12)
					setCoor(an, 837, 137)
				if(_dim == 10)
					setCoor(an, 743, 137)
			}else{
				if(_dim == 16)
					setCoor(an, 193, 31)
				if(_dim == 12)
					setCoor(an, 98, 118)
				if(_dim == 10)
					setCoor(an, 68, 141)
			}
		}else if(name == "megashot"){
			var an = new createjs.Sprite(jsons["JSON3"])
			an.gotoAndPlay("cannon3")
			if(player == "user"){
				an.scaleX = -1
				if(_dim == 16)
					setCoor(an, 1097, 14)
				if(_dim == 12)
					setCoor(an, 843, 115)
				if(_dim == 10)
					setCoor(an, 734, 148)
			}else{
				if(_dim == 16)
					setCoor(an, 184, 34)
				if(_dim == 12)
					setCoor(an, 102, 136)
				if(_dim == 10)
					setCoor(an, 73, 145)
			}
		}
		an.addEventListener("animationend", function(e){
			e.target.stop()
			if(e.target.parent)
				e.target.parent.removeChild(e.target)
			if(cb && pars)
				cb.apply(null, pars)
		})
		// dragAndDrop(an)
		th.addChild(an)
	}
	// Поменять местами объекты в массиве
	function swap(mas, a, b){
		var buf = mas[a]
		mas[a] = mas[b]
		mas[b] = buf
	}

	function createVisualObjects(o){
		var p;
		if(o.getCheck)
			p = true
		var m = o.getTakes(p)
		// if(p)
		// 	console.log(m[0].i, m[0].j)
		// console.log(m)
		if(!o.getVisual()[0]){
			o.getVisual().setParent(th, _viewmod)
			o.getVisual().setToCell(m[0].i, m[0].j)
			change_cont.addChild(o.getVisual())
		}
	}

	var mouseChildren = true
	function playAnimPeriscope(callBack){
		if(!mouseChildren)
			return
		mouseChildren = false
		var p = _viewmod.getData()
		var cur_obj;
		for(var a=0; a<p.game_data.selected_objects.length; a++)
			if(p.game_data.selected_objects[a].getName() == "periskop")
				cur_obj = p.game_data.selected_objects[a]
		cur_obj.clearVisible()
		cur_obj.setVisible("submarine_area1")
		cur_obj.setMouseEnabled(false)
		cur_obj.dontMouseTouch()
		// if(cur_obj.getVisual().parent)
		// 	cur_obj.getVisual().parent.removeChild(cur_obj.getVisual())
		
		var first_cell = cur_obj.getTakes()[0]
		var end_x = field_params.startX_subm + (field_params.dx * first_cell.j) + (field_params.dx * first_cell.i)
		var end_y = field_params.startY_subm + (-field_params.dy * first_cell.j) + (field_params.dy * first_cell.i)
		var start_x = field_params.startX_subm + (field_params.dx * _dim) + (field_params.dx * first_cell.i)
		var start_y = field_params.startY_subm + (-field_params.dy * _dim) + (field_params.dy * first_cell.i)
		var subm = new createjs.Sprite(jsons["JSON2"])
		subm.gotoAndStop("submarine")
		th.addChildAt(subm, 0)
		subm.x = start_x
		subm.y = start_y
		var time = distXY(start_x, start_y, end_x, end_y)/300*__koefDisplay

		__tweener.tweenTo(subm, {x: end_x, y: end_y, d: time, call: function(){
			cur_obj.clearVisible()
			cur_obj.setVisible("submarine_area2")
			callBack()

			tw_tweenTo(subm, {x: subm.x, y: subm.y, alpha: .01, call: function(){
				th.removeChild(subm)
			}})
			mouseChildren = true
		} }, th)
		// console.log(end_x, end_y)
		// callBack()
	}

	function runTorpedo(player, mas, search, delay){
		var tor = new createjs.Sprite(jsons["JSON4"])
		tor.gotoAndPlay("torpedo")
		if(player == "user"){
			// var out_x = field_params.startX_torpedo + (field_params.dx * -10) + (field_params.dx * mas[0].i)
			// var out_y = field_params.startY_torpedo + (-field_params.dy * -10) + (field_params.dy * mas[0].i)
			var end_x = field_params.startX_torpedo + (field_params.dx * mas[0].j) + (field_params.dx * mas[0].i)
			var end_y = field_params.startY_torpedo + (-field_params.dy * mas[0].j) + (field_params.dy * mas[0].i)
			var start_x = field_params.startX_torpedo + (field_params.dx * _dim) + (field_params.dx * mas[0].i)
			var start_y = field_params.startY_torpedo + (-field_params.dy * _dim) + (field_params.dy * mas[0].i)
		}else if(player == "bot"){
			var out_x = field_params.startX_torpedo + (field_params.dx * mas[0].j) + (field_params.dx * (_dim + 10))
			var out_y = field_params.startY_torpedo + (-field_params.dy * mas[0].j) + (field_params.dy * (_dim + 10))
			var end_x = 88/__koefDisplay + (field_params.dx * mas[0].j) + (field_params.dx * (mas[0].i) + 15/__koefDisplay)
			var end_y = 386/__koefDisplay + (-field_params.dy * mas[0].j) + (field_params.dy * (mas[0].i) + 15/__koefDisplay)
			var start_x = 88/__koefDisplay + (field_params.dx * mas[0].j) + (field_params.dx * (-1))
			var start_y = 386/__koefDisplay + (-field_params.dy * mas[0].j) + (field_params.dy * (-1))
			tor.scaleX = -1
		}
		tor.x = start_x
		tor.y = start_y
		th.addChildAt(tor, 0)
		var time = distXY(start_x, start_y, end_x, end_y)/300*__koefDisplay
		// dragAndDrop(tor)
		_parent.removeEvents()
		__tweener.tweenTo(tor, {x: end_x, y: end_y, d: time, call: function(){
			_parent.addEvents()
			th.removeChild(tor)
				for(var a=0; a< mas.length; a++){
					var de = a == 0 ? 1 : false
					explosionCell(player, mas[a].i, mas[a].j, search, de, de)
				}
		} }, th)
	}

	function flyMoney(){
		var p = _viewmod.getData()
		var mon = new createjs.Sprite(jsons["JSON1"])
		mon.gotoAndPlay("coin")
		// mon.scaleX = mon.scaleY = .8

		var start_x = field_params.startX_money + (field_params.dx * p.game_data.flying_money.j) + (field_params.dx * p.game_data.flying_money.i)
		var start_y = field_params.startY_money + (-field_params.dy * p.game_data.flying_money.j) + (field_params.dy * p.game_data.flying_money.i)
		var end_point = th.globalToLocal(2/__koefDisplay, 224/__koefDisplay)
		var end_x = end_point.x
		var end_y = end_point.y

		mon.x = start_x
		mon.y = start_y

		th.addChild(mon)
		p.game_data.flying_money = false

		// dragAndDrop(mon)
		t_delayOn(.3, function(){
			tw_tweenTo(mon, {x: end_x, y: end_y, d:.5, call: function(o){
				if(o.parent)
					o.parent.removeChild(o)
			}, pars: [mon]})
		})
		
	}
};