Ignore:
Timestamp:
May 19, 2022, 10:39:34 PM (2 years ago)
Author:
chronos
Message:
  • Modified: Use first capital letter in identifiers.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UnitProcessing.pas

    r442 r447  
    1313  TMoveInfo = record
    1414    MoveType: TMoveType;
    15     Cost, ToMaster, EndHealth, Defender, Dcix, Duix, EndHealthDef: integer;
    16     MountainDelay: boolean;
     15    Cost, ToMaster, EndHealth, Defender, Dcix, Duix, EndHealthDef: Integer;
     16    MountainDelay: Boolean;
    1717  end;
    1818
    1919var
    20   uixSelectedTransport: integer;
    21   Worked: array [0 .. nPl - 1] of integer; { settler work statistics }
     20  uixSelectedTransport: Integer;
     21  Worked: array [0 .. nPl - 1] of Integer; { settler work statistics }
    2222
    2323  // Moving/Combat
    24 function HostileDamage(p, mix, Loc, MP: integer): integer;
    25 function CalculateMove(p, uix, ToLoc, MoveLength: integer; TestOnly: boolean;
    26   var MoveInfo: TMoveInfo): integer;
    27 function GetBattleForecast(Loc: integer; var BattleForecast: TBattleForecast;
    28   var Duix, Dcix, AStr, DStr, ABaseDamage, DBaseDamage: integer): integer;
    29 function LoadUnit(p, uix: integer; TestOnly: boolean): integer;
    30 function UnloadUnit(p, uix: integer; TestOnly: boolean): integer;
    31 procedure Recover(p, uix: integer);
    32 function GetMoveAdvice(p, uix: integer; var a: TMoveAdviceData): integer;
    33 function CanPlaneReturn(p, uix: integer;
    34   PlaneReturnData: TPlaneReturnData): boolean;
     24function HostileDamage(P, mix, Loc, MP: Integer): Integer;
     25function CalculateMove(P, uix, ToLoc, MoveLength: Integer; TestOnly: Boolean;
     26  var MoveInfo: TMoveInfo): Integer;
     27function GetBattleForecast(Loc: Integer; var BattleForecast: TBattleForecast;
     28  var Duix, Dcix, AStr, DStr, ABaseDamage, DBaseDamage: Integer): Integer;
     29function LoadUnit(P, uix: Integer; TestOnly: Boolean): Integer;
     30function UnloadUnit(P, uix: Integer; TestOnly: Boolean): Integer;
     31procedure Recover(P, uix: Integer);
     32function GetMoveAdvice(P, uix: Integer; var A: TMoveAdviceData): Integer;
     33function CanPlaneReturn(P, uix: Integer;
     34  PlaneReturnData: TPlaneReturnData): Boolean;
    3535
    3636// Terrain Improvement
    37 function StartJob(p, uix, NewJob: integer; TestOnly: boolean): integer;
    38 function Work(p, uix: integer): boolean;
    39 function GetJobProgress(p, Loc: integer;
    40   var JobProgressData: TJobProgressData): integer;
     37function StartJob(P, uix, NewJob: Integer; TestOnly: Boolean): Integer;
     38function Work(P, uix: Integer): Boolean;
     39function GetJobProgress(P, Loc: Integer;
     40  var JobProgressData: TJobProgressData): Integer;
    4141
    4242// Start/End Game
     
    7474
    7575type
    76   TToWorkList = array [0 .. INFIN, 0 .. nJob - 1] of word;
     76  TToWorkList = array [0 .. INFIN, 0 .. nJob - 1] of Word;
    7777
    7878var
     
    8383    ____________________________________________________________________
    8484  }
    85 function HostileDamage(p, mix, Loc, MP: integer): integer;
    86 var
    87   Tile: integer;
     85function HostileDamage(P, mix, Loc, MP: Integer): Integer;
     86var
     87  Tile: Integer;
    8888begin
    8989  Tile := RealMap[Loc];
    90   if (RW[p].Model[mix].Domain >= dSea) or (RW[p].Model[mix].Kind = mkSettler)
    91     and (RW[p].Model[mix].Speed >= 200) or
     90  if (RW[P].Model[mix].Domain >= dSea) or (RW[P].Model[mix].Kind = mkSettler)
     91    and (RW[P].Model[mix].Speed >= 200) or
    9292    (Tile and (fCity or fRiver or fCanal) <> 0) or (Tile and fTerImp = tiBase)
    93     or (GWonder[woGardens].EffectiveOwner = p) then
    94     result := 0
     93    or (GWonder[woGardens].EffectiveOwner = P) then
     94    Result := 0
    9595  else if (Tile and fTerrain = fDesert) and
    9696    (Tile and fSpecial <> fSpecial1 { Oasis } ) then
    9797  begin
    98     assert((Tile and fTerImp <> tiIrrigation) and (Tile and fTerImp <> tiFarm));
    99     result := (DesertThurst * MP - 1) div RW[p].Model[mix].Speed + 1
     98    Assert((Tile and fTerImp <> tiIrrigation) and (Tile and fTerImp <> tiFarm));
     99    Result := (DesertThurst * MP - 1) div RW[P].Model[mix].Speed + 1
    100100  end
    101101  else if Tile and fTerrain = fArctic then
    102102  begin
    103     assert((Tile and fTerImp <> tiIrrigation) and (Tile and fTerImp <> tiFarm));
    104     result := (ArcticThurst * MP - 1) div RW[p].Model[mix].Speed + 1
     103    Assert((Tile and fTerImp <> tiIrrigation) and (Tile and fTerImp <> tiFarm));
     104    Result := (ArcticThurst * MP - 1) div RW[P].Model[mix].Speed + 1
    105105  end
    106106  else
    107     result := 0
    108 end;
    109 
    110 function Controlled(p, Loc: integer; IsDest: boolean): integer;
     107    Result := 0;
     108end;
     109
     110function Controlled(P, Loc: Integer; IsDest: Boolean): Integer;
    111111{ whether tile at Loc is in control zone of enemy unit
    112112  returns combination of tile control flags }
    113113var
    114   Loc1, V8: integer;
     114  Loc1, V8: Integer;
    115115  Adjacent: TVicinity8Loc;
    116116begin
    117   result := 0;
    118   if IsDest and (Occupant[Loc] = p) and (ZoCMap[Loc] > 0) then
    119     exit;
     117  Result := 0;
     118  if IsDest and (Occupant[Loc] = P) and (ZoCMap[Loc] > 0) then
     119    Exit;
    120120  // destination tile, not controlled if already occupied
    121121
    122   if (RealMap[Loc] and fCity = 0) or (integer(RealMap[Loc] shr 27) <> p) and
    123     (ServerVersion[p] >= $000EF0) then
     122  if (RealMap[Loc] and fCity = 0) or (Integer(RealMap[Loc] shr 27) <> P) and
     123    (ServerVersion[P] >= $000EF0) then
    124124  begin // not own city
    125125    V8_to_Loc(Loc, Adjacent);
     
    128128      Loc1 := Adjacent[V8];
    129129      if (Loc1 >= 0) and (Loc1 < MapSize) and (ZoCMap[Loc1] > 0) and
    130         (Occupant[Loc1] >= 0) and (Occupant[Loc1] <> p) and
    131         (RW[p].Treaty[Occupant[Loc1]] < trAlliance) then
    132         if ObserveLevel[Loc1] and (3 shl (p * 2)) > 0 then
     130        (Occupant[Loc1] >= 0) and (Occupant[Loc1] <> P) and
     131        (RW[P].Treaty[Occupant[Loc1]] < trAlliance) then
     132        if ObserveLevel[Loc1] and (3 shl (P * 2)) > 0 then
    133133        begin // p observes tile
    134           result := coKnown or coTrue;
    135           exit;
     134          Result := coKnown or coTrue;
     135          Exit;
    136136        end
    137137        else
    138           result := coTrue; // p does not observe tile
     138          Result := coTrue; // p does not observe tile
    139139    end;
    140140  end;
    141141end;
    142142
    143 function GetMoveCost(p, mix, FromLoc, ToLoc, MoveLength: integer;
    144   var MoveCost: integer): integer;
     143function GetMoveCost(P, mix, FromLoc, ToLoc, MoveLength: Integer;
     144  var MoveCost: Integer): Integer;
    145145// MoveLength - 2 for short move, 3 for long move
    146146var
    147   FromTile, ToTile: integer;
    148 begin
    149   result := eOK;
     147  FromTile, ToTile: Integer;
     148begin
     149  Result := eOK;
    150150  FromTile := RealMap[FromLoc];
    151151  ToTile := RealMap[ToLoc];
    152   with RW[p].Model[mix] do
     152  with RW[P].Model[mix] do
    153153  begin
    154154    case Domain of
     
    160160          if (FromTile and (fRR or fCity) <> 0) and
    161161            (ToTile and (fRR or fCity) <> 0) then
    162             if GWonder[woShinkansen].EffectiveOwner = p then
     162            if GWonder[woShinkansen].EffectiveOwner = P then
    163163              MoveCost := 0
    164164            else
     
    174174              MoveCost := 20
    175175          else if Cap[mcOver] > 0 then
    176             result := eNoRoad
     176            Result := eNoRoad
    177177          else
    178178            case Terrain[ToTile and fTerrain].MoveCost of
     
    181181              2:
    182182                begin
    183                   assert(Speed - 150 <= 600);
     183                  Assert(Speed - 150 <= 600);
    184184                  MoveCost := 50 + (Speed - 150) * 13 shr 7; // heavy terrain
    185185                end;
     
    187187                begin
    188188                  MoveCost := Speed;
    189                   result := eMountains;
    190                   exit;
     189                  Result := eMountains;
     190                  Exit;
    191191                end;
    192192            end;
     
    194194        end
    195195        else
    196           result := eDomainMismatch;
     196          Result := eDomainMismatch;
    197197
    198198      dSea:
     
    202202            MoveCost := 50 * MoveLength { valid move }
    203203          else
    204             result := eNoNav { navigation required for open sea }
    205         else
    206           result := eDomainMismatch;
     204            Result := eNoNav { navigation required for open sea }
     205        else
     206          Result := eDomainMismatch;
    207207
    208208      dAir:
     
    212212end;
    213213
    214 function CalculateMove(p, uix, ToLoc, MoveLength: integer; TestOnly: boolean;
    215   var MoveInfo: TMoveInfo): integer;
     214function CalculateMove(P, uix, ToLoc, MoveLength: Integer; TestOnly: Boolean;
     215  var MoveInfo: TMoveInfo): Integer;
    216216var
    217217  uix1, p1, FromLoc, DestControlled, AStr, DStr, ABaseDamage,
    218     DBaseDamage: integer;
     218    DBaseDamage: Integer;
    219219  PModel: ^TModel;
    220220  BattleForecast: TBattleForecast;
    221221begin
    222   with RW[p], Un[uix] do
     222  with RW[P], Un[uix] do
    223223  begin
    224224    PModel := @Model[mix];
    225225    FromLoc := Loc;
    226226
    227     BattleForecast.pAtt := p;
     227    BattleForecast.pAtt := P;
    228228    BattleForecast.mixAtt := mix;
    229229    BattleForecast.HealthAtt := Health;
     
    231231    BattleForecast.FlagsAtt := Flags;
    232232    BattleForecast.Movement := Movement;
    233     result := GetBattleForecast(ToLoc, BattleForecast, MoveInfo.Duix,
     233    Result := GetBattleForecast(ToLoc, BattleForecast, MoveInfo.Duix,
    234234      MoveInfo.Dcix, AStr, DStr, ABaseDamage, DBaseDamage);
    235235
    236     if result = eHiddenUnit then
     236    if Result = eHiddenUnit then
    237237      if TestOnly then
    238         result := eOK // behave just like unit was moving
     238        Result := eOK // behave just like unit was moving
    239239      else if Mode > moLoading_Fast then
    240240        Map[ToLoc] := Map[ToLoc] or fHiddenUnit;
    241     if result = eStealthUnit then
     241    if Result = eStealthUnit then
    242242      if TestOnly then
    243         result := eOK // behave just like unit was moving
     243        Result := eOK // behave just like unit was moving
    244244      else if Mode > moLoading_Fast then
    245245        Map[ToLoc] := Map[ToLoc] or fStealthUnit;
    246     if result < rExecuted then
    247       exit;
    248 
    249     case result of
     246    if Result < rExecuted then
     247      Exit;
     248
     249    case Result of
    250250      eOK:
    251251        MoveInfo.MoveType := mtMove;
     
    261261      begin
    262262        p1 := RealMap[ToLoc] shr 27;
    263         if (p1 < nPl) and (p1 <> p) and
     263        if (p1 < nPl) and (p1 <> P) and
    264264          ((RealMap[Loc] shr 27 <> Cardinal(p1)) and (PModel.Kind <> mkDiplomat)
    265265          and (Treaty[p1] >= trPeace) and (Treaty[p1] < trAlliance) or
    266266          (RealMap[ToLoc] and fCity <> 0) and (Treaty[p1] >= trPeace)) then
    267267        begin
    268           result := eTreaty;
    269           exit;
     268          Result := eTreaty;
     269          Exit;
    270270        end; // keep peace treaty!
    271271      end;
    272272      if (RealMap[ToLoc] and fCity <> 0) and
    273         (RealMap[ToLoc] shr 27 <> Cardinal(p)) then // empty enemy city
     273        (RealMap[ToLoc] shr 27 <> Cardinal(P)) then // empty enemy city
    274274        if PModel.Kind = mkDiplomat then
    275275        begin
     
    280280          if PModel.Flags and mdCivil <> 0 then
    281281          begin
    282             result := eNoCapturer;
    283             exit;
     282            Result := eNoCapturer;
     283            Exit;
    284284          end;
    285285          MoveInfo.MoveType := mtCapture;
     
    289289          if (PModel.Domain = dSea) and (PModel.Cap[mcArtillery] = 0) then
    290290          begin
    291             result := eDomainMismatch;
    292             exit;
     291            Result := eDomainMismatch;
     292            Exit;
    293293          end
    294294          else if (PModel.Attack = 0) and
     
    296296          then
    297297          begin
    298             result := eNoBombarder;
    299             exit;
     298            Result := eNoBombarder;
     299            Exit;
    300300          end
    301301          else if Movement < 100 then
    302302          begin
    303             result := eNoTime_Bombard;
    304             exit;
     303            Result := eNoTime_Bombard;
     304            Exit;
    305305          end;
    306306          MoveInfo.MoveType := mtBombard;
    307           result := eBombarded;
    308         end;
    309     end;
    310 
    311     MoveInfo.MountainDelay := false;
     307          Result := eBombarded;
     308        end;
     309    end;
     310
     311    MoveInfo.MountainDelay := False;
    312312    if MoveInfo.MoveType in [mtAttack, mtBombard, mtExpel] then
    313313    begin
     
    317317      then
    318318      begin
    319         result := eViolation;
    320         exit
     319        Result := eViolation;
     320        Exit;
    321321      end;
    322322      if MoveInfo.MoveType = mtBombard then
     
    337337        MoveInfo.Cost := PModel.Speed;
    338338        if RealMap[ToLoc] and fTerrain < fGrass then
    339           result := eDomainMismatch;
     339          Result := eDomainMismatch;
    340340      end
    341341      else
    342342      begin
    343         result := GetMoveCost(p, mix, FromLoc, ToLoc, MoveLength,
     343        Result := GetMoveCost(P, mix, FromLoc, ToLoc, MoveLength,
    344344          MoveInfo.Cost);
    345         if result = eMountains then
    346         begin
    347           result := eOK;
    348           MoveInfo.MountainDelay := true
     345        if Result = eMountains then
     346        begin
     347          Result := eOK;
     348          MoveInfo.MountainDelay := True
    349349        end;
    350350      end;
    351       if (result >= rExecuted) and (MoveInfo.MoveType = mtSpyMission) then
    352         result := eMissionDone;
     351      if (Result >= rExecuted) and (MoveInfo.MoveType = mtSpyMission) then
     352        Result := eMissionDone;
    353353
    354354      MoveInfo.ToMaster := -1;
    355       if (result = eDomainMismatch) and (PModel.Domain < dSea) and
     355      if (Result = eDomainMismatch) and (PModel.Domain < dSea) and
    356356        (PModel.Cap[mcOver] = 0) then
    357357      begin
     
    361361              (TroopLoad < Model[mix].MTrans * Model[mix].Cap[mcSeaTrans]) then
    362362            begin
    363               result := eLoaded;
     363              Result := eLoaded;
    364364              MoveInfo.Cost := PModel.Speed;
    365365              MoveInfo.ToMaster := uix1;
     
    378378              (AirLoad < Model[mix].MTrans * Model[mix].Cap[mcCarrier]) then
    379379            begin // load plane to ship
    380               result := eLoaded;
     380              Result := eLoaded;
    381381              MoveInfo.ToMaster := uix1;
    382382              if (uixSelectedTransport >= 0) and (uix1 = uixSelectedTransport)
     
    385385            end;
    386386      end;
    387       if result < rExecuted then
    388         exit;
     387      if Result < rExecuted then
     388        Exit;
    389389
    390390      if (Master < 0) and (MoveInfo.ToMaster < 0) then
    391         MoveInfo.EndHealth := Health - HostileDamage(p, mix, ToLoc,
     391        MoveInfo.EndHealth := Health - HostileDamage(P, mix, ToLoc,
    392392          MoveInfo.Cost)
    393393      else
     
    395395
    396396      if (Mode = moPlaying) and (PModel.Flags and mdZOC <> 0) and (Master < 0)
    397         and (MoveInfo.ToMaster < 0) and (Controlled(p, FromLoc, false) >= coTrue)
     397        and (MoveInfo.ToMaster < 0) and (Controlled(P, FromLoc, False) >= coTrue)
    398398      then
    399399      begin
    400         DestControlled := Controlled(p, ToLoc, true);
     400        DestControlled := Controlled(P, ToLoc, True);
    401401        if DestControlled >= coTrue + coKnown then
    402402        begin
    403           result := eZOC;
    404           exit;
     403          Result := eZOC;
     404          Exit;
    405405        end
    406406        else if not TestOnly and (DestControlled >= coTrue) then
    407407        begin
    408           result := eZOC_EnemySpotted;
    409           exit;
     408          Result := eZOC_EnemySpotted;
     409          Exit;
    410410        end;
    411411      end;
    412       if (Movement = 0) and (ServerVersion[p] >= $0100F1) or
     412      if (Movement = 0) and (ServerVersion[P] >= $0100F1) or
    413413        (MoveInfo.Cost > Movement) then
    414414        if (Master >= 0) or (MoveInfo.ToMaster >= 0) then
    415415        begin
    416           result := eNoTime_Load;
    417           exit;
     416          Result := eNoTime_Load;
     417          Exit;
    418418        end
    419419        else
    420420        begin
    421           result := eNoTime_Move;
    422           exit;
     421          Result := eNoTime_Move;
     422          Exit;
    423423        end;
    424424      if (MoveInfo.EndHealth <= 0) or (MoveInfo.MoveType = mtSpyMission) then
    425         result := result or rUnitRemoved;
     425        Result := Result or rUnitRemoved;
    426426      // spy mission or victim of HostileDamage
    427427
     
    438438end;
    439439
    440 function GetBattleForecast(Loc: integer; var BattleForecast: TBattleForecast;
    441   var Duix, Dcix, AStr, DStr, ABaseDamage, DBaseDamage: integer): integer;
    442 var
    443   Time, Defender, ABon, DBon, DCnt, MultiDamage: integer;
     440function GetBattleForecast(Loc: Integer; var BattleForecast: TBattleForecast;
     441  var Duix, Dcix, AStr, DStr, ABaseDamage, DBaseDamage: Integer): Integer;
     442var
     443  Time, Defender, ABon, DBon, DCnt, MultiDamage: Integer;
    444444  PModel, DModel: ^TModel;
    445445begin
     
    449449    if (Defender < 0) or (Defender = pAtt) then
    450450    begin
    451       result := eOK;
    452       exit;
     451      Result := eOK;
     452      Exit;
    453453    end; // no attack, simple move
    454454
     
    459459      EndHealthAtt := HealthAtt;
    460460      EndHealthDef := RW[Defender].Un[Duix].Health;
    461       result := eOK;
    462       exit;
     461      Result := eOK;
     462      Exit;
    463463    end;
    464464
     
    470470        (ObserveLevel[Loc] shr (2 * pAtt) and 3 < lObserveAll) then
    471471      begin
    472         result := eHiddenUnit;
    473         exit;
     472        Result := eHiddenUnit;
     473        Exit;
    474474      end; // attacking submarine not allowed
    475475      if (DModel.Cap[mcStealth] > 0) and
    476476        (ObserveLevel[Loc] shr (2 * pAtt) and 3 <> lObserveSuper) then
    477477      begin
    478         result := eStealthUnit;
    479         exit;
     478        Result := eStealthUnit;
     479        Exit;
    480480      end; // attacking stealth aircraft not allowed
    481481      if (DModel.Domain = dAir) and (DModel.Kind <> mkSpecial_Glider) and
    482482        (PModel.Domain <> dAir) then
    483483      begin
    484         result := eDomainMismatch;
    485         exit;
     484        Result := eDomainMismatch;
     485        Exit;
    486486      end; // can't attack plane
    487487    end;
     
    492492      (PModel.Domain = dSea) and (RealMap[Loc] and fTerrain >= fGrass)) then
    493493    begin
    494       result := eDomainMismatch;
    495       exit;
     494      Result := eDomainMismatch;
     495      Exit;
    496496    end;
    497497    if (PModel.Attack = 0) and not((PModel.Cap[mcBombs] > 0) and
    498498      (FlagsAtt and unBombsLoaded <> 0) and (DModel.Domain < dAir)) then
    499499    begin
    500       result := eInvalid;
    501       exit;
     500      Result := eInvalid;
     501      Exit;
    502502    end;
    503503
    504504    if Movement = 0 then
    505505    begin
    506       result := eNoTime_Attack;
    507       exit;
    508     end;
    509 
    510 {$IFOPT O-}assert(InvalidTreatyMap = 0); {$ENDIF}
     506      Result := eNoTime_Attack;
     507      Exit;
     508    end;
     509
     510{$IFOPT O-}Assert(InvalidTreatyMap = 0); {$ENDIF}
    511511    if RW[pAtt].Treaty[Defender] >= trPeace then
    512512    begin
    513513      if (PModel.Domain <> dAir) and (PModel.Attack > 0) and
    514         (integer(RealMap[Loc] shr 27) = pAtt) then
     514        (Integer(RealMap[Loc] shr 27) = pAtt) then
    515515        if Movement >= 100 then
    516516        begin // expel friendly unit
    517517          EndHealthDef := RW[Defender].Un[Duix].Health;
    518518          EndHealthAtt := HealthAtt;
    519           result := eExpelled
     519          Result := eExpelled
    520520        end
    521521        else
    522           result := eNoTime_Expel
     522          Result := eNoTime_Expel
    523523      else
    524         result := eTreaty;
    525       exit;
     524        Result := eTreaty;
     525      Exit;
    526526    end;
    527527
     
    534534        (Continent[RW[Defender].City[Dcix].Loc] = GrWallContinent[Defender]))
    535535      then
    536         inc(DBon, 8)
     536        Inc(DBon, 8)
    537537      else if (PModel.Domain = dSea) and
    538538        (RW[Defender].City[Dcix].Built[imCoastalFort] = 1) then
    539         inc(DBon, 4)
     539        Inc(DBon, 4)
    540540      else if (PModel.Domain = dAir) and
    541541        (RW[Defender].City[Dcix].Built[imMissileBat] = 1) then
    542         inc(DBon, 4);
     542        Inc(DBon, 4);
    543543      if RW[Defender].City[Dcix].Built[imBunker] = 1 then
    544         inc(DBon, 4)
     544        Inc(DBon, 4)
    545545    end;
    546546    if (PModel.Domain = dAir) and (DModel.Cap[mcAirDef] > 0) then
    547       inc(DBon, 4);
     547      Inc(DBon, 4);
    548548    DStr := DModel.Defense * DBon * 100;
    549549    if (DModel.Domain = dAir) and ((RealMap[Loc] and fCity <> 0) or
     
    622622
    623623    if EndHealthDef > 0 then
    624       result := eLost
     624      Result := eLost
    625625    else if EndHealthAtt > 0 then
    626       result := eWon
     626      Result := eWon
    627627    else
    628       result := eBloody;
     628      Result := eBloody;
    629629  end;
    630630end;
    631631
    632 function LoadUnit(p, uix: integer; TestOnly: boolean): integer;
    633 var
    634   uix1, d, Cost, ToMaster: integer;
    635 begin
    636   result := eOK;
    637   with RW[p].Un[uix] do
    638   begin
    639     d := RW[p].Model[mix].Domain;
    640     if (Master >= 0) or (d = dSea) or
    641       (RW[p].Model[mix].Cap[mcAirTrans] + RW[p].Model[mix].Cap[mcOver] > 0) then
    642       result := eViolation
     632function LoadUnit(P, uix: Integer; TestOnly: Boolean): Integer;
     633var
     634  uix1, D, Cost, ToMaster: Integer;
     635begin
     636  Result := eOK;
     637  with RW[P].Un[uix] do
     638  begin
     639    D := RW[P].Model[mix].Domain;
     640    if (Master >= 0) or (D = dSea) or
     641      (RW[P].Model[mix].Cap[mcAirTrans] + RW[P].Model[mix].Cap[mcOver] > 0) then
     642      Result := eViolation
    643643    else
    644644    begin
    645645      ToMaster := -1;
    646       for uix1 := 0 to RW[p].nUn - 1 do
    647         if RW[p].Un[uix1].Loc = Loc then
    648           with RW[p].Un[uix1], RW[p].Model[mix] do
    649             if (d < dSea) and
     646      for uix1 := 0 to RW[P].nUn - 1 do
     647        if RW[P].Un[uix1].Loc = Loc then
     648          with RW[P].Un[uix1], RW[P].Model[mix] do
     649            if (D < dSea) and
    650650              (TroopLoad < MTrans * (Cap[mcSeaTrans] + Cap[mcAirTrans])) or
    651               (d = dAir) and (AirLoad < MTrans * Cap[mcCarrier]) then
     651              (D = dAir) and (AirLoad < MTrans * Cap[mcCarrier]) then
    652652            begin { load onto unit uix1 }
    653653              if (uixSelectedTransport < 0) or (uix1 = uixSelectedTransport)
     
    661661            end;
    662662      if ToMaster < 0 then
    663         result := eNoLoadCapacity
     663        Result := eNoLoadCapacity
    664664      else
    665665      begin
    666         if d = dAir then
     666        if D = dAir then
    667667          Cost := 100
    668668        else
    669           Cost := RW[p].Model[mix].Speed;
     669          Cost := RW[P].Model[mix].Speed;
    670670        if Movement < Cost then
    671           result := eNoTime_Load
     671          Result := eNoTime_Load
    672672        else if not TestOnly then
    673673        begin
    674           FreeUnit(p, uix);
    675           dec(Movement, Cost);
    676           if d = dAir then
    677             inc(RW[p].Un[ToMaster].AirLoad)
     674          FreeUnit(P, uix);
     675          Dec(Movement, Cost);
     676          if D = dAir then
     677            Inc(RW[P].Un[ToMaster].AirLoad)
    678678          else
    679             inc(RW[p].Un[ToMaster].TroopLoad);
     679            Inc(RW[P].Un[ToMaster].TroopLoad);
    680680          Master := ToMaster;
    681681          UpdateUnitMap(Loc);
     
    686686end;
    687687
    688 function UnloadUnit(p, uix: integer; TestOnly: boolean): integer;
    689 var
    690   Cost: integer;
    691 begin
    692   result := eOK;
    693   with RW[p].Un[uix] do
     688function UnloadUnit(P, uix: Integer; TestOnly: Boolean): Integer;
     689var
     690  Cost: Integer;
     691begin
     692  Result := eOK;
     693  with RW[P].Un[uix] do
    694694    if Master < 0 then
    695       result := eNotChanged
    696     else if (RW[p].Model[mix].Domain < dSea) and
     695      Result := eNotChanged
     696    else if (RW[P].Model[mix].Domain < dSea) and
    697697      (RealMap[Loc] and fTerrain < fGrass) then
    698       result := eDomainMismatch
     698      Result := eDomainMismatch
    699699      // else if (RW[p].Model[mix].Domain<dSea)
    700700      // and (RW[p].Model[mix].Flags and mdCivil<>0)
     
    702702    else
    703703    begin
    704       if RW[p].Model[mix].Domain = dAir then
     704      if RW[P].Model[mix].Domain = dAir then
    705705        Cost := 100
    706706      else
    707         Cost := RW[p].Model[mix].Speed;
     707        Cost := RW[P].Model[mix].Speed;
    708708      if Movement < Cost then
    709         result := eNoTime_Load
     709        Result := eNoTime_Load
    710710      else if not TestOnly then
    711711      begin
    712         dec(Movement, Cost);
    713         if RW[p].Model[mix].Domain = dAir then
    714           dec(RW[p].Un[Master].AirLoad)
    715         else
    716         begin
    717           dec(RW[p].Un[Master].TroopLoad);
     712        Dec(Movement, Cost);
     713        if RW[P].Model[mix].Domain = dAir then
     714          Dec(RW[P].Un[Master].AirLoad)
     715        else
     716        begin
     717          Dec(RW[P].Un[Master].TroopLoad);
    718718          // Movement:=0 // no more movement after unload
    719719        end;
    720720        Master := -1;
    721         PlaceUnit(p, uix);
     721        PlaceUnit(P, uix);
    722722        UpdateUnitMap(Loc);
    723723      end;
     
    725725end;
    726726
    727 procedure Recover(p, uix: integer);
    728 var
    729   cix, Recovery: integer;
    730 begin
    731   with RW[p], Un[uix] do
     727procedure Recover(P, uix: Integer);
     728var
     729  cix, Recovery: Integer;
     730begin
     731  with RW[P], Un[uix] do
    732732  begin
    733733    if (Master >= 0) and (Model[Un[Master].mix].Cap[mcSupplyShip] > 0) then
     
    739739      cix := nCity - 1;
    740740      while (cix >= 0) and (City[cix].Loc <> Loc) do
    741         dec(cix);
     741        Dec(cix);
    742742      if City[cix].Flags and chDisorder <> 0 then
    743743        Recovery := NoCityRecovery
     
    762762    if Recovery > 100 - Health then
    763763      Recovery := 100 - Health;
    764     inc(Health, Recovery);
     764    Inc(Health, Recovery);
    765765  end;
    766766end;
    767767
    768 function GetMoveAdvice(p, uix: integer; var a: TMoveAdviceData): integer;
     768function GetMoveAdvice(P, uix: Integer; var A: TMoveAdviceData): Integer;
    769769const
    770770  // domains
     
    778778  gmaAlpine = 8;
    779779var
    780   i, FromLoc, EndLoc, T, T1, maxmov, initmov, Loc, Loc1, FromTile, ToTile, V8,
     780  I, FromLoc, EndLoc, T, T1, maxmov, initmov, Loc, Loc1, FromTile, ToTile, V8,
    781781    MoveInfo, HeavyCost, RailCost, MoveCost, AddDamage, MaxDamage,
    782     MovementLeft: integer;
     782    MovementLeft: Integer;
    783783  Map: ^TTileList;
    784784  Q: TIPQ;
    785785  Adjacent: TVicinity8Loc;
    786   From: array [0 .. lxmax * lymax - 1] of integer;
    787   Time: array [0 .. lxmax * lymax - 1] of integer;
    788   Damage: array [0 .. lxmax * lymax - 1] of integer;
    789   MountainDelay, Resistant: boolean;
     786  From: array [0 .. lxmax * lymax - 1] of Integer;
     787  Time: array [0 .. lxmax * lymax - 1] of Integer;
     788  Damage: array [0 .. lxmax * lymax - 1] of Integer;
     789  MountainDelay, Resistant: Boolean;
    790790  // tt,tt0: int64;
    791791begin
    792792  // QueryPerformanceCounter(tt0);
    793793
    794   MaxDamage := RW[p].Un[uix].Health - 1;
    795   if MaxDamage > a.MaxHostile_MovementLeft then
    796     if a.MaxHostile_MovementLeft >= 0 then
    797       MaxDamage := a.MaxHostile_MovementLeft
     794  MaxDamage := RW[P].Un[uix].Health - 1;
     795  if MaxDamage > A.MaxHostile_MovementLeft then
     796    if A.MaxHostile_MovementLeft >= 0 then
     797      MaxDamage := A.MaxHostile_MovementLeft
    798798    else
    799799      MaxDamage := 0;
    800800
    801   Map := @(RW[p].Map^);
    802   if (a.ToLoc <> maNextCity) and ((a.ToLoc < 0) or (a.ToLoc >= MapSize)) then
    803   begin
    804     result := eInvalid;
    805     exit;
     801  Map := @(RW[P].Map^);
     802  if (A.ToLoc <> maNextCity) and ((A.ToLoc < 0) or (A.ToLoc >= MapSize)) then
     803  begin
     804    Result := eInvalid;
     805    Exit;
    806806  end;
    807   if (a.ToLoc <> maNextCity) and (Map[a.ToLoc] and fTerrain = fUNKNOWN) then
    808   begin
    809     result := eNoWay;
    810     exit;
     807  if (A.ToLoc <> maNextCity) and (Map[A.ToLoc] and fTerrain = fUNKNOWN) then
     808  begin
     809    Result := eNoWay;
     810    Exit;
    811811  end;
    812812
    813   with RW[p].Model[RW[p].Un[uix].mix] do
     813  with RW[P].Model[RW[P].Un[uix].mix] do
    814814    case Domain of
    815815      dGround:
    816         if (a.ToLoc <> maNextCity) and (Map[a.ToLoc] and fTerrain = fOcean) then
    817         begin
    818           result := eDomainMismatch;
    819           exit;
     816        if (A.ToLoc <> maNextCity) and (Map[A.ToLoc] and fTerrain = fOcean) then
     817        begin
     818          Result := eDomainMismatch;
     819          Exit;
    820820        end
    821821        else
     
    826826            MoveInfo := gmaGround_NoZoC;
    827827          if Cap[mcOver] > 0 then
    828             inc(MoveInfo, gmaOver);
     828            Inc(MoveInfo, gmaOver);
    829829          if Cap[mcAlpine] > 0 then
    830             inc(MoveInfo, gmaAlpine);
     830            Inc(MoveInfo, gmaAlpine);
    831831          HeavyCost := 50 + (Speed - 150) * 13 shr 7;
    832           if GWonder[woShinkansen].EffectiveOwner = p then
     832          if GWonder[woShinkansen].EffectiveOwner = P then
    833833            RailCost := 0
    834834          else
     
    836836          maxmov := Speed;
    837837          initmov := 0;
    838           Resistant := (GWonder[woGardens].EffectiveOwner = p) or
     838          Resistant := (GWonder[woGardens].EffectiveOwner = P) or
    839839            (Kind = mkSettler) and (Speed >= 200);
    840840        end;
    841841      dSea:
    842         if (a.ToLoc <> maNextCity) and (Map[a.ToLoc] and fTerrain >= fGrass) and
    843           (Map[a.ToLoc] and (fCity or fUnit or fCanal) = 0) then
    844         begin
    845           result := eDomainMismatch;
    846           exit;
     842        if (A.ToLoc <> maNextCity) and (Map[A.ToLoc] and fTerrain >= fGrass) and
     843          (Map[A.ToLoc] and (fCity or fUnit or fCanal) = 0) then
     844        begin
     845          Result := eDomainMismatch;
     846          Exit;
    847847        end
    848848        else
     
    850850          MoveInfo := gmaSea;
    851851          if Cap[mcNav] > 0 then
    852             inc(MoveInfo, gmaNav);
    853           maxmov := UnitSpeed(p, RW[p].Un[uix].mix, 100);
    854           initmov := maxmov - UnitSpeed(p, RW[p].Un[uix].mix,
    855             RW[p].Un[uix].Health);
     852            Inc(MoveInfo, gmaNav);
     853          maxmov := UnitSpeed(P, RW[P].Un[uix].mix, 100);
     854          initmov := maxmov - UnitSpeed(P, RW[P].Un[uix].mix,
     855            RW[P].Un[uix].Health);
    856856        end;
    857857      dAir:
     
    863863    end;
    864864
    865   FromLoc := RW[p].Un[uix].Loc;
     865  FromLoc := RW[P].Un[uix].Loc;
    866866  FillChar(Time, SizeOf(Time), 255); { -1 }
    867867  Damage[FromLoc] := 0;
    868868  Q := TIPQ.Create(MapSize);
    869   Q.Put(FromLoc, (maxmov - RW[p].Un[uix].Movement) shl 8);
     869  Q.Put(FromLoc, (maxmov - RW[P].Un[uix].Movement) shl 8);
    870870  while Q.Get(Loc, T) do
    871871  begin
    872872    Time[Loc] := T;
    873     if T >= (a.MoreTurns + 1) shl 20 then
     873    if T >= (A.MoreTurns + 1) shl 20 then
    874874    begin
    875875      Loc := -1;
     
    877877    end;
    878878    FromTile := Map[Loc];
    879     if (Loc = a.ToLoc) or (a.ToLoc = maNextCity) and (FromTile and fCity <> 0)
     879    if (Loc = A.ToLoc) or (A.ToLoc = maNextCity) and (FromTile and fCity <> 0)
    880880    then
    881881      Break;
    882882    if T and $FFF00 = $FFF00 then
    883       inc(T, $100000); // indicates mountain delay
     883      Inc(T, $100000); // indicates mountain delay
    884884    V8_to_Loc(Loc, Adjacent);
    885885    for V8 := 0 to 7 do
     
    889889      begin
    890890        ToTile := Map[Loc1];
    891         if (Loc1 = a.ToLoc) and (ToTile and (fUnit or fOwned) = fUnit) and
     891        if (Loc1 = A.ToLoc) and (ToTile and (fUnit or fOwned) = fUnit) and
    892892          not((MoveInfo and 3 = gmaSea) and (FromTile and fTerrain >= fGrass))
    893893          and not((MoveInfo and 3 = gmaAir) and ((FromTile and fCity <> 0) or
     
    898898        end
    899899        else if (ToTile and fTerrain <> fUNKNOWN) and
    900           ((Loc1 = a.ToLoc) or (ToTile and (fCity or fOwned) <> fCity))
     900          ((Loc1 = A.ToLoc) or (ToTile and (fCity or fOwned) <> fCity))
    901901        // don't move through enemy cities
    902           and ((Loc1 = a.ToLoc) or (ToTile and (fUnit or fOwned) <> fUnit))
     902          and ((Loc1 = A.ToLoc) or (ToTile and (fUnit or fOwned) <> fUnit))
    903903        // way is blocked
    904904          and (ToTile and not FromTile and fPeace = 0) and
     
    910910          // calculate move cost, must be identic to GetMoveCost function
    911911          AddDamage := 0;
    912           MountainDelay := false;
     912          MountainDelay := False;
    913913          case MoveInfo of
    914914
     
    956956                    begin
    957957                      MoveCost := maxmov;
    958                       MountainDelay := true;
     958                      MountainDelay := True;
    959959                    end;
    960960                end;
     
    990990          if (MoveCost > 0) and not MountainDelay then
    991991            if V8 and 1 <> 0 then
    992               inc(MoveCost, MoveCost * 2)
     992              Inc(MoveCost, MoveCost * 2)
    993993            else
    994               inc(MoveCost, MoveCost);
     994              Inc(MoveCost, MoveCost);
    995995
    996996          if (MoveInfo and 2 <> 0) // ground unit, check transport load/unload
     
    10111011                if FromTile and (fTerrain or fCity or fRiver or fCanal or
    10121012                  fSpecial1 { Oasis } ) = fDesert then
    1013                   inc(AddDamage, (DesertThurst * (maxmov - T shr 8 and $FFF) -
     1013                  Inc(AddDamage, (DesertThurst * (maxmov - T shr 8 and $FFF) -
    10141014                    1) div maxmov + 1)
    10151015                else if FromTile and (fTerrain or fCity or fRiver or fCanal) = fArctic
    10161016                then
    1017                   inc(AddDamage, (ArcticThurst * (maxmov - T shr 8 and $FFF) -
     1017                  Inc(AddDamage, (ArcticThurst * (maxmov - T shr 8 and $FFF) -
    10181018                    1) div maxmov + 1);
    10191019
     
    10371037  end;
    10381038  FreeAndNil(Q);
    1039   if (Loc = a.ToLoc) or (a.ToLoc = maNextCity) and (Loc >= 0) and
     1039  if (Loc = A.ToLoc) or (A.ToLoc = maNextCity) and (Loc >= 0) and
    10401040    (Map[Loc] and fCity <> 0) then
    10411041  begin
    1042     a.MoreTurns := T shr 20;
     1042    A.MoreTurns := T shr 20;
    10431043    EndLoc := Loc;
    1044     a.nStep := 0;
     1044    A.nStep := 0;
    10451045    while Loc <> FromLoc do
    10461046    begin
    10471047      if Time[Loc] < $100000 then
    1048         inc(a.nStep);
     1048        Inc(A.nStep);
    10491049      Loc := From[Loc];
    10501050    end;
    10511051    Loc := EndLoc;
    1052     i := a.nStep;
     1052    I := A.nStep;
    10531053    while Loc <> FromLoc do
    10541054    begin
    10551055      if Time[Loc] < $100000 then
    10561056      begin
    1057         dec(i);
    1058         if i < 25 then
    1059         begin
    1060           a.dx[i] := ((Loc mod lx * 2 + Loc div lx and 1) -
     1057        Dec(I);
     1058        if I < 25 then
     1059        begin
     1060          A.dx[I] := ((Loc mod lx * 2 + Loc div lx and 1) -
    10611061            (From[Loc] mod lx * 2 + From[Loc] div lx and 1) + 3 * lx)
    10621062            mod (2 * lx) - lx;
    1063           a.dy[i] := Loc div lx - From[Loc] div lx;
     1063          A.dy[I] := Loc div lx - From[Loc] div lx;
    10641064        end
    10651065      end;
    10661066      Loc := From[Loc];
    10671067    end;
    1068     a.MaxHostile_MovementLeft := maxmov - Time[EndLoc] shr 8 and $FFF;
    1069     if a.nStep > 25 then
    1070       a.nStep := 25;
    1071     result := eOK
     1068    A.MaxHostile_MovementLeft := maxmov - Time[EndLoc] shr 8 and $FFF;
     1069    if A.nStep > 25 then
     1070      A.nStep := 25;
     1071    Result := eOK
    10721072  end
    10731073  else
    1074     result := eNoWay;
     1074    Result := eNoWay;
    10751075
    10761076  // QueryPerformanceCounter(tt);{time in s is: (tt-tt0)/PerfFreq}
    10771077end;
    10781078
    1079 function CanPlaneReturn(p, uix: integer;
    1080   PlaneReturnData: TPlaneReturnData): boolean;
     1079function CanPlaneReturn(P, uix: Integer;
     1080  PlaneReturnData: TPlaneReturnData): Boolean;
    10811081const
    10821082  mfEnd = 1;
    10831083  mfReached = 2;
    10841084var
    1085   uix1, T, T1, Loc, Loc1, FromTile, ToTile, V8, MoveCost, maxmov: integer;
     1085  uix1, T, T1, Loc, Loc1, FromTile, ToTile, V8, MoveCost, maxmov: Integer;
    10861086  Map: ^TTileList;
    10871087  Q: TIPQ;
    10881088  Adjacent: TVicinity8Loc;
    1089   MapFlags: array [0 .. lxmax * lymax - 1] of byte;
    1090 begin
    1091   Map := @(RW[p].Map^);
     1089  MapFlags: array [0 .. lxmax * lymax - 1] of Byte;
     1090begin
     1091  Map := @(RW[P].Map^);
    10921092
    10931093  // calculate possible return points
    10941094  FillChar(MapFlags, SizeOf(MapFlags), 0);
    1095   if RW[p].Model[RW[p].Un[uix].mix].Kind = mkSpecial_Glider then
     1095  if RW[P].Model[RW[P].Un[uix].mix].Kind = mkSpecial_Glider then
    10961096  begin
    10971097    for Loc := 0 to MapSize - 1 do
     
    11061106        (Map[Loc] and (fUnit or fOwned) <> fUnit) then
    11071107        MapFlags[Loc] := MapFlags[Loc] or mfEnd;
    1108     if RW[p].Model[RW[p].Un[uix].mix].Cap[mcAirTrans] = 0 then
     1108    if RW[P].Model[RW[P].Un[uix].mix].Cap[mcAirTrans] = 0 then
    11091109    // plane can land on carriers
    1110       for uix1 := 0 to RW[p].nUn - 1 do
    1111         with RW[p].Un[uix1], RW[p].Model[mix] do
     1110      for uix1 := 0 to RW[P].nUn - 1 do
     1111        with RW[P].Un[uix1], RW[P].Model[mix] do
    11121112          if AirLoad < MTrans * Cap[mcCarrier] then
    11131113            MapFlags[Loc] := MapFlags[Loc] or mfEnd;
    11141114  end;
    11151115
    1116   with RW[p].Un[uix] do
     1116  with RW[P].Un[uix] do
    11171117  begin
    11181118    if Master >= 0 then // can return to same carrier, even if full now
    11191119      MapFlags[Loc] := MapFlags[Loc] or mfEnd;
    1120     maxmov := RW[p].Model[mix].Speed;
     1120    maxmov := RW[P].Model[mix].Speed;
    11211121  end;
    11221122
    1123   result := false;
     1123  Result := False;
    11241124  Q := TIPQ.Create(MapSize);
    11251125  Q.Put(PlaneReturnData.Loc, (maxmov - PlaneReturnData.Movement) shl 8);
     
    11291129    if T >= (PlaneReturnData.Fuel + 1) shl 20 then
    11301130    begin
    1131       result := false;
     1131      Result := False;
    11321132      Break;
    11331133    end;
    11341134    if MapFlags[Loc] and mfEnd <> 0 then
    11351135    begin
    1136       result := true;
     1136      Result := True;
    11371137      Break;
    11381138    end;
     
    11731173  ____________________________________________________________________
    11741174}
    1175 function CalculateJobWork(p, Loc, Job: integer; var JobWork: integer): integer;
    1176 var
    1177   TerrType: integer;
    1178 begin
    1179   result := eOK;
     1175function CalculateJobWork(P, Loc, Job: Integer; var JobWork: Integer): Integer;
     1176var
     1177  TerrType: Integer;
     1178begin
     1179  Result := eOK;
    11801180  TerrType := RealMap[Loc] and fTerrain;
    11811181  with Terrain[TerrType] do
     
    11831183      jCity:
    11841184        if RealMap[Loc] and fCity <> 0 then
    1185           result := eInvalid
     1185          Result := eInvalid
    11861186        else if IrrEff = 0 then
    1187           result := eNoCityTerrain
     1187          Result := eNoCityTerrain
    11881188        else
    11891189          JobWork := CityWork;
     
    11931193          JobWork := MoveCost * RoadWork;
    11941194          if RealMap[Loc] and fRiver <> 0 then
    1195             if RW[p].Tech[adBridgeBuilding] >= tsApplicable then
    1196               inc(JobWork, RoadBridgeWork) { across river }
     1195            if RW[P].Tech[adBridgeBuilding] >= tsApplicable then
     1196              Inc(JobWork, RoadBridgeWork) { across river }
    11971197            else
    1198               result := eNoBridgeBuilding;
     1198              Result := eNoBridgeBuilding;
    11991199        end
    12001200        else
    1201           result := eInvalid;
     1201          Result := eInvalid;
    12021202      jRR:
    12031203        if RealMap[Loc] and fRoad = 0 then
    1204           result := eNoPreq
     1204          Result := eNoPreq
    12051205        else if RealMap[Loc] and fRR <> 0 then
    1206           result := eInvalid
     1206          Result := eInvalid
    12071207        else
    12081208        begin
    12091209          JobWork := MoveCost * RRWork;
    12101210          if RealMap[Loc] and fRiver <> 0 then
    1211             inc(JobWork, RRBridgeWork); { across river }
     1211            Inc(JobWork, RRBridgeWork); { across river }
    12121212        end;
    12131213      jClear:
    1214         if (TerrType = fDesert) and (GWonder[woGardens].EffectiveOwner <> p)
     1214        if (TerrType = fDesert) and (GWonder[woGardens].EffectiveOwner <> P)
    12151215        then
    1216           result := eInvalid
     1216          Result := eInvalid
    12171217        else if ClearTerrain >= 0 then
    12181218          JobWork := IrrClearWork
    12191219        else
    1220           result := eInvalid;
     1220          Result := eInvalid;
    12211221      jIrr:
    12221222        begin
     
    12241224          if (IrrEff = 0) or (RealMap[Loc] and fTerImp = tiIrrigation) or
    12251225            (RealMap[Loc] and fTerImp = tiFarm) then
    1226             result := eInvalid;
     1226            Result := eInvalid;
    12271227        end;
    12281228      jFarm:
    12291229        if RealMap[Loc] and fTerImp <> tiIrrigation then
    1230           result := eNoPreq
     1230          Result := eNoPreq
    12311231        else
    12321232        begin
    12331233          JobWork := IrrClearWork * FarmWork;
    12341234          if (JobWork <= 0) or (RealMap[Loc] and fTerImp = tiFarm) then
    1235             result := eInvalid;
     1235            Result := eInvalid;
    12361236        end;
    12371237      jAfforest:
     
    12391239          JobWork := MineAfforestWork
    12401240        else
    1241           result := eInvalid;
     1241          Result := eInvalid;
    12421242      jMine:
    12431243        begin
    12441244          JobWork := MineAfforestWork;
    12451245          if (MineEff = 0) or (RealMap[Loc] and fTerImp = tiMine) then
    1246             result := eInvalid;
     1246            Result := eInvalid;
    12471247        end;
    12481248      jFort:
     
    12501250          JobWork := MoveCost * FortWork
    12511251        else
    1252           result := eInvalid;
     1252          Result := eInvalid;
    12531253      jCanal:
    12541254        if (RealMap[Loc] and fCanal = 0) and (TerrType in TerrType_Canalable)
     
    12561256          JobWork := CanalWork
    12571257        else
    1258           result := eInvalid;
     1258          Result := eInvalid;
    12591259      jTrans:
    12601260        begin
    12611261          JobWork := TransWork;
    12621262          if JobWork <= 0 then
    1263             result := eInvalid;
     1263            Result := eInvalid;
    12641264        end;
    12651265      jPoll:
     
    12671267          JobWork := PollWork
    12681268        else
    1269           result := eInvalid;
     1269          Result := eInvalid;
    12701270      jBase:
    12711271        if RealMap[Loc] and fTerImp <> tiBase then
    12721272          JobWork := MoveCost * BaseWork
    12731273        else
    1274           result := eInvalid;
     1274          Result := eInvalid;
    12751275      jPillage:
    12761276        if RealMap[Loc] and (fRoad or fRR or fCanal or fTerImp) <> 0 then
    12771277          JobWork := PillageWork
    12781278        else
    1279           result := eInvalid;
    1280     end;
    1281 end;
    1282 
    1283 function StartJob(p, uix, NewJob: integer; TestOnly: boolean): integer;
    1284 var
    1285   JobWork, Loc0, p1, uix1, TerrType: integer;
    1286 begin
    1287 {$IFOPT O-}assert(1 shl p and InvalidTreatyMap = 0); {$ENDIF}
    1288   result := eOK;
    1289   with RW[p].Un[uix] do
     1279          Result := eInvalid;
     1280    end;
     1281end;
     1282
     1283function StartJob(P, uix, NewJob: Integer; TestOnly: Boolean): Integer;
     1284var
     1285  JobWork, Loc0, p1, uix1, TerrType: Integer;
     1286begin
     1287{$IFOPT O-}Assert(1 shl P and InvalidTreatyMap = 0); {$ENDIF}
     1288  Result := eOK;
     1289  with RW[P].Un[uix] do
    12901290  begin
    12911291    if NewJob = Job then
    12921292    begin
    1293       result := eNotChanged;
    1294       exit;
     1293      Result := eNotChanged;
     1294      Exit;
    12951295    end;
    12961296    if NewJob = jNone then
     
    12981298      if not TestOnly then
    12991299        Job := jNone;
    1300       exit;
     1300      Exit;
    13011301    end;
    13021302    Loc0 := Loc;
     
    13041304      (NewJob <> jRR) then
    13051305    begin
    1306       result := eDeadLands;
    1307       exit;
     1306      Result := eDeadLands;
     1307      Exit;
    13081308    end;
    13091309    TerrType := RealMap[Loc0] and fTerrain;
    13101310    if (RealMap[Loc0] and fCity <> 0) or (TerrType < fGrass) or (Master >= 0) or
    1311       not((NewJob = jPillage) and (RW[p].Model[mix].Domain = dGround) or
    1312       (RW[p].Model[mix].Kind = mkSettler) or (NewJob <> jCity) and
    1313       (RW[p].Model[mix].Kind = mkSlaves) and (GWonder[woPyramids].EffectiveOwner
     1311      not((NewJob = jPillage) and (RW[P].Model[mix].Domain = dGround) or
     1312      (RW[P].Model[mix].Kind = mkSettler) or (NewJob <> jCity) and
     1313      (RW[P].Model[mix].Kind = mkSlaves) and (GWonder[woPyramids].EffectiveOwner
    13141314      >= 0)) then
    13151315    begin
    1316       result := eInvalid;
    1317       exit;
     1316      Result := eInvalid;
     1317      Exit;
    13181318    end;
    13191319    if (JobPreq[NewJob] <> preNone) and
    1320       (RW[p].Tech[JobPreq[NewJob]] < tsApplicable) then
    1321     begin
    1322       result := eNoPreq;
    1323       exit;
    1324     end;
    1325 
    1326     result := CalculateJobWork(p, Loc0, NewJob, JobWork);
    1327     if (Mode = moPlaying) and (result = eOK) and (NewJob <> jPoll) then
     1320      (RW[P].Tech[JobPreq[NewJob]] < tsApplicable) then
     1321    begin
     1322      Result := eNoPreq;
     1323      Exit;
     1324    end;
     1325
     1326    Result := CalculateJobWork(P, Loc0, NewJob, JobWork);
     1327    if (Mode = moPlaying) and (Result = eOK) and (NewJob <> jPoll) then
    13281328    begin // not allowed in territory of friendly nation
    13291329      p1 := RealMap[Loc0] shr 27; // owner of territory
    1330       if (p1 < nPl) and (p1 <> p) and (RW[p].Treaty[p1] >= trPeace) then
    1331         result := eTreaty; // keep peace treaty!
    1332     end;
    1333     if TestOnly or (result < rExecuted) then
    1334       exit;
     1330      if (p1 < nPl) and (p1 <> P) and (RW[P].Treaty[p1] >= trPeace) then
     1331        Result := eTreaty; // keep peace treaty!
     1332    end;
     1333    if TestOnly or (Result < rExecuted) then
     1334      Exit;
    13351335
    13361336    if (ToWork[Loc0, NewJob] = 0) or (ToWork[Loc0, NewJob] > JobWork) then
     
    13381338    Job := NewJob;
    13391339    Flags := Flags and not unFortified;
    1340     for uix1 := 0 to RW[p].nUn - 1 do
    1341       if (RW[p].Un[uix1].Loc = Loc) and
    1342         (RW[p].Un[uix1].Job in ContraJobs[NewJob]) then
    1343         RW[p].Un[uix1].Job := jNone; // stop contradictive jobs
    1344     if ServerVersion[p] < $000EF0 then
    1345       if Work(p, uix) then
    1346         result := eJobDone;
    1347     if (NewJob = jCity) and (result = eJobDone) then
    1348     begin
    1349       RemoveUnit_UpdateMap(p, uix);
    1350       result := eCity;
     1340    for uix1 := 0 to RW[P].nUn - 1 do
     1341      if (RW[P].Un[uix1].Loc = Loc) and
     1342        (RW[P].Un[uix1].Job in ContraJobs[NewJob]) then
     1343        RW[P].Un[uix1].Job := jNone; // stop contradictive jobs
     1344    if ServerVersion[P] < $000EF0 then
     1345      if Work(P, uix) then
     1346        Result := eJobDone;
     1347    if (NewJob = jCity) and (Result = eJobDone) then
     1348    begin
     1349      RemoveUnit_UpdateMap(P, uix);
     1350      Result := eCity;
    13511351    end
    13521352    else if Health <= 0 then
    13531353    begin // victim of HostileDamage
    1354       RemoveUnit_UpdateMap(p, uix);
    1355       result := result or rUnitRemoved;
     1354      RemoveUnit_UpdateMap(P, uix);
     1355      Result := Result or rUnitRemoved;
    13561356    end;
    13571357    if Mode > moLoading_Fast then
    13581358    begin
    1359       if result = eCity then
    1360       begin
    1361         ObserveLevel[Loc0] := ObserveLevel[Loc0] and not(3 shl (2 * p));
    1362         Discover21(Loc0, p, lObserveUnhidden, true, true);
     1359      if Result = eCity then
     1360      begin
     1361        ObserveLevel[Loc0] := ObserveLevel[Loc0] and not(3 shl (2 * P));
     1362        Discover21(Loc0, P, lObserveUnhidden, True, True);
    13631363        // CheckContact;
    13641364      end;
     
    13671367end;
    13681368
    1369 function Work(p, uix: integer): boolean;
    1370 var
    1371   uix1, j0: integer;
    1372 begin
    1373   result := false;
    1374   with RW[p].Un[uix] do
     1369function Work(P, uix: Integer): Boolean;
     1370var
     1371  uix1, j0: Integer;
     1372begin
     1373  Result := False;
     1374  with RW[P].Un[uix] do
    13751375    if Movement >= 100 then
    13761376    begin
    1377       assert(ToWork[Loc, Job] < $FFFF); // should have been set by StartJob
     1377      Assert(ToWork[Loc, Job] < $FFFF); // should have been set by StartJob
    13781378      if Job >= jRoad then
    1379         if integer(Movement) >= integer(ToWork[Loc, Job]) then { work complete }
    1380         begin
    1381           result := true;
     1379        if Integer(Movement) >= Integer(ToWork[Loc, Job]) then { work complete }
     1380        begin
     1381          Result := True;
    13821382          if Job <> jIrr then
    1383             Health := Health - HostileDamage(p, mix, Loc, ToWork[Loc, Job]);
    1384           dec(Movement, ToWork[Loc, Job]);
     1383            Health := Health - HostileDamage(P, mix, Loc, ToWork[Loc, Job]);
     1384          Dec(Movement, ToWork[Loc, Job]);
    13851385          if not(Job in [jCity, jPillage, jPoll]) then
    1386             inc(Worked[p], ToWork[Loc, Job]);
     1386            Inc(Worked[P], ToWork[Loc, Job]);
    13871387          if Job = jCity then
    13881388          begin // found new city
    1389             FoundCity(p, Loc);
    1390             inc(Founded[p]);
    1391             with RW[p].City[RW[p].nCity - 1] do
     1389            FoundCity(P, Loc);
     1390            Inc(Founded[P]);
     1391            with RW[P].City[RW[P].nCity - 1] do
    13921392            begin
    1393               ID := p shl 12 + Founded[p] - 1;
     1393              ID := P shl 12 + Founded[P] - 1;
    13941394              Flags := chFounded;
    13951395            end;
    13961396            if Mode = moPlaying then
    13971397            begin
    1398               LogCheckBorders(p, RW[p].nCity - 1);
    1399               RecalcPeaceMap(p);
     1398              LogCheckBorders(P, RW[P].nCity - 1);
     1399              RecalcPeaceMap(P);
    14001400            end;
    14011401{$IFOPT O-} if Mode < moPlaying then
    1402               InvalidTreatyMap := not(1 shl p); {$ENDIF}
     1402              InvalidTreatyMap := not(1 shl P); {$ENDIF}
    14031403            // territory should not be considered for the rest of the command
    14041404            // execution, because during loading a game it's incorrect before
    14051405            // subsequent sIntExpandTerritory is processed
    1406             RW[p].Un[uix].Health := 0; // causes unit to be removed later
     1406            RW[P].Un[uix].Health := 0; // causes unit to be removed later
    14071407          end
    14081408          else
    1409             CompleteJob(p, Loc, Job);
     1409            CompleteJob(P, Loc, Job);
    14101410          ToWork[Loc, Job] := 0;
    14111411          j0 := Job;
    1412           for uix1 := 0 to RW[p].nUn - 1 do
    1413             if (RW[p].Un[uix1].Loc = Loc) and (RW[p].Un[uix1].Job = j0) then
    1414               RW[p].Un[uix1].Job := jNone
     1412          for uix1 := 0 to RW[P].nUn - 1 do
     1413            if (RW[P].Un[uix1].Loc = Loc) and (RW[P].Un[uix1].Job = j0) then
     1414              RW[P].Un[uix1].Job := jNone
    14151415        end
    14161416        else
    14171417        begin
    1418           dec(ToWork[Loc, Job], Movement);
     1418          Dec(ToWork[Loc, Job], Movement);
    14191419          if not(Job in [jCity, jPillage, jPoll]) then
    1420             inc(Worked[p], Movement);
    1421           Health := Health - HostileDamage(p, mix, Loc, Movement);
     1420            Inc(Worked[P], Movement);
     1421          Health := Health - HostileDamage(P, mix, Loc, Movement);
    14221422          Movement := 0;
    14231423        end
     
    14251425end;
    14261426
    1427 function GetJobProgress(p, Loc: integer;
    1428   var JobProgressData: TJobProgressData): integer;
    1429 var
    1430   Job, JobResult, uix: integer;
     1427function GetJobProgress(P, Loc: Integer;
     1428  var JobProgressData: TJobProgressData): Integer;
     1429var
     1430  Job, JobResult, uix: Integer;
    14311431begin
    14321432  for Job := 0 to nJob - 1 do
    14331433  begin
    1434     JobResult := CalculateJobWork(p, Loc, Job, JobProgressData[Job].Required);
     1434    JobResult := CalculateJobWork(P, Loc, Job, JobProgressData[Job].Required);
    14351435    if JobResult = eOK then
    14361436    begin
     
    14481448    JobProgressData[Job].NextTurnPlus := 0;
    14491449  end;
    1450   for uix := 0 to RW[p].nUn - 1 do
    1451     if (RW[p].Un[uix].Loc = Loc) and (RW[p].Un[uix].Movement >= 100) then
    1452       inc(JobProgressData[RW[p].Un[uix].Job].NextTurnPlus,
    1453         RW[p].Un[uix].Movement);
    1454   result := eOK;
     1450  for uix := 0 to RW[P].nUn - 1 do
     1451    if (RW[P].Un[uix].Loc = Loc) and (RW[P].Un[uix].Movement >= 100) then
     1452      Inc(JobProgressData[RW[P].Un[uix].Job].NextTurnPlus,
     1453        RW[P].Un[uix].Movement);
     1454  Result := eOK;
    14551455end;
    14561456
Note: See TracChangeset for help on using the changeset viewer.