Error GridMap::create_area(int p_id, const Rect3 &p_bounds) { ERR_FAIL_COND_V(area_map.has(p_id), ERR_ALREADY_EXISTS); ERR_EXPLAIN("ID 0 is taken as global area, start from 1"); ERR_FAIL_COND_V(p_id == 0, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(p_bounds.has_no_area(), ERR_INVALID_PARAMETER); // FIRST VALIDATE AREA IndexKey from, to; from.x = p_bounds.pos.x; from.y = p_bounds.pos.y; from.z = p_bounds.pos.z; to.x = p_bounds.pos.x + p_bounds.size.x; to.y = p_bounds.pos.y + p_bounds.size.y; to.z = p_bounds.pos.z + p_bounds.size.z; for (Map<int, Area *>::Element *E = area_map.front(); E; E = E->next()) { //this should somehow be faster... Area &a = *E->get(); //does it interset with anything else? if (from.x >= a.to.x || to.x <= a.from.x || from.y >= a.to.y || to.y <= a.from.y || from.z >= a.to.z || to.z <= a.from.z) { // all good } else { return ERR_INVALID_PARAMETER; } } Area *area = memnew(Area); area->from = from; area->to = to; area->portal_disable_distance = 0; area->exterior_portal = false; area->name = "Area " + itos(p_id); area_map[p_id] = area; _recreate_octant_data(); return OK; }