public void Update(float deltaTime)
 {
     if (updateActions != null)
     {
         //updateActions(this, deltaTime);
         FurnitureActions.CallFunctionsWithFurniture(updateActions.ToArray(), this, deltaTime);
     }
 }
 /// <summary>
 /// Fire the event named actionName, resulting in all lua functions being called.
 /// </summary>
 /// <param name="actionName">Name of the action being triggered.</param>
 /// <param name="target">Object, passed to LUA function as 1-argument (TODO: make it an object).</param>
 /// <param name="deltaTime">Time since last Trigger of this event.</param>
 public void Trigger(string actionName, Furniture target, float deltaTime = 0f)
 {
     if (!actionsList.ContainsKey(actionName) || actionsList[actionName] == null)
     {
         return;
     }
     else
     {
         FurnitureActions.CallFunctionsWithFurniture(actionsList[actionName].ToArray(), target, deltaTime);
     }
 }
Beispiel #3
0
 /// <summary>
 /// "Fire" the event named actionName, resulting in all lua functions being called.
 /// </summary>
 /// <param name="actionName">Name of the action being triggered.</param>
 /// <param name="target">Object, passed to LUA function as 1-argument (TODO: make it an object).</param>
 /// <param name="deltaTime">Time since last Trigger of this event.</param>
 public void Trigger(string actionName, Furniture target, float deltaTime = 0f)
 {
     if (!actionsList.ContainsKey(actionName) || actionsList[actionName] == null)
     {
         ////Debug.LogWarning(string.Format("The action \"{0}\" is associated with no LUA function.", actionName));
         return;
     }
     else
     {
         FurnitureActions.CallFunctionsWithFurniture(actionsList[actionName].ToArray(), target, deltaTime);
     }
 }
    public void Update(float deltaTime)
    {
        if (updateActions != null)
        {
            //updateActions(this, deltaTime);

            if (powerValue > 0 && isPowerGenerator == false)
            {
                if (World.current.powerSystem.RequestPower(this) == false)
                {
                    World.current.powerSystem.RegisterPowerConsumer(this);
                    return;
                }
            }

            FurnitureActions.CallFunctionsWithFurniture(updateActions.ToArray(), this, deltaTime);
        }
    }
    public void Deconstruct()
    {
        Debug.Log("Deconstruct");
        int  x                = tile.X;
        int  y                = tile.Y;
        int  fwidth           = 1;
        int  fheight          = 1;
        bool linksToNeighbour = false;

        if (tile.Furniture != null)
        {
            Furniture f = tile.Furniture;
            fwidth           = f.Width;
            fheight          = f.Height;
            linksToNeighbour = f.linksToNeighbour;
            f.CancelJobs();
        }

        // We call lua to decostruct
        if (uninstallActions != null)
        {
            FurnitureActions.CallFunctionsWithFurniture(uninstallActions.ToArray(), this, 0);
        }

        // Update thermalDiffusifity to default value
        World.current.temperature.SetThermalDiffusivity(tile.X, tile.Y,
                                                        Temperature.defaultThermalDiffusivity);

        tile.UnplaceFurniture();

        if (cbOnRemoved != null)
        {
            cbOnRemoved(this);
        }
        // Do we need to recalculate our rooms?
        if (roomEnclosure)
        {
            Room.DoRoomFloodFill(this.tile);
        }

        ////World.current.InvalidateTileGraph();

        if (World.current.tileGraph != null)
        {
            World.current.tileGraph.RegenerateGraphAtTile(tile);
        }

        // We should inform our neighbours that they have just lost a
        // neighbour regardless of objectType.
        // Just trigger their OnChangedCallback.
        if (linksToNeighbour == true)
        {
            for (int xpos = x - 1; xpos < (x + fwidth + 1); xpos++)
            {
                for (int ypos = y - 1; ypos < (y + fheight + 1); ypos++)
                {
                    Tile t = World.current.GetTileAt(xpos, ypos);
                    if (t != null && t.Furniture != null && t.Furniture.cbOnChanged != null)
                    {
                        t.Furniture.cbOnChanged(t.Furniture);
                    }
                }
            }
        }

        // At this point, no DATA structures should be pointing to us, so we
        // should get garbage-collected.
    }
    static public Furniture PlaceInstance(Furniture proto, Tile tile)
    {
        if (proto.funcPositionValidation(tile) == false)
        {
            Debug.LogError("PlaceInstance -- Position Validity Function returned FALSE.");
            return(null);
        }

        // We know our placement destination is valid.
        Furniture obj = proto.Clone();

        obj.tile = tile;

        // FIXME: This assumes we are 1x1!
        if (tile.PlaceFurniture(obj) == false)
        {
            // For some reason, we weren't able to place our object in this tile.
            // (Probably it was already occupied.)

            // Do NOT return our newly instantiated object.
            // (It will be garbage collected.)
            return(null);
        }

        if (obj.linksToNeighbour)
        {
            // This type of furniture links itself to its neighbours,
            // so we should inform our neighbours that they have a new
            // buddy.  Just trigger their OnChangedCallback.

            Tile t;
            int  x = tile.X;
            int  y = tile.Y;

            for (int xpos = x - 1; xpos < (x + proto.Width + 1); xpos++)
            {
                for (int ypos = y - 1; ypos < (y + proto.Height + 1); ypos++)
                {
                    t = World.current.GetTileAt(xpos, ypos);
                    if (t != null && t.Furniture != null && t.Furniture.cbOnChanged != null)
                    {
                        t.Furniture.cbOnChanged(t.Furniture);
                    }
                }
            }
        }

        // Call LUA install scripts
        if (obj.installActions != null)
        {
            FurnitureActions.CallFunctionsWithFurniture(obj.installActions.ToArray(), obj, 0);
        }

        // Update thermalDiffusifity using coefficient
        float thermalDiffusivity = Temperature.defaultThermalDiffusivity;

        if (obj.furnParameters.ContainsKey("thermal_diffusivity"))
        {
            thermalDiffusivity = obj.furnParameters["thermal_diffusivity"];
        }

        World.current.temperature.SetThermalDiffusivity(tile.X, tile.Y, thermalDiffusivity);

        return(obj);
    }