Esempio n. 1
0
    public void DepartFromTile(UrbTile Tile, UrbAgent Agent)
    {
        int Xoffset = 0;
        int Yoffset = 0;

        if (X == 1 && Y == 1)
        {
            UnprintAtTile(Print[0][0], Tile, Agent);
            s_ArriveAtTile_p.End();
            return;
        }

        if (X > 2 && Y > 2)
        {
            Vector2 Voffset = GetOffset();
            Xoffset = (int)Voffset.x;
            Yoffset = (int)Voffset.y;
        }

        for (int y = 0; y < Print.Length; y++)
        {
            for (int x = 0; x < Print[y].Length; x++)
            {
                UrbTile FillingTile = Tile.GetRelativeTile(x + Xoffset, y + Yoffset);

                if (FillingTile == null)
                {
                    continue;
                }

                UrbTileprintFill Fill = Print[y][x];
                UnprintAtTile(Fill, FillingTile, Agent);
            }
        }
    }
Esempio n. 2
0
    public UrbTile[] GetAllPrintTiles(UrbTile Tile)
    {
        int Xoffset = 0;
        int Yoffset = 0;

        if (X > 2 && Y > 2)
        {
            Vector2 Voffset = GetOffset();
            Xoffset = (int)Voffset.x;
            Yoffset = (int)Voffset.y;
        }
        else
        {
            return(new UrbTile[] { Tile });
        }

        UrbTile[] ReturnTiles = new UrbTile[X * Y];

        int Index = 0;

        for (int y = 0; y < Print.Length; y++)
        {
            for (int x = 0; x < Print[y].Length; x++)
            {
                UrbTile CheckedTile = Tile.GetRelativeTile(x + Xoffset, y + Yoffset);
                ReturnTiles[Index] = CheckedTile;
                Index++;
            }
        }

        return(ReturnTiles);
    }
Esempio n. 3
0
 public override void MouseClick(UrbTile currentCursorTile)
 {
     if (!UrbAgentSpawner.SpawnAgent(AgentTemplate, currentCursorTile, out _))
     {
         Debug.LogWarning("Failed to spawn agent from click");
     }
 }
Esempio n. 4
0
 public virtual void MouseExit(UrbTile input)
 {
     if (MapDisplay != null)
     {
         MapDisplay.SetActive(false);
     }
 }
Esempio n. 5
0
    public UrbTile GetTile(Vector3 Location)
    {
        if (LandMap == null)
        {
            return(null);
        }
        UrbTile Result       = null;
        bool    EmptySkyTile = true;

        if (SkyMap != null)
        {
            Result = SkyMap.GetInboundsTile(Location);


            if (Result != null && Result.Occupants != null && Result.Occupants.Count > 0)
            {
                EmptySkyTile = false;
            }
        }

        if (EmptySkyTile)
        {
            Result = LandMap.GetInboundsTile(Location);
        }

        return(Result);
    }
Esempio n. 6
0
    public override float PerformTask(UrbAgent Instigator, UrbTile WorkTile)
    {
        if (NoTarget || WorkTile.Occupants.Count == 0)
        {
            return(0);
        }

        if (Instigator.HasAction(UrbTestCategory.Hold))
        {
            UrbAction Action      = Instigator.PickAction(UrbTestCategory.Hold);
            float     CarryAmount = 0;

            if (WorkTile == TargetTile)
            {
            }
            else
            {
                for (int o = 0; o < WorkTile.Occupants.Count; o++)
                {
                }
            }
        }

        return(0);
    }
Esempio n. 7
0
    public override float TaskCompletionCostEstimate(UrbAgent Instigator, UrbTile WorkTile)
    {
        if (NoTarget)
        {
            return(float.MaxValue);
        }

        if (Instigator.HasAction(UrbTestCategory.Hold))
        {
            UrbAction Action       = Instigator.PickAction(UrbTestCategory.Hold);
            float     Estimate     = Action.CostEstimate(Instigator);
            float     CarryAmount  = Action.Test(Instigator);
            float     TargetAmount = GoalSubstance.SubstanceAmount - _TargetTile[GoalSubstance.Substance];
            if (CarryAmount >= TargetAmount)
            {
                return(Estimate);
            }
            else
            {
                return(Estimate * (TargetAmount / CarryAmount));
            }
        }

        return(float.MaxValue);
    }
