Example #1
0
    void TileAdditionChanged(Tile tile, TileAddition old, TileAddition addition)
    {
        if (old != null)
        {
            // Need to remove the old entry
            if (additions.ContainsKey(old.Name))
            {
                additions [old.Name].Remove(old);
            }
            else
            {
                Debug.LogError("An addition is being changed, but the old entry wasn't in the dictionary!");
            }
        }
        if (addition == null)
        {
            return;
        }

        if (!additions.ContainsKey(addition.Name))
        {
            // There is no list yet for this type of tile addition
            additions[addition.Name] = new List <TileAddition>();
        }
        additions [addition.Name].Add(addition);

        // Change the worlds graph if a door was added
        if (addition.Name == Door.AdditionName)
        {
            if (OnRoomDoorAdded != null)
            {
                OnRoomDoorAdded(this);
            }
        }
    }
    public ConstructionJob(TileAddition addition) : base()
    {
        Addition = addition;

        if (addition != null)
        {
            DestinationTile = addition.tile;
            addition.TileAdditionRemoved += TileAdditionRemoved;
        }
    }
    public HarvestJob(TileAddition addition) : base()
    {
        Addition = addition;

        if (addition != null)
        {
            addition.TileAdditionRemoved += TileAdditionRemoved;
            DestinationTile = addition.tile;
        }
    }
Example #4
0
    public PlantJob(TileAddition addition) : base()
    {
        Addition = addition;

        if (addition != null)
        {
            addition.TileAdditionRemoved += TileAdditionRemoved;
            addition.TileAdditionBuilt   += Addition_TileAdditionBuilt;
            DestinationTile = addition.tile;
        }
    }
Example #5
0
    /// <summary>
    /// Remove the currently installed addition from the tile.
    /// </summary>
    public void RemoveTileAddition()
    {
        TileAddition old = Addition;

        Addition = null;
        if (old != null)
        {
            old.UnregisterTileAddition();
        }
        OnTileAdditionChanged(this, old, Addition);
    }
Example #6
0
 private void ContainerRemoved(TileAddition addition)
 {
     if (addition is ItemContainer)
     {
         ItemContainer c = (ItemContainer)addition;
         activeContainers.Remove(c);
     }
     else
     {
         Debug.LogError("The tile addition telling us that it got removed is not an item container, so why are we getting a message from it?");
     }
 }
 /// <summary>
 /// Registered to when the tile addition is fully built. Registers the container as an available storage container
 /// </summary>
 /// <param name="container"></param>
 private void ContainerBuilt(TileAddition container)
 {
     Debug.Log("Container is built!");
     if (container == this)
     {
         tile.world.storageContainers.AddContainer(this);
     }
     else
     {
         Debug.LogError("Receiving information about a container that is built that is not this container?");
     }
 }
Example #8
0
    void OnTileAdditionChanged(Tile tile, TileAddition oldAddition, TileAddition newAddition)
    {
        // Installing a tile addition might require to update the graph
        if (oldAddition == null && newAddition != null)
        {
            InvalidateWorldGraph(tile.Room);
            return;
        }

        if (newAddition == null || oldAddition.MovementCostMultiplier != newAddition.MovementCostMultiplier)
        {
            InvalidateWorldGraph(tile.Room);
        }
    }
    void TryBuildAddition(Tile tile)
    {
        // North-South door
        Room north = world.GetTileAt(tile.X, tile.Y + 1).Room;
        Room south = world.GetTileAt(tile.X, tile.Y - 1).Room;
        Room east  = world.GetTileAt(tile.X + 1, tile.Y).Room;
        Room west  = world.GetTileAt(tile.X - 1, tile.Y).Room;

        if (proto == null)
        {
            tile.RemoveTileAddition();
        }
        else
        {
            TileAddition addition = proto.Clone(tile);
            if (tile.InstallAddition(addition))                // We can install the addition on the tile, so lets add a job to build it
            {
                switch (requiredSkill)
                {
                case Skills.Construction:
                    world.Jobs.EnqueueJob(new ConstructionJob(addition));
                    break;

                case Skills.Planting:
                    world.Jobs.EnqueueJob(new PlantJob(addition));
                    break;

                case Skills.Harvesting:
                    world.Jobs.EnqueueJob(new HarvestJob(addition));
                    break;

                default:
                    Debug.LogError("Don't know how to create a job for this skill");
                    break;
                }
            }
            else
            {
                Debug.Log("Can't install " + addition.Name + " at the tile" + addition.tile.ToString());
            }
        }
    }
    void OnTileAdditionWorkDone(TileAddition addition)
    {
        Tile tile = addition.tile;
        // For now we just set an alpha texture, later on we could do stages of progress based on the buildpercentage
        // At this point we know that there is a gameobject to render the new tile addition;

        //

        GameObject addition_go = additionGOMap [addition.tile];

        addition_go.transform.eulerAngles = new Vector3(0, 0, addition.Orientation);

        SpriteRenderer spriteRenderer = additionGOMap[tile].GetComponent <SpriteRenderer>();

        spriteRenderer.sprite = addition == null ? null : additionSprites [addition.GetRenderState()];
        Color c = spriteRenderer.color;

        c.a = addition.BuildPercentage == 1 ? 1 : 0.4f;
        spriteRenderer.color = c;
    }
