Freeciv21
Develop your civilization from humble roots to a global empire
view_research_reqtree.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 1996-2020 Freeciv21 and Freeciv contributors. This file is
3  __ __ part of Freeciv21. Freeciv21 is free software: you can
4 / \\..// \ redistribute it and/or modify it under the terms of the GNU
5  ( oo ) General Public License as published by the Free Software
6  \__/ Foundation, either version 3 of the License, or (at your
7  option) any later version. You should have received
8  a copy of the GNU General Public License along with Freeciv21. If not,
9  see https://www.gnu.org/licenses/.
10 **************************************************************************/
11 #pragma once
12 
13 // client
14 #include "canvas.h"
15 
16 #include <QRect>
17 
18 /* Requirements Tree
19  *
20  * This file provides functions for drawing a tree-like graph of
21  * requirements. This can be used for creating an interactive diagram
22  * showing the dependencies of various sources.
23  *
24  * A tree must first be created with create_reqtree; this will do all of the
25  * calculations needed for the tree and is a fairly expensive operation.
26  * After creating the tree, the other functions may be used to access or
27  * draw it.
28  *
29  * Currently only techs are supported (as sources and requirements).
30  */
31 
32 /****************************************************************************
33  This structure desribes a node in a technology tree diagram.
34  A node can by dummy or real. Real node describes a technology.
35 ****************************************************************************/
36 struct tree_node {
37  bool is_dummy;
39 
40  // Incoming edges
41  int nrequire;
42  struct tree_node **require;
43 
44  // Outgoing edges
45  int nprovide;
46  struct tree_node **provide;
47 
48  // logical position on the diagram
49  int order, layer;
50 
51  // Coordinates of the rectangle on the diagram in pixels
53 
54  // for general purpose
55  int number;
56 };
57 
58 /****************************************************************************
59  Structure which describes abstract technology diagram.
60  Nodes are ordered inside layers[] table.
61 ****************************************************************************/
62 struct reqtree {
63  int num_nodes;
64  struct tree_node **nodes;
65 
67  // size of each layer
68  int *layer_size;
69  struct tree_node ***layers;
70 
71  // in pixels
73 };
74 
75 /****************************************************************************
76  Helper item for research diagram, about drawn rectangles and what
77  tech/unit/improvement they point to.
78 ****************************************************************************/
80 public:
81  req_tooltip_help() = default;
82  QRect rect;
84  struct unit_type *tunit{nullptr};
85  struct impr_type *timpr{nullptr};
86  struct government *tgov{nullptr};
87 };
88 
89 struct reqtree *create_reqtree(struct player *pplayer, bool show_all);
90 void destroy_reqtree(struct reqtree *tree);
91 
92 void get_reqtree_dimensions(struct reqtree *tree, int *width, int *height);
93 
94 QList<req_tooltip_help *> *draw_reqtree(struct reqtree *tree,
95  QPixmap *pcanvas, int canvas_x,
96  int canvas_y, int tt_x, int tt_y,
97  int w, int h);
98 
99 Tech_type_id get_tech_on_reqtree(struct reqtree *tree, int x, int y);
100 
101 bool get_position_on_reqtree(struct reqtree *tree, Tech_type_id tech, int *x,
102  int *y);
struct government * tgov
req_tooltip_help()=default
struct unit_type * tunit
struct impr_type * timpr
int Tech_type_id
Definition: fc_types.h:294
Definition: player.h:231
struct tree_node ** nodes
struct tree_node *** layers
struct tree_node ** provide
Tech_type_id tech
struct tree_node ** require
void get_reqtree_dimensions(struct reqtree *tree, int *width, int *height)
Give the dimensions of the reqtree.
struct reqtree * create_reqtree(struct player *pplayer, bool show_all)
Generate optimized tech_tree from current ruleset.
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!
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).
void destroy_reqtree(struct reqtree *tree)
Free all memory used by tech_tree struct.
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 f...