Esempio n. 8
0
 public override void RegisterTileForBehaviour(float Evaluation, UrbTile Target, int Index)
 {
     if (Crowd < MateCrowding)
     {
         base.RegisterTileForBehaviour(Evaluation, Target, Index);
     }
 }
Esempio n. 9
0
    public override float TileEvaluateCheck(UrbTile Target, bool Contact = false)
    {
        if (Stomach == null || Target == null)
        {
            return(0);
        }

        s_TileEvaluateCheck_p.Begin();
        float Evaluation = 0;

        for (int o = 0; o < Target.Occupants.Count; o++)
        {
            if (Target.Occupants[o] == mAgent)
            {
                continue;
            }
            UrbBody PossibleFood = Target.Occupants[o].mBody;

            if (PossibleFood != null)
            {
                for (int f = 0; f < FoodSubstances.Length; f++)
                {
                    if (PossibleFood.BodyComposition == null)
                    {
                        break;
                    }
                    Evaluation += PossibleFood.BodyComposition[FoodSubstances[f]];
                }
            }
        }

        s_TileEvaluateCheck_p.End();
        return(Evaluation * Stomach.Emptiness);
    }
Esempio n. 10
0
    //The reason this is here is because it has a dependency which is
    //not necessarily available until after OnEnable, etc, have been called. 
    protected void SyncContacts()
    {
        List<UrbBehaviour> ContactList = new List<UrbBehaviour>();
        List<UrbBehaviour> SenseList = new List<UrbBehaviour>();

        UrbTile currentTile = mAgent.CurrentTile; 
        Assert.IsNotNull(currentTile, $"AgentLocalName: {mAgent.AgentLocalName}, ID: {mAgent.ID}");
        
        for (int c = 0; c < Components.Length; c++)
        {
            if (!(Components[c].TileEvaluateCheck(currentTile) > -1f))
            {
                continue;
            }

            if (Components[c].ContactBehaviour)
            {
                ContactList.Add(Components[c]);
            }
            else if (Components[c].SenseBehaviour)
            {
                SenseList.Add(Components[c]);
            }
        }
        cBehaviours = ContactList.ToArray();
        sBehaviours = SenseList.ToArray();
        ContactList.Clear();
        
        contactsSynced = true;
    }
Esempio n. 11
0
    public override void RegisterTileForBehaviour(float Evaluation, UrbTile Target, int Index)
    {
        s_RegisterTileForBehaviour_p.Begin();
        for (int o = 0; o < Target.Occupants.Count; o++)
        {
            if (Target.Occupants[o] == mAgent)
            {
                continue;
            }
            UrbBody PossibleFood = Target.Occupants[o].mBody;

            if (PossibleFood != null)
            {
                for (int f = 0; f < FoodSubstances.Length; f++)
                {
                    if (PossibleFood.BodyComposition == null)
                    {
                        break;
                    }
                    if (PossibleFood.BodyComposition[FoodSubstances[f]] > 0)
                    {
                        DetectedFood.Add(PossibleFood);
                        break;
                    }
                }
            }
        }
        base.RegisterTileForBehaviour(Evaluation, Target, Index);
        s_RegisterTileForBehaviour_p.End();
    }
Esempio n. 12
0
 public virtual void MouseEnter(UrbTile input)
 {
     if (MapDisplay != null)
     {
         MapDisplay.SetActive(true);
     }
 }
Esempio n. 13
0
 public void MoveTo(UrbTile Goal)
 {
     if (Movement == null)
     {
         Movement = StartCoroutine(Moving(Goal));
     }
 }
Esempio n. 14
0
    public virtual Color GetColorFromTile(UrbTile Tile)
    {
        Color TileColor = DetectionColor;

        TileColor.a = 1 - (Tile.RemainingCapacity / UrbTile.TileCapacity);

        return(TileColor);
    }
