private TaskState Check(Dwarf d, float dt, double dtd)
        {
            // Checks if building has the necessary building materials to build the building. If not, order it
            Dictionary<MapElementType, int> needed = d.GetActionbuilding().GetMapElementsNeededForConstruction();
            if (needed.Count > 0)
            {
                // If needed resources has already been requested
                if (_bb.HasRequestedNeededResourcesForConstruction == true)
                    return TaskState.Fail;

                // If not, request the resources
                foreach (KeyValuePair<MapElementType, int> need in needed)
                {
                    for (int i = 0; i < need.Value; i++)
                    {
                        TaskManager.AddTask(new GetBuildingMaterialTask(need.Key, 1, d.GetActionbuilding()));
                    }
                }
                _bb.HasRequestedNeededResourcesForConstruction = true;
                return TaskState.Fail;
            }

            // Success if the building has all the necessary buidling materials
            return TaskState.Success;
        }
示例#2
0
 private TaskState Check(Dwarf d, float dt, double dtd)
 {
     if (d.GetActionbuilding().GetCraftSlot() == null)
         return TaskState.Absolete;
     if (d.GetActionbuilding().GetCraftSlot().Id.ToString() != d.GetActionWorldObject().Id.ToString())
         return TaskState.Absolete;
     return TaskState.Success;
 }
 private TaskState Check(Dwarf d, float dt, double dtd)
 {
     if (DoesBuildingHaveFreeCraftingSlot(d.GetActionbuilding()) == false)
     {
         d.GetActionbuilding().ReleaseForCrafting();
         return TaskState.Fail;
     }
     return TaskState.Success;
 }
 private TaskState Check(Dwarf d, float dt, double dtd)
 {
     if (DoesBuildingHaveNecessaryMaterialsForCrafting(d.GetActionbuilding(), WorldObject.CreateWorldObject(d.GetActionMapElementType(), d.GetActionLevel())) == false)
     {
         d.GetActionbuilding().ReleaseForCrafting();
         return TaskState.Fail;
     }
     return TaskState.Success;
 }
 private TaskState Pickup(Dwarf d, float dt, double dtd)
 {
     if (d.GetActionbuilding().GetCraftSlot() == null)
     {
         return TaskState.Absolete;
         throw new Exception("If this happes, it might be a bug. If it happens very rarely, just make the task fail. It might fail infinently.. That might be a problem");
     }
     WorldObject m = d.GetActionbuilding().TakeCraftSlot();
     d.CarryWorldObject(m);
     return TaskState.Success;
 }
示例#6
0
        private TaskState Construct(Dwarf d, float dt, double dtd)
        {
            d.GetActionbuilding().ConstructOnBuilding(ConstructionRules.GetDwarfConstructionPoints(d));
            d.DidSomeConstruction(dt);

            if (d.GetActionbuilding().IsBuildingConstructed())
            {
                return TaskState.Success;
            }
            else
                return TaskState.Running;
        }
        private TaskState Deposit(Dwarf d, float dt, double dtd)
        {
            //DwarfConsole.WriteLine("DepositeInBuilding: " + d.GetActionbuilding().BuildingType + " " + d.GetActionbuilding().Id + ", " + d.GetHoldingWorldObject().ElementType + " " + d.GetHoldingWorldObject().Level, ConsoleColor.Green);
            WorldObject m = d.RemoveHoldingWorldObject();

            if (m == null)
                throw new Exception("The dwarf was not carrying any item, and failed to deposit");
                //return TaskState.Fail;

            d.GetActionbuilding().DepositWorldObject(m);

            return TaskState.Success;
        }
示例#8
0
        private TaskState Pickup(Dwarf d, float dt, double dtd)
        {
            WorldObject tool = d.GetActionWorldObject();

            d.GetActionbuilding().WithdrawWorldObject(tool);

            //if (WorldMap.Instance.GetDeposWithTool().Count == 0)
            //    return TaskState.PersonalFail;
            //else
            //    return TaskState.PersonalFailTryBehaviorAgain;

            d.CarryWorldObject(tool);

            return TaskState.Success;
        }
