Exemplo n.º 1
0
static void testItemMove (void)
{
	Inventory inv;
	const objDef_t* od;
	const invDef_t* container, *containerTo;
	Item* addedItem;

	ResetInventoryList();

	od = INVSH_GetItemByIDSilent("assault");
	CU_ASSERT_PTR_NOT_NULL(od);

	container = INVSH_GetInventoryDefinitionByID("right");
	CU_ASSERT_PTR_NOT_NULL(container);

	Item item(od);

	CU_ASSERT(inv.containsItem(container->id, &item) == false);

	addedItem = i.addToInventory(&inv, &item, container, NONE, NONE, 1);
	CU_ASSERT_PTR_NOT_NULL(addedItem);

	CU_ASSERT(inv.containsItem(container->id, &item) == true);

	containerTo = INVSH_GetInventoryDefinitionByID("backpack");
	CU_ASSERT_PTR_NOT_NULL(containerTo);

	CU_ASSERT_EQUAL(IA_MOVE, i.moveInInventory(&inv, container, addedItem, containerTo, NONE, NONE, nullptr, nullptr));

	CU_ASSERT(inv.containsItem(container->id, &item) == false);
	CU_ASSERT(inv.containsItem(containerTo->id, &item) == true);
}
Exemplo n.º 2
0
static void testItemMassActions (void)
{
	ResetInventoryList();

	const objDef_t* od = INVSH_GetItemByIDSilent("assault");
	CU_ASSERT_PTR_NOT_NULL_FATAL(od);

	const invDef_t* container = INVSH_GetInventoryDefinitionByID("right");
	CU_ASSERT_PTR_NOT_NULL_FATAL(container);

	Inventory inv;
	bool addedItem = testAddSingle(&inv, od, container);
	CU_ASSERT(addedItem == true);

	/* second try should fail as the right container is a single container */
	addedItem = testAddSingle(&inv, od, container);
	CU_ASSERT(addedItem == false);

	container = INVSH_GetInventoryDefinitionByID("left");
	CU_ASSERT_PTR_NOT_NULL_FATAL(container);

	od = INVSH_GetItemByIDSilent("fraggrenade");
	CU_ASSERT_PTR_NOT_NULL_FATAL(od);

	addedItem = testAddSingle(&inv, od, container);
	CU_ASSERT(addedItem == true);

	container = INVSH_GetInventoryDefinitionByID("equip");
	CU_ASSERT_PTR_NOT_NULL_FATAL(container);

	for (int i = 0; i < csi.numODs; i++) {
		od = INVSH_GetItemByIDX(i);
		/* every item should be placable on the ground container and there should really be enough space */
		addedItem = testAddSingle(&inv, od, container);
		CU_ASSERT(addedItem == true);
		addedItem = testAddSingle(&inv, od, container);
		CU_ASSERT(addedItem == true);
		addedItem = testAddSingle(&inv, od, container);
		CU_ASSERT(addedItem == true);
		for (int j = 0; j < od->numAmmos; j++) {
			addedItem = testAddSingle(&inv, od->ammos[j], container);
			CU_ASSERT(addedItem == true);
			addedItem = testAddSingle(&inv, od->ammos[j], container);
			CU_ASSERT(addedItem == true);
			addedItem = testAddSingle(&inv, od->ammos[j], container);
			CU_ASSERT(addedItem == true);
			addedItem = testAddSingle(&inv, od->ammos[j], container);
			CU_ASSERT(addedItem == true);
			addedItem = testAddSingle(&inv, od->ammos[j], container);
			CU_ASSERT(addedItem == true);
			addedItem = testAddSingle(&inv, od->ammos[j], container);
			CU_ASSERT(addedItem == true);
		}
	}
}
Exemplo n.º 3
0
static void testItemAdd (void)
{
	inventory_t inv;
	const objDef_t *od;
	item_t item;
	const invDef_t *container;

	ResetInventoryList();

	OBJZERO(inv);

	od = INVSH_GetItemByIDSilent("assault");
	CU_ASSERT_PTR_NOT_NULL(od);

	container = INVSH_GetInventoryDefinitionByID("right");
	CU_ASSERT_PTR_NOT_NULL(container);

	item.t = od;
	item.m = NULL;
	item.a = 0;

	CU_ASSERT(INVSH_ExistsInInventory(&inv, container, &item) == false);

	CU_ASSERT_PTR_NOT_NULL(i.AddToInventory(&i, &inv, &item, container, NONE, NONE, 1));

	CU_ASSERT(INVSH_ExistsInInventory(&inv, container, &item) == true);
}
Exemplo n.º 4
0
static void testItemToHeadgear (void)
{
	inventory_t inv;
	const objDef_t *od;
	const invDef_t *container;
	item_t item;

	ResetInventoryList();

	OBJZERO(inv);

	od = INVSH_GetItemByIDSilent("irgoggles");
	CU_ASSERT_PTR_NOT_NULL_FATAL(od);

	container = INVSH_GetInventoryDefinitionByID("headgear");
	CU_ASSERT_PTR_NOT_NULL_FATAL(container);

	item.t = od;
	item.m = NULL;
	item.a = 0;

	CU_ASSERT_FALSE(INVSH_ExistsInInventory(&inv, container, &item));

	CU_ASSERT_PTR_NOT_NULL(i.AddToInventory(&i, &inv, &item, container, NONE, NONE, 1));

	CU_ASSERT_TRUE(INVSH_ExistsInInventory(&inv, container, &item));

	CU_ASSERT_PTR_NULL(i.AddToInventory(&i, &inv, &item, container, NONE, NONE, 1));
}
Exemplo n.º 5
0
static void testItemDel (void)
{
	Inventory inv;
	const objDef_t* od;
	const invDef_t* container;
	Item* addedItem;

	ResetInventoryList();

	od = INVSH_GetItemByIDSilent("assault");
	CU_ASSERT_PTR_NOT_NULL(od);

	container = INVSH_GetInventoryDefinitionByID("right");
	CU_ASSERT_PTR_NOT_NULL(container);

	Item item(od);

	CU_ASSERT(inv.containsItem(container->id, &item) == false);

	addedItem = i.addToInventory(&inv, &item, container, NONE, NONE, 1);

	CU_ASSERT(inv.containsItem(container->id, &item) == true);

	CU_ASSERT(i.removeFromInventory(&inv, container, addedItem));

	CU_ASSERT(inv.containsItem(container->id, &item) == false);
}
Exemplo n.º 6
0
static void testItemMove (void)
{
	inventory_t inv;
	const objDef_t *od;
	item_t item;
	const invDef_t *container, *containerTo;
	invList_t *addedItem;

	ResetInventoryList();

	OBJZERO(inv);
	OBJZERO(item);

	od = INVSH_GetItemByIDSilent("assault");
	CU_ASSERT_PTR_NOT_NULL(od);

	container = INVSH_GetInventoryDefinitionByID("right");
	CU_ASSERT_PTR_NOT_NULL(container);

	item.t = od;
	item.m = NULL;
	item.a = 0;

	CU_ASSERT(INVSH_ExistsInInventory(&inv, container, &item) == false);

	addedItem = i.AddToInventory(&i, &inv, &item, container, NONE, NONE, 1);
	CU_ASSERT_PTR_NOT_NULL(addedItem);

	CU_ASSERT(INVSH_ExistsInInventory(&inv, container, &item) == true);

	containerTo = INVSH_GetInventoryDefinitionByID("backpack");
	CU_ASSERT_PTR_NOT_NULL(containerTo);

	CU_ASSERT_EQUAL(IA_MOVE, i.MoveInInventory(&i, &inv, container, addedItem, containerTo, NONE, NONE, NULL, NULL));

	CU_ASSERT(INVSH_ExistsInInventory(&inv, container, &item) == false);
	CU_ASSERT(INVSH_ExistsInInventory(&inv, containerTo, &item) == true);
}
Exemplo n.º 7
0
/**
 * @brief Calculates the size of a container node and links the container
 * into the node (uses the @c invDef_t shape bitmask to determine the size)
 * @param[in,out] node The node to get the size for
 */
