anchor.diff:      end;
   
       //Keep track of how many are ordered
  -    fResourceDeliveryCount[I] := Max(fResourceDeliveryCount[I] - aCount, 0);
  +    ResDeliveryCnt[I] := ResDeliveryCnt[I] - aCount;
   
       Assert(ResIn[I] >= aCount, 'fResourceIn[i] < 0');
       ResIn[I] := ResIn[I] - aCount;
       //Only request a new resource if it is allowed by the distribution of wares for our parent player
       for K := 1 to aCount do
  -      if fResourceDeliveryCount[I] < GetResDistribution(I) then
  +      if ResDeliveryCnt[I] < GetResDistribution(I) then
         begin
           gHands[fOwner].Deliveries.Queue.AddDemand(Self, nil, aWare, 1, dtOnce, diNorm);
  -        Inc(fResourceDeliveryCount[I]);
  +        ResDeliveryCnt[I] := ResDeliveryCnt[I] + 1;
         end;
       Exit;
     end;
  
positive.code:       ResIn[I] := ResIn[I] + aCount;
        if aFromScript then
        begin
          Inc(fResourceDeliveryCount[I], aCount);
          OrdersRemoved := gHands[fOwner].Deliveries.Queue.TryRemoveDemand(Self, aWare, aCount);
          Dec(fResourceDeliveryCount[I], OrdersRemoved);
        end;
      end;
  end;
  
negative.code:     if not (fType = htTownHall) and not (gRes.Houses[fType].ResInput[I] in [wtAll, wtWarfare, wtNone]) then
      begin
        //Not enough resources ordered, add new demand
        if ResDeliveryCnt[I] < GetResDistribution(I) then
        begin
          Count := GetResDistribution(I) - ResDeliveryCnt[I];
          gHands[fOwner].Deliveries.Queue.AddDemand(
            Self, nil, gRes.Houses[fType].ResInput[I], Count, dtOnce, diNorm);
  
          ResDeliveryCnt[I] := ResDeliveryCnt[I] + Count;
        end;
  
        //Too many resources ordered, attempt to remove demand if nobody has taken it yet
        if ResDeliveryCnt[I] > GetResDistribution(I) then
        begin
          Excess := ResDeliveryCnt[I] - GetResDistribution(I);
          Count := gHands[fOwner].Deliveries.Queue.TryRemoveDemand(Self, gRes.Houses[fType].ResInput[I], Excess);
  
          ResDeliveryCnt[I] := ResDeliveryCnt[I] - Count; //Only reduce it by the number that were actually removed
        end;
  
      end;
  