public void updateGranary(GraphicsMgr gfx, VillageMap vm)
 {
     if (this.baseSprite != null)
     {
         if (this.granaryExtension == null)
         {
             this.granaryExtension = new VillageMapBuildingGranaryExtension();
             for (int j = 0; j < 0x15; j++)
             {
                 this.granaryExtension.cell[j] = new SpriteWrapper();
                 this.granaryExtension.cell[j].Visible = false;
                 this.granaryExtension.cell[j].PosX = 5 + VillageMapBuildingGranaryExtension.granaryLayout[j * 2];
                 this.granaryExtension.cell[j].PosY = -33 + VillageMapBuildingGranaryExtension.granaryLayout[(j * 2) + 1];
                 this.baseSprite.AddChild(this.granaryExtension.cell[j]);
                 this.granaryExtension.showGood(gfx, j, -1, 0);
             }
         }
         for (int i = 0; i < 0x15; i++)
         {
             this.granaryExtension.showGood(gfx, i, -1, 0);
         }
         VillageMap.GranaryLevels levels = new VillageMap.GranaryLevels();
         if (vm.getGranaryLevels(levels))
         {
             if (vm.granaryOpenCount == 0)
             {
                 this.open = false;
             }
             double num3 = ((((levels.applesLevel + levels.breadLevel) + levels.cheeseLevel) + levels.fishLevel) + levels.meatLevel) + levels.vegLevel;
             if (num3 > 0.0)
             {
                 if (vm.granaryOpenCount > 0)
                 {
                     this.open = true;
                 }
                 else
                 {
                     return;
                 }
                 int index = 0;
                 if (levels.meatLevel > 416.0)
                 {
                     index = 4;
                 }
                 else if (levels.meatLevel > 96.0)
                 {
                     index = 3;
                 }
                 else if (levels.meatLevel > 16.0)
                 {
                     index = 2;
                 }
                 else if (levels.meatLevel > 0.0)
                 {
                     index = 1;
                 }
                 else
                 {
                     index = 0;
                 }
                 int num5 = 0;
                 if (levels.vegLevel > 96.0)
                 {
                     num5 = 3;
                 }
                 else if (levels.vegLevel > 16.0)
                 {
                     num5 = 2;
                 }
                 else if (levels.vegLevel > 0.0)
                 {
                     num5 = 1;
                 }
                 else
                 {
                     num5 = 0;
                 }
                 int num6 = 0;
                 if (levels.cheeseLevel > 416.0)
                 {
                     num6 = 4;
                 }
                 else if (levels.cheeseLevel > 96.0)
                 {
                     num6 = 3;
                 }
                 else if (levels.cheeseLevel > 16.0)
                 {
                     num6 = 2;
                 }
                 else if (levels.cheeseLevel > 0.0)
                 {
                     num6 = 1;
                 }
                 else
                 {
                     num6 = 0;
                 }
                 int num7 = 0;
                 if (levels.applesLevel > 96.0)
                 {
                     num7 = 3;
                 }
                 else if (levels.applesLevel > 16.0)
                 {
                     num7 = 2;
                 }
                 else if (levels.applesLevel > 0.0)
                 {
                     num7 = 1;
                 }
                 else
                 {
                     num7 = 0;
                 }
                 int num8 = 0;
                 if (levels.fishLevel > 96.0)
                 {
                     num8 = 3;
                 }
                 else if (levels.fishLevel > 16.0)
                 {
                     num8 = 2;
                 }
                 else if (levels.fishLevel > 0.0)
                 {
                     num8 = 1;
                 }
                 else
                 {
                     num8 = 0;
                 }
                 int num9 = 0;
                 if (levels.breadLevel > 832.0)
                 {
                     num9 = 4;
                 }
                 else if (levels.breadLevel > 192.0)
                 {
                     num9 = 3;
                 }
                 else if (levels.breadLevel > 32.0)
                 {
                     num9 = 2;
                 }
                 else if (levels.breadLevel > 0.0)
                 {
                     num9 = 1;
                 }
                 else
                 {
                     num9 = 0;
                 }
                 int cellID = 0;
                 for (int k = 0; k < index; k++)
                 {
                     cellID = this.meatPileOrder[k];
                     if (k != (index - 1))
                     {
                         this.granaryExtension.showGood(gfx, cellID, 0x10, 0x10);
                     }
                     else
                     {
                         int num12 = (((int) levels.meatLevel) - this.goods16Levels[index]) / this.goodsDividers[index];
                         this.granaryExtension.showGood(gfx, cellID, 0x10, Math.Min(num12, 0x10));
                     }
                 }
                 for (int m = 0; m < num5; m++)
                 {
                     cellID = this.vegPileOrder[m];
                     if (m != (num5 - 1))
                     {
                         this.granaryExtension.showGood(gfx, cellID, 15, 0x10);
                     }
                     else
                     {
                         int num14 = (((int) levels.vegLevel) - this.goods16Levels[num5]) / this.goodsDividers[num5];
                         this.granaryExtension.showGood(gfx, cellID, 15, Math.Min(num14, 0x10));
                     }
                 }
                 for (int n = 0; n < num6; n++)
                 {
                     cellID = this.cheesePileOrder[n];
                     if (n != (num6 - 1))
                     {
                         this.granaryExtension.showGood(gfx, cellID, 0x11, 0x10);
                     }
                     else
                     {
                         int num16 = (((int) levels.cheeseLevel) - this.goods16Levels[num6]) / this.goodsDividers[num6];
                         this.granaryExtension.showGood(gfx, cellID, 0x11, Math.Min(num16, 0x10));
                     }
                 }
                 for (int num17 = 0; num17 < num7; num17++)
                 {
                     cellID = this.applesPileOrder[num17];
                     if (num17 != (num7 - 1))
                     {
                         this.granaryExtension.showGood(gfx, cellID, 13, 0x10);
                     }
                     else
                     {
                         int num18 = (((int) levels.applesLevel) - this.goods16Levels[num7]) / this.goodsDividers[num7];
                         this.granaryExtension.showGood(gfx, cellID, 13, Math.Min(num18, 0x10));
                     }
                 }
                 for (int num19 = 0; num19 < num8; num19++)
                 {
                     cellID = this.fishPileOrder[num19];
                     if (num19 != (num8 - 1))
                     {
                         this.granaryExtension.showGood(gfx, cellID, 0x12, 0x10);
                     }
                     else
                     {
                         int num20 = (((int) levels.fishLevel) - this.goods16Levels[num8]) / this.goodsDividers[num8];
                         this.granaryExtension.showGood(gfx, cellID, 0x12, Math.Min(num20, 0x10));
                     }
                 }
                 for (int num21 = 0; num21 < num9; num21++)
                 {
                     cellID = this.breadPileOrder[num21];
                     if (num21 != (num9 - 1))
                     {
                         this.granaryExtension.showGood(gfx, cellID, 14, 0x20);
                     }
                     else
                     {
                         int num22 = (((int) levels.breadLevel) - (this.goods16Levels[num9] * 2)) / this.goodsDividers[num9];
                         this.granaryExtension.showGood(gfx, cellID, 14, Math.Min(num22, 0x20));
                     }
                 }
             }
         }
     }
 }
 public void updateGranary(GraphicsMgr gfx, VillageMap vm)
 {
     if (this.baseSprite != null)
     {
         if (this.granaryExtension == null)
         {
             this.granaryExtension = new VillageMapBuildingGranaryExtension();
             for (int j = 0; j < 0x15; j++)
             {
                 this.granaryExtension.cell[j]         = new SpriteWrapper();
                 this.granaryExtension.cell[j].Visible = false;
                 this.granaryExtension.cell[j].PosX    = 5 + VillageMapBuildingGranaryExtension.granaryLayout[j * 2];
                 this.granaryExtension.cell[j].PosY    = -33 + VillageMapBuildingGranaryExtension.granaryLayout[(j * 2) + 1];
                 this.baseSprite.AddChild(this.granaryExtension.cell[j]);
                 this.granaryExtension.showGood(gfx, j, -1, 0);
             }
         }
         for (int i = 0; i < 0x15; i++)
         {
             this.granaryExtension.showGood(gfx, i, -1, 0);
         }
         VillageMap.GranaryLevels levels = new VillageMap.GranaryLevels();
         if (vm.getGranaryLevels(levels))
         {
             if (vm.granaryOpenCount == 0)
             {
                 this.open = false;
             }
             double num3 = ((((levels.applesLevel + levels.breadLevel) + levels.cheeseLevel) + levels.fishLevel) + levels.meatLevel) + levels.vegLevel;
             if (num3 > 0.0)
             {
                 if (vm.granaryOpenCount > 0)
                 {
                     this.open = true;
                 }
                 else
                 {
                     return;
                 }
                 int index = 0;
                 if (levels.meatLevel > 416.0)
                 {
                     index = 4;
                 }
                 else if (levels.meatLevel > 96.0)
                 {
                     index = 3;
                 }
                 else if (levels.meatLevel > 16.0)
                 {
                     index = 2;
                 }
                 else if (levels.meatLevel > 0.0)
                 {
                     index = 1;
                 }
                 else
                 {
                     index = 0;
                 }
                 int num5 = 0;
                 if (levels.vegLevel > 96.0)
                 {
                     num5 = 3;
                 }
                 else if (levels.vegLevel > 16.0)
                 {
                     num5 = 2;
                 }
                 else if (levels.vegLevel > 0.0)
                 {
                     num5 = 1;
                 }
                 else
                 {
                     num5 = 0;
                 }
                 int num6 = 0;
                 if (levels.cheeseLevel > 416.0)
                 {
                     num6 = 4;
                 }
                 else if (levels.cheeseLevel > 96.0)
                 {
                     num6 = 3;
                 }
                 else if (levels.cheeseLevel > 16.0)
                 {
                     num6 = 2;
                 }
                 else if (levels.cheeseLevel > 0.0)
                 {
                     num6 = 1;
                 }
                 else
                 {
                     num6 = 0;
                 }
                 int num7 = 0;
                 if (levels.applesLevel > 96.0)
                 {
                     num7 = 3;
                 }
                 else if (levels.applesLevel > 16.0)
                 {
                     num7 = 2;
                 }
                 else if (levels.applesLevel > 0.0)
                 {
                     num7 = 1;
                 }
                 else
                 {
                     num7 = 0;
                 }
                 int num8 = 0;
                 if (levels.fishLevel > 96.0)
                 {
                     num8 = 3;
                 }
                 else if (levels.fishLevel > 16.0)
                 {
                     num8 = 2;
                 }
                 else if (levels.fishLevel > 0.0)
                 {
                     num8 = 1;
                 }
                 else
                 {
                     num8 = 0;
                 }
                 int num9 = 0;
                 if (levels.breadLevel > 832.0)
                 {
                     num9 = 4;
                 }
                 else if (levels.breadLevel > 192.0)
                 {
                     num9 = 3;
                 }
                 else if (levels.breadLevel > 32.0)
                 {
                     num9 = 2;
                 }
                 else if (levels.breadLevel > 0.0)
                 {
                     num9 = 1;
                 }
                 else
                 {
                     num9 = 0;
                 }
                 int cellID = 0;
                 for (int k = 0; k < index; k++)
                 {
                     cellID = this.meatPileOrder[k];
                     if (k != (index - 1))
                     {
                         this.granaryExtension.showGood(gfx, cellID, 0x10, 0x10);
                     }
                     else
                     {
                         int num12 = (((int)levels.meatLevel) - this.goods16Levels[index]) / this.goodsDividers[index];
                         this.granaryExtension.showGood(gfx, cellID, 0x10, Math.Min(num12, 0x10));
                     }
                 }
                 for (int m = 0; m < num5; m++)
                 {
                     cellID = this.vegPileOrder[m];
                     if (m != (num5 - 1))
                     {
                         this.granaryExtension.showGood(gfx, cellID, 15, 0x10);
                     }
                     else
                     {
                         int num14 = (((int)levels.vegLevel) - this.goods16Levels[num5]) / this.goodsDividers[num5];
                         this.granaryExtension.showGood(gfx, cellID, 15, Math.Min(num14, 0x10));
                     }
                 }
                 for (int n = 0; n < num6; n++)
                 {
                     cellID = this.cheesePileOrder[n];
                     if (n != (num6 - 1))
                     {
                         this.granaryExtension.showGood(gfx, cellID, 0x11, 0x10);
                     }
                     else
                     {
                         int num16 = (((int)levels.cheeseLevel) - this.goods16Levels[num6]) / this.goodsDividers[num6];
                         this.granaryExtension.showGood(gfx, cellID, 0x11, Math.Min(num16, 0x10));
                     }
                 }
                 for (int num17 = 0; num17 < num7; num17++)
                 {
                     cellID = this.applesPileOrder[num17];
                     if (num17 != (num7 - 1))
                     {
                         this.granaryExtension.showGood(gfx, cellID, 13, 0x10);
                     }
                     else
                     {
                         int num18 = (((int)levels.applesLevel) - this.goods16Levels[num7]) / this.goodsDividers[num7];
                         this.granaryExtension.showGood(gfx, cellID, 13, Math.Min(num18, 0x10));
                     }
                 }
                 for (int num19 = 0; num19 < num8; num19++)
                 {
                     cellID = this.fishPileOrder[num19];
                     if (num19 != (num8 - 1))
                     {
                         this.granaryExtension.showGood(gfx, cellID, 0x12, 0x10);
                     }
                     else
                     {
                         int num20 = (((int)levels.fishLevel) - this.goods16Levels[num8]) / this.goodsDividers[num8];
                         this.granaryExtension.showGood(gfx, cellID, 0x12, Math.Min(num20, 0x10));
                     }
                 }
                 for (int num21 = 0; num21 < num9; num21++)
                 {
                     cellID = this.breadPileOrder[num21];
                     if (num21 != (num9 - 1))
                     {
                         this.granaryExtension.showGood(gfx, cellID, 14, 0x20);
                     }
                     else
                     {
                         int num22 = (((int)levels.breadLevel) - (this.goods16Levels[num9] * 2)) / this.goodsDividers[num9];
                         this.granaryExtension.showGood(gfx, cellID, 14, Math.Min(num22, 0x20));
                     }
                 }
             }
         }
     }
 }