Ignore:
Timestamp:
Mar 27, 2024, 12:31:14 PM (5 weeks ago)
Author:
chronos
Message:
  • Modified: Code cleanup.
File:
1 edited

Legend:

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

    r522 r531  
    3434  TBarbarina = class(TToolAI)
    3535    constructor Create(Nation: Integer); override;
    36 
    3736  protected
    3837    ColonyShipPlan: TColonyShipPlan;
     
    4746    procedure Barbarina_DoNegotiation;
    4847    procedure MakeColonyShipPlan;
    49 
    5048  private
    5149    TurnOfMapAnalysis, Neighbours: Integer;
     
    173171  Moved: array[0..numax - 1] of Boolean;
    174172  UnitPresence: array[0..lxmax * lymax - 1] of Byte;
    175   euixMap: array[0..lxmax * lymax - 1] of smallint;
    176   uixAttack: array[0..neumax - 1] of smallint;
     173  euixMap: array[0..lxmax * lymax - 1] of SmallInt;
     174  uixAttack: array[0..neumax - 1] of SmallInt;
    177175  AttackScore: array[0..neumax - 1] of Integer;
    178176
     
    15991597          end;
    16001598          if (City_CurrentImprovementProject(cix) = imCourt) and
    1601             (Built[imTownHall] > 0) and (prod >= imp[imCourt].cost *
     1599            (Built[imTownHall] > 0) and (Prod >= imp[imCourt].Cost *
    16021600            BuildCostMod[G.Difficulty[Me]] div 12 -
    1603             (imp[imTownHall].cost * BuildCostMod[G.Difficulty[Me]] div 12) *
     1601            (Imp[imTownHall].Cost * BuildCostMod[G.Difficulty[Me]] div 12) *
    16041602            2 div 3) then
    16051603            City_RebuildImprovement(cix, imTownHall)
     
    16221620var
    16231621  nPreq, rmix, rmixChosen, I, MaxWeight, MaxDefense, ChosenPreq: Integer;
    1624   NeedSeaUnits, ready: Boolean;
     1622  NeedSeaUnits, Ready: Boolean;
    16251623  ModelExists: set of 0..nModelCategory - 1;
    1626   known: array[0..nAdv - 1] of Integer;
     1624  Known: array[0..nAdv - 1] of Integer;
    16271625
    16281626  procedure ChoosePreq(ad: Integer);
     
    16321630  begin
    16331631    Assert(RO.Tech[ad] < tsApplicable);
    1634     if known[ad] = 0 then
     1632    if Known[ad] = 0 then
    16351633    begin
    1636       known[ad] := 1;
     1634      Known[ad] := 1;
    16371635      PreqOk := True;
    16381636      if not (ad in [adScience, adMassProduction]) and (RO.Tech[ad] < tsSeen) then
     
    16951693        if IsResearched(adSteel) then
    16961694          Inc(MaxDefense);
    1697         ready := (MaxWeight >= Weight) and (MaxDefense >= Cap[mcDefense]);
    1698         if ready then
     1695        Ready := (MaxWeight >= Weight) and (MaxDefense >= Cap[mcDefense]);
     1696        if Ready then
    16991697          for I := 0 to nFeature - 1 do
    17001698            if (Cap[I] > 0) and (Feature[I].Preq <> preNone) and
    17011699              ((Feature[I].Preq < 0) or not IsResearched(Feature[I].Preq)) then
    1702               ready := False;
    1703         if ready then
     1700              Ready := False;
     1701        if Ready then
    17041702        begin
    17051703          for I := 0 to nUpgrade - 1 do
    17061704            if (Upgrades and (1 shl I) <> 0) and not
    17071705              IsResearched(Upgrade[Domain, I].Preq) then
    1708               ready := False;
    1709         end;
    1710         if ready then
     1706              Ready := False;
     1707        end;
     1708        if Ready then
    17111709        begin
    17121710          Include(ModelExists, Category);
     
    17361734  I := 0;
    17371735  while (I < nResearchOrder) and (not NeedSeaUnits and (ResearchOrder[I] < 0) or
    1738       IsResearched(Abs(ResearchOrder[I]))) do
    1739     Inc(I);
     1736    IsResearched(Abs(ResearchOrder[I]))) do
     1737      Inc(I);
    17401738  if I >= nResearchOrder then // list done, continue with future tech
    17411739  begin
     
    17471745  else
    17481746  begin
    1749     FillChar(known, SizeOf(known), 0);
     1747    FillChar(Known, SizeOf(Known), 0);
    17501748    nPreq := 0;
    17511749    ChosenPreq := -1;
     
    18351833                    (MyModel[mix].Domain <> dSea)) then
    18361834                  begin
    1837                     DebugMessage(1, 'Declare war on P' + char(48 + Nation));
     1835                    DebugMessage(1, 'Declare war on P' + Char(48 + Nation));
    18381836                    NegoCause := CancelTreaty;
    18391837                    Result := True;
     
    18581856procedure TBarbarina.MakeColonyShipPlan;
    18591857var
    1860   I, V21, V21C, CityLoc, Loc1, part, cix, BestValue, TestValue, FoodCount,
     1858  I, V21, V21C, CityLoc, Loc1, Part, cix, BestValue, TestValue, FoodCount,
    18611859  ProdCount, ProdExtra, Score, BestScore: Integer;
    18621860  Tile: Cardinal;
    1863   ok, check: Boolean;
     1861  Ok, Check: Boolean;
    18641862  Radius, RadiusC: TVicinity21Loc;
    18651863begin
    1866   for part := 0 to nShipPart - 1 do
     1864  for Part := 0 to nShipPart - 1 do
    18671865  begin
    1868     ColonyShipPlan[part].cixProducing := -1;
    1869     ColonyShipPlan[part].nLocResource := 0;
    1870     ColonyShipPlan[part].nLocFoundCity := 0;
     1866    ColonyShipPlan[Part].cixProducing := -1;
     1867    ColonyShipPlan[Part].nLocResource := 0;
     1868    ColonyShipPlan[Part].nLocFoundCity := 0;
    18711869  end;
    18721870  if RO.Tech[adMassProduction] >= tsApplicable then // able to recognize ressources yet
    18731871  begin
    1874     // check already existing cities
     1872    // Check already existing cities
    18751873    for cix := 0 to RO.nCity - 1 do
    18761874      with MyCity[cix] do
     
    18861884              if Tile and fModern <> 0 then
    18871885              begin
    1888                 part := (Tile and fModern) shr 25 - 1;
    1889                 if RO.Ship[Me].Parts[part] < ShipNeed[part] then
     1886                Part := (Tile and fModern) shr 25 - 1;
     1887                if RO.Ship[Me].Parts[Part] < ShipNeed[Part] then
    18901888                  // not enough of this kind already
    18911889                begin
    1892                   ok := True;
    1893                   if ColonyShipPlan[part].cixProducing >= 0 then
     1890                  Ok := True;
     1891                  if ColonyShipPlan[Part].cixProducing >= 0 then
    18941892                  begin // another city is already assigned to this ship part, choose one of the two
    18951893                    TestValue := (ID and $FFF) shl 4 + ((ID shr 12) + 15 - Me) and $F;
    18961894                    BestValue :=
    1897                       (MyCity[ColonyShipPlan[part].cixProducing].ID and $FFF) shl
    1898                       4 + ((MyCity[ColonyShipPlan[part].cixProducing].ID shr 12) +
     1895                      (MyCity[ColonyShipPlan[Part].cixProducing].ID and $FFF) shl
     1896                      4 + ((MyCity[ColonyShipPlan[Part].cixProducing].ID shr 12) +
    18991897                      15 - Me) and $F;
    19001898                    if TestValue <= BestValue then
    1901                       ok := False;
     1899                      Ok := False;
    19021900                  end;
    1903                   if ok then
     1901                  if Ok then
    19041902                    ColonyShipPlan[part].cixProducing := cix;
    19051903                end;
     
    19101908
    19111909    // for parts without existing city, look for location of city to found
    1912     check := False;
    1913     for part := 0 to nShipPart - 1 do
    1914       if (RO.Ship[Me].Parts[part] < ShipNeed[part]) // not enough of this kind already
    1915         and (ColonyShipPlan[part].cixProducing < 0) then // no city to produce
    1916         check := True;
    1917     if check then
     1910    Check := False;
     1911    for Part := 0 to nShipPart - 1 do
     1912      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;
     1915    if Check then
    19181916    begin
    19191917      for Loc1 := 0 to MapSize - 1 do
     
    19221920        if Tile and fModern <> 0 then
    19231921        begin
    1924           part := (Tile and fModern) shr 25 - 1;
    1925           if ColonyShipPlan[part].nLocResource < maxModern then
    1926           begin
    1927             ColonyShipPlan[part].LocResource[ColonyShipPlan[part].nLocResource] := Loc1;
    1928             Inc(ColonyShipPlan[part].nLocResource);
    1929           end;
    1930         end;
    1931       end;
    1932       for part := 0 to nShipPart - 1 do
    1933         if (RO.Ship[Me].Parts[part] < ShipNeed[part]) // not enough of this kind already
    1934           and (ColonyShipPlan[part].cixProducing < 0) // no city to produce
    1935           and (ColonyShipPlan[part].nLocResource > 0) then // resource is known
    1936         begin
    1937           for I := 0 to ColonyShipPlan[part].nLocResource - 1 do
     1922          Part := (Tile and fModern) shr 25 - 1;
     1923          if ColonyShipPlan[Part].nLocResource < maxModern then
     1924          begin
     1925            ColonyShipPlan[Part].LocResource[ColonyShipPlan[Part].nLocResource] := Loc1;
     1926            Inc(ColonyShipPlan[Part].nLocResource);
     1927          end;
     1928        end;
     1929      end;
     1930      for Part := 0 to nShipPart - 1 do
     1931        if (RO.Ship[Me].Parts[Part] < ShipNeed[Part]) // not enough of this kind already
     1932          and (ColonyShipPlan[Part].cixProducing < 0) // no city to produce
     1933          and (ColonyShipPlan[Part].nLocResource > 0) then // resource is known
     1934        begin
     1935          for I := 0 to ColonyShipPlan[Part].nLocResource - 1 do
    19381936          begin
    19391937            BestScore := 0;
    1940             V21_to_Loc(ColonyShipPlan[part].LocResource[I], Radius);
     1938            V21_to_Loc(ColonyShipPlan[Part].LocResource[I], Radius);
    19411939            for V21 := 1 to 26 do
    1942             begin // check all potential cities in range
     1940            begin // Check all potential cities in range
    19431941              CityLoc := Radius[V21];
    19441942              if CityLoc >= 0 then
     
    19901988                  begin
    19911989                    BestScore := Score;
    1992                     ColonyShipPlan[part].LocFoundCity[
    1993                       ColonyShipPlan[part].nLocFoundCity] :=
     1990                    ColonyShipPlan[Part].LocFoundCity[
     1991                      ColonyShipPlan[Part].nLocFoundCity] :=
    19941992                      CityLoc;
    19951993                  end;
     
    19981996            end;
    19991997            if BestScore > 0 then
    2000               Inc(ColonyShipPlan[part].nLocFoundCity);
     1998              Inc(ColonyShipPlan[Part].nLocFoundCity);
    20011999          end;
    20022000        end;
Note: See TracChangeset for help on using the changeset viewer.