Exemple #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;
}
/**
 * @brief Update the GUI with the selected item
 */
static void INV_UpdateObject_f (void)
{
    /* check syntax */
    if (Cmd_Argc() < 3) {
        Com_Printf("Usage: %s <objectid> <confunc> [mustwechangetab]\n", Cmd_Argv(0));
        return;
    }

    bool changeTab = true;
    if (Cmd_Argc() == 4)
        changeTab = atoi(Cmd_Argv(3)) >= 1;

    const int num = atoi(Cmd_Argv(1));
    if (num < 0 || num >= csi.numODs) {
        Com_Printf("Id %i out of range 0..%i\n", num, csi.numODs);
        return;
    }
    const objDef_t* obj = INVSH_GetItemByIDX(num);

    /* update tab */
    if (changeTab) {
        const cvar_t* var = Cvar_FindVar("mn_equiptype");
        const int filter = INV_GetFilterFromItem(obj);
        if (var && var->integer != filter) {
            Cvar_SetValue("mn_equiptype", filter);
            UI_ExecuteConfunc("%s", Cmd_Argv(2));
        }
    }

    /* update item description */
    INV_ItemDescription(obj);
}
Exemple #3
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;
}