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

Function getEdgeCost

plugins/diggingInvaders/edgeCost.cpp:55–319  ·  view source on GitHub ↗

limitations ramps cave-ins */

Source from the content-addressed store, hash-verified

53 cave-ins
54*/
55cost_t getEdgeCost(color_ostream& out, df::coord pt1, df::coord pt2, DigAbilities& abilities) {
56 int32_t dx = pt2.x - pt1.x;
57 int32_t dy = pt2.y - pt1.y;
58 int32_t dz = pt2.z - pt1.z;
59 cost_t cost = abilities.costWeight[CostDimension::Walk];
60 if ( cost < 0 )
61 return -1;
62
63 if ( Maps::getTileBlock(pt1) == NULL || Maps::getTileBlock(pt2) == NULL )
64 return -1;
65
66 df::tiletype* type2 = Maps::getTileType(pt2);
67 df::tiletype_shape shape2 = ENUM_ATTR(tiletype, shape, *type2);
68
69 if ( Maps::getTileBlock(pt1)->designation[pt1.x&0xF][pt1.y&0xF].bits.flow_size >= 4 )
70 return -1;
71 if ( Maps::getTileBlock(pt2)->designation[pt2.x&0xF][pt2.y&0xF].bits.flow_size >= 4 )
72 return -1;
73
74 if ( shape2 == df::enums::tiletype_shape::EMPTY ) {
75 return -1;
76 }
77
78 if ( shape2 == df::enums::tiletype_shape::BRANCH ||
79 shape2 == df::enums::tiletype_shape::TRUNK_BRANCH ||
80 shape2 == df::enums::tiletype_shape::TWIG )
81 return -1;
82
83/*
84 if () {
85 df::map_block* temp = Maps::getTileBlock(df::coord(pt1.x,pt1.y,pt1.z-1));
86 if ( temp && temp->designation[pt1.x&0xF][pt1.y&0xF]
87 }
88*/
89
90 if ( Maps::canStepBetween(pt1, pt2) ) {
91 return cost;
92 }
93
94 df::building* building2 = Buildings::findAtTile(pt2);
95 if ( building2 ) {
96 if ( abilities.costWeight[CostDimension::DestroyBuilding] < 0 )
97 return -1;
98 cost += abilities.costWeight[CostDimension::DestroyBuilding];
99 if ( dx*dx + dy*dy > 1 )
100 return -1;
101 }
102
103 bool construction2 = ENUM_ATTR(tiletype, material, *type2) == df::enums::tiletype_material::CONSTRUCTION;
104 if ( construction2 ) {
105 //smooth or not?
106 df::construction* constr = df::construction::find(pt2);
107 bool smooth = constr != NULL && constr->item_type != df::enums::item_type::BOULDER;
108 if ( smooth ) {
109 if ( abilities.costWeight[CostDimension::DestroySmoothConstruction] < 0 )
110 return -1;
111 cost += abilities.costWeight[CostDimension::DestroySmoothConstruction];
112 } else {

Callers 3

diggingInvadersCommandFunction · 0.85
findAndAssignInvasionJobFunction · 0.85
getEdgeSetFunction · 0.85

Calls 4

getTileBlockFunction · 0.85
getTileTypeFunction · 0.85
getTypeMethod · 0.80
findFunction · 0.50

Tested by

no test coverage detected