Example #1
0
void useInventoryItem()
{
	int index;
	Entity *temp;

	if (inventory.item[inventory.selectedIndex].inUse == TRUE && inventory.item[inventory.selectedIndex].activate != NULL)
	{
		temp = self;

		index = inventory.selectedIndex;

		self = &inventory.item[inventory.selectedIndex];

		self->activate(0);

		if (inventory.item[inventory.selectedIndex].inUse == FALSE)
		{
			sortInventory();

			if (index == inventory.cursorIndex)
			{
				inventory.cursorIndex = inventory.selectedIndex;
			}
		}

		self = temp;
	}
}
Example #2
0
int removeInventoryItemByObjectiveName(char *name)
{
	int i, found;
	Entity *e;

	found = FALSE;

	for (i=0;i<MAX_INVENTORY_ITEMS;i++)
	{
		if (inventory.item[i].inUse == TRUE && strcmpignorecase(inventory.item[i].objectiveName, name) == 0)
		{
			if (inventory.item[i].flags & STACKABLE)
			{
				inventory.item[i].health--;

				if (inventory.item[i].health <= 0)
				{
					inventory.item[i].inUse = FALSE;
				}
			}

			else
			{
				inventory.item[i].inUse = FALSE;

				if (strcmpignorecase(playerWeapon.name, inventory.item[i].name) == 0)
				{
					e = removePlayerWeapon();

					e->inUse = FALSE;
				}

				else if (strcmpignorecase(playerShield.name, inventory.item[i].name) == 0)
				{
					e = removePlayerShield();

					e->inUse = FALSE;
				}
			}

			found = TRUE;

			break;
		}
	}

	if (found == TRUE)
	{
		sortInventory();
	}

	return found;
}
int main(void){
  addBook("Algorithms in C",1998,"Matthews",3);
  addBook("C",1978,"Smith",2);
  addBook("C",1988,"Jacob",4);
  addBook("Algorithms",1990,"Cohen",1);
  addBook("Art of Computer Programming",1978,"Burger",2);
  addBook("Fortran", 1965,"Moran",3);
  addBook("The Practice of Programming", 1999,"Andrews", 4);
  printf("Inventory\n ");
  /* Print unsorted inventory */
  show();
  sortInventory();
  /* Records in Inventory are rearranged!
     Print the sorted inventory
  */
  printf("\nInventory in sorted order: \n");
  show();
  return 1;
}
Example #4
0
Entity *removeInventoryItemAtCursor()
{
	sortInventory();

	return (inventory.item[inventory.selectedIndex].inUse == TRUE ? &inventory.item[inventory.selectedIndex] : NULL);
}