TbBool can_place_trap_on(PlayerNumber plyr_idx, MapSubtlCoord stl_x, MapSubtlCoord stl_y) { MapSlabCoord slb_x, slb_y; slb_x = subtile_slab_fast(stl_x); slb_y = subtile_slab_fast(stl_y); struct SlabMap *slb; slb = get_slabmap_block(slb_x, slb_y); struct SlabAttr *slbattr; slbattr = get_slab_attrs(slb); if (!subtile_revealed(stl_x, stl_y, plyr_idx)) { return false; } if (((slbattr->block_flags & (SlbAtFlg_Filled|SlbAtFlg_Digable|SlbAtFlg_Valuable)) != 0)) { return false; } if (slab_kind_is_liquid(slb->kind)) { return false; } if ((slabmap_owner(slb) == plyr_idx) && (slb->kind == SlbT_CLAIMED)) { if (!slab_has_trap_on(slb_x, slb_y) && !subtile_has_door_thing_on(stl_x, stl_y)) { return true; } } return false; }
TbBool find_place_to_put_door_around_room(const struct Room *room, struct Coord3d *pos) { long m,n; m = ACTION_RANDOM(SMALL_AROUND_SLAB_LENGTH); for (n = 0; n < SMALL_AROUND_SLAB_LENGTH; n++) { // Get position containing room center MapSlabCoord slb_x,slb_y; slb_x = subtile_slab_fast(room->central_stl_x); slb_y = subtile_slab_fast(room->central_stl_y); // Move the position to edge of the room struct Room *sibroom; sibroom = slab_room_get(slb_x, slb_y); while (!room_is_invalid(sibroom) && (sibroom->index == room->index)) { slb_x += small_around[m].delta_x; slb_y += small_around[m].delta_y; sibroom = slab_room_get(slb_x, slb_y); } // Move the position a few tiles further in that direction searching for a place to put door //TODO COMPUTER_PLAYER Why we can only have doors if corridor is at center of the room? This should be fixed to allow doors everywhere around room. int i; for (i = 4; i > 0; i--) { struct SlabMap *slb; slb = get_slabmap_block(slb_x, slb_y); if ((slabmap_owner(slb) != room->owner) || (slb->kind != SlbT_CLAIMED)) { i = 0; break; } if (tag_cursor_blocks_place_door(room->owner, slab_subtile_center(slb_x), slab_subtile_center(slb_y))) { break; } if (!subtile_has_door_thing_on(slab_subtile_center(slb_x), slab_subtile_center(slb_y))) { // No door - the position looks ok break; } slb_x += small_around[m].delta_x; slb_y += small_around[m].delta_y; } // Now if we were able to move, then the position seem ok. One last check - make sure the corridor is not dead end and doesn't already have a door if (i > 0) { MapSlabCoord nxslb_x,nxslb_y; nxslb_x = slb_x + small_around[m].delta_x; nxslb_y = slb_y + small_around[m].delta_y; struct SlabMap *nxslb; nxslb = get_slabmap_block(nxslb_x, nxslb_y); if ((slabmap_owner(nxslb) == room->owner) && (nxslb->kind == SlbT_CLAIMED)) { if (!subtile_has_door_thing_on(slab_subtile_center(nxslb_x), slab_subtile_center(nxslb_y))) { pos->x.val = subtile_coord_center(slab_subtile_center(slb_x)); pos->y.val = subtile_coord_center(slab_subtile_center(slb_y)); pos->z.val = subtile_coord(1,0); return true; } } } m = (m + 1) % SMALL_AROUND_SLAB_LENGTH; } return false; }