示例#9
0
        private TaskState Pickup(Dwarf d, float dt, double dtd)
        {
            WorldObject food = d.GetActionWorldObject();

            d.GetActionbuilding().WithdrawWorldObject(food);

            //if (food == null)
            //{
            //    if (WorldMap.Instance.GetDeposWithFood().Count == 0)
            //        return TaskState.PersonalFail;
            //    return TaskState.PersonalFailTryBehaviorAgain;
            //}

            d.CarryWorldObject(food);

            return TaskState.Success;
        }
        private TaskState Generate(Dwarf d, float dt, double dtd)
        {
            if (State == TaskState.NotActive)
                d.TimeWorked = 0;

            d.TimeWorked += dt;

            SimulationWorld.Instance.GeneratePower(dt * Settings.POWER_PRODUCES_BY_BIKE);

            if (d.TimeWorked >= Settings.WORK_TIME_FOR_BIKE)
            {
                d.TimeWorked = 0;
                TaskManager.AddTask(new BikeGenerationTask(d.GetActionbuilding()));
                return TaskState.Success;
            }
            else
                return TaskState.Running;
        }
        private TaskState Pickup(Dwarf d, float dt, double dtd)
        {
            WorldObject m = d.GetActionbuilding().WithdrawWorldObject(d.GetActionMapElementType(), d.GetActionLevel());

            if (m == null)
                return TaskState.Fail;

            if (m.RegisteredForConsumption == true)
            {
                //throw new Exception("");
            }

            if (m.ElementType == MapElementType.Plank)
                DwarfDebugInfo.PlanksPickedUp++;

            d.CarryWorldObject(m);
            d.SetActionBuilding(d.GetPrevActionBuilding());
            return TaskState.Success;
        }
        private TaskState FindPath(Dwarf d, float dt, double dtd)
        {
            if (State == TaskState.NotActive)
            {
                AsyncPathfinding.RequestPathfinding(d, new Point((int)d.Position.X, (int)d.Position.Y), d.GetActionbuilding().GetActivationPoint(), null);
            }

            List<Path> paths = AsyncPathfinding.GetFinishedPaths(d);
            if (paths.Count == 0)
                return TaskState.Running;
            else
            {
                if (paths[0] == null)
                    return TaskState.Fail;

                d.SetMovePath(paths[0]);
                return TaskState.Success;
            }
        }
