1 #pragma once
2 #ifndef CATA_SRC_CONSTRUCTION_H
3 #define CATA_SRC_CONSTRUCTION_H
4 
5 #include <functional>
6 #include <iosfwd>
7 #include <list>
8 #include <map>
9 #include <new>
10 #include <set>
11 #include <string>
12 #include <utility>
13 #include <vector>
14 
15 #include "item.h"
16 #include "optional.h"
17 #include "translations.h"
18 #include "type_id.h"
19 
20 class player;
21 class read_only_visitable;
22 struct construction;
23 struct point;
24 
25 namespace catacurses
26 {
27 class window;
28 } // namespace catacurses
29 class JsonObject;
30 class nc_color;
31 struct tripoint;
32 
33 struct partial_con {
34     int counter = 0;
35     std::list<item> components = {};
36     construction_id id = construction_id( -1 );
37 };
38 
39 template <>
40 const construction &construction_id::obj() const;
41 template <>
42 bool construction_id::is_valid() const;
43 
44 struct construction {
45         // Construction type category
46         construction_category_id category;
47         // Which group does this construction belong to.
48         construction_group_str_id group;
49         // Additional note displayed along with construction requirements.
50         translation pre_note;
51         // Beginning terrain for construction
52         std::string pre_terrain;
53         // Final terrain after construction
54         std::string post_terrain;
55 
56         // Item group of byproducts created by the construction on success.
57         cata::optional<item_group_id> byproduct_item_group;
58 
59         // Flags beginning terrain must have
60         std::set<std::string> pre_flags;
61 
62         // Post construction flags
63         std::set<std::string> post_flags;
64 
65         /** Skill->skill level mapping. Can be empty. */
66         std::map<skill_id, int> required_skills;
67         // the requirements specified by "using"
68         std::vector<std::pair<requirement_id, int>> reqs_using;
69         requirement_id requirements;
70 
71         // Index in construction vector
72         construction_id id = construction_id( -1 );
73         construction_str_id str_id = construction_str_id::NULL_ID();
74 
75         // Time in moves
76         int time = 0;
77 
78         // If true, the requirements are generated during finalization
79         bool vehicle_start = false;
80 
81         // Custom constructibility check
82         std::function<bool( const tripoint & )> pre_special;
83         // Custom after-effects
84         std::function<void( const tripoint & )> post_special;
85         // Custom error message display
86         std::function<void( const tripoint & )> explain_failure;
87         // Whether it's furniture or terrain
88         bool pre_is_furniture = false;
89         // Whether it's furniture or terrain
90         bool post_is_furniture = false;
91 
92         // NPC assistance adjusted
93         int adjusted_time() const;
94         int print_time( const catacurses::window &w, const point &, int width, nc_color col ) const;
95         std::vector<std::string> get_folded_time_string( int width ) const;
96         // Result of construction scaling option
97         float time_scale() const;
98 
99         // make the construction available for selection
100         bool on_display = true;
101 
102         //can be build in the dark
103         bool dark_craftable = false;
104     private:
105         std::string get_time_string() const;
106 };
107 
108 const std::vector<construction> &get_constructions();
109 
110 //! Set all constructions to take the specified time.
111 void standardize_construction_times( int time );
112 
113 void load_construction( const JsonObject &jo );
114 void reset_constructions();
115 construction_id construction_menu( bool blueprint );
116 void complete_construction( player *p );
117 bool can_construct( const construction &con, const tripoint &p );
118 bool player_can_build( player &p, const read_only_visitable &inv, const construction &con );
119 void check_constructions();
120 void finalize_constructions();
121 
122 #endif // CATA_SRC_CONSTRUCTION_H
123