public int mv_cost(CLoc t_loc, string level, CUnit aiunit) { if (t_loc == null) { return(int.MaxValue); } string t = map_.getMapLocation(t_loc.x, t_loc.y); CUnit[] hosts = getHostsAtLoc(t_loc); //No One in location bool nohost = true; if (hosts != null) { switch (level) { case CUnitConstants.LVL_ORB: nohost = (hosts[CUnitConstants.ORB_LEVEL_INDEX] == null); break; case CUnitConstants.LVL_SUB: nohost = (hosts[CUnitConstants.SUB_LEVEL_INDEX] == null); break; default: //stack nohost = ((hosts[CUnitConstants.STACK_GROUND_INDEX] == null) && (hosts[CUnitConstants.STACK_AIR_INDEX] == null)); break; } } if (nohost) { if (aiunit.entry_.canMove(t)) { return(aiunit.entry_.getMove(t)); } else { return(EmpireCC.IMPOSSIBLE); } } //we have a host //some of the cases here are simplified and could fail on execution CUnit hu = null; switch (level) { case CUnitConstants.LVL_ORB: { hu = hosts[CUnitConstants.ORB_LEVEL_INDEX]; break; } case CUnitConstants.LVL_SUB: { hu = hosts[CUnitConstants.SUB_LEVEL_INDEX]; break; } default: //stack { hu = (hosts[CUnitConstants.STACK_AIR_INDEX] != null) ? hosts[CUnitConstants.STACK_AIR_INDEX] : hosts[CUnitConstants.STACK_GROUND_INDEX]; break; } } //friendly if (hu.owner_ == position_) { if (hu.entry_.canTransport(aiunit.utype_)) { return(1); } return(EmpireCC.IMPOSSIBLE); } if (aiunit.entry_.canMove(t)) { if (hu.entry_.isCity()) { return((aiunit.entry_.cityCombat() != CUnitConstants.CC_NONE) ? 1:EmpireCC.IMPOSSIBLE); } return(aiunit.entry_.getMove(t)); } else if ((t == EmpireCC.CT_SEA || t == EmpireCC.CT_SHALLOWSEA) && aiunit.entry_.canSeaBombardAttack()) { return(1); } return(EmpireCC.IMPOSSIBLE); }