- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
private void spreadBullets() {
bulletItemsWip.clear();
for (AbstractInventoryItem item : inventoryItemsSortedByValue) {
if (item instanceof RangeBulletItem) {
bulletItemsWip.add((RangeBulletItem) item);
}
}
rangeUnitsQueueWip.clear();
for (Unit unit : areaObject.getUnits()) {
if (unit.getSpecialization().equals(Unit.UnitSpecialization.RANGE)) {
rangeUnitsQueueWip.add(unit);
}
}
while (rangeUnitsQueueWip.size > 0 && bulletItemsWip.size > 0) {
Iterator<Unit> unitsIterator = rangeUnitsQueueWip.iterator();
while (unitsIterator.hasNext()) {
// find suitable bullets or remove unit from queue
Unit rangeUnit = unitsIterator.next();
RangeBulletItem foundBulletItemInInventoryForUnit = searchBulletFor(rangeUnit);
if (foundBulletItemInInventoryForUnit == null) {
// remove unit from bullets queue
unitsIterator.remove();
} else {
// bullet was found
RangeBulletItem unitBulletsItem = rangeUnit.getEquipment().getRangeBulletsItem();
if (unitBulletsItem == null) {
unitBulletsItem = foundBulletItemInInventoryForUnit.split(1);
rangeUnit.getEquipment().setRangeBulletsItem(unitBulletsItem);
} else {
if (unitBulletsItem.getClass().equals(foundBulletItemInInventoryForUnit.getClass())){
if (!unitBulletsItem.isFull()) {
foundBulletItemInInventoryForUnit.moveQuantity(1, unitBulletsItem);
}
} else {
rangeUnit.getEquipment().dropRangeBullets();
unitBulletsItem = foundBulletItemInInventoryForUnit.split(1);
rangeUnit.getEquipment().setRangeBulletsItem(unitBulletsItem);
}
}
if (foundBulletItemInInventoryForUnit.isEmpty()) {
// remove item from inventory
bulletItemsWip.removeValue(foundBulletItemInInventoryForUnit, true);
remove(foundBulletItemInInventoryForUnit);
}
if (unitBulletsItem.isFull()) {
// remove unit from bullets queue
unitsIterator.remove();
}
if (bulletItemsWip.size == 0) {
// stop spreading
break;
}
}
}
}
// sync quantities to inventory
for (AbstractInventoryItem item : bulletItemsWip) {
getItem(item.getClass()).setQuantity(item.getQuantity());
}
}
pushistayapodmyshka 02.03.2015 07:21 # +2