Changeset 549 for trunk/GameServer.pas


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

Legend:

Unmodified
Added
Removed
  • trunk/GameServer.pas

    r531 r549  
    474474  for ix := 0 to RW[P].nUn - 1 do
    475475    with RW[P].Un[ix] do
    476       if (Loc >= 0) and (SavedStatus <> Status) then
     476      if (Loc >= 0) and (SavedStatus <> Status) then begin
    477477        Result := True;
     478        Exit;
     479      end;
    478480  for ix := 0 to RW[P].nCity - 1 do
    479481    with RW[P].City[ix] do
    480       if (Loc >= 0) and (SavedStatus <> Status) then
     482      if (Loc >= 0) and (SavedStatus <> Status) then begin
    481483        Result := True;
     484        Exit;
     485      end;
    482486  for ix := 0 to RW[P].nModel - 1 do
    483487    with RW[P].Model[ix] do
    484       if SavedStatus <> Status then
     488      if SavedStatus <> Status then begin
    485489        Result := True;
     490        Exit;
     491      end;
    486492  for ix := 0 to RW[P].nEnemyCity - 1 do
    487493    with RW[P].EnemyCity[ix] do
    488       if (Loc >= 0) and (SavedStatus <> Status) then
     494      if (Loc >= 0) and (SavedStatus <> Status) then begin
    489495        Result := True;
     496        Exit;
     497      end;
    490498  if RW[P].Data <> nil then
    491499    for ix := 0 to bix[P].DataSize - 1 do
    492       if PDWortList(SavedData[P])[ix] <> PDWortList(RW[P].Data)[ix] then
     500      if PDWortList(SavedData[P])[ix] <> PDWortList(RW[P].Data)[ix] then begin
    493501        Result := True;
     502        Exit;
     503      end;
    494504end;
    495505
     
    10691079  for cix := 0 to RW[pTurn].nCity - 1 do
    10701080    with RW[pTurn].City[cix] do
    1071       if Loc >= 0 then
    1072       begin
    1073         // if SavedResourceWeights[cix]<>ResourceWeights then result:=true;
    1074         if SavedTiles[cix] <> Tiles then
     1081      if Loc >= 0 then begin
     1082        // if SavedResourceWeights[cix] <> ResourceWeights then Result := true;
     1083        if SavedTiles[cix] <> Tiles then begin
    10751084          Result := True;
     1085          Break;
     1086        end;
    10761087      end;
    10771088end;
     
    12041215    Notify(ntLoadBegin);
    12051216
    1206   started := False;
     1217  Started := False;
    12071218  StatRequest := False;
    12081219  MovieStopped := False;
     
    12241235    end;
    12251236    // complete all internal commands following an sTurn before generating statistics
    1226     if (Command = sTurn) and not started then
     1237    if (Command = sTurn) and not Started then
    12271238    begin
    12281239{$IFDEF TEXTLOG}WriteLn(TextLog, '---Turn 0 P0---'); {$ENDIF}
     
    12371248      end;
    12381249      StatRequest := True;
    1239       started := True;
     1250      Started := True;
    12401251    end
    12411252    else if (Command = sTurn) and (pTurn = 0) and (GTurn = LoadTurn) then
     
    12831294  if StatRequest then
    12841295    GenerateStat(pTurn);
    1285   Assert(started);
     1296  Assert(Started);
    12861297{$IFDEF TEXTLOG}CloseFile(TextLog); {$ENDIF}
    12871298{$IFDEF LOADPERF}QueryPerformanceCounter(time_total); { time in s is: (time_total-time_total0)/PerfFreq }{$ENDIF}
     
    14991510procedure DestroyCity_TellPlayers(P, cix: Integer; SaveUnits: Boolean);
    15001511begin
    1501   if RW[P].City[cix].built[imSpacePort] > 0 then
     1512  if RW[P].City[cix].Built[imSpacePort] > 0 then
    15021513    DestroySpacePort_TellPlayers(P, -1);
    15031514  DestroyCity(P, cix, SaveUnits);
     
    15061517procedure ChangeCityOwner_TellPlayers(pOld, cixOld, pNew: Integer);
    15071518begin
    1508   if RW[pOld].City[cixOld].built[imSpacePort] > 0 then
     1519  if RW[pOld].City[cixOld].Built[imSpacePort] > 0 then
    15091520    if RW[pNew].NatBuilt[imSpacePort] > 0 then
    15101521      DestroySpacePort_TellPlayers(pOld, pNew)
     
    15211532  ShipComplete := True;
    15221533  for I := 0 to nShipPart - 1 do
    1523     if GShip[P].Parts[I] < ShipNeed[I] then
     1534    if GShip[P].Parts[I] < ShipNeed[I] then begin
    15241535      ShipComplete := False;
     1536      Break;
     1537    end;
    15251538  if ShipComplete then
    15261539    GWinner := GWinner or 1 shl P; // game won!
     
    15871600            for cix := 1 to nCity - 1 do
    15881601              if (City[cix].Loc >= 0) and
    1589                 ((Loc1 < 0) or (City[cix].built[imPalace] > 0)) then
     1602                ((Loc1 < 0) or (City[cix].Built[imPalace] > 0)) then
    15901603                Loc1 := City[cix].Loc;
    15911604            for uix := 0 to nUn - 1 do
     
    19331946          for cix := 0 to RW[p1].nCity - 1 do
    19341947            if (RW[p1].City[cix].Loc >= 0) and
    1935               (RW[p1].City[cix].built[imTemple] > 0) then
     1948              (RW[p1].City[cix].Built[imTemple] > 0) then
    19361949              Inc(OracleIncome);
    19371950    end;
     
    23962409        dGround:
    23972410          LoseCityPop := (PModel.Cap[mcArtillery] > 0) or
    2398             (RW[MoveInfo.Defender].City[MoveInfo.Dcix].built[imWalls] = 0) and
     2411            (RW[MoveInfo.Defender].City[MoveInfo.Dcix].Built[imWalls] = 0) and
    23992412            (Continent[ToLoc] <> GrWallContinent[MoveInfo.Defender]);
    24002413        dSea:
    2401           LoseCityPop := RW[MoveInfo.Defender].City[MoveInfo.Dcix].built
     2414          LoseCityPop := RW[MoveInfo.Defender].City[MoveInfo.Dcix].Built
    24022415            [imCoastalFort] = 0;
    24032416        dAir:
    2404           LoseCityPop := RW[MoveInfo.Defender].City[MoveInfo.Dcix].built
     2417          LoseCityPop := RW[MoveInfo.Defender].City[MoveInfo.Dcix].Built
    24052418            [imMissileBat] = 0;
    24062419      end;
     
    24592472          for cix1 := 1 to nCity - 1 do
    24602473            if (City[cix1].Loc >= 0) and
    2461               ((ExpelToLoc < 0) or (City[cix1].built[imPalace] > 0)) then
     2474              ((ExpelToLoc < 0) or (City[cix1].Built[imPalace] > 0)) then
    24622475              ExpelToLoc := City[cix1].Loc;
    24632476        end;
     
    31053118        AllHumansDead := True;
    31063119        for p1 := 0 to nPl - 1 do
    3107           if (1 shl p1 and GAlive <> 0) and (bix[p1].Kind = btTerm) then
     3120          if (1 shl p1 and GAlive <> 0) and (bix[p1].Kind = btTerm) then begin
    31083121            AllHumansDead := False;
     3122            Break;
     3123          end;
    31093124        if (pDipActive >= 0) // still in negotiation mode
    31103125          or (pTurn = 0) and ((GWinner > 0) or (GTurn = MaxTurn) or
     
    32253240            (Integer(Data) >= 0) and (Integer(Data) < GTurn);
    32263241          for p1 := 1 to nPl - 1 do
    3227             if bix[p1].Kind = btTerm then
     3242            if bix[p1].Kind = btTerm then begin
    32283243              Ok := False;
     3244              Break;
     3245            end;
    32293246          // allow reload in AI-only games only
    32303247        end
     
    33633380              Result := eOfferNotAcceptable;
    33643381            for I := 0 to nDeliver + nCost - 1 do
    3365               if Price[I] = opChoose then
     3382              if Price[I] = opChoose then begin
    33663383                Result := eOfferNotAcceptable;
     3384                Break;
     3385              end;
    33673386            for I := 0 to nCost - 1 do
    33683387              if not PayPrice(pDipActive, p1, Price[nDeliver + I], False) then
     
    34873506          begin // no tribute allowed!
    34883507            for I := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do
    3489               if (TOffer(Data).Price[I] and opMask = opTribute) then
     3508              if (TOffer(Data).Price[I] and opMask = opTribute) then begin
    34903509                Result := eInvalidOffer;
     3510                Break;
     3511              end;
    34913512            for I := 0 to TOffer(Data).nDeliver + TOffer(Data).nCost - 1 do
    3492               if (TOffer(Data).Price[I] = opTreaty + trPeace) then
     3513              if (TOffer(Data).Price[I] = opTreaty + trPeace) then begin
    34933514                Result := eOK;
     3515                Break;
     3516              end;
    34943517          end;
    34953518          for I := 0 to TOffer(Data).nDeliver - 1 do
     
    35003523            Result := eInvalidOffer;
    35013524          for I := 0 to nShipPart - 1 do
    3502             if CountPrice(TOffer(Data), opShipParts + I shl 16) > 1 then
     3525            if CountPrice(TOffer(Data), opShipParts + I shl 16) > 1 then begin
    35033526              Result := eInvalidOffer;
     3527              Break;
     3528            end;
    35043529          if CountPrice(TOffer(Data), opMoney) > 1 then
    35053530            Result := eInvalidOffer;
     
    41914216                for I := 0 to nImpReplacement - 1 do
    41924217                  if (ImpReplacement[I].OldImp = NewProject and cpIndex) and
    4193                     (built[ImpReplacement[I].NewImp] > 0) then
    4194                     Result := eObsolete;
     4218                    (Built[ImpReplacement[I].NewImp] > 0) then begin
     4219                      Result := eObsolete;
     4220                      Break;
     4221                    end;
    41954222                if Result = eObsolete then
    41964223                else if Preq = preNA then
     
    41994226                then
    42004227                  Result := eNoPreq
    4201                 else if built[NewProject and cpIndex] > 0 then
     4228                else if Built[NewProject and cpIndex] > 0 then
    42024229                  Result := eInvalid
    42034230                else if (NewProject and cpIndex < nWonder) and
     
    42074234                  (RW[Player].NatBuilt[imSpacePort] > 0) then
    42084235                  Result := eViolation // space port already exists
    4209                 else if (NewProject = cpImp + imBank) and (built[imMarket] = 0)
     4236                else if (NewProject = cpImp + imBank) and (Built[imMarket] = 0)
    42104237                  or (NewProject = cpImp + imUniversity) and
    4211                   (built[imLibrary] = 0) or (NewProject = cpImp + imResLab) and
    4212                   (built[imUniversity] = 0) or (NewProject = cpImp + imMfgPlant)
    4213                   and (built[imFactory] = 0) then
     4238                  (Built[imLibrary] = 0) or (NewProject = cpImp + imResLab) and
     4239                  (Built[imUniversity] = 0) or (NewProject = cpImp + imMfgPlant)
     4240                  and (Built[imFactory] = 0) then
    42144241                  Result := eNoPreq;
    42154242                case NewProject - cpImp of
     
    43624389        else
    43634390          with RW[Player].City[Subject] do
    4364             if built[Integer(Data)] = 0 then
     4391            if Built[Integer(Data)] = 0 then
    43654392              Result := eInvalid
    43664393            else if (RW[Player].Government = gAnarchy) or
     
    43734400              Inc(RW[Player].Money, Imp[Integer(Data)].Cost * BuildCostMod
    43744401                [Difficulty[Player]] div 12);
    4375               built[Integer(Data)] := 0;
     4402              Built[Integer(Data)] := 0;
    43764403              if Imp[Integer(Data)].Kind in [ikNatLocal, ikNatGlobal] then
    43774404              begin
     
    44024429          else
    44034430            with RW[Player].City[Subject] do
    4404               if (built[OldImp] = 0) or (Project and cpImp = 0) or
     4431              if (Built[OldImp] = 0) or (Project and cpImp = 0) or
    44054432                not(Imp[Project and cpIndex].Kind in [ikCommon, ikNatLocal,
    44064433                ikNatGlobal]) then
     
    44194446                  Project0 := Project;
    44204447                Prod0 := Prod;
    4421                 built[OldImp] := 0;
     4448                Built[OldImp] := 0;
    44224449                if Imp[OldImp].Kind in [ikNatLocal, ikNatGlobal] then
    44234450                begin // nat. project lost
Note: See TracChangeset for help on using the changeset viewer.