示例#13
0
        private TaskState CraftItem(Dwarf d, float dt, double dtd)
        {
            if (State == TaskState.NotActive) // DEADEDIT: Not sure about this || ... fixes a bug where line 50 will crash, because GetCraftSlot() is null.. but that should not happen (i think)
            {
                if (
                    d.GetActionbuilding().GetCraftSlot() != null && // If an item is being crafted
                    d.GetActionbuilding().GetCraftSlot().ElementType != d.GetActionMapElementType() // and the item is different than the item the dwarf wants to craft
                    )
                    throw new Exception("Can't craft, workshop allready in use");
                // If an item is already being crafted of the same kind

                if (
                    d.GetActionbuilding().GetCraftSlot() != null &&
                    d.GetActionbuilding().GetCraftSlot().ElementType != d.GetActionMapElementType() // DEADEDIT TODO: Mabey this should be == instead of !=
                    )
                {
                    DwarfConsole.WriteLine("Continues crafting, after it was aborted", ConsoleColor.Green);
                    // Do thothing
                }
                else
                {
                    // Creates a new item, that needs to be crafted
                    // TODO: Mabey this should first be created when the building has enough materials to make it?
                    WorldObject newWorldObject = (WorldObject)WorldObject.CreateWorldObject(d.GetActionMapElementType(), d.GetActionLevel());
                    d.GetActionbuilding().SetCraftSlot(newWorldObject);
                }
            }

            // DEADEDIT: Removed because of copy paste
            //if (DoesBuildingHaveNecessaryMaterialsForCrafting(d.GetActionbuilding(), d.GetActionbuilding().GetCraftSlot()) == false)
            //{
            //    d.GetActionbuilding().ReleaseDwarfFromCrafting();
            //    return TaskState.Fail;
            //}

            // Increases cooking stats
            if (d.GetActionMapElementType() == MapElementType.Meal)
            {
                d.DidSomeCooking(dt);
            }
            else
            {
                d.DidSomeCrafting(dt);
            }
            // Craft on the item
            d.GetActionbuilding().CraftOnItemInCraftSlot(CraftRules.CraftOnItem(d.GetActionbuilding().BuildingType, d), dt, dtd);

            // Check if the item is crafted
            if (d.GetActionbuilding().GetCraftSlot().IsCrafted() == true)
            {
                RemoveUsedResources(d.GetActionbuilding(), d.GetActionbuilding().GetCraftSlot());
                DwarfConsole.WriteLine("Crafted: " + d.GetActionbuilding().GetCraftSlot().ElementType + " " + d.GetActionbuilding().GetCraftSlot().Level, ConsoleColor.Yellow);
                //d.CarryWorldObject(d.GetActionbuilding().TakeCraftSlot());
                d.GetActionbuilding().ReleaseForCrafting();
                return TaskState.Success;
            }
            else
                return TaskState.Running;
        }
        private TaskState FindPath(Dwarf d, float dt, double dtd)
        {
            if (d.GetActionMapElementType() == MapElementType.Meal)
            {

            }
            if (State == TaskState.NotActive)
            {
                //List<Building> craftingBuildings = WorldMap.Instance.GetCraftingBuildings(d.GetActionMapElementType());

                //if (d.GetActionMapElementType() == MapElementType.Arrow)
                //{

                //}

                //foreach (Building b in craftingBuildings)
                //{
                //    if (_cot.AssignedWorkshop != null && b != _cot.AssignedWorkshop)
                //        continue;

                Building b = d.AssignedWorkBuilding;

                if (b.IsCraftingItem() == false ||
                    //b.IsTakenByDwarf(d, d.GetActionMapElementType()) == true ||
                    (b.IsCraftingItem() == true && b.HasADwarfWorkingOnItem() == false && b.TypeThatIsBeingCrafted() == d.GetActionMapElementType()))
                {
                    AsyncPathfinding.RequestPathfinding(d, new Point((int)d.Position.X, (int)d.Position.Y), b.GetActivationPoint(), b);
                    _numerOfPaths++;

                }
                else
                {
                    DwarfConsole.WriteLine("DWARF TRIED TO TAKE CRAFTING BUILD, BUT WAS ALREADY IN USE. THIS SHOULD HAPPEN RARELY", ConsoleColor.DarkRed);
                    //Debugger.Break();
                    return TaskState.Fail;
                }

                // If no crafting building that can be used
                if (_numerOfPaths == 0)
                {
                    return TaskState.Fail;
                }

            }

            _paths.AddRange(AsyncPathfinding.GetFinishedPathsWithData(d));

            if (_numerOfPaths != _paths.Count)
                return TaskState.Running;

            PathfindingResult shortestPath = Path.ShortestPath(_paths);

            Building bb = (Building)shortestPath.Data;

            // If the crafting building was taken by another dwarf while we where calculating paths.
            if (bb.HasADwarfWorkingOnItem() == true)
                return TaskState.SmallFail;

            d.SetActionBuilding(bb);
            d.SetMovePath(shortestPath.Path);
            d.GetActionbuilding().TakeForCrafting(d, d.GetActionMapElementType());
            _cot.AssignedWorkshop = d.GetActionbuilding();

            return TaskState.Success;
        }