public override Selector ActivateBehavior(Dwarf d)
        {
            d.SetActionWorldObject(WorldObject) ;
            d.SetActionMapElement(WorldMap.Instance.GetMapElement(WorldObject.Position.X, WorldObject.Position.Y, WorldObject.Position.Z));

            return new CollectGameObject();
        }
        private TaskState FindPath(Dwarf d, float dt, double dtd)
        {
            WorldObject m = d.GetActionWorldObject();

            if (State == TaskState.NotActive)
            {
                AsyncPathfinding.RequestPathfinding(d, new Point((int)d.Position.X, (int)d.Position.Y), new Point(m.Position.X, m.Position.Y), 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]);

                Point p = paths[0].PathPoints[paths[0].PathPoints.Count - 1];

                if (p.X == m.Position.X && p.Y == m.Position.Y)
                {

                }
                else
                {

                }

                return TaskState.Success;
            }
        }
Example #3
0
        private TaskState FindPath(Dwarf d, float dt, double dtd)
        {
            if (State == TaskState.NotActive)
            {
                // If dwarf has no assigned bed, sleep where he currently is
                if (d.AssignedBed == null)
                    AsyncPathfinding.RequestPathfinding(d, new Point((int)d.Position.X, (int)d.Position.Y), new Point((int)d.Position.X, (int)d.Position.Y), null);
                else
                {
                    AsyncPathfinding.RequestPathfinding(d, new Point((int)d.Position.X, (int)d.Position.Y), d.AssignedBed.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;
            }
        }
Example #4
0
        public override Selector ActivateBehavior(Dwarf d)
        {
            d.SetActionBuilding(Tower);
            d.SetActionTower(Tower);

            return new MoveToTower();
        }
Example #5
0
 public static double GetDwarfWalkSpeed(double dtd, Dwarf d)
 {
     if (d.GetHoldingWorldObject() != null && d.GetHoldingWorldObject().Weight == Map.MapElementWeight.Heavy)
         return 0.003 * dtd;
     else
         return 0.005 * dtd;
 }
        public override Selector ActivateBehavior(Dwarf d)
        {
            d.SetActionPasture(Pasture);
            d.SetActionWorldObject(FoodItem);

            return new CollectFoodFromPasture();
        }
        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;
        }
 public override Selector ActivateBehavior(Dwarf d)
 {
     DwarfConsole.WriteLine("Move crafted task taken: " + Obj.ElementType + " - dwarf: " +d.Id, ConsoleColor.Red);
     d.SetActionBuilding(CraftBuilding);
     d.SetActionWorldObject(Obj);
     return new MoveCraftToDepot(CraftBuilding);
 }
Example #9
0
        private TaskState Move(Dwarf d, float dt, double dtd)
        {
            if (State == TaskState.NotActive)
            {
                if (d.MovePath.Count == 1)
                {

                }
                ChangeMoveTo(d);
            }

            // Improves hauling
            if (d.GetHoldingWorldObject() != null && d.GetHoldingWorldObject().Weight == MapElementWeight.Heavy)
                d.DidSomeHauling(dt);

            Vector2 addition = d.MoveToDirection * (float)DwarfRules.GetDwarfWalkSpeed(dtd, d);
            Vector2 newPosition = new Vector2(d.Position.X, d.Position.Y) + addition ;

            d.DistanceMoved = d.DistanceMoved + addition.Length();

            if (d.DistanceMoved >= d.MoveToDistance)
            {
                if (d.MovePath.Count == 0)
                    return TaskState.Success;
                d.ChangePosition(new Vector3(d.MoveTo.X, d.MoveTo.Y, 5));
                ChangeMoveTo(d);
            }
            else
                d.ChangePosition(new Vector3(newPosition.X, newPosition.Y, 5));

                return TaskState.Running;
        }
        private TaskState Pickup(Dwarf d, float dt, double dtd)
        {
            WorldObject obj = d.GetActionPasture().WithdrawWorldObject(d.GetActionWorldObject());
            d.CarryWorldObject(obj);

            return TaskState.Success;
        }
Example #11
0
        private TaskState FindPath(Dwarf d, float dt, double dtd)
        {
            if (State == TaskState.NotActive)
            {
                RequestPathfinding(d.GetActionMapElement(), d);
            }

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

            if (_paths.Count != _numberOfPathRequests)
                return TaskState.Running;
            else
            {
                Path shortest = Path.ShortestPath(_paths);

                if (shortest == null)
                    return TaskState.Fail;
                else
                {
                    d.SetMovePath(shortest);
                    return TaskState.Success;
                }

            }
        }
Example #12
0
        public override void Update(Dwarf d, float dt, double dtd)
        {
            if (_currentTask == null)
            {
                if (_currentTask == null)
                    return;
                _currentBehavior = _currentTask.ActivateBehavior(d);
            }

            _currentBehavior.Execute(d, dt, dtd);
            if (_currentBehavior.State == TaskState.Success)
            {
                Stop();
                Update(d, dt, dtd);
            }
            else if (_currentBehavior.State == TaskState.Fail)
            {
                Stop();
                Update(d, dt, dtd);
            }
            else if (_currentBehavior.State == TaskState.SmallFail)
            {
                Stop();
                Update(d, dt, dtd);
            }
            else if (_currentBehavior.State == TaskState.Absolete)
            {
                Stop();
                Update(d, dt, dtd);
            }

            base.Update(d, dt, dtd);
        }
Example #13
0
        private TaskState Find(Dwarf d, float dt, double dtd)
        {
            if (State == TaskState.NotActive)
            {

                    AsyncPathfinding.RequestPathfinding(d, new Point((int)d.Position.X, (int)d.Position.Y), new Point((int)d.GetActionVector().X, (int)d.GetActionVector().Y), null);
                    _numerOfPaths = 1;
            }

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

            if (_paths.Count > _numerOfPaths)
            {

            }

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

            PathfindingResult shortestPath = Path.ShortestPath(_paths);

            d.SetMovePath(shortestPath.Path);

            return TaskState.Success;
        }
 public override Selector ActivateBehavior(Dwarf d)
 {
     d.SetActionBuilding(GeneratorBuilding);
     d.SetActionLevel(1);
     d.SetActionMapElementType(Map.MapElementType.Coal);
     return new GetCoal();
 }
        private TaskState FindDepot(Dwarf d, float dt, double dtd)
        {
            if (d.GetActionMapElementType() == MapElementType.FoodSpecial)
            {

            }

            if (State == TaskState.NotActive)
            {
                List<BuildingRequest> depoesCandidates = new List<BuildingRequest>();

                    List<Building> depos = WorldMap.Instance.GetDepos(d.GetActionMapElementType(), d.GetActionLevel());
                    foreach (Building b in depos)
                    {
                        depoesCandidates.Add(new BuildingRequest() { Building = b, TypeToGet = d.GetActionMapElementType(), Level = d.GetActionLevel() });
                    }

                // If no depot exist that has the required materials, the behavier fails
                if (depoesCandidates.Count == 0)
                {
                    if (_buildBuilding.HasRequestedNeededResourcesForCrafting== true)
                        return TaskState.Fail;

                    if (CraftRules.IsMapElementTypeCraftable(d.GetActionMapElementType()) == true)
                    {
                        TaskManager.AddTask(new CraftingOfResourceTask(d.GetActionMapElementType(), d.GetActionLevel()));
                        _buildBuilding.HasRequestedNeededResourcesForCrafting = true;
                    }

                    return TaskState.Fail;
                }

                foreach (BuildingRequest b in depoesCandidates)
                {
                    AsyncPathfinding.RequestPathfinding(d, new Point((int)d.Position.X, (int)d.Position.Y), b.Building.GetActivationPoint(), b);
                    _numerOfPaths++;
                }
            }

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

            if (_paths.Count > _numerOfPaths)
            {

            }

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

            PathfindingResult shortestPath = Path.ShortestPath(_paths);
            BuildingRequest br = (BuildingRequest)shortestPath.Data;

            d.SetActionBuilding(br.Building);
            d.SetActionMapElementType(br.TypeToGet);
            d.SetActionLevel(br.Level);
            d.SetMovePath(shortestPath.Path);

            return TaskState.Success;
        }
Example #16
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;
        }
        public override Selector ActivateBehavior(Dwarf d)
        {
            d.SetActionMapElementType(Type);
            d.SetActionBuilding(Building);
            d.SetActionLevel(Level);

            return new GetBuildingMaterial(Building, this);
        }
