public void SetPercentage(TechField whichField, int amount)
{
int remainingPercentile = 100;
if (ComputerLocked)
{
remainingPercentile -= ComputerPercentage;
}
if (ConstructionLocked)
{
remainingPercentile -= ConstructionPercentage;
}
if (ForceFieldLocked)
{
remainingPercentile -= ForceFieldPercentage;
}
if (PlanetologyLocked)
{
remainingPercentile -= PlanetologyPercentage;
}
if (PropulsionLocked)
{
remainingPercentile -= PropulsionPercentage;
}
if (WeaponLocked)
{
remainingPercentile -= WeaponPercentage;
}
if (amount >= remainingPercentile)
{
if (!ComputerLocked)
{
ComputerPercentage = 0;
}
if (!ConstructionLocked)
{
ConstructionPercentage = 0;
}
if (!ForceFieldLocked)
{
ForceFieldPercentage = 0;
}
if (!PlanetologyLocked)
{
PlanetologyPercentage = 0;
}
if (!PropulsionLocked)
{
PropulsionPercentage = 0;
}
if (!WeaponLocked)
{
WeaponPercentage = 0;
}
amount = remainingPercentile;
}
//Now scale
int totalPointsExcludingSelectedType = 0;
switch (whichField)
{
case TechField.COMPUTER:
{
ComputerPercentage = amount;
remainingPercentile -= ComputerPercentage;
totalPointsExcludingSelectedType = GetTotalPercentageExcludingTypeAndLocked(TechField.COMPUTER);
} break;
case TechField.CONSTRUCTION:
{
ConstructionPercentage = amount;
remainingPercentile -= ConstructionPercentage;
totalPointsExcludingSelectedType = GetTotalPercentageExcludingTypeAndLocked(TechField.CONSTRUCTION);
} break;
case TechField.FORCE_FIELD:
{
ForceFieldPercentage = amount;
remainingPercentile -= ForceFieldPercentage;
totalPointsExcludingSelectedType = GetTotalPercentageExcludingTypeAndLocked(TechField.FORCE_FIELD);
} break;
case TechField.PLANETOLOGY:
{
PlanetologyPercentage = amount;
remainingPercentile -= PlanetologyPercentage;
totalPointsExcludingSelectedType = GetTotalPercentageExcludingTypeAndLocked(TechField.PLANETOLOGY);
} break;
case TechField.PROPULSION:
{
PropulsionPercentage = amount;
remainingPercentile -= PropulsionPercentage;
totalPointsExcludingSelectedType = GetTotalPercentageExcludingTypeAndLocked(TechField.PROPULSION);
} break;
case TechField.WEAPON:
{
WeaponPercentage = amount;
remainingPercentile -= WeaponPercentage;
totalPointsExcludingSelectedType = GetTotalPercentageExcludingTypeAndLocked(TechField.WEAPON);
} break;
}
if (remainingPercentile < totalPointsExcludingSelectedType)
{
int amountToDeduct = totalPointsExcludingSelectedType - remainingPercentile;
int prevValue;
if (!ComputerLocked && whichField != TechField.COMPUTER)
{
prevValue = ComputerPercentage;
ComputerPercentage -= (ComputerPercentage >= amountToDeduct ? amountToDeduct : ComputerPercentage);
amountToDeduct -= (prevValue - ComputerPercentage);
}
if (amountToDeduct > 0)
{
if (!ConstructionLocked && whichField != TechField.CONSTRUCTION)
{
prevValue = ConstructionPercentage;
ConstructionPercentage -= (ConstructionPercentage >= amountToDeduct ? amountToDeduct : ConstructionPercentage);
amountToDeduct -= (prevValue - ConstructionPercentage);
}
}
if (amountToDeduct > 0)
{
if (!ForceFieldLocked && whichField != TechField.FORCE_FIELD)
{
prevValue = ForceFieldPercentage;
ForceFieldPercentage -= (ForceFieldPercentage >= amountToDeduct ? amountToDeduct : ForceFieldPercentage);
amountToDeduct -= (prevValue - ForceFieldPercentage);
}
}
if (amountToDeduct > 0)
{
if (!PlanetologyLocked && whichField != TechField.PLANETOLOGY)
{
prevValue = PlanetologyPercentage;
PlanetologyPercentage -= (PlanetologyPercentage >= amountToDeduct ? amountToDeduct : PlanetologyPercentage);
amountToDeduct -= (prevValue - PlanetologyPercentage);
}
}
if (amountToDeduct > 0)
{
if (!PropulsionLocked && whichField != TechField.PROPULSION)
{
prevValue = PropulsionPercentage;
PropulsionPercentage -= (PropulsionPercentage >= amountToDeduct ? amountToDeduct : PropulsionPercentage);
amountToDeduct -= (prevValue - PropulsionPercentage);
}
}
if (amountToDeduct > 0)
{
if (!WeaponLocked && whichField != TechField.WEAPON)
{
prevValue = WeaponPercentage;
WeaponPercentage -= (WeaponPercentage >= amountToDeduct ? amountToDeduct : WeaponPercentage);
amountToDeduct -= (prevValue - WeaponPercentage);
}
}
}
if (remainingPercentile > totalPointsExcludingSelectedType) //excess points needed to allocate
{
int amountToAdd = remainingPercentile - totalPointsExcludingSelectedType;
if (!ComputerLocked && whichField != TechField.COMPUTER)
{
ComputerPercentage += amountToAdd;
amountToAdd = 0;
}
if (amountToAdd > 0)
{
if (!ConstructionLocked && whichField != TechField.CONSTRUCTION)
{
ConstructionPercentage += amountToAdd;
amountToAdd = 0;
}
}
if (amountToAdd > 0)
{
if (!ForceFieldLocked && whichField != TechField.FORCE_FIELD)
{
ForceFieldPercentage += amountToAdd;
amountToAdd = 0;
}
}
if (amountToAdd > 0)
{
if (!PlanetologyLocked && whichField != TechField.PLANETOLOGY)
{
PlanetologyPercentage += amountToAdd;
amountToAdd = 0;
}
}
if (amountToAdd > 0)
{
if (!PropulsionLocked && whichField != TechField.PROPULSION)
{
PropulsionPercentage += amountToAdd;
amountToAdd = 0;
}
}
if (amountToAdd > 0)
{
if (!WeaponLocked && whichField != TechField.WEAPON)
{
WeaponPercentage += amountToAdd;
amountToAdd = 0;
}
}
if (amountToAdd > 0)
{
//All fields are already checked, so have to add the remaining back to the current tech field
switch (whichField)
{
case TechField.COMPUTER:
ComputerPercentage += amountToAdd;
break;
case TechField.CONSTRUCTION:
ConstructionPercentage += amountToAdd;
break;
case TechField.FORCE_FIELD:
ForceFieldPercentage += amountToAdd;
break;
case TechField.PLANETOLOGY:
PlanetologyPercentage += amountToAdd;
break;
case TechField.PROPULSION:
PropulsionPercentage += amountToAdd;
break;
case TechField.WEAPON:
WeaponPercentage += amountToAdd;
break;
}
}
}
}