float HighTerrainAttrAreaFactor::calcDecision(Crood &crood)
{
	float possibility = 0.0f;
	MapDataManager* mapdata = MapDataManager::getSingletonPtr();
	for(int x = crood.mX - 2; x <= crood.mX + 2; x++)
	{
		for(int y = crood.mY- 2; y <= crood.mY + 2; y++)
		{
			int dist = 4 - GetDistance(x, y, crood.mX, crood.mY);
			switch(mAttrType)
			{
			case 0:
				possibility += 0.83f * dist * mapdata->getDefModify(x, y, -1);
				break;
			case 1:
				possibility += 0.83f * dist * mapdata->getCovert(x, y, -1);
				break;
			case 2:
				possibility += 0.83f * dist * (mapdata->getInfApCost(x, y, -1) - 2.0f);
				break;
			case 3:
				possibility += 0.83f * dist * (mapdata->getCavApCost(x, y, -1) - 2.0f);
				break;
			}
		}
	}
	return possibility;
}
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;
}