Example #18
0
        public override Selector ActivateBehavior(Dwarf d)
        {
            d.SetActionWorldObject(WorldObject);
            d.SetActionMapElementType(WorldObject.ElementType);
            d.SetActionLevel(WorldObject.Level);

            return new PlaceWorldObject(this);
        }
Example #19
0
        public override Selector ActivateBehavior(Dwarf d)
        {
            d.SetActionWorldObject(Crop);
            d.SetActionMapElement(WorldMap.Instance.GetMapElement(Crop.Position.X, Crop.Position.Y, Crop.Position.Z));
            d.SetActionMapElementType(Crop.ElementType);

            return new HarvestCrop();
        }
Example #20
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;
 }
Example #21
0
        public void RegisterDwarf(Dwarf d)
        {
            _mutex.WaitOne();
            _dwarfs.Add(d, new DwarfDebugInfo());

            dwarfList.Items.Add(d.Id);
            _mutex.ReleaseMutex();
        }
Example #22
0
 private TaskState Work(Dwarf d, float dt, double dtd)
 {
     d.DidSomeFarming(dt);
     if (d.GetActionField().WorkOn(dt,dtd, d))
         return TaskState.Success;
     else
         return TaskState.Running;
 }
Example #23
0
 private TaskState Construct(Dwarf d, float dt, double dtd)
 {
     // TODO: WorldObject is currently constructed instantly because of this code line. This should change in the future
     d.GetActionWorldObject().CraftOnObject(d.GetActionWorldObject().CraftPointsNeeded);
     DwarfConsole.WriteLine("Placed Worldobject: " + d.GetActionWorldObject().ElementType +" " + d.GetActionWorldObject().Level, ConsoleColor.Blue);
     d.RemoveHoldingWorldObject();
     return TaskState.Success;
 }
