/* struct node { int data; node* left; node* right; }; */ static void left_side(node *root){ if(root == NULL){ return; } left_side(root->left); cout << root->data << " "; }
static void top_view(node * root) { if(root == NULL){ return; } left_side(root->left); cout << root->data << " "; right_side(root->right); }
int is_identical(struct node_dll *head, struct node *root){ int n,n1, n2; if (root == NULL || head == NULL) return -1; n = check_node(head, root->data); if (n == 0) return 0; n1=left_side(root->left, head); n2=right_side(root->right, head); if (n1 == 1 && n2 == 1) return 1; else return 0; }
int left_side(node *curr, node_dll *head) { int n,n1, n2; if (curr == NULL) return -1; else { n = check_node(head, curr->data); if (n == 0) return 0; n1 = left_side(curr->left, head); n2 = right_side(curr->right, head); if (n1 == 1 && n2 == 1) return 1; else return 0; } }
IntPoint to_the_right_middle_of(window_t window, const IntSize& size){ const auto x = left_side(window) + get_width(window) + 5; const auto y = top(window) + get_height(window) / 2 - size.h / 2; return {x, y}; }
IntPoint below(window_t window){ return {left_side(window), bottom(window) + ui::small_item_spacing}; }
void unit_preview_pane::draw_contents() { if(index_ < 0 || index_ >= int(size())) { return; } const details det = get_details(); const bool right_align = left_side(); surface screen = video().getSurface(); SDL_Rect const &loc = location(); const SDL_Rect area = create_rect(loc.x + unit_preview_border , loc.y + unit_preview_border , loc.w - unit_preview_border * 2 , loc.h - unit_preview_border * 2); const clip_rect_setter clipper(screen, &area); surface unit_image = det.image; if (!left_) unit_image = image::reverse_image(unit_image); SDL_Rect image_rect = create_rect(area.x, area.y, 0, 0); if(unit_image != NULL) { SDL_Rect rect = create_rect( right_align ? area.x : area.x + area.w - unit_image->w , area.y , unit_image->w , unit_image->h); sdl_blit(unit_image,NULL,screen,&rect); image_rect = rect; } // Place the 'unit profile' button const SDL_Rect button_loc = create_rect( right_align ? area.x : area.x + area.w - details_button_.location().w , image_rect.y + image_rect.h , details_button_.location().w , details_button_.location().h); details_button_.set_location(button_loc); SDL_Rect description_rect = create_rect(image_rect.x , image_rect.y + image_rect.h + details_button_.location().h , 0 , 0); if(det.name.empty() == false) { std::stringstream desc; desc << font::BOLD_TEXT << det.name; const std::string description = desc.str(); description_rect = font::text_area(description, font::SIZE_NORMAL); description_rect = font::draw_text(&video(), area, font::SIZE_NORMAL, font::NORMAL_COLOR, desc.str(), right_align ? image_rect.x : image_rect.x + image_rect.w - description_rect.w, image_rect.y + image_rect.h + details_button_.location().h); } std::stringstream text; text << font::unit_type << det.type_name << "\n" << font::race << (right_align && !weapons_ ? det.race+" " : " "+det.race) << "\n" << _("level") << " " << det.level << "\n" << det.alignment << "\n" << det.traits << "\n"; for(std::vector<t_string>::const_iterator a = det.abilities.begin(); a != det.abilities.end(); ++a) { if(a != det.abilities.begin()) { text << ", "; } text << (*a); } text << "\n"; // Use same coloring as in generate_report.cpp: text << det.hp_color << _("HP: ") << det.hitpoints << "/" << det.max_hitpoints << "\n"; text << det.xp_color << _("XP: ") << det.experience << "/" << det.max_experience << "\n"; if(weapons_) { text << _("Moves: ") << det.movement_left << "/" << det.total_movement << "\n"; for(std::vector<attack_type>::const_iterator at_it = det.attacks.begin(); at_it != det.attacks.end(); ++at_it) { // specials_context seems not needed here //at_it->set_specials_context(map_location(),u); // see generate_report() in generate_report.cpp text << font::weapon << at_it->damage() << font::weapon_numbers_sep << at_it->num_attacks() << " " << at_it->name() << "\n"; text << font::weapon_details << " " << string_table["range_" + at_it->range()] << font::weapon_details_sep << string_table["type_" + at_it->type()] << "\n"; std::string accuracy_parry = at_it->accuracy_parry_description(); if(accuracy_parry.empty() == false) { text << font::weapon_details << " " << accuracy_parry << "\n"; } std::string special = at_it->weapon_specials(true); if (!special.empty()) { text << font::weapon_details << " " << special << "\n"; } } } // we don't remove empty lines, so all fields stay at the same place const std::vector<std::string> lines = utils::split(text.str(), '\n', utils::STRIP_SPACES & !utils::REMOVE_EMPTY); int ypos = area.y; if(weapons_) { ypos += image_rect.h + description_rect.h + details_button_.location().h; } for(std::vector<std::string>::const_iterator line = lines.begin(); line != lines.end(); ++line) { int xpos = area.x; if(right_align && !weapons_) { const SDL_Rect& line_area = font::text_area(*line,font::SIZE_SMALL); // right align, but if too long, don't hide line's beginning if (line_area.w < area.w) xpos = area.x + area.w - line_area.w; } SDL_Rect cur_area = font::draw_text(&video(),location(),font::SIZE_SMALL,font::NORMAL_COLOR,*line,xpos,ypos); ypos += cur_area.h; } }