Esempio n. 15
0
    public void ToggleLink(UrbTile input)
    {
        bool containedLink = RemoveLink(input);

        if (!containedLink)
        {
            AddLink(input);
        }
    }
Esempio n. 16
0
    public virtual void AssignDisplayFromTile(int DisplayIndex, UrbTile Tile)
    {
        if (Tile == null || DisplayIndex >= InvestigationDisplay.Length)
        {
            return;
        }

        InvestigationDisplay[DisplayIndex].transform.position = Tile.RawLocation;
        InvestigationDisplay[DisplayIndex].enabled            = true;

        InvestigationDisplay[DisplayIndex].color = GetColorFromTile(Tile);
    }
Esempio n. 17
0
    public override float TileEvaluateCheck(UrbTile Target, bool Contact = false)
    {
        float value = 0;

        if (WorkerTasks.Count < MaxTasks)
        {
        }
        for (int j = 0; j < WorkerTasks.Count; j++)
        {
            value += WorkerTasks[j].Task.TaskSuitableTileCheck(Target);
        }
        return(value);
    }
Esempio n. 18
0
    public UrbEnvironment(UrbTile Owner)
    {
        Conditions = new float[MaxCond];
        Transfer   = new float[MaxCond];

        for (int i = 0; i < MaxCond; i++)
        {
            Conditions[i] = 0.0f;
            Transfer[i]   = 1.0f;
        }

        OwningTile = Owner;
    }
Esempio n. 19
0
    public virtual void MouseOver(UrbTile input)
    {
        if (input == null)
        {
            return;
        }

        if (MapDisplayInitialized)
        {
            MapDisplay.transform.position   = input.Location;
            MapDisplay.transform.localScale = new Vector3(input.OwningMap.TileSize, input.OwningMap.TileSize, input.OwningMap.TileSize);
        }
    }
Esempio n. 20
0
    public override void MouseOver(UrbTile input)
    {
        if (UrbUIManager.Instance.OverlayPrint != null)
        {
            HideDisplay();
            UrbTile[] OverlayTiles = UrbUIManager.Instance.OverlayPrint.GetAllPrintTiles(input);

            for (int i = 0; i < OverlayTiles.Length; i++)
            {
                AssignDisplayFromTile(i, OverlayTiles[i]);
            }
        }

        base.MouseOver(input);
    }
Esempio n. 21
0
    public static UrbAgent LoadAgentFromID(int ID, UrbTile Tile, UrbObjectData Data)
    {
        if (ID < 0 || !HasInstance || ID >= Instance.AgentTypes.Count)
        {
            return(null);
        }

        if (!UrbAgentSpawner.SpawnAgent(Instance.AgentTypes[ID], Tile, out var AgentObject, Data))
        {
            return(null);
        }

        UrbAgent LoadedAgent = AgentObject.GetComponent <UrbAgent>();

        return(LoadedAgent);
    }
Esempio n. 22
0
    public void EvaluateSizeLimit()
    {
        if (Blocked)
        {
            PathableSize = 0;
            return;
        }
        UrbTile[] Adjacent = OwningMap.GetAdjacent(XAddress, YAddress);

        int fullOpen   = 0;
        int mediumOpen = 0;

        for (int i = 0; i < Adjacent.Length; i++)
        {
            UrbTile Tile = Adjacent[i];

            if (Tile == null || Tile.Blocked)
            {
                if (i > 4)
                {
                    break;
                }
            }
            else
            {
                fullOpen++;
                if (i > 1 && i < 5)
                {
                    mediumOpen++;
                }
            }
        }

        if (fullOpen > 7) // all eight directions are open
        {
            PathableSize = 3;
        }
        else if (mediumOpen > 2)
        {
            PathableSize = 2;
        }
        else
        {
            PathableSize = 1;
        }
        ScentDirty = true;
    }
