Example #1
0
        private TaskState Find(Dwarf d, float dt)
        {
            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;
        }
 private TaskState Construct(Dwarf d, float dt)
 {
     d.GetActionWorldObject().CraftOnObject(d.GetActionWorldObject().CraftPointsNeeded);
     DwarfConsole.WriteLine("Placed Worldobject: " + d.GetActionWorldObject().ElementType +" " + d.GetActionWorldObject().Level, ConsoleColor.Blue);
     d.RemoveHoldingWorldObject();
     return TaskState.Success;
 }
Example #3
0
        public override TaskState Execute(Dwarf d, float dt)
        {
            foreach (Node s in Nodes)
            {
                if (s.State == TaskState.Success)
                    continue;
                // Den executer ikke FindPath.. :S
                State = s.Execute(d, dt);
                s.State = State;
                if (State == TaskState.Running)
                    return State;
                else if (State == TaskState.Fail)
                    return TaskState.Fail;
                else if (State == TaskState.SmallFail)
                    return TaskState.SmallFail;
                else if (State == TaskState.Absolete)
                    return TaskState.Absolete;
                else if (State == TaskState.PersonalFail)
                    return TaskState.PersonalFail;
                else if (State == TaskState.PersonalFailTryBehaviorAgain)
                    return TaskState.PersonalFailTryBehaviorAgain;
                else if (State == TaskState.PersonalSuccess)
                    return TaskState.PersonalSuccess;
            }

            return State;
        }
        private TaskState FindPath(Dwarf d, float dt)
        {
            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;
            }
        }
 public override Selector ActivateBehavior(Dwarf d)
 {
     d.SetActionBuilding(GeneratorBuilding);
     d.SetActionLevel(1);
     d.SetActionMapElementType(Map.MapElementType.Coal);
     return new GetCoal();
 }
Example #6
0
        private TaskState FindPath(Dwarf d, float dt)
        {
            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;
                }

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

            return TaskState.Success;
        }
Example #8
0
        private TaskState Move(Dwarf d, float dt)
        {
            if (State == TaskState.NotActive)
            {
                if (d.MovePath.Count == 1)
                {

                }
                ChangeMoveTo(d);
            }

            Vector2 addition = d.MoveToDirection * d.Speed * dt;
            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;
        }
Example #9
0
        public override Selector ActivateBehavior(Dwarf d)
        {
            d.SetActionBuilding(Tower);
            d.SetActionTower(Tower);

            return new MoveToTower();
        }
 public override Selector ActivateBehavior(Dwarf d)
 {
     DwarfConsole.WriteLine("Move crafted", ConsoleColor.Red);
     d.SetActionBuilding(CraftBuilding);
     d.SetActionWorldObject(Obj);
     return new MoveCraftToDepot(CraftBuilding);
 }
Example #11
0
        public override void Update(Dwarf d, float dt)
        {
            if (_currentTask == null)
            {
                if (_currentTask == null)
                    return;
                _currentBehavior = _currentTask.ActivateBehavior(d);
            }

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

            base.Update(d, dt);
        }
        public override Selector ActivateBehavior(Dwarf d)
        {
            d.SetActionPasture(Pasture);
            d.SetActionWorldObject(FoodItem);

            return new CollectFoodFromPasture();
        }
        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();
        }
        public override Selector ActivateBehavior(Dwarf d)
        {
            d.SetActionMapElementType(Type);
            d.SetActionBuilding(Building);
            d.SetActionLevel(Level);

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

            return new PlaceWorldObject(this);
        }
Example #16
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 #17
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;
 }
Example #19
0
        private TaskState Damage(Dwarf d, float dt)
        {
            MapElement e = d.GetActionMapElement();

            if (e.DoDamage(DamageRules.DamageMapElement(e, d)))
                return TaskState.Success;
            else
                return TaskState.Running;
        }
 private TaskState Check(Dwarf d, float dt)
 {
     if (DoesBuildingHaveFreeCraftingSlot(d.GetActionbuilding()) == false)
     {
         d.GetActionbuilding().ReleaseForCrafting();
         return TaskState.Fail;
     }
     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 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 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;
        }
        public override Selector ActivateBehavior(Dwarf d)
        {
            d.SetActionMapElementType(Type);
            d.SetActionLevel(Level);

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

            //return new BuildBuilding(Building);
        }
Example #25
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 FindDepot(Dwarf d, float dt)
        {
            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;
        }
        private TaskState Pickup(Dwarf d, float dt)
        {
            WorldObject me = d.GetActionWorldObject();

            //if ((int)d.Position.X != me.Position.X || (int)d.Position.Y != me.Position.Y)
            //    throw new Exception("Dwarf not in place");
            Console.WriteLine("Pickup: " + d.Id + " - " + d.GetActionWorldObject().Position.X + ", " + d.GetActionWorldObject().Position.Y);
            d.GetActionMapElement().RemoveFromMap();
            d.CarryWorldObject(d.GetActionWorldObject());
            return TaskState.Success;
        }
Example #28
0
        public static float DamageMapElement(MapElement element, Dwarf d)
        {
            if (element.ElementType == MapElementType.Grass)
                return 0.1f;
            else if (element.ElementType == MapElementType.Rock)
                return 0.1f;
            else if (element.ElementType == MapElementType.IronOreCube)
                return 0.1f;

            throw new Exception("Crap");
        }
Example #29
0
        private void ChangeMoveTo(Dwarf d)
        {
            d.MoveTo = d.MovePath.Pop();
            float dist = 0;
            d.MoveToDistance = Vector2.Distance(new Vector2(d.MoveTo.X, d.MoveTo.Y),new Vector2(d.Position.X, d.Position.Y));

            Vector2 dir = new Vector2(d.MoveTo.X, d.MoveTo.Y) - new Vector2(d.Position.X, d.Position.Y);
            Vector2.Normalize(ref dir, out dir);
            d.MoveToDirection = dir;

            d.DistanceMoved = 0;
        }
Example #30
0
        private TaskState Work(Dwarf d, float dt)
        {
            d.GetActionField().WorkOn(dt, d);

            if (d.GetActionField().IsWorkFinish())
            {
                d.GetActionField().MarkFieldForHarvesting();
                return TaskState.Success;
            }
            else
                return TaskState.Running;
        }