Changeset 549 for trunk/AI


Ignore:
Timestamp:
Apr 21, 2024, 8:55:53 PM (7 months ago)
Author:
chronos
Message:
  • Modified: Optimize code with earlier break from for cycle evaluating boolean result.
  • Modified: Code cleanup.
Location:
trunk/AI/StdAI
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/AI/StdAI/AI.pas

    r548 r549  
    17881788  DistrictNeed, DistrictNeed0: array[0..maxCOD - 1] of Integer;
    17891789  ModelOrder: array[0..nMmax - 1] of Integer;
    1790   complete, Fortified: Boolean;
     1790  Complete, Fortified: Boolean;
    17911791
    17921792  function IsBombarded(cix: Integer): Boolean;
     
    19531953            end;
    19541954
    1955       complete := Loop >= FirstSurplusLoop[Cat];
     1955      Complete := Loop >= FirstSurplusLoop[Cat];
    19561956      for I := nModelOrder - 1 downto 0 do
    19571957      begin
     
    19671967                  Dec(DistrictNeed[District[Loc]]);
    19681968                Destination[uix] := Loc;
    1969                 complete := False;
     1969                Complete := False;
    19701970              end;
    19711971
     
    19801980                FindDestination(uix);
    19811981                if Destination[uix] >= 0 then
    1982                   complete := False;
     1982                  Complete := False;
    19831983              end;
    19841984      end;
    19851985      Inc(Loop)
    1986     until complete;
     1986    until Complete;
    19871987  end;
    19881988
     
    20052005    DistrictNeed0 := DistrictNeed;
    20062006
    2007     complete := True;
     2007    Complete := True;
    20082008    for uix := 0 to RO.nUn - 1 do
    20092009      with MyUnit[uix] do
     
    20152015            begin
    20162016              if DistrictNeed0[District[Loc]] > 0 then
    2017                 complete := False;
     2017                Complete := False;
    20182018            end
    20192019            else
     
    20212021              FindDestination(uix);
    20222022              //          if (Destination[uix]<0) and (RO.Territory[Loc]=me) then
    2023               //            complete:=false; // causes hangup when unit can't move due to zoc
     2023              //            Complete:=false; // causes hangup when unit can't move due to zoc
    20242024            end;
    2025   until complete;
     2025  until Complete;
    20262026
    20272027  for uix := 0 to RO.nUn - 1 do
     
    20442044        case ModelCat[mix] of
    20452045          mctGroundDefender, mctGroundAttacker:
    2046             Dec(UnitLack[District[Loc], ModelCat[mix]])
     2046            Dec(UnitLack[District[Loc], ModelCat[mix]]);
    20472047        end;
    20482048end;
     
    23512351            F := Formation[AdjacentLoc];
    23522352            if (F >= 0) and (F < maxCOD) and (OceanPresence[F] and
    2353               not (1 shl Me) <> 0) then
    2354               Result := True;
     2353              not (1 shl Me) <> 0) then begin
     2354                Result := True;
     2355                Exit;
     2356              end;
    23552357          end;
    23562358        end;
  • trunk/AI/StdAI/Barbarina.pas

    r531 r549  
    218218    Result := True;
    219219    for cix := 0 to RO.nCity - 1 do
    220       with MyCity[cix] do
     220      with MyCity[cix] do begin
    221221        if Loc >= 0 then
    222222        begin // search for modern resource
     
    225225          begin
    226226            Loc1 := Radius[V21];
    227             if (Loc1 >= 0) and (RO.Map[Loc1] and fModern <> 0) then
     227            if (Loc1 >= 0) and (RO.Map[Loc1] and fModern <> 0) then begin
    228228              Result := False;
    229           end;
    230         end;
     229              Break;
     230            end;
     231          end;
     232        end;
     233        if not Result then Break;
     234      end;
    231235  end
    232236  else if IsResearched(adGunPowder) then
     
    892896    for F := 0 to maxCOD - 1 do
    893897      if (F < nContinent) and (ContinentPresence[F] and not
    894         (1 shl Me or PresenceUnknown) <> 0) then
    895         Go := True; // any enemy island known?
     898        (1 shl Me or PresenceUnknown) <> 0) then begin
     899          Go := True; // any enemy island known?
     900          Break;
     901        end;
    896902    if not Go then
    897903      Exit;
     
    922928              (TroopLoad = 0) and (Health = 100) then
    923929            begin
    924               go := True;
     930              Go := True;
    925931              SeaTransport_AddTransport(uix);
    926932            end;
     
    11701176          if MyUnit[uix].Loc >= 0 then
    11711177            RateAttack(uix);
    1172         end
    1173       until BackToStart
     1178        end;
     1179      until BackToStart;
    11741180    until not BackToStart;
    11751181
     
    12141220  function LowPriority(cix: Integer): Boolean;
    12151221  var
    1216     part, cixHighPriority, TestDistance: Integer;
     1222    Part, cixHighPriority, TestDistance: Integer;
    12171223  begin
    12181224    Result := False;
    1219     for part := 0 to nShipPart - 1 do
     1225    for Part := 0 to nShipPart - 1 do
    12201226    begin
    1221       cixHighPriority := ColonyShipPlan[part].cixProducing;
     1227      cixHighPriority := ColonyShipPlan[Part].cixProducing;
    12221228      if (cixHighPriority >= 0) and (cixHighPriority <> cix) then
    12231229      begin
     
    13751381  for cix := 0 to RO.nCity - 1 do
    13761382    with MyCity[cix] do
    1377       if (Loc >= 0) and (Project and (cpImp + cpIndex) = cpImp + imAlgae) then
     1383      if (Loc >= 0) and (Project and (cpImp + cpIndex) = cpImp + imAlgae) then begin
    13781384        AlgaeAvailable := False;
     1385        Break;
     1386      end;
    13791387
    13801388  for cix := 0 to RO.nCity - 1 do
     
    14941502                with MyUnit[uix] do
    14951503                  if (Loc >= 0) and (Home = cix) and
    1496                     (MyModel[mix].Kind = mkSettler) then
    1497                     HasSettler := True;
     1504                    (MyModel[mix].Kind = mkSettler) then begin
     1505                      HasSettler := True;
     1506                      Break;
     1507                    end;
    14981508              if ((RO.Government <> gDespotism) or (RO.nUn >= RO.nCity * 4)) and
    14991509                not IsResearched(adMassProduction) and (Built[imPalace] > 0) and
     
    15521562                ImportantCity := WillProduceColonyShip or (Built[imPalace] > 0);
    15531563                for iix := 0 to nWonder - 1 do
    1554                   if Built[iix] > 0 then
     1564                  if Built[iix] > 0 then begin
    15551565                    ImportantCity := True;
     1566                    Break;
     1567                  end;
    15561568                City_GetReportNew(cix, Report);
    15571569                if (Report.Corruption >= 6) and (RO.nUn >= RO.nCity * 4) and
     
    16971709          for I := 0 to nFeature - 1 do
    16981710            if (Cap[I] > 0) and (Feature[I].Preq <> preNone) and
    1699               ((Feature[I].Preq < 0) or not IsResearched(Feature[I].Preq)) then
    1700               Ready := False;
     1711              ((Feature[I].Preq < 0) or not IsResearched(Feature[I].Preq)) then begin
     1712                Ready := False;
     1713                Break;
     1714              end;
    17011715        if Ready then
    17021716        begin
    17031717          for I := 0 to nUpgrade - 1 do
    17041718            if (Upgrades and (1 shl I) <> 0) and not
    1705               IsResearched(Upgrade[Domain, I].Preq) then
    1706               Ready := False;
     1719              IsResearched(Upgrade[Domain, I].Preq) then begin
     1720                Ready := False;
     1721                Break;
     1722              end;
    17071723        end;
    17081724        if Ready then
     
    19111927    for Part := 0 to nShipPart - 1 do
    19121928      if (RO.Ship[Me].Parts[Part] < ShipNeed[Part]) // not enough of this kind already
    1913         and (ColonyShipPlan[Part].cixProducing < 0) then // no city to produce
    1914         Check := True;
     1929        and (ColonyShipPlan[Part].cixProducing < 0) then begin // no city to produce
     1930          Check := True;
     1931          Break;
     1932        end;
    19151933    if Check then
    19161934    begin
Note: See TracChangeset for help on using the changeset viewer.