  var
    Units, Recruits: array of Integer;
    I, K, Counter: Integer;
    Barracks: array[0..1] of Integer;

  procedure OnMissionStart;
    begin
      Counter := 0;
      Barracks[0] := States.HouseAt(20, 58);
      Barracks[1] := States.HouseAt(91, 59);

      for I := 0 to 1 do begin
        Units := States.PlayerGetAllUnits(I);
          for K := 0 to Length(Units) - 1 do
            if States.UnitType(Units[K]) = 13 then begin
              SetLength(Recruits, Counter + 1);
              Recruits[Counter] := Units[K];
              Counter := Counter + 1;
            end;
          end;
        end;

  procedure OnTick;
    begin
      if States.GameTime mod 6000 = 0 then
        for K := 0 to Length(Recruits) - 1 do
          Actions.UnitHungerSet(Recruits[K], States.UnitMaxHunger);
        end;

  function LootType(aUnitID: Integer): Integer;
    begin
      case States.UnitType(aUnitID) of
        14: Result := 20;

        15: case States.KaMRandomI(3) of
              0: Result := 16;
              1: Result := 20;
              2: Result := 18;
            end;

        16: case States.KaMRandomI(3) of
              0: Result := 17;
              1: Result := 21;
              2: Result := 19;
            end;

        17: case States.KaMRandomI(2) of
              0: Result := 24;
              1: Result := 18;
            end;

        18: case States.KaMRandomI(2) of
              0: Result := 25;
              1: Result := 19;
            end;

        19: case States.KaMRandomI(2) of
              0: Result := 22;
              1: Result := 18;
            end;

        20: case States.KaMRandomI(2) of
              0: Result := 23;
              1: Result := 19;
            end;

        21: case States.KaMRandomI(4) of
              0: Result := 26;
              1: Result := 18;
              2: Result := 16;
              3: Result := 20;
            end;

        22: case States.KaMRandomI(4) of
              0: Result := 26;
              1: Result := 19;
              2: Result := 17;
              3: Result := 21;
            end;
          end;
        end;

  procedure OnUnitDied(aUnitID, aKillerIndex: Integer);
    begin
      if States.KaMRandomI(100) < 20 then
        if aKillerIndex <> -1 then
          Actions.HouseAddWaresTo(Barracks[aKillerIndex], LootType(aUnitID), 1);
        end;