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

Function setAmmoItem

plugins/siege-engine.cpp:586–621  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

584}
585
586static int setAmmoItem(lua_State *L)
587{
588 if (!enable_plugin())
589 return 0;
590
591 auto engine = find_engine(L, 1, true);
592 auto item_type = (df::item_type)luaL_optint(L, 2, item_type::BOULDER);
593 if (!is_valid_enum_item(item_type))
594 luaL_argerror(L, 2, "invalid item type");
595
596 auto key = stl_sprintf("siege-engine/ammo/%d", engine->id);
597 auto entry = World::GetPersistentData(key, NULL);
598 if (!entry.isValid())
599 return 0;
600
601 engine->ammo_vector_id = job_item_vector_id::IN_PLAY;
602 engine->ammo_item_type = item_type;
603
604 FOR_ENUM_ITEMS(job_item_vector_id, id)
605 {
606 auto other = ENUM_ATTR(job_item_vector_id, other, id);
607 auto type = ENUM_ATTR(items_other_id, item, other);
608 if (type == item_type)
609 {
610 engine->ammo_vector_id = id;
611 break;
612 }
613 }
614
615 entry.ival(0) = engine->id;
616 entry.ival(1) = engine->ammo_vector_id;
617 entry.ival(2) = engine->ammo_item_type;
618
619 lua_pushboolean(L, true);
620 return 1;
621}
622
623static void forgetStockpileLink(EngineInfo *engine, int pile_id)
624{

Callers

nothing calls this directly

Calls 8

find_engineFunction · 0.85
is_valid_enum_itemFunction · 0.85
luaL_argerrorFunction · 0.85
stl_sprintfFunction · 0.85
lua_pushbooleanFunction · 0.85
ivalMethod · 0.80
enable_pluginFunction · 0.70
isValidMethod · 0.45

Tested by

no test coverage detected