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

Function find_engine

plugins/siege-engine.cpp:366–408  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

364static std::map<df::coord, df::building*> coord_engines;
365
366static EngineInfo *find_engine(df::building *bld, bool create = false)
367{
368 auto ebld = strict_virtual_cast<df::building_siegeenginest>(bld);
369 if (!ebld)
370 return NULL;
371
372 auto &obj = engines[bld];
373
374 if (obj)
375 {
376 obj->bld = ebld;
377 return obj;
378 }
379
380 if (!create || !is_build_complete(bld))
381 return NULL;
382
383 obj = new EngineInfo();
384
385 obj->id = bld->id;
386 obj->bld = ebld;
387 obj->center = df::coord(bld->centerx, bld->centery, bld->z);
388 obj->building_rect = coord_range(
389 df::coord(bld->x1, bld->y1, bld->z),
390 df::coord(bld->x2, bld->y2, bld->z)
391 );
392 obj->quality = average_quality(ebld);
393 obj->is_catapult = (ebld->type == siegeengine_type::Catapult);
394 obj->proj_speed = 2;
395 obj->hit_delay = obj->is_catapult ? 2 : -1;
396 obj->fire_range = get_engine_range(ebld, obj->quality);
397
398 // Base coefficients per engine type, plus 6% exponential bonus per quality level
399 obj->sigma_coeff = (obj->is_catapult ? 30.0 : 48.0) * pow(1.06f, obj->quality);
400
401 obj->ammo_vector_id = job_item_vector_id::BOULDER;
402 obj->ammo_item_type = item_type::BOULDER;
403
404 obj->operator_id = obj->operator_frame = -1;
405
406 coord_engines[obj->center] = bld;
407 return obj;
408}
409
410static EngineInfo *find_engine(lua_State *L, int idx, bool create = false, bool silent = false)
411{

Callers 15

load_enginesFunction · 0.85
getTargetAreaFunction · 0.85
clearTargetAreaFunction · 0.85
setTargetAreaFunction · 0.85
getAmmoItemFunction · 0.85
setAmmoItemFunction · 0.85
getStockpileLinksFunction · 0.85
isLinkedToPileFunction · 0.85
addStockpileLinkFunction · 0.85
removeStockpileLinkFunction · 0.85
saveWorkshopProfileFunction · 0.85
getOperatorUnitFunction · 0.85

Calls 5

is_build_completeFunction · 0.85
average_qualityFunction · 0.85
get_engine_rangeFunction · 0.85
luaL_errorFunction · 0.85
findFunction · 0.50

Tested by

no test coverage detected