Esempio n. 1
0
 private TaskState Check(Dwarf d, float dt)
 {
     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 Pickup(Dwarf d, float dt)
 {
     if (d.GetActionbuilding().GetCraftSlot() == null)
         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;
 }
 private TaskState Check(Dwarf d, float dt)
 {
     if (DoesBuildingHaveNecessaryMaterialsForCrafting(d.GetActionbuilding(), WorldObject.CreateWorldObject(d.GetActionMapElementType(), d.GetActionLevel())) == false)
     {
         d.GetActionbuilding().ReleaseForCrafting();
         return TaskState.Fail;
     }
     return TaskState.Success;
 }
 private TaskState Check(Dwarf d, float dt)
 {
     if (DoesBuildingHaveFreeCraftingSlot(d.GetActionbuilding()) == false)
     {
         d.GetActionbuilding().ReleaseForCrafting();
         return TaskState.Fail;
     }
     return TaskState.Success;
 }
Esempio n. 5
0
 private TaskState Construct(Dwarf d, float dt)
 {
     d.GetActionbuilding().ConstructOnBuilding(ConstructionRules.DwarfConstructionPoints(d));
     if (d.GetActionbuilding().IsBuildingConstructed())
     {
         return TaskState.Success;
     }
     else
         return TaskState.Running;
 }
 private TaskState Pickup(Dwarf d, float dt)
 {
     WorldObject m = d.GetActionbuilding().WithdrawWorldObject(d.GetActionMapElementType(), d.GetActionLevel());
     if (m == null)
         return TaskState.Fail;
     d.CarryWorldObject(m);
     d.SetActionBuilding(d.GetPrevActionBuilding());
     return TaskState.Success;
 }
        private TaskState Deposit(Dwarf d, float dt)
        {
            //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("This should not happen");
                //return TaskState.Fail;

            d.GetActionbuilding().DepositWorldObject(m);

            return TaskState.Success;
        }
        private TaskState Check(Dwarf d, float dt)
        {
            // Checks if building has the necessary building materials. 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;
            }
            return TaskState.Success;
        }
Esempio n. 9
0
        private TaskState Pickup(Dwarf d, float dt)
        {
            WorldObject food = d.GetActionbuilding().WithdrawAnyFood();

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

            d.CarryWorldObject(food);

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

            d.TimeWorked += dt;

            SimulationWorld.Instance.GeneratePower(dt * 0.1f);

            if (d.TimeWorked >= 2000f)
            {
                d.TimeWorked = 0;
                TaskManager.AddTask(new BikeGenerationTask(d.GetActionbuilding()));
                return TaskState.Success;
            }
            else
                return TaskState.Running;
        }
Esempio n. 11
0
        private TaskState FindPath(Dwarf d, float dt)
        {
            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;
            }
        }
        private TaskState FindPath(Dwarf d, float dt)
        {
            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;

                    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
                        continue;
                }

                // 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;
        }
Esempio n. 13
0
        private TaskState CraftItem(Dwarf d, float dt)
        {
            if (State == TaskState.NotActive)
            {
                if (d.GetActionbuilding().GetCraftSlot() != null && d.GetActionbuilding().GetCraftSlot().ElementType != d.GetActionMapElementType())
                    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())
                {
                    DwarfConsole.WriteLine("Continues crafting, after it was aborted", ConsoleColor.Green);
                    // Do thothing
                }
                else
                    d.GetActionbuilding().SetCraftSlot((WorldObject)WorldObject.CreateWorldObject(d.GetActionMapElementType(), d.GetActionLevel()));
            }

            if (DoesBuildingHaveNecessaryMaterialsForCrafting(d.GetActionbuilding(), d.GetActionbuilding().GetCraftSlot()) == false)
            {
                d.GetActionbuilding().ReleaseDwarfFromCrafting();
                return TaskState.Fail;
            }

            d.GetActionbuilding().CraftOnItemInCraftSlot(CraftRules.CraftOnItem(d.GetActionbuilding().BuildingType, d), dt);

            // The item was 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;
        }