示例#1
0
bool Fleet::removeItem(const std::string& ItemID, int numberOf)
{
    // First, count how many in total we have.
    int count = getNumberOfItems(ItemID);
    if (count < numberOf)
        return false;

    // Well, now that we know we have enough items to remove, let's set about doing it.
    for (auto it = ships.begin(); it != ships.end(); it++)
    {
        int num = it->second.getNumberOfItems(ItemID);
        if (num == 0)
            continue;
        if (num > numberOf)
        {
            it->second.removeItem(ItemID, numberOf);
            return true;
        }            
        else
        {
            it->second.removeItem(ItemID, num);
            numberOf -= num;
        }
    }
    return true;
}
示例#2
0
void HashTable<Type>::printHistogram() {
  cout << "\n\nHash Table Contains ";
  cout << getNumberOfItems() << " Items total\n";
  for (int i = 0; i < length; i++) {
    cout << i + 1 << ":\t";
    for (int j = 0; j < array[i].getSize(); j++) cout << " X";
    cout << "\n";
  }
}
示例#3
0
void
T64Archive::dumpDirectory()
{
    Archive::dumpDirectory();
    
    for (unsigned i = 0; i < getNumberOfItems(); i++) {
        fprintf(stderr, "  Item %2d:      %s (%d bytes, load address: %d)\n",
                i, getNameOfItem(i), getSizeOfItem(i), getDestinationAddrOfItem(i));
    }
}
void HashTable::printHistorgram() const{
	std::cout << "\n\nHash Table Contains ";
	std::cout << getNumberOfItems() << " Items total \n";

	for(int i=0; i < length; i++){
		std::cout << i + 1 << ":\t";
		for(int j=0; j < array[i].size(); j++){
			std::cout << " X";
		}
		std::cout << std::endl;
	}
}
示例#5
0
void
Archive::dumpDirectory()
{
    msg("Archive:           %s\n", getName());
    msg("-------\n");
    msg("  Path:            %s\n", getPath());
    msg("  Items:           %d\n", getNumberOfItems());

    for (unsigned i = 0; i < getNumberOfItems(); i++) {
        msg("  Item %2d:      %s (%d bytes, load address: %d)\n",
                i, getNameOfItem(i), getSizeOfItem(i), getDestinationAddrOfItem(i));
        msg("                 ");
        selectItem(i);
        for (unsigned j = 0; j < 8; j++) {
            int byte = getByte();
            if (byte != -1)
                msg("%02X ", byte);
        }
        msg("\n");
    }
}
示例#6
0
int
Archive::getSizeOfItem(int n)
{
    int size = 0;

    if (n < getNumberOfItems()) {
        
        selectItem(n);
        while (getByte() != EOF)
            size++;
        }

    return size;
}
示例#7
0
	void BonusController::onTimeGoesBy( double timeUnits )
	{
		for( int i=0; i<getNumberOfItems(); i++ )
		{
			bonuses[i]->timeToLive -= (long)timeUnits;
			if( bonuses[i]->timeToLive < 0 )
			{
				//System::Diagnostics::Trace::WriteLine("XXXXXX unspawn3=" + getNumberOfItems() );

				bonuses.removeAt(i);
				i--;
				//System::Diagnostics::Trace::WriteLine("XXXXXX unspawn4=" + getNumberOfItems() );

			}
		}
	}
示例#8
0
void 
T64Archive::selectItem(int n)
{
	unsigned i;
    
    if (n < getNumberOfItems()) {

        // Compute start address in container
        i = 0x48 + (n * 0x20);
        if ((fp = LO_LO_HI_HI(data[i], data[i+1], data[i+2], data[i+3])) >= size)
            fprintf(stderr, "PANIC! fp is out of bounds!\n");

        // Compute start address in memory
        i = 0x42 + (n * 0x20);
        uint16_t startAddrInMemory = LO_HI(data[i], data[i+1]);
        
        // Compute end address in memory
        i = 0x44 + (n * 0x20);
        uint16_t endAddrInMemory = LO_HI(data[i], data[i+1]);

        if (endAddrInMemory == 0xC3C6) {
            fprintf(stderr, "WARNING: Corrupted archive. Mostly likely created with CONV64!\n");
            // WHAT DO WE DO ABOUT IT?
        }

        // Compute size of item
        uint16_t length = endAddrInMemory - startAddrInMemory;

        // fprintf(stderr, "start = %d end = %d diff = %d\n", startAddrInMemory, endAddrInMemory, length);
        // fprintf(stderr, "fp = %d fp_eof = %d\n", fp, fp_eof);

        // Store largest offset that belongs to the file
        if ((fp_eof = fp + length) > size)
            fprintf(stderr, "PANIC! fp_eof is out of bounds!\n");
        
        // Return if offset values are safe
        if (fp < size && fp_eof <= size)
            return; // success
    }

    fp = fp_eof = -1; // fail
	return;
}
示例#9
0
int 
Archive::getItemWithName(char *pattern)
{
	int i, j, length, pattern_length, no_of_items = getNumberOfItems();
	const char *name;
	
	assert(pattern != NULL);
	pattern_length = strlen(pattern);
	
	// Iterate through all directory items
	for (i = 0; i < no_of_items; i++) {
	
		name   = getNameOfItem(i);
		length = strlen(name);
		
		// Pattern can't match if it has more characters
		if (length < pattern_length) {
			continue;
		}
		
		// Iterate through all characters of the search pattern
		for (j = 0; j < pattern_length; j++) {

			// '*' matches everything
			if (pattern[j] == '*')
				return i;
			
			// '?' matches an arbitrary character
			if (pattern[j] == '?') 
				continue;
			
			if (pattern[j] != name[j])
				break;
		}
		
		if (j == length) {
			return i;
		}
	}
	
	return -1;
}
示例#10
0
	void setList ( struct generic_node *list )
	{
		element = list;
		getNumberOfItems();
	}