Example #11
0
    public void ReadXml(XmlReader reader)
    {
        // X and Y is read at world level (to know which tile to load data for)
        borderDefinition = bool.Parse(reader.GetAttribute("DefinesRoomBorder"));
        this.TileType    = (TileType)int.Parse((reader.GetAttribute("TileType")));

        if (reader.ReadToDescendant("Addition"))
        {
            do
            {
                // We have an addition
                // For now lets juist build the serialization string
                string classPath    = reader.GetAttribute("TypePath");
                string assemblyName = reader.GetAttribute("Assembly");

                Type         targetType    = Type.GetType(classPath);
                TileAddition emptyAddition = (TileAddition)Activator.CreateInstance(targetType);
                emptyAddition.ReadXml(reader, this);
                InstallAddition(emptyAddition, false, true);
            } while (reader.ReadToNextSibling("Addition"));              // Should always be one, but how to advance?
        }
    }
    // Listens to the tile for when the adddition changes, merely updates our listener to start listening to the right addition
    void OnTileAdditionChanged(Tile tile, TileAddition oldAddition, TileAddition newAddition)
    {
        if (newAddition == null)
        {
            // No addition is present here anymore, just disable the SR for now (no need to delete the game object, we might need it later?)
            if (additionGOMap.ContainsKey(tile) == false)
            {
                return;
            }
            additionGOMap[tile].GetComponent <SpriteRenderer>().sprite = null;
            return;
        }

        if (additionGOMap.ContainsKey(tile) == false)
        {
            // There is no gameobject yet to visualise the tile additions for this tile
            // So lets create one
            GameObject additionGO = new GameObject();
            additionGOMap.Add(tile, additionGO);
            additionGO.name = "Addition_" + tile.X + "_" + tile.Y + ": " + (newAddition == null ? "" : newAddition.GetRenderState());
            additionGO.transform.position = new Vector3(tile.X, tile.Y, 0);
            additionGO.transform.SetParent(TileGOMap[tile].transform);
            additionGO.transform.eulerAngles = new Vector3(0, 0, newAddition.Orientation);

            SpriteRenderer sr = additionGO.AddComponent <SpriteRenderer>();
            sr.sprite           = newAddition == null ? null : additionSprites [newAddition.GetRenderState()];
            sr.sortingLayerName = "TileAdditions";
        }
        if (oldAddition != null)
        {
            oldAddition.WorkDone -= OnTileAdditionWorkDone;
        }

        newAddition.WorkDone += OnTileAdditionWorkDone;

        // Manually call OnWorkDone to update the texture
        OnTileAdditionWorkDone(newAddition);
    }
Example #13
0
    /// <summary>
    /// Installs the addition on the tile.
    /// </summary>
    /// <returns><c>true</c>, if addition was installed, <c>false</c> otherwise.</returns>
    /// <param name="addition">the addition to install.</param>
    /// <param name="fullyBuilt">If set to <c>true</c> the addition gets fully built</param>
    /// <param name="loading">If set to <c>true</c>, we are loading the world, so conditions don't apply (since the world isn't properly loaded yet).</param>
    public bool InstallAddition(TileAddition addition, bool fullyBuilt = false, bool loading = false)
    {
        if (addition == null || addition.Conditions() || loading)
        {
            TileAddition oldAddition = this.Addition;
            this.Addition = addition;
            addition.TileAdditionBuilt += TileAdditionBuilt;

            if (OnTileAdditionChanged != null)
            {
                OnTileAdditionChanged(this, oldAddition, addition);
            }
            if (fullyBuilt)
            {
                addition.FinishBuilding();
            }

            BorderDefinitionPossiblyChanged();

            return(true);
        }
        return(false);
    }
Example #14
0
 // we register this method to the tileAddition.OnBuilt event
 void TileAdditionBuilt(TileAddition addition)
 {
     BorderDefinitionPossiblyChanged();
     Addition.TileAdditionBuilt -= TileAdditionBuilt;
 }
 public BuildAdditionState(MouseController mouseController, BuildController controller, TileAddition prototype, Skills requiredSkill) : base(mouseController, controller)
 {
     proto = prototype;
     this.requiredSkill = requiredSkill;
 }
Example #16
0
    protected override void ReadAdditionalXmlProperties(XmlReader reader)
    {
        base.ReadAdditionalXmlProperties(reader);

        Addition = this.DestinationTile.Addition;
    }
Example #17
0
 protected void TileAdditionRemoved(TileAddition addition)
 {
     DeleteJob();
 }
Example #18
0
 private void Addition_TileAdditionBuilt(TileAddition obj)
 {
     JobComplete();
     Addition.TileAdditionBuilt -= Addition_TileAdditionBuilt;
 }