void uiContainerNode::onLoaded (uiNode_t* const node)
{
	const char *name;
	const invDef_t *container;

	/** @todo find a better way to add more equip node, without this hack */
	name = node->name;
	if (Q_strstart(node->name, "equip_"))
		name = "equip";

	container = INVSH_GetInventoryDefinitionByID(name);
	if (container == NULL)
		return;

	EXTRADATA(node).container = container;

	if (UI_IsScrollContainerNode(node)) {
		/* No need to compute the size, the script provide it */
	} else {
		int i, j;
		/* Start on the last bit of the shape mask. */
		for (i = SHAPE_BIG_MAX_WIDTH - 1; i >= 0; i--) {
			for (j = 0; j < SHAPE_BIG_MAX_HEIGHT; j++)
				if (container->shape[j] & (1 << i))
					break;
			if (j < SHAPE_BIG_MAX_HEIGHT)
				break;
		}
		node->box.size[0] = C_UNIT * (i + 1) + 0.01;

		/* start on the lower row of the shape mask */
		for (i = SHAPE_BIG_MAX_HEIGHT - 1; i >= 0; i--)
			if (container->shape[i] & ~0x0)
				break;
		node->box.size[1] = C_UNIT * (i + 1) + 0.01;
	}
}
Exemplo n.º 8
0
static void testItemToHeadgear (void)
{
	Inventory inv;
	const objDef_t* od;
	const invDef_t* container;

	ResetInventoryList();

	od = INVSH_GetItemByIDSilent("irgoggles");
	CU_ASSERT_PTR_NOT_NULL_FATAL(od);

	container = INVSH_GetInventoryDefinitionByID("headgear");
	CU_ASSERT_PTR_NOT_NULL_FATAL(container);

	Item item(od);

	CU_ASSERT_FALSE(inv.containsItem(container->id, &item));

	CU_ASSERT_PTR_NOT_NULL(i.addToInventory(&inv, &item, container, NONE, NONE, 1));

	CU_ASSERT_TRUE(inv.containsItem(container->id, &item));

	CU_ASSERT_PTR_NULL(i.addToInventory(&inv, &item, container, NONE, NONE, 1));
}
Exemplo n.º 9
0
/**
 * @brief Calculates the size of a container node and links the container
 * into the node (uses the @c invDef_t shape bitmask to determine the size)
 * @param[in,out] node The node to get the size for
 */
