Changeset 663


Ignore:
Timestamp:
Jul 5, 2025, 10:57:12 AM (3 hours ago)
Author:
chronos
Message:
  • Fixed: Fixed unit move style hostile calculation in StdAI. Engineers don't take hostile damage on hostile terrain.
Location:
trunk
Files:
3 edited

Legend:

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

    r592 r663  
    177177
    178178procedure Loc_to_ab(Loc0, Loc: Integer; var A, B: Integer);
    179 {$IFDEF FPC}// freepascal
    180179var
    181180  dx, dy: Integer;
     
    187186  B := (dy - dx) div 2;
    188187end;
    189 
    190 {$ELSE}// delphi
    191 register;
    192 asm
    193 push ebx
    194 
    195 // calculate
    196 push ecx
    197 div Byte ptr [G]
    198 xor ebx,ebx
    199 mov bl,ah  // ebx:=Loc0 mod G.lx
    200 mov ecx,eax
    201 and ecx,$000000FF // ecx:=Loc0 div G.lx
    202 mov eax,edx
    203 div Byte ptr [G]
    204 xor edx,edx
    205 mov dl,ah // edx:=Loc mod G.lx
    206 and eax,$000000FF // eax:=Loc div G.lx
    207 sub edx,ebx // edx:=Loc mod G.lx-Loc0 mod G.lx
    208 mov ebx,eax
    209 sub ebx,ecx // ebx:=dy
    210 and eax,1
    211 and ecx,1
    212 add edx,edx
    213 add eax,edx
    214 sub eax,ecx // eax:=dx, not normalized
    215 pop ecx
    216 
    217 // normalize
    218 mov edx,dword ptr [G]
    219 cmp eax,edx
    220 jl @A
    221   sub eax,edx
    222   sub eax,edx
    223   jmp @ok
    224 @A:
    225 neg edx
    226 cmp eax,edx
    227 jnl @ok
    228   sub eax,edx
    229   sub eax,edx
    230 
    231 // return results
    232 @ok:
    233 mov edx,ebx
    234 sub edx,eax
    235 add eax,ebx
    236 sar edx,1 // edx:=b
    237 mov ebx,[B]
    238 mov [ebx],edx
    239 sar eax,1 // eax:=a
    240 mov [A],eax
    241 
    242 pop ebx
    243 end;
    244 {$ENDIF}
    245188
    246189procedure ab_to_V8(A, B: Integer; var V8: Integer);
  • trunk/AI/StdAI/ToolAI.pas

    r592 r663  
    613613      dGround:
    614614      begin
    615         Inc(Result, (50 + (Speed - 150) * 13 shr 7) shl 8); //HeavyCost
     615        Inc(Result, (50 + (Speed - 150) * 13 shr 7) shl 8); // HeavyCost
    616616        if RO.Wonder[woShinkansen].EffectiveOwner <> Me then
    617617          Inc(Result, Speed * (4 * 1311) shr 17); // RailCost
    618         if (RO.Wonder[woGardens].EffectiveOwner <> Me) or
    619           (Kind = mkSettler) and (Speed >= 200) then
     618        if (RO.Wonder[woGardens].EffectiveOwner <> Me) and
     619          not ((Kind = mkSettler) and (Speed >= 200)) then
    620620          Inc(Result, msHostile);
    621621        if Kind = mkDiplomat then
  • trunk/UnitProcessing.pas

    r558 r663  
    2121  Worked: array [0 .. nPl - 1] of Integer; { settler work statistics }
    2222
    23   // Moving/Combat
     23// Moving/Combat
    2424function HostileDamage(P, mix, Loc, MP: Integer): Integer;
    2525function CalculateMove(P, uix, ToLoc, MoveLength: Integer; TestOnly: Boolean;
     
    7979  ToWork: ^TToWorkList; { work left for each tile and job }
    8080
    81   {
    82     Moving/Combat
    83     ____________________________________________________________________
    84   }
     81{
     82  Moving/Combat
     83  ____________________________________________________________________
     84}
    8585function HostileDamage(P, mix, Loc, MP: Integer): Integer;
    8686var
     
    9797  begin
    9898    Assert((Tile and fTerImp <> tiIrrigation) and (Tile and fTerImp <> tiFarm));
    99     Result := (DesertThurst * MP - 1) div RW[P].Model[mix].Speed + 1
     99    Result := (DesertThurst * MP - 1) div RW[P].Model[mix].Speed + 1;
    100100  end
    101101  else if Tile and fTerrain = fArctic then
    102102  begin
    103103    Assert((Tile and fTerImp <> tiIrrigation) and (Tile and fTerImp <> tiFarm));
    104     Result := (ArcticThurst * MP - 1) div RW[P].Model[mix].Speed + 1
     104    Result := (ArcticThurst * MP - 1) div RW[P].Model[mix].Speed + 1;
    105105  end
    106106  else
     
    346346        begin
    347347          Result := eOK;
    348           MoveInfo.MountainDelay := True
     348          MoveInfo.MountainDelay := True;
    349349        end;
    350350      end;
     
    748748        Recovery := FastRecovery { city has baracks/shipyard/airport }
    749749      else
    750         Recovery := CityRecovery
     750        Recovery := CityRecovery;
    751751    end
    752752    else if (RealMap[Loc] and fTerrain >= fGrass) and (Model[mix].Domain <> dAir)
     
    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,
    782782    MovementLeft: Integer;
     
    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
     
    955955                  3:
    956956                    begin
    957                       MoveCost := maxmov;
     957                      MoveCost := MaxMov;
    958958                      MountainDelay := True;
    959959                    end;
     
    967967                  if V8 and 1 <> 0 then
    968968                    AddDamage := ((DesertThurst * 3) * MoveCost - 1)
    969                       div maxmov + 1
     969                      div MaxMov + 1
    970970                  else
    971971                    AddDamage := ((DesertThurst * 2) * MoveCost - 1)
    972                       div maxmov + 1
     972                      div MaxMov + 1;
    973973                end
    974974                else if ToTile and (fTerrain or fCity or fRiver or fCanal) = fArctic
     
    977977                  if V8 and 1 <> 0 then
    978978                    AddDamage := ((ArcticThurst * 3) * MoveCost - 1)
    979                       div maxmov + 1
     979                      div MaxMov + 1
    980980                  else
    981981                    AddDamage := ((ArcticThurst * 2) * MoveCost - 1)
    982                       div maxmov + 1
     982                      div MaxMov + 1;
    983983                end;
    984             end
    985             else
    986               MoveCost := -1;
    987 
     984            end else MoveCost := -1;
    988985          end;
    989986
     
    998995            fOwned) // assume ship/airplane is transport -- load!
    999996            or (MoveCost >= 0) and (FromTile and fTerrain < fGrass)) then
    1000             MoveCost := maxmov; // transport load or unload
     997            MoveCost := MaxMov; // transport load or unload
    1001998
    1002999          if MoveCost >= 0 then
    10031000          begin { valid move }
    1004             MovementLeft := maxmov - T shr 8 and $FFF - MoveCost;
     1001            MovementLeft := MaxMov - T shr 8 and $FFF - MoveCost;
    10051002            if (MovementLeft < 0) or ((MoveCost = 0) and (MovementLeft = 0))
    10061003            then
     
    10111008                if FromTile and (fTerrain or fCity or fRiver or fCanal or
    10121009                  fSpecial1 { Oasis } ) = fDesert then
    1013                   Inc(AddDamage, (DesertThurst * (maxmov - T shr 8 and $FFF) -
    1014                     1) div maxmov + 1)
     1010                  Inc(AddDamage, (DesertThurst * (MaxMov - T shr 8 and $FFF) -
     1011                    1) div MaxMov + 1)
    10151012                else if FromTile and (fTerrain or fCity or fRiver or fCanal) = fArctic
    10161013                then
    1017                   Inc(AddDamage, (ArcticThurst * (maxmov - T shr 8 and $FFF) -
    1018                     1) div maxmov + 1);
    1019 
    1020               T1 := T and $7FF000FF + $100000 + (initmov + MoveCost) shl 8;
     1014                  Inc(AddDamage, (ArcticThurst * (MaxMov - T shr 8 and $FFF) -
     1015                    1) div MaxMov + 1);
     1016
     1017              T1 := T and $7FF000FF + $100000 + (InitMov + MoveCost) shl 8;
    10211018            end
    10221019            else
     
    10621059            mod (2 * lx) - lx;
    10631060          A.dy[I] := Loc div lx - From[Loc] div lx;
    1064         end
     1061        end;
    10651062      end;
    10661063      Loc := From[Loc];
    10671064    end;
    1068     A.MaxHostile_MovementLeft := maxmov - Time[EndLoc] shr 8 and $FFF;
     1065    A.MaxHostile_MovementLeft := MaxMov - Time[EndLoc] shr 8 and $FFF;
    10691066    if A.nStep > 25 then
    10701067      A.nStep := 25;
    1071     Result := eOK
     1068    Result := eOK;
    10721069  end
    10731070  else
     
    14121409          for uix1 := 0 to RW[P].nUn - 1 do
    14131410            if (RW[P].Un[uix1].Loc = Loc) and (RW[P].Un[uix1].Job = j0) then
    1414               RW[P].Un[uix1].Job := jNone
     1411              RW[P].Un[uix1].Job := jNone;
    14151412        end
    14161413        else
     
    14211418          Health := Health - HostileDamage(P, mix, Loc, Movement);
    14221419          Movement := 0;
    1423         end
    1424     end
     1420        end;
     1421    end;
    14251422end;
    14261423
Note: See TracChangeset for help on using the changeset viewer.