anchor.diff:    //it looks bad that serfs remove the stone then take it back. To be converted to todo item.
   
     //How much do we need to ask to add to delivery system = Needed - (Ordered + Arrived)
  -  ResRequired := GetResRequired;
  +  resRequired := GetResRequired;
   
     if fTradeAmount <> 0 then
     begin
  -    movedOut2In := MoveResOut2In(fResFrom, ResRequired);
  +    movedOut2In := MoveResOut2In(fResFrom, resRequired);
       if movedOut2In > 0 then
       begin
         //Remove demands, we took some of the wares from OUT queue
  -      OrdersRemoved := gHands[fOwner].Deliveries.Queue.TryRemoveDemand(Self, fResFrom, movedOut2In);
  -      Dec(fMarketDeliveryCount[fResFrom], OrdersRemoved);
  +      ordersRemoved := gHands[fOwner].Deliveries.Queue.TryRemoveDemand(Self, fResFrom, movedOut2In);
  +      Dec(fMarketDeliveryCount[fResFrom], ordersRemoved);
       end;
     end;
   
  -  OrdersAllowed := MAX_RES_ORDERED - fMarketDeliveryCount[fResFrom];
  -
  -  Assert(OrdersAllowed >= 0); //We must never have ordered more than we are allowed
  +  ordersAllowed := MAX_RES_ORDERED - fMarketDeliveryCount[fResFrom];
  +
  +  Assert(ordersAllowed >= 0); //We must never have ordered more than we are allowed
   
     //Order as many as we can within our limit
  -  if (ResRequired > 0) and (OrdersAllowed > 0) then
  -  begin
  -    OrderToDo := Min(ResRequired, OrdersAllowed);
  -    Inc(fMarketDeliveryCount[fResFrom], OrderToDo);
  -    gHands[fOwner].Deliveries.Queue.AddDemand(Self, nil, fResFrom, OrderToDo, dtOnce, diNorm)
  +  if (resRequired > 0) and (ordersAllowed > 0) then
  +  begin
  +    orderToDo := Min(resRequired, ordersAllowed);
  +    Inc(fMarketDeliveryCount[fResFrom], orderToDo);
  +    gHands[fOwner].Deliveries.Queue.AddDemand(Self, nil, fResFrom, orderToDo, dtOnce, diNorm)
     end
     else
       //There are too many resources ordered, so remove as many as we can from the delivery list (some will be being performed)
  -    if (ResRequired < 0) then
  +    if (resRequired < 0) then
       begin
  -      OrdersRemoved := gHands[fOwner].Deliveries.Queue.TryRemoveDemand(Self, fResFrom, -ResRequired);
  -      Dec(fMarketDeliveryCount[fResFrom], OrdersRemoved);
  +      ordersRemoved := gHands[fOwner].Deliveries.Queue.TryRemoveDemand(Self, fResFrom, -resRequired);
  +      Dec(fMarketDeliveryCount[fResFrom], ordersRemoved);
       end;
   end;
   
  
positive.code: 
  procedure TKMHouseMarket.SetResInCnt(aWareType: TKMWareType; aValue: Word);
  var
    CntChange: Integer;
  begin
    Assert(aWareType in [WARE_MIN..WARE_MAX]);
  
    CntChange := aValue - fMarketResIn[aWareType];
  
    fMarketResIn[aWareType] := aValue;
  
    if CntChange <> 0 then
      gScriptEvents.ProcHouseWareCountChanged(Self, aWareType, ResToTrade[aWareType], CntChange);
  end;
  
  
  procedure TKMHouseMarket.SetResOutCnt(aWareType: TKMWareType; aValue: Word);
  var
    CntChange: Integer;
  begin
    Assert(aWareType in [WARE_MIN..WARE_MAX]);
  
    CntChange := aValue - fMarketResOut[aWareType];
  
    fMarketResOut[aWareType] := aValue;
  
    if CntChange <> 0 then
      gScriptEvents.ProcHouseWareCountChanged(Self, aWareType, ResToTrade[aWareType], CntChange);
  end;
  
  
  
negative.code: procedure TKMHouseMarket.Paint;
  var
    R: TKMWareType;
    maxCount: Word;
    maxRes: TKMWareType;
  begin
    inherited;
    if fBuildState < hbsDone then Exit;
  
    //Market can display only one ware at a time (lookup ware that has most count)
    maxCount := 0;
    maxRes := wtNone;
    for R := WARE_MIN to WARE_MAX do
    if fMarketResIn[R] + fMarketResOut[R] > maxCount then
    begin
      maxCount := fMarketResIn[R] + fMarketResOut[R];
      maxRes := R;
    end;
  
    if maxCount > 0 then
      //FlagAnimStep is required for horses animation
      gRenderPool.AddHouseMarketSupply(fPosition, maxRes, maxCount, FlagAnimStep);
  end;
  
  
  