| 852 | } |
| 853 | |
| 854 | void cOrgSensor::SetWalkLimits(cAvidaContext& ctx, sLookInit& in_defs, sWalkLimits& limits, sBounds& worldBounds, sBounds& tot_bounds, Apto::Array<int, Apto::Smart>& val_res, int worldx, Apto::Coord<int>& this_cell, int facing, int cell, Apto::Coord<int>& center_cell, const Apto::Coord<int>& ahead_dir) |
| 855 | { |
| 856 | limits.start = 0; |
| 857 | limits.end = in_defs.distance; |
| 858 | |
| 859 | // set geometric bounds, and fast-forward, if possible |
| 860 | Apto::Array<int, Apto::Smart> val_res2 = val_res; |
| 861 | if (in_defs.habitat != -2 && in_defs.habitat != 3) { |
| 862 | bool has_global = false; |
| 863 | bool in_res = false; //check to see org in resource RKB |
| 864 | bool global_only = true; |
| 865 | int temp_start_dist = in_defs.distance; |
| 866 | for (int i = 0; i < val_res.GetSize(); i++) { |
| 867 | if (m_res_lib.GetResource(val_res[i])->GetGradient()) { |
| 868 | int this_start_dist = 0; |
| 869 | sBounds res_bounds = GetBounds(ctx, val_res[i]); |
| 870 | this_start_dist = GetMinDist(worldx, res_bounds, cell, in_defs.distance, facing); |
| 871 | // drop any out of range... |
| 872 | if (this_start_dist == -1) { |
| 873 | val_res.Swap(i, val_res.GetSize() - 1); |
| 874 | val_res.Pop(); |
| 875 | i--; |
| 876 | } else { |
| 877 | global_only = false; |
| 878 | if (res_bounds.min_x < tot_bounds.min_x) tot_bounds.min_x = res_bounds.min_x; |
| 879 | if (res_bounds.min_y < tot_bounds.min_y) tot_bounds.min_y = res_bounds.min_y; |
| 880 | if (res_bounds.max_x > tot_bounds.max_x) tot_bounds.max_x = res_bounds.max_x; |
| 881 | if (res_bounds.max_y > tot_bounds.max_y) tot_bounds.max_y = res_bounds.max_y; |
| 882 | in_res = ((res_bounds.min_x <= this_cell.X() && res_bounds.max_x >= this_cell.X()) && (res_bounds.min_y <= this_cell.Y() && res_bounds.max_y >= this_cell.Y())); //Assigns bool to that state RKB |
| 883 | if (this_start_dist < temp_start_dist) temp_start_dist = this_start_dist; |
| 884 | } |
| 885 | } else { |
| 886 | in_res = true; |
| 887 | // if any res is global, we just need to make sure we check at least one cell |
| 888 | if (m_res_lib.GetResource(val_res[i])->GetGeometry() == nGeometry::GLOBAL) has_global = true; |
| 889 | // if any res is spatial and non-gradient, we can't bound things because those res don't track the variables we use for bounding |
| 890 | else { |
| 891 | global_only = false; |
| 892 | tot_bounds = worldBounds; |
| 893 | temp_start_dist = 0; |
| 894 | break; |
| 895 | } |
| 896 | } |
| 897 | } |
| 898 | limits.start = temp_start_dist; |
| 899 | if (val_res.GetSize() == 0) { // nothing in range |
| 900 | limits.visible = false; |
| 901 | return; |
| 902 | } |
| 903 | |
| 904 | /* Code to allow searching to continue past world edges in torus */ |
| 905 | if (in_res && m_world->GetConfig().WORLD_GEOMETRY.Get() == 2) { |
| 906 | if (facing == 0 || facing == 4) limits.end = worldBounds.max_y - 1; |
| 907 | else if (facing == 2 || facing == 6) limits.end = worldBounds.max_x - 1; |
| 908 | else if (facing == 1 || facing == 5) limits.end = max(abs(worldBounds.max_x - 1), abs(worldBounds.max_y - 1)); |
| 909 | else if (facing == 7 || facing == 3) limits.end = max(abs(worldBounds.max_x - 1), abs(worldBounds.max_y - 1)); |
| 910 | limits.end = min(limits.end, in_defs.distance); |
| 911 | } |
nothing calls this directly
no test coverage detected