void creature_t::step_toward(int px, int py, creature_t* exclude) { TCODMap* map = new TCODMap(current_dungeon->width, current_dungeon->height); for (int y = 0; y < current_dungeon->height; y++) { for (int x = 0; x < current_dungeon->width; x++) { tile_t* tile = get_tile_at(current_dungeon, x, y); bool walkable = tile_is_walkable_by(*tile, this); if (flag & CF_INTELLIGENT) { // Intelligent monsters know how to open doors. if (tile->id == TILE_DOOR_CLOSED) { walkable = true; } } map->setProperties(x, y, tile->properties & TILE_PROP_TRANSPARENT, walkable); } } for (size_t i = 0; i < current_dungeon->creatures.size(); i++) { creature_t* c = current_dungeon->creatures.at(i); if (c == this || c == exclude) continue; if (sees(c)) { // If this creature can see another creature, then consider that // square as unwalkable. map->setProperties(c->pos.x, c->pos.y, 1, 0); } } TCODPath* path = new TCODPath(map, 1.0f); if (path->compute(pos.x, pos.y, px, py)) { if (path->size() > 0) { int move_x, move_y; path->get(0, &move_x, &move_y); try_move(move_x, move_y); } else { // No path found, walk around confused. random_walk(); } } else { // No path found, walk around confused. random_walk(); } delete map; delete path; }
void Dungeon::drawPath(int y0, int y1, int x0, int x1, int width, char *tiles, void (*tileCallback)(char *)) { TCODMap *map = new TCODMap(m_width, m_height); for(int y=0;y<m_height;y++){ for(int x=0;x<m_width;x++){ map->setProperties(x,y,true,tiles[x+y*width] != 127); } } TCODPath *path = new TCODPath(map,0.0f); bool success = path->compute(x0,y0,x1,y1); if(success){ int x; int y; while(!path->isEmpty()){ path->walk(&x,&y,false); tileCallback(&(tiles[x+y*width])); } } else{ drawLine(y0,y1,x0,x1,width,tiles,tileCallback); } }
void BuildRoom(TCODBsp *node){ auto minX = node->x + _wallThickness - 1; auto minY = node->y + _wallThickness - 1; auto maxX = node->x + node->w; auto maxY = node->y + node->h; auto minSize = (_wallThickness + _minRoomSize); bool hasRoom = node->w > minSize && node->h > minSize; for(int x = node->x; x <= (node->x + node->w); x++){ for(int y = node->y; y <= (node->y + node->h); y++){ if(hasRoom){ if(((x > minX && x < maxX && x != DUNGEON_X -1) || (x <= _wallThickness && x >= 1)) && ((y > minY && y < maxY && y != DUNGEON_Y -1) || (y <= _wallThickness && y >= 1))) { _map->setProperties(x,y,true,true); } } else{ _map->setProperties(x,y,false,false); } } } };