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

Method UnitPath

plugins/siege-engine.cpp:1192–1240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1190 };
1191
1192 UnitPath(df::unit *unit) : unit(unit)
1193 {
1194 if (unit->flags1.bits.rider)
1195 {
1196 auto mount = df::unit::find(unit->relationship_ids[df::unit_relationship_type::RiderMount]);
1197
1198 if (mount)
1199 {
1200 path = get(mount)->path;
1201 return;
1202 }
1203 }
1204
1205 df::coord pos = unit->pos;
1206 df::coord dest = unit->path.dest;
1207 auto &upath = unit->path.path;
1208
1209 if (dest.isValid() && !upath.x.empty())
1210 {
1211 float time = unit->counters.job_counter+0.5f;
1212 float speed = Units::computeMovementSpeed(unit)/100.0f;
1213 float slowdown = Units::computeSlowdownFactor(unit);
1214
1215 if (unit->counters.unconscious > 0)
1216 time += unit->counters.unconscious;
1217
1218 for (size_t i = 0; i < upath.size(); i++)
1219 {
1220 df::coord new_pos = upath[i];
1221 if (new_pos == pos)
1222 continue;
1223
1224 float delay = speed;
1225
1226 // Diagonal movement
1227 if (new_pos.x != pos.x && new_pos.y != pos.y)
1228 delay *= 362.0/256.0;
1229
1230 // Meandering slowdown
1231 delay += (slowdown - 1) * speed;
1232
1233 path[time] = pos;
1234 pos = new_pos;
1235 time += delay + 1;
1236 }
1237 }
1238
1239 path[MAX_TIME] = pos;
1240 }
1241
1242 void get_margin(std::map<float,df::coord>::iterator &it, float time, float *lmargin, float *rmargin)
1243 {

Callers

nothing calls this directly

Calls 5

getFunction · 0.70
findFunction · 0.50
isValidMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected