Shannon V. OKeets
Posts: 22095
Joined: 5/19/2005 From: Honolulu, Hawaii Status: offline
|
For those with a despearte interest in this, here's the MWIF code: =========
// ****************************************************************************
// ProdTCount subtracts the production points already lost.
// ****************************************************************************
ProdCount := Map.FactoryList.FactoryProductionCount[TargetHex.X, TargetHex.Y];
ProdTCount :=
Map.FactoryList.FactoryTargetProductionCount[TargetHex.X, TargetHex.Y];
Pts := Msg_SBRo.PtsDestroyed; // # of points lost.
Destroyed := Msg_SBRo.FacsDestroyed; // # of factories/facilities destroyed.
EffectiveRoll := Msg_SBRo.Roll + Msg_SBRo.DieMod;
AddResult(Format(rsStrategicBombingRoll, [EffectiveRoll, Msg_SBRo.Roll,
Msg_SBRo.DieMod]));
// ****************************************************************************
// Effect point losses.
// ****************************************************************************
if Pts = 0 then NoEffect // No damage.
else
begin
// ****************************************************************************
// Factories lose production points first.
// ****************************************************************************
if ProdTCount > 0 then
begin
P := Min([ProdTCount, Pts]); // # of production points lost.
if P > 0 then
begin // Record the production loss.
Dec(Pts, P); // Reduce the losses that remain to be taken.
Inc(FH.ProductionLost[FH.Owner.Value], P);
AddResult(Format(rsProductionLost, [P, PluralString(rsPointWas,
rsPointsWere, P)]));
Inc(M.ProductionLost, P);
Inc(EntryNumber);
PtsDestroyedCnt := P; // Points lost for the turn.
SetGRL(RLID_SBPL); // Production point losses.
UseGRL(RLID_SBPL); // Executes Nada.
end;
end;
// ****************************************************************************
// Synthetic oil plants lose points second.
// ****************************************************************************
if OptRules.SyntheticOilPlants and (Pts <> 0) then
begin
P := 0;
repeat
U := MapStack.FindUnit(UFilterSynthOilUnitNotLost);
if U <> nil then
begin
U.SynthOilLost := True;
TSynthOilResource(Map.ResourceList.Search(TSynthOilResource,
TargetHex.X, TargetHex.Y)).ProductionLost := True;
Inc(P);
Dec(Pts);
end;
until (Pts = 0) or (U = nil);
if P > 0 then
begin
Inc(M.SynthOilLost, P);
AddResult(Format(rsSynthOilLost, [P, PluralString(rsResourceWas,
rsResourcesWere, P)]));
Inc(EntryNumber);
PtsDestroyedCnt := P; // Points lost for the turn.
SetGRL(RLID_SBSL); // Synthetic oil point losses.
UseGRL(RLID_SBSL); // Executes Nada.
end;
end;
// ****************************************************************************
// Oil resources lose points third.
// ****************************************************************************
if (Pts <> 0) and Map.Oil[TargetHex.X, TargetHex.Y] then
begin
P := Map.OilProduction[TargetHex.X, TargetHex.Y];
if P > 0 then
begin
P := Min([P - Map.ResourceList.TotalProductionLost(TargetHex.X,
TargetHex.Y), Pts]);
if P > 0 then
begin
Dec(Pts, P);
Map.ResourceList.LoseProduction(TargetHex.X, TargetHex.Y, P);
Inc(M.OilLost, P);
AddResult(Format(rsOilLost, [P, PluralString(rsResourceWas,
rsResourcesWere, P)]));
Inc(EntryNumber);
PtsDestroyedCnt := P; // Points lost for the turn.
SetGRL(RLID_SBOL); // Oil resource losses.
UseGRL(RLID_SBOL); // Executes Nada.
end;
end;
end;
// ****************************************************************************
// Saved oil points are lost fourth.
// ****************************************************************************
if Pts > 0 then
begin
SU := MapStack.OilPointsUnit;
if SU <> nil then
begin
P := Min([SU.Points, Pts]);
Dec(Pts, P);
Inc(M.SavedOilLost, P);
AddResult(Format(rsSavedOilLost, [P, PluralString(rsPointWas,
rsPointsWere, P)]));
if P = SU.Points then
begin
CurrAirAttackStack.DeleteIndexOf(SU);
GSVGround.SVStack.DeleteIndexOf(SU);
end;
MainForm.PointsChange(SU, SU.Points - P);
Inc(EntryNumber);
PtsDestroyedCnt := P; // Points lost for the turn.
SetGRL(RLID_SBOS); // Saved oil point losses.
UseGRL(RLID_SBOS); // Executes Nada.
end;
end;
// ****************************************************************************
// Saved build points are lost fifth.
// ****************************************************************************
if Pts > 0 then
begin
SU := MapStack.BuildPointsUnit;
if SU <> nil then
begin
P := Min([SU.Points, Pts]);
AddResult(Format(rsSavedBuildPointsLost,
[P, PluralString(rsPointWas, rsPointsWere, P)]));
if P = SU.Points then
begin
CurrAirAttackStack.DeleteIndexOf(SU);
GSVGround.SVStack.DeleteIndexOf(SU);
end;
MainForm.PointsChange(SU, SU.Points - P);
Inc(M.BuildPointsLost, P);
Inc(EntryNumber);
PtsDestroyedCnt := P; // Points lost for the turn.
SetGRL(RLID_SBBS); // Saved build point losses.
UseGRL(RLID_SBBS); // Executes Nada.
end;
end;
// ****************************************************************************
// End of production point losses. Effect factory/facility losses.
// Factories get destroyed first.
// ****************************************************************************
if OptRules.FactoryConstruction and
(ProdCount > 0) and
(Destroyed > 0) then
begin
// ****************************************************************************
// We can't destroy any more than the # of productive factories in the hex.
// ****************************************************************************
P := Min([ProdCount, Destroyed]);
PCounter := 0; // No facilities destroyed so far.
FDCounter := 0; // No factories destroyed.
// ****************************************************************************
// Destory green factories first, if they are usable.
// ****************************************************************************
while Map.FactoryList.FactoryHexUsable[TargetHex.X, TargetHex.Y] and
(FH.GreenFact > 0) and
(PCounter < P) do
begin
Dec(FH.GreenFact); // Destroy a green factory.
Inc(PCounter); // 1 factory destroyed.
Inc(FDCounter); // 1 factory destroyed.
FH.GreenDestroyed := True; // Display a destroyed factory in the hex.
end;
// ****************************************************************************
// Write an entry to the game record log for destroyed facilities.
// ****************************************************************************
if FDCounter > 0 then
begin
Inc(EntryNumber);
FacsDestroyedCnt := FDCounter; // Facilities destroyed.
FDCounter := 0; // Reset counter.
SetGRL(RLID_SBGF);
UseGRL(RLID_SBGF); // Executes Nada.
end;
// ****************************************************************************
// Damage blue factories next, if they are usable.
// ****************************************************************************
while Map.FactoryList.FactoryHexUsable[TargetHex.X, TargetHex.Y] and
((FH.BlueFact - FH.BlueDamaged) > 0) and
(PCounter < P) do
begin
Inc(FH.BlueDamaged); // Damage a blue factory.
Inc(PCounter); // 1 factory damaged.
Inc(FDCounter); // 1 factory damaged.
end;
// ****************************************************************************
// Write an entry to the game record log for destroyed facilities.
// ****************************************************************************
if FDCounter > 0 then
begin
Inc(EntryNumber);
FacsDestroyedCnt := FDCounter; // Facilities destroyed.
FDCounter := 0; // Reset counter.
SetGRL(RLID_SBBF);
UseGRL(RLID_SBBF); // Executes Nada.
end;
// ****************************************************************************
// Only as a last resort, damage red factories.
// ****************************************************************************
while ((FH.RedFact - FH.RedDamaged) > 0) and (PCounter < P) do
begin
Inc(FH.RedDamaged); // Damage a red factory.
Inc(PCounter); // 1 factory damaged.
Inc(FDCounter); // 1 factory damaged.
end;
// ****************************************************************************
// Write an entry to the game record log for destroyed facilities.
// ****************************************************************************
if FDCounter > 0 then
begin
Inc(EntryNumber);
FacsDestroyedCnt := FDCounter; // Facilities destroyed.
SetGRL(RLID_SBRF);
UseGRL(RLID_SBRF); // Executes Nada.
end;
MapWindows.RedrawHex(TargetHex.X, TargetHex.Y);
Inc(M.FactoriesDestroyed, PCounter);
AddResult(Format(rsSBDestroyed, [PCounter, PluralString(rsFactoryWas,
rsFactoriesWere, PCounter)]));
end;
// ****************************************************************************
// Synthetic oil plants get destroyed second (after factories).
// ****************************************************************************
if OptRules.SyntheticOilPlants then
begin
if Destroyed > 0 then
begin
P := 0;
LocalPlayerOnly := True;
try
repeat
U := MapStack.FindUnit(UFilterSynthOilUnit);
if U <> nil then
begin
PrepareMoveForcePool(U);
Dec(Destroyed);
Inc(P);
end;
until (Destroyed = 0) or (U = nil);
finally
LocalPlayerOnly := False;
end;
if P > 0 then
begin
MapWindows.RedrawStack(TargetHex.X, TargetHex.Y);
Inc(M.SynthOilDestroyed, P);
AddResult(Format(rsSynthOilDestroyed, [P, PluralString(rsUnitWas,
rsUnitsWere, P)]));
// ****************************************************************************
// Write an entry to the game record log for destroyed facilities.
// ****************************************************************************
Inc(EntryNumber);
FacsDestroyedCnt := P; // Facilities destroyed.
SetGRL(RLID_SBSO);
UseGRL(RLID_SBSO); // Executes Nada.
end;
end;
// ****************************************************************************
// Oil resources get destroyed third.
// ****************************************************************************
if Destroyed > 0 then
begin
P := Map.OilProduction[TargetHex.X, TargetHex.Y];
if P > 0 then
begin
P := Min([P, Destroyed]);
for Counter := 1 to P do Map.OilDamage(TargetHex.X, TargetHex.Y);
Map.ResourceList.LoseProduction(TargetHex.X, TargetHex.Y,
Min([Map.ResourceList.TotalProductionLost(TargetHex.X, TargetHex.Y),
Map.OilProduction[TargetHex.X, TargetHex.Y]]));
MapWindows.RedrawHex(TargetHex.X, TargetHex.Y);
Inc(M.OilDestroyed, P);
AddResult(Format(rsOilDestroyed, [P, PluralString(rsResourceWas,
rsResourcesWere, P)]));
// ****************************************************************************
// Write an entry to the game record log for destroyed facilities.
// ****************************************************************************
Inc(EntryNumber);
FacsDestroyedCnt := P; // Facilities destroyed.
SetGRL(RLID_SBOH);
UseGRL(RLID_SBOH); // Executes Nada.
end;
end;
end;
end;
_____________________________
Steve Perfection is an elusive goal.
|