Esempio n. 23
0
    private void OnSceneGUI()
    {
        //if (Event.current.type == EventType.Repaint)

        Vector3 Position = ((UrbMap)target).transform.position;

        {
            Handles.color = ((UrbMap)target).Color;

            float width  = ((UrbMap)target).TileSize * ((UrbMap)target).Xsize;
            float height = ((UrbMap)target).TileSize * ((UrbMap)target).Ysize;



            Rect MapRect = new Rect(Position, new Vector2(width, height));
            Handles.DrawSolidRectangleWithOutline(MapRect, Color.clear, ((UrbMap)target).Color);
        }

        if (((UrbMap)target).DebugDisplay)
        {
            UrbMap DisplayMap = (UrbMap)target;

            for (int x = 0; x < DisplayMap.Xsize; x++)
            {
                for (int y = 0; y < DisplayMap.Ysize; y++)
                {
                    UrbTile Tile = DisplayMap.GetTile(x, y);
                    if (Tile == null)
                    {
                        continue;
                    }

                    UrbTile[] LinkedTiles = Tile.GetLinked();

                    for (int l = 0; l < LinkedTiles.Length; l++)
                    {
                        if (LinkedTiles[l] == null)
                        {
                            continue;
                        }
                        Handles.color = Color.yellow;
                        Handles.DrawLine(Tile.Location, LinkedTiles[l].Location);
                    }
                }
            }
        }
    }
Esempio n. 24
0
 public virtual void ClearBehaviour()
 {
     s_ClearBehavior_p.Begin();
     if (LastBehaviourOrigin == null || LastBehaviourOrigin != mAgent.CurrentTile)
     {
         if (RegisteredTiles != null)
         {
             for (int t = 0; t < RegisteredTiles.Length; t++)
             {
                 RegisteredTiles[t] = null;
             }
         }
         LastBehaviourOrigin = mAgent.CurrentTile;
     }
     BehaviourEvaluation = 0;
     s_ClearBehavior_p.End();
 }
Esempio n. 25
0
    protected void CacheTiles(bool GetLinked)
    {
        UrbTile[] Self = mAgent.Tileprint.GetAllPrintTiles(mAgent);

        UrbTile[] Adjacent = mAgent.Tileprint.GetBorderingTiles(mAgent, GetLinked);

        UrbTile[] SearchTiles = new UrbTile[Adjacent.Length + Self.Length];

        Self.CopyTo(SearchTiles, 0);

        Adjacent.CopyTo(SearchTiles, Self.Length);

        LastOriginTile   = mAgent.CurrentTile;
        CachedSearchTile = SearchTiles;
        CachedSelfTile   = Self;
        CachedAdjacent   = Adjacent;
    }
Esempio n. 26
0
    public IEnumerator Moving(UrbTile Goal)
    {
        s_Moving_p.Begin();
        Vector3 StartingPosition = transform.position;
        float   Complete         = 0;

        if (Speed > 0)
        {
            if (mAgent.Display)
            {
                Vector3 Direction = Goal.Location - StartingPosition;

                mAgent.Display.Flip = Direction.x > 0;
            }

            if (mAgent.CurrentTile != null)
            {
                mAgent.CurrentTile.OnAgentLeave(mAgent);
                if (Goal != mAgent.CurrentTile)
                {
                    if (mAgent.Metabolism != null)
                    {
                        mAgent.Metabolism.SpendEnergy(EnergyCost * mAgent.Mass * mAgent.Mass);
                    }
                }
            }
            Goal.OnAgentArrive(mAgent);

            float   TravelTime      = (1 / Speed);
            float   ArrivalTime     = Time.time + TravelTime;
            float   StartTime       = Time.time;
            Vector3 ArrivalLocation = Goal.Location;
            while (Complete < 1.0f)
            {
                //This is absolutely atrocious but I'm not sure how else to manage this
                s_Moving_p.End();
                yield return(new WaitForEndOfFrame());

                s_Moving_p.Begin();
                mAgent.transform.position = Vector3.Lerp(StartingPosition, ArrivalLocation, Complete);
                Complete = (Time.time - StartTime) / TravelTime;
            }
        }
        Movement = null;
        s_Moving_p.End();
    }
