Exemplo n.º 1
0
/**
 * @brief Load a weapon with ammo.
 * @param[in] weaponList Pointer to weapon to load.
 * @param[in] inv Pointer to inventory where the change happen.
 * @param[in] srcContainer Pointer to inventorydef where to search ammo.
 * @param[in] destContainer Pointer to inventorydef where the weapon is.
 */
bool INV_LoadWeapon (const invList_t *weaponList, inventory_t *inv, const invDef_t *srcContainer, const invDef_t *destContainer)
{
	invList_t *ic = NULL;
	const objDef_t *weapon;
	int x, y;

	assert(weaponList);

	weapon = weaponList->item.item;
	INVSH_GetFirstShapePosition(weaponList, &x, &y);
	x += weaponList->x;
	y += weaponList->y;
	if (weapon->oneshot) {
		ic = INVSH_SearchInInventory(inv, destContainer, x, y);
		if (ic) {
			ic->item.ammoLeft = weapon->ammo;
			ic->item.ammo = weapon;
			return true;
		}
	} else if (weapon->reload) {
		const itemFilterTypes_t equipType = INV_GetFilterFromItem(weapon);
		int i = 0;
		/* search an ammo */
		while (i < weapon->numAmmos && !ic) {
			const objDef_t *ammo = weapon->ammos[i];
			ic = INV_SearchInInventoryWithFilter(inv, srcContainer, ammo, equipType);
			i++;
		}
		if (ic) {
			return INV_MoveItem(inv, destContainer, x, y, srcContainer, ic, NULL);
		}
	}

	return false;
}
Exemplo n.º 2
0
/**
 * @brief Load a weapon with ammo.
 * @param[in] weaponList Pointer to weapon to load.
 * @param[in] inv Pointer to inventory where the change happen.
 * @param[in] srcContainer Pointer to inventorydef where to search ammo.
 * @param[in] destContainer Pointer to inventorydef where the weapon is.
 */
bool INV_LoadWeapon (const invList_t *weaponList, inventory_t *inv, const invDef_t *srcContainer, const invDef_t *destContainer)
{
	assert(weaponList);

	int x, y;
	weaponList->getFirstShapePosition(&x, &y);
	x += weaponList->getX();
	y += weaponList->getY();

	const objDef_t *weapon = weaponList->def();
	if (weapon->weapons[0]) {
		invList_t *ic = inv->getItemAtPos(destContainer, x, y);
		if (ic) {
			ic->setAmmoLeft(weapon->ammo);
			ic->setAmmoDef(weapon);
		}
	} else if (weapon->isReloadable()) {
		const itemFilterTypes_t equipType = INV_GetFilterFromItem(weapon);
		int i = 0;
		invList_t *ic = nullptr;
		/* search an ammo */
		while (i < weapon->numAmmos && !ic) {
			const objDef_t *ammo = weapon->ammos[i];
			ic = INV_SearchInInventoryWithFilter(inv, srcContainer, ammo, equipType);
			i++;
		}
		if (ic) {
			return INV_MoveItem(inv, destContainer, x, y, srcContainer, ic, nullptr);
		}
	}

	return false;
}
Exemplo n.º 3
0
/**
 * @brief Searches if there is an item at location (x/y) in a scrollable container. You can also provide an item to search for directly (x/y is ignored in that case).
 * @note x = x-th item in a row, y = row. i.e. x/y does not equal the "grid" coordinates as used in those containers.
 * @param[in] node Context node
 * @param[in] item Item requested
 * @param[in] filterType Filter used.
 * @todo Remove filter it is not a generic concept, and here it mean nothing
 * @return Item Pointer to the Item/item that is located at x/y or equals "item".
 * @sa Inventory::getItemAtPos
 */
static Item* UI_ContainerNodeGetExistingItem (const uiNode_t* node, const objDef_t* item, const itemFilterTypes_t filterType)
{
	return INV_SearchInInventoryWithFilter(ui_inventory, EXTRADATACONST(node).super.container, item, filterType);
}
Exemplo n.º 4
0
/**
 * @brief Searches if there is an item at location (x/y) in a scrollable container. You can also provide an item to search for directly (x/y is ignored in that case).
 * @note x = x-th item in a row, y = row. i.e. x/y does not equal the "grid" coordinates as used in those containers.
 * @param[in] container The container to get the item from
 * @param[in] item Item requested
 * @param[in] filterType Filter used.
 * @todo Remove filter it is not a generic concept, and here it mean nothing
 * @return invList_t Pointer to the invList_t/item that is located at x/y or equals "item".
 * @sa INVSH_SearchInInventory
 */
static invList_t *UI_ContainerNodeGetExistingItem (const invDef_t *container, const objDef_t *item, const itemFilterTypes_t filterType)
{
	return INV_SearchInInventoryWithFilter(ui_inventory, container, item, filterType);
}