Changeset 531 for trunk/AI/StdAI


Ignore:
Timestamp:
Mar 27, 2024, 12:31:14 PM (9 months ago)
Author:
chronos
Message:
  • Modified: Code cleanup.
Location:
trunk/AI/StdAI
Files:
5 edited

Legend:

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

    r522 r531  
    9393  TPersistentData = record
    9494    LastResearchTech, BehaviorFlags, TheologyPartner: Integer;
    95     RejectTurn: array[Suggestion, 0..15] of smallint;
     95    RejectTurn: array[Suggestion, 0..15] of SmallInt;
    9696    RequestedTechs: array[0..nRequestedTechs - 1] of Integer;
    9797    // ad + p shl 8 + Turn shl 16
     
    196196    else
    197197      BehaviorFlags := bMale;
    198     DebugMessage(1, 'Gender:=' + char(48 + BehaviorFlags and bGender));
     198    DebugMessage(1, 'Gender:=' + Char(48 + BehaviorFlags and bGender));
    199199    TheologyPartner := -1;
    200200    FillChar(RejectTurn, SizeOf(RejectTurn), $FF);
    201     Fillchar(RequestedTechs, SizeOf(RequestedTechs), $FF);
     201    FillChar(RequestedTechs, SizeOf(RequestedTechs), $FF);
    202202  end;
    203203end;
     
    324324  mi: TModelInfo;
    325325  Entry: array[0..nAdv - 1] of Boolean;
    326   ok: Boolean;
     326  Ok: Boolean;
    327327
    328328  function MarkEntry(ad: Integer): Boolean;
     
    540540      ((EarliestNeeded < 0) or (Advancedness[ad] < Advancedness[EarliestNeeded])) then
    541541    begin
    542       ok := False;
     542      Ok := False;
    543543      for iad := 0 to nResearchOrder - 1 do
    544544        if ResearchOrder[Data.BehaviorFlags and bGender, iad] = ad then
    545545        begin
    546           ok := True;
     546          Ok := True;
    547547          Break;
    548548        end;
    549       if not ok then
     549      if not Ok then
    550550      begin
    551551        EarliestNeeded := ad;
     
    14061406  begin
    14071407    Data.BehaviorFlags := Data.BehaviorFlags and not bGender or NewGender;
    1408     DebugMessage(1, 'Gender:=' + char(48 + NewGender));
     1408    DebugMessage(1, 'Gender:=' + Char(48 + NewGender));
    14091409  end;
    14101410end;
     
    24272427            Total := Total + CityResult[cix];
    24282428      if Total = 0 then
    2429         continue; // district does not exist
     2429        Continue; // district does not exist
    24302430
    24312431      Share := 0;
  • 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;
  • trunk/AI/StdAI/CustomAI.pas

    r522 r531  
    682682function TCustomAI.DebugMessage(Level: Integer; Text: string): Boolean;
    683683begin
    684   Text := Copy('P' + char(48 + Me) + ' ' + Text, 1, 254);
     684  Text := Copy('P' + Char(48 + Me) + ' ' + Text, 1, 254);
    685685  Server(sMessage, Me, Level, PChar(Text)^);
    686686
  • trunk/AI/StdAI/CustomAI_Reload.pas

    r522 r531  
    639639function TCustomAI.DebugMessage(Level: Integer; Text: string): Boolean;
    640640begin
    641   Text := Copy('P' + char(48 + Me) + ' ' + Text, 1, 254);
     641  Text := Copy('P' + Char(48 + Me) + ' ' + Text, 1, 254);
    642642  Server(sMessage, Me, Level, PChar(Text)^);
    643643
  • trunk/AI/StdAI/ToolAI.pas

    r522 r531  
    355355  UnitsToAssign: Boolean;
    356356  Adjacent: TVicinity8Loc;
    357   SettlerOfJobLoc, DistToLoc: array[0..lxmax * lymax - 1] of smallint;
     357  SettlerOfJobLoc, DistToLoc: array[0..lxmax * lymax - 1] of SmallInt;
    358358  // DistToLoc is only defined where SettlerOfJobLoc>=0
    359359  TileChecked: array[0..lxmax * lymax - 1] of Boolean;
     
    471471  I, J, Loc, Loc1, V8, Count, Kind, MostIndex: Integer;
    472472  Adjacent: TVicinity8Loc;
    473   IndexOfID: array[0..lxmax * lymax - 1] of smallint;
    474   IDOfIndex: array[0..lxmax * lymax div 2 - 1] of smallint;
     473  IndexOfID: array[0..lxmax * lymax - 1] of SmallInt;
     474  IDOfIndex: array[0..lxmax * lymax div 2 - 1] of SmallInt;
    475475begin
    476476  FillChar(District, MapSize * 4, $FF);
     
    11071107  nSelectedLoad, F, OriginContinent, A, B: Integer;
    11081108  CompleteFlag, NotReachedFlag, ContinueUnit: Cardinal;
    1109   IsComplete, ok, IsFirstLoc: Boolean;
     1109  IsComplete, Ok, IsFirstLoc: Boolean;
    11101110  StartLocPtr, ArrivedEnd: pinteger;
    11111111  Adjacent: TVicinity8Loc;
     
    11131113  tuixSelectedLoad: array[0..15] of Integer;
    11141114  Arrived: array[0..lxmax * lymax] of Cardinal;
    1115   ResponsibleTransport: array[0..lxmax * lymax - 1] of smallint;
     1115  ResponsibleTransport: array[0..lxmax * lymax - 1] of SmallInt;
    11161116  TurnsBeforeLoad: array[0..lxmax * lymax - 1] of ShortInt;
    11171117  GroupComplete: array[0..lxmax * lymax - 1] of Boolean;
     
    11911191    FillChar(ResponsibleTransport, MapSize * 2, $FF); // -1
    11921192    FillChar(TurnsBeforeLoad, MapSize, $FF); // -1
    1193     ok := False;
     1193    Ok := False;
    11941194    for uix := 0 to RO.nUn - 1 do
    11951195      if TransportAvailable[uix] > 0 then
    11961196      begin
    1197         ok := True;
     1197        Ok := True;
    11981198        Pile.Put(MyUnit[uix].Loc, ($800 - MyUnit[uix].Movement) shl 12 + uix);
    11991199      end;
    1200     if not ok then // no transports
     1200    if not Ok then // no transports
    12011201    begin
    12021202      TransportPlan.LoadLoc := -1;
     
    13921392            begin
    13931393              Arrived[Loc0] := (Arrived[Loc0] or CompleteFlag) and not NotReachedFlag;
    1394               continue;
     1394              Continue;
    13951395            end;
    13961396            IsComplete := True;
     
    14001400              if Loc1 >= 0 then
    14011401              begin
    1402                 ok := False;
     1402                Ok := False;
    14031403                case CheckStep(MoveStyle, Time0, V8 and 1, ArriveTime,
    14041404                    RecoverTurns, Map[Loc0], Map[Loc1], False) of
    1405                   csOk: ok := True;
     1405                  csOk: Ok := True;
    14061406                  csForbiddenTile:
    14071407                    ;// !!! don't check moving there again
    14081408                  csCheckTerritory:
    1409                     ok := RO.Territory[Loc1] = RO.Territory[Loc0];
     1409                    Ok := RO.Territory[Loc1] = RO.Territory[Loc0];
    14101410                end;
    1411                 if ok and Pile.TestPut(Loc1, ArriveTime) then
     1411                if Ok and Pile.TestPut(Loc1, ArriveTime) then
    14121412                  if ArriveTime < $2000 then
    14131413                    Pile.Put(Loc1, ArriveTime)
Note: See TracChangeset for help on using the changeset viewer.