public bool gather(Agent A)
 {
     // can the agent gather from this garden?
     if (A.Home == owner)
         return true;
     return false;
 }
 public bool takeCare(Agent A)
 {
     // you can only take care of the garden if its part of your house
     if (A.Home == owner)
     {
         health += 5;
         return true;
     }
     return false;
 }
        public bool moveIn(Agent a)
        {
            if (currentOccupants.Count >= MaxCapacity)
                return false; // you can not move in here... its full

            // We should probably add stuff like if that person is liked or family then thay can move in
            // else they can not
            currentOccupants.Add(a);
            //Console.WriteLine("We now have " + currentOccupants.Count + " people living here.");
            return true;
        }
        public bool moveOut(Agent a)
        {
            if (currentOccupants.Contains(a))
            {
                currentOccupants.Remove(a);
                //Console.WriteLine("We now have " + currentOccupants.Count + " people living here.");
                a.Home = null;
            }
            else
                return false; // that person does not live here dummy

            return true;
        }
        public bool relax(Agent a)
        {
            if (!this.currentOccupants.Contains(a))
                return false; // you can not chill here
            // now while the agent is chilling they put all there inventory in the house
            int spaceLeft = MaxStorage - currentStorage;
            foreach (KeyValuePair<string, int> resource in a.Inventory)
            {
                int Gathered = Math.Min(spaceLeft, resource.Value);
                if (Inventory.ContainsKey(resource.Key))
                    Inventory[resource.Key] += Gathered;
                else
                    Inventory.Add(resource.Key, Gathered);
                currentStorage += Gathered;
            }
            a.Inventory.Clear();
            a.AmountInventory = 0;
            // Ok now that everything is in the house... lets chill
            // First we eat fruits!
            while (a.hungry < 30
                   && Inventory.ContainsKey("fruit"))
            {
                // while we are hungry.. we eat!
                if (Inventory["fruit"] > 5) // if we have enough food
                {
                    a.hungry += 5;
                    Inventory["fruit"] -= 5;
                    currentStorage -= 5;
                }
                else
                    break; //the house needs more food :(
            }
            // if we are still hungry... try some meat
            while (a.hungry < 30
                   && Inventory.ContainsKey("meat"))
            {
                // while we are hungry.. we eat!
                if (Inventory["meat"] > 5) // if we have enough food
                {
                    a.hungry += 10;
                    Inventory["meat"] -= 5;
                    currentStorage -= 5;
                }
                else
                    break; //the house needs more food :(
            }

            //We might need a garden... lets find out
            if (currentLevel > 0 && this.gardens < Math.Pow(currentLevel, 1.5))
            {
                // we are high enough level to build a garden
                if (Inventory.ContainsKey("fruit"))
                {
                    // we have enough fruit to create a garden
                    int NewX = X;
                    int NewY = Y;
                    int randomD = EnvironmentMap.Rand.Next(1, 4);
                    switch (randomD)
                    {
                        case 1:
                            ++NewX;
                            break;
                        case 2:
                            --NewX;
                            break;
                        case 3:
                            ++NewY;
                            break;
                        case 4:
                            --NewY;
                            break;
                    }

                    EnvironmentMap.add(new garden(bnet, this), NewX, NewY);
                    ++this.gardens;
                }
            }
            // how about a wood mill?
            if (currentLevel > 1 && this.woodmile < Math.Pow(currentLevel, 1))
            {
                // we are high enough level to build a garden
                if (Inventory.ContainsKey("wood"))
                {
                    // we have enough fruit to create a garden
                    int NewX = X;
                    int NewY = Y;
                    int randomD = EnvironmentMap.Rand.Next(1, 4);
                    switch (randomD)
                    {
                        case 1:
                            ++NewX;
                            ++NewY;
                            break;
                        case 2:
                            --NewX;
                            ++NewY;
                            break;
                        case 3:
                            ++NewX;
                            --NewY;
                            break;
                        case 4:
                            --NewX;
                            --NewY;
                            break;
                    }

                    EnvironmentMap.add(new woodmile(bnet, this), NewX, NewY);
                    ++this.woodmile;
                }
            }

            // Now we are well fead, lets go back to the hunt!
            if (currentOccupants.Count > (MaxCapacity / 2)
                && Inventory.ContainsKey("meat") && Inventory.ContainsKey("fruit")
                && (Inventory["meat"] + Inventory["fruit"]) > (optimal * MaxStorage))
            {
                if (currentLevel < 6)
                {
                    Dictionary<string, int> requirements = Upgrades[currentLevel];
                    if (Inventory.ContainsKey("wood") && Inventory["wood"] >= requirements["wood"])
                    {
                        if (Inventory.ContainsKey("stone") && Inventory["stone"] >= requirements["stone"])
                        {
                            // let's upgrade the house now.
                            Inventory["wood"] -= requirements["wood"];
                            currentStorage -= requirements["wood"];
                            Inventory["stone"] -= requirements["stone"];
                            currentStorage -= requirements["stone"];
                            MaxCapacity = requirements["NewCapacity"];
                            MaxStorage = requirements["NewStorage"];
                            ++currentLevel;
                            a.goal = "hunt";
                        }
                        else
                            a.goal = "collectStone";
                    }
                    else
                        a.goal = "collectWood";
                }
                else
                {
                    a.goal = "hunt";
                    // we are at max lvl inside the house
                }

            }
            else
            {
                a.goal = "hunt";
            }

            return true;
        }
        public bool addFamily(Agent a)
        {
            if (Family.Contains(a) || a.Family.Contains(this))
                return false;

            Family.Add(a);
            a.Family.Add(this);
            return true;
        }
        public override bool duplicate()
        {
            if (age < 18 || age > 50 ||
                hungry < 5)
                return false;

            HashSet<EnvironmentObject> O = EnvironmentMap.getAll(X, Y);
            double chance;
            bool other = false;

            foreach (EnvironmentObject E in O)
                // if there are other agents around.... try to mate with them
                if (E.name.Equals(this.name) && E.age > 20)
                    other = true;

            if (other && amIAtHome() && EnoughFood())
            {
                chance = EnvironmentMap.Rand.NextDouble();
                if (chance < chanceToDuplicate)
                {
                    Agent a = new Agent(bnet, this.Home);
                    // children enherite there parents family
                    a.addFamily(Family);
                    // and the parents teach the child the lay of the land
                    a.teach(myMap);
                    EnvironmentMap.add(a, X, Y);
                }
            }

            return true;
        }
        public bool relax(Agent a)
        {
            if (!this.currentOccupants.Contains(a))
                return false; // you can not chill here
            // now while the agent is chilling they put all there inventory in the house
            int spaceLeft = MaxStorage - currentStorage;
            foreach(KeyValuePair<string, int> resource in a.Inventory)
            {
                int Gathered = Math.Min(spaceLeft, resource.Value);
                if (Inventory.ContainsKey(resource.Key))
                    Inventory[resource.Key] += Gathered;
                else
                    Inventory.Add(resource.Key, Gathered);
                currentStorage += Gathered;
            }
            a.Inventory.Clear();
            a.AmountInventory = 0;
            // Ok now that everything is in the house... lets chill
            // First we eat fruits!
            while (a.hungry < 25
                   && Inventory.ContainsKey("fruit"))
            {
                // while we are hungry.. we eat!
                if (Inventory["fruit"] > 5) // if we have enough food
                {
                    a.hungry += 5;
                    Inventory["fruit"] -= 5;
                    currentStorage -= 5;
                }
                else
                    break; //the house needs more food :(
            }
            // if we are still hungry... try some meat
            while (a.hungry < 25
                && Inventory.ContainsKey("meat"))
            {
                // while we are hungry.. we eat!
                if (Inventory["meat"] > 5) // if we have enough food
                {
                    a.hungry += 10;
                    Inventory["meat"] -= 5;
                    currentStorage -= 5;
                }
                else
                    break; //the house needs more food :(
            }

            // Now we are well fead, lets go back to the hunt!
            if (currentOccupants.Count > (MaxCapacity / 2)
                && Inventory.ContainsKey("meat") && Inventory.ContainsKey("fruit")
                && (Inventory["meat"] + Inventory["fruit"]) > (optimal * MaxStorage))
            {
                if (Inventory.ContainsKey("wood") && Inventory["wood"] > 50)
                {
                    if (a.Inventory.ContainsKey("wood"))
                        a.Inventory["wood"] += 50;
                    else
                        a.Inventory.Add("wood", 50);

                    Inventory["wood"] -= 50;
                    currentStorage -= 50;
                    a.goal = "buildHouse";
                    this.moveOut(a);
                }
                else
                    a.goal = "collectWood";

            }
            else
            {
                a.goal = "hunt";
            }

            return true;
        }