MCPcopy Create free account
hub / github.com/DFHack/dfhack / designateNew

Method designateNew

library/modules/Constructions.cpp:73–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71}
72
73bool Constructions::designateNew(df::coord pos, df::construction_type type,
74 df::item_type item, int mat_index)
75{
76 auto ttype = Maps::getTileType(pos);
77 if (!ttype || tileMaterial(*ttype) == tiletype_material::CONSTRUCTION)
78 return false;
79
80 auto current = Buildings::findAtTile(pos);
81 if (current)
82 {
83 auto cons = strict_virtual_cast<df::building_constructionst>(current);
84 if (!cons)
85 return false;
86
87 cons->type = type;
88 return true;
89 }
90
91 auto newinst = Buildings::allocInstance(pos, building_type::Construction);
92 if (!newinst)
93 return false;
94
95 auto newcons = strict_virtual_cast<df::building_constructionst>(newinst);
96 newcons->type = type;
97
98 df::job_item *filter = new df::job_item();
99 filter->item_type = item;
100 filter->mat_index = mat_index;
101 filter->flags2.bits.building_material = true;
102 if (mat_index < 0)
103 filter->flags2.bits.non_economic = true;
104
105 std::vector<df::job_item*> filters;
106 filters.push_back(filter);
107
108 if (!Buildings::constructWithFilters(newinst, filters))
109 {
110 delete newinst;
111 return false;
112 }
113
114 return true;
115}
116
117bool Constructions::designateRemove(df::coord pos, bool *immediate)
118{

Callers

nothing calls this directly

Calls 2

getTileTypeFunction · 0.85
tileMaterialFunction · 0.85

Tested by

no test coverage detected