bool BattleSquad::move(int tgx, int tgy, unsigned int &eventflag, bool costap)
{
	MapDataManager* mapdatamanager = MapDataManager::getSingletonPtr();
	if(mapdatamanager->getPassable(tgx, tgy, getFaction()))
	{
		float mapapcost = 0.0f;
		if(getHorseId() != "none")
			mapapcost = mapdatamanager->getCavApCost(tgx, tgy, getFaction());
		else
			mapapcost = mapdatamanager->getInfApCost(tgx, tgy, getFaction());

		LuaTempContext* luatempcontext = new LuaTempContext();
		luatempcontext->strMap["squadid"] = getSquadId();
		luatempcontext->intMap["srcx"] = getGridX();
		luatempcontext->intMap["srcy"] = getGridY();
		luatempcontext->intMap["tgtx"] = tgx;
		luatempcontext->intMap["tgty"] = tgy;
		luatempcontext->floatMap["apcost"] = mapapcost;
		Trigger("MoveTo", luatempcontext);
		mapdatamanager->Trigger("MoveTo", luatempcontext);
		mapapcost = luatempcontext->floatMap["apcost"];
		delete luatempcontext;

		if(costap)
		{
			float ap = getActionPoint();
			if(mapapcost <= ap)
			{
				ap -= mapapcost;
				setActionPoint(ap);
				if(mapapcost <= 2)
				{
					eventflag |= MOVEEVENT_CHARGE;
					int curdir = GetDirection(getGridX(), getGridY(), tgx, tgy);
					eventflag &= 0x03f;
					eventflag |= SetChargeDir(curdir);
				}
				else
				{
					eventflag &= ~MOVEEVENT_CHARGE;
				}
				return true;
			}
		}
		else
		{
			return true;
		}
	}
	eventflag |= MOVEEVENT_WRONG;
	return false;
}
bool BattleDeployState::mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
{
	int GX,GY;
	Terrain::getSingletonPtr()->coordinateToGrid(arg.state.X.abs,arg.state.Y.abs,GX,GY);
	if(mSelectSquad)
	{
		if(id == OIS::MB_Left)
		{
			MapDataManager* datamanager = MapDataManager::getSingletonPtr();
			if(mAreaGrap->inArea(GX,GY) && datamanager->getPassable(GX,GY,0) && BattleSquadManager::getSingleton().getBattleSquadAt(GX,GY,0,false) == NULL)
			{
				std::string id = mSelectSquad->getSquadId();
				SquadGraphics* squadgrap = SquadGrapManager::getSingleton().getSquad(id);
				squadgrap->setGrid(GX,GY);
				mSelectSquad->setGridX(GX);
				mSelectSquad->setGridY(GY);
				mDeployWindow->setDeployInfo(mSelectIndex,StringTable::getSingleton().getString("DeployConfirm"));
				mMapWindow->updatePoint();
				if(BattleSquadManager::getSingleton().allDeployed())
					mDeployWindow->setAllowConfirm(true);
			}
		}
		else if(id == OIS::MB_Right)
		{
			int x,y;
			x = mSelectSquad->getGridX();
			y = mSelectSquad->getGridY();
			Direction d = GetDirection(x,y, GX, GY);
			mSelectSquad->setDirection(d);
			std::string grapid = mSelectSquad->getSquadId();
			SquadGraphics* squadgrap = SquadGrapManager::getSingleton().getSquad(grapid);
			squadgrap->setDirection(d,false);
			mSquadWindow->setSquad(mSelectSquad);
		}

	}
	return true;
}