void uiBaseInventoryNode::onLoaded (uiNode_t* const node)
{
	EXTRADATA(node).super.container = INVSH_GetInventoryDefinitionByID("equip");
}
Exemplo n.º 10
0
static void testItemReload (void)
{
	inventory_t inv;
	const objDef_t *od, *ad;
	item_t item, ammo, ammoFrom;
	const invDef_t *container, *containerFrom;
	invList_t *addedItem;

	ResetInventoryList();

	OBJZERO(inv);

	od = INVSH_GetItemByIDSilent("rpg");
	CU_ASSERT_PTR_NOT_NULL(od);

	container = INVSH_GetInventoryDefinitionByID("right");
	CU_ASSERT_PTR_NOT_NULL(container);

	item.t = od;
	item.m = NULL;
	item.a = 0;

	CU_ASSERT(INVSH_ExistsInInventory(&inv, container, &item) == false);

	addedItem = i.AddToInventory(&i, &inv, &item, container, NONE, NONE, 1);
	CU_ASSERT_PTR_NOT_NULL(addedItem);

	CU_ASSERT(INVSH_ExistsInInventory(&inv, container, &item) == true);

	ad = INVSH_GetItemByIDSilent("rpg_ammo");
	CU_ASSERT_PTR_NOT_NULL(ad);

	ammo.t = ad;
	ammo.m = NULL;
	ammo.a = 0;

	containerFrom = INVSH_GetInventoryDefinitionByID("backpack");
	CU_ASSERT_PTR_NOT_NULL(containerFrom);

	CU_ASSERT(INVSH_ExistsInInventory(&inv, containerFrom, &ammo) == false);

	addedItem = i.AddToInventory(&i, &inv, &ammo, containerFrom, NONE, NONE, 1);
	CU_ASSERT_PTR_NOT_NULL(addedItem);

	CU_ASSERT(INVSH_ExistsInInventory(&inv, containerFrom, &ammo) == true);

	CU_ASSERT_EQUAL(IA_RELOAD, i.MoveInInventory(&i, &inv, containerFrom, addedItem, container, NONE, NONE, NULL, NULL));

	CU_ASSERT(INVSH_ExistsInInventory(&inv, containerFrom, &ammo) == false);

	item.m = ad;
	item.a = 1;

	CU_ASSERT(INVSH_ExistsInInventory(&inv, container, &item) == true);

	ad = INVSH_GetItemByIDSilent("rpg_incendiary_ammo");
	CU_ASSERT_PTR_NOT_NULL(ad);

	ammoFrom.t = ad;
	ammoFrom.m = NULL;
	ammoFrom.a = 0;

	CU_ASSERT(INVSH_ExistsInInventory(&inv, containerFrom, &ammoFrom) == false);

	addedItem = i.AddToInventory(&i, &inv, &ammoFrom, containerFrom, NONE, NONE, 1);
	CU_ASSERT_PTR_NOT_NULL(addedItem);

	CU_ASSERT(INVSH_ExistsInInventory(&inv, containerFrom, &ammoFrom) == true);

	CU_ASSERT_EQUAL(IA_RELOAD_SWAP, i.MoveInInventory(&i, &inv, containerFrom, addedItem, container, NONE, NONE, NULL, NULL));

	CU_ASSERT(INVSH_ExistsInInventory(&inv, containerFrom, &ammoFrom) == false);
	CU_ASSERT(INVSH_ExistsInInventory(&inv, containerFrom, &ammo) == true);

	item.m = ad;

	CU_ASSERT(INVSH_ExistsInInventory(&inv, container, &item) == true);
}
Exemplo n.º 11
0
static void testItemReload (void)
{
	Inventory inv;
	const objDef_t* od, *ad;
	const invDef_t* container, *containerFrom;
	Item* addedItem;

	ResetInventoryList();

	od = INVSH_GetItemByIDSilent("rpg");
	CU_ASSERT_PTR_NOT_NULL(od);

	container = INVSH_GetInventoryDefinitionByID("right");
	CU_ASSERT_PTR_NOT_NULL(container);

	Item item(od);

	CU_ASSERT(inv.containsItem(container->id, &item) == false);

	addedItem = i.addToInventory(&inv, &item, container, NONE, NONE, 1);
	CU_ASSERT_PTR_NOT_NULL(addedItem);

	CU_ASSERT(inv.containsItem(container->id, &item) == true);

	ad = INVSH_GetItemByIDSilent("rpg_ammo");
	CU_ASSERT_PTR_NOT_NULL(ad);

	Item ammo(ad);

	containerFrom = INVSH_GetInventoryDefinitionByID("backpack");
	CU_ASSERT_PTR_NOT_NULL(containerFrom);

	CU_ASSERT(inv.containsItem(containerFrom->id, &ammo) == false);

	addedItem = i.addToInventory(&inv, &ammo, containerFrom, NONE, NONE, 1);
	CU_ASSERT_PTR_NOT_NULL(addedItem);

	CU_ASSERT(inv.containsItem(containerFrom->id, &ammo) == true);

	CU_ASSERT_EQUAL(IA_RELOAD, i.moveInInventory(&inv, containerFrom, addedItem, container, NONE, NONE, nullptr, nullptr));

	CU_ASSERT(inv.containsItem(containerFrom->id, &ammo) == false);

	item.setAmmoDef(ad);
	item.setAmmoLeft(1);

	CU_ASSERT(inv.containsItem(container->id, &item) == true);

	ad = INVSH_GetItemByIDSilent("rpg_incendiary_ammo");
	CU_ASSERT_PTR_NOT_NULL(ad);

	Item ammoFrom(ad);

	CU_ASSERT(inv.containsItem(containerFrom->id, &ammoFrom) == false);

	addedItem = i.addToInventory(&inv, &ammoFrom, containerFrom, NONE, NONE, 1);
	CU_ASSERT_PTR_NOT_NULL(addedItem);

	CU_ASSERT(inv.containsItem(containerFrom->id, &ammoFrom) == true);

	CU_ASSERT_EQUAL(IA_RELOAD_SWAP, i.moveInInventory(&inv, containerFrom, addedItem, container, NONE, NONE, nullptr, nullptr));

	CU_ASSERT(inv.containsItem(containerFrom->id, &ammoFrom) == false);
	CU_ASSERT(inv.containsItem(containerFrom->id, &ammo) == true);

	item.setAmmoDef(ad);

	CU_ASSERT(inv.containsItem(container->id, &item) == true);
}