Example #24
0
        private TaskState Harvest(Dwarf d, float dt, double dtd)
        {
            d.DidSomeFarming(dt);

            CropBase crop = (CropBase)d.GetActionWorldObject();
            d.CarryWorldObject(crop.TakeHarvest());

            return TaskState.Success;
        }
Example #25
0
        private TaskState DoSleep(Dwarf d, float dt, double dtd)
        {
            d.DidSomeSleep(dt);

            if (d.Stats.Tiredness >= 100)
                return TaskState.PersonalSuccess;
            else
                return TaskState.Running;
        }
Example #26
0
 public void BehaviorSuccessfull(Dwarf d, string behavior)
 {
     if (d.Type != LivingType.Dwarf)
         return;
     if (behavior.StartsWith("Bevelle.GameMono.Ai.Behavior.Action"))
         return;
     string behaviorShort = behavior.Remove(0, "Bevelle.GameMono.Ai.Behavior.Behaviors".Length);
     _dwarfs[d].AddBehavior(behaviorShort);
 }
Example #27
0
        public override Selector ActivateBehavior(Dwarf d)
        {
            d.SetActionMapElementType(MapElementType.Meal);

            return new MakeMeal(this);
            //d.SetActionBuilding(Building);

            //return new BuildBuilding(Building);
        }
 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 Check(Dwarf d, float dt, double dtd)
 {
     if (DoesBuildingHaveFreeCraftingSlot(d.GetActionbuilding()) == false)
     {
         d.GetActionbuilding().ReleaseForCrafting();
         return TaskState.Fail;
     }
     return TaskState.Success;
 }
Example #30
0
        private TaskState Fight(Dwarf d, float dt, double dtd)
        {
            if (TaskManager.GetTaskMode() == TaskMode.Peace)
            {
                d.GetActionTower().LeaveTower(d);
                return TaskState.Absolete;
            }

            return TaskState.Running;
        }