Esempio n. 27
0
    //Contact is for saying what KIND of check - only when trying to do something that REQUIRES a contact
    // A contact is done for checks that require sharing a tile with another entity
    // "Roughly things that are roughly in-reach"
    public override float TileEvaluateCheck(UrbTile Target, bool Contact = false)
    {
        if (Target?.Occupants == null)
        {
            return(0);
        }

        s_UrbMergeTileEvalCheck_p.Begin(this);
        //Evaluation tells us to what degree the current behavior of the entity cares
        //about the Target tile.
        float Evaluation = 0;

        for (int c = 0; c < Target.Occupants.Count; c++)
        {
            if (MergeProduct.TemplatesMatch(Target.Occupants[c]))
            {
                logger.Log("Attempting to merge into target", this);
                MergeIntoTarget(Target.Occupants[c]);
                break;
            }
            UrbMerge[] MergeComponents = Target.Occupants[c].GetComponents <UrbMerge>();
            for (int i = 0; i < MergeComponents.Length; i++)
            {
                var mergeComp = MergeComponents[i];
                if (mergeComp.WasDestroyed)
                {
                    logger.Log("A potential mergeComponent was destroyed", this);
                    continue;
                }

                if (mergeComp == this || !MergeProduct.TemplatesMatch(mergeComp.MergeProduct))
                {
                    continue;
                }

                if (mAgent.Mass >= Target.Occupants[c].Mass)
                {
                    Evaluation += Target.Occupants[c].Mass;
                }
            }
        }

        s_UrbMergeTileEvalCheck_p.End();
        return(Evaluation);
    }
Esempio n. 28
0
 public override void RegisterTileForBehaviour(float Evaluation, UrbTile Target, int Index)
 {
     //Get all the merges
     for (int c = 0; c < Target.Occupants.Count; c++)
     {
         UrbMerge[] MergeComponents = Target.Occupants[c].GetComponents <UrbMerge>();
         for (int i = 0; i < MergeComponents.Length; i++)
         {
             if (MergeComponents[i] != this && mAgent.Mass >= Target.Occupants[c].Mass)
             {
                 TotalMass  += Target.Occupants[c].Mass;
                 TotalCount += 1;
             }
         }
     }
     TotalTiles++;
     base.RegisterTileForBehaviour(Evaluation, Target, Index);
 }
Esempio n. 29
0
    public override void MouseClick(UrbTile currentCursorTile)
    {
        Ray     mouseray = Camera.main.ScreenPointToRay(Input.mousePosition);
        Vector3 Location = mouseray.origin;

        Collider2D Result = Physics2D.OverlapCircle(Location, 0.1f);

        if (Result != null)
        {
            UrbAgent SelectedAgent = Result.GetComponentInParent <UrbAgent>();
            if (SelectedAgent != null)
            {
                SelectedAgent.Remove();
            }
        }

        base.MouseClick(currentCursorTile);
    }
Esempio n. 30
0
    public bool LoadTileFromData(UrbTileData input)
    {
        LinksDirty = true;
        if (input.Links.Length > 0)
        {
            Links = new UrbTile[input.Links.Length];

            for (int i = 0; i < Links.Length; i++)
            {
                UrbMap LinkedMap = UrbSystemIO.GetMapFromID(input.Links[i].MapID);
                if (LinkedMap != null)
                {
                    UrbTile LinkedTile = LinkedMap.GetTile(input.Links[i].X, input.Links[i].Y);
                    Links[i] = LinkedTile;
                }
            }
        }
        else
        {
            Links = new UrbTile[0];
        }

        ClearTile();

        if (input.Contents != null && input.Contents.Length > 0)
        {
            for (int c = 0; c < input.Contents.Length; c++)
            {
                UrbSystemIO.LoadAgentFromID(input.Contents[c], this, input.Objects[c]);
            }
        }

        Blocked = input.Blocked;
        Environment.LoadEnvironmentFromData(input.Environment);
        // This is broken somehow, fix it.

        /*TerrainTypes = new UrbPathTerrain[input.TerrainTypes.Length];
         *
         * for (int i = 0; i < TerrainTypes.Length; i++)
         * {
         *  TerrainTypes[i] = input.TerrainTypes[i];
         * }*/
        return(true);
    }