![]() |
Freeciv21
Develop your civilization from humble roots to a global empire
|
#include "log.h"#include "government.h"#include "improvement.h"#include "research.h"#include "tech.h"#include "client_main.h"#include "options.h"#include "tileset/tilespec.h"#include "views/view_research_reqtree.h"#include "colors_g.h"#include "sprite_g.h"#include <QPainter>#include <QPainterPath>#include <QPixmap>#include <QRect>
Include dependency graph for view_research_reqtree.cpp:Go to the source code of this file.
Classes | |
| struct | node_and_float |
Enumerations | |
| enum | reqtree_edge_type { REQTREE_EDGE = 0 , REQTREE_READY_EDGE , REQTREE_KNOWN_EDGE , REQTREE_ACTIVE_EDGE , REQTREE_GOAL_EDGE } |
| Edge types for coloring the edges by type in the tree. More... | |
Functions | |
| static void | add_requirement (struct tree_node *node, struct tree_node *req) |
| Add requirement edge to node and provide edge to req. More... | |
| static struct tree_node * | new_tree_node () |
| Allocate and initialize new tree node. More... | |
| static void | node_rectangle_minimum_size (struct tree_node *node, int *width, int *height) |
| Return minimum size of the rectangle in pixels on the diagram which corresponds to the given node. More... | |
| static void | symmetrize (struct reqtree *tree) |
| Move nodes up and down without changing order but making it more symetrical. More... | |
| static void | calculate_diagram_layout (struct reqtree *tree) |
| Calculate rectangles position and size from the tree. More... | |
| static struct reqtree * | create_dummy_reqtree (struct player *pplayer, bool show_all) |
| Create a "dummy" tech tree from current ruleset. More... | |
| void | destroy_reqtree (struct reqtree *tree) |
| Free all memory used by tech_tree struct. More... | |
| static int | longest_path (struct tree_node *node) |
| Compute the longest path from this tree_node to the node with no requirements. More... | |
| static void | longest_path_layering (struct reqtree *tree) |
| Compute longest_path for all nodes, thus prepare longest path layering. More... | |
| static int | max_provide_layer (struct tree_node *node) |
| Find the largest value of layer amongst children of the given node. More... | |
| static struct reqtree * | add_dummy_nodes (struct reqtree *tree) |
| Create new tree which has dummy nodes added. More... | |
| static void | set_layers (struct reqtree *tree) |
| Calculate layers[] and layer_size[] fields of tree. More... | |
| static int | cmp_func (const node_and_float &a, const node_and_float &b) |
| Comparison function used by barycentric_sort. More... | |
| static void | barycentric_sort (struct reqtree *tree, int layer) |
| Simple heuristic: Sort nodes on the given layer by the average x-value of its' parents. More... | |
| static int | count_crossings (struct reqtree *tree, int layer) |
| Calculate number of edge crossings beetwen layer and layer+1. More... | |
| static void | swap (struct reqtree *tree, int layer, int order1, int order2) |
| Swap positions of two nodes on the same layer. More... | |
| static void | improve (struct reqtree *tree) |
| Try to reduce the number of crossings by swapping two nodes and checking if it improves the situation. More... | |
| struct reqtree * | create_reqtree (struct player *pplayer, bool show_all) |
| Generate optimized tech_tree from current ruleset. More... | |
| void | get_reqtree_dimensions (struct reqtree *reqtree, int *width, int *height) |
| Give the dimensions of the reqtree. More... | |
| static QColor | node_color (struct tree_node *node) |
| Return a background color of node's rectangle. More... | |
| static enum reqtree_edge_type | get_edge_type (struct tree_node *node, struct tree_node *dest_node) |
| Return the type for an edge between two nodes if node is a dummy, dest_node can be nullptr. More... | |
| static QColor | edge_color (struct tree_node *node, struct tree_node *dest_node) |
| Return a stroke color for an edge between two nodes if node is a dummy, dest_node can be nullptr. More... | |
| QList< req_tooltip_help * > * | draw_reqtree (struct reqtree *tree, QPixmap *pcanvas, int canvas_x, int canvas_y, int tt_x, int tt_y, int w, int h) |
| Draw the reqtree diagram! More... | |
| Tech_type_id | get_tech_on_reqtree (struct reqtree *tree, int x, int y) |
| Return the tech ID at the given position of the reqtree (or A_NONE). More... | |
| bool | get_position_on_reqtree (struct reqtree *tree, Tech_type_id tech, int *x, int *y) |
| Find the center of a node, identified by tech id in a given reqtree and return true if the node was found; false otherwise. More... | |
| enum reqtree_edge_type |
Edge types for coloring the edges by type in the tree.
| Enumerator | |
|---|---|
| REQTREE_EDGE | |
| REQTREE_READY_EDGE | |
| REQTREE_KNOWN_EDGE | |
| REQTREE_ACTIVE_EDGE | |
| REQTREE_GOAL_EDGE | |
Definition at line 67 of file view_research_reqtree.cpp.
Create new tree which has dummy nodes added.
The source tree is completely copied, you can freely deallocate it.
Definition at line 507 of file view_research_reqtree.cpp.
Referenced by create_reqtree().
Add requirement edge to node and provide edge to req.
Definition at line 78 of file view_research_reqtree.cpp.
Referenced by add_dummy_nodes(), and create_dummy_reqtree().
|
static |
Simple heuristic: Sort nodes on the given layer by the average x-value of its' parents.
Definition at line 655 of file view_research_reqtree.cpp.
Referenced by create_reqtree().
|
static |
Calculate rectangles position and size from the tree.
Logical order should already be calculated.
Definition at line 249 of file view_research_reqtree.cpp.
Referenced by create_reqtree().
|
static |
Comparison function used by barycentric_sort.
Definition at line 646 of file view_research_reqtree.cpp.
Referenced by barycentric_sort().
|
static |
Calculate number of edge crossings beetwen layer and layer+1.
Definition at line 687 of file view_research_reqtree.cpp.
Referenced by improve().
Create a "dummy" tech tree from current ruleset.
This tree is then fleshed out further (see create_reqtree). This tree doesn't include dummy edges. Layering and ordering isn't done also.
If pplayer is given, add only techs reachable by that player to tree.
Definition at line 347 of file view_research_reqtree.cpp.
Referenced by create_reqtree().
Generate optimized tech_tree from current ruleset.
You should free it by destroy_reqtree.
If pplayer is not nullptr, techs unreachable to that player are not shown.
Definition at line 789 of file view_research_reqtree.cpp.
Referenced by research_diagram::reset().
| void destroy_reqtree | ( | struct reqtree * | tree | ) |
Free all memory used by tech_tree struct.
Definition at line 433 of file view_research_reqtree.cpp.
Referenced by create_reqtree(), research_diagram::reset(), and research_diagram::~research_diagram().
| QList<req_tooltip_help *>* draw_reqtree | ( | struct reqtree * | tree, |
| QPixmap * | pcanvas, | ||
| int | canvas_x, | ||
| int | canvas_y, | ||
| int | tt_x, | ||
| int | tt_y, | ||
| int | w, | ||
| int | h | ||
| ) |
Draw the reqtree diagram!
This draws the given portion of the reqtree diagram (given by (tt_x,tt_y) and (w,h) onto the canvas at position (canvas_x, canvas_y).
Definition at line 984 of file view_research_reqtree.cpp.
Referenced by research_diagram::update_reqtree().
Return a stroke color for an edge between two nodes if node is a dummy, dest_node can be nullptr.
Definition at line 959 of file view_research_reqtree.cpp.
Referenced by draw_reqtree().
|
static |
Return the type for an edge between two nodes if node is a dummy, dest_node can be nullptr.
Definition at line 833 of file view_research_reqtree.cpp.
Referenced by edge_color().
| bool get_position_on_reqtree | ( | struct reqtree * | tree, |
| Tech_type_id | tech, | ||
| int * | x, | ||
| int * | y | ||
| ) |
Find the center of a node, identified by tech id in a given reqtree and return true if the node was found; false otherwise.
If a node is found, x and y are filled with the center of the node in reqtrees coordinate system.
Definition at line 1193 of file view_research_reqtree.cpp.
Referenced by research_diagram::get_tech_position().
| void get_reqtree_dimensions | ( | struct reqtree * | reqtree, |
| int * | width, | ||
| int * | height | ||
| ) |
Give the dimensions of the reqtree.
Definition at line 820 of file view_research_reqtree.cpp.
Referenced by research_diagram::reset().
| Tech_type_id get_tech_on_reqtree | ( | struct reqtree * | tree, |
| int | x, | ||
| int | y | ||
| ) |
Return the tech ID at the given position of the reqtree (or A_NONE).
Definition at line 1168 of file view_research_reqtree.cpp.
Referenced by research_diagram::mousePressEvent().
|
static |
Try to reduce the number of crossings by swapping two nodes and checking if it improves the situation.
Definition at line 734 of file view_research_reqtree.cpp.
Referenced by create_reqtree(), and plr_widget::nation_selected().
|
static |
Compute the longest path from this tree_node to the node with no requirements.
Store the result in node->layer.
Definition at line 458 of file view_research_reqtree.cpp.
Referenced by longest_path_layering().
|
static |
Compute longest_path for all nodes, thus prepare longest path layering.
Definition at line 476 of file view_research_reqtree.cpp.
Referenced by create_reqtree().
|
static |
Find the largest value of layer amongst children of the given node.
Definition at line 490 of file view_research_reqtree.cpp.
Referenced by add_dummy_nodes().
|
static |
Allocate and initialize new tree node.
Definition at line 97 of file view_research_reqtree.cpp.
Referenced by add_dummy_nodes(), and create_dummy_reqtree().
|
static |
Return a background color of node's rectangle.
Definition at line 833 of file view_research_reqtree.cpp.
Referenced by draw_reqtree().
|
static |
Return minimum size of the rectangle in pixels on the diagram which corresponds to the given node.
Definition at line 114 of file view_research_reqtree.cpp.
Referenced by calculate_diagram_layout().
|
static |
Calculate layers[] and layer_size[] fields of tree.
There should be layer value calculated for each node. Nodes will be put into layers in no particular order.
Definition at line 598 of file view_research_reqtree.cpp.
Referenced by create_reqtree().
|
static |
Swap positions of two nodes on the same layer.
Definition at line 719 of file view_research_reqtree.cpp.
Referenced by base_set_mapview_origin(), draw_trade_route_line(), improve(), update_map_canvas(), and map_view::wheelEvent().
|
static |
Move nodes up and down without changing order but making it more symetrical.
Gravitate towards parents average position.
Definition at line 193 of file view_research_reqtree.cpp.
Referenced by calculate_diagram_layout().