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

Method makeProjectile

library/modules/Items.cpp:1065–1106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1063}
1064
1065df::proj_itemst *Items::makeProjectile(df::item *item)
1066{ using df::global::proj_next_id;
1067 CHECK_NULL_POINTER(item);
1068 if (!world || !proj_next_id)
1069 return NULL;
1070
1071 auto pos = getPosition(item);
1072 if (!pos.isValid())
1073 return NULL;
1074
1075 auto ref = df::allocate<df::general_ref_projectile>();
1076 if (!ref)
1077 return NULL;
1078
1079 auto proj = df::allocate<df::proj_itemst>();
1080 if (!proj) {
1081 delete ref;
1082 return NULL;
1083 }
1084 else if (!detachItem(item)) {
1085 delete ref;
1086 delete proj;
1087 return NULL;
1088 }
1089
1090 item->pos = pos;
1091 item->flags.bits.in_job = true;
1092
1093 proj->link = new df::proj_list_link();
1094 proj->link->item = proj;
1095 proj->id = (*proj_next_id)++;
1096
1097 proj->origin_pos = proj->target_pos = pos;
1098 proj->cur_pos = proj->prev_pos = pos;
1099 proj->item = item;
1100
1101 ref->projectile_id = proj->id;
1102 item->general_refs.push_back(ref);
1103
1104 linked_list_append(&world->projectiles.all, proj->link);
1105 return proj;
1106}
1107
1108int Items::getItemBaseValue(int16_t item_type, int16_t item_subtype,
1109 int16_t mat_type, int32_t mat_subtype)

Callers

nothing calls this directly

Calls 3

detachItemFunction · 0.85
linked_list_appendFunction · 0.85
isValidMethod · 0.45

Tested by

no test coverage detected